akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define REP(i,n) for(int i=0;i<n;i++)
#define FORq(i, m, n) for(int i = m;i <= n;i++)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define PRINTD(n) printf("%d\n",n)
#define DEBUG printf("%s\n","debug")
using namespace std;
//////////////////////////////////////////////////////
int main(){
	int N,A,B;
	SCD(N);SCD(A);SCD(B);
	
	if((B-A)%2) printf("Borys\n");
	else printf("Alice\n");

	return 0;
}








Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(a + b < c + d) cout << "Right" << endl;
  else if(a + b > c + d) cout << "Left" << endl;
  else cout << "Balanced" << endl;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
cnt = [0] * (n+1)
for x in a: cnt[x] += 1
s = 0
for x in cnt: s += x * (x-1) // 2

for x in a:
    ans = s
    if cnt[x] >= 2: ans -= cnt[x]-1
    print(ans)


Measured memory_bytes: 24748
/*
 *  Created on: 24-May-2019
 *      Author: ankur314
 */
#include<bits/stdc++.h>
#define lli long long int 
#define li long int
#define db double 
#define ldb long double
#define vr vector 
#define it iterator
#define fi(i,a,n) for(int i=a;i<n;i++)
#define fli(i,a,n) for(long int i=a;i<n;i++)
#define flli(i,a,n) for(long long int i=a;i<n;i++)
#define pb(n) push_back(n)
#define ppf() pop_front()
#define pii pair<int,int>
#define MOD 1000000007

#define debug1(x) cout<<x<<"\n"
#define debug2(x,y) cout<<x<<" "<<y<<"\n"
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define debug4(x,y,z,w) cout<<x<<" "<<y<<" "<<z<<" "<<w<<"\n"

using namespace std;

vector <int> g[100005];
int dp[100005];
bool vis[100005];

int dfs(int u)
{
    vis[u]=true;
    dp[u]=1;
    for(int i:g[u])
    {
        if(!vis[i])
        {
            dp[u]=max(dp[u],1+dfs(i));
        }
        else
        {
            dp[u]=max(dp[u],1+dp[i]);
        }
    }
    return dp[u];
}

int main() {
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    /*freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);*/
    int n,m;cin>>n>>m;
    fi(i,0,m)
    {
        int s,d;cin>>s>>d;
        g[s].pb(d);
    }
    memset(dp,0,sizeof(dp));
    memset(vis,false,sizeof(vis));
    fi(i,1,n+1)
    {
        if(!vis[i])
        {
            dfs(i);
        }
    }
    int ans=1;
    fi(i,1,n+1)
    {
        ans=max(ans,dp[i]);
    }
    cout<<ans-1;
    return 0;
}

Measured memory_bytes: 7552
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD=1000000007;
#define INF 1LL<<30
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()

int main(){
    int n;
    cin>>n;
    vector<ll> a(n+1);
    rep(i,n+1) cin>>a[i];

    if(n==0){
        if(a[0]==1) cout<<1<<endl;
        else cout<<-1<<endl;
        return 0;
    }

    if(a[0]!=0){
        cout<<-1<<endl;
        return 0;
    }

    ll tot=0;
    rep(i,n+1) tot+=a[i];
    ll cur=1;
    ll ans=1;
    for(int i=1;i<n+1;i++){
        cur*=2;
        if(cur<a[i]){
            cout<<-1<<endl;
            return 0;
        }

        ans+=min(cur,tot);
        cur=min(cur,tot)-a[i];
        tot-=a[i];
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 4036
def input_number():
    num = raw_input()
    array = num.strip().split(" ")
    int_array = map(int, array)

    return int_array


def main():
    n = raw_input()
    count = 0
    int_array = input_number()
    for i in range(int(n)):
        minj = i
        for j in range(i, int(n)):
            if int_array[j] < int_array[minj]:
                minj = j
        v = int_array[i]
        int_array[i] = int_array[minj]
        int_array[minj] = v
        if minj != i:
            count += 1
    array = map(str, int_array)
    print " ".join(array)
    print count


if __name__ == '__main__':
    main()

Measured memory_bytes: 6364
S = input()
T = input()
S_dic = {}
T_dic = {}

for i in range(len(S)):
    s = S[i]
    t = T[i]
    if s in S_dic:
        S_dic[s] += 1
    else:
        S_dic[s] = 1

    if t in T_dic:
        T_dic[t] +=1

    else:
        T_dic[t] = 1

S_dic = sorted(S_dic.items(), key= lambda x:x[1])
T_dic = sorted(T_dic.items(), key=lambda x:x[1])
f = True
if len(S_dic) >= len(T_dic):
    length = len(T_dic)
else:
    length = len(S_dic)
for i in range(length):
    s = S_dic[i][1]
    t = T_dic[i][1]
    if s != t:
        f = False

if f:
    print("Yes")
else:
    print("No")


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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<n;i++)
typedef long long ll;

int main(){
  string a,b;
  cin >> a >> b;
  if(a[0]==b[2]&&a[1]==b[1]&&a[2]==b[0])cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

int mas[2005][2005] = {};
int raw[2005][2005] = {};
int col[2005][2005] = {};

main()
{
  int h, w, q;
  char c;
  cin >> h >> w >> q;

  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      cin >> c;
      mas[i][j] = c - '0';
      if(mas[i][j] == 1) {
	if(i > 1 && mas[i - 1][j] == 1) col[i][j] = 1;
	if(j > 1 && mas[i][j - 1] == 1) raw[i][j] = 1;
      }
    }
  }

  for(int i = 1; i <= h; i++) {
    for(int j = 1; j <= w; j++) {
      col[i][j] += col[i - 1][j] + col[i][j - 1] - col[i - 1][j - 1];
      raw[i][j] += raw[i - 1][j] + raw[i][j - 1] - raw[i - 1][j - 1];
      mas[i][j] += mas[i - 1][j] + mas[i][j - 1] - mas[i - 1][j - 1];
    }
  }

  while(q > 0) {
    int sx, sy, gx, gy;
    cin >> sy >> sx >> gy >> gx;
    
    int val = raw[gy][gx] - raw[gy][sx] - raw[sy - 1][gx] + raw[sy - 1][sx];
    val += col[gy][gx] - col[gy][sx - 1] - col[sy][gx] + col[sy][sx - 1];
    val = mas[gy][gx] - mas[gy][sx - 1] - mas[sy - 1][gx] + mas[sy - 1][sx - 1] - val;
    cout << val << endl;
    q--;
  }

  return (0);
}
  


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

using namespace std;

int main(){
	int n; cin>>n;
	int a[n],b[n];       
	for(int i=0;i<n;i++){ cin>>a[i];b[i] = a[i];}
	sort(a,a+n);
	for(int i=0;i<n;i++){
		if(b[i]<=a[n/2-1]) cout<<a[n/2]<<endl;
		else cout<<a[n/2-1]<<endl;
	}
}


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

int main(){
  int n,k;
  cin >> n >> k;
  vector<int> x(n);
  rep(i,n) cin >> x[i];
  int ans = 0;
  rep(i,n){
    ans += min(x[i],k - x[i]) * 2;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
char a;

while(1){
scanf("%c",&a);
if(a == '\n') break;
switch(a){
case 'A' : putchar('X');break;
case 'B' : putchar('Y');break;
case 'C' : putchar('Z');break;
default : printf("%c",a-3);break;
}
}
printf("\n");
return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <algorithm>
#include <cassert>
#define rep(i, a, b) for (int i = (a), _ = (b); i <= _; ++ i)
#define per(i, a, b) for (int i = (a), _ = (b); i >= _; -- i)
#define For(i, a, b) for (int i = (a), _ = (b); i < _; ++ i)
#define ri rd<int>
using namespace std;
const int maxN = 1e5 + 7;

template<class T> inline T rd() {
	bool f = 1; char c = getchar(); for (; !isdigit(c); c = getchar()) if (c == '-') f = 0;
	T x = 0; for (; isdigit(c); c = getchar()) x = x * 10 + c - 48; return f ? x : -x;
}

inline void END(int kd) { kd ? puts("First") : puts("Second"); exit(0); }

int n, sum;
int a[maxN];

inline int gcd(int x, int y) { while (y) swap(x %= y, y); return x; }

void play(int kd) {
	int cnt = 0, tag = 0;
	rep (i, 1, n) if (a[i] == 1) tag = 1;
	rep (i, 1, n) if (a[i] & 1)	++ cnt;
	if ((cnt & 1) ^ (n & 1)) END(kd);
	if (cnt > 1 || tag) END(kd ^ 1);
	assert(cnt == 1);
	rep (i, 1, n) if (a[i] & 1) --a[i];
	int g = 0; rep (i, 1, n) g = gcd(g, a[i]);
	rep (i, 1, n) a[i] /= g;
	play(kd ^ 1);
}

int main() {

	n = ri(); 
	rep (i, 1, n) a[i] = ri();
	
	if (n >= 3) play(1);
	else if (n == 1) END(a[1] % 2 == 0);
	else if (n == 2) END (a[1] % 2 == 0 || a[2] % 2 == 0);

	return 0;
}

Measured memory_bytes: 512
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, acos, atan, asin, log, log10
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
def debug(*args):
    if debugmode:
        print(*args)
def input(): return sys.stdin.readline().strip()
def STR(): return input()
def INT(): return int(input())
def FLOAT(): return float(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 9)
inf = sys.maxsize
mod = 10 ** 9 + 7
dx = [0, 0, 1, -1, 1, -1, -1, 1]
dy = [1, -1, 0, 0, 1, -1, 1, -1]
debugmode = False

o = STR()
e = STR()
ans = ''
for i in range(min(len(o), len(e))):
    ans += o[i] + e[i]
if min(len(o), len(e)) != len(o):
    ans += o[-1]
print(ans)

Measured memory_bytes: 60012
#include<bits/stdc++.h>
#define X first
#define Y second
#define pb emplace_back
#define FOR(i,a,b) for(int (i)=(a);i<(b);++(i))
#define EFOR(i,a,b) for(int (i)=(a);i<=(b);++(i))
#define rep(X,Y) for (int (X) = 0;(X) < (Y);++(X))
#define REP rep
#define rrep(X,Y) for (int (X) = (Y)-1;(X) >=0;--(X))
#define all(X) (X).begin(),(X).end()
#define eb emplace_back

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef ll LL;
typedef pii PII;
typedef pll PLL;
const ll MOD=1e9+7;

#define rall(X) (X).rbegin(),(X).rend()
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define reps(X,S,Y) for (int (X) = S;(X) < (Y);++(X))
#define rreps(X,S,Y) for (int (X) = (Y)-1;(X) >= (S);--(X))
template<class T> inline bool MX(T &l,const T &r){return l<r?l=r,1:0;}
template<class T> inline bool MN(T &l,const T &r){return l>r?l=r,1:0;}

int N;
int Y, M, D;

int Get(int Y, int M, int D) {
  int ans = 0;
  reps(y, 1, Y) {
    reps(m, 1, 11) {
      if (y%3 == 0) ans += 20;
      else if (m%2) ans += 20;
      else ans += 19;
    }
  }
  reps(m, 1, M) {
    if (Y%3 == 0) ans += 20;
    else if (m%2) ans += 20;
    else ans += 19;
  }
  ans += D;
  return ans;
}

signed main(){
  ios_base::sync_with_stdio(false);
  cout<<fixed<<setprecision(0);

  cin >> N;
  rep(i, N) {
    cin >> Y >> M >> D;
    cout << Get(1000, 1, 1) - Get(Y, M, D)  << "\n";
  }
}



Measured memory_bytes: 3224
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:16777216")
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
#include <string>
#include <cmath>
#include <stack>
#include <iomanip>
#include <set>
#include <queue>
#include <unordered_map>

using namespace std;

#define ff first
#define ss second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int maxn = 2e5 + 7;
const int inf = 2e9 + 7;
const ll infl = 1e18 + 7;
const long double eps = 1e-9;
const ll mod = 1e9 + 7;

ll t[4 * maxn];

ll get(int v, int tl, int tr, int l, int r) {
	if (tl == l && tr == r) {
		return t[v];
	}
	int tm = (tl + tr) / 2;
	if (r <= tm) return get(2 * v, tl, tm, l, r);
	else if (l > tm) return get(2 * v + 1, tm + 1, tr, l, r);
	else {
		return max(get(2 * v, tl, tm, l, tm), get(2 * v + 1, tm + 1, tr, tm + 1, r));
	}
}

void upd(int v, int tl, int tr, int ind, ll val) {
	if (tl == tr) {
		t[v] = val;
		return;
	}
	int tm = (tl + tr) / 2;
	if (ind <= tm) upd(2 * v, tl, tm, ind, val);
	else upd(2 * v + 1, tm + 1, tr, ind, val);
	t[v] = max(t[2 * v], t[2 * v + 1]);
}

int main() {
#ifdef _DEBUG
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
#endif // _DEBUG

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	int n;
	cin >> n;
	vector<ll> h(n), a(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	for (int i = 0; i < n; i++) cin >> a[i];

	ll ans = 0;

	for (int i = 0; i < n; i++) {
		ll d = get(1, 0, n - 1, 0, h[i] - 1);
		ans = max(ans, d + a[i]);
		upd(1, 0, n - 1, h[i] - 1, d + a[i]);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 9472
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <map>
#include <iostream>
#include <vector>
#include <queue>
#include <unordered_map>
#include <random>
#include <stack>
#include <set>
#include <unordered_set>

#define bug(x) cout<<"zdongdebug1: "<<x<<endl;
#define bug2(x, y) cout<<"zdongdebug2: "<<x<<" "<<y<<endl;
#define bug3(x, y, z) cout<<"zdongdebug3: "<<x<<" "<<y<<" "<<z<<endl;
using namespace std;
typedef long long ll;
const int maxn = 1005;
const int mod = 1000000007;

int main() {
#ifdef suiyuan2009
  freopen("/Users/suiyuan2009/CLionProjects/icpc/input.txt", "r", stdin);
  //freopen("/Users/suiyuan2009/CLionProjects/icpc/output.txt", "w", stdout);
#endif
  int n;
  cin>>n;
  cout<<n + n*n + n*n*n<<endl;
  return 0;
}

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

int main() {
  int a = 1, b, n;
  cin >> n;
  string s;
  cin >> s;
  for(int i = 1; i < n; i++){
    if(s.at(i) != s.at(i - 1)) a++;
  }
  cout << a << endl;
}

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

const int MAXN = 1100;
int R, C;
bool vis[MAXN][MAXN];

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	cin >> R >> C;
	vector<pair<int, int>> q;
	for (int i = 0; i < R; i++) {
		for (int j = 0; j < C; j++) {
			char c; cin >> c;
			if (c == '#') {
				vis[i][j] = true;
				q.emplace_back(i, j);
			} else {
				vis[i][j] = false;
			}
		}
	}

	int ans = 0;
	assert(!q.empty());
	while (true) {
		assert(!q.empty());
		vector<pair<int, int>> nq;
		for (auto it : q) {
			const int mx[4] = {-1, 0, 1, 0};
			const int my[4] = {0, -1, 0, 1};
			for (int d = 0; d < 4; d++) {
				int i = it.first + mx[d];
				int j = it.second + my[d];
				if (0 <= i && i < R && 0 <= j && j < C && !vis[i][j]) {
					vis[i][j] = true;
					nq.emplace_back(i, j);
				}
			}
		}
		if (nq.empty()) {
			break;
		}
		q = nq;
		ans++;
	}
	cout << ans << '\n';

	return 0;
}


Measured memory_bytes: 14056
#include<iostream>
#include<cstdio>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int ll;

int main()
{
    int n;
	double a;
	int ans[6]={0,0,0,0,0,0};
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		cin >> a;
		for(int j=0;j<5;j++){
			if(a<165+5*j){
				ans[j]++;
				break;
			}
		}
		if(a>=185)ans[5]++;
	}
	for(int i=0;i<6;i++){
		printf("%d:",i+1);
		for(int j=0;j<ans[i];j++){
			printf("*");
		}
		printf("\n");
	}
    return 0;
}

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

int t[110];
int p[110];
int x[110];
int n, m, g;

int main() {
  cin >> n;
  rep(i, n) cin >> t[i];
  cin >> m;
  rep(i, m) cin >> p[i] >> x[i];

  rep(i, m) {
    g = 0;
    rep(j, n) {
      if(j+1 == p[i]) {
        g += x[i];
      }else {
        g += t[j];
      }
    }
    cout << g << endl;
  }

  return 0;
}


Measured memory_bytes: 256
import itertools
N,M,R = map(int,input().split())
r = list(map(int,input().split()))
p = list(itertools.permutations(r))
dp = [[float('inf')]*N for _ in range(N)]
for i in range(M):
    a,b,c = map(int,input().split())
    dp[a-1][b-1] = c
    dp[b-1][a-1] = c
for i in range(N):
    dp[i][i] = 0

for k in range(N):
    for i in range(N):
        for j in range(N):
            dp[i][j] = min(dp[i][j], dp[i][k]+dp[k][j])
ans = float('inf')
for v in p:
    temp = 0
    for i in range(len(v)-1):
        temp += dp[v[i]-1][v[i+1]-1]
    ans = min(ans,temp)

print(ans)

Measured memory_bytes: 76888
import java.io.*
import java.util.*

const val MOD = 1000000007L

fun amida(n: Int): Long = when {
    n <= 1 -> 1L
    n == 2 -> 2L
    else -> amida(n - 1) + amida(n - 2)
}

fun solve(H: Int, W: Int, K: Int) {
    // dp[w][h] = 高さhでwにたどり着くあみだくじの総数
    val dp = Array<LongArray>(W + 1) { LongArray(H + 1) }
    dp[0][0] = 1
    for (h in 1..H) {
        for (w in 0 until W) {
            dp[w][h] = when (w) {
                0 -> 0 + amida(W - 1) * dp[w][h - 1] % MOD + amida(W - 2) * dp[w + 1][h - 1] % MOD
                W - 1 -> amida(W - 2) * dp[w - 1][h - 1] % MOD + amida(W - 1) * dp[w][h - 1] % MOD + 0
                else ->
                    (
                        amida(w-1) * amida(W - w - 1) * dp[w - 1][h - 1] % MOD +
                            amida(w) * amida(W - w - 1) * dp[w][h - 1] % MOD +
                            amida(w) * amida(W - w - 2) * dp[w + 1][h - 1] % MOD
                        )
            }
            dp[w][h] %= MOD
        }
    }
    println(dp[K - 1][H])
    return
}

fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val H = sc.next().toInt()
    val W = sc.next().toInt()
    val K = sc.next().toInt()
    solve(H, W, K)
}


Measured memory_bytes: 29720
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=510;
char s[N][N],w[N][N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++) scanf("%s",s[i]+1);
    for(int i=1;i<=n;i++) {
	w[i][1]=1,w[i][m]=2;
	for(int j=2;j<m;j++) {
	    if(s[i][j]=='#') w[i][j]=3;
	    else w[i][j]=1+(i&1);
	}
    }
    for(int i=1;i<=n;i++) {
	for(int j=1;j<=m;j++)
	    putchar(w[i][j]&1?'#':'.');
	puts("");
    }
    puts("");
    for(int i=1;i<=n;i++) {
	for(int j=1;j<=m;j++)
	    putchar(w[i][j]&2?'#':'.');
	puts("");
    }
    return 0;
}

Measured memory_bytes: 1280
using System;
using System.Collections.Generic;
using System.Text;

class Program
{

    public void Proc()
    {
        int cmdCount = int.Parse(Console.ReadLine());
        TreeNd root = null;

        for (int i = 0; i < cmdCount; i++)
        {
            string[] inpt = Console.ReadLine().Split(' ');
            if (inpt[0].Equals("print"))
            {
                this.GetInorderText(root);
                Console.WriteLine(string.Empty);
                this.GetPreorderText(root);
                Console.WriteLine(string.Empty);
            }
            else
            {
                long num = int.Parse(inpt[1]);
                if (root == null)
                {
                    root = new TreeNd(num);
                }
                else
                {
                    TreeNd target = root;
                    for (int j = 0; j < cmdCount; j++)
                    {
                        if (target.NodeId > num)
                        {
                            if (target.LeftChild == null)
                            {
                                target.LeftChild = new TreeNd(num);
                                target.LeftChild.Parent = target;
                                break;
                            }
                            else
                            {
                                target = target.LeftChild;
                            }
                        }
                        else
                        {
                            if (target.RightChild == null)
                            {
                                target.RightChild = new TreeNd(num);
                                target.RightChild.Parent = target;
                                break;
                            }
                            else
                            {
                                target = target.RightChild;
                            }
                        }
                    }
                }
            }

        }
        // ????????????

    }

    private void GetPreorderText(TreeNd root)
    {
        Console.Write(" " + root.NodeId);
        if (root.LeftChild != null)
        {
            this.GetPreorderText(root.LeftChild);
        }
        if (root.RightChild != null)
        {
            this.GetPreorderText(root.RightChild);
        }
    }

    private void GetInorderText(TreeNd root)
    {
        if (root.LeftChild != null)
        {
            this.GetInorderText(root.LeftChild);
        }
        Console.Write(" " + root.NodeId);
        if (root.RightChild != null)
        {
            this.GetInorderText(root.RightChild);
        }
    }

    public class TreeNd
    {
        public TreeNd Parent;
        public long NodeId;
        public TreeNd LeftChild;
        public TreeNd RightChild;


        public TreeNd(long nodeid)
        {
            this.NodeId = nodeid;
        }


    }


    static void Main(string[] args)
    {
        Program prg = new Program();
        prg.Proc();
    }
}

Measured memory_bytes: 46628
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
#define rep(i,n) for(int i=0;i<n;i++)

typedef int long long ll;
using namespace std;
typedef pair<int,int> P;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
const ll MOD=1e9+7;
static const int MAX = 100;
//static const int INF = (1<<23);
template<class T> T gcd(T a, T b){return b? gcd(b,a%b) : a;}
template<class T> T lcm(T a,T b){return a / gcd(a,b)*b;}
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
constexpr ll INF = TEN(18);
int main(){


    ll n,k;
    cin>>n>>k;
    ll ans = -1*INF;
    vector<ll> p(n,0);
    vector<ll> c(n,0);
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    rep(i,n){
        cin>>c[i];
    }


    rep(i,n){
        ll ansk = 0;
        ll circl_sum = 0;
        ll circle_len = 0;
        ll v = p[i];

        while(true){
            circl_sum  += c[v];
            circle_len ++;
            if(v==i)break;
            v=p[v];
        }

      // cout<<circl_sum<<" "<<circle_len<<endl;


      if(circle_len<k&&circl_sum>0){
          vector<ll> s;
          v = p[i];
          ll path = 0;
          ll ma = -1*INF;

          while(true){
              path += c[v];
              ma=max(ma,path);
              s.push_back(path);
              if(v==i)break;
              v=p[v];
          }


          ll send = s[s.size()-1];
          ll score1 = send*((k/circle_len)-1);
          score1 += ma;
          ll score2 = send*((k/circle_len));
          ll r = k%circle_len;
          int l=0;
          path = -1*INF;

          if(r!=0){
              for(int j=0;j<r;j++){
                  path = max(path,s[j]);
              }
              score2 += max(0ll,path);
          }
          ll score = max(score2,score1);
          ans = max(score,ans);


      }else{

          ll kremain = 0;
          if(circle_len>=k){
              kremain = k;
          }else if(circl_sum<=0){
              kremain = circle_len;
          }
          ll kremain_sum = -1*INF;
          // cout<<kremain<<"aaaa"<<ansk<<endl;

          ll ck = 0;
          ll vck = i;
          for(int j=0;j<kremain;j++){
              vck = p[vck];
              ck += c[vck];
              kremain_sum=max(kremain_sum,ck);
          }

          if(kremain!=0){
              ansk += kremain_sum;
          }

          //  cout<<ansk<<endl;
          ans = max(ans,ansk);
      }
    }
    if(ans==-1*INF){
        cout<<0<<endl;
    }else{
        cout<<ans<<endl;
    }




return 0;
}


Measured memory_bytes: 3808
// created by mtnshh
 
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;

#define ll long long
#define ld long double
 
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define repb(i,a,b) for(ll i=a;i>=b;i--)
 
#define err() cout<<"=================================="<<endl;
#define errA(A) for(auto i:A)   cout<<i<<" ";cout<<endl;
#define err1(a) cout<<#a<<" "<<a<<endl
#define err2(a,b) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<endl
#define err3(a,b,c) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<endl
#define err4(a,b,c,d) cout<<#a<<" "<<a<<" "<<#b<<" "<<b<<" "<<#c<<" "<<c<<" "<<#d<<" "<<d<<endl

#define pb push_back
#define all(A)  A.begin(),A.end()
#define allr(A)    A.rbegin(),A.rend()
#define ft first
#define sd second
 
#define pll pair<ll,ll>
#define V vector<ll>
#define S set<ll>
#define VV vector<V>
#define Vpll vector<pll>
 
#define endl "\n"
 
const ll logN = 20;
const ll M = 1000000007;
const ll INF = 1e12;
#define PI 3.14159265
 
const ll N = 100005;

void solve(){
	ll a,b,n;
	cin>>a>>b>>n;
	ll x = min(n, b-1);
	cout << (a*x)/b - a*(x/b) << endl;
	return;
}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	ll no;
	// cin>>no;
	no = 1;
	while(no--){
		solve();
	}
    return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<bitset>

using namespace std;
typedef long long ll;
#define i_7 1000000007
#define i_5 1000000005

ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    else return c+i_7;
}
typedef pair<int,int> i_i;
typedef pair<ll,ll> l_l;
#define inf 100000000/*10^8*/

/////////////////////////////////

struct edge{
    int to;
    int cost;
};


int main(){
    int k;cin>>k;
    vector<edge>e[k];
    for(int i=1;i<=k-1;i++){
        e[i].push_back(edge{(i+1)%k,1});
    }
    int dis[k];for(int i=0;i<=k-1;i++)dis[i]=inf;dis[1]=1;
    for(int i=1;i<=k-1;i++){
        e[i].push_back(edge{(i*10)%k,0});
    }
    queue<int> q;
    q.push(1);
    while(!q.empty()){
        int top=q.front();q.pop();
        for(auto x:e[top]){
            if(x.cost+dis[top]<dis[x.to]){
                dis[x.to]=x.cost+dis[top];
                q.push(x.to);
            }
        }
    }
    cout<<dis[0]<<endl;
    
    
    return 0;
}

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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(string s) {ll v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#define INF LONG_MAX
typedef long long ll;
struct edge{ll to, cost;};
typedef pair<ll,ll> P;

struct graph{
  ll V;
  vector<vector<edge> > G;
  vector<ll> d;

  graph(ll n){
    init(n);
  }

  void init(ll n){
    V = n;
    G.resize(V);
    d.resize(V);
    for(int i = 0; i < V; i++){
      d[i] = INF;
    }
  }

  void add_edge(ll s, ll t, ll cost){
    edge e;
    e.to = t, e.cost = cost;
    G[s].push_back(e);
  }

  void dijkstra(ll s){
    for(int i = 0; i < V; i++){
      d[i] = INF;
    }
    d[s] = 0;
    priority_queue<P,vector<P>, greater<P> > que;
    que.push(P(0,s));
    while(!que.empty()){
      P p = que.top(); que.pop();
      ll v = p.second;
      if(d[v]<p.first) continue;
      for(auto e : G[v]){
        if(d[e.to]>d[v]+e.cost){
          d[e.to] = d[v]+e.cost;
          que.push(P(d[e.to],e.to));
        }
      }
    }
  }
};

/*
graph g(n);

と書けばn頂点のグラフが作成され、

  g.add_edge(a,b,cost);

とすれば頂点aから頂点bへのコストcostの辺が張られます。そして

  g.dijkstra(s);

とすれば頂点sから各頂点への最短経路をダイクストラ法で探索できます。探索結果は

  int dist = g.d[i]:

と呼び出して使うことができます。
*/

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h, w;
  cin >> h >> w;
  int a[h][w];
  int b[h][w];

  rep(i,h) rep(j,w) cin >> a[i][j];
  rep(i,h) rep(j,w) cin >> b[i][j];

  int diff[h][w];
  rep(i,h) rep(j,w) diff[i][j] = abs(a[i][j] - b[i][j]);

  bool dp[h+1][w+1][13000];
  rep(i,h+1) rep(j,w+1) rep(k,13000) dp[i][j][k] = false;
  dp[0][0][0] = true;

  rep(i,h){
    rep(j,w){
      rep(k,13000){
        if(dp[i][j][k] == false) continue;
        if(j+1 <= w)  {dp[i][j+1][k+diff[i][j]] = true; dp[i][j+1][abs(k-diff[i][j])] = true;}
        if(i+1 <= h)  {dp[i+1][j][k+diff[i][j]] = true; dp[i+1][j][abs(k-diff[i][j])] = true;}
      }
    }
  }

  rep(i,13000){
    if(dp[h][w-1][i] || dp[h-1][w][i]){
      cout << i << endl;
      return 0;
    }
  }
  return 0;
}


Measured memory_bytes: 83584
q = int(input())
A = []
ans = []
for i in range(q):
    q = str(input())
    if q[0] == "0": #pushBack
        A.append(int(q[2:]))
    elif q[0] == "1": #randamAccess
        # ans.append(A[int(q[2:])])
        print(A[int(q[2:])])
    else: #popBack
        A.pop()
 
 


Measured memory_bytes: 13424
#include<stdio.h>

int main (void){
	
	int N, i, j, ii, v;
	
	scanf("%d", &N);
	
	int A[N];
	
	for(i=0; i<N; i++){
		scanf("%d", &A[i]);
	}
	
	for(ii=0; ii<N-1; ii++){
		printf("%d ", A[ii]);
	}
	printf("%d\n", A[ii]);
	
	for(i=0+1; i<N; i++){
		
		
		v=A[i];
		j=i-1;
		
		while(0<=j && v<A[j]){
			A[j+1]=A[j];
			j--;
		}
		
		A[j+1]=v;
		
		for(ii=0; ii<N-1; ii++){
			printf("%d ", A[ii]);
		}
		printf("%d\n", A[ii]);
		
	}
	
	return 0;
}




Measured memory_bytes: 2136
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define FORR(i, a, b) for (int i = b - 1; i >= a; --i)
#define SORT(v) sort(v.begin(), v.end())
#define SORTR(v) sort(v.rbegin(), v.rend())
#define REV(v) reverse(v.begin(), v.end())
#define ITER(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define LB(v, x) (lower_bound(v.begin(), v.end(), x) - v.begin())
#define UB(v, x) (upper_bound(v.begin(), v.end(), x) - v.begin())
#define SZ(v) (int)v.size()
using namespace std;
using ll = long long;
using P = pair<int, int>;

class UnionFind {
    int n;
    vector<int> par, rank;

public:
    UnionFind(int N) : n(N), par(N, -1), rank(N) {}
    int root(int i) {
        if (par[i] < 0) return i;
        return par[i] = root(par[i]);
    }
    bool same(int i, int j) { return root(i) == root(j); }
    void unite(int i, int j) {
        i = root(i);
        j = root(j);
        if (i == j) return;
        if (rank[i] <= rank[j]) {
            par[i] = j;
            if (rank[i] == rank[j]) { rank[j]++; }
        } else {
            par[j] = i;
        }
    }
};

class Main {
    int N, M;
    vector<int> X, Y, Z;
    void input() {
        cin >> N >> M;
        X.resize(M);
        Y.resize(M);
        Z.resize(M);
        REP(i, M) {
            cin >> X[i] >> Y[i] >> Z[i];
            X[i]--;
            Y[i]--;
        }
    }
    void output() {
        UnionFind ufd(N);
        REP(i, M) { ufd.unite(X[i], Y[i]); }
        set<int> st;
        REP(i, N) { st.emplace(ufd.root(i)); }
        cout << st.size() << endl;
    }

public:
    Main() {
        input();
        output();
    }
};

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

    Main();

    return 0;
}


Measured memory_bytes: 9796
#include<iostream>
#include<cstdio>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<deque>
#include<unordered_map>
#include<map>
#include<string>
#include<cstring>
#include<stack>
#include<cmath>

#define vint vector<int>
#define vstr vector<string>
#define vll vector<long long>
#define ll long long
#define pf printf
#define sf scanf
#define sfd(n) scanf("%d", &n)
#define sflf(n) scanf("%lf", &n)
#define sfll(n) scanf("%lld", &n)
#define pfd(n) printf("%d", n)
#define pflf(n) printf("%lf", n)
#define pfll(n) printf("%lld", n)
#define pft	printf("\t")
#define pfn printf("\n")
#define pfk printf(" ")
#define PI 3.1415926
#define MAX 100000
#define M 100003

using namespace std;

bool vj(int *p, int n) {
	for( int i=0; i<n-1; i++ ) {
		if( p[i]>p[i+1] ) {
			return false;
		}
	}
	return true;
}

int main() {
//	int n;
//	sfd(n);
// 	double* value = new double[n];
//	for( int i=0; i<n; i++ ) {
//		sflf(value[i]);
//	}
	int n;
	sfd(n);
	int* num = new int[n];
	for( int i=0; i<n; i++ ) {
		sfd(num[i]);
	}
	for( int i=n-1; i>0; i-- ) {
		if( num[i]<num[i-1] ) {
			num[i-1]--;
		}
	}
	bool f = vj(num, n);
	if( f ) {
		cout << "Yes";
	}else {
		cout << "No";
	}
	
	return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define POSSIBLE(n) cout << ((n) ? "POSSIBLE" : "IMPOSSIBLE"  ) << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible"  ) << endl

#define VIN(x) for(auto&youso_: (x) )cin>>youso_
#define VOUT(x, delim) for(auto&youso_: (x) )cout<<youso_<<delim;cout<<endl

#define COUT(x) cout<<(x)<<endl
void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}
#define CIN(...) i64 __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;

int main() {
    CIN(N, K);
    vector<i64> A(N);
    VIN(A);
    ALL(sort, A, greater<i64>());

    auto ok = [&](i64 x) {
        i64 cnt = 0;
        REP(i, N) {
            if (A[i] <= x) break;
            cnt += A[i] / x;
        }
        return cnt <= K;
    };

    i64 ub = A[0] + 1;
    i64 lb = 0;
    while (ub - lb > 1) {
        i64 mid = (ub + lb) / 2;

        if (ok(mid)) ub = mid;
        else lb = mid;
    }
    COUT(ub);

    return 0;
}


Measured memory_bytes: 4756
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MAX_N 1000001
#define MAX_M 100010
const long long mod=1e9+7;
#define vec vector<int>
#define vecll vector<ll>
#define vecllvec vector<vector<ll>>
#define vecb vector<bool>
#define vecBvec vector<vector<bool>>
#define vecst vector<string>
#define veche vector<char>
#define vecd vector<double>
#define vecvec vector<vector<int>>
#define vecDvec vector<vector<double>>
#define vecHvec vector<vector<char>>
#define all(x) (x).begin(),(x).end()
#define ent cout<<endl
#define printvec(vec) for(int aqw=0;aqw<vec.size();aqw++){cout<<vec[aqw]<<" ";}ent;
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define REP(i,m,n) for(int i=m;i<(int)n;++i)
#define INF 1e+9
#define P pair<int, int>;
#define YES "Yes"
#define NO "No"
#define MAX_V 1000
#define PI 3.141592653589793
// cout << setprecision(15) << std::fixed;

// テレンス「もしかしてACですかーッ!?」　ジョセフ「Yse! Yse! Yse! Oh~MyGod」

int main(){
  int n;
  cin>>n;
  int A[n][3];
  for(int i=0;i<n;i++){
    cin>>A[i][0]>>A[i][1]>>A[i][2];
  }
  vecvec dp(n+1,vec(3,0));
  for(int i=1;i<=n;i++){
    for(int a=0;a<3;a++){
      for(int b=0;b<3;b++){
        if(a!=b){
          dp[i][a]=max(dp[i][a],dp[i-1][b]+A[i-1][a]);
        }
      }
    }
  }
  cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}



Measured memory_bytes: 6912
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <chrono>

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

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

//#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define loop(x,n) for(int x = 0; x < n; ++x)
#define FORd(i,a,b) for (int i = (b)-1; i >= (a); i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a, x) for (auto& a : x)

#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound

#define sz(x) (int)x.size()
#define beg(x) x.begin()
#define en(x) x.end()
#define all(x) beg(x), en(x)
#define resz resize

const int MOD = 1000000007; // 998244353
const ll INF = 1e18;
const int MX = 100001;

string get_str() {
    string temp;
    cin >> temp;
    return temp;
}
int get_int() {
    int temp;
    cin >> temp;
    return temp;
}

int ans[4];

void solve() {

    int n; cin >> n;
    

    loop(i, n) {
        string s;
        cin >> s;
        if(s == "AC") {
            ans[0]++;
        }
        else if(s=="WA") {
            ans[1]++;
        }
        else if(s=="TLE") {
            ans[2]++;
        }
        else {
            ans[3]++;
        }
    }

    cout << "AC x " << ans[0] << endl;
    cout << "WA x " << ans[1] << endl;
    cout << "TLE x " << ans[2] << endl;
    cout << "RE x " << ans[3] << endl;


}

int main() {
    
    solve();

}

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

int main() {
    ll A, B, K; cin >> A >> B >> K;
    if(A >= K) {
        cout << A - K << " " << B << endl;
    } else if(A + B >= K) {
        cout << 0 << " " << B - (K - A) << endl;
    } else {
        cout << 0 << " " << 0 << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

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

    if(N % K == 0){
      ans = 0;
    }else{
      ans = 1;
    }

    System.out.println(ans);
  }
}


Measured memory_bytes: 21588
while(True):
    h,w = [int(i) for i in input().split()]
    if(h == 0 and w == 0):
        break
    for i in range(h):
        for j in range(w - 1):
            if(i == 0 or i % 2 == 0):
                if(j == 0 or j % 2 == 0):
                    print('#',end = '')
                else:
                    print('.',end = '')
            if(i % 2 != 0):
                if(j % 2 != 0):
                    print('#',end = '')
                else:
                    print('.',end = '')
        if(i % 2 != 0 and w % 2 == 0):
            print('#')
        elif(i % 2 == 0 and w % 2 != 0):
            print('#')
        else:
            print('.')
    print('')

Measured memory_bytes: 9208
import sys
input = sys.stdin.readline
N = list(input())[: -1]
r = 1
for i in range(len(N) - 1):
  if N[i] == N[i + 1]:
    r += 1
  elif i != 2: r = 1
if r >= 3: print("Yes")
else: print("No")

Measured memory_bytes: 38256
#include <bits/stdc++.h>
using namespace std;
int main()
{
  string s, t;
  cin >> s >> t;

  if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0]) {
    cout << "YES" << endl;
  } else {
    cout << "NO" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cassert>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<functional>
#include<limits>
#include<list>
#include<map>
#include<numeric>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<queue>
#include<vector>
using namespace std;

#define MOD 1000000007
#define INF 0x3f3f3f3f
#define INFL 0x3f3f3f3f3f3f3f3fLL

bool isPrime(int x) {
	if (x < 2)return 0;
	else if (x == 2)return 1;
	if (x % 2 == 0)return 0;
	for (int i = 3; i*i<= x; i+=2)
		if (x%i == 0)return 0;
	return 1;
}

int main() {
	int n; cin >> n;
	int ans = 0;
	for (int i = 0; i < n; i++) {
		int x; cin >> x;
		ans += isPrime(x);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1160
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));
var mod = 1e9+7;
//"a".charCodeAt()//97

console.log(main());
function main(){
  var n = o.a();
  var s = o.a(1);
  var ans = 1;
  var a = Array(26).fill(0);
  for(var i = 0; i < n; i++){
    var t = s[i].charCodeAt()-97;
    a[t]++;
  }
  for(i = 0; i < 26; i++){
    ans *= a[i] + 1;
    ans %= mod;
  }
  return ans-1;
}

Measured memory_bytes: 21576
#include <bits/stdc++.h>
using namespace std;
#define N 2010
bitset<4000010>f;
int n,sum,tmp,a[N];
int main(){
    scanf("%d",&n);
    for (int i=1;i<=n;i++) {
        scanf("%d",&a[i]);
        sum+=a[i];
    }
    f[0]=1;
    for (int i=1;i<=n;i++) {
		f|=(f<<a[i]);
	//	for (int j=0;j<=sum;j++) if (f[j]) printf("%d\n",j);
	}
    for (int i=0;i<=sum;i++) {
		if (f[i]) tmp++;
	//	if (f[i]) printf("%d\n",i);
	}
    tmp/=2; tmp++;
    for (int i=0;i<=sum;i++) {
        if (f[i]) tmp--;
        if (!tmp) {printf("%d\n",i); return 0;}
    }
    return 0;
}

Measured memory_bytes: 1664
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

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

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

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

    ll a, b; cin>>a>>b;
    ll mi = min(a, b);
    ll ma = max(a, b);
    if((mi + ma) % 2 == 0) cout << (mi + ma) / 2 << endl;
    else cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
typedef long long int lld;

int main(){
    lld A,B;
    scanf("%lld %lld",&A,&B);
    if(B-A == 0 || abs(B-A)%2==1)
    {
        fprintf(stdout, "IMPOSSIBLE");        
    }else{
        fprintf(stdout, "%lld", (A+B)/2);
    }
    return 0;
}

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

int main(){

  long long int n,m,a,b,c;

  while(cin >> n >> m){
    a = max(n,m);
    b = min(n,m);

    while(b != 0 && a % b != 0){
      c = a % b;
      a = b;
      b = c;
    }

    cout << b << endl;
  }
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <math.h>
using namespace std;
long int N;
int eu(int x,int y){
    if(x<y) return eu(y,x);
    int r;
    while((r=x%y)){
        x = y;
        y = r;
    }
    return y;
}
int main(){
    cin >> N;
    long int sum=0;
    for(int a=1;a<=N;a++){
        for(int b =1;b<=N;b++){
            for(int c =1; c<=N;c++){
                sum += eu(a,eu(b,c));
            }
        }
    }
    printf("%ld\n",sum);
}

Measured memory_bytes: 3724
using System;
class Program{
	static void Main(){
		int[] s=Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
		long[] a=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
		long ans=Math.Abs(s[2]-a[s[0]-1]);
		if(s[0]>1){ans=Math.Max(ans,Math.Abs(a[s[0]-2]-a[s[0]-1]));}
		Console.WriteLine(ans);
	}
}

Measured memory_bytes: 13204
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

const int MOD = 2019;


int main()
{
    long long L, R;
    cin >> L >> R;

    bool include_multiple = false;
    for(long long i = 1; i <= 1e+6; ++i){
        if(L <= i*MOD and i*MOD <= R){
            include_multiple = true;
            break;
        }
    }

    if(include_multiple){
        cout << 0 << endl;
    }else{
        long long ans = 2019;
        for(long long i = L; i <= R; ++i){
            for(long long j = i+1; j <= R; ++j){
                ans = min(ans, i%MOD * j%MOD % MOD);
            }
        }
        //int i = L%MOD;
        //cout << i*(i+1)%MOD << endl;
        cout << ans << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

	int a[3][3];
	for(int i=0;i<3;i++){
	
		for(int j=0;j<3;j++){
		
			cin>>a[i][j];
		}
	}
	int n;
	cin>>n;
	int b[n];
	for(int i=0;i<n;i++){
	
		cin>>b[i];
	}
     for(int x=0;x<n;x++){	

		for(int i=0;i<3;i++){
		
			for(int j=0;j<3;j++){
			
				if(a[i][j]==b[x]){
				
					a[i][j]=0;
				}
			}
		}
	}
		int ch=0;
		for(int i=0;i<3;i++){
		
			if(a[i][0]==a[i][1]&&a[i][1]==a[i][2]){

				cout<<"Yes";
				return 0;
			}
		}
		for(int i=0;i<3;i++){
		
			if(a[0][i]==a[1][i]&&a[1][i]==a[2][i]){

				cout<<"Yes";
				return 0;
			}
		}

		if(a[0][0]==a[1][1]&&a[1][1]==a[2][2]){
		
			cout<<"Yes";
			return 0;
		}
		if(a[0][2]==a[1][1]&&a[1][1]==a[2][0]){
		
			cout<<"Yes";
			return 0;
		}

		cout<<"No";
		return 0;
}



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

int main(){
  ll a, b, c, d;
  cin >> a >> b >> c >> d;
  ll ans = max(a*c, a*d);
  ans = max(ans, b*c);
  ans = max(ans, b*d);
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main()
{
    int A, B;
    int c =0;
cin >> A >> B;
    for(int i = A; i <= B; ++i)
    {
        int  s = i % 10 , t = i / 10000 % 10;
        int u = i / 10 % 10 , v = i / 1000 % 10;
        if( s==t && u == v)
            c++;

    }
    cout << c;
}


Measured memory_bytes: 256
n=int(input())
s=[input() for i in range(n)]
a='abcdefghijklmnopqrstuvwxyz'
b=[[0]*n for i in range(26)]
for i in range(n):
  m=len(s[i])
  for j in range(m):
    b[a.index(s[i][j])][i]+=1
out=''
for i in range(26):
  out+=a[i]*min(b[i])
print(out)

Measured memory_bytes: 3064