akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;
import java.util.ArrayList;

public class Main {
	Scanner sc = new Scanner(System.in);
	public void run(){
		while(true){
			String s = sc.next();
			if(s.equals("#")) break;
			calc(s);
		}
	}
	public void calc(String s){
		int[] north = new int[20];
		int n = 0;
		
		String check = s;
		while(check.length()!= 0){
			String part = check.substring(0, 4);
			if(part.equals("west")){
				north[n] = -1;
				check = check.substring(4);
			}
			else{
				north[n] = 1;
				check = check.substring(5);
			}
			n++;
		}
		
		int ans = 0;
		int ansd = 1;
		if(north[n-1] == -1) ans = 90;
		
		for(int i = n-2; i >= 0; i--){
			if(north[i] == 1) {
				ans = 2*ans - 90;
				ansd = 2*ansd;
				if(ans < 0){
					ans = 0;
					ansd = 1;
				}
			}
			else if(north[i] == -1){
				ans = 2*ans + 90;
				ansd = 2*ansd;
			}
		}
		
		while(ans%2 == 0 && ansd%2 == 0){
			ans = ans / 2;
			ansd = ansd / 2;
		}
		
		System.out.print(ans);
		if(ansd != 1) System.out.print("/"+ansd);
		System.out.println();
	}
	
	public static void main(String[] args){
		new Main().run();
	}
	
}

Measured memory_bytes: 25960
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int H = sc.nextInt();
    int W = sc.nextInt();
    int h = sc.nextInt();
    int w = sc.nextInt();
    int ans = H * W;
    ans -= h * W + H * w - h * w;
    System.out.println(ans);
  }
}


Measured memory_bytes: 23124
#include <algorithm>
#include <cstdint>
#include <iostream>

using Integer = std::int_fast64_t;

Integer f(Integer b, Integer n) {
  Integer y = 0;
  while (n > 0) {
    y += n % b;
    n /= b;
  }
  return y;
}

int main() {
  Integer n, s;
  std::cin >> n >> s;
  for (Integer b = 2; b < 400000; ++b) {
    if (f(b, n) == s) {
      std::cout << b << std::endl;
      return 0;
    }
  }
  for (Integer x = 400000; x > 0; --x) {
    Integer b = std::max(Integer(2), (n - s) / x + 1);
    if (f(b, n) == s) {
      std::cout << b << std::endl;
      return 0;
    }
  }
  std::cout << (s == n? n + 1: -1) << std::endl;
  return 0;
}


Measured memory_bytes: 256
//Grid Coloring

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int h,w;cin>>h>>w;
    nvarep(n,a);
    vector<vector<int>>m(h,vector<int>(w,-1));
    int c = 0,v = 0;
    rep(i,0,n){
        rep(j,0,a[i]){
            m[c][v]=i+1;
            v++;
            if(v==w){
                v=0;
                c++;
            }
        }
    }
    rep(i,0,h){
        if(i%2==1){
            reverse(range(m[i]));
        }
    }
    rep(i,0,h){
        rep(j,0,w){
            cout<<m[i][j];
            cout<<(j==w-1?nnn:spa);
        }
    }
    return 0;
}

Measured memory_bytes: 3692
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	string str;
	cin >> str;
	if(str[0] == str[2]) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
//#include "../cxx-prettyprint/prettyprint.hpp"

int main() {
    int N;
    std::cin >> N;

    std::vector<int> X(N + 1);
    for (int i = 1; i <= N; i ++) {
        std::cin >> X[i];
    }

    std::vector<int> X_sorted = X;
    std::sort(X_sorted.begin(), X_sorted.end());
    int lower_median = X_sorted[N / 2];
    int upper_median = X_sorted[N / 2 + 1];

    for (int i = 1; i <= N; i ++) {
        if (X[i] > lower_median) {
            std::cout << lower_median << std::endl;
        } else {
            std::cout << upper_median << std::endl;
        }
    }
}


Measured memory_bytes: 3712
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> a(M), b(M), c(M, 0);
    for (ll i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        c[i] = 0;
        for (ll j = 0; j < b[i]; j++) {
            ll num;
            cin >> num;
            c[i] |= (1ull << (num - 1));
        }
    }

    const ll MAX = 1 << N;
    const ll INF = INT_MAX;
    vector<vector<ll>> dp(M + 1, vector<ll>(MAX, INF));
    dp[0][0] = 0;

    for (ll i = 0; i < M; i++) {
        for (ll j = 0; j < MAX; j++) {
            //i番目の鍵を買うとする
            dp[i + 1][j | c[i]] = min(dp[i + 1][j | c[i]], dp[i][j] + a[i]);

            //買わない
            dp[i + 1][j] = min(dp[i + 1][j], dp[i][j]);
        }
    }

    cout << (dp[M][MAX - 1] == INF ? -1 : dp[M][MAX - 1]) << endl;
}

Measured memory_bytes: 32384
#include <iostream>
#include <sstream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <iomanip>
#include <cstdio>
#include <float.h>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>
#include <stack>
#include <functional>
       
using namespace std;
       
#define endl '\n'
#define MOD 1000000007
#define INF 1ll<<30
 
// #define MAX 100010
 
#define eps 1e-11
#define bit_max 1ll<<32
#define _USE_MATH_DEFINES
 
// long long binpow(long long a,long long b)
// {
//     if (b == 1) return a;
//     long long res = binpow(a, b/2)%MOD;
//     if (b % 2) return (res*((res*a)%MOD))%MOD;
//     else return (res * res)%MOD;
// }
 
// long long int fact(long long int a)
// {
//     if(a==0||a==1)
//         return 1;
//     long long int ans = 1;
//     for(int i=a;i>=1;i--)
//         ans = (ans * i);
//     return ans;
// }
 
// long long int ivmod(long long int a)
// {
//     return binpow(a,MOD-2);
// }
 
// long long int ncr(long long int a,long long int b)
// {
//     long long int pans=1;
//     for(int i =a;i>max(b,a-b);i--)
//         pans=pans*i;
//     long long int div = fact(min(b,a-b));
//     // cout<<ans<<"            "<<div<<endl;
//     pans = pans/div;
//     return pans;
// }


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    // #ifndef ONLINE_JUDGE
        // freopen("input.txt","r",stdin);
        // freopen("output.txt","w",stdout);
    // #endif
    int a,b,c;
    cin>>a>>b>>c;
    if(b-a == c-b)
        cout<<"YES";
    else
        cout<<"NO";
    cout<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <stdio.h>
#include <algorithm>
using namespace std;
int main()
{
	char c;
	int n;
	while(cin>>n&&n){
		int ba=0,fuda[10]={};
		for(int i=0;i<100;i++){
			cin>>c;
			if(c=='M'){
				fuda[i%n]++;
			}else if(c=='S'){
				ba+=fuda[i%n]+1;
				fuda[i%n]=0;
			}else{
				fuda[i%n]+=ba+1;
				ba=0;
			}
		}
		sort(fuda,fuda+n);
		for(int i=0;i<n;i++)cout<<fuda[i]<<" ";
		cout<<ba<<endl;
	}

	return 0;
}

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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





using ll = long long;

const ll mod = 1e9+7;
const int maxn = 1e6 + 5;



int n;
int a[maxn];

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


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

    for (int i=0; i<n; i++) {
	int x = all ^ a[i];
	cout<<x<<" ";
    }
    cout<<endl;
    
    return 0;
}


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


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout<<setprecision(10)<<fixed;
	
	int n;
	cin>>n;
	int mx=0;
	string s;
	map<string,int> m;
	for(int i=0;i<n;i++)
	{
		cin>>s;
		m[s]++;
		mx=max(mx,m[s]);
	}
	vector<string> v;
	for(auto i=m.begin();i!=m.end();i++)
	{
		if(i->second==mx)
			v.push_back(i->first);
	}
	sort(v.begin(),v.end());
	for(int i=0;i<v.size();i++)
		cout<<v[i]<<endl;
	return 0;
}


Measured memory_bytes: 25584
n=int(input())
a=list(map(int,input().split()))
dai=[0]*n
x=a[0]
for i in range(n-1):
    if a[i+1]-x<0:
        dai[i+1]=x-a[i+1]
        x=a[i+1]+dai[i+1]
    else:
        x=a[i+1]
print(sum(dai))

Measured memory_bytes: 32112
x1,y1,x2,y2 = map(int,input().split())

delx12 = x2-x1
dely12 = y2-y1

x3 = x2-dely12
y3 = y2 +delx12
x4 = x3-delx12
y4 =y3-dely12

print(x3,y3,x4,y4)

Measured memory_bytes: 61764
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int M=0;
  long long L=0;
  cin>>N;
  vector<int>vec(N);
  for(int X=0;X<N;X++){
    cin>>vec.at(X);
    L+=vec.at(X);
    if(M!=0){
      M=lcm(vec.at(X),M);
    }
    else{
      M=vec.at(X);
    }
  }
  cout<<L-N<<endl;
}

Measured memory_bytes: 3612
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>
#include<string.h>

typedef int32_t i32;
typedef int64_t i64;

static void print_int(i64 n){if(n<0){putchar('-');n=-n;}if(n==0){putchar('0');return;}int s[20],len=0;while(n>0){s[len++]=n%10+'0';n/=10;}while(len>0){putchar(s[--len]);}}
static i64 read_int(void){int prev='\0';int c=getchar();while(!('0'<=c && c<='9')){prev=c;c=getchar();}i64 res=0;while('0'<=c && c<='9'){res=10*res+c-'0';c=getchar();}return prev=='-'?-res:res;}

typedef struct range {
  i32 l, r;
} range;

typedef range radix_type;
typedef uint32_t u32;

#define RADIX_WIDTH 3
const u32 radix_type_max = 17;
const u32 radix_type_begin = 0;
const u32 radix_width = RADIX_WIDTH;
const u32 radix_mask = (1 << RADIX_WIDTH) - 1;
#undef RADIX_WIDTH

static inline u32 radix_get_bit (radix_type v, u32 shift) {
  return (u32)(v.r - v.l) >> shift & radix_mask;
}

void radix_sort (radix_type *a, u32 n) {
  radix_type * const array = (radix_type *) calloc (n, sizeof (radix_type));
  i32 *next = (i32 *) calloc (n + (1 << radix_width), sizeof (i32));
  i32 *start = next + n;
  for (u32 shift = radix_type_begin; shift < radix_type_max; shift += radix_width) {
    for (i32 i = 0; i < (i32)(1 << radix_width); ++i) {
      start[i] = -1;
    }
    for (i32 i = 0; i < (i32)n; ++i) {
      u32 bit = radix_get_bit (a[i], shift);
      array[i] = a[i];
      next[i] = start[bit];
      start[bit] = i;
    }
    for (i32 bit = radix_mask, i = n - 1; bit >= 0; --bit) {
      for (i32 p = start[bit]; p != -1; p = next[p]) {
	a[i--] = array[p];
      }
    }
  }
  free (array);
  free (next);
}

void add (i32 *bit, i32 x, i32 v) {
  i32 n = bit[0];
  for (i32 i = x; i <= n; i += i & -i) {
    bit[i] += v;
  }
}

i32 find (i32 *bit, i32 x) {
  i32 sum = 0;
  for (i32 i = x; i > 0; i -= i & -i) {
    sum += bit[i];
  }
  return sum;
}

void run (void) {
  i32 n = read_int();
  i32 m = read_int();
  range *p = (range *) calloc (n, sizeof (range));
  for (i32 i = 0; i < n; ++i) {
    p[i].l = read_int();
    p[i].r = read_int() + 1;
  }
  radix_sort (p, n);
  i32 *bit = (i32 *) calloc (m + 2, sizeof (i32));
  bit[0] = m + 1;
  for (i32 d = 1, i = 0; d <= m; ++d) {
    for (; i < n && p[i].r - p[i].l < d; ++i) {
      add (bit, p[i].l, 1);
      add (bit, p[i].r, -1);
    }
    i32 ans = n - i;
    for (i32 j = d; j <= m; j += d) {
      ans += find (bit, j);
    }
    print_int (ans);
    putchar ('\n');
  }
}

int main (void) {
  run();
  return 0;
}


Measured memory_bytes: 6016
a = gets.split(' ')
a_zahyou = a[0].to_i
a_kyori = a[1].to_i

b = gets.split(' ')
b_zahyou = b[0].to_i
b_kyori = b[1].to_i

time = gets.to_i

a_plus = a_zahyou + a_kyori * time
a_minus = a_zahyou - a_kyori * time

b_plus = b_zahyou + b_kyori * time
b_minus = b_zahyou - b_kyori * time

if a_plus >= b_plus && a_minus <= b_minus
  puts 'YES'
else 
  puts 'NO'
end

Measured memory_bytes: 14436
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, n, sum = 0;
	cin >> h >> n;
	for(int i = 0; i < n; i++) {
		int x; cin >> x; sum += x;
	}
	cout << (sum >= h ? "Yes" : "No") << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <cassert>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <string>
#include <algorithm>
#include <utility>
#define llint long long
#define inf 1e18
#define rep(x, s, t) for(llint (x) = (s); (x) < (t); (x)++)
#define Rep(x, s, t) for(llint (x) = (s); (x) <= (t); (x)++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))

using namespace std;
typedef pair<llint, llint> P;

llint n;
char c[200005];
llint sum[200005];

int main(void)
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> n;
	for(int i = 1; i <= n; i++) cin >> c[i];
	for(int i = 1; i <= n; i++){
		sum[i] = sum[i-1];
		if(c[i] == 'R') sum[i]++;
	}
	
	llint ans = inf;
	for(int i = 0; i <= n; i++){
		llint l = i - sum[i], r = sum[n]-sum[i], m = min(l, r);
		ans = min(ans, l+r-m);
	}
	cout << ans << endl;
	
	return 0;
}

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

using namespace std;

int main()
{
    string a;
    cin >> a;
    string b = a;
    reverse( a.begin() , a.end() );
    for( int i = 0 ; i < a.size() ; ++ i )
    {
        if(a[i]=='b') a[i]='d';
        else if(a[i]=='d') a[i]='b';
        else if(a[i]=='p') a[i]='q';
        else if(a[i]=='q') a[i]='p';
    }
    if(a==b) cout<<"Yes";
    else cout<<"No";
}

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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define repr(i, j) for(int i = j; i >= 0; --i)
#define INF (1 << 30)
#define MOD 1e9 + 7

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

#define PRIM 50021

bool prim[50022];
int a_prime[50022];

int main(){
	memset(prim, true, sizeof(prim));
	int N;
	prim[0] = false;
	FOR(i, 1, sqrt(PRIM)) {
		if(prim[i]) {
			for(int j = (i + 1); (i + 1) * j <= PRIM; ++j) {
				prim[(i + 1) * j - 1] = false;
			}
		}
	}
	while(cin >> N) {
		repr(i, N - 2) {
			if(prim[i]){
				printf("%d ", i + 1);
				break;
			}
		}
		FOR(i, N, PRIM) {
			if(prim[i]) {
				printf("%d\n", i + 1);
				break;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 3264
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
int main(void){
	int a[100000];
	int b[100000];
	int c;
	int k;
	int n;
	int m;
	int p;
	int q;
	int s;
	int x;
	int y;
	int z;
	c = 0;
	scanf("%d %d", &x,&y);
	if (x < 0)p = -x;
	else p = x;
	if (y < 0)q = -y;
	else q = y;
	if (y - x > 0){
		if (x <= 0 && y <= 0)c = p - q;
		else if (x >= 0 && y >= 0)c = q - p;
		else{
			if (p < q)c = q - p + 1;
			else c = p - q + 1;
		}
	}
	else{
		if (x < 0 && y < 0)c = q - p + 2;
		else if (x > 0 && y >0)c = p - q + 2;
		else{
			if (p < q)c = q - p + 1;
			else c = p - q+ 1;
		}
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 128
import io.{StdIn => in}

object Main extends App {
  val out = new java.io.PrintWriter(System.out)
  val Array(h, w) = in.readLine.split(" ").map(_.toInt)
  Iterator.continually(in.readLine)
    .take(h)
    .foreach(s => {
      out.println(s)
      out.println(s)
    })
  out.flush
}

Measured memory_bytes: 26496
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, idx, i, j, k, ans,curr;
    scanf("%d %d",&n,&k);
    ans = 1e9+5;
    int arr[n];
    for(i=0;i<n;i++)
    {
        scanf("%d",&arr[i]);
    }
    k--;
    sort(arr,arr+n);
    for(i=0;i<n-k;i++)
    {
        ans = min(ans,arr[i+k] - arr[i]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)(n); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define repid(i, a, b) for(intl i = (intl)(a); i >= (intl)(b); i--)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,1,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define alength(a) (sizeof(a) / sizeof(a[0]))
#define cin(i, a) rep(i, alength(a))cin >> a[i]
#define ccin(i, j, a) rep(i, alength(a))rep(j, alength(a[i]))cin >> a[i][j]
#define debug(x) cout << #x << ":" << x << endl
#define rdebug(i,x) rep(i, alength(x))cout << #x << "[" << i << "]:" << x[i] << endl
#define sqrt sqrtl
#define int intl
#define itn intl
#define double ld
#define pb push_back
#define mp make_pair
const intl INF = 1e9;
const intl MOD = 1e9+7;
const ld eps = 1.0e-14;//-9
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
void fp(bool flag, string s, string t){
    if(flag)cout << s << endl;
    else cout << t << endl;
}
intl kai(intl k){
    intl a = 1;
    for(int i = 2; i <= k; i++){
        a *= i;
    }
    return a;
}
intl gcd(intl a, intl b){
    if(!b)return a;
    return gcd(b, a % b);
}
intl digit10(intl a){
    if(!a)return 1;
    intl b = 0;
    while(a){
        a /= 10;
        b++;
    }
    return b;
}
signed main(){
    cout << fixed << setprecision(10);
    string s,t,u;
    cin >> s >> t >> u;
    cout << (char)(s[0] + 'A' - 'a') << (char)(t[0] + 'A' - 'a') << (char)(u[0] + 'A' - 'a') << endl;
    return 0;
}

Measured memory_bytes: 256
check=[list(input()) for i in range(3)]
cur=0
while True:
  if cur==0:
    if len(check[0])==0:
      break
  elif cur==1:
    if len(check[1])==0:
      break
  else:
    if len(check[2])==0:
      break
  cur=ord(check[cur].pop(0))-ord("a")
if cur==0:
  print("A")
elif cur==1:
  print("B")
else:
  print("C")


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

#define ll long long
#define ar array

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	string s, t;
	cin >> s >> t;
	int n=s.size(), m=t.size();
	int ans=1e9;
	for(int i=0; i<n-m+1; ++i) {
		int c=0;
		for(int j=i; j<i+m; ++j) {
			c+=(s[j]!=t[j-i]);
		}
		ans=min(ans, c);
	}
	if(ans==(int)1e9)
		ans=0;
	cout << ans << "\n";
}


Measured memory_bytes: 3652
/*  ***  In The Name of God ... ***  */
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define bug() cout << "BUG" << endl ;
#define X first
#define Y second
#define sz(x) (int)x.size()
#define per(how) cout << fixed << setprecision(how)
#define bit(a , b) (a >> b) & 1
#define all(v) v.begin() , v.end()
#define LB(x) (x & -x)
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 , MOD = 1e9 + 7 , SQRT = 350 ;
inline void smin(ll &x , ll y) { x = min(x , y) ; }
inline void smax(ll &x , ll y) { x = max(x , y) ; }

const ll MAXN = 2e5 + 100 ; 
ll n , a[MAXN]; 

int main ()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	ll s = 0 ; 
	cin >> n ; 
	for(ll i = 1 ; i <= n ; i++)	cin >> a[i] , s += a[i];
	ll res = 0 , ans = INF;
	for(ll i = 1 ; i < n ; i++)
	{
		res += a[i];
		smin(ans , abs(s - res - res));
	}
	cout << ans ; 
}


Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;
int main()
{  
    int N, D;
    
    cin >> N >> D;
    
    vector<int>X[N];
    for ( int i = 0; i < N; i ++ ) {
        for ( int j = 0; j < D; j ++ ) {
            int x;
            cin >> x;
            X[i].push_back( x );
        }
    }

    int count = 0;
    for ( int i = 0; i < N-1; i ++ ) {
        for ( int j = i+1; j < N; j ++ ) {
            // cout << "i j " << i << " " << j << endl;
            int dist1 = 0;
            for ( int d = 0; d < D; d ++ ) {
                dist1 += abs(X[i][d] - X[j][d]) * abs(X[i][d] - X[j][d]);
            }
            int dist2 = sqrt( dist1 );
            if ( dist1 == (dist2*dist2) ) {
                count ++;
            }
        }
    }

    cout << count << endl;


    return 0;
}

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

#define INPUT_ARRAY(N, A) \
    int N; \
    std::cin >> N; \
    std::vector<int> A(N); \
    for(int i = 0; i < N; ++i) std::cin >> A[i];

template<class T>
void print(const T &C)
{
    for(auto i : C)
    {
        std::cout << i << " ";
    }
    std::cout << std::endl;
}

int main()
{
    INPUT_ARRAY(N, A);
    
    std::sort(begin(A), end(A), [](int l, int r){ return l > r; });
    
    int pointBob = 0, pointAlice = 0;
    
    for(int i = 0; i < N; ++i)
    {
        if(i % 2 == 0)
        {
            pointBob += A[i];
        }
        else
        {
            pointAlice += A[i];
        }
    }
    
    std::cout << pointBob - pointAlice;
}


Measured memory_bytes: 256
from collections import defaultdict,deque
import math
def gcd(a,b):
    return b if not a%b else gcd(b,a%b)
def lcm(a,b):
    return (a*b)//gcd(a,b)

def main():
    n,k=map(int, input().split())
    a=[int(i) for i in input().split()]
    tmp = 0
    res = []
    ind = 0
    for i in range(n-k):
        if(a[ind] < a[ind+k]):
            res.append(1)
        else:
            res.append(0)
        ind += 1

    for i in range(0,len(res)):
        if(res[i]):
            print("Yes")
        else:
            print("No")


if __name__ == '__main__':
    main()


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

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    bool arr[26]={false};
    string s;cin>>s;
    for (char i:s){
        arr[i-'a']=true;
    }char ans=' ';
    for (int i=0;i<26;i++){
        if (!arr[i]){
            ans=i+'a';
            break;
        }
    }if (ans==' '){
        cout<<"None";
    }else cout<<ans;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<pair<int,int>> p(n);
  rep(i,n) cin >> p[i].second >> p[i].first;
  sort(p.begin(),p.end());
  ll tim = 0;
  rep(i,n){
    tim += p[i].second;
    if(tim>p[i].first){
      puts("No");
      return 0;
    }
  }
  puts("Yes");
}


Measured memory_bytes: 1792
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{
    static void Main(string[] args)
    {
      int n = int.Parse(Console.ReadLine());
      var txy = new List<List<int>>();
      bool flag = true;
      int ans = 0;
      txy.Add("0 0 0".Split(' ').ToList().ConvertAll(x => int.Parse(x)));
      for (int i=0;i<n;i++){
      	txy.Add(Console.ReadLine().Split(' ').ToList().ConvertAll(x => int.Parse(x)));
      }
      for (int i=0;i<n;i++){
        if ((txy[i+1][0]-txy[i][0])%2==0){
          ans = Math.Abs(txy[i+1][1]-txy[i][1])+Math.Abs(txy[i+1][2]-txy[i][2]);
          if (ans>(txy[i+1][0]-txy[i][0]) || ans%2!=0){
          	flag =false;
            break;
          }
        }
        else{
          ans = Math.Abs(txy[i+1][1]-txy[i][1])+Math.Abs(txy[i+1][2]-txy[i][2]);
          
          if (ans%2==0 || ans>(txy[i+1][0]-txy[i][0])){
          	flag =false;
            break;
          }
        }
      }
      if (flag){
        Console.WriteLine("Yes");
      }
      else{
        Console.WriteLine("No");
      }
        
        
      
    }
}


Measured memory_bytes: 49824
n  = int(input())
a = list( map(int, input().split())) # a1 a2 ... aN

ans=0
right=0
count = 0
left = 0
while left < n:
    while right < n-1 and a[right] >= a[right+1]:
        right+=1

    count = right - left
    ans = max(ans, count)
    count = 0
    right += 1
    left = right

print(ans)

Measured memory_bytes: 14252
n, m = list(map(int, input().split()))
X = list(map(int, input().split()))
X.sort()
# print(X)
sub = [0 for i in range(m)]
for i in range(m):
    if i == m-1:
        sub[i]=0
    else:
        sub[i] = X[i+1]-X[i]
# print(sub)

ans = sum(sorted(sub)[:m-n+1])
if n>= m:
    ans = 0
print(ans)


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

const int MAX = 200005;
const int MOD = 1000000007;

ll inv[MAX];

ll modpow(ll a, ll n, ll mod) {
  ll res=1;
  while (n>0) {
    if (n&1) res = res * a % mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

void inv_init() {
  for (int i=1; i<MAX; i++) {
    inv[i]=modpow(i, MOD-2, MOD);
  }
}

int main() {
  ll n; cin>>n;
  ll a,b; cin>>a>>b;
  inv_init();
  ll res=modpow(2, n, MOD);
  res--;
  ll Am=1;
  for (ll i=n-a+1LL; i<=n; i++) {
    Am*=i;
    Am%=MOD;
  }
  rep(i, a) {
    Am*=inv[i+1];
    Am%=MOD;
  }
  ll Bm=1;
  for (ll i=n-b+1LL; i<=n; i++) {
    Bm*=i;
    Bm%=MOD;
  }
  rep(i, b) {
    Bm*=inv[i+1];
    Bm%=MOD;
  }
  res-=Am;
  if (res<0) res+=MOD;
  res-=Bm;
  if (res<0) res+=MOD;
  cout<<res%MOD<<endl;
}


Measured memory_bytes: 1920
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
using pll = pair<ll, ll>;
using vp = vector<pll>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define PRINT(V) for (auto v:(V)) {cerr << v << " ";} cerr << endl
#define dump(x) cerr << #x << " : " << (x) << endl
#define dump2(x, y) cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl
inline ll GCD(ll a, ll b){return b ? GCD(b, a % b) : a;}
const ll MOD = 1000000007;
const ll INF = 100000000000000000LL;
/* END OF TEMPLATE */

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vll W(N);
    rep(i, N){
        cin >> W[i];
    }
    ll s1 = W[0], s2 = 0;
    repr(i, 1, N){
        s2 += W[i];
    }
    ll ans = abs(s1-s2);
    repr(i, 1, N-1){
        s1 += W[i];
        s2 -= W[i];
        ans = min(ans, abs(s1-s2));
    }
    cout << ans << endl;
    return 0;
}

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

typedef long long int ll;
ll mod = 1000000000 + 7;
ll _gcd[100000];

ll _pow(ll base, ll exp){
    ll ans = 1;
    ll temp = base;
    while(exp > 0){
        if(exp%2 == 1) ans *= temp, ans %= mod;
        temp *= temp; temp %= mod;
        exp /= 2;
    }
    return ans;
}

int main(){
    ll n, ans = 0, k; cin >> n >> k;
    for(ll i = k; i >= 1; i--){
        _gcd[i - 1] = _pow(k/i, n);

        //if(i%1000 == 0) cout << i << " " << _gcd[i - 1] << " ";

        for(int j = 2*i; j <= k; j += i){
            _gcd[i - 1] -= _gcd[j - 1];
            _gcd[i - 1] %= mod;
            while(_gcd[i - 1] < 0) _gcd[i - 1] += mod;
        }

        ans += _gcd[i - 1]*i; ans %= mod;
        //if(i%1000 == 0) cout << _gcd[i - 1] << endl;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4416
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <queue>
#include <map>
#include <set>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<29;

struct P {
  double x,y,z;
  P(double x, double y, double z) :x(x),y(y),z(z) {}
  P() {}
};

double dis(P a, P b) {
  return sqrt((a.x-b.x)*(a.x-b.x) + (a.y-b.y)*(a.y-b.y) + (a.z-b.z)*(a.z-b.z));
}

bool judge(double a1,double b1, double c1, double a2, double b2, double c2) {
  return (abs(b1/a1 - b2/a2)<=5e-4 && abs(c1/a1 - c2/a2)<=5e-4);
}


int main() {
  int N;
  cin >> N;
  while(N--) {
    double qr,rp,pq;
    cin >>qr>>rp>>pq;
    int n;
    cin >> n;
    P p[n];
    REP(i, n) {
      double x, y, z;
      cin >> x >> y >> z;
      p[i] = P(x,y,z);
    }
    vector<bool> v(n);
    REP(i,3) v[n-i-1] = 1;
    bool ok = 0;
    do {
      P pp[3];
      int id[3];
      int c = 0;
      REP(i,n) {
        if (v[i]) {
          id[c] = i;
          pp[c++] = p[i];
        }
      }
      int s[3] = {0,1,2};
      do {
        if (judge(dis(pp[s[1]], pp[s[2]]), dis(pp[s[2]], pp[s[0]]), dis(pp[s[0]], pp[s[1]]),qr,rp,pq)) {
          REP(i,3)
            cout << (i?" ":"") << id[s[i]]+1;
          cout << endl;
          ok = 1;
          break;
        }
      }while(next_permutation(s,s+3));
      if (ok)
        break;
      
    } while(next_permutation(ALL(v)));
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for(int i = 0; i < n; i++)
#define all(a) a.begin(), a.end()
#define P pair<int, int>
#define F first
#define S second
#define mod 1000000007
#define INF 4000000000000000000
int dx8[8]={-1,0,1,1,1,0,-1,-1};
int dy8[8]={1,1,1,0,-1,-1,-1,0};
int dx4[4]={-1,0,1,0};
int dy4[4]={0,-1,0,1};
int gcd(int a,int b){
    if(b==0)return a;
    return gcd(b,a%b);
}
int uni[100010];
int root(int a){
    if(uni[a]<0)return a;
    return uni[a]=root(uni[a]); 
}
bool connect(int a,int b){
    a=root(a);
    b=root(b);
    if(a==b)return false;
    if(uni[a]>uni[b]){
        swap(a,b);
    }
    uni[a]=uni[a]+uni[b];
    uni[b]=a;
    return true;
}
signed main(void){
    rep(i,100009)uni[i]=-1;
    int n,m,k;cin>>n>>m>>k;
    vector<int>Friend[n];
    vector<int>Block[n];
    rep(i,m){
        int a,b;cin>>a>>b;
        Friend[a-1].push_back(b-1);
        Friend[b-1].push_back(a-1);
        connect(a-1,b-1);
    }
    rep(i,k){
        int a,b;cin>>a>>b;
        Block[a-1].push_back(b-1);
        Block[b-1].push_back(a-1);
    }
    rep(i,n){
        int ans=-uni[root(i)];
        for(auto x:Friend[i]){
            if(root(x)==root(i))ans--;
        }
        for(auto x:Block[i]){
            if(root(x)==root(i))ans--;
        }
        cout<<ans-1<<' ';
    }
}
        


Measured memory_bytes: 13684
import java.util.*;
public class Main {
        static Scanner sc = new Scanner(System.in);
        static void myout(Object t){System.out.println(t);}//standard output
        static void myerr(Object t){System.err.println(t);}//standard error
        static String getStr(){return sc.next();}
        static int getInt(){return Integer.parseInt(getStr());}
        static Long getLong(){return Long.parseLong(getStr());}
        static boolean isNext(){return sc.hasNext();}
        static char[] splitSingle(String str){return str.toCharArray();}
        public static void main(String[] args){
          int N = getInt();
          int T = getInt();
          int[] list = new int[N];
          for(int i = 0; i < N; i++){
            list[i] = getInt();
          }
          long output = 0;
          for(int i = 1; i < N; i++){
            if(list[i] - list[i-1] > T){
              output += T;
            }else{
              output += list[i] - list[i-1];
            }
          }
          output += T;
          myout(output);
        }
        //便利メソッド追加枠ここから

        //便利メソッド追加枠ここまで
}


Measured memory_bytes: 50168
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto xyabc = readln.split.to!(int[]);
    auto X = xyabc[0];
    auto Y = xyabc[1];
    auto A = xyabc[2];
    auto B = xyabc[3];
    auto C = xyabc[4];
    auto ps = readln.split.to!(long[]);
    sort!"a > b"(ps);
    auto qs = readln.split.to!(long[]);
    sort!"a > b"(qs);
    auto rs = readln.split.to!(long[]);
    sort!"a > b"(rs);

    long res;
    foreach (i; 0..X) res += ps[i];
    foreach (i; 0..Y) res += qs[i];
    foreach (i; 0..C) res += rs[i];

    int i = X-1, j = Y-1, k = C-1;
    foreach (_; 0..C) {
        auto p = i >= 0 ? ps[i] : long.max;
        auto q = j >= 0 ? qs[j] : long.max;
        auto r = k >= 0 ? rs[k] : long.max;
        if (p <= q && p <= r) {
            --i;
            res -= p;
        } else if (q <= p && q <= r) {
            --j;
            res -= q;
        } else {
            --k;
            res -= r;
        }
    }
    writeln(res);
}

Measured memory_bytes: 12528
#include <iostream>
#include <algorithm>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;

int main(){
    long n,m,ans; cin>>n>>m;
    if(2*n<m){
        ans=n+(m-2*n)/4;
    }else{
        ans=m/2;
    }
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef long int li;
typedef long double lb;
#define rep(i,j,n) for (ll i = j; i < (n); i++)
#define repr(i,j,n) for(ll i = j; i >= (n); i--)
#define all(x) (x).begin(),(x).end()
#define CLR(mat,f) memset(mat, f, sizeof(mat))
#define IN(a, b, x) (a<=x&&x<b)
#define out(ans) cout << ans << endl
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; }
typedef pair<ll,ll>P;
const ll mod=1e9+7;
const ll INF = 1LL<<60;

int main(){

  ll n;cin>>n;
  map<ll,ll>mp;
  rep(i,0,n){
    ll d;cin>>d;
    mp[d]++;
  }
  ll m;cin>>m;
  ll t[m];rep(i,0,m)cin>>t[i];

  rep(i,0,m){
    if(mp[t[i]]!=0)mp[t[i]]--;
    else {
      out("NO");
      return 0;
    }
  }
  out("YES");



  return 0;
}


Measured memory_bytes: 14336
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> pip;
const ll INF = 1ll<<29;
const ll MOD = 1000000007;
const double EPS = 1e-9;
const bool debug = 0;
//---------------------------------//
 
int main() {
	ll D; cin >> D;
	
	ll ans = 0;
	
	FOR(k, 2, 20) {
		ll t[11] = {};
		REP(i, k / 2) t[i] = (ll)powl(10, k - i - 1) - (ll)powl(10, i);
		
		ll nowcnt = 0;
		
		queue<pll> que[11];
		que[0].push(pll(D, 1));
		REP(i, k / 2) {
			while (!que[i].empty()) {
				pll now = que[i].front(); que[i].pop();
				ll n = now.fi, c = now.se;
				
				ll d = abs(n) / t[i];
				if (d >= 10) continue;
				
				int tim = 10 - d;
				if (i == 0) tim--;
				que[i + 1].push(pll(n - d * t[i] * (n >= 0 ? 1 : -1), c * tim));
				
				if (d == 9) continue;
				d++;
				tim = 10 - d;
				if (i == 0) tim--;
				que[i + 1].push(pll(n - d * t[i] * (n >= 0 ? 1 : -1), c * tim));
			}
		}
		
		while (!que[k / 2].empty()) {
			pll now = que[k / 2].front(); que[k / 2].pop();
			ll n = now.fi, c = now.se;
			if (n == 0) nowcnt += c;
		}
		
		if (k & 1) nowcnt *= 10;
		ans += nowcnt;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#define pq priority_queue
#define mp make_pair

using namespace std;

typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;

const int iinf = 1 << 29;
const long long linf = 1ll << 61;


int main(){
  int n;
  cin>>n;
  cout<<n/3<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
    int A,B;
    cin >> A >> B;
    
    int ans;
    
    if(B % A == 0){
        ans = A+B;
        
    }else{
        ans = B-A;
        
    }
    cout << ans << endl;
    
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<set>
#include<map>

using namespace std;

#define x first
#define y second
#define NMAX 200005
#define INF 1000000009
#define MOD 1000000007

int n, dist[NMAX], goTo[NMAX];
char s[NMAX];
pair<int,int> currentChoice[NMAX];

void reconst(int position) {
   // printf("Sunt la %d %d %d %d\n", position, currentChoice[position].x, currentChoice[position].y, n);
    if(position > n)
        return ;
    printf("%c", currentChoice[position].x + 'a');
    reconst(currentChoice[position].y);
}

int main (){
    int distMin, selectChar;

    scanf("%s", s + 1);    
    n = strlen(s + 1);
    //printf("%d\n", n);
    
    for(int i = 0; i < 26; i++)
        goTo[i] = n + 1;
    
    for(int i = n; i >= 0; i--) {
        distMin = INF;
        selectChar = -1;
        for(int letter = 0; letter < 26; letter++) {
            if(dist[goTo[letter]] + 1 < distMin) {
                distMin = dist[goTo[letter]] + 1;
                selectChar = letter;
            }
        }
        dist[i] = distMin;
        currentChoice[i] = make_pair(selectChar, goTo[selectChar]);
        if(i)
            goTo[s[i] - 'a'] = i;
    }
    
  //  printf("%d\n", n);
//    for(int i = 0; i <= n; i++)
 //       printf("%d %d %d\n", i, currentChoice[i].x, currentChoice[i].y);
    
    reconst(0);
    
    return 0;
}

Measured memory_bytes: 2688
// g++ macro.cpp -std=c++14
#include <bits/stdc++.h> //STL include
typedef long long ll;// long long int
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;//namespace

#define dump(x)  cout << #x << " = " << (x) << endl;// debug cout
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl;
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl;

#define SANKOU(n,a,b) cout << ((n) ? (a) : (b) ) << endl;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)// for macro
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)

#define FOREACH(x,a) for(auto& (x) : (a) )

#define WFA(d,v) REP(k,v)REP(i,v)REP(j,v)d[i][j]=min(d[i][j],d[i][k]+d[k][j]);// warshall-floyd

#define CIN(x) int x;cin>>x;
#define SCIN(x) string x;cin>>x;
#define COUT(x) cout<<(x)<<endl;
#define SCOUT(x) cout<<(x)<<" ";
#define ENDL cout<<endl;

#define VECCIN(x) for(auto&youso_: (x) )cin>>youso_;
#define VECCOUT(x) for(auto&youso_: (x) )cout<<youso_<<" ";cout<<endl;

#define ALL(obj) (obj).begin(),(obj).end()// iterator

#define UNIQUE(obj) sort(ALL( obj )); obj.erase(unique(ALL(obj)),obj.end());

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>

#define pb(a) push_back(a)//push_back
#define mp make_pair// make_pair


int main(){

    CIN(n);
    int sum=0;
    int val;
    REP(i,n+1){
        sum+=i;
        val=i;
        if(sum>=n)break;
    }
    int minu=sum-n;
    FOR(i,1,val+1)if(i!=minu)COUT(i);

    return 0;
}


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

using namespace std;

int main() {
  vector<string> v(3);
  int p[3] = {0};
  cin >> v[0];
  cin >> v[1];
  cin >> v[2];
  v[0].append("x");  // sentinels
  v[1].append("x");
  v[2].append("x");

  int turn = 0;
  for (;;) {
    if (v[turn][p[turn]] == 'x') {
      printf("%c\n", turn + 'A');
      break;
    }
    turn = v[turn][p[turn]++] - 'a';
  }

  return 0;
}


Measured memory_bytes: 256
/// Thank you tanakh!!!
/// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

const INF: usize = 1e15 as usize;

fn main() {
    input!(n: usize, p: [usize1; n - 1], x: [usize; n]);
    let mut tree = vec![vec![]; n];
    for child in 1..n {
        let parent = p[child - 1];
        tree[parent].push(child);
    }
    if dfs(0, &tree, &x) != INF {
        println!("POSSIBLE");
    } else {
        println!("IMPOSSIBLE");
    }
}

fn dfs(v: usize, tree: &Vec<Vec<usize>>, x: &Vec<usize>) -> usize {
    let mut dp = vec![INF; x[v] + 1];
    dp[0] = 0;
    for &child in tree[v].iter() {
        let mut next = vec![INF; x[v] + 1];
        let white = x[child];
        let black = dfs(child, tree, x);
        for i in 0..(x[v] + 1) {
            if i + white <= x[v] {
                next[i + white] = cmp::min(next[i + white], dp[i] + black);
            }
            if i + black <= x[v] {
                next[i + black] = cmp::min(next[i + black], dp[i] + white);
            }
        }
        dp = next;
    }
    *dp.iter().min().unwrap()
}


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

#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define rep(i, n) FOR(i, 0, n - 1)
typedef long long ll;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }


void solve(string S){
    for (int i = 0; i < S.length(); i++) {
        printf("x");
    }
    printf("\n");

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string S;
    cin >> S;
    solve(S);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll MOD = 1e9+7;
int main()
{
    ll n;
    cin >> n;
    string s1, s2;
    cin >> s1 >> s2;
    ll ans = 0, i = 0;
    if(s1[0] == s2[0])
    {
        ans += 3;
        i++;
    }
    else
    {
        ans += 6;
        i+=2;
    }
    while(i<n)
    {
        if(s1[i] == s2[i])
        {
            if(s1[i-1] == s2[i-1])
            {
                ans *= 2;
                ans %= MOD;
            }
        }
        else
        {
            if(s1[i-1] == s2[i-1])
            {
                ans *= 2;
                ans %= MOD;
            }
            else
            {
                ans *= 3;
                ans %= MOD;
            }
            i++;
        }
        i++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define INFL 0x6fffffffffffffffLL

int main() {
	ll		a,b,c,d,w,h,i,j,k,m,n,x,y,z;
	ll		ans = INFL;
	cin >> n >> a >> b >> c;
	vector<ll>	l(n);
	for(i=0;i<n;i++) cin >> l[i];

	for(i=0;i<(1<<(n*2));i++) {
		x = y = z = k = 0;
		for(j=0;j<n;j++) {
			if (((i>>(j*2)) & 3)==1) { if (x!=0) k+=10; x+=l[j]; }
			if (((i>>(j*2)) & 3)==2) { if (y!=0) k+=10; y+=l[j]; }
			if (((i>>(j*2)) & 3)==3) { if (z!=0) k+=10; z+=l[j]; }
		}
		if (x==0 || y==0 || z==0) continue;
		ans = min(ans , k+abs(a-x)+abs(b-y)+abs(c-z));
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3628
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String str = sc.nextLine();
        int length = str.length();

        if (length == 2) {
            System.out.println(str);
        } else {
            System.out.println(new StringBuilder(str).reverse().toString());
        }
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>

using namespace std;

long long MOD = 1000000007;

template<typename T>
void cout_vec(vector<T> &vec){
    for(int i=0; i<vec.size(); i++){
        if (i!=0){
            cout << ' ';
        }
        cout << vec[i];
    }
    cout << endl;
}

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

    vector<vector<vector<int> > > tes(N,vector<vector<int> >(0,vector<int>(0)));
    for(int i=0; i<N; i++){
        vector<vector<int> > tmp(0);
        int A;
        cin >> A;
        for(int j=0; j<A; j++){
            int x, y;
            cin >> x >> y;
            x--;
            tmp.push_back({x,y});
        }
        tes[i]=tmp;
    }

    int max_=(1<<N)-1;
    int ans=0;
    int ans2=0;
    for(int i=max_; i>=0; i--){
        vector<int> tmp(N,-1);
        for(int j=0; j<N; j++){
            tmp[N-1-j]=(i>>j)%2;
        }
        int ans=0;
        for(int j=0; j<N; j++){
            if(tmp[j]==1){
                ans++;
                for(int k=0; k<(int) tes[j].size(); k++){
                    int x=tes[j][k][0];
                    int y=tes[j][k][1];
                    if(tmp[x]!=y){
                        ans=-1;
                        break;
                    }
                }
            }
            if(ans==-1)break;
        }
        ans2=max(ans,ans2);
        //cout_vec(tmp);
    }
    cout << ans2 << endl;
}

Measured memory_bytes: 256
def solution():
    n = int(input().strip())
    a  = [int(x) for x in input().strip().split(" ")]
    for x in a:
        if x % 2 == 0:
            if x % 3 != 0 and x % 5 != 0:
                print("DENIED")
                return
    print("APPROVED")

def main():    
    # T = int(input().strip())
    for _ in range(1):
        solution()
    

main()

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

int main() {
    int x, y;

    while(true) {
        cin >> x >> y;
        if (x == 0 && y == 0) {
            break;
        }
        int swap = x;
        if (swap > y) {
            swap = y;
            y = x;
            x = swap;
        }

        printf("%d %d\n", x, y);
    };

    return 0;
}



Measured memory_bytes: 3124
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;

int main(void) {
    int a, b;
    char op;
    
    cin >> a >> op >> b;
    
    while(op != '?') {
        switch(op) {
            case '+' : cout << a+b << endl; break;
            case '-' : cout << a-b << endl; break;
            case '*' : cout << a*b << endl; break;
            case '/' : cout << a/b << endl; break;
            default: break;
        }
        
        cin >> a >> op >> b;
    }
    
    return 0;
}

Measured memory_bytes: 3072
import java.util.*;

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

        int H = sc.nextInt();
        int W = sc.nextInt();
        int h = sc.nextInt();
        int w = sc.nextInt();
        int ans = H * W - (h * W) - ((H - h) * w);
        System.out.println(ans);
    }
}

Measured memory_bytes: 22868