#include<bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    vector<ll> dol={1,2,5,10,20,50,100},euro={5,10,20,50,100,200};
    ll n,d,e;
    cin>>n>>d>>e;
    ll tmp_df=n,tmp_ef=n;
    vector<bool> used_D(7,true),used_E(6,true);
    while(1){
    for(int i=0;i<7;i++){
        if(dol[0]*d>tmp_df)break;
        if(i>0&&used_D[i-1]&&dol[i]*d>tmp_df){tmp_df-=dol[i-1]*d;used_D[i-1]=false;break;}
        if(i==6&&used_D[i]&&dol[i]*d<=tmp_df){tmp_df-=dol[i]*d;used_D[i]=false;}
    }
    bool check=false;
    for(int i=0;i<7;i++)if(used_D[i]&&dol[i]*d<=tmp_df)check=true;
    if(!check)break;
    }
    while(1){
    for(int i=0;i<6;i++){
        if(euro[0]*e>tmp_df)break;
        if(i>0&&used_E[i-1]&&euro[i]*e>tmp_df){tmp_df-=euro[i-1]*e;used_E[i-1]=false;break;}
        if(i==5&&used_E[i]&&euro[i]*e<=tmp_df){tmp_df-=euro[i]*e;used_E[i]=false;}
    }
     bool check=false;
     for(int i=0;i<6;i++)if(used_E[i]&&euro[i]*e<=tmp_df)check=true;
    if(!check)break;
}
for(int i=0;i<7;i++){
if(i<6){used_D[i]=true;used_E[i]=true;}
else used_D[i]=true;
}
while(1){
    for(int i=0;i<6;i++){
        if(!used_E[i])continue;
        if(euro[0]*e>tmp_ef)break;
        if(i>0&&used_E[i-1]&&euro[i]*e>tmp_ef){tmp_ef-=euro[i-1]*e;used_E[i-1]=false;break;}
        if(i==5&&used_E[i]&&euro[i]*e<=tmp_ef){tmp_ef-=euro[i]*e;used_E[i]=false;}
    }
   bool check=false;
    for(int i=0;i<6;i++)if(used_E[i]&&euro[i]*e<=tmp_ef)check=true;
    if(!check)break;
}
while(1){
    for(int i=0;i<7;i++){
        if(dol[0]*d>tmp_ef)break;
        if(i>0&&used_D[i-1]&&dol[i]*d>tmp_ef){tmp_ef-=dol[i-1]*d;used_D[i-1]=false;break;}
        if(i==6&&used_D[i]&&dol[i]*d<=tmp_ef){tmp_ef-=dol[i]*d;used_D[i]=false;}
    }
    bool check=false;
    for(int i=0;i<7;i++)if(used_D[i]&&dol[i]*d<=tmp_ef)check=true;
    if(!check)break;
}
   //cout<<tmp_df<<" "<<tmp_ef<<endl;
    cout<<max((ll)0,min(tmp_df,tmp_ef))<<endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    vector<ll> dol={1,2,5,10,20,50,100},euro={5,10,20,50,100,200};
    ll n,d,e;
    cin>>n>>d>>e;
    ll tmp_df=n,tmp_ef=n;
    for(int i=0;i<7;i++){
        if(dol[0]*d>n)break;
        if(i>0&&dol[i]*d>n){tmp_df-=dol[i-1]*d;break;}
        if(i==6&&dol[i]*d<=n)tmp_df-=dol[i]*d;
    }
    for(int i=0;i<6;i++){
        if(euro[0]*e>tmp_df)break;
        if(i>0&&euro[i]*e>tmp_df){tmp_df-=euro[i-1]*e;break;}
        if(i==5&&euro[i]*e<=tmp_df)tmp_df-=euro[i]*e;
    }
    for(int i=0;i<6;i++){
        if(euro[0]*e>n)break;
        if(i>0&&euro[i]*e>n){tmp_ef-=euro[i-1]*e;break;}
        if(i==5&&euro[i]*e<=n)tmp_ef-=euro[i]*e;
    }
    for(int i=0;i<7;i++){
        if(dol[0]*d>tmp_ef)break;
        if(i>0&&dol[i]*d>tmp_ef){tmp_ef-=dol[i-1]*d;break;}
        if(i==6&&dol[i]*d<=tmp_ef)tmp_ef-=dol[i]*d;
    }
   //cout<<tmp_df<<" "<<tmp_ef<<endl;
    cout<<max((ll)0,min(tmp_df,tmp_ef))<<endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    //vector<int> dol={1,2,5,10,20,50,100},euro={5,10,20,50,100,200};
    ll n,d,e;
    cin>>n>>d>>e;
    ll tmp_df=(n%d)%(5*e),tmp_ef=(n%(5*e))%d;
    cout<<max((ll)0,min(tmp_df,tmp_ef))<<endl;

}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),v.end()
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
 vector<ll> dol={1,2,5,10,20,50,100},euro={5,10,20,50,100,200};
    ll n,d,e;
    cin>>n>>d>>e;
    ll tmp_df=n,tmp_ef=n;
    for(int i=6;i>=0;i--)if(dol[i]*d<=tmp_df)tmp_df-=dol[i]*d;
    for(int i=5;i>=0;i--)if(euro[i]*e<=tmp_df)tmp_df-=euro[i]*e;
    for(int i=5;i>=0;i--)if(euro[i]*e<=tmp_ef)tmp_ef-=euro[i]*e;
    for(int i=6;i>=0;i--)if(dol[i]*d<=tmp_ef)tmp_ef-=dol[i]*d;
      cout<<max((ll)0,min(tmp_df,tmp_ef))<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define pb push_back
#define all(v) (v).begin(),v.end()
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
 vector<ll> dol={1,2,5,10,20,50,100},euro={5,10,20,50,100,200};
    ll n,d,e;
    cin>>n>>d>>e;
    vector<ll> tmp;
    ll ans=inf;
    for(int i=0;i<7;i++){
       if(i<6){tmp.push_back(dol[i]*d);tmp.push_back(euro[i]*e);}
       else tmp.push_back(dol[i]*d);
    }
     for(int i=0;i<(1<<13);i++){
         ll res=n;
         for(int j=0;j<13;j++){
              if(i&(1<<j))res-=tmp.at(j);
         }
         if(res<0)continue;
         ans=min(ans,res);
     }
   cout<<ans<<endl;
}


#include<bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
set<string> c;
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
    ll n,d,e;
    cin>>n>>d>>e;
    ll ans=inf;
    for(ll i=0;i*d<=n;i++){
    ans=min(ans,(n-i*d)%(5*e));
    }
    cout<<ans<<endl;

}


#include<bits/stdc++.h>
#define ll long long
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN

using namespace std;

int main()
{
	int n,e,d;
	cin>>n;
	cin>>d;
	cin>>e;
	int ans = INT_MAX;
	for(int i=0;i*5*e<=n;i++)
	{
		ans = min(ans,(n-i*5*e)%d);
	}
	cout<<ans<<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN

using namespace std;

int main()
{
	int n,e,d;
	cin>>n;
	cin>>d;
	cin>>e;
	while(n>0)
	{
		if(n%d==0)
		{
			n = 0;
			break;
		}
		n -= 5*e;
	}
	if(n==0)
	{
		cout<<n<<endl;
	}
	else
	{
		n += 5*e;
		n = n%d;
		cout<<n<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN

using namespace std;

int main()
{
	int n,e,d;
	cin>>n;
	cin>>d;
	cin>>e;
	while(n>0)
	{
		n -= 5*e;
	}
	if(n==0)
	{
		cout<<n<<endl;
	}
	else
	{
		n += 5*e;
		n = n%d;
		cout<<n<<endl;
	}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN

using namespace std;

int main()
{
	int n,e,d;
	cin>>n;
	cin>>d;
	cin>>e;
	int ans = INT_MAX;
	for(int i=0;i*5*e<=n;i++)
	{
		ans = min(ans,(n-i*5*e)%d);
	}
	cout<<ans<<endl;
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN

using namespace std;

int main()
{
	int n,e,d;
	cin>>n;
	cin>>d;
	cin>>e;

		int f = 0;
		while(n>0)
		{
			if(n%d!=0 && n%e!=0)
			{
				n -= max(d,5*e);
			}
			else
			{
				cout<<0<<endl;
				f++;
				break;
			}
		}
		if(f==0)
		{
			n += max(d,5*e);
			while(n>=min(d,5*e))
				n -= min(d,5*e);
			cout<<n<<endl;
		}
	return 0;
}


#include<bits/stdc++.h>
#define ll long long
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN

using namespace std;

int main()
{
	int n,e,d;
	cin>>n;
	cin>>d;
	cin>>e;

		int f = 0;
		while(n>0)
		{
			if(n%d!=0 && n%e!=0)
			{
				n -= max(d,5*e);
			}
			else
			{
				cout<<0<<endl;
				f++;
				break;
			}
		}
		if(f==0)
		{
			n += max(d,5*e);
			if(n>=min(d,5*e))
				n -= min(d,5*e);
			cout<<n<<endl;
		}
	return 0;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    //n=h;
    gk1=0,gk2=0;
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        for(i=0; i<6; i++)
        {
            if(br[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk2=1;
                break;
            }
        }
        long long int d2=v2-(v1*d);
        long long int sum=d2;
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        for(i=0; i<6; i++)
        {
            if(ar[i]==v1)
            {
                gk2=1;
                break;
            }
        }
        long long int d2=n-(v1*e);
        long long int sum=d2;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
        cout << min1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    gk1=0,gk2=0;
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        if(v1%5==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        if(v1%1==0)
        {
            gk2=1;
        }
        //cout << v1 << endl;
        long long int d2=v2-(v1*d);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        if(v1%1==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        if(v1%5==0)
        {
            gk2=1;
        }
            //cout << gk2 << endl;
        long long int d2=n-(v1*e);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
    if(gk1==0 && gk2==0)
    {
        cout << n << endl;
    }
    else
        cout << min1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    gk1=0,gk2=0;
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        for(i=0; i<6; i++)
        {
            if(br[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk2=1;
                break;
            }
        }
        //cout << v1 << endl;
        long long int d2=v2-(v1*d);
        long long int sum=d2;
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        for(i=0; i<6; i++)
        {
            if(ar[i]==v1)
            {
                gk2=1;
                break;
            }
        }
        long long int d2=n-(v1*e);
        long long int sum=d2;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
    if(gk1==0 && gk2==0)
    {
        cout << n << endl;
    }
    else
        cout << min1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    j=e;
    gk1=0,gk2=0;
    if((n%d==0) || (n%e==0 && (n/e)%5==0))
    {
        cout << 0 << endl;
        return 0;
    }
    int vv=n;
    while(1)
    {
        if(vv%d==0 || vv%e==0)
        {
            cout << 1 << endl;
            return 0;
        }
        vv-=d;
        if(vv<=0)
            break;
    }
    if(e%5==1)
    {
        e*=5;
    }
    while(1)
    {
        if(vv%d==0 || vv%e==0)
        {
            cout << 2 << endl;
            return 0;
        }
        vv-=e;
        if(vv<=0)
            break;
    }
    e=j;
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        if(v1%5==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        if(v1%1==0)
        {
            gk2=1;
        }
        //cout << v1 << endl;
        long long int d2=v2-(v1*d);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        if(v1%1==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        if(v1%5==0)
        {
            gk2=1;
        }
        //cout << gk2 << endl;
        long long int d2=n-(v1*e);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
    if(gk1==0 && gk2==0)
    {
        cout << n << endl;
    }
    else
        cout << min1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    j=e;
    gk1=0,gk2=0;
    if((n%d==0) || (n%e==0 && (n/e)%5==0))
    {
        cout << 0 << endl;
        return 0;
    }
    int vv=n;
    while(1)
    {
        if(vv%d==0 || vv%e==0)
        {
            cout << 0 << endl;
            return 0;
        }
        vv-=d;
        if(vv<=0)
            break;
    }
    if(e%5==1)
    {
        e*=5;
    }
    while(1)
    {
        if(vv%d==0 || vv%e==0)
        {
            cout << 0 << endl;
            return 0;
        }
        vv-=e;
        if(vv<=0)
            break;
    }
    e=j;
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        if(v1%5==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        if(v1%1==0)
        {
            gk2=1;
        }
        //cout << v1 << endl;
        long long int d2=v2-(v1*d);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        if(v1%1==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        if(v1%5==0)
        {
            gk2=1;
        }
        //cout << gk2 << endl;
        long long int d2=n-(v1*e);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
    if(gk1==0 && gk2==0)
    {
        cout << n << endl;
    }
    else
        cout << min1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    gk1=0,gk2=0;
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        for(i=0; i<6; i++)
        {
            if(br[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk2=1;
                break;
            }
        }
        //cout << v1 << endl;
        long long int d2=v2-(v1*d);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        for(i=0; i<6; i++)
        {
            if(br[i]==v1)
            {
                gk2=1;
                break;
            }
        }
            //cout << gk2 << endl;
        long long int d2=n-(v1*e);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
    if(gk1==0 && gk2==0)
    {
        cout << n << endl;
    }
    else
        cout << min1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    //n=h;
    gk1=0,gk2=0;
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        for(i=0; i<6; i++)
        {
            if(br[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk2=1;
                break;
            }
        }
        long long int d2=v2-(v1*d);
        long long int sum=d2;
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        for(i=0; i<6; i++)
        {
            if(ar[i]==v1)
            {
                gk2=1;
                break;
            }
        }
        long long int d2=n-(v1*e);
        long long int sum=n-(d1+d2);
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
        cout << min1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    gk1=0,gk2=0;
    if((n%d==0) || (n%e==0 && (n/e)%5==0))
    {cout << 0 << endl;
     return 0;}
     int vv=n;
     while(1)
     {
         if(vv%d==0 || vv%e==0 || vv<=0)
         {
             cout << 0 << endl;
             return 0;
         }
         vv-=d;

     }
      while(1)
     {
         if(vv%d==0 || vv%e==0 || vv<=0)
         {
             cout << 0 << endl;
             return 0;
         }
         vv-=e;

     }
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        if(v1%5==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        if(v1%1==0)
        {
            gk2=1;
        }
        //cout << v1 << endl;
        long long int d2=v2-(v1*d);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        if(v1%1==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        if(v1%5==0)
        {
            gk2=1;
        }
            //cout << gk2 << endl;
        long long int d2=n-(v1*e);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
    if(gk1==0 && gk2==0)
    {
        cout << n << endl;
    }
    else
        cout << min1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int ar[500009],br[500009];
int main()
{
    long long int a,b,c,i,j=999999999999,k,e,f,g,w,h,i1,j1;
    string s,d;
    cin>>a>>b>>c;
    e=a;
    c=c*5;
    j=a;
    for(i=1;; i++)
    {
        a=e;
        if(a-(i*b)<0)
        {
            break;
        }
        a=a-(i*b);
        a=a-((a/c)*c);
        j=min(j,a);
    }
    for(i=1;; i++)
    {
        a=e;
        if(a-(i*c)<0)
        {
            break;
        }
        a=a-(i*c);
        a=a-((a/b)*b);
        j=min(j,a);
    }
    cout<<j<<endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    gk1=0,gk2=0;
    if((n%d==0) || (n%e==0 && (n/e)%5==0))
    {cout << 0 << endl;
     return 0;}
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        if(v1%5==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        if(v1%1==0)
        {
            gk2=1;
        }
        //cout << v1 << endl;
        long long int d2=v2-(v1*d);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        if(v1%1==0)
        {
            gk1=1;
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        if(v1%5==0)
        {
            gk2=1;
        }
            //cout << gk2 << endl;
        long long int d2=n-(v1*e);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
    if(gk1==0 && gk2==0)
    {
        cout << n << endl;
    }
    else
        cout << min1 << endl;
}


#include<bits/stdc++.h>
using namespace std;
long long int   ar[]= {1, 2, 5, 10, 20, 50, 100};
long long int br[]= {5, 10, 20, 50, 100, 200};
//long long int ar[10000];
//long long int br[10000];
int main()
{
    long long int i,j,k,e,r,n,d,min1=1234566789,gk1,gk2;
    cin >>n >> d >> e;
    gk1=0,gk2=0;
    if(d<e)
    {
        long long int v=n;
        long long int v1=v/e;
        for(i=0; i<6; i++)
        {
            if(br[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*e);
        long long int v2=n-(v1*e);
        if(gk1==0)
            v2=n;
        v1=v2/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk2=1;
                break;
            }
        }
        //cout << v1 << endl;
        long long int d2=v2-(v1*d);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        //cout << sum << endl;
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }

    }
    else
    {
        long long int v=n;
        long long int v1=v/d;
        for(i=0; i<7; i++)
        {
            if(ar[i]==v1)
            {
                gk1=1;
                break;
            }
        }
        long long int d1=n-(v1*d);
        long long int v2=n-(v1*d);
        if(gk1==0)
            v2=n;
        v1=v2/e;
        for(i=0; i<6; i++)
        {
            if(ar[i]==v1)
            {
                gk2=1;
                break;
            }
        }
        long long int d2=n-(v1*e);
        long long int sum;
        if(gk1==1&& gk2==0)
        {
            sum=d1;
        }
        else if( gk1==0 && gk2 ==1)
        {
            sum=d2;
        }
        else
        {
            sum=d2;
        }
        if(gk1==1 && gk2==1)
        {
            min1=min(sum,min1);
        }
        else
        {
            if(gk1==1)
            {
                min1=min(d1,min1);
            }
            else if(gk2==1)
            {
                //cout << d2 << endl;
                min1=min(d2,min1);
            }
        }
    }
    if(gk1==0 && gk2==0)
    {
        cout << n << endl;
    }
    else
        cout << min1 << endl;
}


#include <bits/stdc++.h>

#define nfs()\
ios_base::sync_with_stdio(false);\
cin.tie(nullptr);

using namespace std;
using ll = long long;
using ull = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    #ifndef LOCAL
        nfs();
    #endif

    vector<int> bills = {
        1, 2, 5, 10, 20, 50, 100, 5, 10, 20, 50, 100, 200
    };

    int n, e, d;
    cin >> n >> d >> e;

    for (int i = 0; i < 7; ++i) {
        bills[i] *= d;
    }

    for (int i = 7; i < bills.size(); ++i) {
        bills[i] *= e;
    }

    sort(bills.begin(), bills.end());

    while (n >= bills.front()) {
        int j = lower_bound(bills.begin(), bills.end(), n) - bills.begin();
        if (j == n || (j > 0 && bills[j] > n)) {
            --j;
        }
        n -= ((n / bills[j]) * bills[j]);
    }
    cout << n << '\n';
}


#include <bits/stdc++.h>

#define nfs()\
ios_base::sync_with_stdio(false);\
cin.tie(nullptr);

using namespace std;
using ll = long long;
using ull = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    #ifndef LOCAL
        nfs();
    #endif

    vector<int> bills = {
        1, 2, 5, 10, 20, 50, 100, 5, 10, 20, 50, 100, 200
    };

    int n, e, d;
    cin >> n >> d >> e;

    for (int i = 0; i < 7; ++i) {
        bills[i] *= d;
    }

    for (int i = 7; i < bills.size(); ++i) {
        bills[i] *= e;
    }

    sort(bills.begin(), bills.end());

    while (n >= bills.front()) {
        int j = lower_bound(bills.begin(), bills.end(), n) - bills.begin();
        if (j == bills.size() || (j > 0 && bills[j] > n)) {
            --j;
        }
        n -= ((n / bills[j]) * bills[j]);
    }
    cout << n << '\n';
}


#include <bits/stdc++.h>

#define nfs()\
ios_base::sync_with_stdio(false);\
cin.tie(nullptr);

using namespace std;
using ll = long long;
using ull = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    #ifndef LOCAL
        nfs();
    #endif

    int n, e, d;
    cin >> n >> d >> e;

    int res = 1E9;
    for (int i = 0; i * e * 5 <= n; ++i) {
        res = min(res, (n - i  * e * 5) % d);
    }
    cout << res << '\n';
}


#include <bits/stdc++.h>

#define nfs()\
ios_base::sync_with_stdio(false);\
cin.tie(nullptr);

using namespace std;
using ll = long long;
using ull = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    #ifndef LOCAL
        nfs();
    #endif

    int n, e, d;
    cin >> n >> d >> e;
    e *= 5;

    int dls = n - (n / d) * d;
    int els = n - (n / e) * e;
    int dels = els - (els / d) * d;

    cout << min(els, min(dls, dels)) << '\n';
}


#include <bits/stdc++.h>

#define nfs()\
ios_base::sync_with_stdio(false);\
cin.tie(nullptr);

using namespace std;
using ll = long long;
using ull = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    #ifndef LOCAL
        nfs();
    #endif

    vector<int> bills = {
        1, 2, 5, 10, 20, 50, 100, 5, 10, 20, 50, 100, 200
    };

    int n, e, d;
    cin >> n >> d >> e;

    for (int i = 0; i < 7; ++i) {
        bills[i] *= d;
    }

    for (int i = 7; i < bills.size(); ++i) {
        bills[i] *= e;
    }

    sort(bills.begin(), bills.end());

    while (n >= bills.front()) {
        int j = lower_bound(bills.begin(), bills.end(), n) - bills.begin();
        if (j > 0 && bills[j] > n) {
            --j;
        }
        n -= ((n / bills[j]) * bills[j]);
    }
    cout << n << '\n';
}


#include <bits/stdc++.h>

#define nfs()\
ios_base::sync_with_stdio(false);\
cin.tie(nullptr);

using namespace std;
using ll = long long;
using ull = long long;
using ld = long double;
constexpr ll MOD = 1e9 + 7;
constexpr ll INF = 1e18;

int main() {
    #ifndef LOCAL
        nfs();
    #endif

    int n, e, d;
    cin >> n >> d >> e;
    e *= 5;

    int dls = n - (n / d) * d;
    int els = n - (n / e) * e;
    int dels = min(els - (els / d) * d, dls - (dls / e) * e);

    cout << min(els, min(dls, dels)) << '\n';
}


#include<bits/stdc++.h>
using namespace std;

int dolla[10];
int erou[10];
int dp[30];
int main(){
    int n,e,d;
    while(cin >> n >> d >> e){

        dolla[0] = 0;
        dolla[1] = d;
        dolla[2] = 2*d;
        dolla[3] = 5*d;
        dolla[4] = 10*d;
        dolla[5] = 20*d;
        dolla[6] = 50*d;
        dolla[7] = 100*d;

        dolla[8] = 5*e;
        dolla[9] = 10*e;
        dolla[10] = 20*e;
        dolla[11] = 50*e;
        dolla[12] = 100*e;
        dolla[13] = 200*e;

       // sort(dolla, dolla+14);
       // for(int i=0;i<14;i++){
       //     cout << dolla[i] <<endl;
       // }
        int i,j;
        int min_num = n;
        int up = 1<<13;
        for(i=0;i <up;i++){
            int sum = 0;
            for(j=0; j<13; j++){
                if(i & (1<<j)){
                    sum += dolla[j];
                }
            }
            if(n - sum < min_num && n-sum >=0){
                min_num = n-sum;
            }
        }
        cout << min_num <<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int dolla[10];
int erou[10];
int dp[30];
int main(){
    int n,e,d;
    while(cin >> n >> d >> e){

        dolla[0] = 0;
        dolla[1] = d;
        dolla[2] = 2*d;
        dolla[3] = 5*d;
        dolla[4] = 10*d;
        dolla[5] = 20*d;
        dolla[6] = 50*d;
        dolla[7] = 100*d;

        dolla[8] = 5*e;
        dolla[9] = 10*e;
        dolla[10] = 20*e;
        dolla[11] = 50*e;
        dolla[12] = 100*e;
        dolla[13] = 200*e;

        sort(dolla, dolla+14);
       // for(int i=0;i<14;i++){
       //     cout << dolla[i] <<endl;
       // }
        int i,j;
        int min_num = n;
        int up = 1<<13;
        for(i=0;i <up;i++){
            int sum = 0;
            for(j=0;j<13 && i <=n ;j++){
                if(i & (1<<j)){
                    sum += dolla[j];
                   // cout <<i<<endl;
                    //cout <<(1<<j) <<endl;
                    //cout<< j <<endl;
                   // cout <<sum <<endl;
                }
            }
            if(n - sum < min_num && n-sum >=0){
                min_num = n-sum;
            }
        }
        cout << min_num <<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int dolla[10];
int erou[10];
int main(){
    int n,e,d;
    while(cin >> n >> d >> e){

        dolla[0] = 0;
        dolla[1] = d;
        dolla[2] = 2*d;
        dolla[3] = 5*d;
        dolla[4] = 10*d;
        dolla[5] = 20*d;
        dolla[6] = 50*d;
        dolla[7] = 100*d;

        erou[0] = 0;
        erou[1] = 5*e;
        erou[2] = 10*e;
        erou[3] = 20*e;
        erou[4] = 50*e;
        erou[5] = 100*e;
        erou[6] = 200*e;

        int min_num = n;
        int sum = n;
        while(1){
            for(int i=0;i<=7;i++){
                for(int j=0;j<=6;j++){
                    int tmp = dolla[i] + erou[j];
                    int left = sum - tmp;
                    if(left < 0) break;
                    if(left < min_num) min_num = left;
                }
            }
            sum = min_num;
            if(sum < d && sum < e) break;

        }
        cout << min_num <<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int dolla[10];
int erou[10];
int main(){
    int n,e,d;
    while(cin >> n >> d >> e){

        dolla[0] = 0;
        dolla[1] = d;
        dolla[2] = 2*d;
        dolla[3] = 5*d;
        dolla[4] = 10*d;
        dolla[5] = 20*d;
        dolla[6] = 50*d;
        dolla[7] = 100*d;

        erou[0] = 0;
        erou[1] = 5*e;
        erou[2] = 10*e;
        erou[3] = 20*e;
        erou[4] = 50*e;
        erou[5] = 100*e;
        erou[6] = 200*e;

        int min_num = n+1;
        for(int i=0;i<=7;i++){
            for(int j=0;j<=6;j++){
                int tmp = dolla[i] + erou[j];
                int left = n - tmp;
                if(left < 0) break;
                if(left < min_num) min_num = left;
            }
        }
        cout << min_num <<endl;
    }
    return 0;
}


#include<bits/stdc++.h>

using namespace std;

int main(){
    int n,d,e;
    cin >> n >> d >> e;
    e = 5 *e;
    int ans = n;
    for(int i=0;i*d<=n;i++){
        ans = min(ans, (n-i*d)%e);
    }
    cout << ans << endl;
    return 0;
}


#include<bits/stdc++.h>
using namespace std;

int dolla[10];
int erou[10];
int main(){
    int n,e,d;
    while(cin >> n >> d >> e){

        dolla[0] = 0;
        dolla[1] = d;
        dolla[2] = 2*d;
        dolla[3] = 5*d;
        dolla[4] = 10*d;
        dolla[5] = 20*d;
        dolla[6] = 50*d;
        dolla[7] = 100*d;

        erou[0] = 0;
        erou[1] = 5*e;
        erou[2] = 10*e;
        erou[3] = 20*e;
        erou[4] = 50*e;
        erou[5] = 100*e;
        erou[6] = 200*e;

        int min_num = n;
        for(int i=0;i<=7;i++){
            for(int j=0;j<=6;j++){
                int tmp = dolla[i] + erou[j];
                int left = n - tmp;
                if(left < 0) break;
                if(left < min_num) min_num = left;
            }
        }
        cout << min_num <<endl;
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef long long int lli;
#define pb push_back
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    int d, e;
    cin >> n >> d >> e;
    //unordered_map<int, int> dl({{1,1}, {2,1}, {5,1}, {10,1}, {20,1}, {50,1},  {100,1}});
    //unordered_map<int, int> eu({{5,1}, {10,1}, {20,1}, {50,1}, {100,1},  {200,1}});
    if(min(d, e) > n)
        cout << n << endl;
    else if(d+e > n)
        cout << n - d << endl;
    else if((n/e)%5 == 0)
        cout << (n%e)%d << endl;
    else
        cout << n%d << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef long long int lli;
#define pb push_back
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    int d, e;
    cin >> n >> d >> e;
    //unordered_map<int, int> dl({{1,1}, {2,1}, {5,1}, {10,1}, {20,1}, {50,1},  {100,1}});
    //unordered_map<int, int> eu({{5,1}, {10,1}, {20,1}, {50,1}, {100,1},  {200,1}});
    if(d+e > n)
        cout << n - d << endl;
    else if((n/e)%5 == 0)
        cout << (n%e)%d << endl;
    else
        cout << n%d << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef long long int lli;
#define pb push_back
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define endl "\n"
const int N = 1e8+5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n, d, e;
    cin >> n >> d >> e;
    e *= 5;
    int ans = n%d;
    for(int i=0; i<n/d; i++)
        ans = min(ans, (n-d*i)%e);
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef long long int lli;
#define pb push_back
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define endl "\n"

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    int d, e;
    cin >> n >> d >> e;
    //unordered_map<int, int> dl({{1,1}, {2,1}, {5,1}, {10,1}, {20,1}, {50,1},  {100,1}});
    //unordered_map<int, int> eu({{5,1}, {10,1}, {20,1}, {50,1}, {100,1},  {200,1}});
    if(min(d, e) > n)
        cout << n << endl;
    else if(d+e > n)
        cout << n - d << endl;
    else if(n % (d+e) == 0)
        cout << "0" << endl;
    else if((n/e)%5 == 0)
        cout << (n%e)%d << endl;
    else
        cout << n%d << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef long long int lli;
#define pb push_back
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define endl "\n"
const int N = 1e8+5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    int d, e;
    cin >> n >> d >> e;
    e *= 5;
    ans = N;
    for(int i=0; i<n/d; i++)
        ans = min(ans, (n-d*i)%e);
    cout << ans << endl;
}


#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
typedef long long int lli;
#define pb push_back
#define all(a) a.begin(), a.end()
#define forn(i, n) for(int i=0; i<(int)(n); ++i)
#define forab(i, a, b) for(int i=(int)(a); i<=(int)(b); ++i)
#define endl "\n"
const int N = 1e8+5;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    int d, e;
    cin >> n >> d >> e;
    e *= 5;
    ll ans = N;
    for(int i=0; i<n/d; i++)
        ans = min(ans, (n-d*i)%e);
    cout << ans << endl;
}


#include <stdio.h>

/* ON TEST 2 MY SCRIPT PRINTS 2 ,WHICH IS JURY'S ANSWER BUT ON WEBPAGE IT PRINTS 1? */
int main(){
	int length;
	scanf("%d",&length);
	int place_numbers[length];
	int i=0;
	int number;
	for(;i<length;i++){
		scanf("%d",&number);
		place_numbers[i]=number;
	}
	i=0;
	int division_array[length];
	for (;i<length;i++){
		division_array[i]=place_numbers[i]%2;		/*1*/
	}

	i=0;
	int even,odd=0;
	for (;i<length;i++){
		if (division_array[i]==1){odd++;}
		else if (division_array[i]==0){even++;}

		}
	int index;
	if(even>odd){
	for(i=0;i<length;i++){
		if(division_array[i]==1){index=i;break;}
	}
	}
	else if (odd>even){
		for(i=0;i<length;i++){
			if(division_array[i]==0){index=i;break;}
		}
	}

	printf("%d",(i+1));  /*WTH*/
	return 0;
}


#include <stdio.h>

/* ON TEST 2 MY SCRIPT PRINTS 2 ,WHICH IS JURY'S ANSWER BUT ON WEBPAGE IT PRINTS 1? */
int main(){
	int length;
	scanf("%d",&length);
	int place_numbers[length];
	int i=0;
	int number;
	for(;i<length;i++){
		scanf("%d",&number);
		place_numbers[i]=number;
	}
	i=0;
	int division_array[length];
	for (;i<length;i++){
		division_array[i]=place_numbers[i]%2;		/*1*/
	}

	i=0;
	int even,odd=0;
	for (;i<length;i++){
		if (division_array[i]==1){odd++;}
		else if (division_array[i]==0){even++;}

		}
	int index;
	if(even>odd){
	for(i=0;i<length;i++){
		if(division_array[i]==1){index=i;break;}
	}
	}
	else if (odd>even){
		for(i=0;i<length;i++){
			if(division_array[i]==0){index=i;break;}
		}
	}

	printf("%d",i+1);  /*WTH*/
	return 0;
}


#include<stdio.h>
int main()
{
    int i,a,d[1000],count=0;
    scanf("%d",&a);

    for(i=0;i<a;i++)
    {
	scanf("%d",&d[i]);
	if(d[i]%2==0)
	{
	    count++;
	   }
	else
	{
	    count--;
	}

    }
    if(count<0)
    {
	count=-count;
    }
    printf("%d",count);

 return 0;
}


#include <stdio.h>

int main()
{
    int i, n ;

    scanf("%d", &n) ;

    int x[n+5] ;

    for(i=1; i<=n; ++i)
        scanf("%d", &x[i]) ;

    for(i=1; i<=n; ++i)
    {
        if(x[i]%2 != x[i+1]%2)
            break ;
    }

    if(x[i]%2 != x[i-1]%2)
        printf("%d\n", i) ;
    else
        printf("%d\n", i+1);

    return 0 ;
}


    #include <stdio.h>
#include <string.h>

int iqtest(int *, int, int);
int main ()
{
    int n,num[100],i=0,x,y,c=0;
    char str[210];
    char * pch;
    scanf("%d ",&n);
      if(n<3 || n>100)
      {
          scanf("%d",&n);
      }
      gets(str);
      pch = strtok (str," ");
      while (pch != NULL)
      {
        num[i]=atoi(pch);
        if(num[i]%2==0)
        {
            c++;
        }
        pch = strtok (NULL, " ");
        i++;
      }

      if (c>1)
      {
          x=1;
      }
      else{
        x=0;
      }
      y=iqtest(num,x,n);

      printf("%d",y);

      return 0;
}
int iqtest(int *num, int x, int n)
{
    int i;;
    if (x==1)
    {
        for(i=0; i<n; i++)
        {
            if(num[i]%2 != 0)
            {
                return i+1;
            }
        }
    }
    else{
        for(i=0; i<n; i++)
        {
            if(num[i]%2 == 0)
            {
                return i+1;
            }
        }
    }
}


    #include <stdio.h>
#include <string.h>

int iqtest(int *, int, int);
int main ()
{
    int n,num[100],i=0,x,y,c=0;
    char str[10000];
    char * pch;
    scanf("%d ",&n);
      if(n<3 || n>100)
      {
          scanf("%d",&n);
      }
      gets(str);
      pch = strtok (str," ");
      while (pch != NULL)
      {
        num[i]=atoi(pch);
        if(num[i]%2==0)
        {
            c++;
        }
        pch = strtok (NULL, " ");
        i++;
      }

      if (c>1)
      {
          x=1;
      }
      else{
        x=0;
      }
      y=iqtest(num,x,n);

      printf("%d",y);

      return 0;
}
int iqtest(int *num, int x, int n)
{
    int i;;
    if (x==1)
    {
        for(i=0; i<n; i++)
        {
            if(num[i]%2 != 0)
            {
                return i+1;
            }
        }
    }
    else{
        for(i=0; i<n; i++)
        {
            if(num[i]%2 == 0)
            {
                return i+1;
            }
        }
    }
}


    #include <stdio.h>
#include <string.h>

int iqtest(int *, int, int);
int main ()
{
    int n,num[100],i=0,x,y,c=0;
    char str[200];
    char * pch;
    scanf("%d ",&n);
      if(n<3 || n>100)
      {
          scanf("%d",&n);
      }
      gets(str);
      pch = strtok (str," ");
      while (pch != NULL)
      {
        num[i]=atoi(pch);
        if(num[i]%2==0)
        {
            c++;
        }
        pch = strtok (NULL, " ,.-");
        i++;
      }

      if (c>1)
      {
          x=1;
      }
      else{
        x=0;
      }
      y=iqtest(num,x,n);

      printf("%d",y);

      return 0;
}
int iqtest(int *num, int x, int n)
{
    int i;;
    if (x==1)
    {
        for(i=0; i<n; i++)
        {
            if(num[i]%2 != 0)
            {
                return i+1;
            }
        }
    }
    else{
        for(i=0; i<n; i++)
        {
            if(num[i]%2 == 0)
            {
                return i+1;
            }
        }
    }
}


    #include <stdio.h>
#include <string.h>

int iqtest(int *, int, int);
int main ()
{
    int n,num[102],i=0,x,y,c=0;
    char str[202];
    char * pch;
    scanf("%d ",&n);
      if(n<3 || n>100)
      {
          scanf("%d",&n);
      }
      gets(str);
      pch = strtok (str," ");
      while (pch != NULL)
      {
        num[i]=atoi(pch);
        if(num[i]%2==0)
        {
            c++;
        }
        pch = strtok (NULL, " ");
        i++;
      }

      if (c>1)
      {
          x=1;
      }
      else{
        x=0;
      }
      y=iqtest(num,x,n);

      printf("%d",y);

      return 0;
}
int iqtest(int *num, int x, int n)
{
    int i;;
    if (x==1)
    {
        for(i=0; i<n; i++)
        {
            if(num[i]%2 != 0)
            {
                return i+1;
            }
        }
    }
    else{
        for(i=0; i<n; i++)
        {
            if(num[i]%2 == 0)
            {
                return i+1;
            }
        }
    }
}


include <stdio.h>
int main{
    int n,a,even,odd;
    int ar[101];
    scanf("%d", &n);
    even, odd = 0;
    for (i = 0; i < n ; i++):
    {
         scanf("%d",&a);
         ar[i] = a;
         if a % 2 == 0
         {
                 even++}
         else
         {
                 odd++}
    }
    if even > 1
        {
                for(i = 1; i <= n; i++)
                {
                        if (ar[i] % 2 = 1)
                        {
                                print(i+1);
                                break;}}}
    else{
             for(i = 1; i <= n; i++)
                {
                        if (ar[i] % 2 = 0)
                        {
                                print(i+1);
                                break;}}}
    }


#include <stdio.h>
int main(){
    int n,a,even,odd,x,y,i;
    scanf("%d", &n);
    even, odd = 0;
    for (i = 0; i < n ; i++)
    {
         scanf("%d",&a);
         if (a % 2 == 0)
         {
                 even++;
                 x = i;}
         else
         {
                 odd++;
                 y = i;}
    }
    printf("%d",even<odd?x:y);}


#include <stdio.h>
int main(){
    int n,a,even,odd,x,y,i;
    scanf("%d", &n);
    even = 0;
    odd = 0;
    for (i = 0 ; i < n ; i++)
    {
         scanf("%d",&a);

         if (a % 2 == 0)
         {
                 even++;
                 x = i;

         }
         else
         {
                 odd++;
                 y = i;
         }
    }
    printf("%d",even < odd ? x+1 : y+1);

}


#include <stdio.h>
int main(){
    int n,a,even,odd,x,y,i;
    scanf("%d", &n);
    even, odd = 0;
    for (i = 0; i < n ; i++)
    {
         scanf("%d",&a);
         if (a % 2 == 0)
         {
                 even++;
                 x = i;}
         else
         {
                 odd++;
                 y = i;}
    }
    printf("%d",even<odd?x+1:y+1);}


#include<stdio.h>
int even, res, a, b, c, n;

main() {
	scanf("%d %d %d %d", &n, &a, &b, &c);
	if(a%2 == b%2) {
		even = a%2;
		if(c%2 != a%2)
			res = 3;
	else {
		even = c%2;
		if (a%2 == c%2)
			res = 2;
		else
			res = 1;
	}
	for(int i = 3; i<n; i++) {
		scanf("%d", &a);
		if (a%2 != even)
			res = i;
	}
	printf("%d", res);
	return 0;
}


#include<stdio.h>
int even, res, a, b, c, n;

main() {
	scanf("%d %d %d %d", &n, &a, &b, &c);
	if(a%2 == b%2) {
		even = a%2;
		if(c%2 != a%2)
			res = 3;
	} else {
		even = c%2;
		if (a%2 == c%2)
			res = 2;
		else
			res = 1;
	}
	for(int i = 3; i<n; i++) {
		scanf("%d", &a);
		if (a%2 != even)
			res = i;
	}
	printf("%d", res);
	return 0;
}


#include<stdio.h>
int even, res, a, b, c, n;

main() {
	scanf("%d %d %d %d", &n, &a, &b, &c);
	if(a%2 == b%2) {
		even = a%2;
		if(c%2 != a%2)
			res = 3;
	} else {
		even = c%2;
		if (a%2 == c%2)
			res = 2;
		else
			res = 1;
	}
	for(int i = 4; i<=n; i++) {
		scanf("%d", &a);
		if (a%2 != even)
			res = i;
	}
	printf("%d", res);
	return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main(){
    int a,i,par=0,impar=0,ppar,pimpar;
    int *v;

    scanf("%d",&a);

    v=(int*)malloc(a*(sizeof(int)));

    for(i=0;i<a;i++){
        scanf("%d",&v[i]);
    }

    for(i=0;i<a;i++){
        if(v[i]%2==0){
            par++;
            ppar=i+1;
        }
        else{
            impar++;
            pimpar=i+1;
        }
    }
    if(par==1){
        printf("%d",ppar);
    }
    else
        printf("%d",pimpar);

    free(v);
return 0;
}


#include<stdio.h>
#include<stdlib.h>
int main(){
    int a,i,par=0,impar=0,ppar,pimpar;/*variables*/
    int *v;

    scanf("%d",&a);

    v=(int*)malloc(a*(sizeof(int)));

    for(i=0;i<a;i++){
        scanf("%d",&v[i]);
    }

    for(i=0;i<a;i++){
        if(v[i]%2==0){
            par++;
            ppar=i+1;
        }
        else{
            impar++;
            pimpar=i+1;
        }
    }
    if(par==1){
        printf("%d",ppar);
    }
    else
        printf("%d",pimpar);

    free(v);
return 0;
}


#include<stdio.h>
int main()
{
	int n,a[100],i,odd=0,even=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0)
			even++;
		else
			odd++;
	}
	printf("%d %d ",even,odd);
	if(even>odd)
	{
		for(i=1;i<=n;i++)
		{
			if(a[i]%2!=0)
			{
				printf("%d",i);
				return 0;
			}
		}
	}
	else
	{
		for(i=1;i<=n;i++)
		{
			if(a[i]%2==0)
			{
				printf("%d",i);
				return 0;
			}
		}
	}
}


#include<stdio.h>
int main()
{
	int n,a[100],i;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0)
			even++;
		else
			odd++;
	}
	if(even>odd)
		for(i=0;i<n;i++)
			if(a[i]%2!=0)
				printf("%d",i);
	else
		for(i=0;i<n;i++)
			if(a[i]%2==0)
				printf("%d",i);
}


#include<stdio.h>
int main()
{
	int n,a[100],i,odd=0,even=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0)
			even++;
		else
			odd++;
	}
	if(even>odd)
		for(i=0;i<n;i++)
			if(a[i]%2!=0)
				printf("%d",i);
	else
		for(i=0;i<n;i++)
			if(a[i]%2==0)
				printf("%d",i);
}


#include<stdio.h>
int main()
{
	int n,a[100],i,odd=0,even=0;
	scanf("%d",&n);
	for(i=1;i<n;i++)
	{
		scanf("%d",&a[i]);
		if(a[i]%2==0)
			even++;
		else
			odd++;
	}
	if(even>odd)
		for(i=1;i<n;i++)
			if(a[i]%2!=0)
			{
				printf("%d",i);
				return 0;
			}
	else
		for(i=1;i<n;i++)
			if(a[i]%2==0)
			{
				printf("%d",i);
				return 0;
			}
}


#include<stdio.h>
int main()
{
    int n,i,ara[n],count1=0,count2=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
    if(ara[i]%2==0){
        count1++;
        if(count1>3){
            break;
        }
    }
    else{
        count2++;
        if(count2>3){
            break;
        }
    }
    }
    for(i=0;i<n;i++){
        if(count1>count2){
            if(ara[i]%2!=0){
                printf("%d",i+1);
                break;
            }
        }
        else{
            if(ara[i]%2==0){
                printf("%d",i+1);
                break;
            }
        }
    }
}


#include<stdio.h>
int main()
{
    int n,i,a,count1=0,count2=0,x,y;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%d",&a);
        if(a%2==0)
        {
            count1++;
            x=i;
        }
        else
        {
            count2++;
            y=i;
        }
    }
    if(count1==1)
    {
       printf("%d",x);
    }
    else
    {
        printf("%d",y);
    }
}


#include<stdio.h>
int main()
{
    int n,i,ara[n],count1=0,count2=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
        if(ara[i]%2==0){
           count1++;
        }
        else{
            count2++;
        }
    }
        if(count1==1){
            for(i=0;i<n;i++){
                if(ara[i]%2==0){
                    printf("%d",i+1);
                    break;
                }
                else{
                    continue;
                }
            }
        }
        else if(count2==1){
            for(i=0;i<n;i++){
                if(ara[i]%2!=0){
                    printf("%d",i+1);
                    break;
                }
                else{
                    continue;
                }
            }
        }
}


#include<stdio.h>
int main()
{
    int n,i,ara[n],count1=0,count2=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
        if(ara[i]%2==0){
           count1++;
        }
        else{
            count2++;
        }
    }
        if(count1==1){
            for(i=0;i<n;i++){
                if(ara[i]%2==0){
                    printf("%d",i+1);
                    break;
                }
                else{
                    continue;
                }
            }
        }
        else if(count2==1){
            for(i=0;i<n;i++){
                if(ara[i]%2!=0){
                    printf("%d",i+1);
                    break;
                }
                else{
                    continue;
                }
            }
        }

}


#include<stdio.h>
int main()
{
    int n,i,ara[n],count1=0,count2=0;
    scanf("%d",&n);
    for(i=0;i<n;i++){
        scanf("%d",&ara[i]);
    }
    for(i=0;i<2;i++){
        if(ara[i]%2==0){
           count1++;
        }
        else{
            count2++;
        }
    }
        if(count1>count2){
            for(i=0;i<n;i++){
                if(ara[i]%2!=0){
                    printf("%d",i+1);
                    break;
                }
            }
        }
        else{
            for(i=0;i<n;i++){
                if(ara[i]%2==0){
                    printf("%d",i+1);
                    break;
                }
            }
        }
}


#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{  int a[101];
    int n,i;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d ",&a[i]);

    }

    for(i=0;i<n;i++)
    {
        if(a[i]%2!=0)
            printf("%d",a[i]);
    }

}


#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{  int a[101];
    int n,i;
    char b;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);

    }

    for(i=0;i<n;i++)
    {
        if((a[i]%2)!=0)
            printf("%d",a[i]);
    }

}


#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{
    int i,j,n,even,odd;
    even=0;
    odd=0;
    int a[101];
    scanf("%d",&n);
    for(i=0; i<n; i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
            even++;
        else
            odd++;
    }

    if(even>odd)
    {
        for(i=0; i<n; i++)
        {
            if((a[i]%2)!=0)
            {
                printf("%d",i+1);
                break;
            }
        }
    }
    else
        for(i=0; i<n; i++)
        {
            if((a[i]%2)==0)
            {
                printf("%d",i+1);
                break;
            }
        }

}


#include<stdio.h>
#include<string.h>
#include<ctype.h>

int main()
{   int i,j,n;
    int a[101];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(i=0;i<n;i++)
    {
        if(a[i]%2!=0)
        {
            printf("%d",i+1);
            break;
        }
    }

}


#include<stdio.h>
int main()
{
    int b[100], i, n, value;

   printf("Enter number of elements in array\n");
   scanf("%d", &n);

   printf("Enter elements\n");

   for (i = 0; i < n; i++)
      scanf("%d", &b[i]);

   for (i = 0; i < n; i++)
      printf("\n%d", b[i]);
printf("answer:");
    if (b[0]%2==b[1]%2)
    {
        for(i=0;i<n;i++)
    {
        if(b[i]%2!=b[0]%2)
        {
            printf("%d", i+1);
            break;
        }
    }

    }
    else
    {
        if(b[0]%2==b[2]%2)
        {
            printf("2");
        }
        else printf("1");
    }
}


#include <stdio.h>
#include <stdlib.h>
// prueba de escritorio//

int main(){
    int n; scanf("%d", &n);
    int k;
    int temporal[3] = {0};
    for( k = 0; k < 3; k++){
         scanf("%d", temporal + k );
         temporal[k] %= 2;
    }

    int objetivo = 0, indice= 0;
    int hecho = 0;
    if(temporal[0] == temporal[1]){
        objetivo = 1 - temporal[0];
        if(temporal[2] == objetivo){
                       indice = 2; hecho = 1;
        }
    }
    else{
        hecho = 1;
        if(temporal[2] == temporal[0]){
                       indice = 1;
        }
        else{indice = 0;
        }
    }

    int actual = 0;
    for( k = 3; k < n && !hecho ; k++){
        scanf("%d", &actual);
        if(actual % 2 == objetivo){
                  indice = k;
                  break;
                  }
    }

    printf("%d\n", indice+ 1);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
// prueba de escritorio//

int main(){
    int n; scanf("%d", &n);
    int k;
    int temporal[3] = {0};
    for( k = 0; k < 3; k++){scanf("%d", temporal + k );temporal[k] %= 2;}

    int objetivo = 0, indice= 0;
    int hecho = 0;
    if(temporal[0] == temporal[1]){
        objetivo = 1 - temporal[0];
        if(temporal[2] == objetivo){indice = 2; hecho = 1;}
    }
    else{
        hecho = 1;
        if(temporal[2] == temporal[0]){indice = 1;}
        else{indice = 0;}
    }

    int actual = 0;
    for( k = 3; k < n && !hecho ; k++){
        scanf("%d", &actual);
        if(actual % 2 == objetivo){indice = k; break;}
    }

    printf("%d\n", indice+ 1);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(){
    int n,k;
    scanf("%d", &n);

    int temporal[3] = {0};
    for( k = 0; k < 3; k++){
         scanf("%d", temporal + k );
         temporal[k] %= 2;

         }

    int objetivo = 0, indice = 0;
    int concluido = 0;
    if(temporal[0] == temporal[1]){
        objetivo = 1 - temporal[0];
        if(temporal[2] == objetivo){
                   indice = 2;
                   concluido= 1;
        }
    }
    else{
        concluido = 1;
        if(temporal[2] == temporal[0]){
                   indice = 1;
                   }
        else{
             indice = 0;
             }
    }

    int actual = 0;
    for( k = 3; k < n && !concluido; k++){
        scanf("%d", &actual);
        if(actual % 2 == objetivo){
                   indice = k;
                   break;
                   }
    }

    printf("%d\n", indice + 1);
    system("pause");
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main(){
    int n; scanf("%d", &n);
    int k;
    int temp[3] = {0};
    for( k = 0; k < 3; k++){scanf("%d", temp + k );temp[k] %= 2;}

    int objetivo = 0, indice= 0;
    int done = 0;
    if(temp[0] == temp[1]){
        objetivo = 1 - temp[0];
        if(temp[2] == objetivo){indice = 2; done = 1;}
    }
    else{
        done = 1;
        if(temp[2] == temp[0]){indice = 1;}
        else{indice = 0;}
    }

    int current = 0;
    for( k = 3; k < n && !done ; k++){
        scanf("%d", &current);
        if(current % 2 == objetivo){indice = k; break;}
    }

    printf("%d\n", indice+ 1);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>
// prueba de escritorio//

int main(){
    int n; scanf("%d", &n);
    int k;
    int temp[3] = {0};
    for( k = 0; k < 3; k++){scanf("%d", temp + k );temp[k] %= 2;}

    int objetivo = 0, indice= 0;
    int done = 0;
    if(temp[0] == temp[1]){
        objetivo = 1 - temp[0];
        if(temp[2] == objetivo){indice = 2; done = 1;}
    }
    else{
        done = 1;
        if(temp[2] == temp[0]){indice = 1;}
        else{indice = 0;}
    }

    int current = 0;
    for( k = 3; k < n && !done ; k++){
        scanf("%d", &current);
        if(current % 2 == objetivo){indice = k; break;}
    }

    printf("%d\n", indice+ 1);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,cnt=0,dew=0,a=0,b=0;
    int num[105];
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%d",&num[i]);
        if(num[i]%2==0){dew++; if(dew==1)a=i;}
        else {cnt++; if(cnt==1)b=i;}

    }
    if(cnt>dew) printf("%d",a+1);
    else printf("%d",b+1);

    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,cnt=0,dew=0;
    int num[105];
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&num[i]);
    for(i=n-1;i>0;i--) num[i]-=num[i-1];
    for(i=2;i<n;i++)
    {
        if(num[i]!=num[i-1])
        {
            cnt++;
            dew=i;
        }
    }
    if(cnt==1&&dew==2) printf("1");
    else if(cnt==1&&dew==n-1) printf("%d",n);
    else if(cnt==2) printf("%d",dew-1);
    else printf("%d",dew-1);
    //printf("\n");
    //for(i=1;i<n;i++) printf("%d ",num[i]);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,cnt=0,dew=0;
    int num[105];
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&num[i]);
    for(i=n-1;i>0;i--) num[i]-=num[i-1];
    if(n==3)
    {
        if(num[1]!=0&&num[2]!=0) printf("%d",n);
        else if(num[1]==0) printf("3");
        else if(num[2]==0)printf("1");
        else printf("2");
        exit(0);
    }
    for(i=2;i<n;i++)
    {
        if(num[i]!=num[i-1])
        {
            cnt++;
            dew=i;
        }
    }
    if(cnt==1&&dew==2) printf("1");
    else if(cnt==1&&dew==n-1) printf("%d",n);
    else if(cnt==2) printf("%d",dew-1);
    else printf("%d",dew-1);
    //printf("\n");
    //for(i=1;i<n;i++) printf("%d ",num[i]);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,cnt=0,dew=0;
    int num[105];
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&num[i]);
    for(i=n-1;i>0;i--) num[i]-=num[i-1];
    if(n==3)
    {
        if(num[1]!=0&&num[2]!=0&&num[1]*(-1)!=num[2]) printf("%d",n);
        else if(num[1]==0) printf("3");
        else if(num[2]==0)printf("1");
        else printf("2");
        exit(0);
    }
    for(i=2;i<n;i++)
    {
        if(num[i]!=num[i-1])
        {
            cnt++;
            dew=i;
        }
    }
    if(cnt==1&&dew==2) printf("1");
    else if(cnt==1&&dew==n-1) printf("%d",n);
    else if(cnt==2) printf("%d",dew-1);
    else printf("%d",dew-1);
    //printf("\n");
    //for(i=1;i<n;i++) printf("%d ",num[i]);
    return 0;
}


#include <stdio.h>
#include <stdlib.h>

int main()
{
    int n,i,cnt=0,dew=0;
    int num[105];
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&num[i]);
    for(i=n-1;i>0;i--) num[i]-=num[i-1];
    if(n==3)
    {
        if(num[1]==0) printf("3");
        else if(num[2]==0)printf("1");
        else printf("2");
        exit(0);
    }
    for(i=2;i<n;i++)
    {
        if(num[i]!=num[i-1])
        {
            cnt++;
            dew=i;
        }
    }
    if(cnt==1&&dew==2) printf("1");
    else if(cnt==1&&dew==n-1) printf("%d",n);
    else if(cnt==2) printf("%d",dew-1);
    else printf("%d",dew-1);
    //printf("\n");
    //for(i=1;i<n;i++) printf("%d ",num[i]);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,index=0,i,a[99],temp1,temp2;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
            {
                temp1=i+1;

            }
        else
            {
                temp2=i+1;
            }

    }
        printf("%d",temp2);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,i,a[99],temp1,temp2,x,y;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
            {
                x++;
                temp1=i+1;

            }
        if (a[i]%2!=0)
            {   y++;
                temp2=i+1;
            }

    }
        if(x>y)
            printf("%d",temp2);
        else
            printf("%d",temp1);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,index=0,i,a[99],temp1,temp2,x,y;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
            {
                x++;
                temp1=i+1;

            }
        else
            {   y++;
                temp2=i+1;
            }

    }
        if(x<y)
            printf("%d",temp1);
        else
            printf("%d",temp2);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,index=0,i,a[99],temp1,temp2,x,y;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
            {
                x++;
                temp1=i+1;

            }
        else
            {   y++;
                temp2=i+1;
            }

    }
        if(x>y)
            printf("%d",temp1);
        else
            printf("%d",temp2);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,index=0,i,a[99],temp1,temp2,x,y;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
            {
                x++;
                temp1=i+1;
                //continue;

            }
        else
            {   y++;
                temp2=i+1;
            }

    }
        if(x<y)
            printf("%d",temp1);
        else
            printf("%d",temp2);
    return 0;
}


#include <stdio.h>
int main()
{
    int n,index=0,i,a[99],j=0,k=0;
    scanf("%d",&n);
    for(i=0;i<=n-1;i++)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
            {
                j++;

            }
        else
            {
                j++;
                continue;

            }

    }
    printf("%d",j);
    return 0;
}


import java.util.*;
public class Main {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int arr[] = new int[n];
int b=0;
int c=0;
for(int i = 0; i<a; i++)
{
arr[i] = sc.nextInt();
}
for(int i = 0; i<a; i++)
{
if(arr[i]%2==0)
{
b=b+1;
}
else
{
c=c+1;
}
}
if(b>0) System.out.println(b);
else System.out.println(c);
 }
 }


import java.util.*;
public class Main {
public static void main(String args[]){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int arr[] = new int[a];
int b=0;
int c=0;
for(int i = 0; i<a; i++)
{
arr[i] = sc.nextInt();
}
for(int i = 0; i<a; i++)
{
if(arr[i]%2==0)
{
b=b+1;
}
else
{
c=c+1;
}
}
if(b>o) System.out.println(b);
else System.out.println(c);
 }
 }


#include<bits/stdc++.h>

using namespace std;

long long dat[400010];
int k[100005];
int b[100005];
int c[100005];
int t[100005];
int a[100005];
long long add[100005];
const long long inf=1e17;

void build(int i,int k,int l,int r,int data){
    add[k]=inf;
    if(r-l==1){
        if(l==i) dat[k]=data;
        return;
    }
    int mid=(l+r)/2;
    if(i<mid)
        build(i,2*k+1,l,mid,data);
    else build(i,2*k+2,mid,r,data);
    dat[k]=dat[2*k+1]+dat[2*k+2];
}

void pushdown(int k,int l,int r){
    if(add[k]!=inf){
        add[2*k+1]=add[k];
        add[2*k+2]=add[k];
        int mid=(l+r)/2;
        dat[2*k+1]+=add[k]*(mid-l);
        dat[2*k+2]+=add[k]*(r-mid);
        add[k]=inf;
    }
}

void update(int ql,int qr,int ad,int k,int l,int r){
    if(ql>=r||qr<=l) return;
    if(ql<=l&&qr>=r) {
        add[k]=ad;
        dat[k]+=ad*(r-l);
        return;
    }
    pushdown(k,l,r);
    int mid=(l+r)/2;
    update(ql,qr,ad,2*k+1,l,mid);
    update(ql,qr,ad,2*k+2,mid,r);
    dat[k]=dat[2*k+1]+dat[2*k+2];
}

long long query(int ql,int qr,int k,int l,int r){
    if(ql>=r||qr<=l) return 0;
    if(ql<=l&&qr>=r) return dat[k];
    pushdown(k,l,r);
    int mid=(l+r)/2;
    if(ql>=mid)  return query(ql,qr,k*2+2,mid,r);
    else if(qr<=mid)  return query(ql,qr,k*2+1,l,mid);
    else return query(ql,qr,k*2+1,l,mid)+query(ql,qr,k*2+2,mid,r);
}

char read_char(){
    char ch;
    while((ch=getchar())!='s'&&ch!='+');
    return ch;
}

int main(){
    int n;
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%d",&a[i]);
    }
    b[1]=a[1];
    for(int i=1;i<n;i++){
        scanf("%d",&k[i]);
        c[i+1]=c[i]+k[i];
        t[i+1]=c[i+1]+t[i];
        b[i+1]=a[i+1]-c[i+1];
        build(i,0,1,n+1,b[i]);
    }
    build(n,0,1,n+1,b[n]);

    int q;
    scanf("%d",&q);
    while(q--){
        char ch=read_char();
        int t1,t2;
        scanf("%d%d",&t1,&t2);
        if(ch=='+'){
            int l=t1,r=n+1;
            int sum=query(l,l+1,0,1,n+1)+t2;
            while(l<r){
                int mid=(l+r)/2;
                if(sum>query(mid,mid+1,0,1,n+1)){
                    l=mid+1;
                }else{
                    r=mid;
                }
            }
            update(t1,r,t2,0,1,n+1);
        }else{

            long long ans=query(t1,t2+1,0,1,n+1);

            printf("%I64d\n",ans+t[t2]-t[t1-1]);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls(x) x<<1
#define rs(x) x<<1|1
const int N = 100009;
ll n,m,a[N],k[N];
struct pp{ll sum,val,siz,flag;}t[N*4];
void pushdown(ll c){
    if(!t[c].flag) return ;
    t[c].flag=0,t[ls(c)].flag=1,t[rs(c)].flag=1;
    t[ls(c)].val=t[c].val,t[ls(c)].sum=t[ls(c)].siz*t[ls(c)].val;
    t[rs(c)].val=t[c].val,t[rs(c)].sum=t[rs(c)].siz*t[rs(c)].val;
    return ;
}
void update(ll c){
    t[c].sum=t[ls(c)].sum+t[rs(c)].sum;
    t[c].siz=t[ls(c)].siz+t[rs(c)].siz;
}
void build(ll c,ll l,ll r){
    if(l==r){t[c].sum=a[l]-k[l-1],t[c].siz=1,t[c].flag=0;return ;}
    ll mid=(l+r)>>1;
    build(ls(c),1,mid);build(rs(c),mid+1,r);
    update(c);return ;
}
ll query(ll c,ll l,ll r,ll x){
    if(l==r) return t[c].sum;
    pushdown(c);
    ll mid=(l+r)>>1,ans;
    if(x<=mid) ans=query(ls(c),l,mid,x);
    if(x>mid) ans=query(rs(c),mid+1,r,x);
    update(c);
    return ans;
}
void modify(ll c,ll l,ll r,ll x,ll y,ll p){
    if(x<=l&&r<=y){
        t[c].flag=1,t[c].val=p,t[c].sum=t[c].siz*p;
        return ;
    }
    pushdown(c);
    ll mid=(l+r)>>1;
    if(x<=mid) modify(ls(c),l,mid,x,y,p);
    if(y>mid) modify(rs(c),mid+1,r,x,y,p);
    update(c);
    return ;
}
ll sum(ll c,ll l,ll r,ll x,ll y){
    if(x<=l&&r<=y) return t[c].sum;
    pushdown(c);
    ll mid=(l+r)>>1,ans=0;
    if(x<=mid) ans+=sum(ls(c),l,mid,x,y);
    if(y>mid) ans+=sum(rs(c),mid+1,r,x,y);
    update(c);
    return ans;
}
int main(){
    scanf("%lld",&n);k[0]=0;
    for(ll i=1ll;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=1ll;i<n;i++) scanf("%lld",&k[i]);
    for(ll i=1ll;i<n;i++) k[i]=k[i-1]+k[i];
    build(1,1,n);
    for(ll i=1ll;i<n;i++) k[i]=k[i-1]+k[i];
    scanf("%lld",&m);
    for(ll i=1ll;i<=m;i++){
        char c;ll x,y;
        cin>>c>>x>>y;
        if(c=='+') {
            ll l=1,r=n,p=query(1,1,n,x)+y,pos=x;
            while(l<=r){
                ll mid=(l+r)>>1;
                if(query(1,1,n,mid)<=p) l=mid+1,pos=mid;
                else r=mid-1;
            }
            modify(1,1,n,x,pos,p);
        }
        if(c=='s') {
            printf("%lld\n",sum(1,1,n,x,y)+k[y-1]-k[x-2]);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls(x) x<<1
#define rs(x) x<<1|1
const int N = 100009;
ll n,m,a[N],k[N];
struct pp{ll sum,val,siz,flag;}t[N*4];
void pushdown(ll c){
    if(!t[c].flag) return ;
    t[c].flag=0,t[ls(c)].flag=1,t[rs(c)].flag=1;
    t[ls(c)].val=t[c].val,t[ls(c)].sum=t[ls(c)].siz*t[ls(c)].val;
    t[rs(c)].val=t[c].val,t[rs(c)].sum=t[rs(c)].siz*t[rs(c)].val;
    return ;
}
void update(ll c){
    t[c].sum=t[ls(c)].sum+t[rs(c)].sum;
    t[c].siz=t[ls(c)].siz+t[rs(c)].siz;
}
void build(ll c,ll l,ll r){
    if(l==r){t[c].sum=a[l]-k[l-1],t[c].siz=1,t[c].flag=0;return ;}
    ll mid=(l+r)>>1;
    build(ls(c),1,mid);build(rs(c),mid+1,r);
    update(c);return ;
}
ll query(ll c,ll l,ll r,ll x){
    if(l==r) return t[c].sum;
    pushdown(c);
    ll mid=(l+r)>>1,ans;
    if(x<=mid) ans=query(ls(c),l,mid,x);
    if(x>mid) ans=query(rs(c),mid+1,r,x);
    update(c);
    return ans;
}
void modify(ll c,ll l,ll r,ll x,ll y,ll p){
    if(x<=l&&r<=y){
        t[c].flag=1,t[c].val=p,t[c].sum=t[c].siz*p;
        return ;
    }
    pushdown(c);
    ll mid=(l+r)>>1;
    if(x<=mid) modify(ls(c),l,mid,x,y,p);
    if(y>mid) modify(rs(c),mid+1,r,x,y,p);
    update(c);
    return ;
}
ll sum(ll c,ll l,ll r,ll x,ll y){
    if(x<=l&&r<=y) return t[c].sum;
    pushdown(c);
    ll mid=(l+r)>>1,ans=0;
    if(x<=mid) ans+=sum(ls(c),l,mid,x,y);
    if(y>mid) ans+=sum(rs(c),mid+1,r,x,y);
    update(c);
    return ans;
}
int main(){
    scanf("%lld",&n);k[0]=0;
    for(ll i=1ll;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=1ll;i<n;i++) scanf("%lld",&k[i]);
    for(ll i=1ll;i<n;i++) k[i]=k[i-1]+k[i];
    build(1,1,n);
    for(ll i=1ll;i<n;i++) k[i]=k[i-1]+k[i];
    scanf("%lld",&m);
    for(ll i=1ll;i<=m;i++){
        char c;ll x,y;
        cin>>c>>x>>y;
        if(c=='+') {
            ll l=1,r=n,p=query(1,1,n,x)+y,pos=x;
            while(l<=r){
                ll mid=(l+r)>>1;
                if(query(1,1,n,mid)<=p) l=mid+1,pos=mid;
                else r=mid-1;
            }
            modify(1,1,n,x,pos,p);
        }
        if(c=='s') {
            printf("%lld\n",sum(1,1,n,x,y)+k[y-1]-k[max(x-2,0ll)]);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls(x) x<<1
#define rs(x) x<<1|1
const int N = 100009;
ll n,m,a[N],k[N];
struct pp{ll sum,val,siz,flag;}t[N*8];
void pushdown(ll c){
    if(!t[c].flag) return ;
    t[c].flag=0,t[ls(c)].flag=1,t[rs(c)].flag=1;
    t[ls(c)].val=t[c].val,t[ls(c)].sum=t[ls(c)].siz*t[ls(c)].val;
    t[rs(c)].val=t[c].val,t[rs(c)].sum=t[rs(c)].siz*t[rs(c)].val;
    return ;
}
void update(ll c){
    t[c].sum=t[ls(c)].sum+t[rs(c)].sum;
    t[c].siz=t[ls(c)].siz+t[rs(c)].siz;
}
void build(ll c,ll l,ll r){
    if(l==r){t[c].sum=a[l]-k[l-1],t[c].siz=1,t[c].flag=0;return ;}
    ll mid=(l+r)>>1;
    build(ls(c),l,mid);build(rs(c),mid+1,r);
    update(c);return ;
}
ll query(ll c,ll l,ll r,ll x){
    if(l==r) return t[c].sum;
    pushdown(c);
    ll mid=(l+r)>>1,ans;
    if(x<=mid) ans=query(ls(c),l,mid,x);
    if(x>mid) ans=query(rs(c),mid+1,r,x);
    update(c);
    return ans;
}
void modify(ll c,ll l,ll r,ll x,ll y,ll p){
    if(x<=l&&r<=y){
        t[c].flag=1,t[c].val=p,t[c].sum=t[c].siz*p;
        return ;
    }
    pushdown(c);
    ll mid=(l+r)>>1;
    if(x<=mid) modify(ls(c),l,mid,x,y,p);
    if(y>mid) modify(rs(c),mid+1,r,x,y,p);
    update(c);
    return ;
}
ll sum(ll c,ll l,ll r,ll x,ll y){
    if(x<=l&&r<=y) return t[c].sum;
    pushdown(c);
    ll mid=(l+r)>>1,ans=0;
    if(x<=mid) ans+=sum(ls(c),l,mid,x,y);
    if(y>mid) ans+=sum(rs(c),mid+1,r,x,y);
    update(c);
    return ans;
}
int main(){
    scanf("%lld",&n);k[0]=0;
    for(ll i=1ll;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=1ll;i<n;i++) scanf("%lld",&k[i]);
    for(ll i=1ll;i<n;i++) k[i]=k[i-1]+k[i];
    build(1,1,n);
    for(ll i=1ll;i<n;i++) k[i]=k[i-1]+k[i];
    scanf("%lld",&m);
    for(ll i=1ll;i<=m;i++){
        char c;ll x,y;
        cin>>c>>x>>y;
        if(c=='+') {
            ll l=1,r=n,p=query(1,1,n,x)+y,pos=x;
            while(l<=r){
                ll mid=(l+r)>>1;
                if(query(1,1,n,mid)<=p) l=mid+1,pos=mid;
                else r=mid-1;
            }
            modify(1,1,n,x,pos,p);
        }
        if(c=='s') {
            printf("%lld\n",sum(1,1,n,x,y)+k[y-1]-k[max(x-2,0ll)]);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ls(x) x<<1
#define rs(x) x<<1|1
const int N = 100009;
ll n,m,a[N],k[N];
struct pp{ll sum,val,siz,flag;}t[N*4];
void pushdown(ll c){
    if(!t[c].flag) return ;
    t[c].flag=0,t[ls(c)].flag=1,t[rs(c)].flag=1;
    t[ls(c)].val=t[c].val,t[ls(c)].sum=t[ls(c)].siz*t[ls(c)].val;
    t[rs(c)].val=t[c].val,t[rs(c)].sum=t[rs(c)].siz*t[rs(c)].val;
    return ;
}
void update(ll c){
    t[c].sum=t[ls(c)].sum+t[rs(c)].sum;
    t[c].siz=t[ls(c)].siz+t[rs(c)].siz;
}
void build(ll c,ll l,ll r){
    if(l==r){t[c].sum=a[l]-k[l-1],t[c].siz=1,t[c].flag=0;return ;}
    ll mid=(l+r)>>1;
    build(ls(c),1,mid);build(rs(c),mid+1,r);
    update(c);return ;
}
ll query(ll c,ll l,ll r,ll x){
    if(l==r) return t[c].sum;
    pushdown(c);
    ll mid=(l+r)>>1,ans;
    if(x<=mid) ans=query(ls(c),l,mid,x);
    if(x>mid) ans=query(rs(c),mid+1,r,x);
    update(c);
    return ans;
}
void modify(ll c,ll l,ll r,ll x,ll y,ll p){
    if(x<=l&&r<=y){
        t[c].flag=1,t[c].val=p,t[c].sum=t[c].siz*p;
        return ;
    }
    pushdown(c);
    ll mid=(l+r)>>1;
    if(x<=mid) modify(ls(c),l,mid,x,y,p);
    if(y>mid) modify(rs(c),mid+1,r,x,y,p);
    update(c);
    return ;
}
ll sum(ll c,ll l,ll r,ll x,ll y){
    if(x<=l&&r<=y) return t[c].sum;
    pushdown(c);
    ll mid=(l+r)>>1,ans=0;
    if(x<=mid) ans+=sum(ls(c),l,mid,x,y);
    if(y>mid) ans+=sum(rs(c),mid+1,r,x,y);
    update(c);
    return ans;
}
int main(){
    scanf("%lld",&n);k[0]=0;
    for(ll i=1ll;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=1ll;i<n;i++) scanf("%lld",&k[i]);
    build(1,1,n);
    for(ll i=1ll;i<n;i++) k[i]=k[i-1]+k[i];
    scanf("%lld",&m);
    for(ll i=1ll;i<=m;i++){
        char c;ll x,y;
        cin>>c>>x>>y;
        if(c=='+') {
            ll l=1,r=n,p=query(1,1,n,x)+y,pos=x;
            while(l<=r){
                ll mid=(l+r)>>1;
                if(query(1,1,n,mid)<=p) l=mid+1,pos=mid;
                else r=mid-1;
            }
            modify(1,1,n,x,pos,p);
        }
        if(c=='s') {
            printf("%lld\n",sum(1,1,n,x,y)+k[y-1]-k[x-2]);
        }
    }
    return 0;
}


#include<bits/stdc++.h>
#define lc rt<<1
#define rc rt<<1|1
using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 2e5+5;
	int n,qt;
	int a[maxn],k[maxn];
	long long sum[maxn<<2],tag[maxn<<2],sum1[maxn],sum2[maxn];
	char ch[5];

	void pushup(int rt)
	{
		sum[rt]=sum[lc]+sum[rc];
	}

	void pushdown(int rt,int l,int r)
	{
		if(tag[rt])
		{
			int mid=(l+r)>>1;
			sum[lc]=(mid-l+1)*tag[rt];
			sum[rc]=(r-mid)*tag[rt];
			tag[lc]=tag[rt];
			tag[rc]=tag[rt];
			tag[rt]=0;
		}
	}

	void build(int rt,int l,int r)
	{
		tag[rt]=0;
		if(l==r)
		{
			sum[rt]=a[l]-sum1[l-1];
			return ;
		}
		int mid=(l+r)>>1;
		build(lc,l,mid);
		build(rc,mid+1,r);
		pushup(rt);
	}

	void update(int rt,int l,int r,int ql,int qr,long long x)
	{
		if(ql<=l&&r<=qr)
		{
			tag[rt]=x;
			sum[rt]=(r-l+1)*x;
			return ;
		}
		pushdown(rt,l,r);
		int mid=(l+r)>>1;
		if(ql<=mid) update(lc,l,mid,ql,qr,x);
		if(qr>mid) update(rc,mid+1,r,ql,qr,x);
		pushup(rt);
	}

	long long query(int rt,int l,int r,int ql,int qr)
	{
		if(ql<=l&&r<=qr) return sum[rt];
		pushdown(rt,l,r);
		int mid=(l+r)>>1;
		long long res=0;
		if(ql<=mid) res+=query(lc,l,mid,ql,qr);
		if(qr>mid) res+=query(rc,mid+1,r,ql,qr);
		return res;
	}

	long long get_pre(int x)
	{
		return x<0?0:sum2[x];
	}

	void work()
	{
		int x,y;
		n=read();
		for(int i=1;i<=n;i++) a[i]=read();
		for(int i=1;i<=n-1;i++) k[i]=read(),sum1[i]=sum1[i-1]+k[i],sum2[i]=sum2[i-1]+sum1[i];
		build(1,1,n);
		qt=read();
		for(int i=1;i<=qt;i++)
		{
			scanf("%s",ch);x=read();y=read();
			if(ch[0]=='+')
			{
				long long tmp=query(1,1,n,x,x);
				tmp+=y;
				int r=n,mid,l=x;
				while(l<=r)
				{
					mid=(l+r)>>1;
					long long k=query(1,1,n,mid,mid);
					if(k==tmp) break;
					else if(k<tmp) l=mid+1;
					else r=mid-1;
				}
				update(1,1,n,x,mid,tmp);
			}
			else printf("%lld\n",query(1,1,n,x,y)+get_pre(y-1)-get_pre(x-2));
		}

	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>
#define lc rt<<1
#define rc rt<<1|1
using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 2e5+5;
	const int inf = 1e9+7;
	int n,qt;
	int a[maxn],k[maxn];
	long long sum[maxn<<2],tag[maxn<<2],sum1[maxn],sum2[maxn];
	char ch[5];

	void pushup(int rt)
	{
		sum[rt]=sum[lc]+sum[rc];
	}

	void pushdown(int rt,int l,int r)
	{
		if(tag[rt]!=-inf)
		{
			int mid=(l+r)>>1;
			sum[lc]=(mid-l+1)*tag[rt];
			sum[rc]=(r-mid)*tag[rt];
			tag[lc]=tag[rt];
			tag[rc]=tag[rt];
			tag[rt]=-inf;
		}
	}

	void build(int rt,int l,int r)
	{
		tag[rt]=-inf;
		if(l==r)
		{
			sum[rt]=a[l]-sum1[l-1];
			return ;
		}
		int mid=(l+r)>>1;
		build(lc,l,mid);
		build(rc,mid+1,r);
		pushup(rt);
	}

	void update(int rt,int l,int r,int ql,int qr,long long x)
	{
		if(ql<=l&&r<=qr)
		{
			tag[rt]=x;
			sum[rt]=(r-l+1)*x;
			return ;
		}
		pushdown(rt,l,r);
		int mid=(l+r)>>1;
		if(ql<=mid) update(lc,l,mid,ql,qr,x);
		if(qr>mid) update(rc,mid+1,r,ql,qr,x);
		pushup(rt);
	}

	long long query(int rt,int l,int r,int ql,int qr)
	{
		if(ql<=l&&r<=qr) return sum[rt];
		pushdown(rt,l,r);
		int mid=(l+r)>>1;
		long long res=0;
		if(ql<=mid) res+=query(lc,l,mid,ql,qr);
		if(qr>mid) res+=query(rc,mid+1,r,ql,qr);
		return res;
	}

	long long get_pre(int x)
	{
		return x<0?0:sum2[x];
	}

	void work()
	{
		int x,y;
		n=read();
		for(int i=1;i<=n;i++) a[i]=read();
		for(int i=1;i<=n-1;i++) k[i]=read(),sum1[i]=sum1[i-1]+k[i],sum2[i]=sum2[i-1]+sum1[i];
		build(1,1,n);
		qt=read();
		for(int i=1;i<=qt;i++)
		{
			scanf("%s",ch);x=read();y=read();
			if(ch[0]=='+')
			{
				long long tmp=query(1,1,n,x,x)+y;
				int r=n,l=x,mid=(l+r)>>1;
				while(l<=r)
				{
					long long k=query(1,1,n,mid,mid);
					if(k==tmp) break;
					else if(k>tmp) r=mid-1;
					else l=mid+1;
					mid=(l+r)>>1;
				}
				update(1,1,n,x,mid,tmp);
			}
			else printf("%lld\n",query(1,1,n,x,y)+get_pre(y-1)-get_pre(x-2));
		}

	}

}

int main()
{
	zzc::work();
	return 0;
}


#include<bits/stdc++.h>
#define lc rt<<1
#define rc rt<<1|1
using namespace std;

namespace zzc
{
	inline int read()
	{
		int x=0,f=1;char ch=getchar();
		while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
		while (isdigit(ch)){x=x*10+ch-48;ch=getchar();}
		return x*f;
	}

	const int maxn = 2e5+5;
	const int inf = 1e9+7;
	int n,qt;
	int a[maxn],k[maxn];
	long long sum[maxn<<2],tag[maxn<<2],sum1[maxn],sum2[maxn];
	char ch[5];

	void pushup(int rt)
	{
		sum[rt]=sum[lc]+sum[rc];
	}

	void pushdown(int rt,int l,int r)
	{
		if(tag[rt]!=-inf)
		{
			int mid=(l+r)>>1;
			sum[lc]=(mid-l+1)*tag[rt];
			sum[rc]=(r-mid)*tag[rt];
			tag[lc]=tag[rt];
			tag[rc]=tag[rt];
			tag[rt]=-inf;
		}
	}

	void build(int rt,int l,int r)
	{
		tag[rt]=-inf;
		if(l==r)
		{
			sum[rt]=a[l]-sum1[l-1];
			return ;
		}
		int mid=(l+r)>>1;
		build(lc,l,mid);
		build(rc,mid+1,r);
		pushup(rt);
	}

	void update(int rt,int l,int r,int ql,int qr,long long x)
	{
		if(ql<=l&&r<=qr)
		{
			tag[rt]=x;
			sum[rt]=(r-l+1)*x;
			return ;
		}
		pushdown(rt,l,r);
		int mid=(l+r)>>1;
		if(ql<=mid) update(lc,l,mid,ql,qr,x);
		if(qr>mid) update(rc,mid+1,r,ql,qr,x);
		pushup(rt);
	}

	long long query(int rt,int l,int r,int ql,int qr)
	{
		if(ql<=l&&r<=qr) return sum[rt];
		pushdown(rt,l,r);
		int mid=(l+r)>>1;
		long long res=0;
		if(ql<=mid) res+=query(lc,l,mid,ql,qr);
		if(qr>mid) res+=query(rc,mid+1,r,ql,qr);
		return res;
	}

	long long get_pre(int x)
	{
		return x<0?0:sum2[x];
	}

	void work()
	{
		int x,y;
		n=read();
		for(int i=1;i<=n;i++) a[i]=read();
		for(int i=1;i<=n-1;i++) k[i]=read(),sum1[i]=sum1[i-1]+k[i],sum2[i]=sum2[i-1]+sum1[i];
		build(1,1,n);
		qt=read();
		for(int i=1;i<=qt;i++)
		{
			scanf("%s",ch);x=read();y=read();
			if(ch[0]=='+')
			{
				long long tmp=query(1,1,n,x,x);
				tmp+=y;
				int r=n,mid,l=x;
				while(l<=r)
				{
					mid=(l+r)>>1;
					long long k=query(1,1,n,mid,mid);
					if(k==tmp) break;
					else if(k>tmp) r=mid-1;
					else l=mid+1;
				}
				update(1,1,n,x,mid,tmp);
			}
			else printf("%lld\n",query(1,1,n,x,y)+get_pre(y-1)-get_pre(x-2));
		}

	}

}

int main()
{
	zzc::work();
	return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;
const ll inf = 1e17;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
const int MAX_N = 200025;
long long s[MAX_N<<2],k[MAX_N],ks[MAX_N],arr[MAX_N],col[MAX_N<<2];
void up(int rt)
{
    s[rt] = s[rt<<1] + s[rt<<1|1];
}
void build(int rt,int l,int r)
{
    col[rt] = inf;
    if(l==r)
    {
        s[rt] = arr[l] - k [l-1];
        return ;
    }
    int mid = (l+r)>>1;
    build(rt<<1,l,mid);
    build(rt<<1|1,mid+1,r);
    up(rt);
}
void down(int rt,int l,int r)
{
    if(col[rt]!=inf)
    {
        int mid = (l+r)>>1;
        col[rt<<1] = col[rt];
        col[rt<<1|1] = col[rt];
        s[rt<<1] = col[rt]*(mid-l+1);
        s[rt<<1|1] = col[rt]*(r-mid) ;
        col[rt] = inf;
    }
}
void update(int rt,int l,int r,int x,int y,long long v)
{
    if(x<=l&&r<=y)
    {
        col[rt] = v;
        s[rt] = col[rt]*(r-l+1);
        return ;
    }
    int mid = (l+r)>>1;
    down(rt,l,r);
    if(x<=mid) update(rt<<1,l,mid,x,y,v);
    if(mid<y) update(rt<<1|1,mid+1,r,x,y,v);
    up(rt);
}
long long query(int rt,int l,int r,int x,int y)
{
    if(x<=l&&r<=y)
    {
        return s[rt];
    }
    int mid = (l+r)>>1;
    long long res = 0;
    down(rt,l,r);
    if(x<=mid) res+=query(rt<<1,l,mid,x,y);
    if(mid<y) res+=query(rt<<1|1,mid+1,r,x,y);
    return res;
}
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,m,x,y;
    char str[5];
    scanf("%d",&n);
    for(int i = 1;i<=n;++i) scanf("%lld",&arr[i]);
    for(int i = 1;i<n;++i)  scanf("%lld",&k[i]);
    for(int i = 2;i<n;++i) k[i]+=k[i-1];
    for(int i = 1;i<n;++i) ks[i] = ks[i-1] + k[i];
    build(1,1,n);
    scanf("%d",&m);
    while(m--)
    {
        scanf("%s%d%d",str,&x,&y);
        if(str[0]=='s')
        {
            printf("%lld\n",query(1,1,n,x,y)+ks[y-1]-(x>=2?ks[x-2]:0))+0;
        }
        else
        {
            int l = 1,r = n,mid,ans_ = 1;
            long long sum = query(1,1,n,x,x) + y;
            while(l<=r)
            {
                mid = (l+r)>>1;
                if(sum>query(1,1,n,mid,mid))
                {
                    ans_ = mid;
                    l = mid + 1;
                }
                else r = mid - 1;
            }
            update(1,1,n,x,ans_,sum);
        }
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}


#include <cstdio>
#include <cstring>
#include <iostream>
#include <queue>
#include <cmath>
#include <map>
#include <stack>
#include <set>
#include <sstream>
#include <vector>
#include <stdlib.h>
#include <algorithm>
using namespace std;

#define dbg(x) cout<<#x<<" = "<< (x)<< endl
#define dbg2(x1,x2) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<endl
#define dbg3(x1,x2,x3) cout<<#x1<<" = "<<x1<<" "<<#x2<<" = "<<x2<<" "<<#x3<<" = "<<x3<<endl
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))

typedef pair<int,int> pll;
typedef long long ll;
const int _inf = 0xc0c0c0c0;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const ll _INF = 0xc0c0c0c0c0c0c0c0;
const ll mod =  (int)1e9+7;
const ll inf = 1e17;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll ksm(ll a,ll b,ll mod){int ans=1;while(b){if(b&1) ans=(ans*a)%mod;a=(a*a)%mod;b>>=1;}return ans;}
ll inv2(ll a,ll mod){return ksm(a,mod-2,mod);}
const int MAX_N = 200025;
long long s[MAX_N<<2],k[MAX_N],ks[MAX_N],arr[MAX_N],col[MAX_N<<2];
void up(int rt)
{
    s[rt] = s[rt<<1] + s[rt<<1|1];
}
void build(int rt,int l,int r)
{
    col[rt] = 0;
    if(l==r)
    {
        s[rt] = arr[l] - k [l-1];
        return ;
    }
    int mid = (l+r)>>1;
    build(rt<<1,l,mid);
    build(rt<<1|1,mid+1,r);
    up(rt);
}
void down(int rt,int l,int r)
{
    if(col[rt])
    {
        int mid = (l+r)>>1;
        col[rt<<1] = col[rt];
        col[rt<<1|1] = col[rt];
        s[rt<<1] = col[rt]*(mid-l+1);
        s[rt<<1|1] = col[rt]*(r-mid) ;
        col[rt] = 0;
    }
}
void update(int rt,int l,int r,int x,int y,long long v)
{
    if(x<=l&&r<=y)
    {
        col[rt] = v;
        s[rt] = col[rt]*(r-l+1);
        return ;
    }
    int mid = (l+r)>>1;
    down(rt,l,r);
    if(x<=mid) update(rt<<1,l,mid,x,y,v);
    if(mid<y) update(rt<<1|1,mid+1,r,x,y,v);
    up(rt);
}
long long query(int rt,int l,int r,int x,int y)
{
    if(x<=l&&r<=y)
    {
        return s[rt];
    }
    int mid = (l+r)>>1;
    long long res = 0;
    down(rt,l,r);
    if(x<=mid) res+=query(rt<<1,l,mid,x,y);
    if(mid<y) res+=query(rt<<1|1,mid+1,r,x,y);
    return res;
}
int main()
{
    //ios::sync_with_stdio(false);
    //freopen("a.txt","r",stdin);
    //freopen("b.txt","w",stdout);
    int n,m,x,y;
    char str[5];
    scanf("%d",&n);
    for(int i = 1;i<=n;++i) scanf("%lld",&arr[i]);
    for(int i = 1;i<n;++i)  scanf("%lld",&k[i]);
    for(int i = 2;i<n;++i) k[i]+=k[i-1];
    for(int i = 1;i<n;++i) ks[i] = ks[i-1] + k[i];
    build(1,1,n);
    scanf("%d",&m);
    while(m--)
    {
        scanf("%s%d%d",str,&x,&y);
        if(str[0]=='s')
        {
            printf("%lld\n",query(1,1,n,x,y)+ks[y-1]-(x>=2?ks[x-2]:0));
        }
        else
        {
            int l = 1,r = n,mid,ans_ = 1;
            long long sum = query(1,1,n,x,x) + y;
            while(l<=r)
            {
                mid = (l+r)>>1;
                if(sum>query(1,1,n,mid,mid))
                {
                    ans_ = mid;
                    l = mid + 1;
                }
                else r = mid - 1;
            }
            update(1,1,n,x,ans_,sum);
        }
    }
    //fclose(stdin);
    //fclose(stdout);
    //cout << "time: " << (long long)clock() * 1000 / CLOCKS_PER_SEC << " ms" << endl;
    return 0;
}