akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  while(cin>>s){
    string t1,t2,t3,a,b,c;
    int p=0;
    for(int i=0;i<s.size();i++){
      if(s[i]=='+'||s[i]=='=')p++;
      else if(p==0)t1+=s[i];
      else if(p==1)t2+=s[i];
      else t3+=s[i];
    }
    reverse(t1.begin(),t1.end());
    reverse(t2.begin(),t2.end());

    for(int i=0;i<10;i++){
      a=t1;b=t2;c=t3;
      for(int j=0;j<a.size();j++)
        if(a[j]=='X')a[j]=i+'0';
      for(int j=0;j<b.size();j++)
        if(b[j]=='X')b[j]=i+'0';
      for(int j=0;j<t3.size();j++)
        if(c[j]=='X')c[j]=i+'0';
      if(a.size()<b.size())swap(a,b);//cout<<a<<endl<<b<<endl;
      int x,y,z;
      for(int j=0;j<b.size();j++){
        if(j&&z)b[j]++;
        z=0;x=a[j]-'0';y=b[j]-'0';
        x+=y;
        if(x>9)x-=10,z++;
        a[j]=x+'0';
        if(j==b.size()-1&&z){
          if(a.size()==b.size())a+='1';
          else{j++;
            a+=' ';
            while(1){
              if(a[j]==9){
                a[j]='0';
              }
              else{
                if(a[j]==' ')a[j]='1';
                else a[j]++;
                break;
              }
              j++;
            }
          }
        }
      }
      if(a[a.size()-1]==' ')a.erase(a.end()-1);
      //cout<<a<<endl<<c<<endl;
      reverse(a.begin(),a.end());
      if(a==c){
        cout<<i<<endl;
        goto L;
      }
    }
    cout<<"NA"<<endl;L:;
  }
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(x) (x).rbegin(),(x).rend()
#define DEBUG(x)  cout << #x << " = " << (x) << endl;
#define SORT(x) sort(ALL(x));
#define RSORT(x) sort(RALL(x));
#define SUM(x) accumulate(ALL(x),0);
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using tiii = tuple<int, int, int>;
const int INF = 1e+9;
const ll mod = 1000000007;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};
//cout << fixed << setprecision(10);

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int h[100010];
int dp[100010];

int main () {
  int N; cin >> N;
  rep(i,N) cin >> h[i];

  dp[0] = 0;
  for (int n = 1; n < 100000; n++) {
    dp[n] = INF;
    dp[n] = min(dp[n], dp[n-1]+abs(h[n-1]-h[n]));
    if (n > 1) {
      dp[n] = min(dp[n], dp[n-2]+abs(h[n-2]-h[n]));
    }
  }

  cout << dp[N-1] << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main(){
  string s;
  ll k;
  cin >> s >> k;
  
  int i,n;
  for(i=0;i<s.size();i++){
    if(s.at(i)!='1') break;
  }
  
  if(i<k) cout << s.at(i) << endl;
  else cout << 1 << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

vector<vector<int>> G(200100, vector<int>()); 

//UnweightedTree
//argument -> [Vertex_Size, Start_Node]
//return   -> [Furthest_Node, Diameter]
P tree_diameter(int V, int st){
	int t = st;
	int diameter = 0;
	queue<int> Q;
	vector<int> dist(V, inf);
	dist[st] = 0;
	Q.push(st);
	while(!Q.empty()){
		int f = Q.front();
		Q.pop();
		for(auto x:G[f]){
			if(dist[x] == inf){
				dist[x] = dist[f] + 1;
				Q.push(x);
				if(dist[x] > diameter){
					diameter = dist[x];
					t = x;
				}
			}
		}
	}
	return make_pair(t, diameter);
}

int main(){
	int N;
	cin >> N;
	int a,b;
	G.resize(N);
	rep(i,N-1){
		cin >> a >> b;
		--a; --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	P x = tree_diameter(N, 0);
	P y = tree_diameter(N, x.first);
	int furthest_dist = y.second + 1;
	cout << ((furthest_dist % 3 == 2)? "Second" : "First") << endl;
	return 0;
}


Measured memory_bytes: 16436
#include<bits/stdc++.h>
#define ll long long int
#define mod 1000000007

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	int n,w;
	cin>>n>>w;
	
	int wt[n],v[n];
	for(int i=0;i<n;i++) {
		cin>>wt[i]>>v[i];
	}
	
	ll dp[n+1][w+1];
	memset(dp,0,sizeof(dp));
	
	for(int i=1;i<=n;i++) {
		for(int j=1;j<=w;j++) {
			if(wt[i-1]>j) {
				dp[i][j] = dp[i-1][j];
			}
			else {
				dp[i][j] = max(dp[i-1][j],v[i-1]+dp[i-1][j-wt[i-1]]);
			}
		}
	}
	
	cout<<dp[n][w];
	
	return 0;
}


Measured memory_bytes: 82540
c={'N':"152304",'E':"310542",'W':"215043",'S':"402351",'R':"024135",'L':"031425"}
while 1:
 n=int(input())
 if n==0:break
 a=1;s='123456'
 for _ in[0]*n:
  s=[s[int(e)]for e in c[input()[0]]]
  a+=int(s[0])
 print(a)


Measured memory_bytes: 5660
#include<iostream>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;

int main(void){
  int a[3], b[3], c[3][3];
  int x;
  rep(i, 3) rep(j, 3) cin >> c[i][j];
  a[0]=0;
  rep(i, 3) {
    b[i] = c[0][i]-a[0];
    a[i] = c[i][0]-b[0];
  }
  rep(i, 3) rep(j, 3) if(c[i][j]!=a[i]+b[j]){
    cout << "No" << endl;
    return 0;
  }
  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main(){
	string s;
	cin >> s;
	
	if(s[0] == '0' && s[1] == '0'){
		if((s[2] == '0' && s[3] >= '1') || (s[2] == '1' && s[3] <= '2')){
			cout << "YYMM" << endl;
		}
		else{
			cout << "NA" << endl;
		}
	}
	else if(s[0] == '0' || (s[0] == '1' && s[1] <= '2')){
		if((s[2] == '0' && s[3] >= '1') || (s[2] == '1' && s[3] <= '2')){
			cout << "AMBIGUOUS" << endl;
		}
		else{
			cout << "MMYY" << endl;
		}
	}
	else{
		if(s[2] == '0' && s[3] == '0'){
			cout << "NA" << endl;
		}
		else if(s[2] == '0' || (s[2] == '1' && s[3] <= '2')){
			cout << "YYMM" << endl;
		}
		else{
			cout << "NA" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 256
/* ex7_3
    fmuacshai */

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

int main(void){
    //縦の行数をheight、横の列数をwideとする
    int height,wide,i;
    //squareを動的確保して定義
    char **square;
    //sensorhとsensorwを動的確保して定義
    int *sensorh,*sensorw;
    //heightの入力
    scanf("%d",&height);
    //wideの入力
    scanf("%d",&wide);
    //マス目の配列をsquareとする
    square=(char**)calloc(height, sizeof(char*));
    if(square==NULL){
        printf("memory allocation error.\n");
        exit(1);
    }
    for(i=0;i<height;i++){
        square[i]=(char*)calloc(wide, sizeof(char));
        if(square[i]==NULL){
            printf("memory allocation error.\n");
            exit(1);
        }
    }
    //縦の列を残すか判別する配列をsensorh[]、
    //横の列を残すか判別する配列をsensorw[]とする
    sensorh=(int*)calloc(height, sizeof(int));
    if(sensorh==NULL){
        printf("memory allocation error.\n");
        exit(1);
    }
    sensorw=(int*)calloc(wide, sizeof(int));
    if(sensorw==NULL){
        printf("memory allocation error.\n");
        exit(1);
    }
    //squeres[height][wide]を入力
    for(int i=0;i<height;i++){
        for(int j=0;j<wide;j++){
            scanf(" %c",&square[i][j]);
        }
    }
    //sensorhの中身を全て0にする
    for(int i=0;i<height;i++){
        sensorh[i]=0;
    }
    //sensorwの中身を全て0にする
    for(int j=0;j<wide;j++){
        sensorw[j]=0;
    }
    //'#'が入力されているところに対応する行と列を把握する
    for(int i=0;i<height;i++){
        for(int j=0;j<wide;j++){
            //'#'だったら
            if(square[i][j]=='#'){
                //対応する部分の配列に1を入力
                sensorh[i]=1;
                sensorw[j]=1;
            }
        }
    }
    //対応する行列がどちらも1が入力されていたらを出力
    for(int i=0;i<height;i++){
        for(int j=0;j<wide;j++){
            //対応する行列がどちらも1が入力されていたら
            if(sensorh[i]==1 && sensorw[j]==1){
                //squeres[i][j]を出力
                printf("%c",square[i][j]);
            }
        }
        //消されなかったものがあった列は最後に改行
        if(sensorh[i]==1){
            printf("\n");
        }
    }
  //メモリの解放
    for(i=0;i<height;i++){
        free(square[i]);
    }
    free(square);
    free(sensorh);
    free(sensorw);
    
    return 0;
}




Measured memory_bytes: 1660
#include <bits/stdc++.h>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())

typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a*b/gcd(a,b);}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b, c;

signed main() {
	cin >> a >> b >> c;
	cout << tmax(a,b,c) - tmin(a,b,c) << ln;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>

#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second

const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;

struct Edge{
    int to,cost;
    Edge(int to,int cost) :to(to),cost(cost){}
    Edge(){}
};
struct Lost{
    int s,t;
    Lost(int s,int t) :s(s),t(t){}
    Lost(){}
};
struct State{
    int v;
    int cost;
    int bit1,bit2;
    State(int v,int cost,int bit1,int bit2):
        v(v),cost(cost),bit1(bit1),bit2(bit2){}
    State(){}

    bool operator>(const State rth) const {
        return this->cost>rth.cost;
    }
};
int n,m,k,p;
vector<Edge> G[1003];
Lost lost[10];
int dp[1003][1<<6][1<<6];

int dijk() {
    rep(i,1003) rep(j,1<<6) rep(c,1<<6) dp[i][j][c]=INF;
    dp[p][0][0]=0;
    priority_queue<State,vector<State> ,greater<State> > que;
    que.push(State(p,0,0,0));

    while(que.size()) {
        State s=que.top(); que.pop();
        if(dp[s.v][s.bit1][s.bit2]>s.cost) continue;

        rep(i,G[s.v].size()) {
            Edge e=G[s.v][i];
            rep(a,k) {
                if(lost[a].s==e.to) {
                    if(dp[e.to][s.bit1|1<<a][s.bit2]>dp[s.v][s.bit1][s.bit2]+e.cost) {
                        dp[e.to][s.bit1|1<<a][s.bit2]=dp[s.v][s.bit1][s.bit2]+e.cost;
                        que.push(State(e.to,dp[e.to][s.bit1|1<<a][s.bit2],s.bit1|1<<a,s.bit2));
                    }
                }
                if(lost[a].t==e.to&&(s.bit1>>a)&1) {
                    if(dp[e.to][s.bit1][s.bit2|1<<a]>dp[s.v][s.bit1][s.bit2]+e.cost) {
                        dp[e.to][s.bit1][s.bit2|1<<a]=dp[s.v][s.bit1][s.bit2]+e.cost;
                        que.push(State(e.to,dp[e.to][s.bit1][s.bit2|1<<a],s.bit1,s.bit2|1<<a));
                    }
                }
            }
            if(dp[e.to][s.bit1][s.bit2]>dp[s.v][s.bit1][s.bit2]+e.cost) {
                dp[e.to][s.bit1][s.bit2]=dp[s.v][s.bit1][s.bit2]+e.cost;
                que.push(State(e.to,dp[e.to][s.bit1][s.bit2],s.bit1,s.bit2));
            }
        }
    }

    int ans=INF;
    rep(i,n) ans=min(ans,dp[i][(1<<k)-1][(1<<k)-1]);

    return ans;
}

int main() {
    cin>>n>>m>>k>>p;
    p--;
    rep(i,m) {
        int x,y,w;
        cin>>x>>y>>w;
        x--,y--;
        G[x].pb(Edge(y,w));
        G[y].pb(Edge(x,w));
    }
    rep(i,k) {
        int s,t;
        cin>>s>>t;
        s--,t--;
        lost[i].s=s;
        lost[i].t=t;
    }
    int ans=dijk();
    if(ans==INF) cout<<"Cannot deliver"<<endl;
    else cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 19232
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define INF (1LL << 60)

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((int)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back


int main()
{
    ll N, K;
    cin >> N >> K;
    vector<ll> p(N);
    REP(i,0,N) cin >> p[i];

    vector<long double> e(N);
    REP(i,0,N) e[i] = ((long double)p[i] + 1.0) / 2.0;
    long double sum = 0.0, m;
    REP(i,0,K) sum += e[i];
    m = sum;
    REP(i,0,N-K) {
        sum = sum - e[i] + e[i+K];
        m = MAX(m,sum);
    }

    cout << setprecision(10) << m << endl;


    return 0;
}

/*



*/

Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> x(N);
	vector<int> y(N);
	vector<int> h(N);
	bool af = true;
	int H;
	int sx, sy, sh;
	bool setted = false;
	for (int i = 0; i < N; i++) {
		cin >> x[i] >> y[i] >> h[i];
		if (h[i] != 0 && !setted) {
			sx = x[i];
			sy = y[i];
			sh = h[i];
			setted = true;
		}
	}
	for (int Cx = 0; Cx <= 100; Cx++) {
		for (int Cy = 0; Cy <= 100; Cy++) {
			H = sh + abs(sx - Cx) + abs(sy - Cy);
			for (int i = 0; i < N; i++) {
				if (max(H - abs(x[i] - Cx) - abs(y[i] - Cy), 0) != h[i]) {
					af = false;
					break;
				}
			}
			if (af) {
				cout << Cx << " " << Cy << " " << H << endl;
				return 0;
			}
			else {
				af = true;
			}
		}
	}
	cout << "What!?" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long int n,i,t,j,k;
  cin>>n>>k;
  long long int a[n],d[n];
  for(i=0;i<n;i++)
    cin>>a[i];
  d[0]=0;
  for(i=1;i<n;i++)
    d[i]=1e9+5;
  for(i=0;i<n-1;i++)
  {
    for(j=1;j<=k;j++)
    {
   	 if(i+j<n)
   	 {
   	   d[i+j]=min(d[i+j],d[i]+abs(a[i+j]-a[i]));
   	 }
    }
   }
  cout<<d[n-1];
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;

int n,a,b,ans;
int main()
{
	ios::sync_with_stdio(false);
    cin.tie(0);
    cin>>n>>a>>b;
    for(int i=1;i<=n;i++)
    {
        int sum=0;
        for(int s=i;s>0;s/=10) sum+=s%10;
        if (a<=sum&&sum<=b) ans+=i;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <stack>
#include <iomanip>
#include <functional>
#include <array>
#include <memory>
#include <bitset>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#undef NDEBUG
#include <assert.h>

using namespace std;
typedef long long ll;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	cout << ((n & 1) ? 2 * n : n) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<sstream>
#include<cstdlib>
#include<cctype>
#include<cmath>
#include<algorithm>
#include<set>
#include<queue>
#include<stack>
#include<list>
#include<iostream>
#include<fstream>
#include<numeric>
#include<string>
#include<vector>
#include<cstring>
#include<map>
#include<iterator>
using namespace std;
int main() {
    double a,b,h,m,s,ans;
    cin>>a>>b>>h>>m;
    s=abs(60*h-11*m)/2;
    s=cos((s*M_PI)/180);
    ans=a*a+b*b-s*2*a*b;
    ans=pow(ans,0.5);
    printf("%0.20lf\n",ans);
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#define pb push_back
#define F first
#define S second

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;



int main(){
	int n;
	cin >> n;
	ll a = 1;
	ll b;
	for (int i = 0;i < n;i++){
		cin >> b;
		a = a / __gcd(a,b) * b;
	}
	cout << a << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int l, a, b, c, d;
	int x, y;
	
	scanf("%d", &l);
	scanf("%d", &a);
	scanf("%d", &b);
	scanf("%d", &c);
	scanf("%d", &d);
	
	x = a / c;
	y = b / d;
	
	if (a % c != 0){
		x++;
	}
	
	if (b % d != 0){
		y++;
	}
	
	if (x < y){
		x = y;
	}
	
	printf("%d\n", l - x);
	
	return (0);
}

Measured memory_bytes: 596
#include <sstream>
#include<iostream>
#include<algorithm>
#include<vector>
#include<set>
#include<ctime>
#include<cmath>
#include<map>
#include<unordered_map>
#include<stack>
#include<random>
#include<queue>
#include<list>
#include<math.h>
#include<bitset>
#include<fstream>
using namespace std;
#define ll long long int
#define ld long double
#define key pair<ld,ld>
#define ii pair<int,int>
#define si set<int>
#define vii vector<pair<int,int> >
#define vi vector<int>
#define vll vector<ll>
#define vb vector<bool>
#define vvi vector<vector<int> >
#define vs vector<string>
#define all(v) v.begin(),v.end()
#define pb push_back
#define mp make_pair
#define f first
#define s second
#define nu 100001
#define mul(x,y) ((ll)(x)*(y))%mod
#define tr(c,i) for(auto i = (c).begin(); i != (c).end(); i++)
#define fastio  ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define forn(i, n) for (int i = 0; i < int(n); i++)
const ll INF=9223372036854775807;
const ll mod=998244353;
int  MOD(int  a, int  b)
{
    if(a>b)
        return a-b;
    else
        return b-a;
}
ll  max3(ll  a,ll  b, ll  c)
{
    return max(c,max(a,b));
}
ll min3(ll  a,ll  b,ll  c)
{
    return min(a,min(b,c));
}
ll  power(ll  x,ll  y,ll mod1)
{
    ll res = 1;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x)%mod1;
        y = y>>1;
        x = (x*x)%mod1;
    }
    return res;
}
ll logg(ll  a)
{
    ll  x=0;
    while(a>1)
    {
        x++;
        a/=2;
    }
    return x;
}
ll  gcd(ll  a,ll   b)
{
    if (a == 0)
        return b;
    return gcd(b % a, a);
}
ll abso(ll x)
{
    if(x<0)
    {
        return -x;
    }
    return x;
}
ll ceiling (ll  a,ll  b)
{
    if(a%b==0)
    {
        return a/b;
    }
    else
    {
        return a/b+1;
    }
}
ll modinv(ll x,ll p)
{
    return power(x,p-2,p);
}
struct point
{
    ll x;ll y;
};
ll cross(point a,point b)
{
    return a.x*b.y-b.x*a.y;
}
bool ccw(point p1,point p2)
{
    /* point n1;n1.x=p1.x-p0.x;n1.y=p1.y-p0.y;
     point n2;n2.x=p2.x-p0.x;n2.y=p2.y-p0.y;*/
    if(cross(p1,p2)>0)
    {
        return true;
    }
    else
    {
        return false;
        //No need to worry about cross=0 case in this question;
    }
}
void ccw_sort(vector<point> &v)
{
    vector<point> v1,v2;
    for(int i=0;i<v.size();i++)
    {
        if(v[i].y>0)
        {
            v1.push_back(v[i]);
        }
        else
        {
            v2.push_back(v[i]);
        }
    }
    sort(all(v1),ccw);
    sort(all(v2),ccw);
    for(int i=0;i<v2.size();i++)
    {
        v1.push_back(v2[i]);
    }
    v=v1;
}
int main()
{
    fastio;
    char a;
    cin>>a;
    cout<<(char)(a+1);
}


Measured memory_bytes: 256
import math
a, b, C = map(float, input().split())
C = C / 180 * math.pi
print('%.06f' % (a * b * math.sin(C) / 2))
print('%.06f' % ((a**2 + b**2 -2*a*b*math.cos(C))**(1/2) + a + b))
print('%.06f' % (b*math.sin(C)))

Measured memory_bytes: 7860
#include<bits/stdc++.h>

#define maxn 300005

using namespace std;
typedef long long ll;

int n;
int a[maxn];

struct par{
  int x, y;
  par(int _x = 0, int _y = 0) : x(max(_x, _y)), y(min(_x, _y)) {};

  par operator + (par op) {
    if (y > op.x) return *this;
    if (op.y > x) return op;
    return par(x, op.x);
  }

  int value() {
    return x + y;
  }
};

par dp[maxn][20];

int main(){
  #define TASK "ABC"
 // freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);
  ios_base::sync_with_stdio(0);

  cin >> n;

  for (int i = 0; i < (1 << n); ++i)
    cin >> a[i];

  int ans = 0;

  for (int mask = 0; mask < (1 << n); ++mask) {
    dp[mask][0] = par(a[mask], 0);

    for (int i = 1; i <= n; ++i)
      if ((mask >> (i - 1)) & 1)
        dp[mask][i] = dp[mask][i - 1] + dp[mask ^ (1 << (i - 1))][i - 1];
      else
        dp[mask][i] = dp[mask][i - 1];

    if (mask != 0)
      cout << (ans = max(ans, dp[mask][n].value())) << '\n';
  }

  return 0;
}


Measured memory_bytes: 50944
#include <bits/stdc++.h>

using namespace std;

int main ()
{

    int n, m;
    cin >> n >> m;
    vector <int> v(m+1);

    for (int i = 0; i < m+1; i++)
    {
        v[i] = 0;
        //cout << i << " ";
    }
    //cout << endl;

    for (int i = 0; i < n; i++)
    {
        int k;
        cin >> k;
        for (int j = 0; j < k; j++)
        {
            int temp;
            cin >> temp;
            v[temp]++;
            //cout << "temp = " << temp << " ";
        }
    }
    //cout << endl;
    int ans = 0;
    for (int i = 0; i < m+1; i++)
    {
        if (v[i] == n)
        {
            ans++;
        }
        //cout << v[i] << " ";
    }
    //cout << endl;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<int>b(n);
  vector<int>a;
  for(int i=0;i<n;i++)cin>>b[i];
  for(int i=0;i<n;i++)
  {
    int x=0,back=1,c;
    for(int i=0;i<n;i++)
    {
      if(back==b[i])
      {
        x=back;
        c=i;
      }
      if(b[i]!=-1)back++;
    }
    if(!x)
    {
      cout<<-1<<endl;
      return 0;
    }
    b[c]=-1;
    a.push_back(x);
  }
  for(int i=a.size()-1;i>=0;i--)cout<<a[i]<<endl;
  return 0;
}

Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())


ans = 0
for i in range(a+1):
    gh = 500*i
    for j in range(b+1):
        hy = 100*j
        for k in range(c+1):
            gj = 50*k
            t = gh + hy + gj
            if t == x:
                ans += 1

print(ans)


Measured memory_bytes: 9192
#include <iostream>
using namespace std;

int main(){

int a,b;

while(1){
  cin >> a >>b;
  if(a<1 || b>100){
    continue;
  }
  else {
    cout << a*b << " "<< a*2+b*2<<endl;
    break;
  }
}

  return 0;
}

Measured memory_bytes: 3092
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
const double PI = 3.14159265358979323846;

int main() {
  int a, b, h;
  cin >> a >> b >> h;
  int ans = (a+b)*h / 2;
  
  cout << ans << endl;
}

Measured memory_bytes: 3632
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <utility>

using namespace std;

int64_t mod = 1e9+7;

int main(int argc, char** argv) {
    string st;
    cin >> st;
    set<char> s;
    for (char c : st) {
        auto it = s.find(c);
        if (it == s.end())
            s.insert(c);
        else s.erase(it);
    }
    cout << (s.empty() ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
/*
 AOJ #2773
 title:Periodic Sequence
 @kankichi573
*/
#include <stdio.h>
#include <string.h>

int n,s[200000],hist[100000],fc;

int gcd(int a,int b)
{
        int c;
        while (b > 0) {
                c = a % b;
                a = b;
                b = c;
        }
        return a;
}


int all_gcd(int n,int hist[])
{
  int i,ret;

  ret = n;
  for(i=0;i<100000;i++)
    if(hist[i])
      {
	//printf("%d[%d]\n",i,hist[i]);
	ret = gcd(ret,hist[i]);
      }
  return(ret);
}
int check(int s[],int n,int g)
{
  int i;

  for(i=0;i<n-n/g;i++)
    if(s[i]!=s[i+n/g])
      return(0);
  return(1);
}

int main()
{
  int i,v,gcd_;
  scanf("%d",&n);

  for(i=0;i<n;i++)
    {
      scanf("%d",&v);
      s[i]=v;
      hist[v]++;
    }
  gcd_=all_gcd(n,hist);
  //printf("all gcd=%d\n",gcd_);
  for(i=gcd_;i>=2;i--)
    if((gcd_ % i)==0 && check(s,n,i))
      {
	printf("%d\n",i);
	goto END;
      }
  printf("1\n");
 END:
  return 0;
}

Measured memory_bytes: 1752
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Solver {
    Scanner sc = new Scanner();

    public void Solve() {
        int A = sc.nextInt();
        int B = sc.nextInt();
        int ans = 0;

        for (int i = 0; i < 2; i++) {
            if (A > B) {
                ans += A;
                A--;
            } else {
                ans += B;
                B--;
            }
        }
        WriteLine(ans);
    }
}


class Scanner {
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner() {
        s = new string[0];
        i = 0;
    }

    public string next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt() {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0) {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong() {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0) {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble() {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0) {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++) {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

class Program {
    static void Main(string[] args) {
        Solver s = new Solver();
        s.Solve();
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <string.h>
#define N_MAX 100
#define S_MAXL 25
#define T_MAXL 100

int n;
char s[S_MAXL + 1], t[N_MAX][T_MAXL + 1];
int sl,ans;

void solve(int i){
	int p,q;
	int tl = strlen(t[i]);
	for(p=0;p<tl;p++){
		if(t[i][p] != s[0])continue;
		q = p;
		while(++q < tl){
			if(t[i][q] != s[1])continue;
			{
				int j;
				int r = q - p;
				int f = 1;
				if(p + r * (sl - 1) >= tl)
					break;
				for(j=2;j<sl;j++)
					if(t[i][p + j * r] != s[j]){
						f = 0;
						break;
					}
				if(f){
					ans++;
					return;
				}
			}
		}
	}
	return;
}

int main(void){
	int i;
	scanf("%d",&n);
	scanf("%s",s);
	sl = strlen(s);
	for(i=0;i<n;i++){
		scanf("%s",t[i]);
		solve(i);
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    string s;
    cin >> s;
    int ans = count(s.begin(), s.end(), 'R');
    if (ans == 2 && s[1] == 'S') ans--;
    cout << ans << endl;
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
#define int long long

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << setprecision(10);

    int n;
    cin >> n;
    vector<int> p(n), q(n);
    for (int i = 0; i < n; i++)
        cin >> p[i];
    for (int i = 0; i < n; i++)
        cin >> q[i];

    int a, b;

    int i = 1;
    vector<int> order(n);
    iota(order.begin(), order.end(), 1);
    do
    {
        if (p == order)
            a = i;
        if (q == order)
            b = i;
        i++;
    } while (next_permutation(order.begin(), order.end()));

    cout << abs(a - b) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;

int main() {
  int H, W;
  
  cin >> H >> W;
  
  vector<vector<char>> a(H, vector<char>(W));
  
  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      cin >> a.at(i).at(j);
    }
  }
  
  bool loop = true;
  while(loop){
    loop = false;
    
    for(vector<vector<char>>::iterator it=a.begin(); it!=a.end(); ++it){
      bool ans = true;
      for(int j=0; j<it->size(); j++){
        if(it->at(j)=='#'){
          ans = false;
          break;
        }
      }
      
      if(ans){
        a.erase(it);
        loop = true;
        break;
      }
    }
  }
  
  loop = true;
  while(loop){
    loop = false;
    
    for(int i=0; i<a.at(0).size(); i++){
      bool ans = true;
      
      for(int j=0; j<a.size(); j++){
        if(a.at(j).at(i)=='#'){
          ans = false;
          break;
        }
      }
      
      if(ans){
        for(int j=0; j<a.size(); j++){
          a.at(j).erase(a.at(j).begin()+i);
        }
        loop = true;
        break;
      }
    }    
  }
  
  for(int i=0; i<a.size(); i++){
    for(int j=0; j<a.at(i).size(); j++){
      cout << a.at(i).at(j);
    }
    cout << endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int a[] = new int[n];

		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt();
		}

		int gcd = a[0];
		for(int i = 1 ; i < n; i++){
			gcd = gcd(a[i], gcd);
		}

		System.out.println(gcd);
	}

	static int gcd(int a, int b){
    	int tmp;

    	while (a % b != 0)
    	{
    		tmp = b;
    		b = a % b;
    		a = tmp;
    	}
    	return b;
    }
}

Measured memory_bytes: 50316
#include<bits/stdc++.h>

using namespace std;

typedef long long int llint;
typedef pair<int, int> pii;
typedef pair<llint, llint> pll;
typedef vector<int> vi;
typedef vector<llint> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;

#define ci cin
#define co cout
#define en endl
#define ln cout<< '\n'
#define rep(i, n) for(int i = 0; i < n; i++)
#define outl(x) cout<< (x) << '\n'
#define pb push_back
#define fi first
#define se second
#define MOD 1000000007

template<typename Tn> Tn gcd(Tn a, Tn b)
{
    return (b ? gcd(b, a % b) : a);
}

template<typename Tn> Tn lcm(Tn a, Tn b)
{
    return a / gcd(a, b) * b;
}

string IntToString(int number)
{
    stringstream ss;
    ss << number;
    return ss.str();
}

llint cnt = 0;
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

int n;
int a[100001];
int b[100001];
int c[100001];

int main()
{
    ci >> n;
    rep(i, n) ci >> a[i];

    b[0] = a[0];
    for(int i = 1; i < n; i++) {
	b[i] = gcd(a[i], b[i - 1]);
    }
    
    c[n - 1] = a[n - 1];
    for(int i = n - 2; i >= 0; i--) {
	c[i] = gcd(a[i], c[i + 1]);
    }

    int ans = c[1];
    
    for(int i = 1; i < n - 1; i++) {
	ans = max(ans, gcd(b[i - 1], c[i + 1]));
    }
    
    co << max(ans, b[n - 2]) << en;
  
    return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;

int main(){
    int n,k;
    cin >> n >> k;
    double ans=0;
    for(int i=1;i<=n;i++){
        double kakuritu=1.0/(double)n;
        int tokutenn=i;
        while(true){
            if(tokutenn>=k){ans+=kakuritu;break;}
            tokutenn*=2;
            kakuritu/=2.0;
        }
    }
    printf("%.12f\n",ans);
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>


void swap(int *a, int *b){
    int work;
    work = *a;
    *a = *b;
    *b = work;
}

int main(void){
    int A, B, C;
    int cost = 0;
    scanf("%d %d %d",&A, &B, &C);
    //ソート
    if(C < B) swap(&C, &B);
    if(C < A) swap(&C, &A);
    if(B < A) swap(&B, &A);
    
    cost = (B-A) + (C-B);
    printf("%d\n",cost);

    return 0;
}

Measured memory_bytes: 128
#include <iostream>

using namespace std;

int main() {
    int n;
    string f[101];

    while (cin >> n) {
        if (!n) { break; }

        for (int i = 0; i < n; i++) { cin >> f[i]; }

        int ans = 0;

        for (int i = 1; i < n; i++) {
            if (f[i] == "lu" && f[i-1] == "ru") { ans++;}
            else if (f[i] == "ru" && f[i-1] == "lu") { ans++; }
            else if (f[i] == "ld" && f[i-1] == "rd") { ans++; }
            else if (f[i] == "rd" && f[i-1] == "ld") { ans++; }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3132
S = list(input().split("/"))
S[0] = int(S[0])
S[1] = int(S[1])
S[2] = int(S[2])

ans = "Heisei"

if (S[0] >= 2019) :
    if S[1] >= 5 :
        ans = "TBD"
    elif S[1] == 4 :
        if S[2] == 31 :
            ans = "TBD"
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h> 
using namespace std;

#define sz(x) (int)x.size() 
#define pb push_back 
#define mp make_pair 
#define fi(a, b) for(int i=a; i<=b; i++) 
#define fj(a, b) for(int j=a; j<=b; j++) 
#define fo(a, b) for(int o=a; o<=b; o++) 
#define fdi(a, b) for(int i=a; i>=b; i--) 
#define fdj(a, b) for(int j=a; j>=b; j--) 
#define fdo(a, b) for(int o=a; o>=b; o--) 

#ifdef LOCAL
#define err(...) fprintf(stderr, __VA_ARGS__)
#else
#define err(...) while(false) {}
#endif

typedef long long ll; 
typedef pair<int, int> pii; 
typedef pair<ll, ll> pll; 
typedef vector<int> vi; 
typedef vector<ll> vll;
typedef vector<pii> vpii; 
typedef vector<pll> vpll; 
typedef long double ld;
typedef unsigned long long ull;

/////////////////////////////////

int getsum(int n) {
	int res = 0;
	while (n) {
		res += (n % 10);
		n /= 10;
	}
	return res;
}

int n;
int const INF = 1e9 + 41;

void solve() {
	int ans = INF;
	fi(1, n - 1) {
		ans = min(ans, getsum(i) + getsum(n - i));
	}
	printf("%d\n", ans);
}

int main() {
#ifdef LOCAL
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	scanf("%d", &n);  
	solve();		

	
#ifdef LOCAL
	err("ELAPSED TIME: %.3Lf\n", (ld) clock() / CLOCKS_PER_SEC);
#endif	
	
	return 0;
}

Measured memory_bytes: 768
//include
//------------------------------------------
#include <bits/stdc++.h>

using namespace std;

//typedef
//------------------------------------------
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vbb;
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;

//container util
//------------------------------------------
#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define iter(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)

//repetition
//------------------------------------------
#define loop(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  loop(i,0,n)

//constant
//--------------------------------------------
const double eps = 1e-10;
const double pi  = acos(-1.0);
const double inf = (int)1e8;

// output vector
// ------------------------------------------
namespace std {
    template<typename T> ostream & operator<<(ostream& os, vector<T> const& v){
        for(auto it=v.begin(); it!=v.end(); ++it){
            os << *it << (it+1==v.end() ? "" : ",");
        }
        return os;
    }
}

//clear memory
#define clr(a) memset((a), 0 ,sizeof(a))

int lcm(int a,int b){
   return a*b/__gcd(a,b);
}
 
vb pn((int)1e4+10); 
void prime_number(int n){
   fill(all(pn),true);
   pn[0]=false;pn[1]=false;
   loop(i,2,n/2+1){
      if(!pn[i]) continue;
      for(int j=2;i*j<=n;j++){
         pn[i*j]=false;
      }
   }
}

int main(){
   int k,c,sum;
   
   while(cin>>k){
      if(k==0) break;
      sum=0;
      rep(i,k*(k-1)/2){
         cin >> c;
         sum+=c;
      }
      cout << sum/(k-1) << endl;
   }
}

Measured memory_bytes: 1196
#include<iostream>
using namespace std;

int main(){
  int a,b,n;
  int s,f;

  while(cin >> a >> b >> n){
    s = 0;
    for(int i=0;i<=n;i++){
      f = a/b;
      if(i)s += f;
      a -= b*f;
      a *= 10;
    }
    cout << s << endl;
  }
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
#include<cmath>
#include<string>
using namespace std;
#define f first
#define s second
#define MOD 1000000007
#define fast ios::sync_with_stdio(0),cout.tie(0),cin.tie(0)
#define pb push_back
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define mp make_pair
#define mkt make_tuple
#define INF (ll)1e18
typedef long long ll;
typedef unsigned long long ull;
class solution{
public:
	//ll pow;
	
	void solve(){
		ll h;
		cin>>h;
		int n;
		cin>>n;
		vector<pair<ll,ll>> v(n);
		for(int i=0;i<n;i++){
			cin>>v[i].first>>v[i].second;
		}
		vector<ll> dp(h+1,INF);
		dp[h] =0;
		for(int i=h;i>=0;i--){
			for(int j= 0;j<n;j++){
				if((i-v[j].f)>=0){
					//dp[i-v[j].f] = min(dp[i-v[j].first],(dp[i]+v[j].second));
					if(dp[i-v[j].f]>dp[i]+v[j].s){
						dp[i-v[j].f] = dp[i]+v[j].s;
					} 
				}
				else{
					if(dp[0]>dp[i]+v[j].s){
						dp[0] = dp[i]+v[j].s;
					}	
				}
			}
		}
		cout<<dp[0];
	}

};

int main()
{
    fast;
	ll i=0;
	solution s;
	s.solve();

 return 0;
}



Measured memory_bytes: 384
a = input()
A = len(a)
b = input()
B = len(b)
if A + 1 == B:
    if a == b[0:A]:
        if a + b[A:A + 1] == b:
            print("Yes")
        else:
            print("No")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 9116
#include <stdio.h>
#include <string.h>


int getChar(char);
int h1(int);
int h2(int);
int find(char []);
int insert(char []);



#define LN 14
#define NIL -1
#define M 1000000

char HASH[M][LN];

int main(){
  int i,n;;
  char str[LN];
  char comm[7];

for(i=0;i<M;i++){
  HASH[i][0]='\0';
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s %s",comm,str);

    if(comm[0]=='i'){
      insert(str);
    }else{
      if(find(str)){
        printf("yes\n");
      }else {
          printf("no\n");
        }
      }
    }
    return 0;
  }
}




int getChar(char ch){
  if(ch=='A')return 1;
  else if(ch=='C')return 2;
  else if(ch=='G')return 3;
  else if (ch=='T')return 4;
  else return 0;
}

long getKey(char str[]){
  long sum=0;
  long p=1;
  long i;
  for(i=0;i<strlen(str);i++){
    sum+=p*(getChar(str[i]));
  p*=5 ;
}
return sum;
}

int h1(int key){
  return key%M;
}
int h2(int key){
  return 1+(key%(M-1));
}

int find(char str[]){
  long key,i,h;
  key=getKey(str);
  i=0;
  while(1){
  h=(h1(key)+i*h2(key))%M;
  if(strcmp(HASH[h],str)==0)return 1;
  else if(strlen(HASH[h])==0)return 0;
  i++;
  }
return 0;
}












int insert(char str[]){
  long key,i,h;
  key=getKey(str);
  i=0;
  while(1){
    h=(h1(key)+i*h2(key))%M;
    if(strcmp(HASH[h],str)==0)return 1;
    else if(strlen(HASH[h])==0){
      strcpy(HASH[h],str);
      return 0;
    }
i++;
  }
return 0;
}

Measured memory_bytes: 14272
// vvvvvvvvvvvv TEMPLATE vvvvvvvvvvvv
#include <bits/stdc++.h>
using namespace std; using ll = long long; using P = pair<ll, ll>;
const ll linf = 1e18; const double eps = 1e-12, pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define each(i,a) for (auto&& i : a)
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define eb emplace_back
#define all(a) begin(a),end(a)
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)
template<typename Head> void out(Head h) { cout << h << endl; } template<typename Head, typename... Tail>void out(Head h, Tail... t) { cout << h << " "; out(t...); }
template<typename T> istream& operator>>(istream& is, vector<T>& v) { each(x,v) is >> x; return is; }
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) { rep(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
ostream& operator<<(ostream& os, const vector<string>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) { rep(i,v.size()) { if (i) os << endl; os << v[i]; } return os; }
template<typename T1, typename T2> ostream& operator<<(ostream& os, const pair<T1, T2>& p) { return os << "(" << p.first << ", " << p.second << ")"; }
struct yes_no : std::numpunct<char> { string_type do_truename() const { return "Yes"; } string_type do_falsename() const { return "No"; } };
void solve(); int main() {
  ios::sync_with_stdio(false); cin.tie(0); locale loc(locale(), new yes_no); cout.imbue(loc); cout << fixed << setprecision(10) << boolalpha;
  solve();
}
// ^^^^^^^^^^^^ TEMPLATE ^^^^^^^^^^^^

void solve() {
  ll A, B, M; cin >> A >> B >> M;
  vector<ll> a(A); cin >> a;
  vector<ll> b(B); cin >> b;
  ll ans = *min_element(all(a)) + *min_element(all(b));
  rep(i, M) {
    ll x, y, c; cin >> x >> y >> c; --x, --y;
    chmin(ans, a[x] + b[y] - c);
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>
#include<limits>
#include<bitset>
#include<functional>
#include<type_traits>
#include<queue>
#include<stack>
#include<array>
#include<random>
#include<utility>
#include<cstdlib>
#include<ctime>
#include<sstream>
#include<boost/algorithm/string/trim.hpp>

using namespace std;

vector<int> getInput(int input);

int main()
{
	int N; cin >> N;
	vector<int> A = getInput(N);
	map<int, int> mp;
	for (int i = 0; i < N; i++) {
		mp[A[i]] = i + 1;
	}
	string res = "";
	for (auto x : mp) {
		ostringstream ss;
		ss << x.second;
		res += " " + ss.str();
	}
	boost::algorithm::trim(res);
	cout << res << endl;
}

vector<int> getInput(int input) {
	vector<int> vec(input);
	for (auto& v : vec) {
		cin >> v;
	}
	return vec;
}

Measured memory_bytes: 6656
#include <bits/stdc++.h>
#include<string.h>
using namespace std;

int main(){
  string str;
  string result;
  
  cin >> str;
  
  bool found = false;
  int size = str.length();
  for (int i=0; i<size; ++i) {
   	 found = false;
   	 if (str.at(i) == '?') {
        if (i - 1 >= 0) {
        	if (str.at(i-1) == 'P') {
                result += 'D';
                  found = true;
            } else if (str.at(i-1) == '?') {
                if (result.at(i-1) == 'P') {
                    result += 'D';
                      found = true;
                }
            }
        }
       
        if (found) continue;
       
       
        if (i + 1 < size) {
        	if (str.at(i+1) == 'D') {
            	result += 'P';
              	found = true;
            } else if (str.at(i+1) == '?') {
              	result += 'P';
                found = true;
            }
        }
        if (!found) {
        	result += 'D';
        }
     }
  	 else {
      	result += str.at(i); 
     }
  }
  cout << result;
}

Measured memory_bytes: 3924
#define _CRT_SECURE_NO_WARNINGS
#define REL
#include <algorithm>
#include <string>
#include <iostream>
#include <complex>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <stack>
#include <map>
#include <list>
#include <queue>
#include <deque>
#include <random>
#include <set>
#include <vector>
#include <unordered_map>
#include <bitset>
#include <unordered_set>
#include <array>
#include <forward_list>
#include <chrono>
#include <iomanip>
#include <utility>
#include <assert.h>

#pragma GCC optimize("Ofast")
#pragma target("sse", "sse1")

#define mp make_pair
#define pb push_back

using namespace std;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

mt19937 gen(34);

int k, x;

int main()
{
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#else
	//freopen("memory.in", "r", stdin);
	//freopen("memory.out", "w", stdout);
#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cin >> k >> x;
	if (k * 500 >= x)
		cout << "Yes";
	else
		cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
using namespace std;
int main() {
    int N;
    cin >> N;
    double ans = 0.0;
    if(N % 2 == 0)
        ans = 0.5;
    else
        ans = (double)((N / 2) + 1) / (double)N;
    printf("%.06lf\n", ans);
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep(i,a,b) for(int (i)=int(a);(i)<int(b);(i)++)



using namespace std;

SINT32 DP[101][4][4][4];

int main() {

	SINT32 N = 0;
	cin >> N;
	SINT32 ANS = 0;
	SINT32 MOD = 1000000007;



	DP[0][3][3][3] = 1;

	
	rep(i,0,N) {
		rep(c1,0,4) {
			rep(c2,0,4) {
				rep(c3,0,4) {
					rep(n,0,4) {

						if ((n == 1) && (c1 == 2) && (c2 == 0)) continue;
						if ((n == 2) && (c1 == 0) && (c2 == 1)) continue;
						if ((n == 2) && (c1 == 1) && (c2 == 0)) continue;
						if ((n == 2) && (c1 == 1) && (c3 == 0)) continue;
						if ((n == 2) && (c2 == 1) && (c3 == 0)) continue;

						DP[i+1][n][c1][c2] += DP[i][c1][c2][c3];
						DP[i+1][n][c1][c2] %= MOD;
					}
				}
			}
		}
	}

	rep(c3,0,4) {
		rep(c2,0,4) {
			rep(c1,0,4) {
				ANS += DP[N][c1][c2][c3];
				ANS %= MOD;
			}
		}
	}


	cout << ANS << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

/* SET コンテナ
	set<SINT32> DATA;
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}
*/

/* map
	map<string,SINT32> mp;
	SINT32 N = 0;
	SINT32 mx = 0;

	cin >> N;
	for (SINT32 i = 0; i < N; i++) {
		string s;
		cin >> s;
		mp[s]++;
	}
	for(auto it=mp.begin();it!=mp.end();it++) {
		mx=max(mx,it->second);
	}

*/

Measured memory_bytes: 256