akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
//変数はグローバルで宣言
  int n,m,q;
  vector<int> a,b,c,d;
  int ans;

void dfs(vector<int> A) {
  if (A.size() == n+1) {
    //スコアの計算
    int now = 0;
    rep(i,q) {
      if (A[b[i]] - A[a[i]] == c[i]) now += d[i];//スコアを加算できる条件
    }
    ans = max(ans,now);
    return;
  }
  //末尾に直前の数を追加する
  A.push_back(A.back());
  while (A.back() <= m) {
    dfs(A);
    A.back()++;
  }
}

int main() {
  cin >> n >> m >> q;
  a = b = c = d = vector<int>(q);
  rep(i,q) {
    cin >> a[i] >> b[i] >> c[i] >> d[i];//配列として入力する
  }
  //再帰関数を利用して全探索を実施する
  dfs(vector<int>(1,1));//初期値を1として関数に送ることで、関数が問題なく処理する
  cout << ans << endl;
}


Measured memory_bytes: 3612
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    for(int i=a;i<=b;i++){
        int s[5];
        int x=i;
        for(int j=0;j<5;j++){
            s[j]=x%10;
            x/=10;
        }
        if(s[0]==s[4]&&s[1]==s[3])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
using namespace std;
#define ll long long
#define MAX 2002
inline int read()
{
	int x=0;bool t=false;char ch=getchar();
	while((ch<'0'||ch>'9')&&ch!='-')ch=getchar();
	if(ch=='-')t=true,ch=getchar();
	while(ch<='9'&&ch>='0')x=x*10+ch-48,ch=getchar();
	return t?-x:x;
}
struct Line{int v,next;}e[MAX<<1];
int h[MAX],cnt=1;
inline void Add(int u,int v){e[cnt]=(Line){v,h[u]};h[u]=cnt++;}
int n,K,dep[MAX],tot,ans=1e9;
void dfs(int u,int ff)
{
	dep[u]=dep[ff]+1;
	if(dep[u]>K/2)++tot;
	for(int i=h[u];i;i=e[i].next)
		if(e[i].v!=ff)dfs(e[i].v,u);
}
int main()
{
	n=read();K=read();
	for(int i=1;i<n;++i)
	{
		int u=read(),v=read();
		Add(u,v);Add(v,u);
	}
	dep[0]=-1;
	if(K%2==0)
		for(int i=1;i<=n;++i)tot=0,dfs(i,0),ans=min(ans,tot);
	else
		for(int u=1;u<=n;++u)
			for(int i=h[u];i;i=e[i].next)
				dep[e[i].v]=-1,tot=0,dfs(u,e[i].v),dep[u]=-1,dfs(e[i].v,u),ans=min(ans,tot);
	printf("%d\n",ans);
	return 0;
}


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

int main() {
    vector<vector<int>> A(3, vector<int>(3));
    bool bingo = false;
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> A[i][j];
        }
    }
    int N;
    cin >> N;
    vector<int> b(N);
    for (int i = 0; i < N; i++) {
        cin >> b[i];
    }
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 3; k++) {
                if (b[i] == A[j][k]) {
                    A[j][k] = 0;
                }
            }
        }
    }

    for (int i = 0; i < 3; i++) {
        if ((A[i][0] == A[i][2] && A[i][2] == A[i][1]) || (A[1][i] == A[2][i] && A[0][i] == A[1][i])) {
            bingo = true;
        }
    }

    if ((A[1][1] == A[2][2] && A[0][0] == A[1][1]) || (A[1][1] == A[0][2] && A[1][1] == A[2][0])) {
        bingo = true;
    }

    if (bingo) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

bool firstpred (const pair<int, int>&a, const pair<int, int>& b){
  if(a.second == b.second) return a.first < b.first;
  else return a.second > b.second;
}

int main(){
  int n, m;
  bool f;
  while(cin >> n >> m, n && m){
    pair<int, int> w[m];
    for(int i = 0 ; i < m ; i++){
      w[i].first = i+1;
      w[i].second = 0;
    }

    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < m ; j++){
	cin >> f;
	w[j].second += f;
      }
    }
    
    sort(w, w+m, firstpred);

    for(int i = 0 ; i < m ; i++){
      if(i == m-1) cout << w[i].first << endl;
      else cout << w[i].first << ' ';
    }
  }
  return 0;
}

Measured memory_bytes: 864
#include<bits/stdc++.h>
using namespace std;
const int MAXN = 1e4 + 5;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template <typename T> void chkmax(T &x, T y) {x = max(x, y); }
template <typename T> void chkmin(T &x, T y) {x = min(x, y); } 
template <typename T> void read(T &x) {
	x = 0; int f = 1;
	char c = getchar();
	for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
	for (; isdigit(c); c = getchar()) x = x * 10 + c - '0';
	x *= f;
}
template <typename T> void write(T x) {
	if (x < 0) x = -x, putchar('-');
	if (x > 9) write(x / 10);
	putchar(x % 10 + '0');
}
template <typename T> void writeln(T x) {
	write(x);
	puts("");
}
int tot, prime[MAXN], f[MAXN];
void sieve(int n) {
	for (int i = 2; i <= n; i++) {
		if (f[i] == 0) prime[++tot] = f[i] = i;
		for (int j = 1; j <= tot && prime[j] <= f[i]; j++) {
			int tmp = prime[j] * i;
			if (tmp > n) break;
			f[tmp] = prime[j];
		}
	}
}
set <int> ans;
int n, gcd, a[MAXN];
void factor(int x) {
	for (int i = 2; i * i <= x; i++)
		while (x % i == 0) {
			x /= i;
			ans.insert(i);
		}
	if (x != 1) ans.insert(x);
}
void update(int &x, int y, int p) {
	x = (x + y) % p;
}
void test(int p) {
	static int sum[MAXN];
	for (int i = 0; i <= p - 2; i++)
		sum[i] = 0;
	for (int i = 0; i <= n; i++)
		update(sum[i % (p - 1)], a[i], p);
	for (int i = 0; i <= p - 2; i++)
		if (sum[i] != 0) return;
	ans.insert(p);
}
int main() {
	read(n), sieve(n);
	for (int i = n; i >= 0; i--) {
		read(a[i]);
		if (a[i] != 0) {
			int tmp = a[i];
			if (tmp < 0) tmp = -tmp;
			if (gcd == 0) gcd = tmp;
			else gcd = __gcd(gcd, tmp);
		}
	}
	factor(gcd);
	for (int i = 1; i <= tot; i++)
		if (a[0] % prime[i] == 0) test(prime[i]);
	for (auto x : ans)
		writeln(x);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define REP(i,n,N) for(int i=n;i<(int)N;i++)
#define p(S) cout<<(S)<<endl
using namespace std;
const int inf=1e9;

int main(){
	int n;
	cin>>n;
	int dp[100010],effect[100010];
	bool visited[100010];
	REP(i,0,n) cin>>effect[i];
	REP(i,1,n) {
		dp[i]=inf;
		visited[i]=false;
	}
	queue<int> q;
	dp[0]=0;
	visited[0]=true;
	q.push(0);
	//bfs
	while(!q.empty()){
		int now=q.front();q.pop();
		REP(i,1,7){
			int next=now+i;
			if(next>n-1) break;
			while(!visited[next]){
				visited[next]=true;
				if(effect[next]==0){
					dp[next]=dp[now]+1;
					q.push(next);
				}
				next+=effect[next];
			}
		}
		if(dp[n-1]<inf){
			break;
		}
	}
	p(dp[n-1]);
	return 0;
}

Measured memory_bytes: 4044
import java.util.*; 
class Main {
   public static void main(String[] args) {
      
        Scanner sc = new Scanner(System.in);
       int sam = sc.nextInt();
       int aaa = sc.nextInt();
       
       aaa = aaa * 2;
       int cnt = 0;
       if(aaa >= sam){
           System.out.print(0);
       }else{
           System.out.print(sam - aaa);
       }

     
   }
}


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

#define N_MAX 10000

int main(){

  int h, w, n, cnt=0, a[N_MAX], c[100][100];
  cin >> h >> w;
  cin >> n;
  cnt = h * w;

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


  int i=1, cntclr=a[i-1], j=0, k=0;

  while(cnt){
    if(cntclr==0){
      i++;
      cntclr=a[i-1];
    }

    c[k][j] = i;
    if(k%2==0 || k==0){
    if(j<w-1){
      j++;
    } else if(j==w-1){
      k++;
    }
    } else if(k%2!=0){
      if(j>0){
        j--;
      } else if(j==0){
        k++;
      }
    }
    cnt--;
    cntclr--;
  }

  for(int j=0; j<h; j++){
    for(int k=0; k<w; k++){
      cout << c[j][k] << " ";
    }
    cout << endl;
  }

  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] S = new int[n];
		for (int i = 0; i < n; i++) {
			S[i] = sc.nextInt();
		}
		int m = sc.nextInt();
		int[] T = new int[m];
		for (int j = 0; j < m; j++) {
			T[j] = sc.nextInt();
		}
	System.out.println(binSearch(S, n, T, m));
	}

	static int binSearch(int[] array, int n, int[] array1, int m) {
		int count = 0;
		for (int i = 0; i < m; i++) {
			int key = array1[i];
			int pl = 0;
			int pr = n - 1;
			do {
				int pc = (pr + pl) / 2;
			if (array[pc] == key) {
				count++;
				break;
			} else if (array[pc] < key){
				pl = pc + 1;
			} else {
				pr = pc - 1;
			}
			} while (pl <= pr);
		}
		return count;
	}
}


Measured memory_bytes: 69060
let n = read_int ()
let s = read_line ()
let t, u = ref s, ref ""
let f s x = let n = ref 0 in String.iter (fun c -> if c = x then incr n) s; !n
let l, r = while !u <> !t do u := !t; t := Str.(global_replace (regexp "()") "" !u) done; f !t ')', f !t '('
let _ = String.(Printf.printf "%s%s%s\n" (make l '(') s (make r ')'))

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  int A, B;
  cin >> A >> B;
  if(!(A == B)) {
    int q = min(A, B);
    int w = max(A, B);
    for(int i = 0; i < w; i++) {
      cout << q;
    }
  }
    else {
      for(int i = 0; i < B; i++) {
        cout << A;
      }
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;
ll A[200000];
ll sm(ll* A,ll n){
    ll s= 0;
    for (int i = 0; i < n; ++i) {
        s += A[i];
    }
    return s;
}
int main() {
    int n;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    ll sum_t = A[0];
    ll sum = accumulate(A, A+ n, 0ll);
    ll mi = abs(2*A[0] - sum);
    for (int i = 1; i < n-1; ++i) {
        sum_t += A[i];
        mi = min(abs(2*sum_t - sum), mi);
    }
    cout << mi << "\n";




}

Measured memory_bytes: 1792
#include "bits/stdc++.h"

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define out(ans) cout << ans << endl;
const long long mod = 1e9 + 7;

ll _gcd(ll a, ll b) {
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}

int main(){

  ll n;cin>>n;
  ll a[n+10];
  ll g;
  rep(i,n){
    cin>>a[i];
    g = _gcd(g, a[i]);
  }
  out(g);

  return 0;
}


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

const int INF = 80010;

int w,n,a[50010],s[50010],dp[50010];

bool check(int x){
	dp[1] = 1;
	int l = 0,r = 0;
	for(int i = 1;i <= n;i++){
		while(i > l && s[i] - s[l] + (i - l - 1) > w) l++;
		while(i > r && s[i] - s[r] + (i - r - 1) * x >= w) r++;
		dp[i + 1] = dp[i] + !!(dp[r] - dp[l]);
	}
	l = n;
	while(l >= 0 && s[n] - s[l] + n - l - 1 < w) l--;
	return dp[n + 1] - dp[l + 1];
}

void solve(){
	for(int i = 0;i < n;i++){
		scanf("%lld",&a[i]);
		s[i + 1] = s[i] + a[i];
	}
	int ng = 0,ok = INF;
	while(ok - ng > 1){
		int mid = (ok + ng) / 2;
		if(check(mid)) ok = mid;
		else ng = mid;
	}
	printf("%lld\n",ok);
}

signed main(){
	while(cin >> w >> n,n) solve();
}


Measured memory_bytes: 4356
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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


int main(){
    ll N;
    cin>>N;
    v A(N);
    rep(i,0,N)cin>>A[i];
    ll sum = 0;
    rep(i,0,N){
        sum += A[i];
        sum%=MOD;
    }
    sum += MOD;
    ll ans = 0;
    rep(i,0,N){
        sum -= A[i];
        sum += MOD;
        sum %= MOD;
        ans += (A[i] * sum) % MOD;
        ans %= MOD;
    }

    cout<<ans;
    return 0;
}

Measured memory_bytes: 4832
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		String[] tokens = in.nextLine().split("/");
		in.close();
		int year = Integer.parseInt(tokens[0]);
		int month = Integer.parseInt(tokens[1]);
		int day = Integer.parseInt(tokens[2]);
		boolean isHeisei = false;
		if (year <= 2018) {
			isHeisei = true;
		} else if (month <= 4) {
			isHeisei = true;
		}
		String result = isHeisei ? "Heisei" : "TBD";
		System.out.println(result);
	}

}

Measured memory_bytes: 21716
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int min(int a,int b){
  if(a<=b) return a;
  else return b;
}
int max(int a,int b){
  if(a>=b) return a;
  else return b;
}

int main(){
  int N;
  scanf("%d",&N);
  if(N < 1200) printf("ABC");
  if(N >= 1200 && N < 2800) printf("ARC");
  if(N >= 2800) printf("AGC");
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
 
int main(){
    int n,m,c;
     
    while(cin >> n >> m){
        vector<int> A,B,C;
        for(int i = n-1 ; i >= 0 ; i--){
            A.push_back(i);
        }
         
        bool flg = false;
        while(m--){
            if(flg){
                A.clear();
                for(int i = 0 ; i < C.size() ; i++){
                    A.push_back(C[i]);
                }
                reverse(A.begin(),A.end());
                B.clear();
                C.clear();
            }
             
            int s = A.size()-1;
            for(int i = s ; i >= s-n/2+1 ; i--){
                B.push_back(A[i]);
                A.pop_back();
            }
            reverse(B.begin(),B.end());
             
            int cnt = 0;
            cin >> c;
            while(C.size() != n){
                if(cnt%2==0){
                    int s = A.size()-1;
                    for(int i = s ; i >= s-c+1 ; i--){
                        if(i < 0) break;
                        C.push_back(A[i]);
                        A.pop_back();
                    }
                }
                else{
                    int s = B.size()-1;
                    for(int i = s ; i >= s-c+1 ; i--){
                        if(i < 0) break;
                        C.push_back(B[i]);
                        B.pop_back();
                    }
                }
                cnt++;
            }
             
            flg = true;
        }
        reverse(C.begin(),C.end());
        cout << C[0] << endl;
    }     
    return 0;
}

Measured memory_bytes: 3020
#include <cstring>
#include <iostream>
#include <vector>
#include <map>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef long long int64;
int P[400000];
int M[200000];

int main() {
	memset(P, 0, sizeof(P));
	memset(P, 0, sizeof(M));
	int N;
	cin >> N;
	int tmp;
	int64 ans = 0;
	for (int i = 0; i < N; ++i) {
		cin >> tmp;
		if (tmp < 200000) {
			++P[i+tmp];
			if (i-tmp > 0) ++M[i-tmp];
		}
	}
	for (int i = 1; i < N; ++i) {
		ans += (int64)P[i] * M[i];
	}
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 5988
#include <iostream>
#define inf 1e9

using namespace std;

int n;
int a[45], b[45], c[45];
int ma, mb;
int dp[45][405][405];

int main(void)
{
	cin >> n >> ma >> mb;
	for(int i = 1; i <= n; i++) cin >> a[i] >> b[i] >> c[i];
	
	for(int i = 0; i <= n; i++){
		for(int j = 0; j <= 400; j++){
			for(int k = 0; k <= 400; k++){
				dp[i][j][k] = inf;
			}
		}
	}
	dp[0][0][0] = 0;
	
	for(int i = 0; i < n; i++){
		for(int j = 0; j <= 400; j++){
			for(int k = 0; k <= 400; k++){
				if(j+a[i+1] <= 400 && k+b[i+1] <= 400){
					dp[i+1][j+a[i+1]][k+b[i+1]] = min(dp[i+1][j+a[i+1]][k+b[i+1]], dp[i][j][k] + c[i+1]);
				}
				dp[i+1][j][k] = min(dp[i+1][j][k], dp[i][j][k]);
			}
		}
	}
	
	int ans = inf;
	for(int i = 1; ; i++){
		int A = ma*i, B = mb*i;
		if(A > 400 || B > 400) break;
		ans = min(ans, dp[n][A][B]);
	}
	if(ans >= inf) ans = -1;
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 26880
#include <cmath>
#include <iostream>
using namespace std;
int main(int argc, char** argv) {
    int n; cin >> n;
    int X[n], Y[n], h[n];
    for (int i = 0; i < n; i++) cin >> X[i] >> Y[i] >> h[i];
    for (int x = 0; x <= 100; x++)
        for (int y = 0; y <= 100; y++) {
            int ht = -1, hu = 1<<30;
            bool ok = true;
            for (int i = 0; i < n; i++) {
                if (h[i] > 0) {
                    int h0 = h[i] + abs(X[i] - x) + abs(Y[i] - y);
                    if (ht >= 0 && ht != h0 || hu < h0) { ok = false; break; }
                    else { ht = h0; }
                } else {
                    hu = abs(X[i] - x) + abs(Y[i] - y);
                    if (ht >= 0 && hu < ht) { ok = false; break; }
                }
            }
            if (ok) {
                cout << x << ' ' << y << ' ' << ht << endl;
                return 0;
            }
        }
}


Measured memory_bytes: 256
from collections import deque
n=int(input())
d=[-1]*(n+1)
d[1]=0
v=[[] for i in range(n+1)]
for i in range(n):
  a=list(map(int,input().split()))
  v[a[0]]=a[2:]
q=deque()
q.append(1)
while len(q)>0:
  curr=q.popleft()
  for i in v[curr]:
    if d[i]==-1:
      d[i]=d[curr]+1
      q.append(i)
for i in range(1,n+1):
  print(f'{i} {d[i]}')


Measured memory_bytes: 6020
#include<stdio.h>


int main(void){
    int A,B;

    scanf("%d %d",&A,&B);

    if(A == 1)
         A = 14;
    if(B == 1)
         B = 14;

    if(A > B){
        printf("Alice\n");
    }else if(A < B){
        printf("Bob\n");
    }else
        printf("Draw\n");

    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,k;
  cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  sort(all(a));
  ll ans=0;
  rep(i,k){
    ans+=a[i];
  }
  COUT(ans);
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>	
#include <cmath>
#include <string>
#include<math.h>//���炵���̂Œ���
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define Cout(s) cout<<s<<endl
using namespace std;
typedef long long ll;
string Yes(bool b) { if (b) { return "Yes"; } else { return "No"; } }
string YES(bool b) { if (b) { return "YES"; } else { return "NO"; } }
//================================================

int a = 1, b = 0, c, d, n, k = 0, ans = 0;
string s, t;
int mod = 1000000007;

int main()
{
	vector<int> x(3);
	cin >> x[0] >> x[1] >> x[2]; sort(all(x));
	int sum = (x[2]-x[1])/2+(x[2]-x[0])/2;
	if ((x[2] - x[1]) % 2 + (x[2] - x[0]) % 2 == 2)sum += 1;
	else if ((x[2] - x[1]) % 2 + (x[2] - x[0]) % 2 == 1)sum += 2;
		
	cout << sum << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

#define rep(i,a) for(int i = 0 ; i < a ; i ++)
#define loop(i,a,b) for(int i = a ; i < b ; i ++)
#define vi vector<int>
#define vs vector<string>
#define pb push_back
using namespace std;

int main(void){
  int a,b;
  cin>>a>>b;
  bool f = false;
  f = f || (a+b)%3==0 || a%3 == 0 || b % 3 == 0;
  cout<<(f?"Possible":"Impossible")<<endl;
}

Measured memory_bytes: 256
var
  a1: integer;
  a2: integer;
  a3: integer;
  cost: integer;
begin
  readln(a1,a2,a3);
  cost := abs(a1 - a2) + abs(a2 - a3);
  if abs(a1 - a3) + abs(a3 - a2) < cost then cost := abs(a1 - a3) + abs(a3 - a2);
  if abs(a2 - a1) + abs(a1 - a3) < cost then cost := abs(a2 - a1) + abs(a1 - a3);
  if abs(a2 - a3) + abs(a3 - a1) < cost then cost := abs(a2 - a3) + abs(a3 - a1);
  if abs(a3 - a1) + abs(a1 - a2) < cost then cost := abs(a3 - a1) + abs(a1 - a2);
  if abs(a3 - a2) + abs(a2 - a1) < cost then cost := abs(a3 - a2) + abs(a2 - a1);
  writeln(cost);
end.

Measured memory_bytes: 128
N,M=map(int,input().split())
H=[list(map(int,input().split())) for i in range(N)]
C=[list(map(int,input().split())) for i in range(M)]

ans=[]
ith_checkpt=0

INF=float('inf')
tmp=INF

for i in range(N):
    tmp=INF
    for j in range(M):
        m=abs(H[i][0]-C[j][0])+abs(H[i][1]-C[j][1])
        if m==tmp:
            pass
        if m<tmp:
            tmp=m
            ith_checkpt=j+1
    ans.append(ith_checkpt)
            
for a in ans:
    print(a)

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

vector<vector<int>> e;
int N, M;

int path(int pos, vector<bool> memo) {
	memo[pos] = true;

	bool check = true;
	for (int i = 0; i < N; i++) {
		if (!memo[i]) check = false;
	}
	if (check) return 1; 

	int ret = 0;
	for (int i = 0; i < e[pos].size(); i++) {
		if (!memo[e[pos][i]]) {
			ret += path(e[pos][i], memo);
		}
	}
	return ret;
}

int main() {
	cin >> N >> M;
	e.resize(N);

	for (int i = 0; i < M; i++) {
		int a, b;
		cin >> a >> b;
		a--;  b--;
		e[a].push_back(b);
		e[b].push_back(a);
	}

	vector<bool> memo(N);
	fill(memo.begin(), memo.end(), false);
	memo[0] = true;
	cout << path(0, memo) << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
using namespace std;

typedef long long ll;
#define READ(a) int a; cin >> a;
#define READARR(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define READMAT(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}
#define pb(x) push_back(x)
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	READ(n);
    multiset <string> s;
    FOR (i, 1, n)
    {
        string x;
        cin >> x;
        sort(x.begin(), x.end());
        s.insert(x);
    }
    
    string prev = "8";
    int ans = 0;
    for (auto i: s)
    {
        if (i != prev) ans += (s.count(i) - 1) * s.count(i) / 2;
        prev = i;
    }
    
    cout << ans;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(v) v.begin(), v.end()
#define pb push_back
#define INF 1e9
using namespace std;

int main()
{
    int n;
    string s;
    cin>>n;
    cin>>s;
    if(n%2!=0){
        cout<<"No";
        return 0;
    }
    string s1=s.substr(0,n/2);
    string s2=s.substr(n/2,n-1);
    //cout<<s1<<" "<<s2<<endl;

    if(s1 == s2){
        cout<<"Yes";
    }else{
        cout<<"No";
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <sstream>
#include <iostream>
using namespace std;

void split(const char* input,int in_result[100]){
  string str{input};
  istringstream stream(input);
  string tmp;
  
  for(int i = 0; getline(stream, tmp, ' '); i++)
    in_result[i] = atoi(tmp.c_str()); 
}


int main(){
  int parson_num; 
  int game_num;

  scanf("%d",&parson_num);
  scanf("%d",&game_num);
  getchar();
 
  int write_names[game_num][parson_num]; 
  char tmp[6 * game_num + game_num];

  fgets(tmp,sizeof(tmp),stdin);
  int targets[100] = {}; 
  split(tmp,targets);

  for(int i = 0; i < game_num; i++){
    fgets(tmp,sizeof(tmp),stdin);
    split(tmp,write_names[i]);
  }

  int points[parson_num] = {};

  for(int i = 0; i < game_num; i++){
    for(int j = 0; j < parson_num; j++){
      if(write_names[i][j] == targets[i]) points[j]++;
      else points[targets[i] - 1]++;
    }
  }

  for(int i:points) printf("%d\n",i);
}     

Measured memory_bytes: 3332
def solve():
    _ABCD = input()
    ABCD = []
    for i in _ABCD:
        ABCD.append(int(i))
    if ABCD[0] + ABCD[1] + ABCD[2] + ABCD[3] == 7:
        print(_ABCD[0]+"+"+_ABCD[1]+"+"+_ABCD[2]+"+"+_ABCD[3]+"=7")
    elif ABCD[0] + ABCD[1] + ABCD[2] - ABCD[3] == 7:
        print(_ABCD[0]+"+"+_ABCD[1]+"+"+_ABCD[2]+"-"+_ABCD[3]+"=7")
    elif ABCD[0] + ABCD[1] - ABCD[2] + ABCD[3] == 7:
        print(_ABCD[0]+"+"+_ABCD[1]+"-"+_ABCD[2]+"+"+_ABCD[3]+"=7")
    elif ABCD[0] + ABCD[1] - ABCD[2] - ABCD[3] == 7:
        print(_ABCD[0]+"+"+_ABCD[1]+"-"+_ABCD[2]+"-"+_ABCD[3]+"=7")
    elif ABCD[0] - ABCD[1] + ABCD[2] + ABCD[3] == 7:
        print(_ABCD[0]+"-"+_ABCD[1]+"+"+_ABCD[2]+"+"+_ABCD[3]+"=7")
    elif ABCD[0] - ABCD[1] + ABCD[2] - ABCD[3] == 7:
        print(_ABCD[0]+"-"+_ABCD[1]+"+"+_ABCD[2]+"-"+_ABCD[3]+"=7")
    elif ABCD[0] - ABCD[1] - ABCD[2] + ABCD[3] == 7:
        print(_ABCD[0]+"-"+_ABCD[1]+"-"+_ABCD[2]+"+"+_ABCD[3]+"=7")
    elif ABCD[0] - ABCD[1] - ABCD[2] - ABCD[3] == 7:
        print(_ABCD[0]+"-"+_ABCD[1]+"-"+_ABCD[2]+"-"+_ABCD[3]+"=7")

solve()


Measured memory_bytes: 3064
import itertools
import math
n = int(input())
pos = []
for i in range(n):
    pos.append(list(map(int, input().split())))
perm = list(itertools.permutations(range(n)))
total = 0
for i in range(len(perm)):
    for j in range(1, len(perm[i])):
        pos_from = perm[i][j - 1]
        pos_to = perm[i][j]
        total += math.sqrt((pos[pos_to][0] - pos[pos_from][0]) ** 2 + (pos[pos_to][1] - pos[pos_from][1]) ** 2)
print(total / len(perm))

Measured memory_bytes: 80248
#include <iostream>

using namespace std;



int main(){

	int t;
	cin>>t;

	switch(t%10){

		case 0:printf("pon\n");break;

		case 1:printf("pon\n");break;

		case 2:printf("hon\n");break;

		case 3:printf("bon\n");break;

		case 4:printf("hon\n");break;

		case 5:printf("hon\n");break;

		case 6:printf("pon\n");break;

		case 7:printf("hon\n");break;

		case 8:printf("pon\n");break;

		case 9:printf("hon\n");break;

	} 

	return 0;

}

Measured memory_bytes: 3676
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
int inf=1000001000;
ll INF=1e18;
ll mod=1000000007;
ll MOD=INF;


int main() {
  int n,x,t;
  cin >> n >> x >> t;
  cout << (1+(n-1)/x)*t << endl;
}


Measured memory_bytes: 3628
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
int main(){
    int a, b;
    scanf("%d %d", &a, &b);

    if(a < b){
        for(int i = 0; i < b; ++i){
            printf("%d", a);
        }
    } else {
        for(int i = 0; i < a; ++i){
            printf("%d", b);
        }
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
)

const INF = 2000000001
const MAX_ELE = 250

var heapArray []int

func printParent(index int) {
	if index != 0 {
		fmt.Printf("parent key = %d, ", heapArray[(index-1)/2])
	}
}

func printLeft(parent int) {
	index := parent*2 + 1
	if index < 250 && heapArray[index] != INF {
		fmt.Printf("left key = %d, ", heapArray[index])
	}
}

func printRight(parent int) {
	index := parent*2 + 2
	if index < 250 && heapArray[index] != INF {
		fmt.Printf("right key = %d, ", heapArray[index])
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	scanner := bufio.NewScanner(os.Stdin)
	scanner.Split(bufio.ScanWords)
	heapArray  = make([]int, MAX_ELE)
	for i := 0; i < n; i++ {
		scanner.Scan()
		heapArray[i], _ = strconv.Atoi(scanner.Text())
	}
	for i := n; i < 250; i++ {
		heapArray[i] = INF
	}

	for i := 0; i < n; i++ {
		fmt.Printf("node %d: key = %d, ", i+1, heapArray[i])
		printParent(i)
		printLeft(i)
		printRight(i)
		fmt.Println()
	}
}


Measured memory_bytes: 1140
#include <stdio.h>

void insertion_sort() {
  int N;
  int A[1005];
  int i, j;

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

  for (i = 0; i < N; i++) {
    int v = A[i];

    for (j = i - 1; j >= 0 && v < A[j]; j--) {
      A[j + 1] = A[j];
    }
    A[j + 1] = v;

    for (j = 0; j < N; j++) {
      if (j != 0) {
        printf(" ");
      }
      printf("%d", A[j]);
    }
    printf("\n");
  }
}

int main(void) {
  insertion_sort();

  return 0;
}

Measured memory_bytes: 604
#include <iostream>
#include <vector>
#include <string>
#include <stack>

using namespace std;

int main() {
	string s;
	while (getline(cin,s)) {
		if (s == ".") {
			break;
		}
		string ss = "";
		for (int i = 0; i < s.size(); i++) {
			if (s[i] == '(') {
				ss += s[i];
			}
			if (s[i] == ')') {
				ss += s[i];
			}
			if (s[i] == '[') {
				ss += s[i];
			}
			if (s[i] == ']') {
				ss += s[i];
			}
		}
		int a, b;
		a = b = 0;
		stack<int> stk;
		bool hh = true;
		for (int i = 0; i < ss.size(); i++) {
			if (ss[i] == '(') {
				a++;
				stk.push(1);
			}
			if (ss[i] == ')') {
				a--;
				if (!stk.empty()) {
					int c = stk.top();
					stk.pop();
					if (c != 1) {
						hh = false;
						break;
					}
				}
				else {
					hh = false;
					break;
				}
			}
			if (ss[i] == '[') {
				b++;
				stk.push(2);
			}
			if (ss[i] == ']') {
				b--;
				if (!stk.empty()) {
					int c = stk.top();
					stk.pop();
					if (c != 2) {
						hh = false;
						break;
					}
				}
				else {
					hh = false;
					break;
				}
			}
		}
		if (!stk.empty()) {
			hh = false;
		}
		if (hh) {
			cout << "yes" << endl;
		}
		else {
			cout << "no" << endl;
		}
	}
	return 0;
}


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

typedef long long ll;
typedef pair<int, int> P;

int MOD = 1e9 + 7;
ll INF = 1e18;

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

int main(){
    int n, k; cin>>n>>k;
    vector<int> x(n+10);
    for(int i=0; i<n; i++) cin>>x[i];

    int ans=MOD;
    for(int i=0; i<=n-k; i++){
		if(x[i] < 0 && x[i+k-1] <= 0) ans = min(ans, -x[i]);
		else if(x[i] < 0 && x[i+k-1]>0){
			ans = min(ans, x[i+k-1] - x[i]*2);
			ans = min(ans, x[i+k-1]*2 - x[i]);
		}
		else ans = min(ans, x[i+k-1]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  cin >> N;
  for (int i = N; ; i++) {
    int tmp = i;
    int p = tmp % 10;
    int no = 0;
    while (tmp) {
      if (p != tmp % 10) {
        no = 1;
        break;
      }
      tmp /= 10;
    }
    if (no) continue;
    cout << i << endl;
    return 0;
  }    

  return 0;
}

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


using namespace std;


int main(){
	int h,w; cin >> h >> w;
	vector<vector<int> > cost(10,vector<int>(10,0));
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			cin >> cost[i][j];
		}
	}
	vector<vector<int> > field(h, vector<int>(w,0));
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> field[i][j];
		}
	}
	//cerr << "read" << endl;
	for(int i = 0; i < 10; i++){
		for(int j = 0; j < 10; j++){
			for(int k = 0; k < 10; k++){
				cost[j][k] = min(cost[j][k], cost[j][i] + cost[i][k]);
			}
		}
	}
	//cerr << "calc" << endl;
	int ans = 0;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			if(field[i][j] != 1 && field[i][j] != -1){
				ans += cost[field[i][j] ][1];
			}
		}
	}
	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define ull unsigned long long int
#define forn(i,n)for(ll i=0;i<(n);i++)
#define forn_rev(i,n)for(ll i=(n)-1;i>=0;i--)
#define for1n(i,n) for(ll i=1;i<=(n);i++)
#define ARRAY_SIZE(a) sizeof(a)/sizeof(*a)
#define MOD 1000000007
#define MAXN 1000005

using namespace std;

vector<ll> ans;

void recur(ll i,vector<ll> cost,vector<vector<ll>> arr,ll N,ll M,ll X){
    if(i<N){
        vector<ll> temp_cost=cost;
        forn(j,M+1){
            cost[j]+=arr[i][j];
        }
        bool exist=false;
        for1n(j,M){
            if(cost[j]<X){
                exist=true;
                break;
            }

        }
        if(exist){
            recur(i+1,cost,arr,N,M,X);
            recur(i+1,temp_cost,arr,N,M,X);
        }
        else{
            ans.push_back(cost[0]);
            recur(i+1,temp_cost,arr,N,M,X);
        }


    }


}


int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(NULL); cout.tie(NULL);
    ll T=1;
    //cin>>T;
    while(T--)
    {

       ll N,M,X;
       cin>>N>>M>>X;
       vector<ll> cost(M+1,0);
       vector<vector<ll>> arr(N,vector<ll>(M+1,0));
       forn(i,N) forn(j,M+1) cin>>arr[i][j];
       recur(0,cost,arr,N,M,X);
       if(ans.size()==0){
        cout<<-1;
        return 0;
       }
       cout<<*min_element(ans.begin(),ans.end());


    }



    return 0;
}

Measured memory_bytes: 3648
import java.util.*;
import java.util.Arrays;
import java.util.Set;
public class Main{
    public static void main(String[] args){
        Scanner sc=new Scanner(System.in);
        int A=sc.nextInt();
        int B=sc.nextInt();
        int C=A+B;
        if(C>=10){
            System.out.println("error");
        }else{
            System.out.println(C);
        }

}
        
        
    }


Measured memory_bytes: 21844
#include <stdio.h>
#include <stdlib.h>
int main(void){
	int x=0;
	int y=1;
	int a=0;
	int b=0;
	int c=0;
	int d=0;
	int e=0;
	int f=0;
	int g=0;
	int h=0;
	int i=0;
	scanf("%d",&x);
	while(x>=y){
		scanf("%d %d %d",&a,&b,&c);
		g=abs(b-e);
		h=abs(c-f);
		if(a-d<g){
			puts("No");
			return 0;
		}else{
			i=a-d-g;
			if(i<h){
				puts("No");
				return 0;
			}else{
				if((i-h)%2){
					puts("No");
					return 0;
				}else{
				}
			}
		}
		y++;
		d=a;
		e=b;
		f=c;
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 128
import qualified Data.ByteString.Char8 as BS
import Data.Maybe

readInt = fst . fromJust . BS.readInt

readIntList = map readInt . BS.words

getIntList = readIntList <$> BS.getLine

main = do
  as <- getIntList
  putStrLn $ if sum as >= 22 then "bust" else "win"


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

int deg[5];

int main()
{
	for (int i = 0; i < 3; i++) {
		int a, b;
		cin >> a >> b;
		deg[a]++;
		deg[b]++;
	}
	for (int v = 1; v <= 4; v++) {
		if (deg[v] == 3) {
			cout << "NO\n";
			return 0;
		}
	}
	cout << "YES\n";
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n, m, a, b, c[55];
int main() {
	cin>>n>>m;
	while(m--) {
		cin>>a>>b;
		c[a]++, c[b]++;
	}
	for(int i=1; i<=n; i++) cout<<c[i]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main()
{
	int n, k, *a=NULL, *b=NULL;
	int i, l, r, flag;
	scanf("%d%d", &n, &k);
	if ((a = (int *)malloc(sizeof(int) * n)) == NULL) return -1;
	if ((b = (int *)malloc(sizeof(int) * n)) == NULL) return -1;
	for (i = 0; i < n; i++) {
		scanf("%d", &a[i]);
	}
	while (k--) {
		memset(b, 0, sizeof(int) * n);
		for (i = 0; i < n; i++) {
			l = i - a[i];
			r = i + a[i] + 1;
			if (l < 0) l = 0;
			b[l]++;
			if(r < n) b[r]--;
		}
		flag = a[0] == b[0];
		a[0] = b[0];
		for (i = 1; i < n; i++) {
			b[i] += b[i - 1];
			if (b[i] < 0) {
				b[i] = b[i];
			}
			flag &= (a[i] == b[i]);
			a[i] = b[i];
		}
		if (flag) {
			break;
		}
	}
	for (i = 0; i < n; i++) {
		if (i > 0) printf(" ");
		printf("%d", a[i]);
	}
	puts("");
	return 0;
}


Measured memory_bytes: 3296
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main() {
	int N, M;
	cin >> N >> M;
	int Matrix[100][100];
	vector<int> b(M);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			int x;
			cin >> x;
			Matrix[i][j] = x;
		}
	}
	for (int i = 0; i < M; i++) {
		int x;
		cin >> x;
		b[i] = x;
	}
	vector<int> Mb(N);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			Mb[i] += Matrix[i][j] * b[j];
		}
		cout << Mb[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 3132
#include"bits/stdc++.h"

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, n) for (int i = 1; i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pi = pair<int, int>;
const ll INF = 1LL << 60;


int main() {
    int h, w;
    int ix = 0, iy = 0;
    int x[8] = { -1,0,1,1,1,0,-1,-1 };
    int y[8] = { -1,-1,-1,0,1,1,1,0 };
    cin >> h >> w;
    vector<string> vec(h);
    rep(i, h) {
        cin >> vec[i];
    }
    for (int k = 0; k < h;k++) {
        for (int i = 0; i < w; i++) {
            if (vec[k][i] == '.') vec[k][i] = '0';
        }
    }
    rep(i,w){
        rep(j,h) {
            if (vec[j][i] == '#') {
                rep(k, 8) {
                    ix = i + x[k]; iy = j + y[k];
                    if (ix < 0 || w <= ix || iy < 0 || h <= iy || vec[iy][ix] == '#')continue;
                    vec[iy][ix] = vec[iy][ix] + 1 ;
                }
            }
        }
    }

    for (auto s : vec)cout << s << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())//vectorの降順ソート
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
typedef tuple<ll, ll, ll> T;

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    string ans="Yes";
    REP(i,n){
        int t,x,y;
        cin>>t>>x>>y;
        if(x+y>t) ans="No";
        if((x+y)%2!=t%2) ans="No";
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using GraphI = vector<vector<int>>;
using GraphC = vector<vector<char>>;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  int A, B, K;
  cin >> A >> B >> K;
  int cnt = 0;
  for (int i = min(A, B); i >= 1; i--) {
    if (A % i == 0 && B % i == 0) {
      K--;
      if (K == 0) {
        cout << i << endl;
        return 0;
      }
    }
  }

  return 0;
}


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

#define rep(i, n) for(int i=0;i<n;i++)

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

    long long l, r;
    cin >> l >> r;

    long long mi = 2019;

    if (r - l >= 2019){
        cout << 0 << endl;
        return 0;
    }
    for (long long i = l; i < r; i++){
        for (long long j = i + 1; j <= r; j++){
            mi = min(mi, i*j%2019);
        }
    }

    cout << mi << endl;
    return 0;
} 

Measured memory_bytes: 764
(let ((n (read))
      (s (read-line))
      (m (make-hash-table :test 'equal :size 3))
      (ans 0))
  (loop :for c :across "RGB"
        :do (setf (gethash c m) 0))
  (loop :for c :across s
        :do (incf (gethash c m)))
  (setf ans (* (gethash #\R m) (gethash #\G m) (gethash #\B m)))
  (loop :for i :from 0 :to (- n 3)
        :do (loop :for j :from (1+ i) :to (1- n)
                  :do (let ((x (char s i))
                            (y (char s j))
                            (z))
                        (when (>= (1- n) (+ j (- j i)))
                          (setf z (char s (+ j (- j i))))
                          (if (char/= x y z)
                              (decf ans))))))
  (format t "~A~%" ans))


Measured memory_bytes: 24644
#include <iostream>
using namespace std;
int main() {
  int h , w ;
  while(1){
      cin >> h >> w;
      if ( h == 0 && w == 0) break;

      for (int i = 0 ; i < h ; i++){
          for (int j = 0; j < w; j++){
              if( (i + j)%2 ==0){
                  cout << '#';
              }else{
              cout << '.';  
              }
          }
          cout << '\n';
      }
      cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3120
<?php
$Sa = str_split(trim(fgets(STDIN)));
$countA = count($Sa);
$Sb = str_split(trim(fgets(STDIN)));
$countB = count($Sb);
$Sc = str_split(trim(fgets(STDIN)));
$countC = count($Sc);

$next = $Sa[0];
$usedA = 1;
$countA --;
$usedB = 0;
$usedC = 0;

for($i = 0;$i < 400;$i++){
if($next == "a"){
if($countA == 0){
echo "A" . PHP_EOL ;
$i = 500;
}else{
$next = $Sa[$usedA];
$usedA ++;
$countA --;
}
}elseif($next == "b"){
if($countB == 0){
echo "B" . PHP_EOL ;
$i = 500;
}else{
$next = $Sb[$usedB];
$usedB ++;
$countB --;
}
}else{
if($countC == 0){
echo "C" . PHP_EOL ;
$i = 500;
}else{
$next = $Sc[$usedC];
$usedC ++;
$countC --;
}
}
}

Measured memory_bytes: 3832
#include <stdio.h>
#include <queue>
using namespace std;
int l[100001],r[100001];
int main()
{
    int n;
    scanf("%d",&n);
    long long ladd=0,radd=0;
    for (int i=1;i<=n;++i)
        scanf("%d%d",l+i,r+i);
    priority_queue<long long> pl;
    priority_queue<long long,vector<long long>,greater<long long>> pr;
    pl.push(l[1]);
    pr.push(l[1]);
    long long c=0;
    for (int i=2;i<=n;++i)
    {
        ladd+=r[i]-l[i];
        radd+=r[i-1]-l[i-1];
        long long il=pl.top()-ladd,ir=pr.top()+radd;
        if (l[i]<il)
        {
            c+=il-l[i];
            pr.push(il-radd);
            pl.pop();
            pl.push(l[i]+ladd);
            pl.push(l[i]+ladd);
        }
        else if (l[i]>ir)
        {
            c+=l[i]-ir;
            pl.push(ir+ladd);
            pr.pop();
            pr.push(l[i]-radd);
            pr.push(l[i]-radd);
        }
        else
        {
            pl.push(l[i]+ladd);
            pr.push(l[i]-radd);
        }
    }
    printf("%lld\n",c);
    return 0;
}


Measured memory_bytes: 2804
import bisect

a,b,q = map(int,input().split())
s = [0] * a
t = [0] * b
ans = []

for i in range(a):
    s[i] = int(input())
for j in range(b):
    t[j] = int(input())
for x in range(q):
    x = int(input())
    shr = bisect.bisect_left(s,x)
    if shr == 0:
        shrr = shr
    elif shr == a:
        shr = a - 1
        shrr = a - 1
    else:
        shrr = shr - 1
    
    tem = bisect.bisect_left(t,x)
    if tem == 0:
        temm = tem
    elif tem == b:
        tem = b - 1
        temm = b - 1
    else:
        temm = tem - 1
    
    can = []
    l = [[shr,tem],[shr,temm],[shrr,tem],[shrr,temm]]
    
    for i in range(4):
        can.append(min(abs(s[l[i][0]]-x)+abs(t[l[i][1]]-s[l[i][0]]),abs(t[l[i][1]]-x)+abs(s[l[i][0]]-t[l[i][1]])))
    
    ans.append(min(can))

for p in ans:
    print(p)



Measured memory_bytes: 16924
#include<algorithm>
#include<complex>
#include<ctype.h>
#include<iomanip>
#include<iostream>
#include<map>
#include<math.h>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<stdio.h>
#include<string>
#include<string>
#include<vector>

using namespace std;
typedef long long ll;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define pn(s) cout << (#s) << " " << (s) << endl

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    int H, W;
    cin >> H >> W;

    vector<string> S;

    FOR(i, 0, H){
        string s;
        cin >> s;
        S.push_back(s);
    }

	ll dx[4] = {1, 0, -1, 0};
    ll dy[4] = {0, 1, 0, -1};

    FOR(i, 0, H){
        FOR(j, 0, W){
            char c = S[i][j];
            if(c == '#'){
                // check around
                bool allWhite = true;
                FOR(k, 0, 4){
                    int nx = j + dx[k];
                    int ny = i + dy[k];
                    if(0<=nx && nx<W && 0<=ny && ny<H && S[ny][nx]=='#'){
                        allWhite = false;
                    }
                }
                if(allWhite){
                    p("No");
                    return 0;
                }
            }
        }
    }
    
    p("Yes");
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s,t;
int dp[3005][3005],ans,pre[3005][3005];
void print(int i,int j)
{
//	cout<<i<<' '<<j<<endl;
	if(i==0||j==0)return;
	if(pre[i][j]==0)print(i-1,j);
	else if(pre[i][j]==1)print(i,j-1);
	else print(i-1,j-1),cout<<s[i-1];
}
int main()
{
	cin>>s>>t;
	for(int i=1;i<=s.size();i++)
	{
		for(int j=1;j<=t.size();j++)
		{
			if(s[i-1]==t[j-1])dp[i][j]=dp[i-1][j-1]+1,pre[i][j]=2;
			if(dp[i][j]<max(dp[i-1][j],dp[i][j-1]))
			{
				if(dp[i-1][j]>dp[i][j-1])
				pre[i][j]=0;else pre[i][j]=1;
			}
			dp[i][j]=max(max(dp[i-1][j],dp[i][j-1]),dp[i][j]);
			ans=max(ans,dp[i][j]);
	//		cout<<pre[i][j]<<' ';
		}
	}
	print(s.size(),t.size());
//	cout<<ans<<endl;
	return 0;
}

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

using namespace std;

#define INF 1e9+5
int N,K;
vector<int> v;
vector<int> dp;

int main() {
    cin>>N;
    cin>>K;
    v.resize(N);
    dp.resize(N);
    for(int i=0;i<N;i++){
        cin>>v[i];
    }
    fill(dp.begin(),dp.end(),0);
    for (int i = 1; i < N; i++)
    {
        dp[i]=INF;
        for(int j = 1;j <= K; j++){
            if(i-j >= 0) dp[i] = min(dp[i],abs(v[i]-v[i-j])+dp[i-j]);
        }
    }
    cout<<dp[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    num = list(map(int, readline().strip()))

    for bits in range(1 << 3):
        tmp = num[0]
        for i in range(3):
            if bits & (1 << i):
                tmp += num[i + 1]
            else:
                tmp -= num[i + 1]
        if tmp == 7:
            ans = [str(num[0])]
            for i in range(3):
                if bits & (1 << i):
                    ans.append('+')
                else:
                    ans.append('-')
                ans.append(str(num[i + 1]))
            ans.append('=7')
            ans = ''.join(ans)
            break

    print(ans)
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9148