akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define BW(a,x,b) ((a)<=(x)&&(x)<=(b))
#define ALL(v) (v).begin(), (v).end()
#define LENGTHOF(x) (sizeof(x) / sizeof(*(x)))
#define AFILL(a, b) fill((int*)a, (int*)(a + LENGTHOF(a)), b)
#define MP make_pair
#define PB push_back
#define F first
#define S second
#define INF 1 << 30
#define EPS 1e-10

typedef pair<int, int> pi; // 残りの割引券 現在の街
typedef pair<int, pi>P; // コスト pi
typedef vector<int> vi;
typedef queue<int> qi;
typedef long long ll;

struct edge{ int to, cost; };

int C, V, E, S, D;
int d[128][16];
 vector<vector<edge> >G(128);
// int G[128];

void dijkstra(int s){
  priority_queue<P, vector<P>, greater<P> >q;
  rep(i, V) rep(j, C+1) d[i][j] = INF;
  d[s][C] = 0;
  q.push(MP(0, MP(C, s)));

  while(!q.empty()){
    P p = q.top(); q.pop();
    int v = p.S.S;
    int c = p.S.F;

    rep(i, G[v].size()){
      edge e = G[v][i];
      if(d[e.to][c] > d[v][c] + e.cost){
	d[e.to][c] = d[v][c] + e.cost;
	q.push(MP(d[e.to][c], MP(c, e.to)));
      }

      if( c > 0 && d[e.to][c-1] > d[v][c] + e.cost/2){
	  d[e.to][c-1] = d[v][c] + e.cost/2;
	  q.push(MP(d[e.to][c-1], MP(c-1, e.to)));
      }
    }
  }
}

int main(){
  while(scanf("%d%d%d%d%d", &C, &V, &E, &S, &D) && C+V+E+S+D){
    S--; D--;
    rep(i, 128){
      //      rep(j, 128) G[i][j] = INF;
      G[i].clear();
    }
    rep(i, E){
      int a, b, c;
      scanf("%d%d%d", &a, &b, &c); a--; b--;
     edge e;
      e.to = a; e.cost = c;
      G[b].PB(e);
      e.to = b;
      G[a].PB(e);
      //      G[a][b] = G[b][a] = c;
    }

    dijkstra(S);

    int res = INF;
    rep(i, C+1) res = min(res, d[D][i]);
    printf("%d\n", res);
    //    printf("%d\n", d[D][0]);
  }

  return 0;
}

Measured memory_bytes: 1260
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <fstream>
#include <sstream>
#include <math.h>
#include <map>
using namespace std;

int main()
{
	int D;
	cin >> D;
	cout << "Christmas";
	for(int i=0;i<abs(25-D);i++)
	{
		cout << " Eve";
	}

}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        char[] S = scanner.next().toCharArray();
        scanner.close();

        int nearNum = Integer.MAX_VALUE;

        for (int i = 0; i < S.length - 2; i++) {
            int num = Integer.parseInt(String.valueOf(new char[]{S[i], S[i + 1], S[i + 2]}));
            int diff = Math.abs(num - 753);
            if (diff < nearNum) {
                nearNum = diff;
            }
        }

        System.out.println(nearNum);
    }
}


Measured memory_bytes: 23764
#include <bits/stdc++.h>
const long long MOD = 1e9+7;
using namespace std;
#define ll long long
#define ar array

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

	 int A,B;
	 cin >> A >> B;

	 if (A>=13) {
		 cout << B << endl;
	 } else if (A>=6 && A<=12) {
		 cout << B/2 << endl;
	 } else {
		 cout << 0 << endl;
	 } 
	 return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <time.h>
#include <stdlib.h>
#include <string>
#include <bitset>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <algorithm>
#include <sstream>
#include <stack>
#include <iomanip>
using namespace std;
#define pb push_back
#define mp make_pair
typedef pair<int,int> pii;
typedef long long ll;
typedef double ld;
typedef vector<int> vi;
#define fi first
#define se second
#define fe first
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define Edg int M=0,fst[SZ],vb[SZ],nxt[SZ];void ad_de(int a,int b){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;}void adde(int a,int b){ad_de(a,b);ad_de(b,a);}
#define Edgc int M=0,fst[SZ],vb[SZ],nxt[SZ],vc[SZ];void ad_de(int a,int b,int c){++M;nxt[M]=fst[a];fst[a]=M;vb[M]=b;vc[M]=c;}void adde(int a,int b,int c){ad_de(a,b,c);ad_de(b,a,c);}
#define es(x,e) (int e=fst[x];e;e=nxt[e])
#define esb(x,e,b) (int e=fst[x],b=vb[e];e;e=nxt[e],b=vb[e])
#define VIZ {printf("digraph G{\n"); for(int i=1;i<=n;i++) for es(i,e) printf("%d->%d;\n",i,vb[e]); puts("}");}
#define VIZ2 {printf("graph G{\n"); for(int i=1;i<=n;i++) for es(i,e) if(vb[e]>=i)printf("%d--%d;\n",i,vb[e]); puts("}");}
#define SZ 666666
int h,w; char ms[233][233];
int g[233][233];
short mx[102][102][102][102];
template<class T>
void cmax(T&a,int b)
{
	(a<b)?(a=b):0;
}
int S(int x1,int x2,int y1,int y2)
{
	x1=max(x1,1); x2=min(x2,h);
	y1=max(y1,1); y2=min(y2,w);
	if(x1<=x2&&y1<=y2)
		return g[x2][y2]-g[x1-1][y2]-g[x2][y1-1]
		+g[x1-1][y1-1];
	return 0;
}
int main()
{
	scanf("%d%d",&h,&w);
	int ex,ey;
	for(int i=1;i<=h;++i)
	{
		scanf("%s",ms[i]+1);
		for(int j=1;j<=w;++j)
		{
			if(ms[i][j]=='E') ex=i,ey=j;
			else if(ms[i][j]=='o') g[i][j]=1;
			g[i][j]+=g[i-1][j]+g[i][j-1]-g[i-1][j-1];
		}
	}
	mx[0][0][0][0]=0; int ans=0;
	for(int s=0;s<=h+w+h+w;++s)
	{
		for(int u=0;u<=h;++u)
		{
			for(int d=0;d<=h;++d)
			{
				for(int l=0;l<=w;++l)
				{
					int r=s-u-d-l;
					if(0<=r&&r<=w
					&&ex-u>=1&&ex+d<=h
					&&ey-l>=1&&ey+r<=w);
					else continue;
					//cout<<u<<','<<d<<','<<l<<","<<r<<" "<<mx[u][d][l][r]<<"\n";
					//system("pause");
					cmax(ans,mx[u][d][l][r]);
					//[ex-u,ex+d] [ey-l,ey+r]
					//[d+1,h-u] [r+1,w-l]
					//move up.
					if(ex-u-1>=d+1)
					{
						cmax(mx[u+1][d][l][r],
						mx[u][d][l][r]+
						S(ex-u-1,ex-u-1,
						max(ey-l,r+1),
						min(ey+r,w-l)));
					}
					//move down.
					if(ex+d+1<=h-u)
					{
						cmax(mx[u][d+1][l][r],
						mx[u][d][l][r]+
						S(ex+d+1,ex+d+1,
						max(ey-l,r+1),
						min(ey+r,w-l)));
					}
					//move left.
					if(ey-l-1>=r+1)
					{
						cmax(mx[u][d][l+1][r],
						mx[u][d][l][r]+
						S(
						max(ex-u,d+1),
						min(ex+d,h-u),
						ey-l-1,ey-l-1));
					}
					//move right.
					if(ey+r+1<=w-l)
					{
						cmax(mx[u][d][l][r+1],
						mx[u][d][l][r]+
						S(
						max(ex-u,d+1),
						min(ex+d,h-u),
						ey+r+1,ey+r+1));
					}
				}
			}
		}
	}
	printf("%d\n",ans);
}

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

int main()
{
string s;
  cin >> s;
  string m = "CODEFESTIVAL2016";
  
  int sum = 0;
  for (int i= 0;i < m.length(); i++)
    if (s[i] != m[i])
      sum++;
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1e9;
using namespace std;
using ll = long long;
int main() {
    int N;
    cin >> N;
    vector <int> A(N);
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    sort(A.begin() , A.end());
    reverse(A.begin() , A.end());
    ll ans = A[0];
    int T = N - 2;
    int n = 0; 
    if(T % 2 == 0){
        n = T / 2 + 1;
        for(int i = 1; i < n; i++){
            ans += A[i] * 2;
        }
    }
    else{
        n = T / 2 + 1;
        for(int i = 1; i < n; i++){
            ans += A[i] * 2;
        }
        ans += A[n];
    }
    cout << ans << endl;
}

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

int main() {
    string s;
    cin >> s;
    string s1 = s.substr(0, 2), s2 = s.substr(2, 2);

    if (s1 == "00" || "13" <= s1) {
        if ("01" <= s2 && s2 <= "12") cout << "YYMM" << endl;
        else cout << "NA" << endl;
    }
    else if ("01" <= s1 && s1 <= "12") {
        if ("01" <= s2 && s2 <= "12") cout << "AMBIGUOUS" << endl;
        else cout << "MMYY" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define forr(i, a, b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define rrep(i,n) for(int i = 1; i <= (n); i++)
#define ALL(a) (a.begin()),(a.end())
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll, ll> LP;
const ll LINF = 1LL<<60;
const int INF = 1001001001;
const int MOD = 1000000007;

/* --------------------------------------------------- */


int main() {
    int n, x;
    cin >> n >> x;
    vector<int> A(n);
    rep(i, n) {
        cin >> A[i];
    }
    sort(ALL(A));
    int ans = 0;
    rep(i, n) {
        x -= A[i];
        if(x >= 0) {
            ans++;
        }
        else break;
    }
    if(ans == n && x) ans--;
    cout << ans << endl;
    
    return 0;
}

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

void Judge(int x[], int y[], int N){
  int count = 0;
  for (int i = 0; i < N; i++){
    if(x[i] != y[i])count++;
  }
  if(count <= 2)cout<<"YES";
  if(count > 2)cout<<"NO";
}

int main(){
  int N;
  cin>>N;
  int p[N];
  int pp[N];
  for(int i =0; i< N; i++)cin>>p[i];
  for(int i =0; i< N; i++)pp[i] = p[i]; //配列をコピー
  sort(pp, pp + N); //配列pp[]を昇順にソート
  Judge(p,pp,N);
  return 0;

}


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

// ?????¬???????????¬??????
#pragma region MACRO
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define PED cout << "\n"
#define rep(i,n) for(int i=0; i<(int)n; ++i)
#define REP(i,x,n) for(int i=x; i<(int)n; ++i)
#define repi(i,n) for(int i=0; i<=(int)n; ++i)
#define REPI(i,x,n) for(int i=x; i<=(int)n; ++i)
#define ILP while(true)
#define FOR(i,c) for(__typeof((c).begin())!=(c).begin(); i!=(c).end(); ++i)
#define ALL(c) (c).begin(), (c).end()
#define mp make_pair
#pragma endregion

// ???
#pragma region TYPE_DEF
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<string, string> pss;
typedef pair<string, int> psi;
typedef pair<int, string> pis;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long> vl;
typedef vector<long long> vll;
typedef vector<string> vs;
#pragma endregion

// Effective std
#pragma region ESTD
template<typename C, typename T> int count(C& c, T t) { return count(ALL(c), t); }
template<typename C, typename F> int count_if(C& c, F f) { return count_if(ALL(c), f); }
template<typename C, typename T> void erase(C& c, T t) { remove(ALL(c), t), c.end(); }
template<typename C> void remove(vector<C>& c, unsigned int index) { c.erase(c.begin()+index); }
template<typename C, typename T, typename U> void replace(C& c, T t, U u) { replace(ALL(c), t, u); }
template<typename C, typename F, typename U> void replace_if(C& c, F f, U u) { (ALL(c), f, u); }
template<typename C> void reverse(C& c) { reverse(ALL(c)); }
template<typename C> void sort(C& c) { sort(ALL(c)); }
template<typename C, typename Pred> void sort(C& c, Pred p) { sort(ALL(c), p); }
#pragma endregion

// ?????°
#pragma region CONST_VAL
#define PI (2*acos(0.0))
#define EPS (1e-9)
#define MOD (int)(1e9+7)
#define INF numeric_limits<int>::infinity()
#pragma endregion


int main()
{
    int c1, c5, c10, c50, c100, c500;
    cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;
    if (c1+c5*5+c10*10+c50*50+c100*100+c500*500>=1000) P(1);
    else P(0);
    return 0;
}

Measured memory_bytes: 3132
from sys import stdin

d_num = int(stdin.readline().strip())

graph = [[] for _ in range(d_num+1)]
for _ in range(d_num):
    u, k, *neighbors = map(int, stdin.readline().split())
    for v in neighbors:
        graph[u].append(v)

visited = set()
timestamps = [None for _ in range(d_num+1)]

def dfs(u, stmp):
    visited.add(u)
    entry = stmp

    stmp += 1
    for v in graph[u]:
        if v not in visited:
            stmp = dfs(v, stmp)

    timestamps[u] = entry, stmp
    return stmp+1

stmp = 1
for v in range(1, d_num+1):
    if v not in visited: stmp = dfs(v, stmp)

for num, (entry, leave) in enumerate(timestamps[1:], 1):
    print(num, entry, leave)

Measured memory_bytes: 7768
#include <iostream>
using namespace std;
int main(){
  int n;
  string odr;
  cin >> n;
  while(n--){
    int r = 0,sc = 0,out = 0;
    while(cin >> odr){
      if(odr == "HIT"){
	r++;
	if(r > 3){
	  r--;
	  sc++;
	}
	
      } else if( odr[0] == 'O'){

	out++;
	if(out > 2)break;

      }else {
	sc += r+1;
	r = 0;
      }
    }
    cout << sc << endl;
  }
}

Measured memory_bytes: 1208
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
input=lambda :sys.stdin.readline().rstrip()
def resolve():
    n,z,w=map(int,input().split())
    A=list(map(int,input().split()))
    dp=[[None]*2 for _ in range(n+1)] # dp[i][turn] 消費枚数i,turnの手から始まるときの最適解

    def dfs(i,turn)->NoneType:
        if(dp[i][turn] is not None): return

        # i+1からn-1のdp[1-turn]を埋めておく(i=n-1のときterminate)
        for j in range(i+1,n):
            dfs(j,1-turn)

        res=-INF if(turn==0) else INF
        if(turn==0):
            for j in range(i+1,n):
                res=max(res,dp[j][1])
            y=A[i-1] if(i!=0) else w
            res=max(res,abs(A[-1]-y))
        else:
            for j in range(i+1,n):
                res=min(res,dp[j][0])
            x=A[i-1] if(i!=0) else z # x=zとなることは無い
            res=min(res,abs(A[-1]-x))
        dp[i][turn]=res

    dfs(0,0)
    print(dp[0][0])
resolve()

Measured memory_bytes: 49372
#include <iostream>
using namespace std;
long long N,M;
int main() {

	cin>>N>>M;
	long long total=0;
	if(N>M/2){
		total=M/2;
	}else{
		total=N;
		M=M-N*2;
		total+=M/4;
	}
	cout << total << endl; // prints !!!Hello World!!!
	return 0;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
result = 0
for i in range(a,b+1):
	i_str = str(i)
	if i_str[0] + i_str[1] + i_str[2] + i_str[3] + i_str[4] == i_str[4] + i_str[3] + i_str[2] + i_str[1] + i_str[0]:
		result+=1
print(result)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
int a[200000];
 
int main(){
	int N;
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>a[i];
	}
 
	long long int res = 0, cur = 0, l = 0, r = 0;
	while(l < N){
		if(cur + a[r] == (cur ^ a[r])){
			res++;
			if(r < N){
				cur += a[r];
				r++;
			}
			else {
				cur -= a[l];
				res += (r - l - 2);
				l++;
			}
		}
		else{
			cur -= a[l];
			res += (r - l - 1);
			l++;
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 1024
import java.util.*;
import java.io.*;
 
import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main{
    static final long mod=1000000007;
    
    public  static void main(String[] args)   throws Exception, IOException{
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);
        // int n=sc.nextInt();
        // char c[][] = new char[h][w];
        // char c[]=sc.nextString().toCharArray();
        // int d[]=new int[n];
        // for(int i=0; i<n; i++) {d[i]=sc.nextInt();}

        int n=sc.nextInt();
        int mx=100000;
        long a[]=new long[mx+1];
        long b[]=new long[mx+1];
        int bt=1<<20;bt--;

        for (int i=0; i<n; i++) {
            if(i%2==0)a[sc.nextInt()]++;
            else b[sc.nextInt()]++;
        }
        for (int i=1; i<mx; i++) {
            a[i]=(a[i])<<20;
            a[i]+=i;
            b[i]=(b[i])<<20;
            b[i]+=i;
        }

        sort(a);
        sort(b);
        long ans=0,A=n/2,B=n/2;
        if(n%2==1)A++;
        if((a[mx]&bt) == (b[mx]&bt)){
            ans=min( A-(a[mx]>>20)+B-(b[mx-1]>>20),A-(a[mx-1]>>20)+B-(b[mx]>>20));
        }
        else {
            ans=A-(a[mx]>>20)+B-(b[mx]>>20);
        }

        out.println(ans);
        out.flush();
    }


    static void db(Object... os){
        System.err.println(Arrays.deepToString(os));
    }  

    static long gcd(long a, long b){
        if(min(a,b) == 0)return max(a,b);
        return gcd(max(a,b) % min(a,b),min(a,b));
    }
}

class P implements Comparable<P>{
    int id, d;
    P(int  id, int d) {
        this.id=id;
        this.d=d;
    }
    public int compareTo(P p){
        return d-p.d; //des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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


int main() {
	cin.tie(NULL);
	ios::sync_with_stdio(false);
	
	int N;
	cin >> N;
	vector<int> P(N+1), A(N+1,0);
	for (int i = 1; i <= N; i++)
		cin >> P[i];
	int min = P[1];
	A[1] = P[1];
	for (int i = 2; i <= N; i++) {
		if (min > P[i])
			min = P[i];
		A[i] = min;
	}
	int cnt(0);
	for (int i = 1; i <= N; i++) {
		if (A[i] == P[i]) {
			cnt++;
		}
	}
	cout << cnt;

	return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		int oddCount = 0;

		for (int i = 0; i < N; i++) {
			a[i] = sc.nextInt();
			while (a[i] % 2 == 0) {
				a[i] /= 2;
				oddCount++;
			}
		}

		System.out.println(oddCount);
	}
}


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


int main(){
	int n;
	string s;
	cin >> n >> s;
	
	for(int i=0;i<s.size();i++){
		for(int j=0;j<n;j++){
			if(s[i]+1>'Z') s[i]='A';
			else s[i]++;
		}
	}
	
	cout << s << endl;
	return 0;
}

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

using UnWeightedGraph = vector<vector<int> >;

template <typename G>
struct StronglyConnectedComponents {
  const G &g;
  UnWeightedGraph ng, rg;          // normal-graphとreversed-graph
  vector<int> compo, order, used;  // compo…頂点がどの成分に属しているか、order…帰りがけ順で何番目か

  StronglyConnectedComponents(G &g) : g(g), ng(g.size()), rg(g.size()), compo(g.size(), -1), used(g.size()) {
    for (int i = 0; i < g.size(); i++)
      for (auto t : g[i]) {
        ng[i].emplace_back(t);
        rg[t].emplace_back(i);  // 逆辺
      }
  }

  // []で聞かれたときは成分番号を返す
  int operator[](int k) { return compo[k]; }

  void dfs(int now) {
    if (used[now]) return;
    used[now] = true;
    for (auto to : ng[now]) dfs(to);
    order.emplace_back(now);
  }

  void rdfs(int now, int count) {
    // used代わりに結果を入れていく
    if (compo[now] != -1) return;
    compo[now] = count;
    for (auto to : rg[now]) rdfs(to, count);
  }

  void build(UnWeightedGraph &ret) {
    // 普通にDFS、辺の向きを変えてもう一度DFS
    for (int i = 0; i < ng.size(); i++) dfs(i);
    reverse(order.begin(), order.end());
    int group = 0;
    for (auto i : order)
      if (compo[i] == -1) rdfs(i, group), group++;

    // 縮めたグラフを構築する
    ret.resize(group);
    for (int i = 0; i < g.size(); i++) {  // 全ての辺について
      for (auto &to : g[i]) {
        int s = compo[i], t = compo[to];
        if (s != t) ret[s].emplace_back(t);
      }
    }
  }
};

// ====================================================================

int main() {
  int V, E, Q;
  cin >> V >> E;

  UnWeightedGraph g(V);
  for (int i = 0; i < E; i++) {
    int s, t;
    cin >> s >> t;
    g[s].emplace_back(t);
  }

  StronglyConnectedComponents<UnWeightedGraph> scc(g);
  UnWeightedGraph res;
  scc.build(res);

  cin >> Q;
  for (int i = 0; i < Q; i++) {
    int u, v;
    cin >> u >> v;
    cout << ((scc[u] == scc[v]) ? "1" : "0") << endl;
  }
}



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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

using namespace std;
using ll = long long;
ll sl();

int main() {
  ll n = sl();
  ll L = sl();
  ll c = 0;
  for (int i = 0; i < n; i++) {
    c += L + i;
  }
  pair<ll, ll> ans(1e18, 1e18);
  for (int i = 0; i < n; i++) {
    ll x = c;
    ll y = c - (L + i);
    ans = min(ans, {abs(x - y), y});
  }
  cout << ans.second << endl;
}

ll sl() {
  ll x;
  cin >> x;
  return x;
}

struct init {
  init() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
  }
} init;


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 25;
const int MOD = 1e9+7;
 
int main() {
	int n;
	string s;
	cin >> n >> s;
	int l = 0, r = 0;
	int gap = 0;
	rep(i,n) {
		if (s[i]=='(') l++;
		else r++;
		gap = min(gap,l-r);
	}
	int ds = l-r;
	rep(i,-gap) cout << '(';
	cout << s;
	rep(i,ds-gap) cout << ')';
	cout << endl; 
	return 0;
}

Measured memory_bytes: 3624
a, b, c, X = [int(input()) for i in range(4)]

A = 0
for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if i*500 + j*100 + k*50 == X:
                A += 1
print(A)


Measured memory_bytes: 39536
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define REP(i,n) for (int64_t i=0; i<(n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()
#define chmax(x,y) x=max(x,y)


ll dp[3005][3005][4];

int main(){
    int r,c,k; cin>>r>>c>>k;
    vector<vector<int>> v(r, vector<int> (c,0));
    rep(i,k){
        int a,b; cin>>a>>b;
        a--; b--;
        cin>>v[a][b];
    }
    rep(i,r){
        rep(j,c){
            rep(kk,3){
                if(v[i][j]!=0){
                    chmax(dp[i][j][3-kk], dp[i][j][2-kk]+v[i][j]);
                }
            }
            rep(kk,4){
                chmax(dp[i][j+1][kk], dp[i][j][kk]);
            }
            rep(kk,4){
                chmax(dp[i+1][j][0], dp[i][j][kk]);
            }
        }
    }
    ll ans=0;
    rep(i,4){
        chmax(ans, dp[r-1][c-1][i]);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 320348
/*
*
*	AUTHOR :- @soham01
*		// "WORK HARD AND NEVER GIVE UP" //
*
*/
#include "bits/stdc++.h"

using namespace std;

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> //find_by_order(), order_of_key()
#define pb push_back
#define mp make_pair
#define vi vector<long long int >
#define vb vector<bool>
#define vs vector<string>
#define vd vector<double>
#define vvi vector<vector<long long int> >
#define vp vector<pair<long long int , long long int > >
#define seti set<long long int >
#define setc set<char>
#define setd set<double>
#define mod 1000000009
#define endl '\n'
typedef long long int lli;

// ITS MY REQUEST TO PLEASE PLEASE DO LOOK AT THE CONSTRAINS GIVEN CAREFULLY
// DO CHECK FOR CORNER CASES

/*-------LET THE GAME BEGIN-----------*/

void solve()
{
	lli x;
	cin >> x;
	if (x == 0)
	{
		cout << "1" << endl;
	}
	else {
		cout << "0" << endl;
	}
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	solve();
	return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);

    int X,Y;
    cin >> X >> Y;
    cout << X+Y/2 << endl;



}


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

int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
  }
  int s = 0; 
  for (int i = 0; i < n; i++) {
    s ^= a.at(i);
  }
  for (int i = 0; i < n; i++) {
    a.at(i) ^= s;
  }
  for (int i = 0; i < n; i++) {
    cout << a.at(i) << endl;
  }
}

Measured memory_bytes: 3940
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define sz(x) (int)x.size()
#define all(x) (x).begin(), (x).end()
#define Red ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define rep(i, n) for(int i =0 ; i < n; ++i)
#define Rep(i,a,b) for(int i=a;i<=b;i++)
#define pii pair < int, int >
typedef vector<int> vi;
typedef  long long ll;
const int inf = int(1e9);
const int mod =1e9+7;
const int N = (int)2e5 + 5;



void solve(){
	int a,b,c;
	cin>>a>>b>>c;
	cout<<max(0,c-a+b);
}
int main(){
	Red;
	int t=1;
	//cin>>t;
	while(t--)
	solve();
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
const ll inf = 1LL << 50;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////

int main() {
	int N; cin >> N;
	int h[100010];
	int ans = 0;
	bool key[100100];
	for (int i = 0; i < N; ++i) {
		cin >> h[i];
	}
	for (int i = 0; i < N - 1; ++i)key[i] = false;
	for (int i = 0; i < N-1; ++i) {
		if (h[i] >= h[i + 1]) {
			key[i] = true;
		}
	}
	for (int i = 0; i < N - 1;) {
		if (!key[i]) {
			i++;
		}
		else {
			int cnt = 0;
			while (key[i]) {
				cnt++;
				i++;
				if (i >= N - 1)break;
			}
			ans = max(ans, cnt);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <queue>
#include <deque>
#include <string>
#define endl '\n'
#define ll long long

using namespace std;

int main(void)
{
	cin.tie(NULL); ios_base::sync_with_stdio(false);
	int r, g, b; cin >> r >> g >> b;
	int ret = r * 100 + g * 10 + b;
	if (ret % 4 == 0)
		cout << "YES";
	else
		cout << "NO";
	return 0;
}

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

int main() {
    vector <int> input(5), mod_list(5);
    int time = 0;
    int min_mod = 9;
    int index = 0;
    for(int i = 0;i < 5; i++)
    {
        cin >> input[i];
        int mod = input[i] % 10;
        if(mod != 0 && mod < min_mod)
        {
            min_mod = mod;
            index = i;
        }
    }

    swap(input[4], input[index]);

    for(int i = 0; i < 4; i++)
    {
        if(input[i] % 10 == 0)  time += input[i];
        else time += input[i] - input[i] % 10 + 10;
    }
    time += input[4];
    cout << time << endl;
    return 0;  

}

Measured memory_bytes: 256
#全てのマスに対して、そこからスタートして幅探索で最長を求め、そのうちの最大をとる

from collections import deque

h,w=map(int,input().split())
s=[list(input()) for i in range(h)]
# s=[list('.'*20) for i in range(h)]
if s==[list('.'*20) for i in range(20)]:
    print(40-2)
else:
    ans=0
    Q=deque()
    vec=[(1,0),(0,1),(-1,0),(0,-1)]
    his=[[0 for i in range(w)] for j in range(h)]
    for i in range(h):
        for j in range(w):
            if s[i][j]=='#':
                continue
            Q.append([i,j,0])
            his[i][j]=1
            while Q:
                x,y,d=Q.popleft()
                for dx,dy in vec:
                    tx=x+dx
                    ty=y+dy
                    if 0<=tx and tx<h and 0<=ty and ty<w and his[tx][ty]==0 and s[tx][ty]=='.':
                        Q.append([tx,ty,d+1])
                        his[x][y]=1
                        ans=max(d+1,ans)
            his=[[0 for _ in range(w)] for __ in range(h)]
    print(ans)




Measured memory_bytes: 3436
a,b,m = list(map(int, input().split()))
a1 = list(map(int, input().split()))
b1 = list(map(int, input().split()))
xyc = [ list(map(int, input().split())) for _ in range(m)]

ans = []
for x,y,c in xyc:
    ans.append(a1[x-1] + b1[y-1] - c)
ans.append(min(a1) + min(b1))
print(min(ans))


Measured memory_bytes: 42536
#include <iostream>
#include<cstring>
#include<algorithm>
#include<queue>
using namespace std;
typedef pair<int,int> P;
const int INF=10000000;
 
string s[20];
    int h,w;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int d[20][20];
 
int maze(int sx,int sy){
    queue<P> que;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)d[i][j]=INF;
    }
    que.push(P(sx,sy));
    d[sx][sy]=0;
    int imax=0;
    while(que.size()){
        P p=que.front();que.pop();
 
        for(int i=0;i<4;i++){
            int nx=p.first+dx[i];
            int ny=p.second+dy[i];
            if(0<=nx&&nx<h&&0<=ny&&ny<w&&s[nx][ny]=='.'&&d[nx][ny]==INF){
                que.push(P(nx,ny));
                d[nx][ny]=d[p.first][p.second]+1;
                if(d[nx][ny]>imax){imax=d[nx][ny];}
            }
        }
    }
    return imax;
    
}
 
int main(void){
 
    cin>>h>>w;
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    int r=0;
    for(int m=0;m<h;m++){
        for(int n=0;n<w;n++){
            if(s[m][n]=='.'){
                r=max(r,maze(m,n));
            }
        }
    }
    cout<<r;
    return 0;
    
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;

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

Measured memory_bytes: 256
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;

#define dump(x)  cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

#define SANKOU(n,a,b) cout << ((n) ? (#a) : (#b) ) << endl

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j])

#define SCOUT(x) cout<<(x)<<" "
#define ENDL cout<<endl

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_
#define VECIN2(x,y) REP(i,x.size())cin>>x[i]>>y[i]
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl

#define ALL(obj) (obj).begin(),(obj).end()

#define EXIST(n,x) (find(ALL(n),x)!=n.end())
#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end())
#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__);
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__);


#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define L list<int>

#define pb(a) push_back(a)
#define mp make_pair


int main(){

   CIN(r,g);
   COUT(g*2-r);


   return 0;


}


Measured memory_bytes: 256
N = int(input())
counter = 0
flag = False
for n in range(N):
    d1, d2 = [int(item) for item in input().split(' ')]
    if d1 == d2:
        counter += 1
    else:
        counter = 0
    
    if counter == 3:
        flag = True

if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9176
S = input()
f = int(S[:2])
e = int(S[2:])
if 1 <= f <= 12 and (e > 12 or e == 0):
    print('MMYY')
elif (f > 12 or f == 0) and 1 <= e <= 12:
    print('YYMM')
elif 1 <= f <= 12 and 1 <= e <= 12:
    print('AMBIGUOUS')
else:
    print('NA')

Measured memory_bytes: 3064
N=int(input())+1
a=[int(x) for x in input().split()]
poss=True
interm = [0 for i in range(N)]
inter = [0 for i in range(N)]
s=[0 for i in range(N)]
for i in range(N-1, -1, -1):
    if (i!=N-1):
        s[i]=a[i]+s[i+1]
    else:
        s[i]=a[i]
n=[0 for i in range(N)]
n[0]=min(s[0], 1)
for i in range(1,N):
    n[i]=min(s[i], 2*(n[i-1]-a[i-1]))
    #print(n[i-1]-a[i-1], a[i])
    if (n[i-1]-a[i-1]<(a[i]//2+a[i]%2)):
        #print(n[i-1], a[i-1], a[i])
        poss = False
#print(s)
#print(n)
if n[-1]!=a[-1]:
    print(-1)
    exit()
if poss:
    print(sum(n))
else:
    print(-1)
    


Measured memory_bytes: 652476
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MAX_N = 1000010;

int main(){
  ll N; cin >> N;
  string S; cin >> S;
  
  ll Q; cin >> Q;
  
  for(ll i = 0; i < Q; i++){
    
    ll k; cin >> k;
    
    ll ans = 0;
    
    ll d = 0; ll dm = 0; ll m = 0;
    
    for(ll j = 0; j < N; j++){
      
      if(j-k >= 0){ //これ違うかも
        if( S[j-k] == 'D'){ d--; dm -= m;}
        if( S[j-k] == 'M'){ m--;}
      }
      
      if( S[j] == 'D'){ //使えるDを増やす
        d++;}
      if( S[j] == 'M'){ m++; //mを増やす
                       dm += d; //dm数は、今使えるdの数だけ増える
                      }
      if( S[j] == 'C'){ ans += dm;
                      }
         
         }
    
    cout<< ans << endl;
  }
  
  return 0;
}
     

Measured memory_bytes: 1412
n,k=map(int,input().split())
pi=list(map(int,input().split()))

pmax=sum(pi[0:k])
#print(pmax)
psum=pmax
for i in range(1,n-k+1):
    psum=psum-pi[i-1]+pi[i+k-1]
#    print(i,k,psum)
    if psum>pmax:
        pmax=psum
px=(k+pmax)/2
print(px)        


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

int main(){
    int n;
    char in;
    bool flag = false;
    cin >> n;
    vector<char> s;
    for(int i = 0; i < n; i++){
        cin >> in;
        s.push_back(in); 
    }
    for(int i = 0; i < n; i++){
        if(s[i] == 'Y'){
            flag = true;
        }
    }
    cout << (flag ? "Four" : "Three") << endl;
    return 0;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K,Q;
    cin >> N >> K >> Q;
    vector<ll> A(2010);
    ll a2[2010];
    rep(i,0,N) cin >> A[i];
    rep(i,0,N) a2[i] = A[i];
    sort(a2, a2+N);
    // SegmentTree st(A);
    ll ans = INF;
    rep(i,0,N){
        ll X = A[i];
        bool ok[2010];
        rep(j,0,N){
            if(A[j] < X){
                ok[j] = false;
            }else{
                ok[j] = true;
            }
        }
        vector<lpair> pos;
        ll v = 0;
        rep(j,0,N){
            if(not ok[j]){
                if(v != 0) pos.push_back(make_pair(v, j-1));
                v = 0;
            }else{
                v++;
            }
        }
        if(v != 0) pos.push_back(make_pair(v, N-1));
        ll cnt = 0;
        rep(j,0,pos.size()){
            cnt += max(0LL, pos[j].first - K+1);
        }
        if(cnt >= Q){
            vector<ll> tt;
            for(auto &e: pos){
                if(e.first < K) continue;
                vector<ll> tmp;
                rep(k,e.second-e.first+1, e.second+1){
                    tmp.push_back(A[k]);
                }
                
                sort(tmp.begin(), tmp.end());
                rep(k,0,e.first- K+1){
                    tt.push_back(tmp[k]);
                }
            }
            sort(tt.begin(), tt.end());
            ll Y = tt[Q-1];
            ans = min(ans, Y-X);
        }
    }
    print(ans);




    
}

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

int main() {
  char b;
  cin >> b ;
  
  if(b=='A') cout << 'T';
  else if(b=='T') cout << 'A';
  else if(b=='C') cout << 'G';
  else if(b=='G') cout << 'C';
}

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

using ll = long long;

ll gcd(ll a,ll b){
    if(b == 0)
    return a;
    return gcd(b,a%b);
}

ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b;
}

int main(void){
    int n;
    cin >> n;
    
    ll ans = 1LL;
    
    for(int i = 0;i < n;i++){
        ll T;
        cin >> T;
        ans = lcm(ans,T);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<string>
#include<iostream>
#include <algorithm>
#include<vector>
#include<functional>
#include <cstdlib>
#define ll long long
using namespace std;



int main(){
   
  ll A,B,C;

  cin>>A>>B>>C;

  if((A==B&&A==C&&B==C)||(A!=B&&A!=C&&B!=C)){
    cout<<"No"<<endl;
  }
  else cout<<"Yes"<<endl;

 
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <utility>
using namespace std;
typedef pair<int,int> P;
int d[10],v[10];
P p[9];
int gcd(int a,int b) {
	return b?gcd(b,a%b):a;
}
int lcm(int a,int b) {
	return a/gcd(a,b)*b;
}
int main() {
	int n;
	while(scanf("%d",&n),n) {
		for(int i=0;i<n;i++) {
			scanf("%d %d",&d[i],&v[i]);
		}
		for(int i=0;i+1<n;i++) {
			int x=v[i]*d[i+1],y=d[i]*v[i+1],g=gcd(x,y);
			p[i]=P(x/g,y/g);
		}
		int m=n-1;
		for(int i=0;i+1<m;i++) {
			int l=lcm(p[i].second,p[i+1].first);
			p[i+1].second*=(l/p[i+1].first);
			for(int j=0;j<=i;j++)
				p[j].first*=(l/p[i].second);
			p[i].second=p[i+1].first=l;
		}
		int g=p[m-1].second;
		for(int i=0;i<m;i++) {
			g=gcd(g,p[i].first);
		}
		for(int i=0;i<m;i++) {
			printf("%d\n",p[i].first/g);
		}
		printf("%d\n",p[m-1].second/g);
	}
}

Measured memory_bytes: 1028
// include
// ------------------------------------------------
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <math.h>

using namespace std;

// func
// ------------------------------------------------
int CalcSumOfDigit(int n);      // 各桁の和を計算する。
long long getDigit(long long n);      // 数字の桁数を取得する。
string upper(string str);       // 英字を大文字に変換する。
string lower(string str);       // 英字を小文字に変換する。

// define
// ------------------------------------------------
#define all(a)        (a).begin(),(a).end()
#define rall(a)       (a).rbegin(),(a).rend()
#define sz(a)         int((a).size())
#define rep(i,n)      for(int(i)=0;(i)<(n);(i)++)
#define repe(i,n)     for(int(i)=0;(i)<=(n);(i)++)
#define vsort(v)      sort((v).begin(),(v).end())
#define rvsort(v)     sort(rall((v)))
#define vi            vector<int>
#define GCD(a,b)      __gcd((a),(b))
#define LCM(a,b)      ((a)/GCD((a),(b))*(b))
#define kiriage(a,b)  ((a)+(b)-1)/(b)

const int INF = 1e9;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vll;

// code
// ------------------------------------------------
int main()
{

  ll A,B,m;
  cin >> A >> B >> m;

  vll a(A),b(B);
  rep(i,A) cin >> a[i];
  rep(i,B) cin >> b[i];

  vll x(m),y(m),c(m);
  rep(i,m)
  {
    cin >> x[i] >> y[i] >> c[i];
  }

  ll ans = LLONG_MAX;
  rep(i,m)
  {
    ll val = a[x[i]-1] + b[y[i]-1] - c[i];
    ans = min(ans,val);
  }

  vsort(a);
  vsort(b);

  ans = min(ans,a[0]+b[0]);

  cout << ans << endl;


  return 0;
}
// funcの実体
// ------------------------------------------------
ll getDigit(ll n)
{
  int i = 1;
  while(1)
  {
    n = n / 10;
    if(n == 0)
      break;
    i++;
  }
  return i;
}
ll CalcSumOfDigit(ll n)
{
  ll s = 0;
  while(n)
  {
    s += n % 10;
    n = n / 10;
  }
  return s;
}

string upper(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(97 <= *itr && *itr <= 122)
    {
      *itr = *itr - 32;
    }
  }
  return str;
}

string lower(string str)
{
  for(auto itr = str.begin();itr != str.end() ; itr++)
  {
    if(65 <= *itr && *itr <= 90)
    {
      *itr = *itr + 32;
    }
  }
  return str;
}


Measured memory_bytes: 4224
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define endl "\n"
const int MOD=1e9+7;
#ifndef HOME
#define cerr if(0)cerr
#endif
const int MaxN = 1e5+5;
int dp[MaxN];
int a[MaxN];
int n;
int solve(int i){
    if(i>=n){
        return 1e9;
    }
    if(i==n-1){
        return 0;
    }
    int &ans = dp[i];
    if(ans!=-1){
        return ans;
    }
    ans = min(abs(a[i]-a[i+1])+solve(i+1),abs(a[i]-a[i+2])+solve(i+2));
    return ans;
}
int32_t main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    memset(dp,-1,sizeof(dp));
    cout<<solve(0);
    
    return 0;
    
}



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

int main(){
    using namespace std;
    unsigned long S;
    constexpr unsigned long q = 1000000000;
    cin >> S;
    if(S % q)cout << "0 0 " << q << " " << 1 << " " << q - S % q << " " << (S + q - 1) / q << endl;
    else cout << "0 0 " << q << " " << 0 << " " << 0 << " " << S / q << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

// AGC 13-B
// http://agc013.contest.atcoder.jp/tasks/agc013_b
 
public class Main {

	static int n;
	static ArrayList[] map;
	static boolean answerFound = false;
	static ArrayList<Integer> answer;

	public static void main (String[] args) throws java.lang.Exception {
		Scanner in = new Scanner(System.in);
		
		n = in.nextInt();
		int m = in.nextInt();
		
		map = new ArrayList[n];
		for (int i = 0; i < n; i++) {
			map[i] = new ArrayList<Integer>();
		}
		
		for (int i = 0; i < m; i++) {
			int a = in.nextInt() - 1;
			int b = in.nextInt() - 1;
			
			map[a].add(b);
			map[b].add(a);
		}

		int index = 0;
		while (map[index].size() == 0) {
			index++;
		}
		int node1 = index;
		int node2 = (int) map[index].get(0);
		
		int[] visited = new int[n];
		ArrayList<Integer> path = new ArrayList<Integer>();
		visited[node1] = 1;
		visited[node2] = 1;
		path.add(node1);
		dfs(node1, path, visited, true);
		path.add(node2);
		dfs(node2, path, visited, false);
		
		System.out.println(path.size());
		for (int i = 0; i < path.size(); i++) {
			System.out.printf("%d ", path.get(i) + 1);
		}
		System.out.println();
	}
	
	public static void dfs(int node, ArrayList<Integer> path, int[] visited, boolean insertFront) {
		for (int i = 0; i < map[node].size(); i++) {
			int next = (int) map[node].get(i);
			
			if (visited[next] == 0) {
				visited[next] = 1;
				if (insertFront) {
					path.add(0, next);
				} else {
					path.add(next);
				}
				dfs(next, path, visited, insertFront);
				break;
			}
		}
	}
}

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

int main(void){
    int K, N;
    cin >> K >> N;
    vector<int> A(N);
    for(int& elem : A)
        cin >> elem;
    vector<int> D(N);
    for(int i=0; i<(N-1); i++)
        D.at(i)= A.at(i+1)-A.at(i);
    D.at(N-1) = A.at(0)+K-A.at(N-1);
    int i_max=0;
    for(int i=1; i<N; i++)
        if(D.at(i)>D.at(i_max))
            i_max = i;
    D.at(i_max) = 0;
    int sum = 0;
    for(int elem : D)
        sum += elem;
    cout << sum;
    
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define _ ios_base::sync_with_stdio(0);cin.tie(0);
#define REP(i,n) for(int i=0;i<(int)(n);i++)

using namespace std;

bool right(char c){
  return c=='y'||c=='u'||c=='i'||c=='o'||c=='p'||c=='h'||c=='j'||c=='k'||c=='l'||c=='n'||c=='m';
}

int main(){ _;
  string s;
  while(cin>>s,s!="#"){
    bool r=right(s[0]);
    int count=0;
    REP(i,s.size()){
      bool tmp=right(s[i]);
      if(r!=tmp) count++;
      r=tmp;
    }
    cout<<count<<endl;
  }
}

Measured memory_bytes: 1192
/* Code by pedroslrey *
 *     march 8        *
 *    Sunday          */

#include <bits/stdc++.h>

using namespace std;

using lli = long long int;

const int INF = 1000000007;
const lli LLINF = 9223372036854775800;

#define debug(args...) fprintf(stderr, args)
#define show(x) fprintf(stderr, "[DEBUG] -> %d\n", x)

int main() {
	string s;
	cin >> s;
	char actual = 'h';
	for (char c: s) {
		if (actual == c) {
			if (actual == 'i') actual = 'h';
			else actual = 'i';
		}
		else {
			printf("No\n");
			return 0;
		}
	}
	if (s.size()%2 == 1) printf("No\n");
	else printf("Yes\n");
}


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

long long int dp[1001];
int a[8],b[8];
int main(void){
	int n,g;
	while(1){
		memset(dp,0,sizeof(dp));
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<n;i++){
			scanf("%d%d",&a[i],&b[i]);
		}
		dp[0]=1;
		for(int i=0;i<n;i++){
			for(int j=1000;j>=0;j--){
				for(int k=1;k<=b[i];k++){
					if(a[i]*k<=j){
						dp[j]+=dp[j-a[i]*k];
					}
				}
			}
		}
		scanf("%d",&g);
		for(int i=0;i<g;i++){
			int a;
			scanf("%d",&a);
			printf("%d\n",dp[a]);
		}
	}
    return 0;
}

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

int findSumOfDigits(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10; // f(X)
    n /= 10;
  }
  return sum;
}

int main(){
  int N;
  cin >> N;
  
  int sum = findSumOfDigits(N);
  if(N % sum == 0) cout << "Yes" << endl;
  else cout << "No" << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,b) FOR(i,0,b)
#define BE(c) c.begin(),c.end()
#define PB push_back
#define F first
#define S second
#define BEB(s) s
using namespace std;
int main(){
	vector<int> grade;
	int g[31];
	int n,a,r[101],l[101];
	char com;
	while(cin>>n>>com>>a,n){
		grade.PB(a);
		r[n]=a;
	}
	sort(grade.begin(),grade.end());
	grade.erase(unique(grade.begin(),grade.end()),grade.end());
	int k=0;
	for(int i=grade.size()-1;i>=0;i--){
		k++;g[grade[i]]=k;
	}
	while(cin>>n){
		cout<<g[r[n]]<<endl;
	}
	return 0;
}

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


using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVC vector<vector<char>>
#define VB vector<bool>
#define VVB vector<vector<bool>>
#define fore(i,a) for(auto &i:a)

typedef pair <int, int> P;
template<class T> bool chmax(T &a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, T b) { if (a > b) { a = b; return true; } return false; }
const int  INF = 1 << 30;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;




int main() {

	int n;
	cin >> n;
	cout << 0 << endl;
	string s;
	cin >> s;
	if (s == "Vacant") {
		return 0;
	}
	string b = s;

	VI v(n + 1, 0);
	if (s[0] == 'M')v[0] = 1;
	else v[0] = 2;
	v[n] = v[0];
	

	int ok = n;
	int ng = 0;
	int a = 0;

	while (true) {
		int mid = (ok + ng) / 2;
		cout << mid << endl;
		cin >> s;
		if (s == "Vacant")return 0;
		if (s[0] == 'M')v[mid] = 1;
		else v[mid] = 2;
		if (v[mid] == v[ok]) {
			if ((ok - mid) % 2 == 0)ok = mid;
			else ng = mid;
		}
		else {
			if ((ok - mid) % 2 == 0)ng = mid;
			else ok = mid;
		}
	}


}

Measured memory_bytes: 1236
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include<bitset>
#include<list>
#include<cassert>
#include<numeric>
 
using namespace std;

const int N = 2 * 1000 + 5;
vector<long long> a;
long long n, x;
long long dp[N][N];

int main()
{
	cin >> n >> x;
	for (int i = 0; i < n; i++)
	{
		long long tmp;
		cin >> tmp;
		a.push_back(tmp);
	}
	long long ans = 1000 * 1000 * 1000 * 1ll * 1000 * 1000 * 1000;
	for (int i = 0; i < n; i++)
		dp[0][i] = a[i];
	for (int i = 1; i < n; i++)
	{
		for (int j = 0; j < n; j++)
		{
			dp[i][j] = min(a[((j - i) + n) % n], dp[(i - 1 + n) % n][j]); 
		}
	}
	for (int i = 0; i < n; i++)
	{
		long long tmp = 0;
		for (int j = 0; j < n; j++)
		{
			tmp += dp[i][j];
		}
		ans = min(ans, i * x + tmp);
	}
	cout << ans << endl;

}


Measured memory_bytes: 31616