akhauriyash/Code-Regression huggingface dataset:
#define _USE_MATH_DEFINES
#include<bits/stdc++.h>
using namespace std;

void include3(int x, int i){
        if(x % 10 == 3)cout << " " << i;
        else {
                x /= 10;
                if(x) include3(x, i);
        }
}

void check_num(int i){
        int x = i;
        if(x % 3 == 0)cout << " " << i;
        else{
                include3(x, i);
        }
}

void call(int n){
		int i = 1;
        while(++i <= n){
                check_num(i);
        }
}


int main(){
        int n;
        cin >> n;
        call(n);
        cout << endl;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
using namespace std;
using lli = int_fast64_t;
using ulli = uint_fast64_t;
#define debug(x) cerr << #x << " : " << x << endl
#define debugv(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x << ", ";}cerr << endl
#define debugst(x) auto xt = x;cerr << #x << " : {";for(int i=0;i<x.size();i++){ cerr << xt.top() << ", ";xt.pop();}cerr << endl
#define debugvp(x) cerr << #x << " : {";for(auto value_of_x:x){ cerr << value_of_x.first << " : " << value_of_x.second << ", ";}cerr << endl

const lli MOD = 1000000007;
const lli LIMIT = 1000000000000000000 * 5;
const int tenfive = 100000;

template<typename T>
T ncr(T left, T right) {
	right = min(left - right, right);
	T ans = 1;
	for (T i = 1; i <= right; i++) {
		ans = ans * (left - right + i) / i;
	}
	return ans;
}


template<typename T>
T powmod(T n, T p, T m) {
	if (p == 0)return 1;
	if (p % 2 == 0) {
		T t = powmod(n, p / 2, m);
		return t * t % m;
	}
	return n * powmod(n, p - 1, m);
}

int main() {
	lli N, P;
	cin >> N >> P;
	vector<lli> v(N);
	lli odd = 0, even = 0;
	for (int i = 0; i < N; i++) {
		cin >> v[i];
		if (v[i] % 2 == 1) {
			odd++;
		}
		else {
			even++;
		}
	}
	lli evensel = powmod<lli>(2, even, LIMIT);
	debug(evensel);
	if (P == 1) {
		lli oddsel = 0;
		for (lli i = 1; i <= odd; i += 2) {
			oddsel += ncr(odd, i);
		}
		//debug(oddsel);
		cout << oddsel * evensel << endl;
	}
	else {
		lli oddsel = 0;
		for (lli i = 0; i <= odd; i += 2) {
			oddsel += ncr(odd, i);
		}
		//debug(oddsel);
		cout << oddsel * evensel << endl;
	}

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <stdexcept>

using namespace std;
using pii = pair<int, int>;
static const int INF = 1000000000;

pii backward_recur(
	int u, int p, vector<int>& lo, vector<int>& hi,
	const vector<int>& x, const vector<vector<int>>& conn)
{
	int self_lo = -INF, self_hi = INF;
	for(const auto v : conn[u]){
		if(v == p){ continue; }
		const auto c = backward_recur(v, u, lo, hi, x, conn);
		self_lo = max(self_lo, c.first  - 1);
		self_hi = min(self_hi, c.second + 1);
	}
	if(x[u] >= 0){
		if(x[u] < self_lo || self_hi < x[u]){
			throw runtime_error("impossible");
		}
		self_lo = self_hi = x[u];
	}
	lo[u] = self_lo;
	hi[u] = self_hi;
	return pii(self_lo, self_hi);
}

void forward_recur(
	int u, int p, const vector<int>& lo, const vector<int>& hi,
	vector<int>& x, const vector<vector<int>>& conn)
{
	if(x[u] >= 0){
		// skip
	}else if(p < 0){
		x[u] = lo[u];
	}else if(x[p] - 1 >= lo[u]){
		x[u] = x[p] - 1;
	}else if(x[p] + 1 <= hi[u]){
		x[u] = x[p] + 1;
	}else{
		throw runtime_error("impossible");
	}
	for(const auto v : conn[u]){
		if(v == p){ continue; }
		forward_recur(v, u, lo, hi, x, conn);
	}
}

int main(){
	ios_base::sync_with_stdio(false);
	int n;
	cin >> n;
	vector<vector<int>> conn(n);
	for(int i = 1; i < n; ++i){
		int a, b;
		cin >> a >> b;
		--a; --b;
		conn[a].push_back(b);
		conn[b].push_back(a);
	}
	int k;
	cin >> k;
	vector<int> x(n, -1);
	for(int i = 0; i < k; ++i){
		int v, p;
		cin >> v >> p;
		--v;
		x[v] = p;
	}
	vector<int> y(n, INF);
	queue<int> q;
	for(int i = 0; i < n; ++i){
		if(x[i] >= 0){
			y[i] = (x[i] & 1);
			q.push(i);
			break;
		}
	}
	while(!q.empty()){
		const int u = q.front();
		q.pop();
		for(const auto v : conn[u]){
			if(y[v] != INF){ continue; }
			y[v] = y[u] + 1;
			q.push(v);
		}
	}
	bool possible = true;
	for(int i = 0; i < n; ++i){
		if(x[i] < 0){ continue; }
		if((x[i] & 1) != (y[i] & 1)){ possible = false; }
	}
	if(!possible){
		cout << "No" << endl;
		return 0;
	}
	vector<int> lo(n, -INF), hi(n, INF);
	try{
		backward_recur(0, -1, lo, hi, x, conn);
		forward_recur(0, -1, lo, hi, x, conn);
	}catch(runtime_error e){
		cout << "No" << endl;
		return 0;
	}
	cout << "Yes" << endl;
	for(int i = 0; i < n; ++i){
		cout << x[i] << endl;
	}
	return 0;
}



Measured memory_bytes: 18944
import Control.Applicative
import Text.Printf

main :: IO ()
main = do
  s0 <- readLn
  let (h, m, s) = solve s0
  printf "%d:%d:%d\n" h m s

solve :: Int -> (Int, Int, Int)
solve s0 = (h, m, s)
  where
    (m0, s) = s0 `quotRem` 60
    (h , m) = m0 `quotRem` 60



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

using namespace std;

#define all(v)          v.begin(), v.end()
#define pb              push_back
#define sz(x)          (int) (x.size())
#define endl            "\n"
#define isOdd(n)       (n&1)
#define pow(n, m)      (ll)powl(n, m)
#define clr(x, val)     memset(x, val, sizeof(x))


typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;


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

    int x; cin >> x;
    int y = 1800, z = 1;
    while(x/y == 0) y -= 200, z++;
    cout << z;
    return 0;
}


Measured memory_bytes: 3644
def lowerBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>=n: high = mid
        else: low = mid
    return high

def upperBound(arr, n):
    low, high = -1, len(arr)
    while high-low>1:
        mid = (low+high)//2
        if arr[mid]>n: high = mid
        else: low = mid
    return low+1

n = int(input())
a = sorted(map(int, input().split()))
b = sorted(map(int, input().split()))
c = sorted(map(int, input().split()))

ans = 0
for i in b:
    cnt_a = lowerBound(a, i)
    cnt_b = n - upperBound(c,i)
    ans += cnt_a * cnt_b
print(ans)

Measured memory_bytes: 24052
def bisect(f, ok, err):
    while abs(ok - err) > 1:
        m = (ok + err) // 2
        if f(m):
            ok = m
        else:
            err = m
    return ok

def c2i(c): return ord(c)-ord("A")
def mapst(s,t): return c2i(s),-1 if t=="L" else 1
def main():
    N,Q=map(int, input().split())
    S=list(map(c2i, input()))
    TD=[mapst(*input().split())for _ in range(Q)]
    def f(m):
        for t,d in TD:
            m+=(S[m]==t)*d
            if m<0 or m>=N: return False
        return True
    l=bisect(f, N, -1)
    def f(m):
        for t,d in TD:
            m+=(S[m]==t)*d
            if m<0 or m>=N: return False
        return True
    r=bisect(f, -1, N)
    print(r-l+1 if l<=r else 0)

if __name__ == "__main__":
    main()

Measured memory_bytes: 20720
#include<stdio.h>

typedef struct{
  char mark;
  int value;
  int num;
}CARD;

int main() {

  int i, j, n, minj, flag = 0;
  CARD a[100], b[100], temp;

  scanf("%d", &n);
  for(i = 0; i < n; i++) {
    scanf(" %c%d", &a[i].mark, &a[i].value);
    a[i].num = i + 1;
    b[i] = a[i];
  }

  //Bubble
  for(i = 0; i < n; i++){
    for(j = n - 1; j != i; j--){
      if(a[j].value < a[j - 1].value){
        temp = a[j];
        a[j] = a[j-1];
        a[j-1] = temp;
      }
    }
  }
  for(i = 0; i < n; i++){
    printf("%c%d", a[i].mark, a[i].value);
    if(i < n-1) printf(" ");
    else printf("\n");
  }
  for(i = 0; i < n-1; i++){
    if(b[i].value == b[i+1].value){
      if(b[i].num > b[i+1].num){
        flag = 1;
      }
    }
  }
  if(flag == 1) printf("Not stable\n");
  else printf("Stable\n");
  
  //Select
  for(i = 0; i < n; i++){
    minj = i;
    for(j = i; j < n; j++){
      if(b[j].value < b[minj].value) {
        minj = j;
      }
    }
    temp = b[i];
    b[i] = b[minj];
    b[minj] = temp;
  }
  //for(i = 0; i < n; i++){
    //if(a[i].mark != b[i].mark) flag = 1;
  //}
  for(i = 0; i < n; i++){
    printf("%c%d", b[i].mark, b[i].value);
    if(i < n-1) printf(" ");
    else printf("\n");
  }
  for(i = 0; i < n-1; i++){
    if(b[i].value == b[i+1].value){
      if(b[i].num > b[i+1].num){
        flag = 1;
      }
    }
  }
  if(flag == 1) printf("Not stable\n");
  else printf("Stable\n");

  return 0;
}



Measured memory_bytes: 2128
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define SIZE 100005

ll N,A,B;
ll HP[SIZE];

bool isOK(ll num){

	ll base = num*B;

	ll add = 0;

	for(ll i = 0; i < N; i++){
		if(HP[i] <= base)continue;

		if((HP[i]-base)%(A-B) == 0){

			add += (HP[i]-base)/(A-B);

		}else{

			add += (HP[i]-base)/(A-B)+1;
		}
	}

	return add <= num;
}


int main(){

	scanf("%lld %lld %lld",&N,&A,&B);

	for(ll i = 0; i < N; i++){

		scanf("%lld",&HP[i]);
	}

	ll left = 0,right = BIG_NUM,mid = (left+right);
	ll ans = BIG_NUM;

	while(left <= right){

		if(isOK(mid)){

			ans = mid;
			right = mid-1;

		}else{

			left = mid+1;
		}
		mid = (left+right)/2;
	}


	printf("%lld\n",ans);

	return 0;
}


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

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X,i) ((X>>i)&1)
#define REP(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()
#define ina(x,n) rep(x_i,n) cin>>x[x_i]
#define outa(x,n) rep(x_i,n) cout<<x[x_i]<<" \n"[x_i==n-1]

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> pll;
typedef vector<pll> vll;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<28);
const ll INFL = (1L<<61);

int main() {
  int x, y; cin >> x >> y;
  int ans = 0;
  if (x == 3) ans += 100000;
  if (x == 2) ans += 200000;
  if (x == 1) ans += 300000;
  if (y == 3) ans += 100000;
  if (y == 2) ans += 200000;
  if (y == 1) ans += 300000;
  if (x == 1 && y == 1) ans += 400000;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int n,i,j,x,a[10][10],list[1000][3],size;

void push(int x,int y,int s){list[size][0]=i;list[size][1]=j;list[size][2]=s;size++;}

int check(int x,int y,int s){
	int d;
	if(s<3 && (x<1 || x>9 || y<1 || y>9)) return 0;
	if(s==3 && (x<2 || x>8 || y<2 || y>8)) return 0;
	d=a[x][y];
	if(a[x-1][y]<d)d=a[x-1][y];
	if(a[x+1][y]<d)d=a[x+1][y];
	if(a[x][y-1]<d)d=a[x][y-1];
	if(a[x][y+1]<d)d=a[x][y+1];
	if(s==1 || d==0)return d;
	if(a[x-1][y-1]<d)d=a[x-1][y-1];
	if(a[x+1][y+1]<d)d=a[x+1][y+1];
	if(a[x+1][y-1]<d)d=a[x+1][y-1];
	if(a[x-1][y+1]<d)d=a[x-1][y+1];
	if(s==2 || d==0)return d;
	if(a[x-2][y]<d)d=a[x-2][y];
	if(a[x+2][y]<d)d=a[x+2][y];
	if(a[x][y-2]<d)d=a[x][y-2];
	if(a[x][y+2]<d)d=a[x][y+2];
	return d;
}

void draw(int x,int y,int s,int d){
	if(size==3 && (x<2 || x>8 || y<2 || y>8)) return;
	a[x][y]+=d;
	a[x-1][y]+=d;
	a[x+1][y]+=d;
	a[x][y-1]+=d;
	a[x][y+1]+=d;
	if(s==1)return;
	a[x-1][y-1]+=d;
	a[x+1][y+1]+=d;
	a[x+1][y-1]+=d;
	a[x-1][y+1]+=d;
	if(s==2)return;
	a[x-2][y]+=d;
	a[x+2][y]+=d;
	a[x][y-2]+=d;
	a[x][y+2]+=d;
}

int search(int nn,int from){
	int i,x,y,s;
	for(i=from;i>=0;i--){
		x=list[i][0];y=list[i][1];s=list[i][2];
		if(a[x][y]==0 && a[x+1][y]>0)return 0;
		if(s<3 && x<8 && a[x+2][y]>0)return 0;
		if(check(x,y,s)>0){
			draw(x,y,s,-1);
			if(s==1 && a[x+1][y+1]>0 && check(x-1,y+1,3)==0){draw(x,y,s,+1);return 0;}
			if(nn>1){
				if(search(nn-1,i-1)>0){printf("%d %d %d\n",y,x,s);return 1;}
			}else{
				int p,q;
				for(p=0;p<10;p++)for(q=0;q<10;q++){{if(a[p][q]!=0)goto miss;}}
				printf("%d %d %d\n",y,x,s);return 1;miss:;
			}
			draw(x,y,s,+1);
		}
	}
	return 0;
}

int main(void){
	scanf("%d",&n);size=0;
	for(i=0;i<10;i++){for(j=0;j<10;j++){scanf("%d",&a[i][j]);}}
	for(i=1;i<9;i++){
		for(j=1;j<9;j++){
			x=check(i,j,1); if(x==0)continue; else for(;x>0;x--)push(i,j,1);
			x=check(i,j,2); if(x==0)continue; else for(;x>0;x--)push(i,j,2);
			x=check(i,j,3); if(x==0)continue; else for(;x>0;x--)push(i,j,3);
		}
	}
	//for(i=0;i<size;i++)printf("%d %d %d\n",list[i][0],list[i][1],list[i][2]);
	search(n,size-1);
	return 0;
}

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

int main(void){
    string S;
    cin >> S;
    
    int cnt = 0;
    for(int i = 0; i < 3; i++){
        if(S[i] == 'R') cnt++;
    }
    
    if(cnt == 3){
        cout << 3 << endl;
        return 0;
    }else if(cnt == 2){
        if(S[1] == 'R'){
            cout << 2 << endl;
            return 0;
        }
    }else if(cnt == 0){
        cout << 0 << endl;
        return 0;
    }
    
    cout << 1 << endl;
    return 0;
}

Measured memory_bytes: 3612
import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Queue;
import java.util.Scanner;
 


public class Main {
	static int a1[]= {0,-1,0,1};
	static int b1[]= {-1,0,1,0};
	private static         Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static int K,N;
	static long mod =1000000007;
	static 	ArrayList<Integer> cc = new ArrayList<>(100);

	public static void main(String[] args) {
			N=sc.nextInt();

			
			for(int i=0;i<N;i++) {
				cc.add(sc.nextInt());
			}
			v(0,1);
			p(c);
			
			
			
			
	}
	static int c=0;
	static void v(int i,int sum) {
		//p(i);
		if(i==N) {
			if(sum%2==0)c++;
		}else {
			v(i+1,sum*(cc.get(i)+1));
			v(i+1,sum*(cc.get(i)-1));
			v(i+1,sum*(cc.get(i)));
		}	
	}
	
	//N==S
	//E==W
//83 S 
	//69E
	//78N
	//87W
	
	//static ArrayList<Integer> cc = new ArrayList<>(10001);
	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	public static int gcd(int a, int b) {
        return b == 0 ? a: gcd(b, a % b);
	}
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


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

int main()
{
    int n;
    cin>>n;
    int a[n],dp[n];
    for(int i=0;i<n;i++)
        cin>>a[i];
    for(int i=0;i<n;i++)
        dp[i]=INT_MAX;
    dp[0]=0;   dp[1]=abs(a[1]-a[0]);
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(a[i]-a[i-1]),dp[i-2]+abs(a[i]-a[i-2]));
    cout<<dp[n-1];
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i,s,n) for (int i = s; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n,m; string s;
  cin >> n >> m >> s;
  vector<int> line(n+1);
  rep(i,0,n+1) {
    line[i] = stoi(s.substr(n-i,1));
  }
  int p = 0;
  vector<int> ans;
  bool flag = false;
  while (p < n) {
    int j = min(n,p+m);
    while (j > p) {
      if (line[j] == 0) {
        break;
      }
      j--;
    }
    if (j == p) {
      flag = true;
      break;
    }
    ans.push_back(j-p);
    p = j;
  }
  int l = ans.size();
  if (flag) {
    cout << -1 << endl;
  } else {
    rep(i,0,l-1) {
      cout << ans[l-i-1] << " ";
    }
    cout << ans[0] << endl;
  }
  return 0;
}


Measured memory_bytes: 4488
#include<iostream>
#include<numeric>
#include<math.h>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<iomanip>
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,from,to) for(int i=from;i<to;i++)
#define repd(i,from,till) for(int i=from;i>=till;i--)
#define waste ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define inf 1e9+1
#define mod 1e9+7
#define inf1 1e18+1
#define pie 3.14159265358979323846
#define N 100005
using namespace std;

void solve(){
	int l,r;
	cin>>l>>r;
	ll mini=inf1;
	if(r-l>=2019)cout<<"0"<<endl;
	else {
		rep(i,l,r+1){
			rep(j,i+1,r+1){
				mini=min(mini,(ll)(((i%2019)*(j%2019))%2019));	
				if(mini==0)break;
			}
		}
		cout<<mini<<endl;
	}
}
int main()
{
	waste;
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define vvll vector<vll>
#define all(v) v.begin(),v.end()
#define itr(r,v) for(auto r=v.begin();r!=v.end();r++)
#define FOR(i,n) for(ll i=0;i<n;i++)
#define ffo(i,a,b) for(ll i=a;i<=b;i++)
#define rfr(i,a,b) for(ll i=a;i>=b;i--)
#define space cout<<"\n\n";
#define endl "\n"
#define pqmx priority_queue<ll>
#define pqmn priority_queue<ll,vll,greater<ll>>
#define fps(x,y) fixed<<setprecision(y)<<x
#define merg(a,b,c) set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.begin()))
#define set_ar(arr,v) memset(arr,v,sizeof(arr))
#define ctime auto sttart = high_resolution_clock::now()
#define etime auto sttop = high_resolution_clock::now()
#define go_t ll testcases; cin>>testcases; for(ll caseno= 1 ;caseno <= testcases; caseno++)
#define ptime auto z1z = duration_cast<microseconds>(sttop-sttart); cout<<"\nTime taken : "<<z1z.count()<<" microseconds\n"
#define dbg1(x)             cout <<#x<<": "<<x<<'\n';
#define dbg2(x, y)          cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<'\n';
#define dbg3(x, y, z)       cout <<#x<<": "<<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<'\n';
#define dbg4(a, b, c, d)    cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<'\n';
#define dbg5(a, b, c, d, e) cout <<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<<": "<<e<<'\n';

using namespace std;
using namespace std::chrono;

const ll MOD = 1e9 + 7;
const ll N = 1e5 + 5;
const ll maxN = 3e3 + 5;
const ll MAX_SIZE = 2e6 + 6;
const ll INF = 0x3f3f3f3f3f3f3f3fll;
const double PI = 3.14159265359;

ll powerM(ll x, ll y, ll M = MOD) { // default argument
	ll v = 1; x = x % M; while (y > 0) {if (y & 1)v = (v * x) % M; y = y >> 1; x = (x * x) % M;} return v;
}

ll power(ll x, ll y) {
	ll v = 1; while (y > 0) {if (y & 1)v = v * x; y = y >> 1; x = x * x;} return v;
}

int n;
ll a[maxN];
ll dp[maxN][maxN][2];

ll solve(int l, int r, int turn) {
	if (l == r) {
		if (turn == 1) return dp[l][r][1] = a[l];
		else return dp[l][r][0] = 0;
	}
	if (dp[l][r][turn] != -1) return dp[l][r][turn];
	if (turn == 1)
		return dp[l][r][1] = max(a[l] + solve(l + 1, r, 0), a[r] + solve(l, r - 1, 0));
	else
		return dp[l][r][0] = min(solve(l, r - 1, 1), solve(l + 1, r, 1));
	// The first player tries to maximize his score in whichever state the game currently is
	// whereas the second player tries to minimize the max score of the state which
	// will be produced after he makes his move
}

int main()
{
#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	freopen("output1.txt", "w", stdout);
#endif
	FIO
	cin >> n;
	memset(dp, -1, sizeof(dp));
	ll sum = 0;
	FOR(i, n) cin >> a[i], sum += a[i];
	ll s = solve(0, n - 1, 1);
	// dbg2(s, sum);
	cout << s - (sum - s);
	return 0;
}


Measured memory_bytes: 144992
#include<stdio.h>
int main()
{
    int N, K;
    // 整数の入力
    // スペース区切りの整数の入力
    scanf("%d %d",&N,&K);
    // 文字列の入力
    // 出力
    printf("%d \n",N-K+1);
    return 0;
}

Measured memory_bytes: 128
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            string[] strary=cin.ReadStrArray(2);
            Console.WriteLine(strary[1] + strary[0]);



            


        }

    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 11220
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>

using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define EPS 1e-8
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f3f3f3f3f
#define MEM(a, b) memset(a, b, sizeof(a))
#define PPER(i, n, m) for (int i = n; i >= m; i--)
#define REPP(i, n, m) for (int i = n; i <= m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)
#define PER(i, n, m) for (int i = n; i > m; i--)
#define SA(n) scanf("%d", &(n))
#define SLLA(n) scanf("%lld", &(n))
#define MP make_pair
#define FF first
#define SS second
#define PB push_back
#define DE(val) cout << #val << ": " << val << endl;
 
const int dx44[6] = {0, -1, -1, 1, 1};
const int dy44[6] = {0, -1, 1, -1, 1};
const int dx4[6] = {0, 1, 0,-1};
const int dy4[6] = {1, 0, -1,0};
const int dx8[9] = {0, -1, 0, 1, 0, 1, 1, -1, -1};
const int dy8[9] = {0, 0, 1, 0, -1, 1, -1, 1, -1};
const int dx82[9] = {0, -1, -1, 1, 1, 2, 2, -2, -2};
const int dy82[9] = {0, 2, -2, 2, -2, 1, -1, 1, -1};

void update(ll& x,ll v){
    if(x==-1)x=v;
    else if(x>v)x=v;
}
 
ll po(ll a, ll b, ll mod)
{
    ll res = 1;
    a %= mod;
    for (; b; b >>= 1)
    {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
    }
    return res;
}
ll gcd(ll a, ll b)
{
    if (a == 0)
    {
        return b;
    }
    else
    {
        return gcd(b % a, a);
    }
}
void extgcd(ll a, ll b, ll &d, ll &x, ll &y)
{
    if (!b)
    {
        d = a;
        x = 1;
    }
    else
    {
        extgcd(b, a % b, d, y, x);
        y -= x * (a / b);
    }
}
ll inverse(ll a, ll n)
{
    ll d, x, y;
    extgcd(a, n, d, x, y);
    return d == 1 ? (x + n) % n : -1;
}
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
const int maxn = 5e5 + 15;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
/*************************************************************************/

ll n, a, b;
void solve() {
    cin>>n>>a>>b;
    if(abs(a - b) % 2 == 0) {
        cout<<abs(a-b)/2<<endl;
    } else {
        ll ans = n;
        ans = min(ans, (a - 1) + (b-a)/2 +1);
        ans = min(ans, (n-b) + (b-a)/2 +1);
        cout<< ans<<endl;
    }
}

int main()
{   
#ifndef ONLINE_JUDGE
    //freopen("i.txt", "r", stdin);
    // freopen("o.txt", "w", stdout);
#endif
    solve();
    return 0;
 
}
 

Measured memory_bytes: 256
import java.util.Scanner;

public class Main
{
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        String text = sc.nextLine();
        char [] arr = new char[1200];
        int [] ascii = new int [1200];
        arr = text.toCharArray();
        for (int i = 0; i <arr.length; i++)
        {
           ascii[i] =(int)arr[i];
           if(65<=ascii[i] && ascii[i]<=90)
           {
               ascii[i] = ascii[i] + 32; 
           }
           else if (97<=ascii[i] && ascii[i]<=122)
           {
               ascii[i] = ascii[i]-32;
           }
            arr[i] = (char)ascii[i];
            System.out.print(arr[i]);
        }
        System.out.println();
        

       
    
    
    
    
    }
}



Measured memory_bytes: 26836
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
ll jou(ll N, ll P){if(P==0) return 1;
  if(P%2==0){ll t = jou(N, P/2);return t*t % mod;
  }return (N * jou(N, P-1)) % mod;}  //jou(n,mod-2)で逆元
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる




int main(){
  ll n,x;
  cin>>n>>x;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  ll ans=0;
  rep(i,n-2){
    if(p[i]+p[i+1]>x && p[i+1]+p[i+2]>x) {
      ll eat=min(p[i]+p[i+1]-x,p[i+1]+p[i+2]-x);
      if(p[i+1]-eat>=0) {
        p[i+1]-=eat;
        ans+=eat;
      }
      else {
        ans+=p[i+1];
        p[i+1]=0;
      }
    }
  }

  rep(i,n-1){
    if(p[i]+p[i+1]>x) {
      ll eat=p[i]+p[i+1]-x;
      if(p[i+1]-eat>=0) {
        p[i+1]-=eat;
        ans+=eat;
      }
      else {
        p[i+1]=0;
        ans+=eat;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  	int N,Y;
    vector<int> vec(3);
  	vector<int> vecd(3);
    cin >> N >> Y;
  	for (int i=0;i<=N;i++)
    {
      for(int j=0;j<=N-i;j++)
      {
          if(10000*i+5000*j+1000*(N-i-j)==Y)
          { 
           vec.at(0)=i;
           vec.at(1)=j;
           vec.at(2)=N-i-j;
          }
      }
    }
  if(vec==vecd)
  cout <<"-1 -1 -1"<<endl;
    else
    cout << vec.at(0) <<" "<< vec.at(1) <<" "<< vec.at(2) << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        int result = 0;
        if (A == B) {
            result = C;
        }else if(A == C){
            result = B;
        }else{
            result = A;
        }
        System.out.println(result);

    }
}


Measured memory_bytes: 21844
import itertools

N = input()
N = int(N)
P = input().split()
P = [int(p) for p in P]
P = tuple(P)
Q = input().split()
Q = [int(q) for q in Q]
Q = tuple(Q)

CombinationN = list(itertools.permutations(range(1, N+1)))

for i, c in enumerate(CombinationN):
    if c == P:
        a = i
    if c == Q:
        b = i

print(abs(a-b))

Measured memory_bytes: 8052
#include<stdio.h>
#include<string.h>
int main(){
    int A,B;
    char S[10],T[10];
    scanf("%s %s",S,T);
    scanf("%d %d",&A,&B);
    char U[10];
    scanf("%s",U);
    if(strcmp(S,U) == 0)
        printf("%d %d",A-1,B);
    else
        printf("%d %d",A,B-1);
}
     


Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**9)

def mi(): return map(int,input().split())
def ii(): return int(input())
def isp(): return input().split()
def deb(text): print("-------\n{}\n-------".format(text))

INF=10**20
def main():
    a,b,c=mi()
    a,b = b,a
    a,c = c,a

    print(a,b,c)



if __name__ == "__main__":
    main()

Measured memory_bytes: 61968
#include <iostream>
#include <algorithm>

using namespace std;

long min_p;
int n;
int a[21];

void dfs(int i, long pon, long gon) 
{
    if (i == n) {
        min_p = min(min_p, abs(pon - gon));
    }
    else {
        dfs(i + 1, pon + a[i], gon);
        dfs(i + 1, pon, gon + a[i]);
    }
}

int main()
{
    while (cin >> n, n != 0) {
        min_p = 20000000;

        for (int i = 0; i < n; i++)
            cin >> a[i];
        
        dfs(0, 0, 0);
        cout << min_p << endl;
    }

    return 0;
}

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

using i64 = int64_t;

constexpr i64 MOD = 1e9 + 7;

void set_ncr(i64 n, vector<vector<i64>> &ncr){
    for(int i=0;i<=n;++i){
        ncr[i][0] = 1;
        ncr[i][i] = 1;
    }
    for(int i=2;i<=n;++i){
        for(int j=1;j<i;++j){
            ncr[i][j] = ncr[i-1][j-1] + ncr[i-1][j];
            ncr[i][j] %= MOD;
        }
    }
}

int main(){
    i64 n, k;
    cin >> n >> k;
    vector<vector<i64>> ncr(n+1, vector<i64>(n+1));
    set_ncr(n, ncr);
    for(int i=1;i<=k;++i){
        i64 tmp = 0;
        if(i == 1){
            tmp = ncr[n-k+1][n-k];
        }else{
            for(int j=1;j<=n-k;++j){
                i64 tmp2 = ncr[n-k-j+1][n-k-j];
                if(i > 1)tmp2 = tmp2 * ncr[j-1][i-2] % MOD;
                tmp += tmp2;
                tmp %= MOD;
                //cerr << tmp << endl;
            }
        }
        i64 ans = ncr[k-1][i-1] * tmp;
        ans %= MOD;
        //cerr << ncr[k-1][i-1] << " " << tmp << endl;
        cout << ans << endl;
    }

    return 0;
}


Measured memory_bytes: 31616
#include<stdio.h>
int main(void){
  char A[5]={'\0'},B[9]={'\0'},AB[13]={'\0'};
  scanf("%s",AB);
  for(int i=0;i<12;i++){
    if(i<=3){
      A[i]=AB[i];
    }else{
      B[i-4]=AB[i];
    }
  }
  printf("%s",A);
  printf(" ");
  printf("%s\n",B);
  return 0;
}

Measured memory_bytes: 128
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template<class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(vec) vec.begin(),vec.end()
typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
const ll mod=1e9+7;
const int inf=1<<30;

struct mint{
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const{return mint(-x);}
  mint& operator+=(const mint a){
    if((x+=a.x)>=mod) x-=mod;
    return *this;
  }
  mint& operator-=(const mint a){
    if((x+=mod-a.x)>=mod) x-=mod;
    return *this;
  }
  mint& operator*=(const mint a){
    (x*=a.x)%=mod;
    return *this;
  }
  mint operator+(const mint a) const{
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const{
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const{
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const{
    if(!t) return 1;
    mint a=pow(t>>1);
    a*=a;
    if(t&1) a*=*this;
    return a;
  }

  // for prime mod
  mint inv() const{
    return pow(mod-2);
  }
  mint& operator/=(const mint a){
    return (*this)*=a.inv();
  }
  mint operator/(const mint a) const{
    mint res(*this);
    return res/=a;
  }
};

mint dp[2010][2010];

int main(){
  int n,m;
  cin >> n >> m;
  vector<int> s(n);
  rep(i,n) cin >> s[i];
  vector<int> t(m);
  rep(i,m) cin >> t[i];
  dp[0][0]=1;
  rep(i,n+1)rep(j,m+1){
    if(i-1>=0&&j-1>=0&&s[i-1]==t[j-1]) dp[i][j]+=dp[i-1][j-1];
    if(i-1>=0)dp[i][j]+=dp[i-1][j];
    if(j-1>=0)dp[i][j]+=dp[i][j-1];
    if(i-1>=0&&j-1>=0)dp[i][j]-=dp[i-1][j-1];
  }
  cout << dp[n][m].x << endl;
}


Measured memory_bytes: 31872
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#define SIZE 200005
#define MOD 998244353

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

void chadd(int &X,int Y)
{
	X+=Y;
	if(X>=MOD) X-=MOD;
}
char str[SIZE];
int dp[2][3][3][3][2];

int main()
{
	scanf("%s",&str);
	int n=strlen(str);
	bool up=true;
	for(int i=0;i<n;i++)
	{
		if(str[i]!=str[0]) up=false;
	}
	if(up)
	{
		puts("1");
		return 0;
	}
	if(n==2)
	{
		puts("2");
		return 0;
	}
	if(n==3&&str[0]!=str[1]&&str[1]!=str[2]&&str[0]!=str[2])
	{
		puts("3");
		return 0;
	}
	int pos=0;
	dp[pos][2][2][0][0]=1;
	dp[pos][1][0][1][0]=1;
	dp[pos][0][1][2][0]=1;
	for(int i=1;i<n;i++)
	{
		pos^=1;
		memset(dp[pos],0,sizeof(dp[pos]));
		for(int a=0;a<3;a++)
		{
			for(int b=0;b<3;b++)
			{
				for(int c=0;c<3;c++)
				{
					for(int t=0;t<3;t++)//nxt
					{
						int na=a,nb=b;
						if(t==0)
						{
							na+=2,nb+=2;
							if(na>=3) na-=3;
							if(nb>=3) nb-=3;
						}
						else if(t==1)
						{
							na++;
							if(na>=3) na-=3;
						}
						else
						{
							nb++;
							if(nb>=3) nb-=3;
						}
						if(c==t)
						{
							chadd(dp[pos][na][nb][t][1],dp[pos^1][a][b][c][0]);
							chadd(dp[pos][na][nb][t][1],dp[pos^1][a][b][c][1]);
						}
						else
						{
							chadd(dp[pos][na][nb][t][0],dp[pos^1][a][b][c][0]);
							chadd(dp[pos][na][nb][t][1],dp[pos^1][a][b][c][1]);
						}
					}
				}
			}
		}
	}
	int b=0,c=0;
	up=true;
	for(int i=0;i<n;i++)
	{
		if(str[i]=='a')
		{
			b+=2,c+=2;
			b%=3,c%=3;
		}
		else if(str[i]=='b')
		{
			b++;
			b%=3;
		}
		else
		{
			c++;
			c%=3;
		}
		if(i>0&&str[i]==str[i-1])
		{
			up=false;
		}
	}
	int ret=up;
	for(int t=0;t<3;t++) chadd(ret,dp[pos][b][c][t][1]);
	printf("%d\n",ret);
	return 0;
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.List;

public class Main {

    public static void main(String[] args) throws IOException {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(is);

        List<String> mylist = new ArrayList<>();

        // 標準入力からの値を変数strinputに代入
        String strinput = reader.readLine();

        while (strinput != null) {

            mylist.add(strinput);
            strinput = reader.readLine();

        }
        String arr01[] = mylist.get(0).split(" ");
        String arr02[] = mylist.get(1).split(" ");
        Integer n = Integer.valueOf(arr01[0]);
        String s = arr02[0];

        Boolean chkflg = false;
        if (n % 2 == 0) {

            if (s.substring(0, n / 2).equals(s.substring(n / 2, n))) {
                chkflg = true;
            }

        }
        System.out.println(chkflg ? "Yes" : "No");

    }

}

Measured memory_bytes: 21076
using System;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
        new Program().SolveA();
        Console.ReadKey();
    }

    Scanner sc = new Scanner();
    void SolveA()
    {
        int x = sc.NextInt();
        int y = sc.NextInt();
        int res = 0;
        if (x <= y)
        {
            res = Min(Math.Abs(x - y), 1 + Math.Abs(-x - y));
        }
        else
        {
            res = Min(Math.Abs(x - y) + 2, Math.Abs(-x - y) + 1);
        }
        Console.WriteLine(res);
    }

    void SolveB()
    {

    }


    // ------------------------------------- //
    int Max(int v1, int v2) { return Math.Max(v1, v2); }
    int Min(int v1, int v2) { return Math.Min(v1, v2); }
    int[][] CreateArray2D(int n1, int n2)
    {
        int[][] ary = new int[n1][];
        for (int i = 0; i < n1; i++) ary[i] = new int[n2];
        return ary;
    }
}
class Scanner
{
    public Scanner() { }
    private string[] buff = null;
    private int bIndex = 0;
    public string Next()
    {
        if (buff == null || bIndex >= buff.Length)
        {
            buff = Console.ReadLine().Split(' ');
            bIndex = 0;
        }
        return buff[bIndex++];
    }
    public int NextInt()
    {
        return int.Parse(Next());
    }
    public long NextLong()
    {
        return long.Parse(Next());
    }
}
class Pair<T, K>
{
    public Pair() { }
    public Pair(T f, K s)
    {
        first = f;
        second = s;
    }
    public T first {get; set;}
    public K second {get; set;}
}

Measured memory_bytes: 2776
#include <iostream>
#include <climits>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <string>
#include <deque>
#define INF_INT (INT_MAX / 2)
#define INF_LONG (LONG_MAX / 2)
#define DEBUG true
//#define DEBUG false
#define MAX_N 100000
using namespace std;

const int MAX = 100001;
const int MOD = 1000000007;

typedef long long ll;
typedef pair< int, int > pii;
typedef pair< ll, ll > pll;
typedef pair< ll, int > pli;
typedef pair< int, ll > pil;

int ceil(int x, int y){
  return (x % y == 0) ? x / y : x / y + 1;
}

int gcd(int x, int y){
  return y ? gcd(y, x % y) : x;
}

int lcm(int x, int y){
  return x / gcd(x, y) * y;
}

vector< int > graph[MAX_N];
vector< int > igraph[MAX_N];

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

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

  int ind[n];
  fill(ind, ind + n, 0);
  for(int i = 0; i < n - 1 + m; i++){
    graph[a[i]].push_back(b[i]);
    ind[b[i]]++;
    igraph[b[i]].push_back(a[i]);
  }

  int root;
  for(int v = 0; v < n; v++){
    if(ind[v] == 0){
      root = v;
      break;
    }
  }

  int order[n], iorder[n];
  int i = 0;
  queue< int > que;
  que.push(root);
  while(!que.empty()){
    int v = que.front(); que.pop();
    order[i] = v; iorder[v] = i;
    ++i;
    for(int w: graph[v]){
      ind[w]--;
      if(ind[w] == 0) que.push(w);
    }
  }

  int parent[n];
  parent[root] = 0;
  for(int v = 0; v < n; v++){
    if(v == root) continue;
    int p = -1;
    for(int w: igraph[v]){
      p = max(p, iorder[w]);
    }
    parent[v] = order[p] + 1;
  }

  string buf;
  for(int v = 0; v < n; v++){
    buf += to_string(parent[v]) + "\n";
  }

  cout << buf;

  return 0;
}


Measured memory_bytes: 14840
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e9+7;
ll dp[205][100005];
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n,x;cin>>n>>x;
    ll a[n];for(ll i=0;i<n;i++)cin>>a[i];
    sort(a,a+n);
    for(ll i=0;i<=x;i++)dp[0][i]=(i%a[0]);
    for(ll i=1;i<n;i++){
        for(ll j=0;j<=x;j++){
            dp[i][j] = dp[i-1][j%a[i]] + (i*dp[i-1][j])%mod;
            dp[i][j]%=mod;
        }
    }
    cout<<dp[n-1][x];
}



Measured memory_bytes: 157952
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;
 
public class Main {
 
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt(), Q = sc.nextInt();
    String S = sc.next();
    int A[] = new int[S.length() + 1];
    for (int i = 1; i < S.length(); i++)
    {
      if (S.charAt(i - 1) == 'A' && S.charAt(i) == 'C')
      {
        A[i] = 1;
      }
      else
      {
        A[i] = 0;
      }
    }
    int PSA[] = new int[S.length() + 1];
    for (int i = 1; i <= S.length(); i++)
    {
      PSA[i] = PSA[i - 1] + A[i];
    }
    for (int i = 0; i < Q; i++)
    {
      int l = sc.nextInt(), r = sc.nextInt();
      int result = PSA[r - 1] - PSA[l - 1];
      System.out.println(result);
    }
  }
}


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

using namespace std;



int main(){
	long long n,a,b,blue=0;


	cin >> n>> a>> b;
	
	blue += n/(a+b)*a;
	blue += min(n%(a+b) , a);

	cout << blue << endl;
	cin >> n;
	return 0;

	
}



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

template <typename InputIterator>
typename InputIterator::value_type summation(InputIterator first,
                                             InputIterator last) {
  return std::accumulate(first, last, typename InputIterator::value_type());
}
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v);
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p);
template <typename T>
std::istream &operator>>(std::istream &stream, std::vector<T> &v) {
  for (auto &i : v) {
    stream >> i;
  }
  return stream;
}
template <typename T1, typename T2>
std::istream &operator>>(std::istream &stream, std::pair<T1, T2> &p) {
  stream >> p.first >> p.second;
  return stream;
}

int main() {
  int64_t h, w;
  std::cin >> h >> w;
  std::vector<std::vector<int64_t>> a(h, std::vector<int64_t>(w)),
      b(h, std::vector<int64_t>(w)), c(h, std::vector<int64_t>(w));
  std::cin >> a >> b;

  for (int64_t i = 0; i < h; i++) {
    for (int64_t j = 0; j < w; j++) {
      c[i][j] = std::abs(a[i][j] - b[i][j]);
    }
  }

  const int64_t max = (h + w + 1) / 2 * 80;
  const int64_t min = -max;
  const int64_t num = max - min + 1;

  std::vector<std::vector<std::vector<bool>>> s(
      h, std::vector<std::vector<bool>>(w, std::vector<bool>(num, false)));

  std::vector<std::vector<bool>> f(h, std::vector<bool>(w, false));
  std::queue<std::pair<int64_t, int64_t>> q;

  q.push(std::make_pair(0, 0));

  s[0][0][-min] = true;

  while (!q.empty()) {
    const auto data = q.front();
    const auto i = data.first;
    const auto j = data.second;
    q.pop();

    const auto val = c[i][j];
    for (int64_t k = 0; k < num; k++) {
      if (!s[i][j][k]) {
        continue;
      }
      const auto v1 = k + val;
      const auto v2 = k - val;
      if (i + 1 < h) {
        if (0 <= v1 && v1 < num) {
          s[i + 1][j][v1] = true;
        }
        if (0 <= v2 && v2 < num) {
          s[i + 1][j][v2] = true;
        }

        if (!f[i + 1][j]) {
          q.push(std::make_pair(i + 1, j));
          f[i + 1][j] = true;
        }
      }
      if (j + 1 < w) {
        if (0 <= v1 && v1 < num) {
          s[i][j + 1][v1] = true;
        }
        if (0 <= v2 && v2 < num) {
          s[i][j + 1][v2] = true;
        }

        if (!f[i][j + 1]) {
          q.push(std::make_pair(i, j + 1));
          f[i][j + 1] = true;
        }
      }
    }
  }

  int64_t ans = 80;

  for (int64_t k = 0; k < num; k++) {
    if (!s[h - 1][w - 1][k]) {
      continue;
    }
    const auto val = c[h - 1][w - 1];
    ans = std::min(ans, std::abs(k + min - val));
    ans = std::min(ans, std::abs(k + min + val));
  }

  std::cout << ans << std::endl;

  return 0;
}

Measured memory_bytes: 10880
#include <bits/stdc++.h>
#define repr(i,from,to) for(int (i)=(from);(i)<(to);(i)++)
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
// const bool debug=true;
const bool debug=false;
#define DEBUG if(debug==true)
#define vprint(x) for(auto a:(x)) cout << x << endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const ll MOD = 1000000007;
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) { a = b; return true;}
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) { a = b; return true;}
    return false;
}
int main(void) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    set<int> children[n+1];
    vector<int> cnt(n+1,0);
    vector<int> parent(n+1,0);

    rep(i,n+m-1){
        int s,t;cin>>s>>t;
        s;t;
        cnt[t]++;
        children[s].insert(t);
    }
    int root;
    repr(i,1,n+1){
        if(cnt[i]==0){
            root = i;
        }
    }
    stack<int> que;
    que.push(root);
    vector<bool> check(n,false);
    while(!que.empty()){
        int now = que.top();
        que.pop();
        // if(check[now]){
        //     continue;
        // }
        check[now]=true;
        DEBUG{
            printf("now: %d\n",now);
        }
        for(auto x:children[now]){
            cnt[x]--;
            if(cnt[x]==0){
                que.push(x);
            }
            parent[x] = now;
        }
    }
    repr(i,1,n+1){
        cout << parent[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 11340
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
using std::endl;
using std::cin;
using std::cout;
using std::vector;
using std::pair;
using std::string;

int main(void)
{
    int32_t X;
    cin >> X;

    if (X == 3 || X == 5 || X == 7) {
        cout << "YES";
    } else {
        cout << "NO";
    }

    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
    int n, d, x, ai;
    scanf("%d", &n);
    scanf("%d %d", &d, &x);
    for(int i = 0; i < n; i++){
        scanf("%d", &ai);
        x += (floor((d-1)/ai) + 1);
    }

    printf("%d", x);
    return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static List<int[]> list = new ArrayList<>();
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String s = sc.next();
        String t = sc.next();
        int length = 0;
        for (int i = 0; i < N; i++) {
            String S = s.substring(i, N);
            String T = t.substring(0, N-i);
            if (S.equals(T)) {
                length = S.length();
                break;
            }
        }
        System.out.println(N*2-length);
    }
}

Measured memory_bytes: 21844
from collections import deque

INF = float('inf')

N, K = map(int, input().split())
edges = [list(map(lambda x: int(x) - 1, input().split())) for e in range(N - 1)]

adjL = [[] for v in range(N)]
for a, b in edges:
    adjL[a].append(b)
    adjL[b].append(a)

# 頂点の集合VCenterから距離radius以内にある頂点の数を求める
def bfs(adjList, VCenter, radius):
    numV = len(adjList)

    dist = [INF] * numV
    for v in VCenter:
        dist[v] = 0

    ans = 0
    Q = deque(VCenter)
    while Q:
        vNow = Q.popleft()
        distNow = dist[vNow]

        if distNow > radius: break
        ans += 1

        for v2 in adjList[vNow]:
            if dist[v2] != INF: continue
            dist[v2] = distNow + 1
            Q.append(v2)

    return ans


# 削除後の「直径Kの木」の中心を全探索する
if K % 2:
    # Kが奇数の場合、全ての辺を試す
    VC = edges
    r = (K - 1) // 2
else:
    # Kが偶数の場合、全ての頂点を試す
    VC = [[v] for v in range(N)]
    r = K // 2

ans = N
for V in VC:
    num = bfs(adjL, V, r)
    ans = min(ans, N - num)

print(ans)


Measured memory_bytes: 4212