akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;



int p[11] = {};
int can[11] = {};
int m;

int check(int t){
	if( t < 4 ) return true;
	//if( t == 4 ) return (p[1]+p[4]+p[7]) % p[9] == 0;
	int c = (p[1]+p[4]+p[7]) % p[9];
	if( t == 5 ) return (p[0]+p[4]+p[8]) % p[9] == c;
	if( t == 6 ) return (p[0]+p[1]+p[2]) % p[9] == c;
	if( t == 7 ) return (p[2]+p[5]+p[8]) % p[9] == c;
	if( t == 8 ) return (p[6]+p[7]+p[8]) % p[9] == c && (p[2]+p[4]+p[6]) % p[9] == c;
	if( t == 9 ) return (p[0]+p[3]+p[6]) % p[9] == c && (p[3]+p[4]+p[5]) % p[9] == c;
	return true;
}
//

int d[] = {9,0,1,4,7,8,2,5,6,3};

int solve(int t){
	/*cout << t << endl;
	cout << "[" << p[9] << "]" << endl;
	for(int i = 0 ; i < 3 ; i++){
		for(int j = 0 ; j < 3 ; j++) cout << p[i*3+j] << " ";
		cout << endl;
	}
	*/
	if( !check(t-1) ) return 0;
	if( t == 10 ){
		return 1;
	}
	int x = d[t];
	if( p[x] == 0 ){
		int ans = 0;
		for(int i = 1 ; i <= 10 ; i++){
			if( can[i] ){
				can[i] = false;
				p[x] = i;
				ans += solve(t+1);
				p[x] = 0;
				can[i] = true;
			}
		}
		return ans;
	}else{
		return solve(t+1);
		
	}
}

int main(){
	while(1){
		for(int i = 0 ; i < 11 ; i++) can[i] = true;
		
		for(int i = 0 ; i < 10 ; i++){
			cin >> p[i];
			can[p[i]] = false;
		}
		if(p[0]==-1)break;
		cout << solve(0) << endl;
	}
}

Measured memory_bytes: 1160
#include <stdio.h>
#include <stdlib.h>
int cmpint(const void* x, const void* y) { return *(int*)x - *(int*)y; }
int main() {
	int n, a[200000][2], time = 0;
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i][1], &a[i][0]);
	}
	qsort(a, n, sizeof(a[0]), cmpint);
	for (int i = 0; i < n; i++) {
		time += a[i][1];
		if (time > a[i][0]) {
			printf("No\n");
			return 0;
		}
	}
	printf("Yes\n");
	return 0;
}

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

using namespace std;

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

  int x, y;
  cin >> x >> y;
  map<int, int> get;
  get[1] = 300000, get[2] = 200000, get[3] = 100000;
  cout << get[x] + get[y] + (x == 1 and y == 1) * 400000;

  return 0;
}

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

typedef long long ll;
using namespace std;

int n;
vector<int> children[100001];

int dfs(int root) {
    int size = children[root].size();
    if (size == 0) return 0;
    // mx, mn以外にも注目しなきゃいけない？
    vector<int> rets;
    for (auto &ch : children[root]) {
        int ret = dfs(ch);
        rets.push_back(ret);
    }
    int ret = -1;
    sort(rets.begin(), rets.end());
    reverse(rets.begin(), rets.end());
    for (int i = 1; i <= size; i++) {
        ret = max(ret, rets[i-1] + i);
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    for (int i = 2; i <= n; i++) {
        int a; cin >> a;
        children[a].push_back(i);
    }
    cout << dfs(1) << endl;
    return 0;
}


Measured memory_bytes: 15104
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 1e18
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int grid[21][21] = {};
int w, h;
int dfs(int now_x, int now_y,int k) {
	if (k >= 10) return -1;
	int xe[4] = { 1,-1,0,0 };
	int ye[4] = { 0,0,1,-1 };
	int now_ans = 20;
	for (int q = 0; q < 4; ++q) {
		for (int j = 1; j >= 0; ++j) {
			int next_x = j * xe[q] + now_x;
			int next_y = j * ye[q] + now_y;
			if (next_x >= 0 && next_x < h && next_y >= 0 && next_y < w) {
				if (grid[next_x][next_y] == 3) {
					return 1;
				}
				else if (grid[next_x][next_y] == 1) {
					if (j != 1) {
						grid[next_x][next_y] = 0;
						int go_x = next_x - xe[q];
						int go_y = next_y - ye[q];
						int hoge = dfs(go_x, go_y, k + 1);
						if (hoge != -1) {
							now_ans = min(now_ans, hoge);
						}
						grid[next_x][next_y] = 1;
					}
					break;
				}
			}
			else break;
		}
	}
	if (now_ans == 20) {
		return -1;
	}
	return now_ans+1;
}
int main() {
	while (true) {
		cin >> w >> h;
		if (w == 0) return 0;
		int start_x = 0;
		int start_y = 0;
		REP(i, h) {
			REP(q, w) {
				cin >> grid[i][q];
				if (grid[i][q] == 2) {
					start_x = i;
					start_y = q;
					grid[i][q] = 0;
				}
			}
		}
		cout << dfs(start_x, start_y, 0) << endl;
	}
}


Measured memory_bytes: 3024
#include <bits/stdc++.h>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << H << " ";
    debug_out(T...);
}
#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...) 
#endif
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
    for (std::size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
    return os;
}
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const ll mod = 1000000007;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(a<=b) cout << "unsafe" << endl;
    else cout << "safe" << endl;
}

Measured memory_bytes: 3648
import  numpy as np


def divisors(num):
    array = []
    limit = int(num ** 0.5) + 1
    for i in range(1, limit):
        if num % i == 0:
            div1 = i
            div2 = num//i
            array.append(div1)
            if div1 != div2:
                array.append(div2)
    array.sort(reverse=True)
    return array


n, k = map(int, input().split())
A = np.array(list(map(int, input().split())), dtype=int)

total = sum(A)
candidates = divisors(total)


for div in candidates:
    mods = A % div
    mods.sort()
    subcum = np.cumsum(mods)
    idx = subcum[n-1] // div
    count = subcum[-1-idx]
    if count <= k:
        print(div)
        exit()

Measured memory_bytes: 21268
import sys
readline = sys.stdin.readline

N,K = map(int, readline().split())
A = list(map(int,readline().split()))
DIV = 10 ** 9 + 7

# dp[i][j] : i人目までにj個配るときの場合の数
# dp[i][j] = dp[i - 1][j] + dp[i - 1][j - 1] + ... + dp[i - 1][j - A[i - 1]]
# j に j - 1を代入
# dp[i][j - 1] = dp[i - 1][j - 1] + dp[i - 1][j - 2] + ... + dp[i - 1][j - A[i - 1] - 1]
# 上から下を引く
# dp[i][j] - dp[i][j - 1] = dp[i - 1][j] - dp[i - 1][j - A[i - 1] - 1]
# dp[i][j] = dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - Ai-1 - 1]

dp = [[0] * (K + 1) for i in range(N + 1)]
for i in range(N + 1):
  dp[i][0] = 1 # 0個配る方法は常に1通り
  
for i in range(1, N + 1):
  for j in range(1, K + 1):
    if j - A[i - 1] - 1 >= 0: # j個配れる場合 (j >= A[i - 1] + 1)
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1] - dp[i - 1][j - A[i - 1] - 1]) % DIV
    else:
      dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % DIV
      
print(dp[N][K])

Measured memory_bytes: 146576
from math import factorial as fac

N, K = map(int, input().split())


def func(n, k, r):
    return (fac(k - 1) * fac(n - k + 1) // (fac(k - r) * fac(r - 1) * fac(n - k - r + 1) * fac(r)))


for i in range(1, K + 1):
    if N-K+1>=i:
        print(func(N, K, i) % (10 ** 9 + 7))
    else:
        print(0)



Measured memory_bytes: 63192
import std.stdio;
import std.conv;
import std.string;
import std.typecons;
import std.algorithm;
import std.array;
import std.range;
import std.math;
import std.container;
import std.datetime;

void main()
{
	auto path = new int[][](5, 5);
	auto key = [' ', 'U', 'L', ' ', 'D', ' ', ' ', ' ', 'R'];
	auto dx = [0, 0, -1, 0, 0, 0, 0, 0, 1];
	auto dy = [0, -1, 0, 0, 1, 0, 0, 0, 0];
	foreach (i; 0..5) {
		auto x = readln.chomp;
		foreach (j, e; x) {
			if (e == '1') {
				path[i][j] |= 8;
				path[i][j+1] |= 2;
			}
		}
		if (i == 4) continue;
		auto y = readln.chomp;
		foreach (j, e; y) {
			if (e == '1') {
				path[i][j] |= 4;
				path[i+1][j] |= 1;
			}
		}
	}

	int x = 1, 
			y = 0, 
			dir = 8;
	write("R");
	while (x != 0 || y != 0) {
		auto d = dir << 1;
		if (d == 16) d = 1;
		if (path[y][x] & d) {
			x += dx[d];
			y += dy[d];
			write(key[d]);
			dir = d;
			continue;
		}
		d = dir;
		if (path[y][x] & d) {
			x += dx[d];
			y += dy[d];
			write(key[d]);
			continue;
		}
		d = dir >> 1;
		if (d == 0) d = 8;
		if (path[y][x] & d) {
			x += dx[d];
			y += dy[d];
			write(key[d]);
			dir = d;
			continue;
		}
		d = d >> 1;
		if (d == 0) d = 8;
		x += dx[d];
		y += dy[d];
		write(key[d]);
		dir = d; 
	}
	writeln("");
}

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

int main() {
    int N, M;
    while(cin >> N >> M, N) {
        vector<int> P(N+1);
        for(int i=0; i<N; ++i) {
            cin >> P[i];
        }
        P[N] = 0;
        vector<int> v;
        for(int i=0; i<N+1; ++i) {
            for(int j=0; j<N+1; ++j) {
                v.push_back(P[i] + P[j]);
            }
        }
        sort(v.begin(), v.end());
        v.erase(unique(v.begin(), v.end()), v.end());
        int res = 0;
        for(int i=0; i<v.size(); ++i) {
            if(v[i] > M) {
                break;
            }
            res = max(res, v[i] + *(upper_bound(v.begin(), v.end(), M-v[i])-1));
        }
        cout << res << endl;
    }
}


Measured memory_bytes: 10660
S = list(input())
T = list(input())
s = len(S)
t = len(T)
for i in range(s-t,-1,-1):
    ss = S[i:i+t]
    for j in range(t):
        if ss[j] != "?" and ss[j] != T[j]:
            break
    else:
        for j in range(t):
            if ss[j] == "?":
                S[i+j] = T[j]
        break
else:
    print("UNRESTORABLE")
    exit()
for i in range(s):
    if S[i] == "?":
        S[i] = "a"
print("".join(S))

Measured memory_bytes: 9020
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll mod = 998244353;
const ll INF = 1000000000000000;
ll N, T, A[3010], B[3010], dp[3010], ans, tim[3010], score[3010];
vector<P> vec;

ll pow(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return pow(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = pow(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll pow_ll(ll x, ll y)
{
	if (y == 0) return 1;
	return x * pow_ll(x, y - 1);
}

ll div(ll x)
{
	return pow(x, mod - 2);
}



int main(void)
{
	cin >> N;

	cout << N * N << endl;

	int xxx;
	cin >> xxx;
}


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

int main() {
    int n;
    cin >> n;
    // dp[heads]
    // if we had i tosses, then tails=i-heads
    vector<double> dp(n + 1);
    // dp[i] - p-bility that there are i heads so far
    dp[0] = 1;
    for(int coin = 0; coin < n; ++coin) {
        double p_heads;
    
        cin >> p_heads;
        for(int i = coin + 1; i >= 0; --i) {
            dp[i] = (i == 0 ? 0 : dp[i-1] * p_heads) + dp[i] * (1 - p_heads);
        }
    }
    double answer = 0;
    for(int heads = 0; heads <= n; ++heads)
     {
        int tails = n - heads;
        if(heads > tails) 
            answer += dp[heads];
        
    }
   cout<< setprecision(16) << answer;
}

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

int a[11451419];
int b[11451419] = {};

int main(){
    int n;


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

    for(int i=2;i<=n;i++){
        b[ a[i] ]++;
    }
    
    for(int i=1;i<=n;i++){
        cout << b[i] << endl;
    }

    return 0;
}

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

from math import atan,degrees

# 面積にする
X=x/a

if X < a*b/2:
    d = 2*X/b
    print(degrees(atan(b/d)))
else:
    d = (X-a*b/2) /a*2
    print(degrees(atan( (b-d)/a)))

Measured memory_bytes: 3060
from sys import stdout
printn = lambda x: stdout.write(str(x))
inn = lambda : int(input())
inl   = lambda: list(map(int, input().split()))
inm   = lambda:      map(int, input().split())
ins = lambda : input().strip()
DBG = True # and False
BIG = 999999999
R = 10**9 + 7

def ddprint(x):
  if DBG:
    print(x)

n = inn()
a = inl()
for i in range(n):
    x = a[i]
    if x%2==0 and x%3!=0 and x%5!=0:
        print('DENIED')
        exit()
print('APPROVED')


Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> iint;
typedef pair<ll,ll> llll;
#define ALL(x) (x).begin(),(x).end()
const ll zero = 0;
const ll one = 1;
const ll INF = 9223372036854775807; //10^18
const int inINF = 2147483647; //10^9
const ll MOD = 1000000007; //10^9+7
const ll MOD2 = 998244353;
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int main(){
    int N;
    cin >> N;
    ll a;
    map<ll, int> A;
    for (ll i = 0; i < N; i++) {
        cin >> a;
        if(A.count(-a)){
            A[-a]++;
        }
        else{
            A[-a] = 1;
        }
    }
    int ans = 0;
    int tmp;
    for (auto v : A){
        ll w = v.first;
        for (int k = 30; k >= 1; k--) {
            if(A.count(-(w + (1<<k)))){
                if(-(w + (1<<k)) == w){
                    tmp = A[w] / 2;
                    ans += tmp;
                    A[w] -= tmp * 2;
                    continue;
                }
                tmp = min(A[-(w + (1<<k))], A[w]);
                ans += tmp;
                A[-(w + (1<<k))] -= tmp;
                A[w] -= tmp;
            }
        }
    }
    printf("%d\n", ans);


}

Measured memory_bytes: 16216
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int main()
{
//	printf("123");
	long long  a[100005],n,sum=0,min;
	int count=0;
	scanf("%lld",&n);
	//printf("%lld",n);
	for(int i=0;i<n;i++)
	{
		scanf("%lld",&a[i]);
	}
	for(int i=0;i<n;i++)
	{
		if(a[i]<0) count++;
	}
	for(int i=0;i<n;i++)
		{
			sum+=abs(a[i]);
		}
	if(count%2==0)
	{
		printf("%lld",sum);
	}else{
		min=abs(a[0]);
		for(int i=1;i<n;i++)
		{
			if(abs(a[i])<min) min=abs(a[i]);
		}
		sum=sum-2*min;
		printf("%lld",sum);
	}
}

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

int main()
{
    int N;
    cin >> N;
    vector<int> c(4);
    rep(i, N)
    {
        string s;
        cin >> s;
        if (s == "AC")
            c[0]++;
        else if (s == "WA")
            c[1]++;
        else if (s == "TLE")
            c[2]++;
        else
            c[3]++;
    }
    cout << "AC x " << c[0] << endl;
    cout << "WA x " << c[1] << endl;
    cout << "TLE x " << c[2] << endl;
    cout << "RE x " << c[3] << endl;

    return 0;
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <stdlib.h>
int compare(const void *a,const void *b){
    return *(int*)b-*(int*)a;
}
int main(){
    int n,i,r=0,t=1;
    int arr[999];
    scanf("%d",&n);
    for(i=0;i<n;i++)scanf("%d",&arr[i]);
    qsort(arr,n,4,compare);
    for(i=0;i<n;i++){
        r+=t*arr[i];
        t=-t;
    }
    printf("%d\n",r);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int n,q[1010],p[1010],r=1,rr=1,t=0,i,j,c=0,d[1010][1010],e[1010]={};
  int m[1010];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      scanf("%d",&d[i][j]);
      d[i][j]--;
    }
  }
  for(i=0;i<n;i++){
    e[i]=0;
    q[r++]=i;
  }
  for(i=c=0;c<n;i++){//printf("c%d %d\n",c,r);
    if(rr==0){
      printf("-1\n");
      return 0;
    }
    for(j=0;j<n;j++)m[j]=0;
    for(t=rr=0;t<r;t++){//printf("r%d\n",r);
      j=d[q[t]][e[q[t]]];//printf("!%d %d %d %d\n",q[t],j,m[q[t]],m[j]);
      if(m[q[t]]||m[j])continue;
      if(q[t]==d[j][e[j]]){
	e[q[t]]++;
	m[q[t]]=1;
	if(e[q[t]]==n-1)c++;
	else p[rr++]=q[t];
	e[j]++;
	m[j]=1;
	if(e[j]==n-1)c++;	
	else p[rr++]=j;
      }
    }
    //for(j=0;j<n;j++)printf("%d ",e[j]);printf("!!\n");
    for(j=0;j<rr;j++)q[j]=p[j];
    r=rr;
  }
  printf("%d\n",i);
  return 0;
}


Measured memory_bytes: 4096
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

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

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

fn main() {
    input! {
        n: usize,
        x: usize,
        l: [usize; n],
    }
    let mut d = vec![0; n + 1];
    for i in 1..n + 1 {
        d[i] = d[i - 1] + l[i - 1];
    }
    let ans = d.iter().filter(|item| **item <= x).count();
    println!("{}", ans);
}


Measured memory_bytes: 4352
var input = ''

process.stdin.resume()
process.stdin.setEncoding('utf8')
process.stdin.on('data', function(chunk) {
  input += chunk
})
process.stdin.on('end', function() {
  input = input.split('\n')
  main()
})

function main() {
    input.sort(function(a, b) {
        return (parseInt(a) < parseInt(b)) ? 1 : -1;
});
console.log(input[0])
console.log(input[1])
console.log(input[2])
}


Measured memory_bytes: 15528
#%%
n, u, v = map(int, input().split())
u, v = u-1, v-1
reach = [[] for _ in range(n)]
for i in range(n-1):
    a, b = map(lambda x: int(x)-1, input().split())
    reach[a].append(b)
    reach[b].append(a)

def x_route(x, reach):
    x_route = [[-1, -1] for _ in range(n)]
    check = [0] * n
    stack = [x]
    check[x] = 1
    x_route[x] = [-1, 0]
    while len(stack) > 0:
        tmp = stack.pop(-1)
        tmp_list = reach[tmp]
        for i in tmp_list:
            if check[i] == 1:
                pass
            else:
                stack.append(i)
                check[i] = 1
                x_route[i] = [tmp, x_route[tmp][1]+1] 
    return x_route

a_route = x_route(v, reach)
t_route = x_route(u, reach)
ans = 0
for i in range(len(a_route)):
    if t_route[i][1] < a_route[i][1]:
        ans = max(ans, a_route[i][1]-1)

print(ans)

Measured memory_bytes: 49240
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0180
// PCK2008yosen-08
// パソコン甲子園・・・チームrand()・・・うっ・・・高校時代も今もあいつらとは目を合わせないように生きてきたんだ・・・

#include <cstdio>
#include <algorithm>
using namespace std;

struct bridge {
	int a;
	int b;
	int cost;
	
	bool operator < ( const bridge& com ) const {
		return (this->cost < com.cost);
	};
};

int root[110];
bridge br[10010];

int getroot(int city) {
	if ( root[city] == city ) {
		return city;
	}
	root[city] = getroot(root[city]);
	return root[city];
}

int main(void) {
	
	while(true) {
		int n, m;
		scanf("%d %d", &n, &m);
		if ( n == 0 ) { return 0; }
		for(int i=0; i<m; i++) {
			scanf("%d %d %d", &br[i].a, &br[i].b, &br[i].cost);
		}
		
		sort(br, br+m);
		
		for(int i=0; i<n; i++) {
			root[i] = i;
		}
		
		int total = 0;
		for(int i=0; i<m; i++) {
			if ( getroot(br[i].a) == getroot(br[i].b) ) { continue; }
			
			// 橋を追加
			total += br[i].cost;
			int ra = getroot(br[i].a);
			int rb = getroot(br[i].b);
			root[ra] = rb;
			
			int j;
			for(j=1; j<n; j++) {
				if (getroot(j) != getroot(0)) {
					break;
				}
			}
			/*
			for(int aa=0; aa<n; aa++) {
				printf("%d ", root[aa]);
			}
			printf("\n");
			*/
			if ( j == n ) { break; }
		}
		
		printf("%d\n", total);
	}

}

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

int dp[100005];
vector<int> grph[100005];
int vis[100005]={0};
int n,m;

int dfs(int a)
{
    if(dp[a]!=-1)
        return dp[a];
    if(vis[a]==0)
    {
        vis[a]=1;
        int ma=0;
        int &ans=dp[a];
        ans=0;
        for(auto &k:grph[a])
            ans=max(ans,dfs(k) + 1);
        return ans;
    }
}

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    memset(dp,-1,sizeof(dp));
    cin>>n>>m;
    for(int i=0;i<m;i++)
    {
        int x;
        int y;
        cin>>x>>y;
        grph[x].push_back(y);
    }
    int soln=0;
    for(int i=1;i<=n;i++)
        if(!vis[i])
            soln=max(soln,dfs(i));
    cout<<soln;
} 

Measured memory_bytes: 12672
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007LL

typedef long long ll;
typedef pair<ll,ll> P;

long long mod_div(long long a,long long b){
	long long tmp = MOD - 2,c = b,ret = 1;
	while(tmp > 0){
		if(tmp & 1){
			ret *= c;ret %= MOD;
		}
		c *= c;c %= MOD;tmp >>= 1;
	}
	return a*ret%MOD;
}

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

	ll n, k;cin >> n >> k;
	vector<P> pla;
	vector<P> mai;

	REP(i, n){
		ll a;cin >> a;
		if(a > 0)pla.EB(abs(a), a);
		else mai.EB(abs(a), a);
	}

	if(k % 2 == 1 && pla.size() == 0){
		sort(ALL(mai));
		ll ans = 1;
		REP(i, k){
			ans = ans * ((MOD * MOD - mai[i].FI) % MOD) % MOD;
		}
		cout << ans << endl;
		return 0;
	}

	sort(ALL(pla), greater<P>());
	sort(ALL(mai), greater<P>());

	ll ans = 1;
	ll cou = 0;
	ll a = 0;
	ll b = 0;

	//REP(i, pla.size())cout << pla[i].SE << " ";cout << endl;
	//REP(i, mai.size())cout << mai[i].SE << " ";cout << endl;

	while(cou < k){
		ll ma_id = min(2LL, k - cou);
		ll a_ma_id = min(ma_id, (ll)pla.size() - a);
		ll b_ma_id = min(ma_id, (ll)mai.size() - b);

		ll A = -LLINF;
		if(a_ma_id > 0)A = pla[a].FI;
		if(a_ma_id > 1)A *= pla[a+1].FI;

		ll B = -LLINF;
		if(b_ma_id > 0)B = mai[b].SE;
		if(b_ma_id > 1)B *= mai[b + 1].SE;

		if(A <= B){
			ans = ans * ((MOD * MOD + B) % MOD) % MOD;
			b += b_ma_id;
			cou += b_ma_id;
		}
		else {
			ans = ans * (A % MOD) % MOD;
			a += a_ma_id;
			cou += a_ma_id;
		}

		//cout << "now: " << a << " " << b << endl;
	}

	//cout << ans << endl;

	if(b + 1 < mai.size() && 1 < a && pla[a-2].FI * pla[a-1].FI < mai[b].FI * mai[b+1].FI){
		ans = mod_div(ans, pla[a-2].FI * pla[a-1].FI % MOD);
		ans = ans * (mai[b].FI * mai[b+1].FI % MOD) % MOD;
		a -= 2;
		b += 2;
	}

	//cout << "now: " << a << " " << b << endl;
	cout << ans << endl;

	return 0;
}


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()
#define endl "\n"

using ll = long long;
using P = pair<int,int>;
using mp =  map<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;

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

    ll n, k;
    cin >> n >> k;
    vector<ll> v(1e5+5);

    int ans;
    rep(i, n){
        int a, b;
        cin >> a >> b;

        v[a] += b;
    }

    rep(i, 1e5+5){
        if(k <= v[i]){
            ans = i;
            break;
        }
        k -= v[i];
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 1024
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <bitset>

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(a) (a).begin(), (a).end()

int main() {
    int X, A, B;
    cin >> X;
    cin >> A;
    cin >> B;

    X -= A;
    cout << X % B;
}

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

using namespace std;

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;
    cout << (char)toupper(s1[0]);
    cout << (char)toupper(s2[0]);
    cout << (char)toupper(s3[0]);
    cout << endl;

    return 0;
}

Measured memory_bytes: 892
s = list(input())
n = len(s)
ans = 1
cur = s[0]
i = 1

while (i < n):
	if s[i] != cur:
		ans += 1
		cur = s[i]
		i += 1
	else:
		if (i + 2) > n:
			break
		else:
			cur = s[i:i+2]
			ans += 1
			i += 2

print(ans)

Measured memory_bytes: 4840
#include<bits/stdc++.h>
using namespace std;
#define inf 0x3f3f3f3f
#define ll long long
const int N=200005;
const int mod=1e9+7;
const double eps=1e-8;
const double PI = acos(-1.0);
#define lowbit(x) (x&(-x))
ll gcd(ll a,ll b){return b==0?a:gcd(b,a%b);}
ll qpow(ll a,ll b){ll res=1;while(b){if(b&1) res=res*a%mod;a=a*a%mod;b>>=1;}return res;}
ll inv(ll a,ll p){return qpow(a,p-2);}
int main()
{
    std::ios::sync_with_stdio(false);
    ll n,x;
    while(cin>>n>>x)
    {
       ll a[N],ans=0;
       for(int i=1;i<=n;i++)
            cin>>a[i];
       for(int i=2;i<=n;i++)
       {
           if(a[i]+a[i-1]>x)
           {
               int t=a[i]+a[i-1]-x;
               ans+=t;
               if(t>a[i])
               {
                   a[i]=0;
                   a[i-1]-=(t-a[i]);
               }
               else
                a[i]-=t;
           }
       }
       cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 1024
def resolve():
    N, M, K = list(map(int, input().split()))
    A = list(map(int, input().split()))
    B = list(map(int, input().split()))
    def isok(num):
        if num >= N:
            anum = N
            bnum = num-anum
        else:
            anum = num
            bnum = 0
        atotal = sum(A[:anum])
        btotal = sum(B[:bnum])
        if atotal + btotal <= K:
            return True
        i = 0
        while not (anum-1-i < 0 or bnum+i >= M):
            atotal -= A[anum-1-i]
            btotal += B[bnum+i]
            if atotal + btotal <= K:
                return True
            i += 1
        return False
    
    left = -1
    right = N+M+1
    while (right - left) > 1:
        mid = left + (right - left)//2
            
        if isok(mid):
            left = mid
        else:
            right = mid
    print(left)


if '__main__' == __name__:
    resolve()

Measured memory_bytes: 160612
#include <iostream>
#include<set>
#include<vector>
#include<string>
#include<iterator>
#include<iomanip>
#include<cmath>
#include<map>
#include<string.h>
#include<algorithm>

using namespace std;
void ll(){
	std::ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(0);
}

int main() {

	ll();
	
	string n;
	cin >> n;

	if ((n[0] == n[1] && n[1] == n[2]) || (n[0] == n[1] && n[1] == n[2] && n[2] == n[3]) || (n[1] == n[2] && n[2] == n[3]) )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
}

Measured memory_bytes: 3652
# define _CRT_SECURE_NO_WARNINGS 1
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <climits>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
//# define M_PI 3.141592
# define INF ((int)(1<<30))
# define FOR(i,n) for(int i=0;i<(int)n;i++)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define toRad 2.0*M_PI/360.0
# define inin(x) int x;cin>>x;
# define all(x) x.begin(),x.end()
# define debug(x) cout<<#x<<" :"<<x<<endl;
# define rep(i,n) for(int i=0;i<(int)n;i++)
# define EPS 1e-12
# define CHECK(i,a) FOR(i,a.size())cout<<#a<<"["<<i<<"] : "<<a[i]<<endl; 
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
int dx[4] = { 0,-1,1,0 }, dy[4] = { 1,0,0,-1 };

int a[21000];
int main()
{
	int n, m;
	while (cin >> n >> m&&n)
	{
		memset(a, 0, sizeof a);
		a[1] = 1;
		vector<piii> v;
		FOR(i, m)
		{
			piii x;
			cin >> x.first >> x.second.first >> x.second.second;
			v.push_back(x);
		}
		sort(all(v));
		FOR(i, m)
		{
			a[v[i].second.second] += a[v[i].second.first];
		}
		int ans = 0;
		FOR(i, n + 1)if (a[i])ans++;
		cout << ans << endl;
	}
}

Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mset(x, y) memset((x), (y), sizeof(x))
#define sz(x) ((int)(x).size())
#define rep(i, a, b) for(i = a; i < b; i++)
#define per(i, a, b) for(i = a; i >= b; i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define cerr cout
#define endl '\n'
using namespace std;

string to_string(string s) { return '"' + s + '"';}
string to_string(char s) { return string(1, s);}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A> string to_string(A);
template <typename A, typename B>string to_string(pair<A, B> p) {return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";}
template <typename A> string to_string(A v) {bool f = 1; string r = "{"; for (const auto &x : v) {if (!f)r += ", "; f = 0; r += to_string(x);} return r + "}";}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail> void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#define pr(...) cerr << "[" << #__VA_ARGS__ << "] :", debug_out(__VA_ARGS__)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
const ld eps = 1e-7;
const ll mod = 1000000007;
const ll N = 998244353;

ll binpow(ll b, ll p){ ll ans = 1; while(p > 0){if(p & 1) ans = (ans * b) % mod; b = (b * b) % mod; p >>= 1;}return ans;}
ll modinv(ll x){return binpow(x, mod - 2);}

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

	int n, x, t;
	cin >> n >> x >> t;
	cout << ((n + x - 1) / x) * t;
}

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

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

int main() {
  long a,b;
  cin >> a >> b;
  long long ans = (a*b)/gcd(a,b);
  cout << ans << endl;
}


Measured memory_bytes: 256
// in the name of Allah

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

#define endl '\n'
#define pb push_back
#define ll long long
#define double long double
#define sz(x) ((int) (x.size()))

#define fr first
#define se second

#define inf 1e9
#define max_n 123456
#define mod 1000000007

ll add(ll a, ll b) {
	a += b;
	if(a >= mod) return a - mod;
	return a;
}

ll mul(ll a, ll b) {
	a *= b;
	if(a >= mod) return a % mod;
	return a;
}

ll power(ll a, ll b) {
	ll p = 1;
	while(b) {
		if(b&1) p = mul(p, a);
		a = mul(a, a);
		b /= 2;
	}
	return p;
}

int n;
ll dp[1<<16];
int a[16][16];
ll cost[1<<16];
vector <int> g[1<<16];

ll memo(int msk) {
	if(msk == 0) return 0;
	if(dp[msk] != -1) return dp[msk];
	vector <int> v;
	for(int i=0; i<n; i++) if((msk&(1<<i)) > 0) v.pb(1<<i);
	ll res = 0;
	auto go = [&msk, &res, &v] (int MSK, int idx, auto &func) mutable {
		if(idx == sz(v)) {
			if(MSK > 0) res = max(res, cost[MSK] + memo(msk^MSK));
			return;
		}
		func(MSK, idx+1, func);
		func(MSK|v[idx], idx+1, func);
	};
	go(0, 0, go);
	return dp[msk] = res;
}

int main() {
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n;
	for(int i=0; i<n; i++) for(int j=0; j<n; j++) cin >> a[i][j];
	vector <int> v;
	for(int msk=0; msk<(1<<n); msk++) {
		v.clear();
		cost[msk] = 0;
		for(int i=0; i<n; i++) if((msk&(1<<i)) > 0) v.pb(i);
		for(int i=0; i<sz(v); i++) {
			for(int j=i+1; j<sz(v); j++) {
				cost[msk] += a[v[i]][v[j]];
			}
		}
	}
	memset(dp, -1, sizeof dp);
	cout << memo((1<<n)-1) << endl;
	return 0;
}

Measured memory_bytes: 2816
#include <bits/stdc++.h>
#define int long long

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)a, i##_len=(b); i<i##_len; i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

#define all(box) box.begin(), box.end()

using namespace std;

using P = pair<int,int>;
using ll = long long;

const long long INF = LLONG_MAX/3;

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

struct UnionFind{
	std::vector<int> par,siz;
	void init(int n){
		par.resize(n);
		for(int i=0;i<n;i++)par[i]=i;
		siz.resize(n,1);
	}
	UnionFind(int n){
		init(n);
	}
	int root(int n){
		if(par[n]==n)return n;
		else return par[n]=root(par[n]);
	}
	bool issame(int x,int y){
		return (root(x)==root(y));
	}
	bool marge(int a,int b){
		if(issame(a,b))return false;
		else{
			a=root(a),b=root(b);
			if(siz[a]<siz[b])swap(a,b);
			siz[b]+=siz[a];
			par[a]=par[b];
			return true;
		}
	}
	int size(int n){
		return siz[root(n)];
	}
};

long long gcd(long long a,long long b){
    if(b==0)return a;
    return gcd(b,a%b);
}
long long lcm(long long i,long long j){
    return i*(j/gcd(i,j));
}

const int MOD=998244353;
long long fac[510000], finv[510000], inv[510000];
long long MAX=510000;
bool COMinited=false;
long long COM(int n, int k){
	if(COMinited==false){
		fac[0] = fac[1] = 1;
    	finv[0] = finv[1] = 1;
    	inv[1] = 1;
    	for (int i = 2; i < MAX; i++){
        	fac[i] = fac[i - 1] * i % MOD;
        	inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        	finv[i] = finv[i - 1] * inv[i] % MOD;
    	}
		COMinited=true;
	}
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}
template< typename T >
struct BinaryIndexedTree {
  vector< T > data;

  BinaryIndexedTree(int sz) {
    data.assign(++sz, 0);
  }

  T sum(int k) {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x) {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};
signed main(){
	int a,b,c;
	cin>>a>>b>>c;
	if(c-a-b<0){
		cout<<"No"<<endl;
		return 0;
	}
	if(a*b*4<(c-a-b)*(c-a-b))cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.util.*;

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

    String s = sc.next();
    String t = sc.next();

    char[] c1 = s.toCharArray();
    char[] c2 = t.toCharArray();

    int l = c1.length;
    boolean flag = false;

    for(int i=0; i<=l-1; i++ ){
      int count = 0;
      for(int j=0; j<l; j++){
        if(c1[(j+i)%l] == c2[j]){
          count += 1;
        }else{
          break;
        }
      }
      if(count == l){
        flag = true;
        break;
      }
    }

    if(flag){
      System.out.println("Yes");
    }else{
      System.out.println("No");
    }
  }
}

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

int main(){
    int n;
    int64_t x[3];
    int s[100000];
    cin >> n >> x[0] >> x[1] >> x[2];
    for(int i=0;i<n;++i){
        string si;
        cin >> si;
        if(si == "AB") s[i] = 2;
        if(si == "BC") s[i] = 0;
        if(si == "AC") s[i] = 1;        
    }
    vector<int> ans;
    if(x[0] + x[1] + x[2] == 0){ cout << "No" << endl; return 0; }
    else if(x[0] + x[1] + x[2] == 1){
        for(int i=0;i<n;++i){
            if(x[s[i]] == 1){ cout << "No" << endl; return 0; }
            if(x[(s[i]+1)%3] == 0){ ans.push_back((s[i]+1)%3); x[(s[i]+1)%3] = 1; x[(s[i]+2)%3] = 0; }
            else{ ans.push_back((s[i]+2)%3); x[(s[i]+2)%3] = 1; x[(s[i]+1)%3] = 0; }
        }
    }else{
        for(int i=0;i<n;++i){
            if(x[s[i]] == x[0] + x[1] + x[2]){ cout << "No" << endl; return 0; }
            if(x[(s[i]+1)%3] == 0){
                ans.push_back((s[i]+1)%3);
                ++x[(s[i]+1)%3];
                --x[(s[i]+2)%3];
            }else if(x[(s[i]+2)%3] == 0){
                ans.push_back((s[i]+2)%3);
                ++x[(s[i]+2)%3];
                --x[(s[i]+1)%3];
            }else if(i + 1 < n && s[i] != s[i+1]){
                ans.push_back(3 - s[i] - s[i+1]);
                ++x[3 - s[i] - s[i+1]];
                --x[s[i+1]];
            }else{
                if(x[(s[i]+1)%3] < x[(s[i]+2)%3]){
                    ans.push_back((s[i]+1)%3);
                    ++x[(s[i]+1)%3];
                    --x[(s[i]+2)%3];
                }else{
                    ans.push_back((s[i]+2)%3);
                    ++x[(s[i]+2)%3];
                    --x[(s[i]+1)%3];
                }
            }
        }
    }
    cout << "Yes" << endl;
    for(int a: ans){
        cout << "ABC"[a] << endl;
    }

    return 0;
}

Measured memory_bytes: 4316
#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <algorithm>
using namespace std;
#define mp  std::make_pair
#define ll long long int
#define abs(n) ((n>0)?(n):((n)*(-1)))
#define CEIL(a,b) (((a) + ((b)-1)) / (b))
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
#define VREP(v) for(std::vector<ll>::iterator itr = (v).begin(); itr != (v).end();itr++)
#define VALL(v) ((v).begin(),(v).end())
#define errln(v) cerr << (v) << endl;
#define println(v) cout << (v) << endl;

int main(int argc, const char * argv[]) {
	int H,W;
	cin >> H >> W;
	string s;
	bool cell[H][W];
	REP(i,H){
		cin >> s;
		REP(j,W){
			cell[i][j] = (s[j]=='#');
		}
	}
	REP(i,H){
		REP(j,W){
			if(cell[i][j]){
				bool success = false;
				if(i>0) success |= cell[i-1][j];
				if(j>0) success |= cell[i][j-1];
				if(i<H-1) success |= cell[i+1][j];
				if(j<W-1) success |= cell[i][j+1];
				if(!success){
					println("No");
					return 0;
				}
			}
		}
	}
	println("Yes");

	return 0;

}


Measured memory_bytes: 256
import java.util.*;
 
// ABC 42-C
// http://abc042.contest.atcoder.jp/tasks/arc058_a
 
public class Main {
	
	public static void main (String[] args) throws java.lang.Exception {
	    Scanner in = new Scanner(System.in);
	    
	    int n = in.nextInt();
	    int k = in.nextInt();
	    HashMap<Integer, Integer> avoid = new HashMap<Integer, Integer>();
	    
	    for (int i = 0; i < k; i++) {
	    	avoid.put(in.nextInt(), 1);
	    }
	    
	    while (!isConditionMet(avoid, n)) {
	    	n++;
	    }
	    System.out.println(n);
	}
	
	public static boolean isConditionMet(HashMap<Integer, Integer> avoid, int n) {
		while (n > 0) {
			if (avoid.containsKey(n % 10)) {
				return false;
			}
			if (n == 0) {
				break;
			}
			n /= 10;
		}
		return true;
	}
}

Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <algorithm>
#include <cctype>
using namespace std;

int main() {
    int n, a[200000],x=0,y=0;
    cin >> n;
    for (int i = 0; i < n;i++) {
        cin >> a[i];
        if (a[i] > x) x = a[i];
        else if (a[i] > y) y = a[i];
    }
    for (int i = 0;i < n;i++) {
        if (a[i] == x) cout << y << endl;
        else cout << x << endl;
    }
    return 0;
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    ll N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    ll L = N / __gcd(N, M) * M;
    map<ll, char> X;
    ll d1 = L / N;
    ll d2 = L / M;
    for (int i = 0; i < S.size(); i++) {
        X[d1 * i] = S[i];
    }
    for (int i = 0; i < T.size(); i++) {
        if (X.find(d2 * i) != X.end()) {
            if (X[d2 * i] != T[i]) {
                cout << -1 << endl;
                return;
            }
        }
    }
    cout << L << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 6144
use std::io::*;
use std::str::FromStr;
 
/* 
The read function reads a string according to each one. 
*/
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char) 
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}


//main function
fn main() {
    let a:i64 = read();
    let b:i64 = read();
    let c:i64 = read();
    if a+b>=c{
	println!("Yes");
    }else{
	println!("No");
    }
}


Measured memory_bytes: 4352
import bisect
n = int(input())
a, b, c = map(list, [sorted(list(map(int, input().split()))) for i in range(3)])
ans = 0
for i in range(n):
    ans += bisect.bisect_left(a, b[i]) * (n - bisect.bisect_right(c, b[i]))
print(ans)

Measured memory_bytes: 28784
//皆さん、第9回シンデレラガール総選挙は、トップでオンリーワンを目指す城ヶ崎美嘉に
//そしてボイスアイドルオーディションは、プログラミングが趣味の才女大石泉に、ぜひ投票をお願いします！
//#城ヶ崎美嘉を009のシンデレラに
//#大石泉の必勝プログラム
#include<vector>
#include<cmath>
#include<map>
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<lint,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
vector<pint> v;
lint dp[2020][2020];
int n;
lint cal(int x,int y){
	if(dp[x][y]>=0) return dp[x][y];
	if(x==y) return abs(v[n-1].se-x)*v[n-1].fi;
	int i=x+n-1-y;
	lint ret=max(cal(x+1,y)+abs(v[i].se-x)*v[i].fi,cal(x,y-1)+abs(v[i].se-y)*v[i].fi);
	return dp[x][y]=ret;
}
int main()
{
	lint a;
	cin>>n;
	rep(i,n){
		cin>>a;v.pb(mp(a,i));
	}
	sort(All(v));reverse(All(v));
	memset(dp,-1,sizeof(dp));
	cout<<cal(0,n-1)<<endl;
}


Measured memory_bytes: 35636
from collections import Counter
N = int(input())
A = sorted(map(int, input().split()), reverse=True)

c = Counter(A)
check = 0
for i in range(N):
    if (c[A[i]] > 1):
        check += 1
if (check <= 1):
    print(0)
    exit()

L = []
for i, v in c.items():
    if (v > 3):
        L.append(i)
        L.append(i)
    elif (v > 1 and v <= 3):
        L.append(i)

L.sort(reverse=True)
print(L[0] * L[1])


Measured memory_bytes: 22384
#include<iostream>
using namespace std;
int main(){
long long int h,w;
  cin >> h >> w;
  if(h==1 || w==1){
  cout << 1 << endl;
  }else if(h*w%2==0){
  cout << h*w/2 << endl;
  }else{
  cout << h*w/2+1 << endl;
  }
}

Measured memory_bytes: 3624
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,a=0,b=0,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		if(i%2==0) a++;
		else b++;
	}
	printf("%d\n",a*b);
	return 0;
}


Measured memory_bytes: 1696
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>

using namespace std;
typedef long long ll;

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

	int ans = 0;
	for (int i = 0; i < s.size() / 2; i++) {
		if (s.at(i) != s.at(s.size() - 1 - i)) {
			ans++;
		}
	}

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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

typedef long long ll;

ll maxi(ll a, ll b)
{
    if (a > b)
        return a;
    return b;
}

ll mini(ll a, ll b)
{
    if (a < b)
        return a;
    return b;
}

int main()
{
    ios_base::sync_with_stdio(0);
    ll a, b, ab, x, y;
    cin >> a >> b >> ab >> x >> y;
    ll odp = 1000000000000;
    for (ll i = 0; i <= 1000000; i += 2)
    {
        ll ra = maxi(x - i / 2, 0);
        ll rb = maxi(y - i / 2, 0);
        odp = mini(odp, ab * i + ra * a + rb * b);
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
import sys
import itertools
import math

# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

while 1:
    H, W = map(int, readline().split())
    if H == 0 and W == 0:
        break
    else:
        for i in range(H):
            if i % 2 == 0:
                Y = ''
                for j in range(W):
                    if j % 2 == 0:
                        Y += '#'
                    else:
                        Y += '.'
                print(Y)

            else:
                Y = ''
                for j in range(W):
                    if j % 2 == 0:
                        Y += '.'
                    else:
                        Y += '#'
                print(Y)
    print()



Measured memory_bytes: 5712
#include<iostream>
#include<cstdio>
#include<map>
#include<algorithm>
#include<string>
#include<cstring>
using namespace std;
int main(){
	map<string,long long> mp;
	long long n;
	long long ans = 0;
	cin>>n;
	for(int i = 0; i < n; i++){
		string s;
		cin>>s;
		sort(s.begin(),s.end());
		mp[s]++; 
	}
	for(map<string,long long>::iterator it = mp.begin(); it != mp.end(); it++){
		long long num = it->second;
		ans+=(num*(num-1)/2);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 11136