akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

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

struct sq {
    int y; int x; bool white;
};
int pl (sq e, int k, int i) {
    int K = 2 * k;
    return ((((e.y + K - i) % K >= k ? k : 0) + (e.white ? k : 0) + e.x) % K);
}
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k; cin >> n >> k;
    int K = 2 * k;
    vector<sq> squ(n);
    for (auto &e : squ) {
        char col; cin >> e.y >> e.x >> col;
        e.y %= K; e.x %= K;
        e.white = (col == 'W');
    }
    sort(all(squ), [](sq a, sq b){return (a.y != b.y ? a.y < b.y : a.x < b.x);});

    vector<int> check(K);
    int mae = 0, ushiro = 0;
    while (ushiro < n && squ[ushiro].y < k) ushiro++;
    for (auto &e : squ) check[pl(e, k, 0)]++;
    for (int i : check) eprintf("%d ", i); eprintf("\n");
    int ans = 0;
    int tmp = 0;
    rep (i, k) tmp += check[i]; chmax(ans, tmp);
    rep (i, K) {
        tmp += check[(i + k) % K] - check[i % K];
        chmax(ans, tmp);
    }
    rep (i, 1, k + 1) {
        while (mae < n && squ[mae].y < i) {
            check[pl(squ[mae], k, i - 1)]--;
            check[pl(squ[mae], k, i)]++;
            mae++;
        }
        while (ushiro < n && squ[ushiro].y < i + k) {
            check[pl(squ[ushiro], k, i - 1)]--;
            check[pl(squ[ushiro], k, i)]++;
            ushiro++;
        }
        eprintf("%d: %d %d\n", i, mae, ushiro);
        for (int i : check) eprintf("%d ", i); eprintf("\n");
        tmp = 0;
        rep (i, k) tmp += check[i]; chmax(ans, tmp);
        rep (i, K) {
            tmp += check[(i + k) % K] - check[i % K];
            chmax(ans, tmp);
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Diagnostics;

static class CodeJam
{
    static long Solve(string S)
    {
        int N = S.Length;
        long sum = 0;
        int a = 0;
        for (int i = 0; i < N; ++i)
        {
            switch (S[i])
            {
            case 'A':
                ++a;
                break;
            case 'B':
                if (i + 1 < N && S[i + 1] == 'C')
                {
                    sum += a;
                    ++i;
                }
                else
                {
                    a = 0;
                }
                break;
            case 'C':
                a = 0;
                break;
            }
        }
        return sum;
    }

    static void Main(string[] args)
    {
        Console.WriteLine(Solve(Console.ReadLine()));
    }
}


Measured memory_bytes: 13664
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

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

	int coin500 = X / 500;
	int coin5 = (X % 500) / 5;
	int ans = coin500 * 1000 + coin5 * 5;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#100_D
n, m = map(int, input().split())
xyz = [tuple(map(int, input().split())) for _ in range(n)]

ans = 0
for i in range(8):
    t = [-1, -1, -1]
    for j in range(3):
        if (i >> j) & 1:
            t[j] = 1
    
    l = [sum([xyz[i][k]*t[k] for k in range(3)]) for i in range(n)]
    l.sort(reverse= True)
    ans = max(ans, sum(l[:m]))
    
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
using namespace std;
#define DIV 1000000007
long long case_num[100003];

int main()
{
  int N, M;
  cin >> N >> M;
  for (int i = 1; i <= N; i++) case_num[i] = 0;

	vector <int> a(M+1);
	for (int i = 0; i < M; i++) cin >> a[i];

	// ロジックの都合上、最終段の次の階段を壊しておく
	a[M] = N+1;

	// 0段目
  case_num[0] = 1;
  long long now_pos = 0;
  for (int i = 0; i < a.size(); i++) {
		int b_stair = a[i];

		// 壊れた階段を飛び越えた結果、壊れた階段に立っていた場合
		if (now_pos==b_stair) case_num[now_pos] = 0;

		for (int new_pos = now_pos+1; new_pos < b_stair; new_pos++) {
			if (new_pos == 1) {
				// 一段目だけはひとつ前からだけ
				case_num[new_pos] = case_num[new_pos-1];
			} else {
				// ひとつ前からとふたつ前からの2パターン
				case_num[new_pos] = case_num[new_pos-1] + case_num[new_pos-2];
			}
			case_num[new_pos] = case_num[new_pos] % DIV;
		}
    // 飛び越える
    now_pos = b_stair + 1;
    case_num[now_pos] = case_num[now_pos-2];
  }
  cout << case_num[N] << endl;
  return 0;
}


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

int main() {
  
  ll n,k;
  cin >> n >> k;
  
  vector<long double>p(n);
  for(int i=0; i<n; i++) cin >> p[i];

  long double maxans=0;
  for(int i=0; i<k; i++){
   maxans+=(p[i]+1)/2; 
  }
  
  long double ans=maxans;
  for(int i=0; i<n-k+1; i++){
    ans+=(p[i+k]-p[i])/2;
    maxans=max(maxans,ans);
  }
  
  cout << fixed << setprecision(10) << maxans << endl;
  
}


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

int main() {
    char x;
    cin >> x;
    
    if(x >= 'A' && x <= 'Z')
        cout << 'A' << endl;
    else
        cout << 'a' << endl;
    
    return 0;
}


Measured memory_bytes: 3628
#include<iostream>
using namespace std;
int H,W,K;
string s[300];
int A[300][300];
main()
{
	cin>>H>>W>>K;
	for(int i=0;i<H;i++)cin>>s[i];
	int id=0;
	for(int i=0;i<H;i++)
	{
		bool flag=false;
		for(int j=0;j<W;j++)if(s[i][j]=='#')flag=true;
		if(!flag)continue;
		int pre=0;
		for(int j=0;j<W;j++)
		{
			if(s[i][j]=='#')
			{
				id++;
				for(int k=pre;k<=j;k++)A[i][k]=id;
				pre=j+1;
			}
		}
		for(int k=pre;k<W;k++)A[i][k]=id;
	}
	for(int j=0;j<W;j++)
	{
		int pre=0;
		for(int i=0;i<H;i++)
		{
			if(A[i][j]!=0)
			{
				for(int k=pre;k<i;k++)A[k][j]=A[i][j];
				pre=i+1;
			}
		}
		for(int k=pre;k<H;k++)A[k][j]=A[pre-1][j];
	}
	for(int i=0;i<H;i++)
	{
		for(int j=0;j<W;j++)cout<<A[i][j]<<(j==W-1?"\n":" ");
	}
}


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

int main(){
  int w,h,n;
  cin >> w >> h >> n;
  int zx=0,nx=w,zy=0,ny=h;
  
  for(int i=0;i<n;i++){
    int x,y,a;
    cin >> x >> y >> a;
    if(a==1) zx=max(zx,x);
    else if(a==2) nx=min(nx,x);
    else if(a==3) zy=max(zy,y);
    else ny=min(ny,y);
  }
  
  cout << max(nx-zx,0)* max(ny-zy,0) << endl;
}

Measured memory_bytes: 256
N,K = map(int,input().split())
P = [int(t) - 1 for t in input().split()]
C = list(map(int,input().split()))

ans = -1e18
for si in range(N):
    x = si
    s = []
    tot = 0
    while True:
        x = P[x]
        s.append(C[x])
        tot += C[x]
        if x == si:
            break
    l = len(s)
    t = 0
    for i in range(l):
        t += s[i]
        if i+1 > K:
            break
        now = t
        if tot > 0:
            e = (K-(i+1))//l
            now += tot*e
        if ans < now:
            ans = now
print(ans)

Measured memory_bytes: 81092
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = int64_t;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vi>;



int main() {
    int h, n;
    cin >> h >> n;
    vi a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }

    vi dp(h+1, INT_MAX);
    dp[0] = 0;
    rep(i, n) {
        rep(j, h+1) {
            if(dp[j] == INT_MAX) continue;
            if(h-j >= a[i]) {
                dp[j+a[i]] = min(dp[j+a[i]], dp[j] + b[i]);
            } else {
                dp[h] = min(dp[h], dp[j]+b[i]);
            }
        }
    }
    cout << dp[h] << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <ctype.h>
#include <map>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <cctype>
#include <queue>
#define REP(i,n) for(int i=0;i<(int)n;++i)
#define REP1(j,n) for(int j=0;j<(int)n;++j)
#define REPD(i,n) for(int i=n;i>=0;--i)
#define REPD1(j,n) for(int j=n;j=>0;--j)
#define REPS(i,n) for(int i=1;i<=(int)n;++i)
#define REPS1(j,n) for(int j=1;j<=(int)n;++j)
#define rep(i,a,n) for(int i=a;i<=(int)n;++i)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;

int main(void) {
	int n;
	cin >> n;
	int num = n,sum=0;

	while (10<num) {
		sum += num % 10;
		num /= 10;
	}
	sum += num % 10;
//	cout << sum << endl;
	if (n%sum == 0)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}



Measured memory_bytes: 256
n = int(input())

ans = 0
cntA = 0
cntB = 0
cntBA = 0
for i in range(n):
    s = input()
    ans += s.count('AB')
    if s[0] == 'B' and s[-1] == 'A':
        cntBA += 1
    elif s[-1] == 'A':
        cntA += 1
    elif s[0] == 'B':
        cntB += 1
if cntBA == 0:
    ans += min(cntA, cntB)
elif cntA + cntB == 0:
    ans += cntBA - 1
else:
    ans += cntBA + min(cntA, cntB)

print(ans)


Measured memory_bytes: 3064
class Work:
    weight = 0
    deadline = 0
    
    def __init__(self, w, d):
        self.weight = w
        self.deadline = d
        
    def __lt__(self, other):
        return self.deadline < other.deadline
        
N = int(input())
works = []
for l in range(N):
    a,b = [int(i) for i in input().split()]
    works.append(Work(a,b))
    
works.sort()
keika = 0
ans = "Yes"
for i in range(len(works)):
    keika += works[i].weight
    if keika > works[i].deadline:
        ans = "No"
        break

print(ans)

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

int main(){
    int N,K;
    cin >> N >> K;
    vector<int> sunuke(N);
    for(int i=0;i<K;i++){
        int d;
        cin >> d;
        for(int j=0;j<d;j++){
            int n;
            cin >> n;
            sunuke.at(n-1)=1;
        }
    }
    int num = 0;
    for(int i=0;i<N;i++){
        if(sunuke.at(i)==0){
            num++;
        }
    }
    cout << num << endl;
}

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

#define int long long
#define ll long long
#define F first 
#define S second 
#define pb push_back
#define ld double

using namespace std ; 

const int MAXN = 1001 * 1001 , MOD =  1e9 + 7 ;

int ps1[MAXN] , ps2[MAXN] ; 

int32_t main()
{
	ios::sync_with_stdio(0) ;
	string s , t ; 
	cin >> s >> t ; 
	int n = s.size() , m = t.size() ; 
	for(int i = 1 ; i <= n ; i ++ ) ps1[i] = ps1[i-1] + (s[i-1] == 'A') ; 
	for(int i = 1 ; i <= m ; i ++ ) ps2[i] = ps2[i-1] + (t[i-1] == 'A') ; 
	int q ; 
	cin >> q ;
	while(q--)
	{
		int a , b , c , d ; 
		cin >> a >> b >> c >> d ; 
		a -- ; 
		c -- ;
		int x1 = (ps1[b]-ps1[a]) ;
		int x2 = (ps2[d]-ps2[c]) ;
	//	cout << x1 << ' ' << x2 << '\n' ; 
		x1 = x1 - (b-a-x1) ;
		x2 = x2 - (d-c-x2) ;
	  //  cout << x1 << ' ' << x2 << '\n'; 	
		x1 += 99999999;
		x2 += 99999999;
		if(x1%3==x2%3)
			cout << "YES\n" ; 
		else
			cout << "NO\n" ; 	
	}
}




Measured memory_bytes: 5840
def bfs(i, j):
    if a[i][j] == ".":
        a[i][j] = "#"
    res=1
    wc=0
    bc=0
    for dy in range(-1, 2):
        for dx in range(-1, 2):
            if (dx==0 and dy!=0) or (dx!=0 and dy==0):
                pass
            else:
                continue
            ny = i+dy
            nx = j+dx

            if 0<=nx<=w-1 and 0<=ny<=h-1 and a[ny][nx]!="#":
                if a[ny][nx] == ".":
                    wct, bct, rest = bfs(ny, nx)
                    wc+=wct
                    bc+=bct
                    res+=rest
                elif a[ny][nx]=="W":
                    wc+=1
                elif a[ny][nx]=="B":
                    bc+=1
    #print(wc, bc, res)
    return wc, bc, res

import sys
sys.setrecursionlimit(100000)

while True:
    w, h = map(int, input().split())
    wans = 0
    bans = 0
    if w==0 and h==0:
        break
    a = [list(input()) for _ in range(h)]

    for i in range(w):
        for j in range(h):
            if a[j][i] ==".":
                wc, bc, res = bfs(j, i)
                if wc>0 and bc==0:
                    wans+=res
                elif wc==0 and bc>0:
                    bans+=res
    print(bans, wans)



Measured memory_bytes: 8376
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
#include <queue>
using namespace std;

int main(){
    int n;
    cin>>n;
    if(n==1)cout<<"Hello World"<<endl;
    else{
        int a,b;
        cin>>a>>b;
        cout<<a+b<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    a = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(len(a)):
        if a[i] < 0:
            cnt += 1
            a[i] *= -1
    a.sort()
    if cnt % 2 == 0:
        print(sum(a))
    else:
        print(sum(a) - a[0] * 2)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 64752
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i < b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = INT_MAX / 2;
const ll  inf = LLONG_MAX / 2;
const int mod = 1000000007;
const int MAX_N = 101010;
const long double PI = acos(-1);

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	int n, k;
	cin >> n >> k;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	int res = 0;
	int r = 0;

	while (r < n) {
		if (res == 0) {
			r += k;
		}
		else {
			r += k - 1;
		}
		res++;
	}

	out(res);

	return 0;
}

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

int main() {
  int h, w;
  cin >> h >> w;
  char data[h][w];
  rep(i, h) {
    rep(j, w) {
      cin >> data[i][j];
    }
  }


  rep(i, h) {
    bool only_white = true;
    rep(j, w) {
      if (data[i][j] == '#') only_white = false;
    }
    if (only_white) {
      rep(j, w) {
        data[i][j] = ' ';
      }
    }
  }

  rep(j, w) {
    bool only_white = true;
    rep(i, h) {
      if (data[i][j] == '#') only_white = false;
    }
    if (only_white) {
      rep(i, h) {
        data[i][j] = ' ';
      }
    }
  }

  rep(i, h) {
    bool only_white = true;
    rep(j, w) {
      if (data[i][j] != ' ') {
        only_white = false;
        cout << data[i][j];
      }
    }
    if (!only_white) cout << endl;
  }
}


Measured memory_bytes: 256
#pragma comment(linker, "/stack:200000000")

#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")

#include <stdio.h>
#include <bits/stdc++.h>

#define uint unsigned int
#define int long long
#define ull unsigned long long
#define ld long double
#define rep(i, l, r) for (int i = l; i < r; i++)
#define repb(i, r, l) for (int i = r; i > l; i--)
#define sz(a) (int)a.size()
#define fi first
#define se second
#define mp(a, b) make_pair(a, b)
#define ret(a) return cout<<a,0;
using namespace std;
const int N = 2 * 1e5 + 10;
int tot  , n , ans; 
string a , b;

main(){
	ios::sync_with_stdio(0); cin.tie(0);cout.tie(0);
	
	cin >> n >> a >> b;
	ans = n + n;
	
	for(int i = 1 ; i <= n ; i++){
		if(b.substr(0, i) == a.substr(n - i, i))
			ans = n + n - i;
	}
	cout << ans ;
	
}

Measured memory_bytes: 256
#include <iostream>
#include<string.h>
#define ll long long 
#include<vector>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
using namespace std;
const int mod=1e9+7;
int main(){
	IOS;
	int n;
	cin>>n;
	vector<int> h(n);
	for(int i=0;i<n;i++)
	cin>>h[i];
	//dp[i] minimum cost to reach i th rock from 0;
	ll dp[100005];
	dp[0]=0;
	dp[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++){
		dp[i]=min(abs(h[i]-h[i-1])+dp[i-1], abs(h[i]-h[i-2])+dp[i-2]);
	} 
	cout<<dp[n-1];
}

Measured memory_bytes: 4468
//Problem D
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n;ll k,a[55],b[55];
ll solve(int n,ll k){//printf("%d %lld\n",n,k);
	if(!n||!k)return k;
	if(k<=a[n-1]+1)return solve(n-1,k-1);
	return b[n-1]+1+solve(n-1,k-a[n-1]-2-(k==a[n]));
}
int main(){
    scanf("%d%lld",&n,&k);
	a[0]=b[0]=1;for(int i=1;i<=n;i++)a[i]=3+a[i-1]*2,b[i]=1+b[i-1]*2;
	printf("%lld",solve(n,k));
    return 0;
}

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

#define rep(i,n) for(int (i) = 0; (i) < (n); (i)++)

using namespace std;

const long long int inf = 1e20;

int main(void) {
	int n, k;
	cin >> n >> k;

	vector<long long int> x(n), y(n);
    vector<long long int> ox(n), oy(n);

	rep(i, n) {
		cin >> x[i] >> y[i];
        ox[i] = x[i]; oy[i] = y[i];
	}
	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	long long int ans = inf;
  
	rep(x1, n) { if (x1 != 0 && x[x1-1] == x[x1]) continue;
	rep(y1, n) { if (y1 != 0 && y[y1-1] == y[y1]) continue;
	rep(x2, n) { if (x[x2] == x[x2+1]) continue;
	rep(y2, n) { if (y[y2] == y[y2+1]) continue;
	  if (x1 >= x2 || y1 >= y2) continue;
      int cnt = 0;
	  rep(i, n) {
	    if (x[x1] <= ox[i] && ox[i] <= x[x2] && y[y1] <= oy[i] && oy[i] <= y[y2])  cnt++;
	  }
	  if ( cnt >= k) ans = min(ans, (x[x2]-x[x1])*(y[y2]-y[y1]));
	}}}}

	cout << ans << endl;

}


Measured memory_bytes: 256
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include <algorithm>
#include<iostream>
#include<stdio.h>
#include<vector>
#include<set>
#include<string>
#include<iomanip>
#include<queue>
#include<functional>
#include<cmath>
#define rep(i,n) for(int i=0; i<(int)n; i++)//n回繰り返す
using namespace std;
using ll = long long;
using P = pair<int, int>;
using graph = vector<vector<int>>;

int main() {
	long long int N, M,T; cin >> N >> M;
		T = N / M;
		N -= ((T+1)* M);
		cout << min(N + M, abs(N)) << endl;
	
}




	




























































































































	


	 



































    





Measured memory_bytes: 256
#import math.sqrt as sqrt

#S = list(map(int, input().split()))
#B = list(map(int, input().split()))

S = int(input())

if S == 25:
    print("Christmas")
elif S == 24:
    print("Christmas Eve")
elif S == 23:
    print("Christmas Eve Eve")
else:
    print("Christmas Eve Eve Eve")


Measured memory_bytes: 2940
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	int n = read.to!int;
	
	foreach(i; 1 .. n + 1){
		int[] ans;
		foreach(j; 1 .. n - i + 1){
			ans ~= f(j) + 1;
		}
		ans.map!(to!string).array.join(" ").writeln;
	}
	
	log([0, 1, 2, 3, 4, 5, 6].map!f);
	
}

int f(int j){
	int res = 0;
	while(j > 0 && j % 2 == 0) res += 1, j /= 2;
	return res;
}


/*

   1/2/3/4/5/6/7/8/9/A/B
1: - 1 2 1 3 1 2 1 4 1 2
2: 1 - 1 2 1 3 1 2 1 4 1
3: 2 1 - 1 2 1 3 1 2 1 4
4: 1 2 1 - 1 2 1 3 1 2 1
5: 3 1 2 1 - 1 2 1 3 1 2
6: 1 3 1 2 1 - 1 2 1 3 1
7: 2 1 3 1 2 1 - 1 2 1 3
8: 1 2 1 3 1 2 1 - 1 2 1
9: 4 1 2 1 3 1 2 1 - 1 2
A: 1 4 1 2 1 3 1 2 1 - 1
B: 2 1 4 1 2 1 3 1 2 1 -

*/


Measured memory_bytes: 2428
n = int(raw_input())
for i in range(int(raw_input())):
    x,y = map(int, raw_input().split())
    w = min(x, n - x + 1)
    h = min(y, n - y + 1)
    if h > w:
        print (w - 1) % 3 + 1
    else:
        print (h - 1) % 3 + 1

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

using namespace std;

int gcd(int a, int b) {
    if (a % b == 0) {
        return(b);
    } else {
        return(gcd(b, a % b));
    }
}

int main() {

    int K;
    cin >> K;
    int member;

    vector<int> members;

    for (int i = 1; i <= K; i++) {
        for (int j = 1; j <= K; j++) {
            for (int l = 1; l <= K; l++) {

                member = gcd(gcd(i, j), l);
                members.push_back(member);
            }
        }
    }

    cout << accumulate(members.begin(), members.end(), 0LL) << endl;

    return 0;
}


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

int main(){
  int k;
  string s;
  cin >> k >> s;
  if(s.size()<=k) cout << s << endl;
  else {
    rep(i,k){
      cout << s.at(i);
    }
    cout << "..." << endl;
  }
  
  return 0;


}


Measured memory_bytes: 3564
from copy import deepcopy
from sys import exit,setrecursionlimit
import math
from collections import defaultdict,Counter,deque
from fractions import Fraction as frac
import bisect
import sys
input = sys.stdin.readline

setrecursionlimit(1000000)

def main():
	h,w,m = int(input()),int(input()),int(input())
	h,w = max(h,w),min(h,w)
	print(math.ceil(m/h))

def factorization(n):
	arr = []
	temp = n
	for i in range(2, int(-(-n**0.5//1))+1):
		if temp%i==0:
			cnt=0
			while temp%i==0:
				cnt+=1
				temp //= i
			arr.append([i, cnt])

	if temp!=1:
		arr.append([temp, 1])

	if arr==[]:
		arr.append([n, 1])

	return arr

def zip(a):
	mae = a[0]
	ziparray = [mae]
	for i in range(1,len(a)):
		if(mae != a[i]):
			ziparray.append(a[i])
			mae = a[i]
	return ziparray

def is_prime(n):
	if n < 2: return False

	for k in range(2, int(math.sqrt(n)) + 1):
		if n % k == 0:
			return False

	return True

def list_replace(n,f,t):
	return [t if i==f else i for i in n]

def base_10_to_n(X, n):
	X_dumy = X
	out = ''
	while X_dumy>0:
		out = str(X_dumy%n)+out
		X_dumy = int(X_dumy/n)
	if(out == ''): return '0'
	return out

def gcd(l):
	x = l.pop()
	y = l.pop()
	while(x%y!=0):
		z = x%y
		x = y
		y = z
	l.append(min(x,y))
	return gcd(l) if len(l) > 1 else l[0]

class Queue():
	def __init__(self):
		self.q = deque([])
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.popleft()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class Stack():
	def __init__(self):
		self.q = []
	def push(self,i):
		self.q.append(i)
	def pop(self):
		return self.q.pop()
	def size(self):
		return len(self.q)
	def debug(self):
		return self.q

class graph():
	def __init__(self):
		self.graph = defaultdict(list)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
		self.graph[t].append(f)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
		self.graph[t].remove(f)
	def linked(self,f):
		return self.graph[f]

class dgraph():
	def __init__(self):
		self.graph = defaultdict(set)
	def addnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].append(t)
	def rmnode(self,l):
		f,t = l[0],l[1]
		self.graph[f].remove(t)
	def linked(self,f):
		return self.graph[f]

main()


Measured memory_bytes: 65516
#include "iostream"
#include "string"


int main()
{
	int H, W;

	while (true) {
		std::cin >> H >> W;

		if (W == 0 && H == 0)
			break;

		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				if (((j + i) % 2) == 0)
					std::cout << '#';
				else
					std::cout << '.';
			}
			std::cout << std::endl;
		}
		std::cout << std::endl;
	}
	return 0;
}

Measured memory_bytes: 3060
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cassert>
#include <string>
#include <set>
#include <map>
#include <random>
#include <bitset>
#include <string>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <queue>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

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

const int N = 1001;
char a[N][N];
int d[N][N], r[4][2] = {{0, 1}, {0, -1}, {1, 0}, {-1, 0}};

int main() {
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n, m, inf = 3000;
	cin >> n >> m;
	queue<pair<int, int>> q;
	rep(i, n) {
		cin >> a[i];
		rep(j, m) {
			if (a[i][j] == '#')
				q.push({i, j});
			else
				d[i][j] = inf;
		}
	}
	int ans = 0;
	while (!q.empty()) {
		int x = q.front().first, y = q.front().second;
		q.pop();
		ans = d[x][y];
		rep(i, 4) {
			int cx = x + r[i][0], cy = y + r[i][1];
			if (cx >= 0 && cx < n && cy >= 0 && cy < m && d[cx][cy] == inf) {
				d[cx][cy] = d[x][y] + 1;
				q.push({cx, cy});
			}
		}
	}
	cout << ans;
}

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

int main() {
    int n;
    cin >> n;
    const int m = (1 << n);
    vector<int> s(m);
    for (int &e : s) { cin >> e; e *= -1; }
    sort(s.begin(), s.end());
    
    vector<int> dat;
    multiset<int> ms;
    dat.emplace_back(s[0]);
    for (int i = 1; i < m; i++) ms.emplace(s[i]);
    
    bool flag = true;
    for (int _ = 0; _ < n; _++) {
        const int sz = dat.size();
        for (int i = 0; i < sz; i++) {
            auto it = ms.upper_bound(dat[i]);
            if (it == ms.end()) {
                flag = false; break;
            }
            dat.emplace_back(*it);
            ms.erase(it);
        }
        if (not flag) break;
    }
    
    cout << (flag ? "Yes" : "No") << '\n';
    
    return 0;
}

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007
 
void solve()
{
	ll n,m,sum=0,cnt=0;
	cin>>n>>m;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
		sum+=a[i];
	}
	for(ll i=0;i<n;i++) if(a[i]*4*m>=sum) cnt++;
	if(cnt>=m) cout<<"Yes";
	else cout<<"No";
}

int main() 
{
	FAST
	ll t=1;
	//cin>>t;
	for(ll i=0;i<t;i++) solve();
	return 0;
}

Measured memory_bytes: 256
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author
 */

#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define fr(i,n) for(int i=0;i<(n);++i)
#define Fr(i,n) for(int i=1;i<=(n);++i)
#define ifr(i,n) for(int i=(n)-1;i>=0;--i)
#define iFr(i,n) for(int i=(n);i>0;--i)

class EFrequency {
public:
    void solve(istream& in, ostream& out) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        int n;
        in>>n;
        vector<int> a(n),b(n);
        vector<ll> ans(n);
        vector<pair<int,int>> v(n);
        fr(i,n) in>>a[i],v[i]=make_pair(a[i],-i);
        sort(v.rbegin(),v.rend());
        fr(i,n) b[i]=-v[i].second;
        int nw=b[0],w=a[nw];
        Fr(i,n-1){
            ans[nw]+=(ll)i*(w-a[b[i]]);
            w=a[b[i]];
            if(nw>b[i]) nw=b[i];
        }
        ans[nw]+=(ll)n*w;
        for(auto i:ans) out<<i<<endl;
    }
};

int main() {
    EFrequency solver;
    std::istream& in(std::cin);
    std::ostream& out(std::cout);
    solver.solve(in, out);
    return 0;
}


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

#define FOR(i, a, b) for(int i=(a); i<(b); i++)
#define RFOR(i, a, b) for(int i=(a); i>=(b); i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define CEIL(n, m) ceil(n/pow(10.0, m))*pow(10.0, m)
#define FLOOR(n, m) floor(n/pow(10.0, m))*pow(10.0, m)
#define ROUND(n, m) round(n/pow(10.0, m))*pow(10.0, m)
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define RSORT(x) sort((x).begin(),(x).end(),greater<int>())
#define SZ(x) ((int)(x).size())
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) " (L" << __LINE__ << ") " << __FILE__ << endl;

typedef long long ll;
const int mod = 1e9+7;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int inf = 0x3f3f3f3f;

void solve()
{
  string s;
  cin >> s;
  string t;
  cin >> t;

  int slen = (int)(s.length());
  int tlen = (int)(t.length());
  string x = s;

  bool flg=false;
  for (int i=slen-tlen; i>=0; i--) {
    x = s;
    for (int j=0; j<tlen; j++) {
      flg = true;
      if (s[i+j] == t[j] || s[i+j] == '?') {
        x[i+j] = t[j];
      } else {
        flg = false; break;
      }
    }
    if (flg) break;
  }

  if (!flg) {
    cout << "UNRESTORABLE" << endl;
    return;
  }

  for (int i=0; i<slen; i++) {
    if (x[i] == '?') x[i] = 'a';
  }

  cout << x << endl;
}

int main()
{
  solve();
  return 0;
}


Measured memory_bytes: 256
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        String inputString = in.next();
        System.out.println(inputString.substring(0, inputString.length() - 8));
    }
}


Measured memory_bytes: 20820
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())
 
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
 
using namespace std;
class UnionFind {
  vector<int> p;
public:
  UnionFind (int n) : p(n, -1) {}
  int root(int x) {
    return p[x] < 0 ? x : p[x] = root(p[x]);
  }
  bool same(int x, int y) {
    return root(x) == root(y);
  }
  bool unite(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;
    if (p[y] < p[x]) swap(x, y);
    if (p[x] == p[y]) --p[x];
    p[y] = x;
    return true;
  }
};
 
int main(void)
{
  int n,m;
  cin >> n >> m;
  UnionFind uf(n);
  vector<int> la(m+1,-1);
  int answer=1;
  REP(i,n){
    int k;
    cin >> k;
    REP(j,k){
      int l;
      cin >> l;
      if(la[l]!=-1) if(uf.unite(la[l], i)) ++answer;
      la[l]=i;
    }
  }
  cout << (answer==n ? "YES" : "NO") << endl;
  return 0;
}

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


public class Main {

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

		char[] s = sc.next().toCharArray();
		int n = s.length;

		Deque<Character> q = new ArrayDeque<>();
		for (int i = 0; i < n; i++) {
			if (s[i] == 'B') {
				if (q.size() > 0) {
					q.removeLast();
				}
			} else {
				q.add(s[i]);
			}
		}

		StringBuilder sb = new StringBuilder();
		for (Character ch : q) {
			sb.append(ch);
		}

		pr.println(sb);

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 9552
S = input()
Ls = ['L', 'U', 'D'] #偶数
Rs = ['R', 'U', 'D'] #奇数
l = len(S)
n = l//2
f = True
S = 'R' + S
for i in range(1, n + 1):
    if (S[2*i - 1] in Rs) and (S[2*i] in Ls):
        pass
    else:
        f = False
        break
if f:
    if l%2 == 1:
        if S[-1] in Rs:
            print('Yes')
        else:
            print('No')
    else:
        print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
n, T = map(int,input().split())
min_c = 1001
for _ in range(n):
    c,t =  map(int,input().split())
    if t <= T:
        min_c = min(min_c,c)
if min_c == 1001:
    print("TLE")
else:
    print(min_c)

Measured memory_bytes: 2940
class UnionFind:
    def __init__(self, node):
        self.parent = [-1 for _ in range(node)]

    def find(self, target):
        if self.parent[target] < 0:
            return target
        else:
            self.parent[target] = self.find(self.parent[target])
            return self.parent[target]

    def is_same(self, x, y):
        return self.find(x) == self.find(y)

    def union(self, x, y):
        root_x = self.find(x)
        root_y = self.find(y)
        if root_x == root_y:
            return
        if self.parent[root_x] > self.parent[root_y]:
            root_x, root_y = root_y, root_x
        self.parent[root_x] += self.parent[root_y]
        self.parent[root_y] = root_x

    def get_size(self, x):
        return -self.parent[self.find(x)]


def main():
    n, m, k = map(int, input().split())
    uf = UnionFind(n)
    friend = [[] for _ in range(n)]
    answer = [-1 for _ in range(n)]
    for _ in range(m):
        a, b = map(lambda x: int(x) - 1, input().split())
        uf.union(a, b)
        friend[a].append(b)
        friend[b].append(a)
    for _ in range(k):
        c, d = map(lambda x: int(x) - 1, input().split())
        if uf.is_same(c, d):
            answer[c] -= 1
            answer[d] -= 1
    for i in range(n):
        answer[i] += uf.get_size(i) - len(friend[i])
    print(" ".join(map(str, answer)))


if __name__ == '__main__':
    main()



Measured memory_bytes: 33740
//##MohK
#include <bits/stdc++.h>
using namespace std ;
using ll =long long;
int main()
{
    ll a,h;
    ll sum=0;
    cin>>a>>h;
    int x[h];
    for(ll i=0;i<h;i++){
            cin>>x[i];
    }
     for(ll i=0;i<h;i++){
            sum=sum+x[i];
    }
    if(sum>=a)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;



    return 0 ;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define pb push_back
#define pii pair<long long,long long>
#define endl '\n'
#define N 300001
int mod=1000000007;
int dx[]={1,-1,0,0};
int dy[]={0,0,1,-1};
vector<int> parent(N),sz(N),indegree(N),vis(N); char st[N];
vector<int> adj[N];
int modexp(int x,int n,int M)
{
    if(n==0)
        return 1;
    else if(n%2 == 0)        
        return modexp((x*x)%M,n/2,M);
    else                             
        return (x*modexp((x*x)%M,(n-1)/2,M))%M;
}
void make_set(int s)
{
    parent[s]=s;
    sz[s]=1;
}
int find_parent(int p)
{
    if(p==parent[p])
    return p;
    return parent[p]=find_parent(parent[p]);
}
void union_set(int a,int b)
{
    a=find_parent(a);b=find_parent(b);
    if(a!=b)
    {
        if(a<b)
        swap(a,b);
        parent[b]=parent[a];
        sz[a]+=sz[b];
    }
}
void solve()
{
    int n,k; cin>>n>>k;
    vector<int> v(n+1);
    for(int i=1;i<=n;i++)
    make_set(i);
    for(int i=1;i<=n;i++)
    {
        cin>>v[i];
        union_set(i,v[i]);
    }
    vis.assign(N,0);
    if(k<=n)
    {
        int ans=1;
        while(k--)
        {
            ans=v[ans];
        }
        cout<<ans;
        return;
    }
    int cur=1; int len=0;
    while(1)
    {
        if(vis[cur])
        break;
        vis[cur]=1;
        cur=v[cur];
        len++;
    }
    vis.assign(N,0);
    int cnt=0;
    int st=cur;
    while(1)
    {
        if(vis[cur])
        break;
        vis[cur]=1;
        cur=v[cur];
        cnt++;
    }
    k=k-len+cnt;
    k=k%cnt;
    int ans=st;
    while(k--)
    {
        ans=v[ans];
    }
    cout<<ans;
}
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int test; test=1;
    while(test--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 21152
#include <cstdio>
#include <cstring>
#include <string>
#include <iostream>
using namespace std;

int main(void)
{
    string str;
    int n;
    
    scanf("%d\n", &n);
    for (int i = 0; i < n; i++){
        getline(cin,str);
        for (int j = 0; j < str.size(); j++){
            if (str[j] == 'H'){
                if ((str[j + 1] == 'o') && (str[j + 2] == 's') && (str[j + 3] == 'h') && (str[j + 4] == 'i') && (str[j + 5] == 'n') && (str[j + 6] == 'o')){
                    str[j + 6] = 'a';
                    j += 6;
                }
            }
        }
        printf("%s\n", str.c_str());
    }
    
    return (0);
}

Measured memory_bytes: 0
from collections import defaultdict as dd
s=input()
t=input()
ds=dd(int)
dt=dd(int)
for ss in s:
    ds[ss]+=1
for tt in t:
    dt[tt]+=1
cs,ct=[],[]

for v in ds.values():
    cs.append(v)
for v in dt.values():
    ct.append(v)
cs.sort()
ct.sort()

for sss,ttt in zip(cs,ct):
    if sss!=ttt:
        print('No')
        exit()
print('Yes')


Measured memory_bytes: 4144
X = gets.chomp
L = X.length

ns, pos = 0, 0
until pos == L
	nxt = X.index('T', pos)||L
	ns += nxt - pos
	pos = nxt

	nxt = X.index('S', pos)||L
	ns -= nxt - pos
	ns = 0 if ns < 0
	pos = nxt
end

p ns*2


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

using namespace std;
#define int long long
#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                    \
    sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(c i) \
    {
sim>
struct rge {
    c b, e;
};

sim> rge<c> range(c i, c j) { return rge<c>{i, j}; }

sim> auto dud(c *x) -> decltype(cerr << *x, 0);

sim> char dud(...);

struct debug {
#ifndef LOCAL

    ~debug() {
        cerr << endl;
    }

    eni(!=) cerr << boolalpha << i;
        ris;
    }

    eni(==) ris << range(begin(i), end(i));
    }

    sim, class b dor(pair<b, c> d) {
        ris << "(" << d.first << ", " << d.second << ")";
    }

    sim dor(rge<c> d) {
        *this << "[";
        for (auto it = d.b; it != d.e; ++it)
            *this << ", " + 2 * (it == d.b) << *it;
        ris << "]";
    }

#else
    sim dor(const c &)
    {
        ris;
    }
#endif
};

#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

void solve();

int32_t main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
//    test
    solve();
    return 0;
}

void solve() {
    string s, t;
    cin >> s >> t;
    int ans = INT_MAX;
    for (int i = 0; i <= (int) (s.size()) - (int) (t.size()); ++i) {
        int cnt = 0;
        int idx = 0;
        for (int j = i; idx < (int) (t.size()); ++j) {
            if (s[j] != t[idx]) cnt++;
            idx++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 3576
#include <stdio.h>
#include <iostream>

using namespace std;

int main(){
 
  string a, b;
  
  cin >> a >> b;
  
  bool found = false;
  
  int count = 0;
  
  while(!found && count < 26){
   
    string temp = a;
    temp += ('a' + count);
    
    if(temp == b){ 
      cout << "Yes" << endl;
      found = true;
      return 0;
    }
    
    count++;
  }
  
  cout << "No" << endl;
}

Measured memory_bytes: 3632
#include<stdio.h>
int Euclid(int,int);
int main(){
  int x,y,n;             //x,y 入力される数字用 n 最大公約数を求める用
  scanf("%d %d",&x,&y);
  printf("%d\n",Euclid(x,y));
  
  return 0;
}
int Euclid(int x,int y){
  int n;
  if(x == y)return x;// xとyが同じならその値いが最大公約数
  else{              //そうでなければ、ユークリッドの互除法を計算
    if(x > y){        //xの方が大きいとき
      n = x % y;
      if(x%n==0 && y%n==0)return n;
      else return Euclid(y,n);
    }
    else{
      n = y % x; //yの方が大きいとき
      if(x%n==0 && y%n==0)return n;
      else return Euclid(x,n);
    }
  }
}



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

int max(int x, int y){
	return (x > y) ? x : y;
}

int main(void){
	int w, a, b, aw, bw, dist;

	cin >> w >> a >> b;

	aw = a + w;
	bw = b + w;

	if (a < b){
		dist = max(b - aw, 0);
	}
	else{
		dist = max(a - bw, 0);
	}

	cout << dist << endl;

	return 0;
}

Measured memory_bytes: 256
let n=read_int()open Array
let a=init n(fun _->Scanf.scanf"%d "(fun e->e))and b=make n 0and c=make 10001 0;;iter(fun e->c.(e)<-c.(e)+1)a;iteri(fun i _->if i<>0then c.(i)<-c.(i)+c.(i-1))c;for i=n-1downto 0do c.(a.(i))<-c.(a.(i))-1;b.(c.(a.(i)))<-a.(i);done;print_int b.(0);for i=1to n-1do print_string" ";print_int b.(i);done;print_newline()

Measured memory_bytes: 36096
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

//The Code A Doctor Loved
public class Main{

	public static void main(String[] args) {
		Map<Character, String> t = new HashMap<Character, String>();
		t.put(' ', "101");
		t.put('\'', "000000");
		t.put(',', "000011");
		t.put('-', "10010001");
		t.put('.', "010001");
		t.put('?', "000001");
		t.put('A', "100101");
		t.put('B', "10011010");
		t.put('C', "0101");
		t.put('D', "0001");
		t.put('E', "110");
		t.put('F', "01001");
		t.put('G', "10011011");
		t.put('H', "010000");
		t.put('I', "0111");
		t.put('J', "10011000");
		t.put('K', "0110");
		t.put('L', "00100");
		t.put('M', "10011001");
		t.put('N', "10011110");
		t.put('O', "00101");
		t.put('P', "111");
		t.put('Q', "10011111");
		t.put('R', "1000");
		t.put('S', "00110");
		t.put('T', "00111");
		t.put('U', "10011100");
		t.put('V', "10011101");
		t.put('W', "000010");
		t.put('X', "10010010");
		t.put('Y', "10010011");
		t.put('Z', "10010000");
		Map<String, Character> r = new HashMap<String, Character>();
		r.put("00000", 'A');
		r.put("00001", 'B');
		r.put("00010", 'C');
		r.put("00011", 'D');
		r.put("00100", 'E');
		r.put("00101", 'F');
		r.put("00110", 'G');
		r.put("00111", 'H');
		r.put("01000", 'I');
		r.put("01001", 'J');
		r.put("01010", 'K');
		r.put("01011", 'L');
		r.put("01100", 'M');
		r.put("01101", 'N');
		r.put("01110", 'O');
		r.put("01111", 'P');
		r.put("10000", 'Q');
		r.put("10001", 'R');
		r.put("10010", 'S');
		r.put("10011", 'T');
		r.put("10100", 'U');
		r.put("10101", 'V');
		r.put("10110", 'W');
		r.put("10111", 'X');
		r.put("11000", 'Y');
		r.put("11001", 'Z');
		r.put("11010", ' ');
		r.put("11011", '.');
		r.put("11100", ',');
		r.put("11101", '-');
		r.put("11110", '\'');
		r.put("11111", '?');
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext()){
			char[] s = sc.nextLine().toCharArray();
			StringBuilder sb = new StringBuilder();
			for(char c:s)sb.append(t.get(c));
			while(sb.length()%5!=0)sb.append('0');
			String u = sb.toString();
			StringBuilder v = new StringBuilder();
			for(int i=0;i<u.length();i+=5)v.append(r.get(u.substring(i, i+5)));
			System.out.println(v);
		}
	}
}

Measured memory_bytes: 12000
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		//		new Main().solveA();
		new Main().solveB();
		// new Main().solveC();
		// new Main().solveD();
	}

	private void solveA() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();
			lineBC = scanner.nextInt();

			if (lineBC % lineAB == 0) {
				System.out.println(lineAB + lineBC);
			} else {
				System.out.println(lineBC - lineAB);
			}

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveB() {
		Scanner scanner = null;
		int nNin = 0;
		int mSyurui = 0;

		try {
			scanner = new Scanner(System.in);
			String line1 = scanner.nextLine();
			String[] wkStr1 = line1.split(" ");
			nNin = Integer.parseInt(wkStr1[0]);
			mSyurui = Integer.parseInt(wkStr1[1]);

			List<List<Integer>> wkList = new ArrayList<List<Integer>>();

			for (int i = 0; i < nNin; i++) {
				String wk = scanner.nextLine();
				String[] wkStr = wk.split(" ");
				List<Integer> wkInnerList = new ArrayList<Integer>();
				for (int j = 1; j < wkStr.length; j++) {
					wkInnerList.add(Integer.parseInt(wkStr[j]));
				}
				wkList.add(wkInnerList);
			}

			int result = 0;
			List<Integer> alreadyFinishList = new ArrayList<Integer>();
			for (int i = 0; i < wkList.size(); i++) {
				List<Integer> wkInnerList = wkList.get(i);
				for (int i2 = 0; i2 < wkInnerList.size(); i2++) {
					int syokuNum = wkInnerList.get(i2);
					if (alreadyFinishList.contains(syokuNum)) {
						continue;
					}
					if (isContain(nNin, wkList, i, syokuNum)) {
						result++;
					}
					alreadyFinishList.add(syokuNum);
				}

			}
			System.out.println(result);

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private boolean isContain(int nNin, List<List<Integer>> wkList, int i, int syokuNum) {
		int result = 0;
		for (int j = 0; j < nNin; j++) {
			if (i == j || j >= wkList.size()) {
				continue;
			}

			List<Integer> wkSarchList = wkList.get(j);
			if (wkSarchList.contains(syokuNum)) {
				result++;
			}

		}
		return result == nNin - 1;
	}

	private void solveC() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}

	private void solveD() {
		Scanner scanner = null;
		int lineAB = 0;
		int lineBC = 0;
		int lineCA = 0;

		try {
			scanner = new Scanner(System.in);
			lineAB = scanner.nextInt();

			System.out.println("");

		} finally {
			if (scanner != null) {
				scanner.close();
			}
		}
	}
}

Measured memory_bytes: 23380
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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")
    };
}

fn main() {
    input! {
        n: i64,
    }
    if n == 0 {
        println!("0");
        return;
    }
    let mut digits = Vec::new();
    let mut q = n;
    while q != 0 {
        match q % -2 {
            0 => {
                digits.push('0');
                q /= -2;
            },
            1 => {
                digits.push('1');
                q /= -2;
            },
            -1 => {
                digits.push('1');
                q = (q-2)  / -2;
            },
            _ => panic!(),

        }
    }
    println!("{}", digits.into_iter().rev().collect::<String>());
}

Measured memory_bytes: 4352
package main

import "fmt"

func min(a, b int) int {
	if a >= b {
		return b
	}
	return a
}

func main() {
	var a, b, c int
	fmt.Scan(&a, &b, &c)
	fmt.Println(min(a+b, min(b+c, c+a)))
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
int arr[100001];
int row[100001];
int main()
{
  int n,m,c;
  cin>>n>>m>>c;
  int cc=0;
  for(int i=0; i<m; i++)
  {
      cin>>arr[i];
  }
  for(int i=0; i<n; i++)
  {
      int sum=0;
      for(int j=0; j<m; j++)
      {
          int x;
          cin>>x;
          sum+=x*arr[j];
      }
      sum+=c;
      if(sum>0)cc++;
  }
  cout<<cc<<endl;
}


Measured memory_bytes: 256