akhauriyash/Code-Regression huggingface dataset:
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <cctype>    // isupper, islower, isdigit, toupper, tolower
#include <cstdint>   // int64_t, int*_t
#include <cstdio>    // printf
#include <deque>     // deque
#include <iomanip>   // setprecision
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <utility>       // pair, make_pair
#include <vector>        // vector
using namespace std;

int gcd(long long a, long long b) { return b != 0 ? gcd(b, a % b) : a; }

int main() {
    int N;
    cin >> N;
    int target = 1, sum = 0;
    for(size_t i = 0; i < N; i++) {
        int a;
        cin >> a;
        if(a == target) {
            target++;
        }else{
            sum++;
        }
    }
    if(target==1){
        sum = -1;
    }
    cout << sum << endl;
}

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

const int M=3e5+5;
int a[M],cnt[M];

int main()
{
	int n; scanf("%d",&n);
	int nu;
	for(int i=0;i<n;i++)
	{
		scanf("%d",&nu);
		a[nu]++;
	}
	for(int i=1;i<=n;i++)
		cnt[a[i]]++;
	int ans=n;
	int j=n;
	for(int i=1;i<=n;i++)
	{
		while(j>ans/i)
		{
			int ncnt=0;
			int tmp=ans/i;
			while(j>tmp)
			{
				ans-=(j-tmp)*cnt[j];
				ncnt+=cnt[j];
				j--;
			}
			cnt[j]+=ncnt;
		}
		printf("%d\n",ans/i);
	}
	return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+5;
queue<int>q;
int deg[N],n,m,ans,dist[N];
vector<int>v[N];
int main()
{
	cin>>n>>m;
	while(m--)
	{
		int a,b;
		cin>>a>>b;
		a--,b--;
		v[a].push_back(b);
		deg[b]++;
	}
	for(int i=0;i<n;i++)
		if(!deg[i])
			q.push(i);
	while(!q.empty())
	{
		int now=q.front();q.pop();
		for(int i=0;i<v[now].size();i++)
		{
			int to=v[now][i];
			dist[to]=max(dist[now]+1,dist[to]);
			ans=max(ans,dist[to]);
			deg[to]--;
			if(!deg[to])q.push(to);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6528
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

bool check(string& S, string& T, int idx)
{
  for (int i = 0; i < T.size(); i++) {
    if (i + idx >= S.size()) return false;
    if (S[i + idx] != T[i] && S[i + idx] != '?') return false;
  }
  return true;
}

int main()
{
  string S, T;
  cin >> S >> T;
  reverse(S.begin(), S.end());
  reverse(T.begin(), T.end());

  for (int i = 0; i < S.size(); i++) {
    if (check(S, T, i)) {
      for (int j = 0; j < T.size(); j++) {
        S[i + j] = T[j];
      }
      for (int i = 0; i < S.size(); i++) {
        if (S[i] == '?') S[i] = 'a';
      }
      reverse(S.begin(), S.end());
      cout << S << endl;
      return 0;
    }
  }
  cout << "UNRESTORABLE" << endl;

  return 0;
}


Measured memory_bytes: 256
<?php
// B
fscanf(STDIN, '%d', $n);
$c = intdiv($n, 7);
$ans = 'No';
for ($i = 0; $i <= $c; $i++) {
    if (($n - $i * 7) % 4 === 0) {
        $ans = 'Yes';
        break;
    }
}
echo $ans;

Measured memory_bytes: 4604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                    \
  ifstream in("abc179/abc179_e.txt"); \
  cin.rdbuf(in.rdbuf());
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#else
#define INPUT_FILE
#define print_vec(v)
#endif
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  ll N, X, M;
  cin >> N >> X >> M;

  unordered_map<ll, ll> m;
  vector<ll> c(M + 1, 0);

  ll ans = X;
  ll an = X;

  int start = -1, end = -1;
  c[0] = an;
  repi(i, 1, N) {
    an = (ll)(pow(an, 2)) % M;
    if (m.count(an)) {
      start = m[an];
      end = i;
      break;
    }
    ans += an;
    m.emplace(an, i);
    c[i] = an;
  }

  if (start != -1) {
    ll len = end - start;
    ll rest = (N - end) / len;
    ll mod = (N - end) % len;

    ll sum = 0;
    ll modsum = 0;
    int cnt = 0;
    repi(i, start, end) {
      sum += c[i];
      if (i - start < mod) modsum += c[i];
    }
    ans += sum * rest + modsum;
  }
  cout << ans << endl;
}

Measured memory_bytes: 5984
n,m,l = map(int,input().split())
A=[list(map(int,input().split()))for _ in[0]*n]
B=[list(map(int,input().split()))for _ in[0]*m]
C=[[sum([x[i]*y[i] for i in range(m)])for y in zip(*B)]for x in A]
for i in C:print(*i)


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

int main() {
  long long int a, b, c, x, y;
  cin >> a >> b >> c >> x >> y;
  long long int cnt = 0, out = 100000000000000;
  int i = 0, j = 0;
  int base = max(x, y);
  for (int k = 0; k <= base*2; k += 2) {
    i = x - k / 2;
    j = y - k / 2;
    if (i < 0) i = 0;
    if (j < 0) j = 0;
    cnt = i * a + j * b + k * c;
    out = min(out, cnt);
  }
  cout << out << endl;
  return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define DVSORT(v) sort(v.begin(), v.end(),greater<int>())
#define SORT(v, n) sort(v, v+n)
#define DSORT(v,n) sort(v, v+n,greater<int>())
#define vi vector<int>
#define pb push_back
#define P pair<int,int>


template <class T> void chmin(T&a, const T&b) { a = min(a,b); }
template <class T> void chmax(T&a, const T&b) { a = max(a,b); }

const double EPS =1e-9;
const long INF =999999999;
const long MOD =1000000007; //10^9+7
#define PI 3.14159265258979

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


int main(){
	int bell[3]={};
	REP(i,3) cin>>bell[i];
	SORT(bell,3);

	int result=bell[0]+bell[1];
	printf("%d\n",result);
	return 0;
}



Measured memory_bytes: 256
#include<cstdio>

int main(){
	int sum = 0;
	int temp = 0;
	char c;
	while(~scanf("%c",&c)){
		if('0' <= c && c <= '9'){
			temp *= 10;
			temp += c - '0';
		}else{
			sum += temp;
			temp = 0;
		}
	}
	sum += temp;
	printf("%d\n", sum);
}

Measured memory_bytes: 968
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
#define PI 3.141592653589793
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}
int gcd(int a, int b){//ユークリッドの互除法
  if (a < b) gcd(b,a); //aの方がbよりでかいのが前提
  if (b == 0) return a; //aをbで割り切れたらreturn
  else gcd(b, a % b);
}

const int MOD = 1000000007;
const int INF = 1<<30;

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

bool dp[85][85][85*85];
int a[85][85];

int main(){
  int h,w; cin >> h >> w;
  rep(i,h)rep(j,w) cin >> a[i][j];
  rep(i,h)rep(j,w){
    int tmp; cin >> tmp;
    a[i][j] = abs(a[i][j] - tmp);
  }
  dp[0][0][a[0][0]] = true;
  rep(i,h)rep(j,w)rep(k,85*85){  
    if((i >= 1 && dp[i-1][j][k])||(j >= 1 && dp[i][j-1][k])){
      dp[i][j][abs(k-a[i][j])] = true;
      if(k+a[i][j] < 85*85) dp[i][j][k+a[i][j]] = true;
    }
  }
  
  rep(k,85*85){
    if(dp[h-1][w-1][k]){
      cout << k << endl;
      break;
    }
  }
  return 0;
}

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

using namespace std;

void func(char *st, int i, int n, char last){
	//base case
	if(i == n){
		st[i]= '\0';
		cout<<st<<"\n";
		return;
	}
	//recursive case
	for(char j='a'; j<=last+1; j++){
		st[i] = j;
		func(st, i+1, n, max(j, last));
	}
}


int main(){
	int n;
	char st[11];
	cin>>n;
	func(st, 0, n, 'a'-1);
}

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

int main() {
  int n, min_w = 10000;
  cin >> n;
  vector<int> W(n), W_origin(n);
  deque<int> w_cycle;
  for (size_t i = 0; i < n; i++) {
    cin >> W[i];
    min_w = min(min_w, W[i]);
  }

  copy(W.begin(), W.end(), W_origin.begin());
  sort(W.begin(), W.end());

  int cost = 0;
  for (size_t i = 0; i < n; i++) {
    if (W[i] == -1) continue;
    int idx = i;
    while (true) {
      auto correspond_w = find(W.begin(), W.end(), W_origin[idx]);
      if (correspond_w == W.end()) break;
      w_cycle.push_back(*correspond_w);

      idx = distance(W.begin(), correspond_w);
      *correspond_w = -1;
    }

    int cost_inter, cost_ext;
    auto min_w_cycle = min_element(w_cycle.begin(), w_cycle.end());

    cost_inter = accumulate(w_cycle.begin(), w_cycle.end(), 0) +
                 *min_w_cycle * (w_cycle.size() - 2);
    cost_ext = accumulate(w_cycle.begin(), w_cycle.end(), 0) + *min_w_cycle +
               min_w * (w_cycle.size() + 1);

    cost += min(cost_ext, cost_inter);

    w_cycle.clear();
  }

  cout << cost << endl;
}


Measured memory_bytes: 3168
import java.util.*;
import java.io.*;

/**
 * Made by egor https://github.com/chermehdi/egor.
 * 
 * @author Azuz
 * 
 */
public class Main {

    void solve(Scanner in, PrintWriter out) {
      long[] a = new long[2];
      long[] b = new long[2];


      a[0] = in.nextInt();
      a[1] = in.nextInt();
      b[0] = in.nextInt();
      b[1] = in.nextInt();

      long ans = Long.MIN_VALUE;
      for (int i = 0; i < 2; ++i) {
        for (int j = 0; j < 2; ++j) {
          ans = Math.max(ans, a[i] * b[j]);

        }
      }

      out.println(ans);
    }

    public static void main(String[] args) {
        try(Scanner in = new Scanner(System.in);
            PrintWriter out = new PrintWriter(System.out)) {
            new Main().solve(in, out);
        }
    }
}


Measured memory_bytes: 35712
class UnionFind
	def initialize
		@obj_to_node = {}
	end

	def add(obj)
		@obj_to_node[obj] ||= Node.new(obj)
	end

	def size(x = nil)
		x ? @obj_to_node[x].root.size : @obj_to_node.size
	end

	def root(obj)
		(@obj_to_node[obj] ||= Node.new(obj)).root.obj
	end

	class Node
		def initialize(obj)
			@obj = obj
			@parent = self
			@size = 1
			@rank = 0
		end

		def root
			return self if @parent == self
			@parent = @parent.root
		end	

		attr_accessor :parent, :size, :rank
		attr_reader :obj
	end

	def union(x, y)
		u = (@obj_to_node[x] ||= Node.new(x)).root
		v = (@obj_to_node[y] ||= Node.new(y)).root
		return if u == v
		if u.rank > v.rank
			v.parent = u
			u.size += v.size
		elsif v.rank > u.rank
			u.parent = v
			v.size += u.size
		else
			u.parent = v
			v.rank += 1
			v.size += u.size
		end
	end
end

n, w, h = gets.split.map(&:to_i)
row_rep = {}
col_rep = {}
u = UnionFind.new

on_wall = false
n.times do |i|
	x, y = gets.split.map(&:to_i)
	if x == 1 || x == w || y == 1 || y == h
		on_wall = true
	end
	if j = col_rep[x]		
		u.union(i, j)
	else
		col_rep[x] = i
	end	
	if j = row_rep[y]		
		u.union(i, j)
	else
		row_rep[y] = i
	end	
end

roots = (0..n-1).map {|i| u.root(i)}.uniq
k = roots.map{|r| u.size(r) - 1}.inject(:+)
if roots.size > 1
	k += roots.size * 2 - 1
	k -= 1 if on_wall
end
puts k

Measured memory_bytes: 20144
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  a = (a+d-1)/d;
  c = (c+b-1)/b;
  if (a >= c) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3636
#!/usr/bin/env python3
from collections import defaultdict
import sys
sys.setrecursionlimit(10**5)
input = sys.stdin.readline
def LI(): return list(map(int, input().split()))
def LI_(): return list(map(lambda x: int(x)-1, input().split()))
def II(): return int(input())
def LIR(n):
    res = [None] * n
    for i in range(n):
        l, r = map(int, input().split())
        res[i] = (l - 1, r - 1, i)
    return res

#solve
def solve():
    n, q = LI()
    c = LI()
    lr = [None] * q
    for i in range(q):
        l, r = map(int, input().split())
        lr[i] = (l - 1, r - 1, i)
    ans = [None] * q
    lr.sort(key=lambda x: x[1])
    dp = [-1] * (max(c) + 1)
    bit = [0] * (n + 1)
    def add(i, w):
        """
        i番目にwを加える
        :param int i:
        :param int w:
        :return:
        """
        x = i + 1
        while x <= n:
            bit[x - 1] += w
            x += x & -x
        return
    def sum(i):
        """
        [0,i]の合計
        :param int i:
        :return:
        """
        res = 0
        x = i + 1
        while x > 0:
            res += bit[x - 1]
            x -= x & -x
        return res
    t = 0
    def f(t):
        l, r, j = lr[t]
        xr = sum(r)
        xl = sum(l-1)
        tmp = xr - xl
        ans[j] = tmp
        
    for i in range(n):
        ci = c[i]
        l = dp[ci]
        add(i, 1)
        dp[ci] = i
        if l != -1:
            add(l, -1)
        while t < q and lr[t][1]<= i:
            f(t)
            t += 1
        if t == q:
            break
    for ai in ans:
        print(ai) 
    return


#main
if __name__ == '__main__':
    solve()


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

int main () {
  int n, k;
  cin>>n>>k;
  bool dp[k+1];
  int a[n];
  for(int i=0;i<n;i++) cin>>a[i];
  dp[0] = false; 	
  for(int i=1;i<k+1;i++) {
    dp[i] = false;
  	for(int j=0;j<n;j++) {
    	if(a[j]<=i) {
          	if(!dp[i-a[j]])
        		dp[i] = !dp[i-a[j]];
        }
    }
  }
  if(dp[k]) cout<<"First"<<endl;
  else cout<<"Second"<<endl;
  
}

Measured memory_bytes: 384
//Code by 27.
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<queue>
#include<map>
#include<stack>
#include<fstream>
#include<stdlib.h>
#include<set>
#include<climits>
#include<cmath> 
#include<memory.h> 
#include<sstream>
#include<time.h>
using namespace std;
const unsigned long long BIGEST=1000000000000000+1000000000000000;
const long long BIGER=1000000000000000;
const int BIG=1000000000;
const long long MOD=19260817;
int main()
{
	long long n,m;
	cin>>n>>m;
	int g=1;
	while(n<=m)
	{
		g++;
		n*=2;
	}
	cout<<g-1;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
  int n;
  scanf("%d",&n);
  int a[n];
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  int max=-1,nmax=-1,idx;
  for(int i=0;i<n;i++){
if(a[i]>max){max=a[i];
    idx=i;
  }
}
  //printf("idx=%d\n",idx);
  for(int i=0;i<n;i++){
 	if(i==idx){//printf("i=%dなのでスキップ\n",i);
      continue;
              }
    if(a[i]>nmax)nmax=a[i];
  }
  
  for(int i=0;i<n;i++){
if(i==idx)printf("%d\n",nmax);
else printf("%d\n",max);
  }
  return 0;
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>

using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define pb(x) push_back(x)
#define int long long


signed main(void) {
  int N;
  int a[5];
  int minNum = 0;
  int minIndex = 0;
  cin >> N;
  rep(i, 5) {
    cin >> a[i];
    if (i==0) {
      minNum = a[i];
    } else {
      if (minNum > a[i]) {
        minIndex = i;
        minNum = a[i];
      }
    }
  }

  int ans = 0;
  if (N%a[minIndex] == 0) {
    ans = N/a[minIndex] - 1 + 5;
  } else {
    ans = N/a[minIndex] + 5;
  }

  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    long double a,b,c;
    cin>>a>>b>>c;

long double eps = 1.0E-14;
    if(sqrt(a)+sqrt(b)+eps <sqrt(c))
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 256
#ifdef Prateek
  #include "Prateek.h"
#else
  #include <bits/stdc++.h>
  using namespace std;
  #define debug(...) 42
#endif
#define F first
#define S second
#define pb push_back
#define f(i,x,n) for(int i=x;i<n;i++)
#define all(c) c.begin(),c.end()
#define int ll
using ll = long long;
const int MOD = 1e9+7, N = 1e5 + 10; 

int32_t main(){
   ios::sync_with_stdio(false);
   cin.tie(NULL);
   int n;
   cin >> n;
   vector<int> a(n);
   map<int,int> cnt;
   int sm = 0;
   f(i,0,n){
      cin >> a[i];
      sm += a[i];
      ++cnt[a[i]];
   }
   int q;
   cin >> q;
   while(q--){
      int b,c;
      cin >> b >> c;
      sm -= cnt[b]*b;
      sm += cnt[b]*c;
      cnt[c] += cnt[b];
      cnt[b] = 0;
      cout << sm << '\n';
   }
   return 0;
}

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


int main(){
 int n,b,i;
 int a[2*100000+1]={0};
 cin>>n;
 for(i=0;i<n-1;i++){
   cin>>b;
   a[b]=a[b]+1;
 }
 for(i=1;i<=n;i++){
   cout<<a[i]<<"\n";
 }
 return 0;
}


Measured memory_bytes: 3948
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.Math;
public class Main {

	public static void main(String[] args) {
		InputStreamReader is = new InputStreamReader(System.in);
		BufferedReader br = new BufferedReader(is);

		String col = "0";	//入力する行数
		String[] cols = null;
		int colInt = 0;

		//行数の入力後、三角形の三辺の長さを入力
		try {
			col = br.readLine();
			colInt = Integer.parseInt(col);
			cols = new String[colInt];

			for(int i = 0;i < colInt;i++){
				cols[i] = br.readLine();
			}
		}catch(IOException e){

		}

		//値の分離
		int[][] triangle = new int[colInt][3];
		for(int i = 0;i < colInt;i++){
			String[] temp = cols[i].split(" ");
			triangle[i][0] = Integer.parseInt(temp[0]);
			triangle[i][1] = Integer.parseInt(temp[1]);
			triangle[i][2] = Integer.parseInt(temp[2]);
		}
		for(int i = 0;i < colInt;i++){
			//三角形ごとに、最長の辺を求める
			int maxIndex = 0;
			if(triangle[i][maxIndex] < triangle[i][1]){
				maxIndex = 1;
			}
			if(triangle[i][maxIndex] < triangle[i][2]){
				maxIndex = 2;
			}
			//三角形が直角三角形であるかを求める
			switch (maxIndex){
			case 0:
				if(Math.pow(triangle[i][0],2) == Math.pow(triangle[i][1],2) + Math.pow(triangle[i][2],2)){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
				break;
			case 1:
				if(Math.pow(triangle[i][1],2) == Math.pow(triangle[i][0],2) + Math.pow(triangle[i][2],2)){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
				break;
			case 2:
				if(Math.pow(triangle[i][2],2) == Math.pow(triangle[i][0],2) + Math.pow(triangle[i][1],2)){
					System.out.println("YES");
				}else{
					System.out.println("NO");
				}
				break;
			}

		}
	}
}

Measured memory_bytes: 10000
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int N,K,num;
	int cnt=0;
	int aa;
	int ans=0;
	int like[40]={0};
	cin>>N>>K;
	for(int i=0;i<N;i++){
		cin>>num;
		for(int j=0;j<num;j++){
			cin>>aa;
			like[aa]++;
		}
	}
	for(int i=0;i<=K;i++){
		if(like[i]==N) cnt++;
	}
	cout<<cnt<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<algorithm>
#include<cmath>
#include<queue>
#include<vector>
#include<stack>
using namespace std;

#define REP(i,n) for(int i=0;(i)<(n);(i)++)
#define ll long long

static const int INFTY = 60000000;

pair<int, int> cost[1003];
vector<int> adj[1003];

int color[1003];//0は未訪問　1は訪問済み
int N;

int dp[5015];//その部分木の黒コストをiにしたときの白コスト




int makedp(int node) {
	int ta = cost[node].first;

	REP(i, ta + 1) dp[i] = INFTY;//初期化
	dp[0] = 0;

	for (int i = 0;i < adj[node].size();i++) {
		int nxt = adj[node][i];
		if (color[nxt] == 0) continue;//まだ更新されてないノードは参照しない

		for (int j = ta;j >= 0;j--) {
			if (dp[j] == INFTY) continue;
			
			int tmp1 = dp[j] + cost[nxt].first;
			int tmp2 = dp[j] + cost[nxt].second;

			dp[j] = INFTY;

			if (j + cost[nxt].first <= ta) {
				if (j + cost[nxt].first == 0) dp[0] = tmp2;
				else dp[j + cost[nxt].first] = min(dp[j + cost[nxt].first], tmp2);
			}
			if (j + cost[nxt].second <= ta) {
				if (j + cost[nxt].second == 0) dp[0] = tmp1;
				else dp[j + cost[nxt].second] = min(dp[j + cost[nxt].second], tmp1);
			}
		}
	}


	int minv = INFTY;
	for (int i = 0;i <= ta;i++) {
		minv = min(minv, dp[i]);
	}

	return minv;
}

void dfs() {
	REP(i, N + 1) color[i] = 0;

	stack<int> S;
	stack<int> vis;
	
	S.push(1);
	color[1] = 1;

	while (!S.empty()) {
		int now = S.top(); S.pop();

		vis.push(now);

		for (int i = 0;i < adj[now].size();i++) {
			int nn = adj[now][i];
			if (color[nn] == 0) {
				S.push(nn);
				color[nn] = 1;
			}
		}
	}

	REP(i, N + 1) color[i] = 0;//再利用

	while (!vis.empty()) {
		int nxt = vis.top(); vis.pop();

		//cout << nxt << endl;

		cost[nxt].second = makedp(nxt);

		color[nxt] = 1;//探索済み
	}
}

int main() {
	cin >> N;

	int P;
	for (int i = 2; i <= N; i++) {
		cin >> P;
		adj[i].push_back(P);
		adj[P].push_back(i);
	}

	int X;
	for (int i = 1;i <= N;i++) {
		cin >> X;
		cost[i].first = X;
	}

	dfs();

	/*
	for (int i = 1;i <= N;i++) {
		cout << cost[i].first << " " << cost[i].second << endl;
	}

	for (int i = 1;i <= N;i++) cout << color[i] << " ";
	cout << endl;
	*/

	if (cost[1].second == INFTY) {
		cout << "IMPOSSIBLE" << endl;
	}
	else cout << "POSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {

    public static void main(String[] args){
        //  System.setIn(new FileInputStream("D:/samleInput.txt"));

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();
        Map<Integer,Integer> inputMap = new TreeMap<Integer, Integer>();
        LinkedHashMap<Integer,Integer> linkedHashMap = new LinkedHashMap<Integer, Integer>();
        Map<Integer,String> resultCodeMap = new HashMap<Integer, String>();

        for (int i=0;i<m;i++) {
            int p = sc.nextInt();
            int y = sc.nextInt();
            inputMap.put(y, p);
            linkedHashMap.put(y, p);
        }
        Set<Integer> keySet = inputMap.keySet();
        Iterator<Integer> iter = keySet.iterator();
        int []partCitynum = new int[n+1];
        while (iter.hasNext()) {
            int yearKey = iter.next();
            int zone = inputMap.get(yearKey);
            partCitynum[zone] ++;
            String resultCode = insertOO(String.valueOf(zone))+insertOO(String.valueOf(partCitynum[zone]));
            resultCodeMap.put(yearKey,resultCode);
        }

        Set<Integer> keySet1 = linkedHashMap.keySet();
        Iterator<Integer> iter1 = keySet1.iterator();
        while (iter1.hasNext()){
            int year = iter1.next();
            String resultCode = resultCodeMap.get(year);
            System.out.println(resultCode);
        }
    }

    private static String insertOO(String code){

        char a[] = code.toCharArray();
        while (a.length<6){
            code= "0"+code;
            a = code.toCharArray();
        }
        return code;
    }
}

Measured memory_bytes: 125264
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>

using namespace std;
#define     loop(n,i,a)     for(int i=a;i<n;i++)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     vi              vector<int>
#define     vll             vector<ll>
#define     sz(x)           (int)x.size()
#define     pb              push_back
int dx[] = { -1, -1, -1, 0, 0, 1, 1, 1 };
int dy[] = { -1, 0, 1, -1, 1, -1, 0, 1 };

int main() {
	int n;cin>>n;
	int arr[n];
	loop(n,i,0)cin>>arr[i];
	sort(all(arr,n));
	ll dif=1e18;
	int sc;
	loop(n,i,0){
		if(dif>abs(arr[i]*2-arr[n-1])){
			dif=arr[n-1]-arr[i]*2;
			sc=arr[i];
		}
	}
	cout<<arr[n-1]<<' '<<sc<<endl;
}


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

#include <iostream>
#include <vector>

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool unionSet(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool findSet(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};



int main(void){
    // Here your code !
    int n,m;
    cin >> n >> m;
    
    UnionFind uf(n+m+10);
    
    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k ;j++){
            int a;
            cin >> a;
            uf.unionSet(i,a+n);
        }
    }
    
    
    for(int i = 0; i < n; i++){
        if(!uf.findSet(0,i)){
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;
    return 0;
    
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		// 処理対象個数の入力
		Scanner sc = new Scanner(System.in);
		int inputDeckNum = sc.nextInt();
		ArrayList<Integer> deckList = new ArrayList<>();
		for(int i=1;i <= inputDeckNum;i++) {
			deckList.add(sc.nextInt());
		}

		Collections.sort(deckList, Collections.reverseOrder());

		int first_player = 0;
		int second_player = 0;

		for(int i = 0;i < deckList.size();i++) {
			if(i % 2 == 0) {
				first_player += deckList.get(i);
			}else{
				second_player += deckList.get(i);
			}
		}

		sc.close();

		// 出力
		System.out.println(first_player - second_player);

	}

}

Measured memory_bytes: 23764
import java.util.*;

public class Main{
    
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int inf = (int)1e9;
        
        int n = Integer.parseInt(sc.next());
        int[] a = new int[n];
        for(int i=0; i<n; i++){
            a[i] = Integer.parseInt(sc.next());
        }
        
        long ans = 0;
        int bit = 0;
        int val = 0;
        ArrayDeque<Integer> q = new ArrayDeque<>();
        for(int i=0; i<n; i++){
            q.addLast(a[i]);
            bit ^= a[i];
            val += a[i];
            while(bit != val){
                int b = q.pollFirst();
                bit ^= b;
                val -= b;
            }
            //System.out.println("___" + q.size());
            ans += q.size();
        }
        
        System.out.println(ans);
    }
}

Measured memory_bytes: 53028
#include<iostream>
using namespace std;
#define df 0

int main(){
  int n,k; cin >>n >>k;
  char p; cin >>p;
  int cnt=0;
  for(int i=1;i<n;i++){
    char c; cin >>c;
    if(c==p)cnt++;
    p=c;
  }
  cout << min(cnt+2*k,n-1);
}

/// confirm df==0 ///


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main() {
    string s,t;
    cin>>s>>t;
    int ans=t.size();
    int n=t.size();
    for(int i=0;i<s.size()-n+1;i++){
    		int j=0;
    		int p=0;
    		while(j<t.size()){
    			if(s[i+j]!=t[j])
    			p++;
    			j++;
			}
			ans=min(ans,p);
	}
	cout<<ans<<"\n";
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
int n,m,x[55];
vector<pair<int,int>> v[55];
long long dp[1<<20];
bool dfs1(int a,int b,int c,int d){
	if (a==c)
		return 1;
	for (auto& i : v[a])
		if (i.first!=b && dfs1(i.first,a,c,d)){
			x[i.second]^=1<<d;
			return 1;
		}
	return 0;
}
int main(){
	scanf("%d",&n);
	for (int i=1;i<n;i++){
		int ta,tb;
		scanf("%d%d",&ta,&tb);
		v[ta].emplace_back(tb,i);
		v[tb].emplace_back(ta,i);
	}
	scanf("%d",&m);
	for (int i=0;i<m;i++){
		int ta,tb;
		scanf("%d%d",&ta,&tb);
		dfs1(ta,0,tb,i);
	}
	dp[0]=1;
	for (int i=1;i<n;i++)
		for (int j=(1<<m)-1;j>=0;j--)
			dp[j|x[i]]+=dp[j];
	printf("%lld\n",dp[(1<<m)-1]);///////////////////////////////
}

Measured memory_bytes: 8448
#include <iostream>
using namespace std;
int main(void){
   int i,l,g;
cin>>i>>l>>g;
if(i>=g){
cout<<"0"<<endl;
}
else if(i+l>=g&&l>=i){
cout<<g-i<<endl;
}
else if(i+l>=g&&l<i){
cout<<l<<endl;
}
else if(i+l<g){
cout<<"NA"<<endl;
}
}



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

int main(){
	
	int n,k; cin >>n>>k;
	ll cnt{}, l{},r{};
	for(int i=0; i<=n; i++){
		l += i;
		r += n-i;
		if(i+1>=k) (cnt += r-l+1) %= MOD; 
	}
	cout << cnt << endl;
}

Measured memory_bytes: 3636
n,m,l = map(int, input().split())

nm = []
ml = []
cij = []

for i in range(n):
    nm.append(list(map(int,input().split())))
    
for j in range(m):
    ml.append(list(map(int, input().split())))

for i in range(n):
    tmp = []
    for j in range(l):
        sum = 0
        for k in range(m):
            sum += nm[i][k]*ml[k][j]
        tmp.append(sum)
    cij.append(tmp)


for p in cij:
    print(*p)


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

int main() {
  string S; cin >> S;
  set<char> s;
  for (ll i = 0; i < S.size(); i++) {
    s.insert(S[i]);
  }
  if ((!(s.count('N')^s.count('S'))) & (!(s.count('E')^s.count('W')))) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
 
public class Main {
	/**
	* @param args
	*/
	static class RT extends HashMap<Integer, int[]>{}
	static class DS extends HashMap<Integer, Integer>{}
	static class LS extends ArrayList<Integer>{}
	static class AS extends HashMap<Integer, DS>{}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		RT		m = new RT();
		AS		o = new AS();
		int		n = parseNum();
		int		p = 0;
		int		s = 0;
		int		d = 0;
		int		v = 0;
		int[]	T = new int[n];

		// ルータの経路を取得
		for (int i = 0; i < T.length; i++) {
			int		cr = parseNum();
			int[]	nr = new int[parseNum()];

			for (int j = 0; j < nr.length; j++) {
				nr[j] = parseNum();
			}
			m.put(cr, nr);
			T[i] = cr;
		}

		// 他のルータまでの距離を取得
		for (int i = 0; i < T.length; i++) {
			int		len = 0;
			int		cnt = 2;
			DS		ttl = new DS();
			LS		lst = new LS();

			lst.add(T[i]);
			ttl.put(T[i], 1);
			while ((len = lst.size()) > 0) {
				for (int j = 0; j < len; j++) {
					int[]	np = m.get(lst.remove(0));
					for (int k = 0; k < np.length; k++) {
						if (!ttl.containsKey(np[k])) {
							ttl.put(np[k], cnt);
							lst.add(np[k]);
						}
					}
				}
				cnt++;
			}

			o.put(T[i], ttl);
		}

		p = parseNum();
		for (int i = 0; i < p; i++) {
			s = parseNum();
			d = parseNum();
			v = parseNum();
			if (!o.containsKey(s)) {
				System.out.println("NA");
			} else {
				DS	tmp = o.get(s);
				if (!tmp.containsKey(d)) {
					System.out.println("NA");
				} else {
					int	max = tmp.get(d);
					if (v < max) {
						System.out.println("NA");
					} else {
						System.out.println(Math.min(v, max));
					}
				}
			}
		}
	}
 
	private static int parseNum() {
		try {
			int	buf = 0;
			int	num = 0;
			int	mns = 0;
			int	skp = 1;
 
			// -,0〜9以外は読み飛ばす
			while (true) {
				buf = System.in.read();
				if (buf == '-') {
					mns = 1;
					skp = 0;
				} else if (buf >= '0' && buf <= '9') {
					num = num * 10 + (buf - '0');
					skp = 0;
				} else if (skp == 0) {
					return (mns == 0)?num:num*(-1);
				}
			}
		} catch (IOException e) {}
		return -1;
	}
}

Measured memory_bytes: 31408
// JavaProgram.cpp
// Author : Priydarshi Singh (@dryairship)
// One cat just leads to another. One bug leads to two others.

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

// I like my types defined.
typedef long long           ll;
typedef pair<int, int>      pii;
typedef pair<ll, ll>        pll;
typedef vector<int>         vi;
typedef vector<ll>          vl;
typedef vector<pii>         vii;
typedef vector<pll>         vll;
typedef set<int>            si;
typedef map<string, int>    msi;
typedef map<int, int>       mii;

// Traditional science is all about finding "hashtag define"s.
#define fr(i, n)            for(int i=0; i<(n); ++i)
#define frC(i, n, c)        for(int i=0; (i<(n)) && (c); ++i)
#define frA(i, a, n)        for(int i=a; i<=(n); ++i)
#define frD(i, a, n)        for(int i=a; i>=(n); --i)
#define fill(a)             memset(a, 0, sizeof(a))
#define fill1(a)            memset(a, -1, sizeof(a))
#define revsort(a, b)       sort(a, b, greater<int>())
#define ff                  first
#define ss                  second
#define pb                  push_back 
#define dout                if(DEBUGGING) cout
#define dbg                 if(DEBUGGING) 
#define endl                "\n"

// When you realize MOD > INF...
int DEBUGGING    =          0;
const int INF    =          1000000000;
const int MOD    =          1000000007;
const ll LINF    =          1e18;
const double PI  =          3.1415926535897932;
const double EPS =          1e-7;

// I'D SPAM. Hehe.
ll gcdEx                    (ll a, ll b, ll *x, ll *y){if(!a){*x=0;*y=1;return b;} 
ll x1,y1,gcd=gcdEx          (b%a,a,&x1,&y1); *x=y1-(b/a)*x1;*y=x1; return gcd;}
ll modI(ll b, ll m)         {ll x,y;gcdEx(b,m,&x,&y);return (x%m+m)%m;}
ll modD(ll a, ll b)         {return (modI(b,MOD)*(a%MOD))%MOD;}
ll modS(ll a, ll b)         {return ((a%MOD)-(b%MOD)+MOD)%MOD;}
ll modP(ll x, ll y)         {ll r=1; x%=MOD; while(y>0){if(y&1){r=(r*x)%MOD;} y=y>>1; x=(x*x)%MOD;} return r;}
ll modA(ll a, ll b)         {return ((a%MOD)+(b%MOD))%MOD;}
ll modM(ll a, ll b)         {return ((a%MOD)*(b%MOD))%MOD;}

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

void solve(int TEST_CASE){
    int k;
    cin >> k;
    string s;
    cin >> s;
    if(s.length()<=k){
        cout << s;
    }else{
        fr(i,k) cout << s[i];
        cout << "...";
    }
}

int main(int argc, char* argv[]){
    if(argc==2 && argv[1][1]=='v') DEBUGGING = 1;
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    cin.exceptions(cin.failbit);
    int nTestCases=1;
    //cin >> nTestCases;
    frA(i,1,nTestCases) solve(i);
    return 0;
}

Measured memory_bytes: 3656
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_string();
    let keyence = String::from("keyence");

    for i in 1..keyence.len(){
        let(first, last) = keyence.split_at(i);
        //println!("first = {}, last = {}", first, last);
        let first_poses: Vec<_> = line.match_indices(first).map(|x| x.0).collect();
        let last_poses: Vec<_> = line.match_indices(last).map(|x| x.0).collect();
        if first_poses.len() == 0  || last_poses.len() == 0{ continue;}
        //println!("fposes = {:?}, lposes = {:?}", first_poses, last_poses);
        for first_pos in &first_poses{
            for last_pos in &last_poses{
                if *first_pos + first.len() <= *last_pos{
                    let pdust = *first_pos;
                    let mdust = *last_pos - *first_pos - first.len();
                    let sdust = line.len() - *last_pos - last.len();
                    //println!("prefix = {}, middle={}, suffix={}", pdust, mdust, sdust);
                    if (pdust == 0 && mdust == 0) ||
                        (mdust == 0 && sdust == 0) ||
                        (pdust == 0 && sdust == 0){
                            println!("YES");
                            return;
                        }
                }
            }
        }

    }
    println!("NO");
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int x, y, z;
  cin >> x >> y >> z;
  swap(x, y);
  swap(x, z);
  cout << x << " " << y << " " << z;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            string N = Console.ReadLine();
            string laststr = N.Substring(N.Length - 1);
            if(laststr == "2" || laststr == "4" || laststr == "5" || laststr == "7" || laststr == "9")
            {
                Console.WriteLine("hon");
            }
            if(laststr == "0" || laststr == "1" || laststr == "6" || laststr == "8")
            {
                Console.WriteLine("pon");
            }
            if(laststr == "3")
            {
                Console.WriteLine("bon");
            }
        }
    }
}

Measured memory_bytes: 25876
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<functional>
#include<utility>
#include<vector>
#include<bitset>
#include<queue>
#include<stack>
#include<set>
#include<map>
#define re register
#define FOR(i,a,b) for(re int i=(a);i<=(b);i++)
#define ROF(i,a,b) for(re int i=(a);i>=(b);i--)
#define temT template<typename T>
using namespace std;
typedef long long ll;
const int L=int(6)+1;

int a[L][L],b[L][L];
int n,m,K;

inline int crd(){
	char t;
	while(cin>>t){
		if(t=='.')	return 0;
		if(t=='#')	return 1;
	}
}
inline void ar(int x,int t){	FOR(i,1,m) b[x][i]+=t;	}
inline void ac(int x,int t){	FOR(i,1,n)	b[i][x]+=t;	}
inline int calc(){
	int res=0;
	FOR(i,1,n)	FOR(j,1,m)
		if(a[i][j]==1 && b[i][j]==0)
			res++;
	return res;
}

int main(){
	cin>>n>>m>>K;
	FOR(i,1,n)	FOR(j,1,m)
		a[i][j]=crd();
	int res=0;
	FOR(i,0,(1<<n)-1)
		FOR(j,0,(1<<m)-1){
			FOR(k,1,n)	if(i&(1<<(k-1))) ar(k,1);
			FOR(k,1,m) if(j&(1<<(k-1))) ac(k,1);
			if(calc()==K)	res++;
			FOR(k,1,n)	if(i&(1<<(k-1))) ar(k,-1);
			FOR(k,1,m) if(j&(1<<(k-1))) ac(k,-1);
		}
	cout<<res;
	return 0;
}

Measured memory_bytes: 3620
#include <cstdio>

using namespace std;

int n, d1, d2, a[605][605];

void paint(int d){
	int times = 0;
	while (d % 4 == 0) d /= 4, times++;
	
	if (d % 2 == 1){
		for (int i = 0; i < 2 * n; i++)
			for (int j = 0; j < 2 * n; j++)
				if (((i >> times) + (j >> times)) % 2 == 1) a[i][j] = 1;
	}
	if (d % 2 == 0){
		for (int i = 0; i < 2 * n; i++){
			if ((i >> times) % 2 == 1)
				for (int j = 0; j < 2 * n; j++) a[i][j] = 1;
		}
	}
}

int main(){
	scanf("%d%d%d", &n, &d1, &d2);
	int cnt = 0;
	paint(d1); paint(d2);
	
	for (int i = 0; i < 2 * n; i++){
		for (int j = 0; j < 2 * n; j++){
			if (cnt < n * n && !a[i][j]){
				printf("%d %d\n", i, j);
				cnt++;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 2304
#include<stdio.h>
#include<string>
#include<string.h>
#include<utility>
#include<iostream>
#include<queue>
#include<math.h>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<bitset>
#include<tuple>

using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0;i<(int)(n);i++)

int main(){
    int n;
    ll a,b;
    scanf("%d",&n);
    vector<pair<ll,ll>> v;
    REP(i,n){
        scanf("%lld%lld",&a,&b);
        v.push_back(make_pair(a+b,a-b));
    }
    sort(v.begin(),v.end());
    //REP(i,n)printf("#####%lld %lld\n",v[i].first,v[i].second);
    int ans=0;
    int time=-1000000005;
    REP(i,n){
        if(time<=v[i].second){
            ans++;
            time=v[i].first;
        }
    }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 2420
<?php

$input_line = intval(fgets(STDIN));
$n = $input_line;

while ($n != 0) {
    $player1 = 0;
    $player2 = 0;
    for($i = 0; $i < $n; $i++){
        $numbers = preg_split("/[\s,]+/", rtrim(fgets(STDIN)));
        $m1 = intval($numbers[0]);
        $m2 = intval($numbers[1]);
        if($m1 > $m2) {
            $player1 += $m1 + $m2;
        } else if ($m1 == $m2) {
            $player1 += $m1;
            $player2 += $m2;
        } else {
            $player2 += $m1 + $m2;
        }
    }
    print $player1 . " ". $player2 . "\n";
    $input_line = intval(fgets(STDIN));
    $n = $input_line;
}


Measured memory_bytes: 9368
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

#define REP(a, i, n) for (int i = a; i < n; ++i)

int f(int n) {
    if (n % 2 == 0) {
        return n / 2;
    } else {
        return 3 * n + 1;
    }
}

int main() {
    int s;
    cin >> s;

    vector<int> v;
    while(find(v.begin(), v.end(), s) == v.end()) {
        v.push_back(s);
        s = f(s);
    }

    cout << v.size() + 1 << endl;

    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  string s;
  cin >> s;
  char before = '_';
  for (auto it: s) {
    if (before == 'A' and it == 'C') {
      puts("Yes");
      return;
    }
    before = it;
  }
  puts("No");
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define ll long long 
#define FI first 
#define SE second
#define pb push_back 
#define eb emplace_back
#define mod 1000000007
#define all(c) (c).begin(),(c).end()
#define LB  lower_bound
#define UB  upper_bound
#define max3(a,b,c) max(c,max(a,b))
#define min3(a,b,c) min(c,min(a,b))
#define mems(s, n) memset(s, n, sizeof(s))
#define NINF -1e18
#define INF 1e18
#define int ll int
#define OOK order_of_key  //no of elements less than
#define FBO find_by_order //iterator pointing kth element;indexing starts from 0
#define CK3(x,y,z) cout<<(x)<<" "<<(y)<<" "<<(z)<<endl
#define CK4(a,b,c,d) cout<<(a)<<" "<<(b)<<" "<<(c)<<" "<<(d)<<endl

typedef pair<int,int> PII;
typedef pair<pair<int,int>,int> PPII;
typedef pair<int,pair<int,int>> PIPI;
typedef map<int,int>MII;
typedef vector<int> VI;
template <typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int power(int a, int b)
{int x=1,y=a;while(b>0){if(b%2){x =(x*y)%mod;}y =(y*y)%mod;b/=2;}return x%mod;}

//int modInverse(int a, int m) {return power(a, m-2);} //gcd(a,m)=1 


signed main()
{
ios::sync_with_stdio(false); cin.tie(0);
int T=1,T1=0;//cin>>T;
while(T1++<T)
{//cout<<"Case #"<<T1<<": ";
 
 int n,k;
 cin>>k;VI dp(100001,0);n=3;
 int ans=0,sum=0;
 for(int i=k;i>=1;i--)
 {
     int x=k/i;
     int mn=(power(x,n)-dp[i]+mod)%mod;
     ans=(ans+mn*i)%mod;
     //sum+=mn;
     //sum%=mod;
     int aa=i;
     for(int i1=1;i1*i1<=aa;i1++)
     {
         if(aa%i1==0)
         {
             dp[i1]+=mn;
             dp[i1]%=mod;
             if(aa/i1!=i1)
             {
                 dp[aa/i1]+=mn;
                 dp[aa/i1]%=mod;
             }
         }
         
     }
 }//cout<<sum<<endl;
 //int ab=(power(k,n)-sum+mod)%mod;
 //ans=(ans+ab)%mod;
 cout<<ans<<endl;
}


return 0;
}





Measured memory_bytes: 3992
from collections import defaultdict
N = int(input())
s_cards = [input() for _ in range(N)]
M = int(input())
t_cards = [input() for _ in range(M)]

d = defaultdict(int)
for s in s_cards:
    d[s] += 1

m = 0
for s in d:
    m = max(m, d[s] - t_cards.count(s))
print(m)


Measured memory_bytes: 3316
import sys
input = sys.stdin.readline
'''
allinputs = iter(input().splitlines())
input = lambda : next(allinputs)
#'''
N = int(input())
a = list(map(int, input().split()))
dp = [[0] * (N + 1) for _ in range(N + 1)]
#dp[i][j]: 半開区間[i,j)のスライムを結合した時の最小のコスト
sum = [0] * (N + 1) #累積和
inf = float('inf')

for i in range(N):
	sum[i + 1] = sum[i] + a[i]
	
for c in range(2, N + 1):
	for i in range(N - c + 1):
		ans = inf
		for k in range(1, c):
			tmp = dp[i][i + k] + dp[i + k][i + c] + sum[i + c] - sum[i]
			if tmp < ans:
				ans = tmp
				
		dp[i][i + c] = ans
		
print(dp[0][N])


Measured memory_bytes: 44176
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    string s; cin>>s;
    int n=s.size();

    int ans1=0, ans2=0;
    for(int i=0; i<n; i++){
        if(i % 2 == 0 && s[i] == '0') ans1++;
        else if(i % 2 == 1 && s[i] == '1') ans1++;
        else ans2++;
    }

    cout << min(ans1, ans2) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

string f(ll n) {
  if (n == 0) return "";
  n--;
  return f(n/26) + string(1,'a' + n%26);
}

int main() {
  ll n;
  cin >> n;
  cout << f(n) << endl;
  return 0;
}

Measured memory_bytes: 3132
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    FastScanner in;
    PrintWriter out;

    public static void main(String[] args) {
        new Main().runIO();
    }

    long findSame(long a, long b) {
        return (b - a) / 2;
    }

    void solve() {
        long n = in.nextLong();
        long a = in.nextLong();
        long b = in.nextLong();
        if ((b - a) % 2 == 0) {
            out.println(findSame(a, b));
        } else {
            long d = n - b + 1;
            long res = Math.min(a + findSame(1, b - a), d + findSame(a + d, n));
            out.println(res);
        }
    }

    void run() {
        try {
            in = new FastScanner(new File("Main.in"));
            out = new PrintWriter(new File("Main.out"));

            solve();

            out.close();
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }
    }

    void runIO() {

        in = new FastScanner(System.in);
        out = new PrintWriter(System.out);

        solve();

        out.close();
    }

    class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(File f) {
            try {
                br = new BufferedReader(new FileReader(f));
            } catch (FileNotFoundException e) {
                e.printStackTrace();
            }
        }

        public FastScanner(InputStream f) {
            br = new BufferedReader(new InputStreamReader(f));
        }

        String next() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return null;
                st = new StringTokenizer(s);
            }
            return st.nextToken();
        }

        boolean hasMoreTokens() {
            while (st == null || !st.hasMoreTokens()) {
                String s = null;
                try {
                    s = br.readLine();
                } catch (IOException e) {
                    e.printStackTrace();
                }
                if (s == null)
                    return false;
                st = new StringTokenizer(s);
            }
            return true;
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 21204