akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<math.h>
#define FOR(n) for(int i = 0;i < n;i++)
#define PRN(n) printf("%d\n",n)
#define PRS(s) printf("%s",s)
#define PRC(s) printf("%c",s)
int main(void){
  int n,cnt=0,a=0;
  scanf("%d",&n);
  char s[n+1];
  scanf("%s",s);
  FOR(strlen(s)){
    if(!cnt&&s[i]==')'){
      a++;
    }else if(s[i]==')'){
      cnt--;
    }else{
      cnt++;
    }
  }
  FOR(a)PRC('(');
  FOR(-cnt)PRC('(');
  PRS(s);
  FOR(cnt)PRC(')');
  return 0;
}
/*
scanf("%d",&n);
scanf("%d %d",&a,&b);
*/

Measured memory_bytes: 128
#include<iostream>

using namespace std;

int main(void){
  int a, b;
  cin >> a >> b;
  if(a > b){
    cout << 2 * a - 1 << endl;
  }else if (a < b){
    cout << 2 * b - 1 << endl;
  }else {
    cout << 2 * a << endl;
  }
  return 0;
}

Measured memory_bytes: 256
let z = 1000000007

let power m n =
  let rec doit m n acc =
    if n = 0 then acc
    else if n mod 2 = 0 then doit (m * m mod z) (n / 2) acc
    else doit m (n - 1) (acc * m mod z) in
  doit m n 1

let () =
  let (m, n) = Scanf.scanf "%d %d\n" (fun m n -> (m, n)) in
  Printf.printf "%d\n" (power m n)

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

int main() {
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = a; i <= b; i++) {
        string s = to_string(i);
        bool ok = true;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] != s[s.size() - 1 - i]) {
                ok = false;
                break;
            }
        }
        if (ok) {
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

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

int n,q,r[10000]={},p[10000],com,x,y;
int find(int x){
    if(x==p[x]){
        return x;
    }
    else{
       return p[x]=find(p[x]);
    }
}

void unite(int x,int y){
    x=find(x);
    y=find(y);
    if(r[x]<r[y]){
        p[x]=y;
    }
    else{
        p[y]=x;
        if(r[x]==r[y]){
            r[x]=r[x]+1;
        }
    }
}
int main(){
    cin>>n>>q;
    for(int i=0;i<n;i++){
        p[i]=i;
    }
    for(int i=0;i<q;i++){
        cin>>com>>x>>y;
        if(com==0){
            if(find(x)==find(y)){
                continue;
            }
            unite(x,y);
        }
        else{
            if(find(x)==find(y)){
                cout<<1<<endl;
            }
            else{
                cout<<0<<endl;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 3168
class BIT
  attr_reader :tree

  def initialize(n)
    @tree = Array.new(n + 1, 0)
  end

  def add(i, diff)
    while i < @tree.size
      @tree[i] += diff
      i += (i & -i)
    end
  end

  def sum(i)
    t = 0
    while i > 0 do
      t += @tree[i]
      i -= (i & -i)
    end
    return t
  end

  def [](i)
    s = @tree[i]
    if i > 0
      z = i - (i & -i)
      y = i - 1
      while y != z
        s -= @tree[y]
        y -= (i & -i)
      end
    end
    return s
  end
end


n, d, a = gets.chomp.split.map(&:to_i)

ms = []
n.times do
  ms.push gets.chomp.split.map(&:to_i)
end
ms = ms.sort_by { |x| x[0] }
ms.push [1<<60, 0]

dst = {}
(n).times do |i|
  x, _ = *ms[i]
  r = x + 2*d
  k = ms.bsearch_index { |m| m[0] > r }
  dst[i] = k
end

bit = BIT.new(n+1)

res = 0
n.times do |i|
  x, h = *ms[i]
  t = bit.sum(i + 1)
  h -= t
  next if h <= 0

  cnt = (h + a - 1) / a
  res += cnt
  damage = cnt * a

  bit.add(i + 1, damage)
  bit.add(dst[i] + 1, -damage)
end

puts res

Measured memory_bytes: 32420
#include <iostream>
 
using namespace std;
 
int main(void){
  int a,b,c,d,n;
  cin>>n;
  a=n/1000;
  b=n/100%10;
  c=n/10%10;
  d=n%10;
  for(int op1=0;op1<=1;op1++){
    int sum1=a;
    int sum2;
    if(op1==0) sum2=sum1+b;
    else sum2=sum1-b;
    for(int op2=0;op2<=1;op2++){
      int sum3;
      if(op2==0) sum3=sum2+c;
      else sum3=sum2-c;
      for(int op3=0;op3<=1;op3++){
        int sum4;
        if(op3==0) sum4=sum3+d;
        else sum4=sum3-d;
        if(sum4==7){
          string s1,s2,s3;
          if(op1==0) s1="+";
          else s1="-";
          if(op2==0) s2="+";
          else s2="-";
          if(op3==0) s3="+";
          else s3="-";
          cout<<a<<s1<<b<<s2<<c<<s3<<d<<"=7"<<endl;
          return 0;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	f := func() (a int) {
		fmt.Scan(&a)
		return
	}
	N := f();
	var S string;
	fmt.Scan(&S);
	not_turned := 0;
	if_turned := 0;
	for i := 0; i < N; i++ {
		// if leader
		if_learder := not_turned;
		if (S[i] == 'W') {
			not_turned++;
		} else { // E
			if_turned++;
		}
		//fmt.Println(i,if_turned,not_turned,if_learder);
		if if_turned > if_learder {
			if_turned = if_learder;
		}

	}
	fmt.Println(if_turned);

}


Measured memory_bytes: 2432
#define _USE_MATH_DEFINES
#include<iostream>
#include<sstream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<unordered_map>
#include<math.h>
#include<iterator>

using namespace std;

int main(){
  string s;
  cin >> s;
  bool is[4]={};
  for(auto it:s){
    if(it == 'N')is[0]=true;
    if(it == 'S')is[1]=true;
    if(it == 'W')is[2]=true;
    if(it == 'E')is[3]=true;
  }
  if(is[0]== is[1] && is[2] == is[3])cout << "Yes"<<endl;
  else cout << "No" <<endl;
  return 0;
}


Measured memory_bytes: 384
import Control.Monad
import Control.Applicative
import Data.List



main :: IO()
main = do
  s <- readLn :: IO Int
  print $ f (s, 1) []


f :: (Int, Int) -> [Int] -> Int
f (a, n) lst
    | a `elem` lst = n
    | even a = f (a `div` 2, n+1) (a:lst)
    | odd a  = f (3 * a + 1, n+1) (a:lst)


Measured memory_bytes: 508
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <utility>
#include <stack>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <climits>
#include <set>
#include <cmath>
#include <numeric>
#include <iomanip>

using namespace std;
int A[80][80];
int B[80][80];
const int LB = - 80 * 80 * 2;
const int UB = 80 * 80 * 2;
bool dp[80][80][4 * 80 * 80 + 2];
int main(){
  int H;
  int W;
  cin >> H >> W;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> A[i][j];
    }
  }
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> B[i][j];
    }
  }

  dp[0][0][A[0][0] - B[0][0] - LB] = true;
  dp[0][0][B[0][0] - A[0][0] - LB] = true;
  for(int i = 1; i < W; i++){
    for(int j = 0; j <= UB - LB; j++){
      int diff = A[0][i] - B[0][i];
      if(LB <= j + LB + diff && j + LB + diff <= UB){
        dp[0][i][j] |= dp[0][i - 1][j + diff];
      }
      if((LB <= j + LB - diff && j + LB - diff <= UB)){
        dp[0][i][j] |= dp[0][i - 1][j - diff];
      }
    }
  }

  for(int i = 1; i < H; i++){
    for(int j = 0; j < W; j++){
      for(int k = 0; k <= UB - LB; k++){
        int diff = A[i][j] - B[i][j];
        if(LB <= k + LB + diff && k + LB + diff <= UB){
          if(j > 0){
            dp[i][j][k] |= dp[i][j - 1][k + diff];
          }
          dp[i][j][k] |= dp[i - 1][j][k + diff];
        }
        if(LB <= k + LB - diff && k + LB - diff <= UB){
          if(j > 0){
            dp[i][j][k] |= dp[i][j - 1][k - diff];
          }
          dp[i][j][k] |= dp[i - 1][j][k - diff];
        }
      }
    }
  }
  int ans = INT_MAX;
  for(int i = 0; i <= UB - LB; i++){
    if(dp[H - 1][W - 1][i]){
      ans = min(ans, abs(i + LB));
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {
	int n;
	cin >> n;
	int a, b;
	vector<int> c(100005, 0);
	int maxi = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a >> b;
		c[a]++;
		c[b + 1]--;
		maxi = max(maxi, b);
	}
	int ans = 0;
	for (int i = 1; i <= maxi; ++i) {
		c[i] += c[i - 1];
		if (c[i] >= i - 1) ans = i - 1;
	}
	cout << ans << endl;

	return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define forn(i, a, n) for (int i = a; i < n; ++i)
#define ford(i, a, n) for (int i = n - 1; i >= a; --i)
#define fore(i, a, n) for (int i = a; i <= n; ++i)
#define all(a) (a).begin(), (a).end()
#define fs first
#define sn second
#define trace(a)\
	for (auto i : a) cerr << i << ' ';\
	cerr << '\n'
#define eb emplace_back

#ifndef M_PI
const ld M_PI = acos(-1.0);
#endif

const ld eps = 1e-9;
const int INF = 2000000000;
const ll LINF = 1ll * INF * INF;
const ll MOD = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n;
	cin >> n;
	vector<int> a(n);
	forn(i, 0, n) cin >> a[i];
	sort(all(a));
	vector<int> arithm = {a[0] - 1};
	bool toptwo = 1;
	forn(i, 1, n) {
		if (!toptwo) {
			if (a[i] == a[i - 1]) {
				toptwo = 1;
			} else if (a[i] % 2 == a[i - 1] % 2) {
				toptwo = 1;
				//arithm.pop_back();
				arithm.push_back(a[i] - 1 + i);
			} else {
				int sz = arithm.size();
				if (sz >= 2 && arithm[sz - 2] == arithm[sz - 1] - 1) {
					arithm.pop_back();
					arithm.push_back(a[i] - 1 + i);
					toptwo = 1;
				} else {
					toptwo = 1;
					arithm.push_back(a[i] - 1 + i);
				}
			}
		} else {
			if (a[i] == a[i - 1]) {
				toptwo = 0;
				arithm.back() += 2;
			} else if (a[i] % 2 == a[i - 1] % 2) {
				arithm.back() += 2;
				arithm.push_back(a[i] - 1 + i);
			} else {
				arithm.back() = a[i] - 1 + i;
			}
		}
	}
	//for (int i : arithm) cout << i << ' ';
	//cout << '\n';
	if (a[n - 1] == 1) {
		cout << (toptwo ? "Second\n" : "First\n");
		return 0;
	}
	for (int &i : arithm) i -= n - 1;
	for (int i : arithm) if (i >= 1) {
		cout << (i % 2 ? "First\n" : "Second\n");
		return 0;
	}
	return 1;
}

Measured memory_bytes: 1024
from math import sin, cos, pi

a, b, h, m = map(int, input().split())

time = h * 60 + m
half = 12 * 60
x_a = a * cos(2 * pi * time / half)
y_a = a * sin(2 * pi * time / half)
x_b = b * cos(2 * pi * m / 60)
y_b = b * sin(2 * pi * m / 60)
l = ((x_a - x_b) ** 2 + (y_a - y_b) ** 2) ** 0.5
print(l)

Measured memory_bytes: 9508
import java.util.*;
import java.io.*;
public class Main {
	private static BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
    private static int getInt() throws IOException{
    	int res=0;
    	boolean neg=false;
    	char ch=(char)br.read();
    	while(ch>'9'||ch<'0'){
    		if(ch=='-')
    			neg=!neg;
			try {ch=(char)br.read();}
			catch (Exception e) {e.printStackTrace();}
    	}
    	while(ch<='9'&&ch>='0'){
    		res=res*10+ch-'0';
    		try {ch=(char)br.read();}
			catch (Exception e) {e.printStackTrace();}
    	}
    	if(neg)return -1*res;
    	return res;
    }
	public static void main(String args[]) throws IOException{
		int n=getInt();
		while(n!=0){
			int sum=getInt();
			int ans=sum;
			for(int i=1;i<n;i++){
				int x=getInt();
				if(sum>0)sum+=x;
				else	sum=x;
				if(ans<sum)
					ans=sum;
			}
			n=getInt();
			System.out.println(ans);
		}
	}
}

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

#define _GLIBCXX_DEBUG
#define all(v) (v).begin(),(v).end()

using namespace std;

using ll=long long;
using pii=pair<int, int>;
using vi=vector<int>;

const ll INF=1LL<<60;
const int MOD=1e9+7;
const int N=1e9+5;

int main(){
    int X, N; cin >> X >> N;
    vi p(N);
    set<int> in;
    vi cnt(200, 0);
    for(int i=0; i<N; i++){
        cin >> p[i];
        in.insert(p[i]);
    }
    int res;
    int i=0;
    while(X+i <= 101){
        if(!in.count(X+i)){
            res=X+i;
            break;
        }
        i++;
    }
    i=0;
    while(X-i >= 0){
        if(!in.count(X-i) && i <= res-X){
            res=X-i;
            break;
        }
        i++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 3640
#include"iostream"
#include"stdio.h"
using namespace std;
const int Maxn=100005;
int a[Maxn];
int main()
{
//	freopen("text.in","r",stdin);
	int n,sum=0;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)
		if(a[i]==i)
		{
			int x1=0,x2=0;
			if(a[i-1]!=i)
				x1=1;
			if(a[i+1]!=i)
			{
				if(a[i+1]==i+1)x2=2;
				else x2=1;
			}
			if(x1>x2)swap(a[i],a[i-1]),sum++;
			else swap(a[i+1],a[i]),sum++; 
		}
	printf("%d",sum);
	return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<algorithm> 
#include<cstring>
#define ll long long
using namespace std;
int n,h,w,a[10005],map[105][105]; 
int read()
{
	int x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}
	return x*f;
}
int main()
{
	int x=1,y=1,f=1;
	h=read();w=read();n=read();
	for(int i=1;i<=n;i++)
	{
		a[i]=read();
		while(a[i]--)
		{
			if(y==0)x++,y=1,f=1;
			if(y==w+1)x++,y=w,f=-1;
			map[x][y]=i;
			y+=f;
		}
	}
	for(int i=1;i<=h;i++,printf("\n"))
		for(int j=1;j<=w;j++)
			printf("%d ",map[i][j]);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int main(){
	int sx,sy,tx,ty;
	string s,t;
	cin>>sx>>sy>>tx>>ty>>t;
	REP(i,tx-sx){
		s+="R";
	}
	REP(i,ty-sy){
		s+="U";
	}
	REP(i,tx-sx){
		s+="L";
	}
	REP(i,ty-sy){
		s+="D";
	}
	s+="D";
	REP(i,tx-sx+1){
		s+="R";
	}
	REP(i,ty-sy+1){
		s+="U";
	}
	s+="LU";
	REP(i,tx-sx+1){
		s+="L";
	}
	REP(i,ty-sy+1){
		s+="D";
	}
	s+="R";
	cout<<s<<endl;
	DEB(s.size())DEB(t.size())END
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

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

        int N = sc.nextInt();
        Long K = sc.nextLong();


        int[] graph = new int[N];


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

//        for (int i : graph) {
//            System.out.println(i);
//        }

        //訪れた頂点
        List<Integer> s = new ArrayList<Integer>();

        //
        Integer[] ord = new Integer[N + 1];

        //初期化
        Arrays.fill(ord, -1);

        //周期, 例外部分の長さ
        int c = 1; int l;

        int v = 1;
        while (ord[v] == -1) {
            ord[v] = s.size();
            s.add(v);
            v = graph[v-1];
        }
        c = s.size() - ord[v];
        l = ord[v];

        if (K < l) System.out.println(s.get(Math.toIntExact(K)));
        else {
            K -= l;
            K %= c;
            System.out.println(s.get((int) (l + K)));
        }
    }


}


Measured memory_bytes: 62540
#include<stdio.h>

int main(void){
  char s[101];
  long long k;
  
  scanf("%s %lld",s,&k);
  
 for(long long i = 0;i < k;i ++){
   if(s[i] != '1'){
     printf("%c",s[i]);
     return 0;
   }
 }
   
   puts("1");
   
   return 0;
 }
  
   
   


Measured memory_bytes: 128
#![allow(non_snake_case)]

use std::io::*;

#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

pub fn main() {
    let line = rl();
    let mut A = line
        .trim_right()
        .split_whitespace()
        .map(|x| x.parse().unwrap())
        .collect::<Vec<i32>>();
    A.sort();
    println!("{}", A.last().unwrap() - A[0]);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
 
int main(){
	int m,nmin,nmax;
	while(cin >> m >> nmin >> nmax,m){
		vector<int> v(m);
		for(int i=0;i<m;i++){
			cin >> v[i];
		}
		int n = 0;
		int maxi = 0;
		for(int unsigned i=nmin-1;i<nmax;i++){
			if(v[i] - v[i+1] >= maxi){
				n = i+1;
				maxi = v[i] - v[i+1];
			}
		}
		cout << n << endl;
	}
	return 0;
}

Measured memory_bytes: 3088
n=int(input())
a=list(map(int,input().split()))

cnt = 0

for i in range(1,n-1):
    if a[i-1] < a[i] and a[i] < a[i+1]:
        cnt += 1
    elif a[i-1] > a[i] and a[i] > a[i+1]:
        cnt += 1
    else:
        continue

print(cnt)

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<queue>

using namespace std;

struct State{
  int pos,t;
  State(){}
  State(int pos, int t):pos(pos),t(t){}
  bool operator < (const State& s) const { return t > s.t;}
};

const int MAX = 100000;
const int INF = (1<<25);
int M[MAX],T[MAX];
int n;

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

void solve(){
  fill(T,T+MAX,INF);
  
  priority_queue<State> Q;
  T[0] = 0;
  Q.push(State(0,0));

  while(!Q.empty()){
    State now = Q.top();
    Q.pop();
    
    if(T[now.pos] < now.t) continue;

    for(int i = 1; i <= 6; i++){
      State nex;
      nex.pos = (now.pos+i)%n;
      nex.t = now.t+1;

      while(1){
	if(T[nex.pos] > nex.t){
	  T[nex.pos] = nex.t;
	}else break;
	
	if(M[nex.pos] == 0){
	  Q.push(nex);
	  break;
	}

	nex.pos += M[nex.pos];
      }
    }
  }
  cout << T[n-1] << endl;
}
int main(){
  input();
  solve();
  return 0;
}

Measured memory_bytes: 1988
n=int(input())
A=list(map(int,input().split()))
q=int(input())
B=[0 for i in range(10**5)]
for a in A:
    B[a-1]+=1
suma=sum(A)
for i in range(q):
    b,c=map(int,input().split())
    print(B[b-1]*(c-b)+suma)
    suma+=B[b-1]*(c-b)
    B[c-1]+=B[b-1]
    B[b-1]=0

Measured memory_bytes: 21156
S = list(input())
N = len(S)
start = 0
end = 0
ans = [0]*N

for i in range(1,N):
    if S[i-1] == S[i]:
        continue
    elif S[i-1] == 'R' and S[i] == 'L':
        r = i-1
        l = i

    elif S[i-1] == 'L' and S[i] == 'R':
        end = i-1

        ans[r] = int((r-start+2)/2) + int((end-l+1)/2)
        ans[l] = int((end-l+2)/2) + int((r-start+1)/2)
        start = i

end = N-1
ans[r] = int((r-start+2)/2) + int((end-l+1)/2)
ans[l] = int((end-l+2)/2) + int((r-start+1)/2)

for a in ans:
    print(a, end=' ')
print("")

Measured memory_bytes: 10628
#include<stdio.h>
#include<string.h>
 
int main(void){
 
  int n,k;
  char s[n];
  scanf("%d %d",&n,&k);
  scanf("%s",s);
  if(s[k-1]>=65&&s[k-1]<=90){
    s[k-1]=s[k-1]+32;
  }
  /* 変換した文字列を出力 */
  printf("%s\n", s);
 
  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(void)
{
	int a, b;
	scanf("%d%d", &a, &b);
	if ((a + b) % 2 == 1) printf("%d\n", (a + b + 1) / 2);
	else printf("%d\n", (a + b) / 2);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
 
using namespace std;
 
 
#define mod(cans) cans%10**9+7
#define debug(x) cout << "Debug" << x << "\n"
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define cin_pl(n,x) rep(i,n){cin>>x[i];}
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define prians(Answer) cout<<Answer<<"\n"
#define TF(X) X==1?cout<<"Yes\n":cout<<"No\n"
#define elcon else{continue;}
 
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<vector<int>> matrix;
typedef pair<int,int> pii;
typedef vector<pii> vpi;
typedef greater<int> gi;
typedef vector<unsigned> vu;


ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
bool is_prime(const unsigned n){
    switch(n){
        case 0:
        case 1: return false;
        case 2: return true;
    }
 
 
    for(unsigned i=2;i<n;++i){
        if(n%i == 0) return false;
    }
 
    return true;
}

int main()
{
    vi m(2),d(2);
    rep(i,2){cin>>m[i]>>d[i];}
    d[1]-d[0]==1?cout<<0:cout<<1;

}

Measured memory_bytes: 256
// You may see me struggle,but you will never see me quit!
#include <bits/stdc++.h>
 using namespace std;
#define FIO                     ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define mod                     1000000007
#define eps                     1e-9
#define setbits                 __builtin_popcount
#define gcd                     __gcd
#define rep(i,a,b)              for(int i=a;i<=b;i++)
#define repr(i,b,a)             for(int i=b;i>=a;i--)
#define forn(i,n)               for(int i=0;i<n;i++)
#define all(a)                  a.begin(), a.end()
#define pb                      push_back
#define endl                    "\n"
#define ff                      first
#define ss                      second
#define asort(c)                sort(all(c)) 
#define lbpos(x,v)              (int)(lower_bound(all(v),x)-v.begin())//=v.size()==>No LB 
#define ubpos(x,v)              (int)(upper_bound(all(v),x)-v.begin())//=v.size()==>No UB
#define PI                      3.14159265358979323846
#define int                     long long
typedef  vector<int>                 vi;
typedef  pair<int, int>              ii;
typedef  vector<ii>                 vii;
typedef  long double                 ld;
#define debug(...) ZZ(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1> void ZZ(const char* name, Arg1&& arg1){std::cerr << name << " = " << arg1 << endl;}
template <typename Arg1, typename... Args>void ZZ(const char* names, Arg1&& arg1, Args&&... args)
{
  const char* comma = strchr(names + 1, ',');
  std::cerr.write(names, comma - names) << " = " << arg1;
  ZZ(comma, args...);
}
clock_t time_p=clock();
void timer()
{
    time_p=clock()-time_p;
    cerr<<"Execution Time: "<<(double)(time_p)/CLOCKS_PER_SEC<<"\n";
}


int32_t main()
{
  FIO;
 
  int n;
  cin>>n;
  if(n==22)
    cout<<"Christmas Eve Eve Eve";
  else if(n==23)
    cout<<"Christmas Eve Eve";
  else if(n==24)
    cout<<"Christmas Eve";
  else
    cout<<"Christmas";
  return 0;
}  

Measured memory_bytes: 256
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
b = [int(input()) for i in range(n)]
set(b)

bingo = 0
checker = 0

for i in range(len(b)):
  for j in range(3):
    for k in range(3):
      if a[j][k] == b[i]:
        a[j][k] = "o"
        checker += 1

if checker > 0:       
  for l in range(3):
    if a[l].count("o") == 3:
      bingo += 1
    if a[0][l] == a[1][l] == a[2][l] == "o":
      bingo += 1
  if a[0][0] == a[1][1] == a[2][2] == "o":
    bingo += 1
  if a[0][2] == a[1][1] == a[2][0] == "o":
    bingo += 1
    
if bingo > 0:
  print("Yes")
else:
  print("No")

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

using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

ll N;
vector<P> v;

int main(){
    cin >> N;
    for(int i=0;i<N;i++){
        ll x,y;
        cin >> x >> y;
        v.push_back({x,y});
    }
    sort(v.begin(),v.end());
    map<P,ll> m;
    for(int i=0;i<N;i++){
        set<P> s;
        for(int j=i+1;j<N;j++){
            s.insert({v[i].first-v[j].first,v[i].second-v[j].second});
        }
        for(auto &e : s) m[e]++;
    }
    ll max_v = 0;
    for(auto &e : m){
        ll t = e.second;
        max_v = max(t,max_v);
    }
    cout << N - max_v  << endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <string>
#define cinf(n,x) for(int i=0;i<(n);i++) cin >> x[i];
typedef long long int ll;
using namespace std;
int cnt[100010];
int main(){
	int n; cin>>n; 
	string s; cin >>s;
	int cnt=0;
	for(int i=n-1;i>=0;i--){
		if(s[i]=='('){
			if(cnt==0) s+=')';
			else cnt--;
		}
		else cnt++;
	}
	for(int i=0;i<cnt;i++){
		cout << '(';
	}
	cout << s << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
#define endl '\n'
#define fi first
#define se second
#define MOD(n,k) ( ( ((n) % (k)) + (k) ) % (k))
#define forn(i,n) for (int i = 0; i < n; i++)
#define forr(i,a,b) for (int i = a; i <= b; i++)
#define all(v) v.begin(), v.end()
#define pb push_back
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ll> vl;
typedef vector<ii> vii;



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

	int a, b;
	cin >> a >> b;
	cout << max(0, a - 2 * b) << endl;

	return 0;
} 

Measured memory_bytes: 256
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val List(n, m) = sc.nextLine.split(" ").map(_.toInt).toList
  val a = List.fill(n){
    sc.nextLine.split(" ").tail.map(_.toInt)
  }

  val ans = a.flatten.groupBy(identity).mapValues(_.size).toList.filter(_._2 == n).size

  println(ans)
}


Measured memory_bytes: 27216
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int r, g;
	cin >> r >> g;
	print(2 * g - r);





	return 0;
}

Measured memory_bytes: 256
S = input()
l, r = map(int, [S[:-2], S[2:]])

if 0 < l < 13:
    if 0 < r < 13:
        print('AMBIGUOUS')
        exit()
    else:
        print('MMYY')
else:
    if 0 < r < 13:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define e1 first
#define e2 second
#define pb push_back
#define mp make_pair
#define boost ios_base::sync_with_stdio(false)
#define eb emplace_back
#define OUT(x) {cout << x; exit(0); }
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define scanf(...) scanf(__VA_ARGS__)?:0
typedef long long int ll;
typedef unsigned long long ull;
typedef pair <int, int> PII;
typedef pair <ll, ll> PLL;
typedef pair <PLL, int> PLLI;
typedef pair <PLL, PLL> PP;
typedef pair <PII, int> PPI;
typedef pair <ll, int> PLI;
typedef unsigned int ui;
const int inf = 1e9+9;
const int mod = 1e9+7;
#define maxn 100100
int tab[maxn], n;

int main()
{
	boost;
	cin >> n;
	FOR(i, 1, n) cin >> tab[i];
	sort(tab+1, tab+n+1);
	
	PII cell = mp(n, 1);
	while (cell.e1 > 1 && tab[cell.e1] > cell.e2) cell.e2++, cell.e1--;
	if (tab[cell.e1] < cell.e2) cell.e2--, cell.e1++;
	if (tab[cell.e1 - 1] < cell.e2)
	{
		if ((tab[cell.e1] - cell.e2) % 2 == 0) cout << "Second";
		else cout << "First";
		exit(0);
	}
	else
	{
		int LT = cell.e1 - 1;
		while (tab[LT - 1] == cell.e2) --LT;
		int rng = cell.e1 - LT;
		if (rng % 2 == 1 || (tab[cell.e1] - cell.e2) % 2 == 1) cout << "First";
		else cout << "Second";
	}
}


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

const int64_t MOD = 1e9+7;
void add(int64_t& a, int64_t b){
    a = (a+b) % MOD;
}

int nth_bit(int64_t num, int n){
    return (num >> n) & 1;
}

int64_t num[8][8], dp[101][8];

int main(){
    int H, W, K;
    cin >> H >> W >> K;

    for(int bits=0; bits<(1<<(W-1)); bits++){
        bool ok = true;
        for(int i=0; i<W-2; i++){
            if(nth_bit(bits, i) && nth_bit(bits, i+1)){
                ok = false;
                break;
            }
        }
        if(!ok) continue;

        vector<int> P(W);
        for(int i=0; i<W; i++) P[i] = i;
        for(int i=0; i<W-1; i++){
            if(nth_bit(bits, i)) swap(P[i], P[i+1]);
        }
        for(int i=0; i<W; i++) num[i][P[i]]++;
    }

    dp[0][0] = 1;
    for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
            for(int k=0; k<W; k++){
                add(dp[i+1][k], dp[i][j] * num[j][k] % MOD);
            }
        }
    }

    cout << dp[H][K-1] << endl;
    return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())

# 階上の計算
from math import factorial
from collections import defaultdict

def prime_decomposition(n):
  i = 2
  table = defaultdict(int)

  while i * i <= n:
    while n % i == 0:
      n /= i
      table[i] += 1
    i += 1

  if n > 1:
    table[n] += 1

  return list(table.values())


def nHr(n, r):
    return factorial(n+r-1) // (factorial(r) * factorial(n-1))


mod = 10 ** 9 + 7

ans = 1

prim_d_num = prime_decomposition(M)

for p in prim_d_num:
    ans *= nHr(p+1, N-1)

print(ans % mod)


Measured memory_bytes: 114268
import numpy as np
from numba import njit
MOD = 10**9 + 7

def main():
 
    N = int(input())
    aff = np.array([list(map(int, input().split())) for i in range(N)], dtype='int32')
    dpt = np.zeros((N+1, 1<<N), dtype='int64')
    dpt[0][0] = 1

    print(solve(N, aff, dpt))

#@njit(cache=True)
def solve(N, aff, dpt):
    for i, row in enumerate(aff):
        for idx, v in enumerate(row):
            if v == 1:
                dpt[i+1][(1<<idx):] += dpt[i][:-(1<<idx)]
        dpt[i+1] %= MOD
    return dpt[N][(1<<N)-1]

if __name__ == '__main__':
    main()

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

using namespace std;  

int n;
int main() {
	scanf("%d", &n);
	int cnt1 = 0, cnt = 0;
	for(int i = 0, x; i < n; i++) {
		scanf("%d", &x);
		if(x & 1) cnt1++;
	}
	if(cnt1 % 2 == 0) printf("YES\n");
	else printf("NO\n");
	return 0;
} 

Measured memory_bytes: 384
#include<bits/stdc++.h>
#define STDIO
#define MOD 1000000007
#define testbit(mask,i) (((mask)>>(i))&1)
#define setbit(mask,i) ((mask)|(1<<i))
#define delbit(mask,i) ((mask)^(1<<i))
#define lowbit(x) ((x)&(-x))
#define INF MOD
using namespace std;
int a[4][4];
bool won[4][4];
int n;
int x;
int main(){
	#ifndef STDIO
		freopen("input.in","r",stdin);
		freopen("output.out","w",stdout);
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	for(int i=1;i<=3;i++)
		for(int j=1;j<=3;j++)
			cin>>a[i][j];
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>x;
		for(int j=1;j<=3;j++)
			for(int k=1;k<=3;k++)
				if(a[j][k]==x)
					won[j][k]=true;
	}
	for(int i=1;i<=3;i++){
		bool ok=true;
		for(int j=1;j<=3;j++)
			ok&=won[i][j];
		if(ok){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	for(int j=1;j<=3;j++){
		bool ok=true;
		for(int i=1;i<=3;i++)
			ok&=won[i][j];
		if(ok){
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	if(won[1][1]&&won[2][2]&&won[3][3])
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	if(won[1][3]&&won[2][2]&&won[3][1])
	{
		cout<<"Yes"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
package main

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

////////////////////////////////////////
///        templates                 ///
////////////////////////////////////////

var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
        sc.Scan()
        return sc.Text()
}

var rdr = bufio.NewReaderSize(os.Stdin, 1000000)

func readBigLine() string {
        buf := make([]byte, 0, 1000000)
        for {
                l, p, e := rdr.ReadLine()
                if e != nil {
                        panic(e)
                }
                buf = append(buf, l...)
                if !p {
                        break
                }
        }
        return string(buf)
}

func strSprit(str string) []string {
        cols := strings.Split(str, "/")
        return cols
}

func parseInt(str string) int {
        n, _ := strconv.Atoi(str)
        return n
}

func intSprit(str string) []int {
        strs := strSprit(str)
        cols := make([]int, len(strs))
        for i, v := range strs {
                cols[i] = parseInt(v)
        }
        return cols
}

func bitCount(n uint) int {

        x := uint64(n)

        const m = 1<<64 - 1
        const m0 = 0x5555555555555555
        const m1 = 0x3333333333333333
        const m2 = 0x0f0f0f0f0f0f0f0f

        x = x>>1&(m0&m) + x&(m0&m)
        x = x>>2&(m1&m) + x&(m1&m)
        x = (x>>4 + x) & (m2 & m)
        x += x >> 8
        x += x >> 16
        x += x >> 32

        return int(x) & (1<<7 - 1)
}

func bitExist(n, i int) bool {
        return ((n >> uint(i)) & 1) == 1
}

////////////////////////////////////////
///        end templates             ///
////////////////////////////////////////

func main() {
        line := nextLine()

        spl := intSprit(line)

        if spl[0] < 2019 {
                fmt.Println("Heisei")
                return
        } else if spl[0] > 2019 {
                fmt.Println("TBD")
                return
        }
        if spl[1] <= 4 {
                fmt.Println("Heisei")
        } else {
                fmt.Println("TBD")
        }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
string s,tem="",tem2="";
int ans=1;
int main(){
	int i;
	cin>>s;
	tem+=s[0];
	for(i=1;i<=s.size();i++)
	{
		if(tem2!=""&&tem2!=tem)
		{
			ans++;
			//cout<<tem2<<endl;
			tem=tem2;
			tem2="";
		}
		if(i==s.size())
		{
			break;
		}
		tem2+=s[i];
	}
	cout<<ans<<endl;
	return 0;
}

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

int gcd(int A,int B){
    long R=A%B;
    while(R>0){
        A = B;
        B = R;
        R = A%B;
    }
    return(B);
}

int main(){
    long A,B;
    cin >> A >> B;
    //cout << gcd(A,B) << endl;
    cout << (A*B)/gcd(A,B) << endl;

    return(0);
}

Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int n,q,i,key,lb,ub,mid;
  int S[100000],ans = 0;
 
  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d" , S + i);
  }
 
  scanf("%d" ,&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d" ,&key);
    lb = 0; ub = n;
    while(ub >= lb){
      mid = (lb + ub) / 2;
 
      if(S[mid] == key){
    ans++;
    break;
      }
 
      if(S[mid] < key){
    lb = mid+1;
      }else{
    ub = mid-1;
      }
    }
  }
  printf("%d\n" ,ans);
 
  return 0;
}


Measured memory_bytes: 2156
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int div_two(long n)
{
	int cnt = 0;
	while (n > 1)
	{
		if (n % 2 == 0)
		{
			n /= 2;
			cnt++;
		}
		else
			break;
	}
	return cnt;
}

int  main()
{
	int n;
	cin >> n;
	vector<long> a(n);
	rep (i, n)
		cin >> a[i];
	int cnt = 0;
	rep(i, n)
	{
		if(a[i] % 2 == 0)
			cnt += div_two(a[i]);
	}
	cout << cnt << endl;
	return (0);
}


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

#ifdef DEBUG
#define NDEBUG
#include "cout11.h"
#endif
#undef NDEBUG
#include <cassert>

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef pair<ll,ll> llll;
typedef pair<double,double> dd;

typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<ii> vii;
typedef vector<vector<ii>> vvii;
typedef vector<ll> vll;

#define sz(a)  int((a).size())
#define pb  push_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define found(s,e)  ((s).find(e)!=(s).end())
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))

#define W 100000

int main() {
    int N; cin >> N;
    map<int,int> s;
    rep(i,N){
        int Ai; cin >> Ai;
        ++s[Ai];
    }
    int cnt = 0;
    for (ii p : s) {
        if (p.second % 2) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4864
package main

import (
	"fmt"
	"strings"
)

func main() {
	s := make(map[string]string)
	var a, b, c string
	fmt.Scan(&a, &b, &c)
	s["a"] = a
	s["b"] = b
	s["c"] = c

	ans := ""
	p := "a"
	for {
		t := string(s[p][0])
		s[p] = s[p][1:]
		p = t
		if len(s[p]) == 0 {
			ans = strings.ToUpper(string(p))
			break
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include<cmath>
#define N 100005
#define A 1000005
#define MOD 1000000007 // //100000000 998244353 //
#define inf 1000000000000000000
#define ll long long
//#define M_PI 3.141592653589793238463

using namespace std;

#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second
#define pb push_back
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n-1; i >= 0; i--)
#define itr(it, x) for(auto it = x.begin(); it != x.end(); it++)
#define mem(a, b) memset(a, (ll)b, sizeof(a))
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define edge(v, x, y) v[x].pb(y); v[y].pb(x);
#define popcount __builtin_popcount
#define ANS(s) {cout << s << "\n"; return;}

//~~~~~~fancy print~~~~~~~//
#define printpii(a) cout << a.ft << " " << a.sd << endl;
#define printpiii(a) cout << a.ft << " " << a.sd.ft << " " << a.sd.sd << endl;
#define print(a, n) rep(i, n) cout << a[i] << " "; cout << endl;
#define printv(v) for(auto x: v)cout << x << " "; cout << endl;
#define printm(a, n, m) rep(i, n) { rep(j, m) cout << a[i][j] << "\t"; cout << endl;}

ll lx[4] = {0, 0, 1, -1};
ll ly[4] = {1, -1, 0, 0};
ll dx[8] = {0, 0, 1, -1, 1, -1, 1, -1};
ll dy[8] = {1, -1, 0, 0, 1, 1, -1, -1};
void fast(){ios_base::sync_with_stdio(false);cin.tie(0);cout << setprecision(12) << fixed;}
ll lcm(ll a, ll b) {return (a*b)/__gcd(a, b); }



void solve()
{
    ll n;
    cin >> n;
    vector<pii> v;
    rep(i, n)
    {
        ll x, y; cin >> x >> y;
        v.pb({y, x});
    }
    sort(all(v));
    ll t = 0;
    rep(i, n)
    {
        t += v[i].sd;
        if(t > v[i].ft) ANS("No");
    }
    ANS("Yes");
}

int main(){
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    fast();
    ll t = 1; //cin >> t;
    while(t--){
        solve();
    }
    return 0;
}


Measured memory_bytes: 6512
#include <stdio.h>
#include <stdlib.h>

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

void empty(int *,int *);
void swap(int *,int *);
int cal();
int dfs(int ,int ,int ,int ,const int );

 
int main() {
  int i,j,ans,x,y,l;
       
  for(i=0; i<3; i++) for(j=0; j<3; j++) scanf("%d",&puz[i][j]);

        
  empty(&x,&y);
  for(l=0; l<100; l++){
    for(i=0; i<3; i++){
      for(j=0; j<3; j++) tmp[i][j] = puz[i][j];
    }
           
    ans = dfs(x,y,-1,0,l);
    if(ans!=-1){
      printf("%d\n",ans);
      break;
    }
           
    for(i=0; i<3; i++){
      for(j=0; j<3; j++) puz[i][j] = tmp[i][j];
    }
           
    ans = -1;
    if(l==99) printf("%d\n",ans);
  }
       
  return 0;
}

void empty(int *x,int *y) {
  int i,j;
  for(i=0; i<3; i++) {
    for(j=0; j<3; j++) {
      if(!puz[i][j]) {
	*x = j;
	*y = i;
	return;
      }
    }
  }
}
void swap(int *a,int *b){
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}   

int cal(){
  int i,a,sum=0; 
  for(i=0; i<9; i++){
    a = puz[i/3][i%3];
    if(a){
      a--;
      sum += abs(i/3 - a/3) + abs(i%3 - a%3);
    }
  }    
  return sum;
}
int dfs(int x,int y,int p,int dep,const int lim){
  int i,h,nx,ny,res;   
  h = cal();
  if(h==0) return dep;
  if(dep+h>lim) return -1; 
  for(i=0; i<4; i++){
    nx = x+dx[i];
    ny = y+dy[i];      
    if(~p && i==(p+2)%4) continue;
    if(!(0<=nx && nx<3 && 0<=ny && ny<3)) continue;    
    swap(&puz[y][x],&puz[ny][nx]);
    res = dfs(nx,ny,i,dep+1,lim);
    if(~res) return res;       
    swap(&puz[y][x],&puz[ny][nx]);
  }   
  return -1;
}   
  


Measured memory_bytes: 2112
#include<iostream>
#include<bits/stdc++.h>
#include<iomanip>
#include<math.h>
#include<vector>
#include<cctype>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
std::string line;

int main(){

    int n,t,a;
    int h[1010];

    cin >> n;
    cin >> t >> a;
    rep(i,n) cin >> h[i];

    int ans;
    int res = 5000000;
    int restmp = 0;

    rep(i,n){
        restmp = t*1000 - h[i] * 6 - a*1000;

        if(restmp < 0) restmp = -restmp;
        if(res > restmp ) {
            res = restmp;
            ans = i+1;
            };
    };

    cout << ans << endl;

    return 0;
};




Measured memory_bytes: 256
#include<stdio.h>
int main(){
int a[1000000],aa=0,i;
for(i=0;aa<1;i++){
scanf("%d",&a[i]);
if(a[i]==0){
	aa=2;
}
}
for(int j=1;j<i;j++){
printf("Case %d: %d\n",j,a[j-1]);
}
return 0;
}

Measured memory_bytes: 1072
#include <stdio.h>
#include <algorithm>
#include <string>
#include <vector>
using namespace std;

const int mod = 1000000007;

int N; char S[3030];
vector<int> z;

long long inv[3030] = {0,1}, fact[3030] = {1,1}, ifact[3030] = {1,1};
long long prv[3030],nxt[3030];

int main()
{
	scanf ("%d",&N);
	scanf ("%s",S);

	int s = 1;
	for (int i=0;i<N-1;i++){
		if (S[i] == '<') s++;
		else{
			z.push_back(s);
			s = 1;
		}
	}
	z.push_back(s);

	for (int i=2;i<=N;i++){
		inv[i] = (mod - mod / i) * inv[mod % i] % mod;
		fact[i] = fact[i-1] * i % mod;
		ifact[i] = ifact[i-1] * inv[i] % mod;
	}

	prv[z.back()] = 1;
	z.pop_back();
	reverse(z.begin(),z.end());
	for (int x : z){
		for (int j=0;j<=N;j++) nxt[j] = 0;
		for (int j=0;j<=N;j++) if (prv[j]){
			nxt[j+x] = (nxt[j+x] + mod - prv[j]) % mod;
			nxt[x] = (nxt[x] + prv[j] * ifact[j]) % mod;
		}
		for (int j=0;j<=N;j++) prv[j] = nxt[j];
	}

	long long sum = 0;
	for (int j=0;j<=N;j++) sum = (sum + prv[j] * ifact[j]) % mod;
	printf ("%lld\n",sum*fact[N]%mod);
	return 0;
}

Measured memory_bytes: 384
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop
import copy
from test.support import _MemoryWatchdog

BIG_NUM = 2000000000
HUGE_NUM = 99999999999999999
MOD = 1000000007
EPS = 0.000000001
sys.setrecursionlimit(100000)


while True:

    table = list(map(int,input().split()))
    if len(table) == 1 and table[0] == 0:
        break

    num_1 = 0
    tmp_sum = 0
    for tmp in table:
        if tmp >= 11:
            tmp_sum += 10
        else:
            tmp_sum += tmp

        if tmp == 1:
            num_1 += 1

    if tmp_sum > 21:
        print(0)
    else:
        if num_1 == 0:
            print(tmp_sum)
        else:
            if tmp_sum <= 11:
                print(tmp_sum+10)
            else:
                print(tmp_sum)



Measured memory_bytes: 13888
#include <iostream>
#include <math.h>
#include <algorithm>
using namespace std;

int main()
{
    int m,n,o,i;
    string a;
    //cin>>m>>n>>o;
    cin>>a;
    for( int i=0;i<3;i++)
    {
        if(a[i]=='1') cout<<'9';
        else if(a[i]=='9') cout<<'1';
        else cout<<a[i];
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  int c1,c5,c10,c50,c100,c500;
  cin >> c1 >> c5 >> c10 >> c50 >> c100 >> c500;

  int total = c1+c5*5+c10*10+c50*50+c100*100+c500*500;

  if(total >= 1000){ cout << '1' << endl;
    }else{ cout << '0' << endl;}

   return 0;
}




Measured memory_bytes: 3128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define maxn 100005
#define Mod 1000000007
typedef pair<int,int> pii;
typedef map<int,int> mii;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<long long> vll;
typedef vector<bool> vb;
typedef set<int> si; 
#define fori(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,b,a) for(int i = (b); i >= (a); --i)
#define all(a) (a).begin(), (a).end()
#define __builtin_popcountll bitCountLL
#define __builtin_popcount bitCount
//__builtin_ctz 末尾0的个数, __builtin_clz 前导0的个数
//__builtin_ffs 最后一个1的位置
const int INF = 2e9;
const ll ML = 4e18;

void solve() {
    int n;
    cin >> n;
    vll res(n+1,1);
    fori(i,2,n+1) {
        for(int j = i; j <= n;j += i) {
            res[j]++;
        }
    }
    fori(i,2,n+1) res[i] = res[i-1] + res[i] * i;
    cout << res[n];
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
	//cout.precision(30); cout << fixed;
	//freopen("D:\\data_in.txt", "r", stdin);
    //solve();
    
    clock_t start,finish;
    start = clock();
    solve();
    finish = clock();
    //cout << "\n" << (double)(finish - start) / (double)(CLOCKS_PER_SEC) * 1000 << "ms" << endl;
    
    return 0;
}

/***************************************************************
 question:
 idea:
 tag:
 record:
 ***************************************************************/


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

int main(){
    string num;
    int sum;
    while(cin >> num && num != "0"){
        sum = 0;
        for (int i=0; i<num.size(); i++) sum += num[i] - '0';   //'0'(AScii Code 48) を引くことで文字を整数に変換
        cout << sum << endl;
    }
}


Measured memory_bytes: 3152
#include <stdio.h>
int main (){
	
	int N;
	int max = 0, H, count = 0;
	scanf("%d", &N);
	
	while(N--){
		scanf("%d", &H);
		if(H >= max ){
			count++;
			max = H;
		}
	}
	
	printf("%d", count);
	
	
	
	
	
	return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args){
    
    Scanner sc = new Scanner(System.in);
    int W = sc.nextInt();
    int H = sc.nextInt();
    int w = sc.nextInt();
    int h = sc.nextInt();
 
		System.out.println((W-w)*(H-h));	    
	}
}


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

#define DIV 1000000007
//高速べき乗(mod DIV)
long long mypow(long long k, long long n) {
	long long temp = 1;

	k = k % DIV;
	while (n) {
		if (n % 2) temp = temp * k % DIV;
		k = k * k % DIV;
		n = n / 2;
	}
	return temp % DIV;
}

//組み合わせ(mod DIV)
long long cmb(long long n, long long r) {
	long long x = 1, y = 1, y_inv;
	long long min;

	if (n - r > r) min = r;
	else min = n - r;
	if (min >= 0) {
		for (long long i = 0; i < min; i++) {
			x = x * (n - i) % DIV;
			y = y * (i + 1) % DIV;
		}
		y_inv = mypow(y, DIV - 2);
		return x * y_inv % DIV;
	}
	else return 0;
}

int main(void) {
	long long n, k;
	
	scanf("%lld %lld", &n, &k);
	
	for (long long i = 1; i <= k; i++) {
		printf("%lld\n", cmb(n - k + 1, i) * cmb(k - 1, i - 1)%DIV);
	}

	return 0;
}


Measured memory_bytes: 128
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#define rep(i,n) for (int i = 0; i < (n);i++)
typedef long long ll;
const int INF = 1001001001;
using namespace std;

int main() {
  int n; cin >> n;
  vector<int> l(n); rep(i,n) cin>>l.at(i);
  sort(l.begin(),l.end());
  int sum = 0;
  rep(i,n-1) sum+=l.at(i);
  if(sum>l.at(n-1)) cout<< "Yes" << endl;
  else cout<< "No" << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  string S;
  cin >> N >> S;
  int ans=0;
  vector<int> check(1000);
  for(int i=0; i<10; i++){
    check.at(i)=i;
  }
  for(int num=0; num<1000; num++){
    int k=num;
    int i=N-1;
    for(i; i>-1; i--){
      if(k%10==S.at(i)-'0') break;
    }
    if(i<2) continue;
    i--;
    k/=10;
    for(i; i>-1; i--){
      if(k%10==S.at(i)-'0') break;
    }
    if(i<1) continue;
    i--;
    k/=10;
    for(i; i>-1; i--){
      if(k%10==S.at(i)-'0'){
        ans++;
        break;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.BigInteger;
import java.util.*;


public class Main implements Runnable {

    private void solve() throws IOException {

        int N = nextInt();
        int D = nextInt();
        int[] d = new int[D];
        for(int i = 0; i < D; ++i) d[i] = nextInt();
        for(int s = N;; ++s) {
            if(isOk(s,d)) {
                writer.println(s);
                break;
            }
        }
    }

    private boolean isOk(int num, int[] d) {
        
        while(num > 0) {
            int m = (num % 10);
            for(int j = 0; j < d.length; ++j) if(d[j] == m) return false;
            num /= 10;
        }
        return true;
    }

    public static void main(String[] args) {

        new Main().run();
    }

    BufferedReader reader;
    StringTokenizer tokenizer;
    PrintWriter writer;

    public void run() {
        try {
            reader = new BufferedReader(new InputStreamReader(System.in));
//             reader = new BufferedReader(new FileReader("input.txt"));
            tokenizer = null;
            writer = new PrintWriter(System.out);
            solve();
            reader.close();
            writer.close();
        } catch (Exception e) {
            e.printStackTrace();
            System.exit(1);
        }
    }

    int nextInt() throws IOException {
        return Integer.parseInt(nextToken());
    }

    long nextLong() throws IOException {
        return Long.parseLong(nextToken());
    }

    double nextDouble() throws IOException {
        return Double.parseDouble(nextToken());
    }

    String nextToken() throws IOException {
        while(tokenizer == null || !tokenizer.hasMoreTokens()) {
            tokenizer = new StringTokenizer(reader.readLine());
        }

        return tokenizer.nextToken();
    }
}


Measured memory_bytes: 8404