akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
const int mod=1e9+7;
const int maxn=1e5;
using namespace std;

int main()
{
    //freopen("input.txt","r",stdin);
    ios::sync_with_stdio(false);
    ll n,s;
    cin>>n>>s;
    ll sum=0;
    for(ll i=2; i<=sqrt(n)+1; i++)
    {
        ll t=n;
        while(t)
        {
            sum+=(t%i);
            t/=i;
        }
        if(sum==s)
        {
            cout<<i;
            return 0;
        }
        sum=0;
    }
    for(ll i=sqrt(n-s); i>=1; i--)
    {
        ll t=n;
        if((n-s)%i==0)
        {
            ll b=(n-s)/i+1;
            while(t)
            {
                sum+=(t%b);
                t/=b;
            }
            if(sum==s)
            {
                cout<<b;
                return 0;
            }
            sum=0;
        }

    }
    if(n==s) cout<<n+1<<endl;
    else
        cout<<-1<<endl;
}




Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(String[] args) {
        final long DIV = 1000000007L;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        long[] x = new long[n];
        long[] y = new long[m];
        for(int i=0; i<n; i++){
            x[i] = sc.nextLong();
        }
        for(int j=0; j<m; j++){
            y[j] = sc.nextLong();
        }
        sc.close();

        // long[] xmult = new long[n-1];
        long xmultsum = 0;
        for(int i=0; i<n-1; i++){
            // xmult[i] = (x[i+1] - x[i]) * (i+1) * (n-i);
            xmultsum += (x[i+1] - x[i]) * (i+1) * (n-i-1);
            xmultsum %= DIV;
        }
        long ans = 0;
        // long[] ymult = new long[m-1];
        for(int i=0; i<m-1; i++){
            // ymult[i] = (y[i+1] - y[i]) * (i+1) * (m-i);
            ans += xmultsum * (((y[i+1] - y[i]) * (i+1) * (m-i-1)) % DIV);
            ans %= DIV;
        }

        System.out.println(ans);
    }
}

Measured memory_bytes: 92988
#include<iostream>
#include<cmath>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstring>

using namespace std;

#define INF 999999999

struct lec{
	int w, h, t;
	bool operator <(const lec& a) const{
		if(t!=a.t) return t < a.t;
		if(h!=a.h) return h < a.h;
	}
};

int main(){
	int i, j, a, b;
	vector<lec> mat;
	lec s;
	for(i=1;i<=150;i++){
		for(j=1;j<i;j++){
			s.w = i;
			s.h = j;
			s.t = i*i + j*j;
			mat.push_back(s);
		}
	}
	sort(mat.begin(), mat.begin()+mat.size());
	while(1){
		cin >> a >> b;
		if(!a) break;
		i = 0;
		while(1){
			if(mat[i].w==b && mat[i].h==a){
				cout << mat[i+1].h << " " << mat[i+1].w << endl;
				break;
			}
			i++;
		}
	}
	return 0;
}

Measured memory_bytes: 1348
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
#include<string>
#include<vector>
#include<math.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

#define max 100005
#define nil -1
struct node{int p, l, r;};

node t[max];
int n, d[max];

void print(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << t[u].p << ", ";
    cout << "depth = " << d[u] <<", ";

    if(t[u].p == nil) cout <<"root, ";
    else if(t[u].l == nil) cout << "leaf, ";
    else cout << "internal node, ";

    cout << "[";

    for(int i = 0, c = t[u].l; c != nil; i++, c = t[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p){
    d[u] = p;
    if(t[u].r != nil) rec(t[u].r, p);
    if(t[u].l != nil) rec(t[u].l, p+1); 
}

int main(){
    int n, v, d, c, l, r;
    cin >> n;
    rep(i, n) t[i].p = t[i].l = t[i].r = nil;

    rep(i, n){
        cin >> v >> d;
        rep(j, d){
            cin >> c;
            if(j == 0) t[v].l = c;
            else t[l].r = c;
            l = c;
            t[c].p = v;
        }
    }
    rep(i, n){
        if(t[i].p == nil) r = i;
    }

    rec(r, 0);

    rep(i, n) print(i);
 }




Measured memory_bytes: 7772
#include <stdio.h>

void transformation(int year, int month, int day)
{
    if (year > 1989 || (year == 1989 && month > 1) || (year == 1989 && month == 1 && day >= 8)) {
        printf("heisei %d %d %d\n", year - 1989 + 1, month, day);
    } else if (year > 1926 || (year == 1926 && month == 12 && day >= 25)){
        printf("showa %d %d %d\n", year - 1926 + 1, month, day);
    } else if (year > 1912 || (year == 1912 && month > 7) || (year == 1912 && month == 7 && day >= 30)) {
        printf("taisho %d %d %d\n", year - 1912 + 1, month, day);
    } else if (year > 1868 || (year == 1868 && month > 9) || (year == 1868 && month == 9 && day >=8)) {
        printf("meiji %d %d %d\n", year - 1868 +1, month, day);
    } else {
        printf("pre-meiji\n");
    }
}

int main(void)
{
    int year, month, day;
    while (scanf("%d %d %d", &year, &month, &day) != EOF) {
        transformation(year, month, day);
    }
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define FOR(i, a, b) for (int (i) = (a); (i) <= (b); (i)++)
#define ROF(i, a, b) for (int (i) = (a); (i) >= (b); (i)--)
#define REP(i, n) FOR(i, 0, (n)-1)
#define sqr(x) ((x) * (x))
#define all(x) (x).begin(), (x).end()
#define reset(x, y) memset(x, y, sizeof(x))
#define uni(x) (x).erase(unique(all(x)), (x).end());
#define BUG(x) cerr << #x << " = " << (x) << endl
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define _1 first
#define _2 second

int n, a;

int main() {
    bool ans = false;
    scanf("%d", &n);
    FOR(i, 1, n) {
        scanf("%d", &a);
        if (a & 1) {
            ans = true;
            break;
        }
    }
    puts(ans ? "first" : "second");
}

Measured memory_bytes: 256
# coding: utf-8
import sys

stdin = sys.stdin
ns = lambda: stdin.readline().rstrip() # ignore trailing spaces
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))


def main():
    n = ni()
    bo = []
    up = []
    for _ in range(n):
        a,b = na()
        bo += [a]
        up += [b]
    bo.sort()
    up.sort()
    
    if n%2 == 1:
        print(up[n//2] - bo[n//2] + 1)
    else:
        pre_b, pre_u = bo[n//2 - 1], up[n//2 - 1]
        nex_b, nex_u = bo[n//2], up[n//2]
        print((pre_u+nex_u) - (pre_b+nex_b) + 1)
    return


if __name__ == '__main__':
    main()

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  ll N; cin >> N;
  ll D; cin >> D;
  vector<ll> X(N), Y(N); REP(i, N) cin >> X[i] >> Y[i];
  ll ans = 0;
  REP(i, N) {
    ll tmp = pow(D, 2);
    ll tmp2 = X[i] * X[i] + Y[i] * Y[i];
    if(tmp >= tmp2) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 6424
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <map>
#define fo(i,a,b) for(register int i=a;i<=b;++i)
#define fod(i,a,b) for(register int i=a;i>=b;--i)
#define efo(i,q) for(int i=A[q];i;i=B[i][0])
using namespace std;
const int N=100500;
int read(int &n)
{
	char ch=' ';int q=0,w=1;
	for(;(ch!='-')&&((ch<'0')||(ch>'9'));ch=getchar());
	if(ch=='-')w=-1,ch=getchar();
	for(;ch>='0' && ch<='9';ch=getchar())q=q*10+ch-48;n=q*w;return n;
}
int m,n,m1,ans;
int a[N],b[N];
map<int,int>zc;
map<int,int>A;
map<int,bool>z;
int B[2*N][2],B0;
void link(int q,int w)
{
	B[++B0][0]=A[q],A[q]=B0,B[B0][1]=w;
	B[++B0][0]=A[w],A[w]=B0,B[B0][1]=q;
}
void dfs(int q)
{
	z[q]=1;
	efo(i,q)if(!z[B[i][1]])dfs(B[i][1]);
}
int main()
{
	int q,w,e=-1;
	read(n);
	q=w=0;
	fo(i,1,n)q=q^read(a[i]),++zc[a[i]];
	fo(i,1,n)
	{
		if(a[i]!=read(b[i]))
		{
			++ans;
			link(b[i],a[i]);
		}
		if((--zc[b[i]])<0)++w,e=b[i];
	}
	if(!ans)return printf("0\n"),0;
	if(w>1)return printf("-1\n"),0;
	fo(i,1,n)if(a[i]!=b[i]&&!z[b[i]])dfs(b[i]),++ans;
	if(z[q]&&!w||w&&e==q)--ans;
	if(w&&e!=q)printf("-1\n");
	else printf("%d\n",ans);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<(n); ++i)
#define print(x) cout<<x<<endl;
typedef long long ll;
const ll INF = 1000000000000;
const int MOD = 1000000007;

int main() {
  int n,k;
  cin >>n>>k;
  vector<int> a(n);
  vector<ll> dp(n+1,INF);

  rep(i,n)cin>>a[i];
  dp[0] = 0;
  rep(i,n){
     rep(j,k){
         if(i+j+1>=n)break;
         dp[i+j+1] = min(dp[i+j+1],dp[i] + abs(a[i]-a[i+j+1]));
     }
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

Measured memory_bytes: 1408
#include <iostream>
using namespace std;
int n,a[1000];

void print(){
	int i=0;
	while(true){
		cout<<a[i];
		i++;
		if(i<n){
			cout<<" ";
		}else{
			break;
		}
	}
	cout<<endl;
}

int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		int j=i-1,v=a[i];
		for(;j>=0 && a[j]>v;j--){
			a[j+1]=a[j];
		}
		a[j+1]=v;
		print();
	}
	return 0;
}


Measured memory_bytes: 3104
import fractions

n = int(input())
a = list(map(int, input().split()))

gcdl = [0]
gcdr = [0]

for i in range(n-1) :
    gcdl.append(fractions.gcd(gcdl[i], a[i]))
    gcdr.append(fractions.gcd(gcdr[i], a[-(i+1)]))
gcdr = gcdr[::-1]

ans = []
for i in range(n) :
    ans.append(fractions.gcd(gcdl[i], gcdr[i]))

print(max(ans))

Measured memory_bytes: 16148
#include<stdio.h>
int main(void){
    char A[6];
    int a=0;
    int b=0;
    scanf("%s",A);
    if (A[2]==A[3])
    {a=1;
}
if(A[4]==A[5])
{b=1;
}
    if (a==1&&b==1)
    {
       printf("Yes");
    }else{
        printf("No");
    }
}


    
    
    




Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int A,B;
bool digit(int n)
{
    int s=0,r,N=n;
    while(n>0)
    {
        r=n%10;
        s+=r;
        n/=10;
    }

    if(A<=s&&s<=B)return true;
    else return false;
}

int main()
{
    int N,i,sum=0;

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

    for(i=1; i<=N; i++)
        if(digit(i))
            sum+=i;

    printf("%d\n",sum);

}


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

int main(){
	cin.tie(0);
	cout.tie(0);
	ios_base::sync_with_stdio(0);
	int mn = 1e9;
	int n;
	cin >> n;
	int cnt = 0;
	for(int i = 0;i < n; ++i){
		int x;
		cin >> x;
		cnt += mn > x;
		mn = min(x, mn);
	}
	cout << cnt << '\n';
}


Measured memory_bytes: 256
#include <cstdio>

int N,M,D;
char ch[101][101];
int ans = 0;

int main(){
	scanf("%d%d%d",&N,&M,&D);
	for(int i = 0; i < N; i++){
		scanf("%s",ch[i]);
	}
	for(int i = 0 ; i < N; i++){
		for(int j = 0; j <= M - D; j++){
			bool ok = true;
			for(int k = 0; k < D; k++){
				if(ch[i][j+k] == '#'){
					ok = false;
					j += k;
					break;
				}
			}
			if(ok){
				ans++;
			}
		}
	}
	for(int j = 0; j < M; j++){
		for(int i = 0; i <= N - D; i++){
			bool ok = true;
			for(int k = 0; k < D; k++){
				if(ch[i+k][j] == '#'){
					ok = false;
					i += k;
					break;
				}
			}
			if(ok){
				ans++;
			}
		}
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 2616
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		int a, b;
		a = sc.nextInt();
		b = sc.nextInt();
		sc.close();
		
		int ans = a + b;
		
		if(ans >= 10)System.out.println("error");
		else System.out.println(ans);
	}

}


Measured memory_bytes: 22612
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 200500000000000
#define MOD 10007
#define N 100005
#define M 1000005
#define LOG 18
#define KOK 4000000
using namespace std;

int n,m,a,b,c;
int pos[N],vis[N];
vector<ii> v[N];

void fail() {

	printf("No");

	exit(0);

}

void dfs(int node)  {

	vis[node]=1;

	for(ii i:v[node]) {

		if(!vis[i.st]) {

			pos[i.st]=pos[node]+i.nd;

			dfs(i.st);

		}

	}

}

int main() {

	//freopen("input.txt","r",stdin);

	scanf("%d %d",&n,&m);

	for(int i=1;i<=m;i++) {

		scanf("%d %d %d",&a,&b,&c);

		v[b].pb({a,c});
		v[a].pb({b,-c});

	}

	for(int i=1;i<=n;i++) {

		if(!vis[i]) {

			dfs(i);

		}

	}

	for(int i=1;i<=n;i++) {

		for(ii go:v[i]) {

			if(pos[i]+go.nd!=pos[go.st]) fail();

		}

	}

	printf("Yes");

}



Measured memory_bytes: 11392
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1LL << 60;

int main() {
    string s, t, u;
    int a, b;
    cin >> s >> t >> a >> b >> u;
    if (s == u) {
        a--;
    } else {
        b--;
    }
    cout << a << " " << b << endl;
    return 0;
}

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

using namespace std;
using ll = long long;
using ld = long double;
using p = pair<int, int>;
using Graph = vector<vector<char>>;
#define rep(i,n)  for(int i = 0; i < n ; i++)
#define chmax(x,y) x = max(x,y);
int dx[4]{ -1,0,1,0 };
int dy[4]{ 0,1,0,-1 };
const ll INF = 1e18;
ll dp[200005][4]; // i番目までの個数でj個余分な×を選んだ際の和の最大値

int main()
{
    int n, m;
    cin >> n >> m;
    ll workDay = 0;
    rep(i, m)
    {
        int a;
        cin >> a;
        workDay += a;
    }
    if (n < workDay)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << n - workDay << endl;
    }
}

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

int main() {
	int N;
	cin >> N;
	vector<vector<int>> Dist(N, vector<int>(N, N));
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			char c;
			cin >> c;
			if (c == '1') Dist[i][j] = 1;
		}
	}
	for (int k = 0; k < N; k++) {
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				Dist[i][j] = min(Dist[i][j], Dist[i][k] + Dist[k][j]);
			}
		}
	}
	vector<int> Color(N, 0);
	Color[0] = 1;
	int MAX = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			if (Dist[i][j] == N) continue;
			int c = Dist[i][j] % 2 == 0 ? Color[i] : -Color[i];
			if (Color[j] == 0) Color[j] = c;
			else {
				if (Color[j] != c) {
					cout << -1 << endl;
					return 0;
				}
			}
			MAX = max(MAX, Dist[i][j]);
		}
	}
	cout << MAX + 1 << endl;
}

Measured memory_bytes: 3736
#include<stdio.h>

double a(double A,double a,double B,double b,double x,double y)
{
    if(A!=B){
        return ((a-b)/(A-B))*(x-A)+a-y;
    } else {
        return x-A;
    }
}

int main(void)
{
    double x1,y1,x2,y2,x3,y3,xp,yp,xs,ys;
    int i,j,n;

    for(scanf("%d",&n);n>0;n--){

        scanf("%lf%lf%lf%lf%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3,&xp,&yp,&xs,&ys);

        if((a(x1,y1,x2,y2,xp,yp)*a(x1,y1,x2,y2,x3,y3)<0)||(a(x3,y3,x2,y2,xp,yp)*a(x3,y3,x2,y2,x1,y1)<0)||(a(x1,y1,x3,y3,xp,yp)*a(x1,y1,x3,y3,x2,y2)<0)){
            if((a(x1,y1,x2,y2,xs,ys)*a(x1,y1,x2,y2,x3,y3)<0)||(a(x3,y3,x2,y2,xs,ys)*a(x3,y3,x2,y2,x1,y1)<0)||(a(x1,y1,x3,y3,xs,ys)*a(x1,y1,x3,y3,x2,y2)<0)){
                puts("NG");
            } else {
                puts("OK");
            }
        } else {
            if((a(x1,y1,x2,y2,xs,ys)*a(x1,y1,x2,y2,x3,y3)<0)||(a(x3,y3,x2,y2,xs,ys)*a(x3,y3,x2,y2,x1,y1)<0)||(a(x1,y1,x3,y3,xs,ys)*a(x1,y1,x3,y3,x2,y2)<0)){
                puts("OK");
            } else {
                puts("NG");
            }
        }
    }
    return 0;
}

Measured memory_bytes: 620
def liner_search(A, n, B, q):
    cnt = 0
    for i in range(q):
        for j in range(n):
            if B[i] == A[j]:
                cnt += 1
                break
    return cnt

n = int(input())
A = list(map(int,input().split()))
q = int(input())
B = list(map(int,input().split()))
print(liner_search(A, n, B, q))


Measured memory_bytes: 6512
import sys
n, a, b, c, d = [int(i) - 1 for i in sys.stdin.readline().split()]
n += 1
s = input()
s_memo_ls = [0 for i in range(n)]
s_memo_ls[a] = 1
f_memo_ls = [0 for i in range(n)]
f_memo_ls[b] = 1

for i in range(a+1, c+1):
    if s[i] == "#":
        continue
    s_memo_ls[i] = max(s_memo_ls[i - 1], s_memo_ls[i - 2])
for i in range(b+1, d+1):
    if s[i] == "#":
        continue
    f_memo_ls[i] = max(f_memo_ls[i - 1], f_memo_ls[i - 2])

if s_memo_ls[c] and f_memo_ls[d]:
    flg = d > c
    for i in range(1, n - 1):
        if s[i-1] == s[i] == s[i+1] == ".":
            flg |= f_memo_ls[i] and s_memo_ls[i-1]
        if flg:
            break
    print("Yes" if flg else "No")
else:
    print("No")

Measured memory_bytes: 55084
#include <cstdio>
#include <vector>
#include <map>

#define MOD 1000000007

using namespace std;

typedef long long ll;

vector< vector<int> > e;

pair<ll, ll> solve(ll root, ll v) {
    pair<ll, ll> ans = {1, 1};
    for (int dv : e.at(v)) if (root != dv) {
        pair<ll, ll> s = solve(v, dv);
        (ans.first *= s.first) %= MOD;
        (ans.second *= s.second) %= MOD;
    }
    return {(ans.first + ans.second) % MOD, ans.first};
}

int main() {
    int n, x, y;
    scanf("%d", &n);
    e.resize(n + 1);
    for (int i = 0; i < n - 1; ++i) {
        scanf("%d%d", &x, &y);
        e.at(x).push_back(y);
        e.at(y).push_back(x);
    }
    printf("%lld\n", solve(0, 1).first);
    return 0;
}

Measured memory_bytes: 12672
#include<iostream>
#include<cmath>

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

int main(){
	int a,d;
	long int n, ans;
	while(std::cin >> a >> d >> n && (a || d || n)){
		int i=0;
		while(n){
			int count=0;
			ans = a + (i*d);
			i++;
			rep(j,sqrt(ans)+1){
				if (ans == 2 || ans == 3 || ans == 5)
					continue;
				else if(ans % (j + 2) == 0)
				{
					count = 1;
					break;
				}
			}
			if(count == 0 && ans != 1){
				n--;
			}
		}
		std::cout << ans << std::endl;
	}
	return 0;
}

Measured memory_bytes: 864
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <cfloat>
using namespace std;

string mcxi = "mcxi";

int toNum(string s){
    int ret = 0;
    for(unsigned i=0; i<s.size(); ++i){
        int a = 1;
        if('2' <= s[i] && s[i] <= '9'){
            a = s[i] - '0';
            ++ i;
        }
        int tmp = 1000;
        for(int j=0; j<4; ++j){
            if(s[i] == mcxi[j])
                ret += a * tmp;
            tmp /= 10;
        }
    }
    return ret;
}

string solve(string& s1, string& s2)
{
    int num = toNum(s1) + toNum(s2);
    string s;
    int tmp = 1000;
    for(int i=0; i<4; ++i){
        int a = num / tmp;
        if(a != 0){
            if(a != 1)
                s += '0' + a;
            s += mcxi[i];
        }
        num %= tmp;
        tmp /= 10;
    }
    return s;
}

int main()
{
    int n;
    cin >> n;
    for(int i=0; i<n; ++i){
       string s1, s2;
       cin >> s1 >> s2;
       cout << solve(s1, s2) << endl;
    }
}

Measured memory_bytes: 0
#!/usr/bin/env python3

import sys, math, copy
# import fractions, itertools
import numpy as np
# import scipy

HUGE = 2147483647
HUGEL = 9223372036854775807
ABC = "abcdefghijklmnopqrstuvwxyz"

def main():
    n = int(input())
    sl = [[c for c in input()] for i in range(n)]

    s = np.char.array(sl)
    assert s.shape == (n, n)

    res = 0
    for i in range(n):
        sr = np.roll(s, i, axis=1)
        if np.all(sr.T == sr):
            res += n

    print(res)

main()


Measured memory_bytes: 21384
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<set>
#include<stack>
#include<queue>
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pb push_back
#define rep(i,n) for(ll i=0;i<n;i++)
#define repr(i,n) for(ll i=n;i>=0;i--)
#define INF 1e9+7
#define LLINF 1e18
using namespace std;
const int MOD = 1e9 +7;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,a[110];
    cin>>n;
    rep(i,n) cin>>a[i];
    ll ans=0;
    for(ll i=1;i<n;i++){
        if(a[i] ==a[i-1]){
            ans++;
            a[i] =INF;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int m,n,sum=0,cnt=0;
	cin>>m>>n;
	for(int i=m-1;i>0;i--)
	{
		sum=sum+i;
		
	}
		for(int j=n-1;j>0;j--)
		{
			cnt=cnt+j;
		}
	cout<<sum+cnt;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        try (Scanner sc = new Scanner(System.in)) {
            int X = sc.nextInt();
            long sum = 0;
            sum += (X / 500) * 1000;
            sum += ((X % 500) / 5) * 5;
            System.out.println(sum);
        }
    }
}


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

using namespace std;

int main(void){

  int n;
  while(cin >> n,n){
    vector<int>v(n);
    for(int i=0;i<n;i++)cin >> v[i];
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=1;i<n-1;i++)ans += v[i];
    cout << ans/(n-2) << endl;
  }
  return 0;
}

Measured memory_bytes: 3076
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
	   Scanner sc = new Scanner(System.in);
	   int a = sc.nextInt();
	   int b = sc.nextInt();
	   if(a==b){
	       System.out.println("a == b");
	   }else if(a<b){
	       System.out.println("a < b");
	   }else{
	        System.out.println("a > b");
	   }
	   sc.close();
	}
    
}


Measured memory_bytes: 26320
#include<iostream>
#include<vector>
#include<math.h>
typedef long long int ll;
int main() {
	ll n;
	std::cin >> n;
	int a = sqrt(n);
	for (a; a > 0; a--) {
		if (n % a == 0) {
			std::cout << a + n / a - 2 << std::endl;
			break;
		}
	}
	return 0;
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////
int a,b,c,ans;
int main(){
    scanf("%d%d", &a, &b);
    ans = a * 2 - 1;
    c = a + b;
    if(ans<c)
        ans = c;
    c=b*2-1;
    if(ans<c)
        ans = c;
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 256
import java.io.*;
import java.math.*;
import java.util.*;
 
public class Main {
    private static boolean debug = false;
    private static boolean elapsed = false;
 
    private static PrintWriter _out = new PrintWriter(System.out);
    private static PrintWriter _err = new PrintWriter(System.err);
 
    private void solve(Scanner sc) {
        String s = sc.nextLine();
 
        Set<Character> set = new HashSet<>();
        for (int i = 0; i < s.length(); ++i) {
            char ch = s.charAt(i);
            if (!set.contains(ch)) {
                set.add(ch);
            } else {
                _out.println("no");
                return;
            }
        }
        _out.println("yes");
    }
    private static BigInteger C(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        for (long i = r; i > 1; --i) {
            res = res.divide(BigInteger.valueOf(i));
        }
        return res;
    }
    private static BigInteger P(long n, long r) {
        BigInteger res = BigInteger.ONE;
        for (long i = n; i > n - r; --i) {
            res = res.multiply(BigInteger.valueOf(i));
        }
        return res;
    }
    /*
     * 10^10 > Integer.MAX_VALUE = 2147483647 > 10^9
     * 10^19 > Long.MAX_VALUE = 9223372036854775807L > 10^18
     */
    public static void main(String[] args) {
        long S = System.currentTimeMillis();
 
        Scanner sc = new Scanner(System.in);
        new Main().solve(sc);
        _out.flush();
 
        long G = System.currentTimeMillis();
        if (elapsed) {
            _err.println((G - S) + "ms");
        }
        _err.flush();
    }
}

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

int main(){
	int a, b;
	char op;
	while (1){
		cin >> a >> op >> b;
		if (op == '+'){
			cout << a + b << endl;
		}
		else if(op == '-'){
			cout << a - b << endl;
		}
		else if (op == '*'){
			cout << a * b << endl;
		}
		else if (op == '/'){
			cout << a / b << endl;
		}
		else{
			break;
		}
	}
	return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
typedef long long ll;
const int mod = 1e9 + 7;

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

ll factorial(ll n) {
  ll answer = 1;
  while (n > 1) {
    answer *= n;
    answer %= mod;
    n--;
  }
  return answer;
}

ll combination(ll n, ll r) {
  return factorial(n) / (factorial(r) * factorial(n - r));
}

ll permutation(ll n, ll r) { return factorial(n) / factorial(n - r); }

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

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

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main (String args[]) throws IOException {
        // x+rがw以下かつy+rがh以下かつ
        // x-rが0以上かつy-rっが0以上なら長方形の中に含まれる
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] str = br.readLine().split(" ");
        int w = Integer.parseInt(str[0]);
        int h = Integer.parseInt(str[1]);
        int x = Integer.parseInt(str[2]);
        int y = Integer.parseInt(str[3]);
        int r = Integer.parseInt(str[4]);

        if (x + r <= w && y + r <= h && x - r >= 0 && y - r  >= 0) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}


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

int main() {
	char x, y;
	cin >> x >> y;
	if (x < y) {
		cout << "<" << endl;
	}
	else if (x == y) {
		cout << "=" << endl;
	}
	else {
		cout << ">" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include  <iostream>
using namespace std;
int main(void) {
  int trout;
  int i = 0;
  cin >> trout;
  if ((trout & 100) !=0)
    i++;
  if ((trout & 10) !=0)
    i++;
  if ((trout & 1) !=0)
    i++;
  cout << i;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main (String[] args) {
    	Scanner sc = new Scanner(System.in);
    	char[] s = sc.next().toCharArray();
    	char[] t = sc.next().toCharArray();
    	int min = Integer.MAX_VALUE;
    	for (int i = 0; i + t.length <= s.length; i++) {
    	    int count = 0;
    	    for (int j = 0; j < t.length; j++) {
    	        if (s[i + j] != t[j]) {
    	            count++;
    	        }
    	    }
    	    min = Math.min(min, count);
    	}
    	System.out.println(min);
    }
}


Measured memory_bytes: 35744
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		final int N = sc.nextInt();
		int[] p = new int[N];
		for (int i = 0; i < N; i++)
			p[i] = sc.nextInt();

		int ans = 0;

		for (int i = 1; i < N-1; i++)
			if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i + 1] < p[i] && p[i] < p[i - 1]))
				ans++;

		System.out.println(ans);

	}

}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}


Measured memory_bytes: 22356
import numpy as np
INF = 2**60 # 無限大を表す値
N, W = map(int, input().split())
wv = [map(int, input().split()) for i in range(N)]
dp = np.full((N+1, W+1), -INF, dtype = np.int64)
dp[0][0] = 0 # 初期条件
for i, (w, v) in enumerate(wv):
    dp[i+1] = np.maximum(dp[i+1], dp[i])
    dp[i+1][w:] = np.maximum(dp[i+1][w:], dp[i][:-w] + v)
print(np.max(dp[N][:W+1]))

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

int main() {
	int N, K;
	int p[200001];

	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> p[i];
	}

	double result = 0;
	int sum = 0;

	for (int i = 0; i < K; i++) {
		sum += (p[i] + 1);
	}

	result = sum;

	for (int i = K; i < N; i++) {
		sum -= p[i - K] + 1;
		sum += p[i] + 1;

		if (sum > result) {
			result = sum;
		}
	}


	printf("%lf\n", result/2);
}

Measured memory_bytes: 1024
#include <iostream>
#include<algorithm>
#include<cmath>
#include <string>
#include <vector>

 int main (){

	 int a, b;

	 std::cin >> a >> b;

	 if (a + 1 == b || a == b || a == b + 1) {
		 std::cout << "Yay!" << std::endl;
	 }
	 else {
		 std::cout << ":(" << std::endl;
	 }

	 return 0;
}

Measured memory_bytes: 256
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	class Point {
		int x, y;
		int t;
		int ig;
		Point(int x, int y, int t, int ig) {
			this.x =x;
			this.y = y;
			this.t = t;
			this.ig = ig;
		}
		@Override
		public boolean equals(Object obj) {
			if (obj == null || !(obj instanceof Point)) return false;
			return ((Point)obj).x == this.x && ((Point)obj).y == this.y && ((Point)obj).t == this.t && ((Point)obj).ig == this.ig;
		}
	}
	
	class MyComparator<T> implements Comparator<T> {
		@Override
		public int compare(T o0, T o1) {
			return ((Point)o0).ig-((Point)o1).ig;
		}
	}
	
	void run() {
		int INF = 1000000000;
		int pad = 101;
		int sx = sc.nextInt(), sy = sc.nextInt(), gx = sc.nextInt(), gy = sc.nextInt();
		int n = sc.nextInt();
		boolean[][] map = new boolean[2*pad][2*pad];
		for (int i = 0; i < n; i++) {
			map[sc.nextInt()+pad][sc.nextInt()+pad] = true;
		}
		int lx = sc.nextInt(), ly = sc.nextInt();
		int[][][] cost = new int[2*pad][2*pad][6];
		for (int x = -lx; x <= lx; x++)
			for (int y = -ly; y <= ly; y++)
				for (int t = 0; t < 6; t++)
					cost[x+pad][y+pad][t] = INF;
		cost[sx+pad][sy+pad][0] = 0;
		
		PriorityQueue<Point> queue = new PriorityQueue<Point>(11,new MyComparator<Point>());
		queue.add(new Point(sx, sy, 0, 0));
		
		int[] x0 = {0,1, 1, 0,-1,-1,0};
		int[] y0 = {1,0,-1,-1,-1, 0,0};
		int[] x1 = {0,1,1, 0,-1,-1,0};
		int[] y1 = {1,1,0,-1, 0, 1,0};
		
		while (!queue.isEmpty()) {
			Point p = queue.poll();
			int x = p.x, y = p.y, t = p.t;
			int d = Math.abs(t*x*y)%6;
			if (x % 2 == 0) {
				for (int i = 0; i < 7; i++) {
					int X = x+x0[i], Y = y+y0[i];
					if (X >= -lx && X <= lx && Y >= -ly && Y<= ly && !map[X+pad][Y+pad]) {
						int g = (i == d) ? 0 : 1;
						if (cost[X+pad][Y+pad][(t+1)%6] > p.ig+g) {
							cost[X+pad][Y+pad][(t+1)%6] = p.ig+g;
							queue.add(new Point(X,Y,(t+1)%6,p.ig+g));
						}
					}
				}
			} else {
				for (int i = 0; i < 7; i++) {
					int X = x+x1[i], Y = y+y1[i];
					if (X >= -lx && X <= lx && Y >= -ly && Y<= ly && !map[X+pad][Y+pad]) {
						int g = (i == d) ? 0 : 1;
						if (cost[X+pad][Y+pad][(t+1)%6] > p.ig+g) {
							cost[X+pad][Y+pad][(t+1)%6] = p.ig+g;
							queue.add(new Point(X,Y,(t+1)%6,p.ig+g));
						}
					}
				}
			}
		}
		
		int res = INF;
		for (int i = 0; i < 6; i++) {	
			res = Math.min(res, cost[gx+pad][gy+pad][i]);
		}
		if (res == INF)
			out.println(-1);
		else
			out.println(res);
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 38516
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <stdio.h>
#include <cmath>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int mn = 1001000;
    int mx = -1001000;
    long long int sum = 0;
    int a;
    for (int i = 0; i < n; i++)
    {
        cin >> a;
        mx = max(mx, a);
        mn = min(mn, a);
        sum += a;
    }

    cout << mn << " " << mx << " " << sum << endl;

    return 0;
}


Measured memory_bytes: 3108
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define fr(i,n) for(i=0;i<n;i++)
#define F first
#define S second
#define endl "\n"
#define fast std::ios_base::sync_with_stdio(false)
#define mod 1000000007
#define pi 3.14159265
#define sl(a) (int)a.length()
#define sz(a) (int)a.size()
#define all(a) a.begin(),a.end()
void shikhar7s(int cas)
{
    char c;
    cin>>c;
    cout<<char(c+1);
}
signed main()
{
    fast;
    int t=1;
    //cin>>t;
    int cas=1;
    while(cas<=t)
    {
    shikhar7s(cas);
    cas++;
    }
    return 0;
}

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

int const MAXN = 300;
int N, M, L;
int dist[MAXN][MAXN];
int main() {
  std::cin >> N >> M >> L;
  for(int i = 0; i < N; ++i) std::fill_n(dist[i], N, L+1);
  for(int i = 0; i < N; ++i) dist[i][i] = 0;
  for(int i = 0; i < M; ++i) {
    int a, b, c; std::cin >> a >> b >> c; --a; --b;
    if(c > L) continue;
    dist[a][b] = dist[b][a] = std::min(dist[a][b], c);
  }
  for(int k = 0; k < N; ++k) for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      int newc = std::min(dist[i][k]+dist[k][j], L+1);
      dist[i][j] = std::min(dist[i][j], newc);
    }
  }

  for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) {
    if(dist[i][j] <= L) dist[i][j] = 1; else dist[i][j] = N;
  }
  for(int k = 0; k < N; ++k) for(int i = 0; i < N; ++i) {
    for(int j = 0; j < N; ++j) {
      int newc = std::min(dist[i][k]+dist[k][j], N);
      dist[i][j] = std::min(dist[i][j], newc);
    }
  }

  for(int i = 0; i < N; ++i) for(int j = 0; j < N; ++j) {
    if(dist[i][j] < N) --dist[i][j];
    else dist[i][j] = -1;
  }
  int Q;
  std::cin >> Q;
  for(int i = 0; i < Q; ++i) {
    int s, t; std::cin >> s >> t; --s; --t;
    std::cout << dist[s][t] << std::endl;
  }
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  
  int count;
  for(int i = 0; i < N; i++){
    int A;
    cin >> A;
    int c = 0;
    while(A % 2 == 0){
      A /= 2;
      c++;
    }
    if(c <= count || i == 0)
      count = c;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<string> vs;
using pll = pair<ll, ll>;
using vl = vector<ll>;
using vll = vector<vl>;
using vpll = vector<pll>;
struct Edge {
	ll to;
 	ll cost;
 };
using Graph = vector<vector<Edge>>;

#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
/***** define constant start *******/
const ll MOD = 1000000007;
const double PI = 2.0 * asin(1.0);
const ll INF = LLONG_MAX;
string abc = "abcdefghijklmnopqrstuvwxyz";
string ABC = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
const ll MAX = 10000000;
/****** define constant end ********/
/****** define variable start ******/
ll a, b, h, m;
/******* define variable end *******/
int solve() {
	cin >> a >> b >> h >> m;
	long double kakudo = (long double)(h * 60 + m) / (12 * 60) * 360;
	long double kakudo2 = (long double)m / 60 * 360;
	long double hein = pow(a, 2) + pow(b, 2) - 2 * a * b * cos((long double)abs(kakudo-kakudo2)/180 * PI);
	long double hen = sqrt(hein);
	cout << hen << endl;
	return 0;
}

int main() {
	//clock_t start = clock();
	cout << std::fixed << std::setprecision(20);
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	int end_solve = solve();
	/*
	clock_t end = clock();
	const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC *
	1000.0; printf("time %lf[ms]\n", time);
	*/

	return end_solve;
}

Measured memory_bytes: 4208
n,m,q=gets.split.map(&:to_i)
s=q.times.map{gets.split.map(&:to_i)}
ans=[]
ary=[*1..m].repeated_combination(n)
ary.each do |i|
  sum=0
  s.each do |a,b,c,d|
    if i[b-1]-i[a-1]==c
      sum+=d
    end
  end
  ans << sum
end
puts ans.max


Measured memory_bytes: 15496
import sys
from functools import lru_cache


@lru_cache(maxsize=None)
def alg_memoization_recursion(lv, n, m):
    if lv == 0:
        if m <= 0:
            return 0
        else:
            return 1
    else:
        if (n + 1) // 2 == m:
            return alg_memoization_recursion(lv - 1, n // 2 - 1, m - 1) + 1
        elif (n + 1) // 2 > m:
            return alg_memoization_recursion(lv - 1, n // 2 - 1, m - 1)
        elif n == m:
            return alg_memoization_recursion(lv - 1, n // 2 - 1, n // 2 - 1) + alg_memoization_recursion(lv - 1, n // 2 - 1, m - (n // 2) - 1) + 1
        else:
            return alg_memoization_recursion(lv - 1, n // 2 - 1, n // 2 - 1) + alg_memoization_recursion(lv - 1, n // 2 - 1, m - (n // 2) - 1) + 1


def solve():
    input = sys.stdin.readline
    mod = 10 ** 9 + 7
    n, x = list(map(int, input().rstrip('\n').split()))
    t = 1
    for i in range(1, n + 1):
        t = 1 + t + 1 + t + 1
    print(alg_memoization_recursion(n, t, x))


if __name__ == '__main__':
    solve()


Measured memory_bytes: 42352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(x) (x).begin(),(x).end()
template <class T> inline bool chmin(T &a, T b) {if (a > b){a = b;return true;}return false;}
template <class T> inline bool chmax(T &a, T b) {if (a < b){a = b;return true;}return false;}

map<P, int> edge;
const int NM = 1e5 + 2;
vector<int> graph[NM];
int vdist[NM];

void dfs(int now) {
    for(auto next : graph[now]){
        if(vdist[next] >= 0) continue;
        int a=now, b=next;
        if(a>b) swap(a,b);
        int edge_size = edge[make_pair(a, b)];
        vdist[next] = vdist[now] + edge_size;
        dfs(next);
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    rep(i, n-1){
        int u,v,w; cin>>u>>v>>w;
        graph[u].push_back(v);
        graph[v].push_back(u);
        edge[make_pair(u,v)] = w;
    }
    rep(i, NM) vdist[i]=-1;
    vdist[1]=0;
    dfs(1);

    for(int i=1; i<=n; i++){
        cout<< (vdist[i]%2==0 ? 0:1)<<'\n';
    }
}
// abc126_d



Measured memory_bytes: 38016
import java.util.*;

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

    int sec = scan.nextInt();
    int hour = sec / 3600;
    sec -= hour*3600;
    int min = sec / 60;
    sec -= min*60;

    System.out.println(hour+":"+min+":"+sec);

    }
}

Measured memory_bytes: 26340
/*
AIZU ONLINE 0500

Card Game
*/

#include <stdio.h>

main()
{
	int cnt;
	int a,b;
	int totala;
        int totalb;
        int i;

	while(scanf("%d",&cnt),cnt>0)
          {totala=0;totalb=0;
            for(i=0;i<cnt;i++)
            {	scanf("%d %d ",&a,&b);

              totala += ((a>b)?(a+b):0 + (a==b)?a:0);
              totalb += ((a<b)?(a+b):0 + (a==b)?b:0);
            }
            printf("%d %d\n",totala,totalb);
          }
        return(0);
}

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

int main() {
 string a,b;
  cin>>a>>b;

  if(a.at(0)==b.at(2)&&a.at(1)==b.at(1)&&a.at(2)==b.at(0)){
    cout<<"YES"<<endl;
  }
  else{
    cout<<"NO"<<endl;
  }
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		while (!str.equals("0")) {
			int n = Integer.parseInt(str);
			String[] convBef = new String[n];
			String[] convAft = new String[n];
			for (int i = 0; i < n; i++) {
				str = br.readLine();
				String[] chara = str.split(" ");
				convBef[i] = chara[0];
				convAft[i] = chara[1];
			}
			str = br.readLine();
			int m = Integer.parseInt(str);
			for (int i = 0; i < m; i++) {
				Boolean isEqual = false;
				str = br.readLine();
				for (int j = 0; j < n; j++) {
					if (str.equals(convBef[j])) {
						System.out.print(convAft[j]);
						isEqual = true;
						break;
					}
				}
				if (!isEqual)
					System.out.print(str);
			}
			System.out.println();
			str = br.readLine();
		}
	}
}

Measured memory_bytes: 52292
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    sort(all(a));
    reverse(all(a));
    ll ans = 0;
    rep(i,N){
        if(i == 1){
            ans += a[0];
            continue;
        }
        if(i == 0) continue;
        ans += a[i/2];
    }
    cout << ans << endl;
}

Measured memory_bytes: 3944
import math
from functools import reduce
 
def gcd(*numbers):
    return reduce(math.gcd, numbers)
 
K = int(input())
B = list()
a = int()
b = int()
c = int()
ans = 0
for i in range(1,K+1):
    for j in range(1,K+1):
        for k in range(1,K+1):
            ans += gcd(i,j,k)
print(ans)

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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}

int nextInt() { int x; scanf("%d", &x); return x;}
ll nextLong() { ll x; scanf("%lld", &x); return x;}


const ll MOD = (ll)(1e9 + 7);

const int SZ = 312345;
ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}

struct mint {
  ll x;
  mint(ll x=0):x((x%MOD+MOD)%MOD){}
  mint& operator+=(const mint a) {if ((x += a.x) >= MOD) x -= MOD;return *this;}
  mint& operator-=(const mint a) {if ((x += MOD-a.x) >= MOD) x -= MOD;return *this;}
  mint& operator*=(const mint a) {(x *= a.x) %= MOD;return *this;}
  mint operator+(const mint a) const {mint res(*this);return res+=a;}
  mint operator-(const mint a) const {mint res(*this);return res-=a;}
  mint operator*(const mint a) const {mint res(*this);return res*=a;}
  mint pow(ll b) const {
    mint res(1), a(*this);
    while (b) {
      if (b & 1) res *= a;
      a *= a;
      b >>= 1;
    }
    return res;
  }
  // for prime MOD
  mint inv() const {return pow(MOD-2);}
  mint& operator/=(const mint a) {return (*this) *= a.inv();}
  mint operator/(const mint a) const {mint res(*this);return res/=a;}
};

const int MAX_N = 1005;
const int MAX_K = 22;

mint E[MAX_K][MAX_N];
mint dp[MAX_K][MAX_N];

int main2() {

  REP(i, MAX_K) REP(j, MAX_N) E[i][j] = 0;
  REP(i, MAX_K) REP(j, MAX_N) dp[i][j] = 0;

  int N = nextInt();
  int K = nextInt();
  vector<ll> a(K);
  REP(k, K) a[k] = nextInt();

  REP(k, K) {
    E[k][0] = 1;
    for (int i = 1; i <= N; i++) {
      ll rest = (a[k] - i + 1);
      mint v = (rest <= 0) ? mint(0) : mint(rest) / mint(N-i+1);
      E[k][i] = E[k][i-1] * v;
    }
  }

  dp[0][0] = mint(fact[N]);
  for (int k = 0; k < K; k++) {
    for (int n1 = 0; n1 <= N; n1++) {
      for (int n2 = 0; n1 + n2 <= N; n2++) {
        dp[k+1][n1 + n2] += dp[k][n1] * E[k][n2] * mint(fact_inv[n2]);
      }
    }
  }

  mint ans = dp[K][N];
  REP(k, K) ans *= mint(choose(N, a[k]));
  cout << ans.x << endl;

  return 0;
}

int main() {

  inv[1] = 1;
  for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;

#ifdef LOCAL
  for (;!cin.eof();cin>>ws)
#endif
    main2();
  return 0;
}


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

#define ull unsigned long long
#define ll long long
#define mod 1000000007
#define fi first
#define se second
#define pb push_back
#define mkp make_pair
#define PI acos(-1.0)
const int N=1e5 + 5;
const int M=1e5 + 5;


int main()
{
	ios_base::sync_with_stdio(false);
	int n;
	cin>>n;
	set < pair < int , int > > v;
	if(n%2==0){
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(i!=j && i+j!=n+1){
					v.insert(mkp(min(i,j),max(i,j)));
				}
			}
		}
		cout << v.size() << endl;
		while(!v.empty()){
			pair < int , int > p = *v.begin();
			v.erase(v.begin());
			cout << p.fi << " " << p.se << endl;
		}
	}
	else{
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				if(i!=j && i+j!=n){
					v.insert(mkp(min(i,j),max(i,j)));
				}
			}
		}
		cout << v.size() << endl;
		while(!v.empty()){
			pair < int , int > p = *v.begin();
			v.erase(v.begin());
			cout << p.fi << " " << p.se << endl;
		}
	}

	
		
	return 0;
}

Measured memory_bytes: 512