akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <cassert>
#include <cstring>

const int dx[] = {0, 1, 0, -1};
const int dy[] = {-1, 0, 1, 0};
int field[5][5];
using namespace std;
enum FACE{TOP,BOTTOM,NORTH,SOUTH,WEST,EAST};
struct dice{
  int num[6];

  int &operator[](FACE f) { return num[f]; }

  void roll(FACE a, FACE b, FACE c, FACE d) {
    const int tmp = num[a];
    num[a] = num[b];
    num[b] = num[c];
    num[c] = num[d];
    num[d] = tmp;
  }

  void move(int d) {
    switch(d) {
    case 0: roll(TOP, SOUTH, BOTTOM, NORTH); break;
    case 1: roll(TOP, WEST, BOTTOM, EAST);   break;
    case 2: roll(TOP, NORTH, BOTTOM, SOUTH); break;
    case 3: roll(TOP, EAST, BOTTOM, WEST);   break;
    default: assert(false);
    }
  }
};
bool valid(int x,int y){
  return x >= 0 && x < 5 && y >= 0 && y < 5;
}
void dfs(int x,int y,dice &die){
  
  die[BOTTOM] = field[y][x];
  field[y][x] = 0;
  for(int i =0 ;i < 4;i++){
    int nx = x + dx[i];
    int ny = y + dy[i];
    if(valid(nx,ny)){
      if(field[ny][nx]){
	die.move(i);
	dfs(nx,ny,die);
	die.move((i+2)%4);
      }
    }
  }
  
}
bool solve(){
  int cnt[7] = {};
  for(int i = 0;i < 5;i++){
    for(int j = 0;j < 5;j++){
      cin >> field[i][j];
      cnt[field[i][j]]++;
    }
  }
  for(int i = 1;i <= 6;i++){
    if(cnt[i] != 1)return false;
  }
  dice die;
  
  for(int i = 0;i < 5;i++){
    for(int j = 0;j < 5;j++){
      if(field[i][j] != 0){
	dfs(j,i,die);
	goto unloop;
      }
    }
  }
 unloop:;

  return die[TOP] + die[BOTTOM] == 7 && die[EAST] + die[WEST] == 7 && die[NORTH] + die[SOUTH] == 7;
}
int main(){
  int n;
  cin >> n;
  while(n--){
    cout << (solve() ? "true" : "false") << endl;
  }
  return 0;
}

Measured memory_bytes: 1148
import java.util.*;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int number = 2;
        int[] a = new int[2];
        for(int i = 0; i < number; i++){
            a[i] = sc.nextInt();
        }
        sc.close();
        int applepie = ApplePie(a);
        System.out.println(applepie);
    }
    private static int ApplePie(int a[]){
        int pie = a[0] * 3 + a[1];
        pie = pie / 2;
        return pie;
    }
}

Measured memory_bytes: 23252
#include<stdio.h>

int main(void){
   int d,s,i;

while(scanf("%d",&d)!=EOF){
   s=0;
   for(i=0;i<=600-d;i=i+d){
      s=s+(i*i*d);
      }
   printf("%d\n",s);
   }
   return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N = 100010;
int n, k, a[N];
 
 
int main()
{
    cin >> n >> k;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int ans = 2e9+10;
    for (int i = 1; i+k-1 <= n; i++){
        if ((long long)a[i]*a[i+k-1] < 0)
            ans = min(ans, (int)abs(a[i])+(int)abs(a[i+k-1])+min((int)abs(a[i]), (int)abs(a[i+k-1])));
        else ans = min(ans, max((int)abs(a[i]), (int)abs(a[i+k-1])));
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
#include<cstdio>
#include<cmath>
#include<algorithm>
using namespace std;
int main(){
    int n;
    scanf("%d",&n);
    for(int q = 0;q < n; q++){
        int a=0,b=0,ans=0;
        char str[10]={0};
        scanf("%s",str);
        sort(str,str+8);
        for(int i = 7;i >= 0; i--){
            int x = pow(10.0,(double)i);
            a += (str[7-i]-48)*x;
            b += (str[i]-48) * x;
        }
        ans = b - a;
        printf("%d\n",ans);
    }
    return 0;
}

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



ll N,A,B;

int main(){

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

	ll ans = A*(N/(A+B));

	ans += min(A,N%(A+B));

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

	return 0;
}


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

int radix[17];
int end[16][2];

void mk_radix() {
	int x = 1;
	for(int i = 0; i < 17; i++) {
		radix[i] = x;
		x *= 3;
	}

	end[0][0] = 0;
	end[0][1] = 2;
	for(int i = 1; i < 16; i++) {
		end[i][0] = end[i-1][0] + radix[i]*0;
		end[i][1] = end[i-1][1] + radix[i]*2;
	}
}

int main() {
	int n, m;
	mk_radix();
	while(cin >> n >> m, n || m) {
		bitset<50000000> used;
		int in = 0;
		for(int i = 0; i < 3; i++) {
			int k;
			cin >> k;
			for(int j = 0; j < k; j++) {
				int a;
				cin >> a;
				in += i * radix[a-1];
			}
		}

		used.set(in);
		queue<int> q;
		q.push(in);
		int ans = 0;
		bool flg = false;
		while(!q.empty()) {
			queue<int> nex;
			while(!q.empty()) {
				int a = q.front();
				q.pop();
				int c[3] = {-1,-1,-1};
				int d = 0;

				if(a == end[n-1][0] || a == end[n-1][1]) {
					flg = true;
					goto EXIT;
				}

				int tmp = a;
				while(d < n) {
					c[tmp%3] = d;
					tmp /= 3;
					d++;
				}

				if(c[1] != -1 && c[1] > c[0]) {
					int e;
					e = (a / radix[c[1] + 1])*radix[c[1] + 1] + 0 * radix[c[1]] + a % radix[c[1]];
					if(!used[e]) {
						used.set(e);
						nex.push(e);
					}
				}
				if(c[1] != -1 && c[1] > c[2]) {
					int e;
					e = (a / radix[c[1] + 1])*radix[c[1] + 1] + 2 * radix[c[1]] + a % radix[c[1]];
					if(!used[e]) {
						used.set(e);
						nex.push(e);
					}
				}
				if(c[0] != -1 && c[0] > c[1]) {
					int e;
					e = (a / radix[c[0] + 1])*radix[c[0] + 1] + 1 * radix[c[0]] + a % radix[c[0]];
					if(!used[e]) {
						used.set(e);
						nex.push(e);
					}
				}
				if(c[2] != -1 && c[2] > c[1]) {
					int e;
					e = (a / radix[c[2] + 1])*radix[c[2] + 1] + 1 * radix[c[2]] + a % radix[c[2]];
					if(!used[e]) {
						used.set(e);
						nex.push(e);
					}
				}
			}
			ans++;
			q = nex;
		}
		EXIT:;
		if(ans <= m && flg)
			cout << ans << endl;
		else
			cout << -1 << endl;
	}
}

Measured memory_bytes: 7308
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))

if a[0]-b[0] == a[1]-b[1] == a[2]-b[2] and b[0]-c[0] == b[1]-c[1] == b[2]-c[2]:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#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 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
 
int main()
{
  ll a, b;
  cin >> a >> b;

  if(a>0&&b>0){
    cout << "Positive" << endl;
  }else if(a<=0&&b>=0){
    cout << "Zero" << endl;
  }else if(a<0&&b<0&&(b-a)%2==0){
    cout << "Negative" << endl;
  }else{
    cout << "Positive" << endl;
  }
}

Measured memory_bytes: 256
import java.util. *;

class Main{
    public static void main(String[] args){
        Scanner input = new Scanner(System.in);
        int a = Integer.parseInt(input.next());
        int h = a/3600;
        a %= 3600;
        int m = a/60;
        a %= 60;
        System.out.println(h+":"+m+":"+a);      
    }
}


Measured memory_bytes: 26104
#include<stdio.h>
int main(void){
int x=1,y=1;
int temp;
int r=0;

scanf("%d",&x);
scanf("%d",&y);
if(x<y){
temp=x;
x=y;
y=temp;
}

r=x%y;
while(r!=0){
x=y;
y=r;
r=x%y;
}
printf("%d\n",y);
return 0;
}


Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define MOD 1000000007
#define MOD2 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long Int;
typedef pair<Int, Int> P;

int main() {
    int a, b, c;
    Int k;
    cin >> a >> b >> c >> k;
    int ans = a - b;
    if (k % 2 == 1) ans *= -1;
    cout << ans << endl;
}

Measured memory_bytes: 256
a,b,x = list(map(int, input().split()))

if a%x ==0 and b%x == 0:
    print(b//x-a//x+1)
elif a%x == 0:
    print(b//x-a//x+1)
elif b%x == 0:
    print(b//x-a//x)
else:
    print(b//x-a//x)


Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

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

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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;
}

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

ll ctoi(const char c) {
  if ('0' <= c && c <= '9') return (c - '0');
  return -1;
}

signed main() {
  string S;
  cin >> S;

  ll F = ctoi(S[0]) * 10 + ctoi(S[1]);
  ll B = ctoi(S[2]) * 10 + ctoi(S[3]);

  if (F == 0 && B == 0) {
    COUT("NA");
    return 0;
  }

  if (F > 12 && B > 12) {
    COUT("NA");
    return 0;
  }

  if (F > 12 && 1 <= B && B <= 12) {
    COUT("YYMM");
    return 0;
  }

  if (1 <= F && F <= 12 && B > 12) {
    COUT("MMYY");
    return 0;
  }

  if (F == 0 && 1 <= B && B <= 12) {
    COUT("YYMM");
    return 0;
  }

  if (1 <= F && F <= 12 && B == 0) {
    COUT("MMYY");
    return 0;
  }

  if (F <= 12 && B <= 12) {
    COUT("AMBIGUOUS");
    return 0;
  }

  COUT("NA");
  return 0;
}

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

inline int square(int x) {
    return x * x;
}

int N;
int A[100];

int main() {
    scanf("%d", &N);
    for (int i = 0; i < N; i++)
        scanf("%d", &A[i]);
    int sum = 0;
    for (int i = 0; i < N; i++)
        sum += A[i];
    int avg1 = sum / N, avg2 = avg1 + 1;
    int res1 = 0;
    for (int i = 0; i < N; i++)
        res1 += square(avg1 - A[i]);
    int res2 = 0;
    for (int i = 0; i < N; i++)
        res2 += square(avg2 - A[i]);
    printf("%d", min(res1, res2));
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<climits>
#include<algorithm>
#include<cmath>
#include<queue>
using namespace std;
#define MAXN 100000
#define MAXM 100000
#define INF 1000000000000000
struct node
{
    int next,to;
    long long w;
}e[MAXM*2+5];
struct Qr
{
    int xr,dec;
    long long lim;
};
long long T;
int cnt,m,n;
int x,y,z,flag;
long long ri=INF,le=-INF;
long long vis[2][MAXN+5];
int b[MAXN+5];
void fpush(int u,int v,long long w)
{
    e[++cnt].next=b[u];
    e[cnt].w=w;
    e[cnt].to=v;
    b[u]=cnt;
}
int Ch(int x){if(x==-1)x=0;return x;}
int main()
{
    fill(vis[0],vis[0]+MAXN+1,INF);
    fill(vis[1],vis[1]+MAXN+1,INF);
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d%d",&x,&y,&z);
        fpush(x,y,z);fpush(y,x,z);
    }
    queue<Qr> Q;
	Q.push((Qr){1,1,0});
	while(!Q.empty())
	{
	    Qr A=Q.front();
	    Q.pop();
	    int xr=A.xr,dec=A.dec;
	    long long lim=A.lim;
	    for(int i=b[xr];i;i=e[i].next)
        {
            int xnext=e[i].to;
            long long nlim=e[i].w-lim;
            int FD=Ch(dec);
            if(vis[FD][xnext]!=INF)
            {
                if(vis[FD][xnext]!=nlim){printf("0\n");return 0;}
                else continue;
            }
            vis[FD][xnext]=nlim;
            if(!FD)le=max(le,-vis[FD][xnext]);
            else ri=min(ri,vis[FD][xnext]);
            Q.push((Qr){xnext,-dec,nlim});
        }
	}
    long long T=-1;
    for(int i=1;i<=n;i++)
        if(vis[0][i]!=INF&&vis[1][i]!=INF)
        {
            long long NT=(vis[1][i]-vis[0][i])/2;
            if(NT<0){flag=1;break;}
            if(T==-1)T=NT;
            else if(T!=NT){flag=1;break;}
        }
    if(flag){printf("0\n");}
    if(T!=-1)
    {
        if(T>le&&T<ri)printf("1\n");
        else printf("0\n");
    }
    else printf("%lld",max((long long)0,ri-le-1));
}

Measured memory_bytes: 6912
N = int(input())
A_s = [int(input()) for _ in range(N)]
max_a = max(A_s)
is_double_max = False
for i in range(N):
  if A_s[i] != max_a or is_double_max:
      print(max_a)
  else:
      A_s.pop(i)
      if max(A_s) == max_a:
          is_double_max = True
      print(max(A_s))
      A_s.insert(i,max_a)

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

using namespace std;
typedef long long ll;
typedef pair<int,ll> pil;
const int maxN = 1000010;
const int maxC = 1e6 + 10;
const int INF = 1e9; 

ll a[maxN];
ll b[maxN];
int main()
{
   	scanf("%d",&a[1]);
   	b[a[1]]++;
   	for(int i=2;i<=1000000;i++)
   	{
   		ll x = a[i-1];
   		if(x%2 == 0)
   		{
   			a[i] = a[i-1]/2;	
		}
		else
		{
			a[i] = 3*a[i-1] + 1;
		}
		b[a[i]]++;
		if(b[a[i]] == 2)
		{
			printf("%d\n",i);
			break;
		}
	}
    return 0;
}

Measured memory_bytes: 2304
import numpy as np

N, M, C = map(int, input().split())
B = np.array(list(map(int, input().split())))
A = []
ans = 0
for n in range(N):
    a = np.array(list(map(int, input().split())))
    if np.dot(a, B) + C > 0:
        ans += 1

print(ans)


Measured memory_bytes: 12488
n, m = map(int,input().split())
graph = [[] for _ in range(n+1)]

for i in range(m):
    a, b = map(int, input().split())
    graph[a].append(b)
    graph[b].append(a)

counter = 0
def dfs(pointer, already_visited):
    global counter
    if len(already_visited) == n - 1:
        counter += 1
    for el in graph[pointer]:
        if el in already_visited:
            continue
        dfs(el, already_visited + [pointer])

dfs(1, [])
print(counter)


Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <climits>
#include <cstring>
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

using namespace std;

const int N_MAX = 3000000;
int a[N_MAX];
int b[N_MAX];
int c[N_MAX];

void countingsort(int* a, int n){
  int k = 10001;
  rep(i, 1, k) c[i] = c[i] + c[i-1];
  rep(i, n, -1){
    b[c[a[i]]-1] = a[i];
    c[a[i]]--;
  }
}

int main(){
  int n;
  cin >> n;
  memset(c, 0, N_MAX*sizeof(c[0]));
  
  rep(i, 0, n){
    cin >> a[i];
    c[a[i]]++;
  }
  countingsort(a, n);
  rep(i, 0, n){
    cout << b[i];
    if(i==n-1) cout << endl;
    else cout << " ";
  }
  return 0;
}



Measured memory_bytes: 30308
#include<stdio.h>
int main(void){
int n,k;
scanf("%d%d",&n,&k);
  char s[n+1];
  scanf("%s",&s);
  for(int i=0;i<n;i++){
	if(i==k-1)printf("%c",s[i]+'a'-'A');
    else printf("%c",s[i]);
  }
  return 0;
}

Measured memory_bytes: 128
s = '0' + input()
m = len(s)
up = 0
cnt = 0
y = []
for i in range(-1, -m-1, -1):
    cs = int(s[i]) + up
    if cs < 5 or (cs == 5 and int(s[i-1]) < 5):
        cnt += cs
        y.append([cs, s[i]])
        up = 0
    else:
        cnt += 10 - cs
        y.append([10 - cs, s[i]])
        up = 1
        
print(cnt)

Measured memory_bytes: 98784
type drink = {price: int; stock: int};;
let compare_drink d1 d2 = d1.price - d2.price;; 

let (+=) v add = v := !v + add;;

let input_drink_array n = Array.init n @@ fun _ -> Scanf.scanf " %d %d" @@ fun a b -> {price = a; stock = b};;

let () = Scanf.scanf "%d %d" @@ fun n m -> 
  let drinks = input_drink_array n in (
    Array.fast_sort compare_drink drinks;
    let ans = ref 0 in
    let cnt = ref 0 in (
      for i = 0 to n - 1 do
        if drinks.(i).stock + !cnt < m then (
          ans += drinks.(i).price * drinks.(i).stock;
          cnt += drinks.(i).stock
        ) else if !cnt < m then (
          let rest = m - !cnt in (
            ans += drinks.(i).price * rest;
            cnt += m
          )
        )
      done;
      Printf.printf "%d\n" !ans
    )
  )
;;

Measured memory_bytes: 6784
import java.util.Scanner;

public class Main {
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N;
		N=sc.nextInt();
		int gokei[]=new int[N];
		int karikei[]=new int[N];
		int x,y,b,p,z;
		for(z=0;z<=N-1;z++){
			x=sc.nextInt();
			y=sc.nextInt();
			b=sc.nextInt();
			p=sc.nextInt();
			gokei[z]=x*b+y*p;
			karikei[z]=(x*5+y*2)*8/10;
			if(b>=5&&p>=2){
				karikei[z]=(x*b+y*p)*8/10;
			}else if(b>=5){
				karikei[z]=(x*b+y*2)*8/10;
			}else if(p>=2){
				karikei[z]=(x*5+y*p)*8/10;
			}
			
		}

		for(z=0;z<=N-1;z++){
			if(gokei[z]<karikei[z]){
			System.out.println(gokei[z]);
			}else  System.out.println(karikei[z]);
		}

	}

}

Measured memory_bytes: 23384
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, k, a[1003] = {}, z = 0;
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> a[i];
    sort(a, a + n);
    for (int i = 0; i < k; i++) z += a[i];
    cout << z;
}


Measured memory_bytes: 3664
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		try {
			String s1 = sc.next();
			String s2 = sc.next();
			String s3 = sc.next();

			System.out.println(s1.substring(0, 1).toUpperCase() + s2.substring(0, 1).toUpperCase() + s3.substring(0, 1).toUpperCase());

		} finally {
			sc.close();
		}
	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
char s[1000],t[1000];
int n;
bool pa(int a,int b)
{
	bool temp=0;
	double ab=b-a+1;
	int l=a,r=b;
	while(l<=r)
	{
		if(t[l]!=t[r]) temp=1;
		l++;r--;
	}
	if(temp) return false;
	else return true;
}
int main()
{
	scanf("%s",s);
	n=strlen(s)-1;
	for(int k=0;k<=n;++k)
	{
		t[k+1]=s[k];
	}
	n+=1;
	//cout<<n;
	//for(int i=1;i<=n;++i)
	//cout<<t[i];
	
	if(pa(1,(n-1)/2)&&pa(1,n)&&pa((n+3)/2,n)) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

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

int main(){
  char s[100], t[100]="0";
  int k, i;
  scanf("%d %s", &k, &s);
  
  if(strlen(s)<=k)
    printf("%s", s);
  else{
    for(i=0; i<k; i++)
      t[i]=s[i];
    for(i=k; i<=k+2; i++)
      t[i]='.';
  	printf("%s", t);
  }  
  return 0;
}
 

Measured memory_bytes: 1732
A, B, C = map(int, input().split())
K = int(input())


def dfs(a, b, c, k):
    # print(a, b, c, k)
    yield (a, b, c)
    if k+1 <= K:
        for x, y, z in dfs(a, b*2, c, k+1):
            yield (x, y, z)
        for x, y, z in dfs(a, b, c*2, k+1):
            yield (x, y, z)


for a, b, c in dfs(A, B, C, 0):
    if a < b < c:
        print('Yes')
        exit()
print('No')


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

using namespace std;

int main()
{
    string r1,r2;
    getline(cin,r1);
    getline(cin,r2);
    if(r1[0]==r2[2] && r1[1]==r2[1] && r1[2]==r2[0])
        cout<<"YES";
    else
        cout<<"NO";
}


Measured memory_bytes: 256
import sys


input = sys.stdin.readline
k, s = map(int, input().split())

min_num = s - k * 2
if min_num <= 0:
    min_num = 0

ans = 0

for x in range(min_num, k + 1):
    for y in range(min_num, k + 1):
        z = s - x - y
        if z > k or z < 0:
            continue
        else:
            ans += 1

print(ans)

Measured memory_bytes: 40684
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=(input.trim()).split("\n");
var n=Arr.shift()-0;
var arr=Arr.shift().split(" ").map(Number);
var max=Math.max.apply(null,arr);
var ans=[];
if(n==2)for(var i=1;i<=max;i++){
if(arr[0]%i==0 && arr[1]%i==0)ans.push(i);
}
if(n==3)for(var i=1;i<=max;i++){
if(arr[0]%i==0 && arr[1]%i==0 && arr[2]%i==0)ans.push(i);
}
console.log(ans.join("\n"));

Measured memory_bytes: 8684
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>

//#define int long long

#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;

mt19937 mrand(random_device{}());

double PI = acos((double)-1);
const ld eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
//const ll mod = 1e9 + 9;
const ll mod = 998244353;

void solve();
void scan();

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

void solve(){
	int n; cin >> n;
	vector<pair<int, int>> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i].first;
		a[i].second = i;
	}
	sort(all(a));
	int cnt = 0;
	for(int i = 0; i < n; i++){
		if (a[i].second % 2 != i % 2)
			cnt++;
	}
	cout << cnt / 2 << endl;
	return;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k); i > (n); i--)
#define FORre(i, k, n) for(int i = (k); i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

const int mod = 1000000007;

class mint{
  public:
  ll x;
  mint(ll x = 0):x(x % mod){};
  mint pow(ll y) const {
    mint res(1);
    mint a(x);
    while(y>0){
      if(y&1) res *= a;
      a *= a;
      y >>= 1;
    }
    return res;
  }
  mint inv() const{ return pow(mod-2); }
  mint& operator+= (const mint a) noexcept {
    if((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-= (const mint a) noexcept {
    if((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*= (const mint a) noexcept {
    (x *= a.x) %= mod;
    return *this;
  }
  mint& operator/= (const mint a) noexcept {
    return (*this) *= a.inv();
  }
  mint operator+ (const mint a) const noexcept {
    mint res(*this);
    return res += a;
  }
  mint operator- (const mint a) const noexcept {
    mint res(*this);
    return res -= a;
  }
  mint operator* (const mint a) const noexcept {
    mint res(*this);
    return res *= a;
  }
  mint operator/ (const mint a) const noexcept{
    mint res(*this);
    return res /= a;
  }
};

mint modncm(ll n, ll m){
  mint a = 1, b = 1;
  REP(i, m) a *= mint(n-i), b *= (m-i);
  return a * b.inv();
}

int main(void){
  int n, m;
  cin >> n >> m;
  map<int, int> mp;
  REP(i, m){
    int a;
    cin >> a;
    mp[a]++;
  }
  vector<mint> dp(n+5, 0);
  dp[0] = 1;
  REP(i, n+1){
    REP(j, 2){
      int ni = i+j+1;
      if(mp[ni] == 0)dp[ni] += dp[i];
      
    }
  }
  cout << dp[n].x << endl;
  return 0;
}

Measured memory_bytes: 5760
"use strict"
function main(arg) {
    arg = arg.trim().split("\n")
    var n = arg.shift()
    var data = arg
    // var count = 0
    var topB = 0
    var botA = 0
    var both = 0
    var ab = 0
    for (var i = 0; i < data.length; i++) {
        var row = data[i]
        if (row[0] === 'B' && row[row.length - 1] === 'A') {
            both++
        } else if (row[0] === 'B') {
            topB++
        } else if (row[row.length - 1] === 'A') {
            botA++
        }
        ab += row.split('AB').length - 1
    }
    // console.log([both, topB, botA, ab])
    var ans = 0
    if (both > 0) {
        ans += both - 1
        if (Math.min(topB, botA) >= 1) {
            ans += 2
            ans += Math.min(topB - 1, botA - 1)
        } else {
            if (Math.min(topB, botA) === topB) {
                topB += 1
            } else {
                botA += 1
            }
            ans += Math.min(topB, botA)
        }
    } else {
        ans += Math.min(topB, botA)
    }
    ans += ab
    console.log(ans)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 10428
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();
        String[] list = s.split("");

        if (list.length <= k) {
            System.out.println(s);
            return;
        }

        for (int i = 0; i < k; i++) {
            System.out.print(list[i]);
        }
        System.out.print("...");
    }
}

Measured memory_bytes: 27120
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pf push_front

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main()
{long long l,r;
 cin >> l >> r;
    
 if ( (r-l) >= 2019){
   cout << 0 << endl;
 return 0;
 }
 int mymin = 3000;
 for(long long i = l;i < r ;i++){
  for (long long j = i+1; j <= r; j++){
 int k = ((i%2019) * (j%2019))%2019;
    mymin = min (mymin , k);
}
 }
 
 cout << mymin << endl; 
 
 
 
 
 return 0;
}

Measured memory_bytes: 256
import sys
import copy
import math
import itertools
import numpy as np

H,W = [int(c) for c in input().split()]
a = np.array([list(input()) for c in range(H)])
b = copy.deepcopy(a)
Hc=[]
Wc=[]
for i in range(H):
    if np.count_nonzero(a[i,:] == ".") == W:
        Hc.append(i)

for i in range(W):
    if np.count_nonzero(a[:,i] == ".") == H:
        Wc.append(i)

a = np.delete(a,Hc,0)
a = np.delete(a,Wc,1)

for i in range(len(a)):
    s = ""
    for j in range(len(a[i])):
        s+=a[i][j]
    print(s)

Measured memory_bytes: 27496
#include <iostream>
using namespace std;
#include<string.h>
#include<set>
#include<stdio.h>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include <cstdio>
#include <cstdlib>
#include<stack>
#include<vector>
char a[100];
char b[100];
int main()
{
    cin>>a;
    cin>>b;
    int len1=strlen(a);
    int len2=strlen(b);
    if(len1!=len2)
    {
        cout<<"NO"<<endl;
        return 0;
    }
    int i,j;
    for(i=0,j=len2-1;i<len1,j>=0;i++,j--)
    {
        if(a[i]!=b[j])
        {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <limits>
#include <numeric>
#include <queue>
#include <set>
#include <bitset>
#include <map>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
typedef vector<long long> vll;
typedef queue<int, int> qii;
typedef pair<int, int> pii;

#define PI 3.14159265359
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repz(i,n) rep(i,0,n)

//int型を受け取ってその桁数を返す
int check_digits(int n) {
	int digits = 0;
	while (n != 0) {
		n /= 10;
		digits++;
	}
	return digits;
}

//int型を受け取ってその各桁の和を返す
int sum_digits(int n) {
	int sum=0;
	int N = n;
	while (N) {
		sum += N % 10;
		N /= 10;
	}
	return sum;
}


//最大公約数を返す関数
int gcd(int n, int m) {
	while (n != 0) {
		if (n < m) swap(n, m);
		n = n % m;
	}
	return m;
}


//2点間の距離を返す
float dis(int x1, int y1, int x2, int y2) {
	return sqrt(pow(abs(x1 - x2), 2) + pow(abs(y1 - y2), 2));
}


int main() {
	int n,sum = 0;
	cin >> n;
	vi l(n);
	repz(i, n) {
		cin >> l[i];
		sum += l[i];
	}
	sort(l.rbegin(), l.rend());
	int max = l[0];
	sum -= max;

	if (sum > max)cout << "Yes" << endl;
	else cout << "No" << endl;



	system("pause");
	return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
 #define rep(i, n) for (int i = 0; i < (int)(n); i++)
 #define big 1000000007


int64_t gusu(int k,int l,vector<int> d){
    int64_t s = 0;
    if(l-k<0){
        s = 0;
    }
    else{
        for(int i=k;k<=l;k+=2){
            s += d[k];
        }
    }
    return s;
}
int64_t kisu(int k,int l,vector<int> d){
    int64_t s = 0;
    if(l-k<0){
        s = 0;
    }
    else{
        for(int i=k;k<=l;k+=2){
            s += d[k];
        }
    }
    return s;
}
int main(){
    int  n;
    cin >> n;
    vector<int> a(n+1);
    vector<int64_t> y(n+1);
    for(int i=1;i<=n;i++){
        cin >> a[i];
    }
    // y[i] = d[i]-d[i+1]+...+d[N]-d[1]
    int gu =0;
    int ki = 0;
    y[1]=0;
    for(int i = 1;i<=n;i++){
        if(i%2==0){
            y[1] -= a[i];
        }
        else{
            y[1] += a[i];
        }
    }
    for(int i =2;i<=n;i++){
        y[i] = 2*a[i-1] - y[i-1];
        cout << y[i-1] <<" ";
    }
    cout << y[n];
    cout << endl;
}

Measured memory_bytes: 2432
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define eps 1e-9
#define maxp 101010
#define mod 1000000007
#define pi 3.141592653589793238
#define sin(s) scanf("%lld",&s);
#define sout(s) printf("%lld\n",s);
#define in(s) cin>>s
#define in2(a,b) cin>>a>>b
#define in3(a,b,c) cin>>a>>b>>c
#define vll vector<ll>
#define out(s) cout<<s
#define outs(s,a) cout<<s<<a
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define gear_change ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0)
#define nfl(i,n) for(i=0;i<n;i++)
#define sfl(i,s,e) for(i=s;i<e;i++)
#define ufl(i,n) for(i=n-1;i>=0;i--)
ll c2(ll n){
	return (n*(n-1))/2;
}
void solve(){
	ll n,i;
	in(n);
	vector<ll>vec(n);
	map<ll,ll>freq;
	nfl(i,n){
		in(vec[i]);
		freq[vec[i]]++;
	}
	ll ans=0;
	for(auto it:freq){
		if(it.S>1)
		ans+=c2(it.S);
	}
	nfl(i,n){
		ll temp=freq[vec[i]]-1;
		ll fans=ans-c2(temp+1)+c2(temp);
		cout<<fans<<'\n';
	}
}	
int main(){
	clock_t t1=clock();
	gear_change;
	ll test=1;
	// in(test);
	while(test--){
		solve();
	}
	clock_t t2=clock();
	cerr<<"Time elapsed:- "<<(double)(t2-t1)/CLOCKS_PER_SEC<<'\n';
}	

Measured memory_bytes: 11136
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class C
{
	public static void Main()
	{
		long A = GetLong();
		long B = GetLong();
		long C = GetLong();
		long D = GetLong();

		long multiC = Math.Max(0, B/C - (A + C - 1)/C + 1);
		long multiD = Math.Max(0, B/D - (A + D - 1)/D + 1);
		long lcmCD = lcm(C, D);
		long multiCD = Math.Max(0, B/lcmCD - (A + lcmCD - 1)/lcmCD + 1);
		Console.WriteLine(B - A + 1 - multiC - multiD + multiCD);
	}

	private static long gcd(long x, long y)
	{
		return (y == 0) ? x : gcd(y, x % y);
	}

	private static long lcm(long x, long y)
	{
		return (x / gcd(x, y)) * y;
	}
}


public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt(){ return int.Parse(getArg()); }
	public static long GetLong(){ return long.Parse(getArg()); }
	public static double GetDouble(){ return double.Parse(getArg()); }
	public static string GetString(){ return getArg(); }
}


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

using namespace std;
 
typedef long long ll;


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

    int np4 = n % 4;
    int mp4 = m % 4;

    ll ans = 0;
    for(int i = np4; i < 4; i++)
    {
        ans = ans ^ n;
        n++;
    }
    for(int i = mp4; i >= 0; i--)
    {
        ans = ans ^ m;
        m--;
    }
    
    cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,pii> pip;
typedef vector<pip>vip;
const double PI=acos(-1);
const double EPS=1e-7;
const int inf=1e8;
int dx[4]={0,1,0,-1};
int dy[4]={1,0,-1,0};

int main(){
	double a,b;
	cin>>a>>b;
	if(a>b)swap(a,b);
	double t;
	if(b-a<180)t=a+(b-a)/2;
	else t=a-(360-b+a)/2;
	t+=360*10;
	while(t>360)t-=360;
	cout<<t<<endl;
}//*/

Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> pii;
const int MAXN=1e4+10;
const int MAXD=1e2+10;
const int MOD=1e9+7;
string num;
int n,d,sol;
int dp[MAXN][MAXD];
int dp2[MAXN][MAXD][2];
int add(int x,int y){
	return (x+y)%MOD;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	cin>>num>>d;
	n=num.length()-1;
	dp[0][0]=1;
	for(int i=1;i<=n;i++){
		for(int j=(i==1)?1:0;j<=9;j++){
			for(int k=0;k<d;k++){
				dp[i][(j+k)%d]=add(dp[i][(j+k)%d],dp[i-1][k]);
			}
		}
	}
	for(int i=1;i<=n;i++){
		sol=add(sol,dp[i][0]);
	}
	n++;
	dp2[0][0][1]=1;
	for(int i=1;i<=n;i++){
		int z=(int)num[i-1]-'0';
		for(int j=(i==1)?1:0;j<=9;j++){
			if(i==1&&j>z) break;
			for(int k=0;k<d;k++){
				if(j<z){
					dp2[i][(j+k)%d][0]=add(dp2[i][(j+k)%d][0],add(dp2[i-1][k][0],dp2[i-1][k][1]));
					//dp2[i][(j+k)%d][0]+=dp2[i-1][k][0]+dp2[i-1][k][1];
					//dp2[i][(j+k)%d][0]=add(dp2[i][(j+k)%d][0],dp2[i-1][k][1])
				}
				else if(j==z){
					dp2[i][(j+k)%d][0]=add(dp2[i][(j+k)%d][0],dp2[i-1][k][0]);
					dp2[i][(j+k)%d][1]=add(dp2[i][(j+k)%d][1],dp2[i-1][k][1]);
					//dp2[i][(j+k)%d][0]+=dp2[i-1][k][0];
					//dp2[i][(j+k)%d][1]+=dp2[i-1][k][1];
				}
				else{
					dp2[i][(j+k)%d][0]=add(dp2[i][(j+k)%d][0],dp2[i-1][k][0]);
					//dp2[i][(j+k)%d][0]+=dp2[i-1][k][0];
				}
				
				//dp[i][(j+k)%d]=add(dp[i][(j+k)%d],dp[i-1][k]);
			}
		}
	}
	sol=add(sol,add(dp2[n][0][0],dp2[n][0][1]));
	cout<<sol<<"\n";
	return 0;
}

Measured memory_bytes: 13184
use proconio::{input, marker::Usize1};

#[derive(Default)]
struct Solver {
    n: usize,
    m: u64,
    q: Vec<Q>,
    s: Vec<u64>,
}

type Q = (usize, usize, u64, u64);

impl Solver {
    fn solve() {
        input! {
            n: usize, m: u64,
            q: [(Usize1, Usize1, u64, u64)]
        }
        let mut s = Self { n, m, q, s: vec![] };
        println!("{}", s.dfs())
    }

    fn dfs(&mut self) -> u64 {
        if self.s.len() == self.n {
            self.q.iter().filter_map(|q| self.eval(q)).sum()
        } else {
            let l = *self.s.last().unwrap_or(&1);
            (l..=self.m)
                .map(|x| {
                    self.s.push(x);
                    let ret = self.dfs();
                    self.s.pop();
                    ret
                })
                .max()
                .unwrap()
        }
    }

    fn eval(&self, &(a, b, c, d): &Q) -> Option<u64> {
        if self.s[b] - self.s[a] == c {
            Some(d)
        } else {
            None
        }
    }
}

fn main() { Solver::solve(); }


Measured memory_bytes: 2188
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    String S=gs();
	    Map<String, Integer> m=new HashMap<String, Integer>();

        for(int i=0;i<S.length(); i++) {
        	String s=String.valueOf(S.charAt(i));
        	if(m.containsKey(s)) {
        		System.out.println("no");
        		return;
        	}else {
        		m.put(s, 1);
        	}
	    }
        System.out.println("yes");

        //System.out.println((H-h)*(W-w));
//        if (flg) {
//        	System.out.print("YES");
//        }else {
//        	System.out.print("NO");
//        }


	}

	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35496
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<math.h>
using namespace std;
typedef long long ll;
#define int long long
typedef vector<int> VI;
typedef pair<int, int> pii;
typedef priority_queue<int> PQ;
#define fore(i,a) for(auto &i:a)
#define REP(i,n) for(int i=0;i<n;i++)
#define eREP(i,n) for(int i=0;i<=n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define eFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define SORT(c) sort((c).begin(),(c).end())
#define rSORT(c) sort((c).rbegin(),(c).rend())
#define LB(x,a) lower_bound((x).begin(),(x).end(),(a))
#define UB(x,a) upper_bound((x).begin(),(x).end(),(a))
#define INF 1000000000
#define LLINF 9223372036854775807
#define mod 1000000007
//vector<vector<int> > dp;
//vector<vector<vector<int> > > vvvi;
//dp=vector<vector<int> >(N, vector<int>(M,0));
//vector<pair<int,int> > v;
//v.push_back(make_pair(x,y));
//priority_queue<int,vector<int>, greater<int> > q2;

int N;
vector<VI>tree(1010);
VI X(1010);
string ans = "POSSIBLE";
int dp[1010][2];

void dfs(int cu, int pa = -1) {
	int white = 0, black = 0;
	VI any;
	REP(i, tree[cu].size()) {
		int to = tree[cu][i];
		if (to != pa) {
			dfs(to, cu);

			if (dp[to][0] == INF && dp[to][1] == INF) {
				ans = "IMPOSSIBLE";
				return;
			}
			if (dp[to][0] == INF) {
				white = dp[to][1];
				black = X[to];
			}
			else if (dp[to][1] == INF) {
				white = X[to];
				black = dp[to][1];
			}
			else {
				any.push_back(to);
			}
		}
	}

	VI dp2(5050);
	REP(i, 5050)dp2[i] = INF;
	dp2[white] = black;
	REP(i, any.size()) {
		int ch = any[i];
		VI pd2(5050);
		REP(i, 5050)pd2[i] = INF;
		for (int i = 5000; i >= 0; i--) {
			if (dp2[i] != INF) {
				if (i + X[ch] < 5050)pd2[i + X[ch]] = min(pd2[i + X[ch]], dp2[i] + dp[ch][1]);
				if (i + dp[ch][0] < 5050)pd2[i + dp[ch][0]] = min(pd2[i + dp[ch][0]], dp2[i] + X[ch]);
			}
		}
		swap(dp2, pd2);
	}
	REP(i, X[cu] + 1)if (dp2[i] != INF)dp[cu][0] = min(dp[cu][0], dp2[i]);

	dp2.resize(5050, INF);
	dp2[black] = white;
	REP(i, any.size()) {
		int ch = any[i];
		VI pd2(5050);
		REP(i, 5050)pd2[i] = INF;
		
		for (int i = 5000; i >= 0; i--) {
			if (dp2[i] != INF) {
				if (i + X[ch] < 5050)pd2[i + X[ch]] = min(pd2[i + X[ch]], dp2[i] + dp[ch][0]);
				if (i + dp[ch][1] < 5050)pd2[i + dp[ch][0]] = min(pd2[i + dp[ch][1]], dp2[i] + X[ch]);
			}
		}
		swap(dp2, pd2);
	}
	
	REP(i, X[cu] + 1)if (dp2[i] != INF)dp[cu][1] = min(dp[cu][1], dp2[i]);

}

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

	cin >> N;
	
	FOR(i, 1, N) {
		int a;
		cin >> a;
		a--;
		tree[a].push_back(i);
		tree[i].push_back(a);
	}
	REP(i, N)cin >> X[i];
	REP(i, N) {
		dp[i][0] = INF;
		dp[i][1] = INF;
	}

	dfs(0);

	if (dp[0][0] == INF && dp[0][1] == INF)ans = "IMPOSSIBLE";

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 512
program abc133d
  use,intrinsic :: iso_fortran_env
  implicit none
  integer :: n, i
  integer(int64) :: x
  integer,dimension(:),allocatable :: a, ans
  integer,dimension(:,:),allocatable :: b

  read *, n
  allocate(a(n),ans(n))
  read *, a
  b = reshape(a(2:),[2,n/2])
  x = sum(a) - sum(b(1,:)) * 2
  ans(1) = x
  do i = 1,n-1
     x = a(i) * 2 - x
     ans(i+1) = x
  end do
  print *, ans
end program abc133d


Measured memory_bytes: 3712
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val h = sc.nextLong()
    println(problem154d(h))
}

fun problem154d(h: Long): Long {
    var count = 1L
    var h2 = h
    while (h2 != 0L) {
        count *= 2
        h2 /= 2
    }
    return count - 1
}

Measured memory_bytes: 31392
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  string s = to_string(n);
  for(int i = 0;i < s.size();i++) {
    if(s.at(i) == '1') {
      s.at(i) = '9';
    }else {
      s.at(i) = '1';
    }
  }
  cout << s << endl;
}

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

 
int main() {
   int x,a;
   cin>>x>>a;
   if(x<a)cout<<0<<endl;
   else cout<<10<<endl;
}

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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 h,n;
    cin >> h >> n;
    vector<int32> a(n),b(n);
    REP(i,n)cin >> a[i] >> b[i];
    vector<int64> dp(h+1,LLINF);
    dp[0] = 0;
    REP(i,n){
        REP(j,h){
            dp[min(h,j+a[i])] = min(dp[min(h,j+a[i])], dp[j] + b[i]);
        }
    }
    ANS(dp[h]);
    return 0;
}

Measured memory_bytes: 384
int N,A[2<<17];
void sort_impl(int l,int r)
{
	if(r-l<=1);
	else if(r-l==2)
	{
		if(A[l+1]<A[l])
		{
			int tmp=A[l];
			A[l]=A[l+1];
			A[l+1]=tmp;
		}
	}
	else
	{
		int a=A[l];
		int b=A[(l+r)/2];
		int c=A[r-1];
		if((a<b)!=(a<c))
		{
			A[l]=b;
			A[(l+r)/2]=a;
		}
		else if((c<a)!=(c<b))
		{
			A[(l+r)/2]=c;
			A[r-1]=b;
		}
		int mid=(l+r)/2;
		int L=l,R=r-1;
		do{
			while(A[L]<A[mid])L++;
			while(A[mid]<A[R])R--;
			if(L<R)
			{
				int tmp=A[L];A[L]=A[R];A[R]=tmp;
				if(mid==L)mid=R;
				else if(mid==R)mid=L;
				L++;
				R--;
			}
			else if(L==R)L++,R--;
		}while(L<=R);
		sort_impl(l,R+1);
		sort_impl(L,r);
	}
}
void sort(int N)
{
	sort_impl(0,N);
}
main()
{
	scanf("%d",&N);
	for(int i=0;i<N;i++)scanf("%d",&A[i]),A[i]-=i;
	sort(N);
	long ans=0,mid=A[N/2];
	for(int i=0;i<N;i++)ans+=A[i]<mid?mid-A[i]:A[i]-mid;
	printf("%lld\n",ans);
}

Measured memory_bytes: 896
package main

import (
	"bufio"
	"fmt"
	"math/big"
	"os"
	"strconv"
)

func main() {
	bigIntP := big.NewInt(1000000007)

	N := readInt()
	A := make([]*big.Int, N)
	for i := 0; i < N; i++ {
		A[i] = big.NewInt(int64(readInt()))
	}

	v := big.NewInt(1)
	for i := 0; i < N; i++ {
		gcd := new(big.Int).GCD(nil, nil, v, A[i])
		v.Mul(v, A[i])
		v.Div(v, gcd)
	}

	result := big.NewInt(0)
	for i := 0; i < N; i++ {
		t := new(big.Int).Div(v, A[i])
		result.Add(result, t)
	}
	result.Rem(result, bigIntP)

	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c*d/gcd(c,d);}
int main(){
    ll n,m;
    cin>>n>>m;
    string s,t;
    cin>>s>>t;
    ll ans=lcm(n,m);
        bool flag=true;
        map<ll,char> mp;
        for(int i=0;i<n;i++){
            mp[i*ans/n]=s.at(i);
        }
        for(int i=0;i<m;i++){
            if(mp[i*ans/m]!=0&&mp[i*ans/m]!=t.at(i))flag=false;
        }
        if(flag)cout<<ans<<endl;
        else cout<<-1<<endl;
}


Measured memory_bytes: 10880
import java.io.IOException;
import java.util.Scanner;

class Main {
	static final int INF = 1000000001;

	static long changecount = 0;
   public static void main(String args[]) throws IOException{

	   Scanner scanner = new Scanner(System.in);

	   int n = scanner.nextInt();
	   StringBuilder builder = new StringBuilder();

	   int[] A = new int[n];
	   int[] B = new int[n];
	   int K = Integer.MIN_VALUE;
	   for(int i = 0;i < n; i++){
		   A[i] = scanner.nextInt();
		   K = Math.max(K, A[i]);
	   }

	   CountingSort( A, B, K, n);


	   builder.append(B[0]);
       for (int i = 1; i < n; i++) {
           builder.append(' ').append(B[i]);
       }
       System.out.println(builder);
	   scanner.close();
   }






   public static void CountingSort(int[] A, int[] B, int k , int n){

	   int[] C = new int[k+1];

       for (int i = 0; i < A.length; i++)
           C[A[i]]++;

       for (int i = 1; i <= k; i++)
           C[i] += C[i - 1];

       for (int i = A.length - 1; i >= 0; i--) {
           C[A[i]]--;
           B[C[A[i]]] = A[i];

       }


   }
}

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


int main(){

int n,x,y;
cin >> n;
string ans = "No";
for (int i = 0; i < 100; i++)
{
    for (int j = 0; j < 100; j++)
    {
        if (i * 4 + j * 7 == n)
        {
            ans = "Yes";
            goto goal;
        }
        
    }
    
}

goal:
cout << ans << endl;



}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<utility>
#include<cmath>
#include<climits>
#include<queue>
#include<stack>
#include<numeric>
#include<set>
#include<iomanip>
#include<map>
using namespace std;


typedef long long ll;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)

const ll mod = 1000000007;

int main(){
  int n;
  cin >> n;
  vector<pair<int, int> > b(n), r(n);
  vector<bool> used(n, false);
  rep(i, n){
    cin >> r[i].first >> r[i].second;
  }
  rep(i, n){
    cin >> b[i].first >> b[i].second;
  }
  sort(b.begin(), b.end());
  sort(r.begin(), r.end());

  int ans = 0;

  for(int i = 0; i < n; ++i){
    int mx = INT_MIN;
    for(int j = 0; j < n; ++j){
      if(b[i].first > r[j].first && b[i].second > r[j].second && !used[j]){
          if(mx == INT_MIN) mx = j;
          else if(r[mx].second < r[j].second) mx = j;
      }
    }

    if(mx != INT_MIN){
      ans++;
      used[mx] = true;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split(" ")))
sum = -1
flag = 0
while flag == 0:
    for i in range(n):
        if a[i]%2 == 1:
            flag = 1
            break
        a[i] = a[i]/2
    sum += 1
print(sum)

Measured memory_bytes: 3060