akhauriyash/Code-Regression huggingface dataset:
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        MyScanner in = new MyScanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        A solver = new A();
        solver.solve(1, in, out);
        out.close();
    }

    static class A {
        public void solve(int testNumber, MyScanner in, PrintWriter out) {
            int X = in.nextInt();
            int Y = in.nextInt();

            int sum = 0;
            if (X <= 3) {
                sum += (4 - X) * 100000;
            }
            if (Y <= 3) {
                sum += (4 - Y) * 100000;
            }
            if (X == 1 && Y == 1) {
                sum += 400000;
            }
            out.println(sum);
        }

    }

    static class MyScanner {
        private BufferedReader in;
        private StringTokenizer st;

        public MyScanner(InputStream stream) {
            in = new BufferedReader(new InputStreamReader(stream));
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String rl = in.readLine();
                    if (rl == null) {
                        return null;
                    }
                    st = new StringTokenizer(rl);
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
long kaijo(int n){
  long ret = 1;
  for (int i=n; i>0; i--){
    ret *= i;
  }
  return ret;
}

int main(){
  int N; cin >> N;
  vector<int>X(N);
  vector<int>Y(N);
  for (int i=0; i<N; i++){
    cin >> X[i] >> Y[i];
  }
  vector<int>perm(N);
  for (int i=0; i<N; i++){
    perm[i] = i; //perm={0,1,2,...,N-1}の配列
  }
  long double kyori=0.0;
  do{
    for (int i=0; i<N-1; i++){
      kyori += pow((X[perm[i+1]]-X[perm[i]])*(X[perm[i+1]]-X[perm[i]]) + (Y[perm[i+1]]-Y[perm[i]])*(Y[perm[i+1]]-Y[perm[i]]), 0.5);
    }
  }while(next_permutation(perm.begin(), perm.end()));
  int comb = kaijo(N);
  double ans = kyori/comb;
  printf("%f", ans);
}

Measured memory_bytes: 256
S=input()
red=0
blue=0
ans=0
for i,s in enumerate(S):
    if i==0:
        if s=='0':
            red+=1
        else:
            blue+=1
    else:
        if s=='0':
            red+=1
        else:
            blue+=1
            
        if (red>0)and(blue>0):
            ans+=2
            red-=1
            blue-=1
print(ans)

Measured memory_bytes: 3188
from math import isinf
from scipy.sparse.csgraph import shortest_path
from scipy.sparse import csr_matrix

INF = float('inf')

def main():
    N, M, L = list(map(int, input().split()))
    E = [[INF] * N for _ in range(N)]
    for _ in range(M):
        a, b, c = list(map(int, input().split()))
        E[a - 1][b - 1] = c
        E[b - 1][a - 1] = c
    EE = shortest_path(csr_matrix(E))
    E = [[1 if EE[i][j] <= L else INF for j in range(N)] for i in range(N)]
    EE = shortest_path(csr_matrix(E))
    Q = int(input())
    for _ in range(Q):
        s, t = map(int, input().split())
        x = EE[s - 1][t - 1]
        print(-1 if isinf(x) else int(x) - 1)
        

main()


Measured memory_bytes: 21164
#include <iostream>
using namespace std;
int main() {
	int a, b;
	cin >> a >> b;
	if (a == 1)
		a = 14;
	if (b == 1)
		b = 14;
	if (a > b) cout << "Alice"<<endl;
	else if (a < b)cout << "Bob"<<endl;
	else cout << "Draw" << endl;
	return 0;
}

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

int main(){
	int n;
	cin >> n;
	if(n % 1000 == 0) cout << "0" << endl;
	else cout << (1000 - (n % 1000)) << endl;
	return 0;
} 

Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <algorithm>
#include <cmath>
#include <climits>
#define REP(i, n) for(int i=0; i<(n); i++)
#define FOR(i, a, n) for(int i=(a); i<(n); i++)
using namespace std;

int main(){
    int a[] = {0, 1,3,1,2,1,2,1,1,2,1,2,1};
    int x,y; cin>>x>>y;
    string ans;
    if(a[x] == a[y]) ans = "Yes";
    else ans = "No";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define dunk(a) cout << (a) << endl
#define rall(a) (a).rbegin(),(a).rend()
const int INF = 2e9;
using namespace std;
using Graph = vector<vector<int>>;
typedef pair<int,int> P;
typedef long long ll;

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

    vector<int> s(n+1); s[0] = 0;
    rep(i,n) s[i+1] = (s[i] + a[i]) %k;

    map<int,int> mp;
    
    ll ans = 0;

    queue<int> q;

    rep(i,n+1){
        ans += mp[s[i]];
        mp[s[i]]++;
        q.push(s[i]);
        if(q.size() == k){
            mp[q.front()]--;
            q.pop();
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s, t;
	cin>>s>>t;
	int res = 0;
	for(int i = 0; i < 3; ++i){
		if(s[i]==t[i])res++;
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 256
import math
import random
import sys



def main():

    n,m,r = map(int,input().split())
    if n*m>r:
        print(0)
        return
    
    r -= n*m
    
    ans=1
    
    for i in range(r+n-1):
        ans*=i+1
    for i in range(r+1):
        if i>0:
            ans//=i
    for i in range(n-1+1):
        if i>0:
            ans//=i
            
            
    print(int(ans))
    
if __name__ == '__main__':
    main()


Measured memory_bytes: 8264
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9+7,MAX = 1e5;

int trmp[4][13];

int main()
{
	int n;
	cin >> n;
	for(int i =0;i<n;i++)
	{
		char mar;
		int num;
		cin >> mar >> num;
		num --;
		if(mar=='S')mar = 0;
		if(mar=='H')mar = 1;
		if(mar=='C')mar = 2;
		if(mar=='D')mar = 3;
		trmp[mar][num]=1;
	}
	for(int i=0;i<4;i++)
	{
		for(int j =0;j<13;j++)
		{
			if(trmp[i][j]==0)
			{
				char mar;
				if(i==0)mar = 'S';
				if(i==1)mar = 'H';
				if(i==2)mar = 'C';
				if(i==3)mar = 'D';
				cout<<mar<<' '<<j+1<<endl;
			}
		}
	}
	return 0;
}


Measured memory_bytes: 3104
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int N,K; cin>>N>>K;
	cout<<N%K<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int dp[45];

int main(){
	int n;cin >> n;
	dp[0] = dp[1] = 1;
	for(int i = 2;i <= n;i++){
		dp[i] = dp[i-1] + dp[i-2];
	}
	cout << dp[n] << endl;
	return 0;
}

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

#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
#define test cout<<"test"<<endl;
#define fi first
#define se second
typedef long long ll;
typedef long double ld;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const ll INF = 1e18;
const ll zero=0;
using P = pair<ll, ll>;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;}
void pmod(ll &a,ll b,ll c){a=(b+c)%MOD;}
void qmod(ll &a,ll b){a=(a*b)%MOD;}
void qmod(ll &a,ll b,ll c){a=(b*c)%MOD;}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x,ll y,ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}
void ans(bool x,string y,string z){if(x)cout<<y<<endl;else cout<<z<<endl;}   
ll gcd(ll x,ll y){ll r;while((r=x%y)!=0){x=y;y=r;}return y;}

int main(){
  ll i,j,o;
  ll res=0,res1=INF,res2=-INF,buf=0;
  bool judge = true;
  ll n;cin>>n;
  vector<ll>a(n);
  ll maxbuf=0,minbuf=INF;
  for(i=0;i<n;i++){
    cin>>a[i];
    chmax(maxbuf,a[i]);
    chmin(minbuf,a[i]);
  }
  for(i=0;i<n;i++){
    if(minbuf==a[i]){
      buf++;
    }
  }
  //cout<<maxbuf spa minbuf spa buf<<endl;
  if(maxbuf-minbuf==0){
    ans1(maxbuf*2<=n||maxbuf==n-1);
  }
  else{
    ans1(maxbuf-minbuf==1&&buf>=2*(minbuf+1)-n
      &&buf<=minbuf);
  }
  return 0;
}

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

int main()
{
    int n;
    std::cin >> n;
    std::vector<long long> a(n);
    std::set<long long> sa;
    std::map<long long, long long> ma;
    for(int i = 0; i < n; i++) {
        std::cin >> a[i];
        sa.insert(a[i]);
    }

    std::sort(a.begin(), a.end());

    for(auto itr = sa.begin(); itr != sa.end(); itr++) {
        int num = std::upper_bound(a.begin(), a.end(), *itr) - std::lower_bound(a.begin(), a.end(), *itr);
        if(num >= 2) {
          ma.insert(std::make_pair(*itr, num));
        }
    }

    long long ans = 1;
    int cnt2 = 0;
    bool f1 = true;
    bool f2 = false;
    if(ma.size() > 0) {
    for(auto itr = sa.rbegin(); itr != sa.rend(); itr++) {
        if(ma[*itr] >= 4 && f1) {
            ans *= (*itr)*(*itr);
            break;
        } else if(ma[*itr] >= 2) {
            f2 = true;
            f1 = false;
            ans *= *itr;
            cnt2 ++; 
        }

       
        if(cnt2 >= 2) {
           f2 = false;
            break;
        }
    }
    } else {
        ans = 0;
    }

    if (cnt2 < 2 && f2)
    {
        ans = 0;
    }

    std::cout << ans << std::endl;
   
}



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

signed main()
{
	ios::sync_with_stdio(false);
	int n,k,s;
	cin>>n>>k>>s;
	int dif=s+1;
	if(dif>1000000000) dif=1;
	for(int i=1;i<=k;i++) cout<<s<<" ";
	for(int i=1;i<=n-k;i++) cout<<dif<<" ";
	cout<<endl;	
	return 0;
}

Measured memory_bytes: 1280
# AOJ 0610: Weather Forecaster
# Python3 2018.7.2 bal4u

import sys
from sys import stdin
input = stdin.readline

h, w = map(int, input().split())
ans = [[0 for c in range(w)] for r in range(h)]
arr = [input().strip() for r in range(h)]
for r in range(h):
	p = -1
	for c in range(w):
		if arr[r][c] == 'c': p = c
		ans[r][c] = -1 if p < 0 else c-p
for r in range(h): print(*ans[r])


Measured memory_bytes: 6396
import java.util.Scanner;
class Main{
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
   int N = Integer.parseInt(sc.next());
   int A = Integer.parseInt(sc.next());
   int B = Integer.parseInt(sc.next());
   int na = N*A;
  if(na > B){
    System.out.println(B);
  }else{
    System.out.println(na);
  }
   sc.close();
 }
}

Measured memory_bytes: 23764
import java.util.*;

public class Main {
    int k;
    Queue<String> q;

    void run() {
        Scanner sc = new Scanner(System.in);
        k = sc.nextInt();
        q = new ArrayDeque<>();
        q.addAll(Arrays.asList(new String[]{"1", "2", "3", "4", "5", "6", "7", "8", "9"}));
        String next = "";
        int count = 0;

        while (count < k) {
            next = q.remove();
//            debug(q);
            count++;
            char last = next.charAt(next.length() - 1);
            if (last != '0') {
//                debug(last);
//                debug(next +  (Character.getNumericValue(last) - 1));
                q.add(next + (Character.getNumericValue(last) - 1));
            }
            q.add(next + Character.getNumericValue(last));
            if (last != '9') {

                q.add(next + (Character.getNumericValue(last) + 1));
            }
//            debug(q);

        }

        System.out.println(next);

    }

    void bfs() {


    }

    void debug(Object... os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 55252
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

const int MOD = 1e9 + 7;







int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
  LL l, d, x; cin >> l >> d >> x;
  for (int i = 0; i < 10; ++i) {
    x = l * x - d;
    cout << x << '\n';
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
int cnt[501];
bool was[501];
using namespace std;
int N;
bool can = true;
int a[250001];
int pos[500];
vector<pair<int , int> > g;
int main()
{
    memset(a , -1 , sizeof a);
    scanf("%d" , &N);
    for(int i = 1; i <= N; i++)
    {
        cnt[i] = 1;
        int x;
        scanf("%d" , &x);
        pos[i] = x;
        a[x] = i;
        g.pb(mp(x , i));
    }
    sort(g.begin() , g.end());
    for(int i = 0; i < g.size(); i++)
    {
        int curPos = g[i].first;
        int x = g[i].second;
        int cur = x;
        for(int i = 1; i < curPos; i++)
        {
            if(a[i] != -1)
                continue;
            if(cnt[cur] < cur)
            {
                a[i] = cur;
                cnt[cur]++;
            }
        }
        if(cnt[cur] != cur)
        {
            printf("No");
            return 0;
        }
    }
    for(int i = 1; i <= N; i++)
    {
        for(int j = pos[i] + 1; j <= N * N; j++)
        {
            if(a[j] != -1)
                continue;
            if(cnt[i] < N)
            {
                a[j] = i;
                cnt[i]++;
            }
        }
        if(cnt[i] < N)
        {
            printf("No");
            return 0;
        }
    }
    if(!can)
    {
        printf("No");
        return 0;
    }
    printf("Yes\n");
    for(int i = 1; i <= N * N; i++)
        printf("%d " , a[i]);
}


Measured memory_bytes: 2304
import bisect

n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        a = bisect.bisect_left(l, l[i] + l[j]) - j - 1
        ans += a
print(ans)

Measured memory_bytes: 3188
#include<stdio.h>
int main()
{   int a,b,c;
    scanf("%d%d",&a,&b);
    if(a>=1 && a<=100 && b>=1 && b<=100)
    {


    c=a+b;
    if(c%3==0 || a%3==0 || b%3==0)
        printf("Possible\n");
    else
        printf("Impossible\n");


    }
    return 0;
}


Measured memory_bytes: 128
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
using namespace std;
/***********************************************/
/* Dear online judge:
 * I've read the problem, and tried to solve it.
 * Even if you don't accept my solution, you should respect my effort.
 * I hope my code compiles and gets accepted.
 *  ___  __     _______    _______      
 * |\  \|\  \  |\  ___ \  |\  ___ \     
 * \ \  \/  /|_\ \   __/| \ \   __/|    
 *  \ \   ___  \\ \  \_|/__\ \  \_|/__  
 *   \ \  \\ \  \\ \  \_|\ \\ \  \_|\ \ 
 *    \ \__\\ \__\\ \_______\\ \_______\
 *     \|__| \|__| \|_______| \|_______|
 */
const long long mod = 1000000007;

struct PT {
	long long x, y;
	PT() :
		x(0), y(0) {
	}
	PT(long long _x, long long _y) :
		x(_x), y(_y) {
	}
	PT(const PT &p) :
		x(p.x), y(p.y) {
	}
	PT operator +(const PT &p) const {
		return PT(x + p.x, y + p.y);
	}
	PT operator -(const PT &p) const {
		return PT(x - p.x, y - p.y);
	}
	PT operator *(long long c) const {
		return PT(x * c, y * c);
	}
	bool operator<(const PT &p) const {
		return make_pair(x, y) < make_pair(p.x, p.y);
	}
	bool operator==(const PT &p) const {
		return !(*this < p) && !(p < *this);
	}
};
long long dot(PT p, PT q) {
	return p.x * q.x + p.y * q.y;
}
long long dist2(PT p, PT q) {
	return dot(p - q, p - q);
}
long long cross(PT p, PT q) {
	return p.x * q.y - p.y * q.x;
}
istream &operator>>(istream &is, PT &p) {
	return is >> p.x >> p.y;
}
ostream &operator<<(ostream &os, const PT &p) {
	return os << p.x << " " << p.y;
}
/*around the origin*/
PT RotateCCW90(PT p) {
	return PT(-p.y, p.x);
}
PT RotateCW90(PT p) {
	return PT(p.y, -p.x);
}


int main(int argc, char** argv) {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);

	PT a,b,c,d;
	cin>>a>>b;
	c = RotateCW90(a-b) + b;
	d = RotateCW90(b-c) + c;
	cout<<c<<' '<<d<<'\n';
	return 0;
}


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

using namespace std;

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

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

struct UF
{
	vector<int> par; // 親のインデックスを記憶する配列
	vector<int> sz; // サイズを記憶する。
	vector<int> rank;
	// 初期化
	UF(int n):par(n),sz(n),rank(n){
		for(int i = 0; i < n; i++){
			par[i] = i;sz[i] = 0;rank[i] = 0;
		}
	}
	// 親を求める
	int find(int x) {
		if (par[x] == x) return x;
		else return par[x] = find(par[x]);
	}
	// xとyの属する集合を併合
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y) return;
		if(rank[x] < rank[y]){
			par[x] = y;
			sz[y] += sz[x];
		}
		else{
			par[y] = x;
			sz[x] += sz[y];
			if(rank[x] == rank[y])rank[x]++;
		}
	}
	// xとyが同じ集合ならtrue
	bool same(int x, int y) { return find(x) == find(y); }
	// 素の集合のサイズを求める
	int size(int n){return sz[find(n)];}
};

int mp[222][222];
int di[222][222];
int color[222];
int used[222];
int n;
bool ng;

void dfs(int node, int c){
	color[node] = c;
	REP(i, n){
		if(mp[node][i]){
			if(color[node] == color[i]){
				ng = true;
			}
			if(color[i] == 0){
				dfs(i, -c);
			}
		}
	}
}

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

	cin >> n;
	UF uf(n);
	REP(i, n){
		string str;cin >> str;
		REP(j, n){
			mp[i][j] = str[j] - '0';
			di[i][j] = mp[i][j];
			if(mp[i][j])uf.unite(i, j);
		}
	}

	REP(i, n){
		if(color[i] == 0){
			dfs(i, 1);
		}
	}

	if(ng){
		cout << -1 << endl;
		return 0;
	}

	REP(i, n)REP(j, n)if(mp[i][j] == 0)mp[i][j] = INF;
	REP(k, n)REP(i, n)REP(j, n){
		mp[i][j] = min(mp[i][k] + mp[k][j], mp[i][j]);
	}

	REP(i, n){
		REP(j, n){
			if(i == j)continue;
			int pare = uf.find(i);
			uf.sz[pare] = max(uf.sz[pare], mp[i][j]);
		}
	}

	ll ans = 0;
	REP(i, n){
		int pare = uf.find(i);
		if(used[pare])continue;
		used[pare] = true;
		ans += uf.sz[pare] + 1;
	}

	//SHOW2d(mp, n, n);

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
#include<map>
#include<queue>
#include<cstring>
#include<stack>
#include<algorithm>
#include<vector>
using namespace std;

const int maxn = 2e5 + 5;
int father[maxn],other[maxn],pre[maxn],last[maxn],d[maxn];
int all = -1,ans = 0,n;

void build(int x,int y){
	pre[++all] = last[x];
	last[x] = all;
	other[all] = y;
}

int dfs(int x,int fa,int deep){
	int dt = last[x];
	int res = 0;
	while(dt != -1){
		int dr = other[dt];
		if(dr != fa){
			if(dr == n) ans = deep;
			father[dr] = x;
			res++;
			res += dfs(dr,x,deep + 1);
			d[x] = res;
			//d[x] += d[dr] + 1;
		}
		dt = pre[dt];
	}
	return res;
}

int main(){
	while(~scanf("%d",&n)){
		memset(last,-1,sizeof(last));
		for(int i = 1;i <= n - 1;i++){
			int x,y;
			scanf("%d %d",&x,&y);
			build(x,y);
			build(y,x);
		}	
		dfs(1,0,0);
		ans = ans / 2;
		int x = n;
		for(int  i = 1;i <= ans;i++) x = father[x];
		if(d[x] >= n - d[x] - 2) printf("Snuke\n");
		else printf("Fennec\n");
	}
}

Measured memory_bytes: 11136
import java.util.*;
public class Main {

	private boolean isRightTri(double a, double b, double c){
		final double EPS = 1.0e-08;
		double sum = Math.pow(a, 2) + Math.pow(b, 2);
		sum = Math.sqrt(sum);
		if(Math.abs(sum - c) < EPS){
			return true;
		}
		else{
			return false;
		}
	}

	public void doIt(){

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i=0; i < n; i++){
			double a = sc.nextDouble();
			double b = sc.nextDouble();
			double c = sc.nextDouble();
			if(a > c){
				double temp = a;
				a = c;
				c = temp;
			}
			if(b > c){
				double temp = b;
				b = c;
				c = temp;
			}
			if(isRightTri(a,b,c))
				System.out.println("YES");
			else
				System.out.println("NO");
		}
	}
	public static void main(String[] args) {
		Main obj = new Main();
		obj.doIt();

	}

}

Measured memory_bytes: 0
#include <bits/stdc++.h>
typedef unsigned long long ll;
#define INF 1000000000
using namespace std;
int main(void){
    int n;
    cin>>n;
    ll sum=0;
    for(int i=0;i<n;i++){
        ll val;
        cin>>val;
        sum+=val;
    }
    cout<<sum-n<<endl;
}

Measured memory_bytes: 256
h, w = map(int, input().split())
form = []
flg = 0
for i in range(h):
    form.append(input())
for i in range(h):
    for j in range(w):
        if form[i][j]==".":
            continue
        else:
            if i==0:
                if j==0:
                    if form[i][j+1]== "#" or form[i+1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                elif j==w-1:
                    if form[i][j-1]== "#" or form[i+1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                else:
                    if form[i][j-1]== "#" or form[i+1][j]=="#" or form[i][j+1]=="#":
                        continue
                    else:
                        flg=1
                        break
                        
            elif i==h-1:    
                if j==0:
                    if form[i][j+1]== "#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                elif j==w-1:
                    if form[i][j-1]== "#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                else:
                    if form[i][j-1]== "#" or form[i-1][j]=="#" or form[i][j+1]=="#":
                        continue
                    else:
                        flg=1
                        break
                
            else:
                if j==0:
                    if form[i][j+1]== "#" or form[i+1][j]=="#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                elif j==w-1:
                    if form[i][j-1]== "#" or form[i+1][j]=="#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
                else:
                    if form[i][j-1]== "#"or form[i+1][j]=="#" or form[i][j+1]=="#" or form[i-1][j]=="#":
                        continue
                    else:
                        flg = 1
                        break
    if flg ==1:
        break
    
if flg ==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3192
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(int i=1;i<=n;i++)
#define FORl(i,l,n) for(int i=l;i<n;i++)
using namespace std;
#define pi pair<ll,ll>
#define pb push_back
#define ll long long
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e14
ll mod = 1e9 + 7;

ll power(ll num,ll g,ll mod){
  if(g==0)return 1;
  if(g%2==1)return (num*power((num*num)%mod,g/2,mod))%mod;
  return power((num*num)%mod,g/2,mod);
}

int main() {
    int n;
    cin >> n;
    int t = 1000;
    while(t < n) t+= 1000;
    cout << t - n;
}

Measured memory_bytes: 3672
# F - Distinct Numbers
from bisect import bisect_left

def isOK(c, k, N, L, cum_sum):
    i = bisect_left(L, c)
    s = c * (N - i) + cum_sum[i];
    return (s >= c * k)

N = int(input())
D = list(map(int, input().split()))
freq = [0] * N
for d in D:
    freq[d - 1] += 1
    
freq.sort()
cum_sum = [0] * (N + 1)
for i in range(N):
    cum_sum[i + 1] = cum_sum[i] + freq[i]
    
for k in range(1, N + 1):
    l = 0
    r = int(N / k) + 1
    while l + 1 < r:
        c = int((l + r) / 2)
        ok = isOK(c, k, N, freq, cum_sum)
        if ok:
            l = c
        else:
            r = c
    print(l)
    

Measured memory_bytes: 37884
#include <bits/stdc++.h>
#include <unordered_map>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define LLINF 100000000000000000ll
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define all(x) (x).begin(),(x).end()
#define sq(x) ((x)*(x))
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define repn(i,a,n) for(int (i)=(a);(i)<(int)(n);(i)++)
#define EQ(a,b) (abs((a)-(b))<eps)
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 N;
string S;
string s,t;
map<pair<string,string>,int> m;
int main(){
	cin >> N;
	cin >> S;
	for(int i=0;i<N;i++){
		s+=S[i];
		t+=S[i+N];
	}
	reverse(all(t));
	for(int i=0;i<(1<<N);i++){
		string a,b;
		for(int j=0;j<N;j++){
			if((i>>j)&1)a+=t[j];
			else b+=t[j];
		}
		m[mp(a,b)]++;
	}
	ll ans = 0ll;
	for(int i=0;i<(1<<N);i++){
		string a,b;
		for(int j=0;j<N;j++){
			if((i>>j)&1)a+=s[j];
			else b+=s[j];
		}
		ans += m[mp(a,b)];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 91904
#include<iostream>
#include<cstdio>

using namespace std;

int m, n;
int main(){
    while(scanf("%d%d", &m, &n) && m && n){
        for(int i = 1; i <= m; ++i){
            for(int j = 1; j <= n; ++j){
                if(i + j & 1) cout << '.';
                else cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s=scan.nextLine();
		int c=0;
		for(int i=0;i<s.length();i++)
		{
			if(s.charAt(0)>='A' && s.charAt(0)<='Z') c=1;
		}
		if(c==1) System.out.println("A");
		else System.out.println("a");

	}

}


Measured memory_bytes: 26952
//#include<iostream>
//#include<algorithm>
//#include<string>
//#include <cmath>
//#include <vector>
#include <bits/stdc++.h>

using namespace std;

#define ll long long
#define REP(x,n) for(int x=0;x<n;x++)

// vector 操作  vector<int> data(10,5) 5が10個　data(10) 要素数10
// v.size(), v.empty(), v.insert(itr,値), v.erase(itr) (first,last),
// sort(itr), find(all(x),値),reverse(itr),accumulate(itr,0) 積算,
//v.swap
// stringも同じ itrがただの数字になる
// s.substr(n,m)n番目以降m文字取り出す　erase(n,m)も  s.find
#define vei vector<int> 
#define velli vector<long long int> 
#define pb(x) push_back(x) // 末尾にxを加える
#define pb2 pop_back() // 末尾削除
#define all(x) (x).begin(),(x).end() //イテレーター
#define be(x) (x).begin()
//auto  auto begin = v.begin()とか

// map 操作  map<string,int> mp キー=string 値=int型  pair< , >型
// 代入:mp["abc"]=123  mp.erase(キー)
// itr = mp.begin()のとき　itr->first = key, itr->second = val
// mp.find(key) itrを返す
typedef pair<int,int> P;  //q(p.first,p.second)で定義できる？

// lcm( , ) gcd( , ) 最大公約数　最小公倍数
//if(cin.eof()) break; 入力数が決まってないとき
//ifstream  whilwee(ifs>>data)

// 浮動小数点
// cout << fixed; 以下と組fみ合わせで小数点以下n桁
// cout << setprecision(n) << 値; n桁表記
// defaultfloat
int main (){
    int n;
    double m;
    cin >> n >> m;
    vei a(n);
    REP(i,n){
        cin >> a[i];
    }

    sort(all(a));
    reverse(all(a));
    
    int sou=0;
    REP(i,n){
        sou+=a[i];
    }

    int cou  = 0;

    REP(i,n){
        if(a[i]>=sou * 1/(4*m)){cou++;
        }else{
            break;
        }
    }
    if(cou>=m) {
        cout << "Yes";
    }else{
        cout << "No";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;

signed main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max((int)0, min(b, d) - max(a, c)) << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define drep(i,a,b) for(ll i=(a);i>=(b);--i)
#define SIZE(a) ll((a).size())
#define out(a) cout<<(a)<<endl;
const int inf=INT_MAX;
const int MAX = 510000;
const ll MOD = 998244353;

int main(){
  string s;cin>>s;
  ll n=s.size();
  if(s[n-1]=='s'){s+="es";}
  else{s+="s";}
  out(s);
}






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

const int INF = 1001001001;
int dist[100005][3];

int main() {
  int n, m;
  cin >> n >> m;
  vector<vector<int>> to(n);
  rep(i,m) {
    int a, b;
    cin >> a >> b;
    --a; --b;
    to[a].push_back(b);
  }
  int sv, tv;
  cin >> sv >> tv;
  --sv; --tv;
  rep(i,n)rep(j,3) dist[i][j] = INF;
  queue<P> q;
  q.push(P(sv,0));
  dist[sv][0] = 0;
  while (!q.empty()) {
    int v = q.front().first;
    int l = q.front().second;
    q.pop();
    for (int u : to[v]) {
      int nl = (l+1)%3;
      if (dist[u][nl] != INF) continue;
      dist[u][nl] = dist[v][l]+1;
      q.push(P(u,nl));
    }
  }
  int ans = dist[tv][0];
  if (ans == INF) ans = -1;
  else ans /= 3;
  cout << ans << endl;
  return 0;
}


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

int main() {
	int n;
	cin >> n;
	int c;
	cin >> c;
	int p[n];
	int w[n];
	for(int i=0;i<n;i++){
	    cin>>w[i]>> p[i];
	}

	long long int dp[n+1][c+1];
	for(int i=0;i<n+1;i++){
	    for(int j=0;j<c+1;j++){
	        if(i==0||j==0){dp[i][j]=0;}
	        else{
	            if(w[i-1]<=j){
	                dp[i][j]=max(dp[i-1][j-w[i-1]]+p[i-1],dp[i-1][j]);
	            }
	            else{
	                dp[i][j]=dp[i-1][j];
	            }
	        }
	    }
	}
	cout<<dp[n][c]<<"\n";
	
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define repin(Array,n) for(int i=0;i<n;i++){cin>>Array[i];}
using namespace std;

using ll = long long;
const int INF = 1e9 + 1;
const ll LLINF = 1e18;
const int MOD = 1e9 + 7;
using Graph = vector<vector<int>>;

int main() {

	int K, S;
	cin >> K >> S;

	int ans = 0;
	for (int i = 0; i <= K; i++)
		for (int j = 0; j <= K; j++) {
			int k = S - i - j;
			if (k >= 0&&k<=K)
				ans++;
		}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
from collections import deque
from heapq import heapify,heappop,heappush,heappushpop
from copy import copy,deepcopy
from itertools import permutations,combinations
from collections import defaultdict,Counter
from pprint import pprint

def myinput():
    return map(int,input().split())

def mycol(data,col):
    return [ row[col] for row in data ]

def mysort(data,col):
    data.sort(key=lambda x:x[col],reverse=False)
    return data

def mymax(data):
    M = -1*float("inf")
    for i in range(len(data)):
        m = max(data[i])
        M = max(M,m)
    return M

def mymin(data):
    m = float("inf")
    for i in range(len(data)):
        M = min(data[i])
        m = min(m,M)
    return m

n,m = myinput()
ab = [ list(myinput()) for _ in range(m) ]

g = [ [] for _ in range(n) ]
for i in range(m):
    a = ab[i][0] - 1
    b = ab[i][1] - 1
    g[a].append(b)
    g[b].append(a)
# print(g)

def dfs(g):
    color = [0]*n
    stack = deque()
    stack.append([0,1])
    while stack:
        tmp = stack.pop()
        v = tmp[0]
        c = tmp[1]
        color[v] = c
        for i in g[v]:
            if color[i]==c:
                return False,[]
            elif color[i]==0:
                stack.append([i,-1*c])
    return True,color

flag,color =  dfs(g)
# print(flag)
if flag:
    black = color.count(1)
    white = color.count(-1)
    ans = black * white - m
else:
    ans = n*(n-1)//2 - m
print(ans)

Measured memory_bytes: 80856
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    string S;
    cin >> S;
    if(stoi(S.substr(0, 4)) > 2019 || 
       (stoi(S.substr(0, 4)) == 2019 && stoi(S.substr(5, 2)) > 4) ||
       (stoi(S.substr(0, 4)) == 2019 && stoi(S.substr(5, 2)) == 4  && stoi(S.substr(8, 2)) > 30)) 
       cout << "TBD" << endl;
    else cout << "Heisei" << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 3608
#include<iostream>
#include<cstdio>
using namespace std;
int main(){
  int w,h,x,y;
  bool tyo=false;
  double ans,num,sx,sy,ly,ry,ux,dx;
  cin >>w >> h >> x >> y;
  ans=(double)h*(double)w/2;
  printf("%.10f ",ans);
  if(w%2==0&&h%2==0&&w/2==x&&h/2==y){
    cout << "1\n";
  }else cout <<"0\n";
}


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

int main(){
  int a, b;
  cin >> a >> b;
  b--;
  a--;
  if(b % a == 0){
    cout << b / a << endl;
    return 0;
  }
  else{
    cout << b / a + 1 << endl;
  }
}

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

int main() {
  char a, b, c;
  cin >> a >> b >> c;
  char r = 'R';
  if(a==r && b==r && c==r) cout << 3 << endl;
  else if(( a==r && b==r) || (b==r && c==r)) cout << 2 << endl;
  else if(a==r || b==r || c==r) cout << 1 << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 3620
a=int(input())
b=int(input())
c=int(input())
d=int(input())
e=int(input())
k=int(input())

p1=abs(a-b)
p2=abs(a-c)
p3=abs(a-d)
p4=abs(a-e)
p5=abs(b-c)
p6=abs(b-d)
p7=abs(b-e) 
p8=abs(c-d)
p9=abs(c-e)
p10=abs(d-e)

if((p1>k) or (p2>k) or (p3>k) or (p4>k) or (p5>k) or (p6>k) or (p7>k) or (p8>k) or (p9>k) or (p10>k)):
    print(":(")
else:
    print("Yay!")


Measured memory_bytes: 3064
#include<iostream>
using namespace std;
int a[100005];
int main()
{
    int n;
    cin>>n;
    int x;
    for(int i=1;i<=n;i++)
    {
        cin>>x;
        a[x]=i;
    }
    for(int i=1;i<=n;i++)
    {
        if(i-1)cout<<" ";
        cout<<a[i];
    }
}


Measured memory_bytes: 1152
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var a = input[0];
            var b = input[1];

            var ans = a - 2 * b;
            Console.WriteLine(ans < 0 ? 0 : ans);
        }
    }
}


Measured memory_bytes: 11348
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define all(x) x.begin(),x.end()
#define pll  pair <long long,long long>
#define ss second
#define ff first
#define inf 9223372036854775807
#define maa 1000000007
#define ld long double
#define fast  ios_base::sync_with_stdio(false);cin.tie(NULL);
#define bug(x) cout << #x <<": " << x << '\n';
const ll N=200001 ;
int main()
{
   fast ;
   ///Mission-500
   ll n ;
   cin>>n ;
   string r,s ;
   cin>>r>>s ;

   for(ll i=0;i<2*n;i++)
   {
       if(i%2==0)
       {
           cout<<r[i/2] ;
       }
       else
       {
           cout<<s[i/2] ;
       }
   }

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
using namespace std;
int main(){
  string s;
  int a=0,b=0,i;
  cin >> s;
  for(i=0;i<s.size();i++){
    if(s[i]=='0'){
      a++;
    }
    else{
      b++;
    }
  }
  printf("%d\n",min(a,b)*2);
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  
  int a, b;
  vector<int> x(n);
  vector<int> y(n);
  for(int i=0; i<n; i++) cin >> x[i] >> y[i];
  
  int fact = 1;
  for(int i=1; i<=n; i++) fact *= i;
  
  //n*(n-1)/2 組合せの数
  //(n-1)*fact 2点を結ぶ経路の総数
  double dist, sum = 0;
  for(int i=0; i<n-1; i++) {
    for(int j=i+1; j<n; j++) {
      dist = sqrt((x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]));
      sum += dist * ((n-1)*fact) / (n*(n-1)/2);
    }
  }
  
  cout << fixed << setprecision(10) << sum/fact << endl;
  return 0;
}

Measured memory_bytes: 3812
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		int N = stdIn.nextInt();
		int K = stdIn.nextInt();
		String S = stdIn.next();
		String[] words = S.split("", 0);
		if(words[K-1].equals("A")) {
			words[K-1] = "a";
		}
		else if(words[K-1].equals("B")) {
			words[K-1] = "b";
		}
		else if(words[K-1].equals("C")) {
			words[K-1] = "c";
		}
		for(int i = 0; i < N; i++) {
			System.out.print(words[i]);
		}

	}

}

Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(a,n) for (int a = 0; a < (n); ++a)
using namespace std;
using ll = long long;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;


int main(){
    ll x;
    cin >> x;
    for(int i=1;i<1e7;i++){
        if(i*(i+1)>=x*2){
            cout << i << endl;
            return 0;
        }
    }


    return 0;
}

Measured memory_bytes: 3604
import collections
import itertools
import functools
import math
import scipy.special

if __name__ == "__main__":
    k, s = map(int, input().split())
    res = 0
    for i in range(k + 1):
        for j in range(k + 1):
            if 0 <= s - i - j <= k:
                res += 1
    print(res)

Measured memory_bytes: 14592
n = int(input())
dp = [i for i in range(n + 1)]

for i in range(1, n + 1):
  for j in range(1, i + 1):
    if i >= 9**j:
      dp[i] = min(dp[i], dp[i - 9**j] + 1)
    else:
      break
  for k in range(1, i + 1):
    if i >= 6**k:
      dp[i] = min(dp[i], dp[i - 6**k] + 1)
    else:
      break

print(dp[-1])

Measured memory_bytes: 7064
<?php
/**
 * ABC133
 * B - Good Distance
 */

// $s = trim(fgets(STDIN));
// fscanf(STDIN, "%d %d", $a, $b);
// $n = array_map('intval', explode(' ', trim(fgets(STDIN))));

fscanf(STDIN, "%d %d", $N, $D);
for ($i = 0; $i < $N; $i++) {
    $X[$i] = array_map('intval', explode(' ', trim(fgets(STDIN))));
}

$count = 0;
for ($i = 0; $i < $N - 1; $i++) {
    for ($j = $i + 1; $j < $N; $j++) {
        $distance = 0;
        for ($k = 0; $k < $D; $k++) {
            $distance += pow(abs($X[$i][$k] - $X[$j][$k]), 2);
        }
        if (is_pythagoras($distance)) $count++;
    }
}

echo $count, PHP_EOL;

function is_pythagoras($number) {
    for ($i = 0; pow($i, 2) <= $number; $i++) {
        if (pow($i, 2) === $number) return true;
    }
    return false;
}


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

ll n,k;

int main(){
  cin >> n >> k;
  vector<int> cnt(50);
  for(int i=0;i<50;i++) cnt[i]=0;
  vector<ll> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  for(int i=0;i<n;i++){
    std::stringstream ss;
    ss << static_cast<std::bitset<50> >(a[i]);
    std::string x_bin = ss.str();
    for(int i=0;i<50;i++){
      if(x_bin[i] == '1'){
        cnt[i]++;
      }
    }
  }

  ll ans=0;
  std::stringstream ss;
  ss << static_cast<std::bitset<50> >(k);
  std::string x_bin = ss.str();
  bool first = false;
  for(int i=0;i<50;i++){
    // if(x_bin[i] == '1' && cnt[i]<=n/2){
    if(cnt[i]<=n/2){
      ans += pow(2,49-i);
      if(ans > k){
        ans -= pow(2,49-i);
      }
    }
  }
  // cout << ans << endl;
  ll ret=0;
  for(int i=0;i<n;i++){
    ret += ans ^ a[i];
  }
  cout << ret <<endl;
  return 0;
}


Measured memory_bytes: 1024
#!/usr/bin/env python
# coding: utf-8

def ri():
    return int(input())

def rl():
    return list(input().split())

def rli():
    return list(map(int, input().split()))

def main():
    n = ri()
    lp = rli()
    ls = sorted(lp)
    cnt = 0
    for p, s in zip(lp, ls):
        if p != s:
            cnt += 1
    if cnt <= 2:
        print("YES")
    else:
        print("NO")


if __name__ == '__main__':
    main()


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

int main(){

    int a,b;
    cin >> a >> b;


    for(int i=1;i<=10000;i++){
        if((int)(i*0.08)==a&&(int)(i*0.10)==b){
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

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

using namespace std;

typedef long long ll;

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

    int N = S.size();

    vector<int> v(N, 0);
    for(int i = 0 ; i < N; i++) {
        v[i] = S[i] == 'L' ? 0 : 1;
    }

    vector<int> r;
    vector<int> ind;
    int checker = 1;
    int sum = 0;
    for(int i = 0; i < N; i++) {
        if(v[i] == checker) sum++;
        else {
            if(checker == 1) ind.push_back(i);
            r.push_back(sum);
            sum = 1;
            checker = (checker + 1) % 2;
        }
    }
    r.push_back(sum);


    vector<int> ret(N, 0);
    for(int i = 0; i < r.size(); i+=2) {
        int count_r = r[i];
        int count_l = r[i+1];
        
        int big, small;
        if((count_r + count_l) % 2 == 0) {
            big = small = (count_r + count_l) / 2;
        } else {
            big = (count_r + count_l) / 2 + 1;
            small = (count_r + count_l) / 2 ;
        }


        if(count_r % 2 == count_l % 2) {
            ret[ind[i/2]] = big;
            ret[ind[i/2] - 1] = big;
        } else if(count_r > count_l) { 
            if(count_r % 2 == 0) {
                ret[ind[i/2]] = big;
                ret[ind[i/2] - 1] = small;
            } else {
                ret[ind[i/2]] = small;
                ret[ind[i/2] - 1] = big;
            }
        } else if(count_r < count_l) { 
            if(count_l % 2 == 0) {
                ret[ind[i/2]] = small;
                ret[ind[i/2] - 1] = big;
            } else {
                ret[ind[i/2]] = big;
                ret[ind[i/2] - 1] = small;
            }
        }
    }

    for(int i = 0; i < N; i++) {
        cout << ret[i] << " ";
    }

}

Measured memory_bytes: 2168
#include <iostream>
#include <map>
using namespace std;
typedef long long ll;
ll n, res;
map<string, ll> mpm, mpu;
string str, mae, ush, rev, nat;

void dfsa(ll x, ll y) {
	if (x == n) {
		mpm[nat + rev + to_string(y)]++;
	} else {
	    nat += mae[x];
	    dfsa(x + 1, y + 1);
	    nat.pop_back();
		rev = mae[x] + rev;
		dfsa(x + 1, y);
		rev.erase(rev.begin());
	}
}

void dfsb(ll x, ll y) {
	if (x == n) {
		mpu[nat + rev + to_string(y)]++;
	} else {
		nat += ush[n - 1 - x];
		dfsb(x + 1, y + 1);
		nat.pop_back();
		rev = ush[n - 1 - x] + rev;
		dfsb(x + 1, y);
		rev.erase(rev.begin());
	}
}

int main(void) {
	cin >> n >> str;
	mae = str.substr(0, n);
	ush = str.substr(n, n);
	dfsa(0, 0);dfsb(0, 0);
	for (auto itr = mpm.begin(); itr != mpm.end(); ++itr) {
		res += itr->second * mpu[itr->first];
	}
	cout << res << endl;
}


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

int main() {
  int r;
  cin >> r;
  if (r < 1200) {
    cout << "ABC\n";
    return 0;
  }
  if (r < 2800) {
    cout << "ARC\n";
    return 0;
  }
  cout << "AGC\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// ==================================================
using i64 = int64_t;
using u64 = uint64_t;
#define rep(i,a,b) for(i64 i=(int64_t)(a);i<(int64_t)(b);i++)
#define repn(i,n) rep(i,0,n)
#define din(t, ...) t __VA_ARGS__;_din(__VA_ARGS__)
#define v(t,n) vector<t> n
void _din() {}
void dout() { cout << endl; }
template <typename T, typename ... Args> inline void _din(T& head, Args& ... rest) { cin >> head; _din(rest...); }
template <typename T, typename ... Args> inline void dout(T head, Args ... rest) { cout << head; if (sizeof...(rest)) cout << ' '; dout(rest...); }
template <typename T>inline void qsortv(vector<T>& v) { qsort(v.data(), v.size(), sizeof(T), [](const void*a, const void*b)->int {if ((*(T*)a) < (*(T*)b))return -1; if ((*(T*)a) == (*(T*)b))return 0; return 1; }); }
template <typename T, typename F>inline void qsortv(vector<T>& v, F func) { qsort(v.data(), v.size(), sizeof(T), func); }
template <typename T>inline void sortv(vector<T>& v) { sort(v.begin(), v.end()); }
// ==================================================

int main()
{
	din(int, a1, a2, a3);
	int t1 = max(a1, max(a2, a3));
	int t3 = min(a1, min(a2, a3));
	dout(t1 - t3);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){

  int Day,A,B,Aper,Bper,Aday,Bday,plus;

  scanf("%d %d %d %d %d",&Day,&A,&B,&Aper,&Bper);

  Aday=A/Aper;
  Bday=B/Bper;

  if(A%Aper != 0) Aday++;
  if(B%Bper != 0) Bday++;

  if(Aday > Bday){

    plus=Aday;

  } else {

    plus=Bday;

  }

  printf("%d\n",Day-plus);

  return 0;

}

Measured memory_bytes: 596
import sys
import itertools

input = sys.stdin.readline
int1 = lambda x: int(x) - 1

H, W, M = map(int, input().split())
rows, columns = [0] * H, [0] * W
Bomb = set()
for _ in range(M):
    h, w = map(int1, input().split())
    rows[h] += 1
    columns[w] += 1
    Bomb.add((h, w))

r_first = []
r_max = max(rows)
for i, x in enumerate(rows):
    if x == r_max:
        r_first.append(i)

c_first = []
c_max = max(columns)
for i, x in enumerate(columns):
    if x == c_max:
        c_first.append(i)

ans = r_max + c_max - 1
for i, j in itertools.product(r_first, c_first):
    if (i, j) not in Bomb:
        ans = r_max + c_max
        break
print(ans)


Measured memory_bytes: 88156
#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;


int lcs(string x, string y){
    int m = x.size();
    int n = y.size();
    int c[m+1][n+1];
    x = ' ' + x;
    y = ' ' + y;
    int maxv = 0;
    rep(i, m+1) c[i][0] = 0;
    for(int i = 1; i<=n; i++) c[0][i] = 0;
    for(int i = 1; i <= m; i++){
        for(int j = 1; j <= n; j++){
            if(x[i] == y[j]) c[i][j] = c[i-1][j-1] + 1;
            else c[i][j] = max(c[i-1][j], c[i][j-1]);
            maxv = max(maxv, c[i][j]);
        }
    }
    return c[m][n];
}

int main(){
    int n, ans;
    cin >> n;
    rep(i, n){
        string x, y;
        cin >> x >> y;
        ans = lcs(x, y);
        cout << ans << endl;
    }
}


Measured memory_bytes: 7080