akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int A;
    int B;
  int C;
  int K;
  cin >>A>>B>>C>>K;
if (K<A+B&&A<K)
 cout <<A<<endl;
  else if (A==K)
    cout <<A<<endl;
  
  else if (K<A&&K!=0)
cout <<K<<endl;
  else if (A==0&&C==0)
    cout <<0<<endl;
 
  else if (A==0&&B==0&&K>C)
    cout <<-C<<endl;
  else if (K==0)
    cout <<0<<endl;
  else if (A+B+C<K)
    cout <<A-C<<endl;
  
  else 
    cout <<A-(K-(A+B))<<endl;
}

Measured memory_bytes: 3592
#include <iostream>

using namespace std;

int main(void) {
    int A, B;
    cin >> A >> B;
    if(A%3 == 0 || B%3 == 0 || (A+B)%3 == 0) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
    int A,B,C,D;
    int ab,ac,bc;
    cin>>A>>B>>C>>D;

    ac=C-A;
    ab=B-A;
    bc=C-B;

    if(ac < 0){
        ac *= -1;
    }
    if(bc < 0){
        bc *= -1;
    }

    if(ab < 0){
        ab *= -1;
    }


    if(ac <= D || (bc <= D && ab <=D) ){
        cout<< "Yes" <<endl;
    }else{
        cout<< "No" <<endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
#define int long long
using namespace std;
typedef pair<int,int>P;
typedef pair<int,P>P2;
#define fi first
#define se second
 
signed main(){
  int n,k;
  cin>>n>>k;
 
  if(k==0){
    r(i,(1<<n)){
      if(i)cout<<' ';
      cout<<i<<' '<<i;
    }
    cout<<endl;
    return 0;
  }
 
  if(pow(2,n)<=k){
    cout<<-1<<endl;
    return 0;
  }
 
  int s=0;
  r(i,(1<<n))if(i!=k)s^=i;
 
 
  if(s!=k){
    cout<<-1<<endl;
    return 0;
  }
 
  cout<<k;
  for(int i=(1<<n)-1;i>=0;i--){
    if(i==k)continue;
    cout<<' '<<i;
  }
  cout<<' '<<k;
  r(i,(1<<n)){
    if(i==k)continue;
    cout<<' '<<i;
  }
  cout<<endl;
 
}

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

using namespace std;

bool Bsearch(int key, int A[], int len) {
	int l = 0, r = len - 1;
	while (l <= r) {
		int mid = l + (r - l) / 2;
		if (A[mid] > key)
			r = mid - 1;
		else if (A[mid] < key)
			l = mid + 1;
		else
			return true;
	}
	return false;
}

int main() {
	int n, *S;
	int q, *T;
	int ans = 0;
	cin >> n;
	S = new int[n];
	for (int i = 0; i < n; i++)
		cin >> S[i];
	cin >> q;
	T = new int[q];
	for (int i = 0; i < q; i++)
		cin >> T[i];

	sort(S, S + n);
	for (int i = 0; i < q; i++)
		for (int j = 0; j < n; j++)
			if (Bsearch(T[i], S, n) == true) {
				ans++;
				break;
			}

	cout << ans << endl;
	delete[] S;
	delete[] T;
	return 0;
}

Measured memory_bytes: 1532
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long int
#define mod 1000000007
#define string_mod 2549536629329_base_255
#define pb push_back
#define F first
#define S second
#define ff first
#define endl "\n"
#define ss second
#define all(v) v.begin(), v.end()
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
int power(int x, unsigned int y, int p)
{
    int res = 1;
    x = x % p;
    while (y > 0)
    {

        if (y & 1)
            res = (res * x) % p;

        y = y >> 1;
        x = (x * x) % p;
    }
    return res;
}
int lcm(int a, int b)
{
    return (a * b) / __gcd(a, b);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int tc;
    tc = 1;
    while (tc--)
    {
        char c;
        cin >> c;
        c++;
        cout << c;
    }

    return 0;
}

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

//使い方がよくわからない
#include<stack>
#include<queue>
#include<bitset>
#include<sstream>

#define rep(i,n) for(int i=0;i<(n);i++) 
#define rep1(i,n) for(int i=1;i<(n);i++)
#define co(x) cout << x << endl
#define cosp(x) cout << x << " "

using namespace std;
using ll = long long;

int main(int argc, const char *argv[]){
    int r;
    cin >> r;
    co(r*r);
    return 0;
}

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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

typedef long long LL;
typedef pair<int, int> pii;

const int INTINF = int(1e9) + 1;
const LL LLINF   = LL(1e18) + 1;
#define pow10(n) int(1e##n + n)

void solve()
{
    string S;
    cin >> S;
    deque<char> dq;

    for (auto ch : S) dq.push_back(ch);

    int Q;
    cin >> Q;
    bool rev = false;

    REP0 (i, Q)
    {
        int T;
        cin >> T;
        if (T == 1)
            rev = !rev;
        else
        {
            int F;
            cin >> F;
            char s;
            cin >> s;
            if ((F == 1) ^ rev)
                dq.push_front(s);
            else
                dq.push_back(s);
        }
    }

    int sz = dq.size();

    if (rev)
        for (int i = sz - 1; i >= 0; i--)
        {
            cout << dq[i];
        }
    else
        for (int i = 0; i < sz; i++)
        {
            cout << dq[i];
        }

    cout << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


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

class Main {
    public static void main(String[] args) throws IOException {
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int test_cases = 1;
        Solver s = new Solver();
        for (int i = test_cases; i >= 1; i--) {
            s.solve(1, in, out);
        }
        out.close();
    }

    static class Solver {

        public void solve(int test_number, InputReader in, PrintWriter out) throws IOException {
                char[] s = in.next().toCharArray();
                out.println(check(s) ? "Yes" : "No");
        }

        private boolean check(char[] s) {
            for (int i = 0; i < s.length / 2; i++) if (s[i] != s[s.length - i - 1]) return false;
            return true;
        }
    }
    static class InputReader {
        BufferedReader br;
        StringTokenizer st;

        public InputReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong()
        {
            return Long.parseLong(next());
        }

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

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 21460
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
using namespace std;
using Int = long long;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,f,t) for(int i=f;i<t;i++)
#define P(ary) do { for(auto i:ary){ cout << i << " "; } cout << endl; } while (0)
const int MOD = 1000000007;
int main()
{
    int N; cin >> N;
    string s1, s2; cin >> s1 >> s2;
    int idx = 0;
    vector<Int> pats(9);
    //    0   1   2   3   4   5   6   7   8
    // { 11, 22, 33, 12, 23, 31, 21, 13, 32 };
    if (s1[0] == s2[0]) {
        pats = { 1, 1, 1, 0, 0, 0, 0, 0, 0 };
        idx += 1;
    } else {
        pats = { 0, 0, 0, 1, 1, 1, 1, 1, 1 };
        idx += 2;
    }
    while (idx < s1.size()) {
        if (s1[idx] == s2[idx]) {
            pats = {
                (pats[1] + pats[2] + pats[4] + pats[8]) % MOD,
                (pats[0] + pats[2] + pats[5] + pats[7]) % MOD,
                (pats[0] + pats[1] + pats[3] + pats[6]) % MOD,
                0, 0, 0, 0, 0, 0
            };
            idx += 1;
        } else {
            pats = {
                0, 0, 0,
                (pats[2] + pats[4] + pats[5] + pats[6]) % MOD,
                (pats[0] + pats[3] + pats[5] + pats[8]) % MOD,
                (pats[1] + pats[3] + pats[4] + pats[7]) % MOD,
                (pats[2] + pats[3] + pats[7] + pats[8]) % MOD,
                (pats[1] + pats[5] + pats[6] + pats[8]) % MOD,
                (pats[0] + pats[4] + pats[6] + pats[7]) % MOD
            };
            idx += 2;
        }
    }
    cout << accumulate(pats.begin(), pats.end(), (Int)0) % MOD << endl;
    return 0;
}

Measured memory_bytes: 256
S=input()
S_len=len(S)
flag_1=True
flag_2=True
flag_3=True

for i in range(S_len):
  if S[i]!=S[S_len-1-i]:
    flag_1=False
for i in range(int((S_len-1)/2)):
  if S[i]!=S[int((S_len-1)/2)-1-i]:
    flag_2=False
for i in range(int((S_len-1)/2)):
  if S[int((S_len+3)/2)-1+i]!=S[S_len-1-i]:
    flag_3=False
flag=flag_1*flag_2*flag_3
if flag==True:
  print('Yes')
else:
  print('No')

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

N, M, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))


a = [0]
b = [0]

for i in range(N):
    a.append(a[-1] + A[i])


for i in range(M):
    b.append(b[-1] + B[i])

ret = 0
j = M
for i in range(N+1):
    if a[i] > K:
        break
    while a[i] + b[j] > K:
        j -= 1

    ret = max(i+j, ret)


print(ret)


Measured memory_bytes: 127192
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, n) for (int i = 0; i < (n); i++)
 
int main(){
    int a,b;
    cin >> a >> b;
    if(a < 10 && b < 10){
        cout << a * b;
    }else{
        cout << -1;
    }
    return 0;
}

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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

int main() {
    int X, Y;
    cin >> X >> Y;
    for (int i = 0; i <= X; i++) {
        int j = X - i;
        if (i * 2 + j * 4 == Y) {
            cout << "Yes" << endl;
            return 0;
        }
    }

    cout << "No" << endl;
}


Measured memory_bytes: 3600
N = int(input())

def dfs(s):
  #文字列sで始まる七五三数の個数
  if int(s) > N:
    return 0
  
  # s自体が七五三数なら+1
  ret = 1 if all(s.count(c) > 0 for c in '753') else 0
  
  return ret + sum((dfs(s+c) for c in '753'))

print(dfs('0'))

Measured memory_bytes: 9156
#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
const int maxn=1e6+7;
typedef long long ll;
const int mod=1e9+7;
///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair<ll,ll>
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

double a[17];
char s[107];
int Sheryang(){

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

    double ans=0;
    for(int i=1;i<=n;i++){
        scanf("%lf %s",&a[i],s);
        if(s[0]=='J')
            ans+=a[i];
        else if(s[0]=='B')
            ans+=1.0*380000*a[i];
    }
    printf("%.10f",ans);

    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
	int a,b,d,r;
	double f;
	Scanner scan = new Scanner(System.in);
	
	a= Integer.parseInt(scan.next());
	b= Integer.parseInt(scan.next());
	d=a/b;
	r=a%b;
	f=(double)a/(double)b;

	
	System.out.printf("%d %d %.5f",d,r,f);
	}
	
}

Measured memory_bytes: 26460
// j > iのとき、 j - i = A[i] + A[j]
// i + A[i] = j - A[j]
// この式を満たすとき、かならずj > iになる(j < iとすると、j - A[j] < j , i + A[i] < j , i < jとなり矛盾)
#include <bits/stdc++.h>
using namespace std;

int main() {
    int N;
    cin >> N;
    map<long long, long long> L, R;
    for(int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        ++L[i + 1 + A];
        ++R[i + 1 - A];
    }
    long long res = 0;
    for(auto &p : L) {
        res += p.second*R[p.first];
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 37952
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
#define showmap(is, js, x) {rep(i, is){rep(j, js){cout << x[i][j] << " ";}cout << endl;}}
#define show(x) {for(auto i: x){cout << i << " ";} cout<<endl;}
#define showm(m) {for(auto i: m){cout << m.x << " ";} cout<<endl;}
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> llP;
ll gcd(int x, int y){ return y?gcd(y, x%y):x;}
ll lcm(ll x, ll y){ return (x*y)/gcd(x,y);}

ll calc(int x){
    vector<ll> num(5, 0);
    ll tmp = 1;
    for (int i = 0; i < 5; i++)
    {
        tmp *= x;
        num[i] = tmp;        
    }
    
    ll ans = num[4];
    return ans;
}


int main()
{
    ll x;
    cin >> x;

    //(a+1)^5 - (a)^5

    for (int a = -240; a < 240; a++)
    {
        for (int b = -240; b < 240; b++)
        {
            if (calc(a)-calc(b) == x){
                cout << a << " " << b << endl;
                return 0;
            }
        }
        
    }
    

}



Measured memory_bytes: 3592
#include<iostream>
using namespace std;
#define int long long
#define MOD (long long)(1e9+7)
#define MAX_V (long long)(1e5*2+200)

long long MAX_VAL, MAX_VAL2;
long long fac[MAX_V], mmi[MAX_V], temp[MAX_V];

inline void factorial(){
	fac[0] = fac[1] = 1;
	for(long long i = 2; i < MAX_VAL; fac[i]%=MOD,i++)
		fac[i] = fac[i-1]*(i%MOD);
}

inline long long power_mod(long long x, long long n){
	long long ans = 1;
	for(;n;n>>=1,x*=x,ans%=MOD,x%=MOD)
		if(n&1)ans*=x;
	return ans%MOD;
}

inline void modular_multiplicatibe_inverse(){
	mmi[MAX_VAL2-1] = power_mod(fac[MAX_VAL2-1],MOD-2);
	for(long long i = MAX_VAL2-2; i >= 0; mmi[i]%=MOD,i--)
		mmi[i] = mmi[i+1]*((i+1)%MOD);
}

inline long long combination(long long n, long long r){
	return fac[n]*(mmi[r]*mmi[n-r]%MOD)%MOD;
}

signed main(){
	int H, W, A, B, ans = 0;
	cin>>H>>W>>A>>B;
	MAX_VAL = max(W+H-A-2,A+W-1)+30;
	MAX_VAL2 = max(max(W-B+1,W-1),max(H-A-1, A-1))+10;
	
	factorial();
	modular_multiplicatibe_inverse();

	for(int i = B+1; i <= W; ans%=MOD,i++)
		ans += combination(H-A+i-2,H-A-1)*combination(W+A-i-1,A-1)%MOD;
	cout<<ans<<endl;

}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
#define REP(i,N) for(i=0;i<N;i++)
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL;
  typedef pair<ll,char> PLC;
  typedef pair<char,ll> PCL;
 
class UnionFind{
  public:
    //親の番号を格納．親の場合は-(その集合のサイズ)
    vector<int> Parent;
    int count;
    //作るときはParentの値をすべて-1にする
    UnionFind(int N){
      Parent = vector<int>(N,-1);
      count = N;
    }

    //親を求める
    int find(int x){
      if(Parent[x] < 0) return x;
      //親の紐づけを変更
      return Parent[x] = find(Parent[x]);
    }

    //xの属する集合のサイズを取ってくる
    int size(int x){
      return -Parent[find(x)];
    }

    //xとyの属する集合を併合
    //併合できたらtrue，すでに併合していたらfalse 
    bool unite(int x, int y){
      //xとyを直接つけない，親同士をつける
      x = find(x);
      y = find(y);
      if(x==y) return false;

      //大きいほうに小さいほうをくっつける
      if(size(x) < size(y)) swap(x,y);

      //xのサイズを更新
      Parent[x] += Parent[y];
      Parent[y] = x;
      count--;
      return true;
    }

    //xとyが同じ集合に属するか
    bool same(int x, int y){
      return find(x) == find(y);
    }
};

int main(void){
  int N,M;cin >> N >> M;
  UnionFind uni = UnionFind(N+1);
  vector<vector<int> > diff(N+1,vector<int>(0));
  queue<PII> que;
  int i;
  REP(i,M){
    int x,y,z; cin >> x >> y >> z;
    uni.unite(x,y);
  }
  cout << uni.count-1 << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    map<ll,ll> m;
    ll sum=0;
    for(int i=0;i<n;i++)
    {
        ll a;
        cin >> a;
        m[a]++;
        sum+=a;
    }
    int q;
    cin >> q;
    while(q--)
    {
        ll b,c;
        cin >> b >> c;
        sum-=m[b]*b;
        sum+=m[b]*c;
        m[c]+=m[b];
        m.erase(b);
        cout << sum << "\n";
    }
    return 0;
}


Measured memory_bytes: 7572
class Combination:
    def __init__(self, size, mod=10**9 + 7):
        self.size = size + 2
        self.mod = mod
        self.fact = [1, 1] + [0] * size
        self.factInv = [1, 1] + [0] * size
        self.inv = [0, 1] + [0] * size

        for i in range(2, self.size):
            self.fact[i] = self.fact[i - 1] * i % self.mod
            self.inv[i] = -self.inv[self.mod % i] * (self.mod // i) % self.mod
            self.factInv[i] = self.factInv[i - 1] * self.inv[i] % self.mod

    def npr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * self.factInv[n - r] % self.mod

    def ncr(self, n, r):
        if n < r or n < 0 or r < 0:
            return 0
        return self.fact[n] * (self.factInv[r] * self.factInv[n - r] % self.mod) % self.mod

    def nhr(self, n, r):  # 重複組合せ
        return self.ncr(n + r - 1, n - 1)

    def factN(self, n):
        if n < 0:
            return 0
        return self.fact[n]

N = int(input())
MOD = 10**9 + 7
comb = Combination(N + 100)

edges = [[] for _ in range(N + 1)]
for _ in range(N - 1):
    fr, to = map(int, input().split())
    edges[fr].append(to)
    edges[to].append(fr)

parent = [0] * (N + 1)
order = []
st = [1]
while st:
    now = st.pop()
    order.append(now)
    for to in edges[now]:
        if to == parent[now]:
            continue
        st.append(to)
        parent[to] = now

size = [1] * (N + 1)
for v in order[::-1]:
    size[parent[v]] += size[v]

dp = [1] * (N + 1)
for v in order[::-1]:
    dp[v] = dp[v] * comb.fact[size[v] - 1] % MOD
    dp[parent[v]] *= dp[v] * comb.factInv[size[v]]

ans = [1] * (N + 1)
dpL = [[] for _ in range(N + 1)]
dpR = [[] for _ in range(N + 1)]
eToI = [{to: i for i, to in enumerate(edges[v])} for v in range(N + 1)]

for v in order:
    pr = parent[v]
    M = len(edges[v])
    L = [1] * (M + 1)
    R = [1] * (M + 1)

    for i, to in enumerate(edges[v]):
        if to == pr:
            j = eToI[pr][v]
            L[i + 1] = L[i] * dpL[pr][j] * dpR[pr][j + 1] * comb.fact[N - size[v] - 1] * comb.factInv[N - size[v]] % MOD
        else:
            L[i + 1] = L[i] * dp[to] * comb.factInv[size[to]] % MOD
    for i, to in enumerate(edges[v][::-1]):
        if to == pr:
            j = eToI[pr][v]
            R[i + 1] = R[i] * dpL[pr][j] * dpR[pr][j + 1] * comb.fact[N - size[v] - 1] * comb.factInv[N - size[v]] % MOD
        else:
            R[i + 1] = R[i] * dp[to] * comb.factInv[size[to]] % MOD

    dpL[v] = L
    dpR[v] = R[::-1]
    ans[v] = R[-1] * comb.fact[N - 1] % MOD

print(*ans[1:], sep='\n')

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

int main() {
    ll N, K;
    cin >> N >> K;
    int A[N];
    unordered_map<int, vector<int>> d;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        d[A[i]].push_back(i);
    }
    ll a = K - 1, b = 0;
    unordered_set<int> s;
    while (a) {
        if (b == N) {
            a--;
            b = 0;
            continue;
        }
        if (s.count(b)) {
            a %= (K - 1 - a);
            break;
        }
        else s.insert(b);
        vector<int> l = d[A[b]];
        auto i = upper_bound(l.begin(), l.end(), b);
        if (i == l.end()) {
            a--;
            b = 1 + l[0];
        }
        else b = *i + 1;
    }
    while (a) {
        vector<int> l = d[A[b]];
        auto i = upper_bound(l.begin(), l.end(), b);
        if (i == l.end()) {
            a--;
            b = 1 + l[0];
        }
        else b = *i + 1;
    }
    vector<int> ans;
    while (b < N) {
        vector<int> l = d[A[b]];
        auto i = upper_bound(l.begin(), l.end(), b);
        if (i == l.end()) ans.push_back(A[b++]);
        else b = *i + 1;
    }
    if (ans.size()) {
        cout << ans[0];
        for (int i = 1; i < ans.size(); i++) cout << " " << ans[i];
        cout << endl;
    }
}


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

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n-1);
  rep(i,n-1){
    cin >> a.at(i);
  }
  sort(all(a));
  ll j = 0;
  for (int i = 0; i < n - 1; i++){
    ll count = 0;
   if(j==n-1){
     cout << count << "\n";
     continue;
   }
    while (a.at(j) == i + 1){
      count++;
      j++;
      if(j==n-1){
        break;
      }
    }
    cout << count << "\n";
  }
  cout << 0 << endl;
}

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

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

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

typedef long long ll;
typedef long double R;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

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

class UnionFind {
  public:
    // 親の番号を格納する。親だった場合は-(その集合のサイズ)
    vector<int> Parent;

    // 作る時はParentの値を全て-1にする
    // こうすると全てバラバラが表現できる。
    UnionFind(int N) {
      Parent = vector<int>(N, -1);
    }

    // Aがどのグループに属しているか調べる
    int root(int A) {
      if(Parent[A] < 0) return A;
      return Parent[A] = root(Parent[A]);
    }

    int size(int A) {
      return -Parent[root(A)]; // 親を取ってきたい
    }

    bool connect(int A, int B) {
      // AとBを直接繋ぐのではなく、root(A)をroot(B)をくっつける
      A = root(A);
      B = root(B);
      if(A == B) {
        //すでにくっついているからくっつけない
        return false;
      }

      // 大きい方に小さい方をくっつけたい
      // 代償が逆だったらひっくり返す
      if(size(A) < size(B)) swap(A, B);
      // Aのsizeを更新
      Parent[A] += Parent[B];
      // Bの親をAに変更する
      Parent[B] = A;

      return true;
    }
};

int main() {
  int N, M; cin >> N >> M;
  vector<int> x(M), y(M), z(M);
  long long ans = N;
  for(int i = 0; i < M; ++i) {
    cin >> x[i] >> y[i] >> z[i];
    x[i]--, y[i]--, z[i]--;
  }
  UnionFind Uni(N);
  for(int i = 0; i < M; ++i) {
    if(Uni.root(x[i]) != Uni.root(y[i])) {
      Uni.connect(x[i], y[i]);
      ans--;
    }
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 1792
class UF():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
 
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
 
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
 
        if x == y:
            return
 
        if self.parents[x] > self.parents[y]:
            x, y = y, x
 
        self.parents[x] += self.parents[y]
        self.parents[y] = x
 
    def size(self, x):
        return -self.parents[self.find(x)]
 
    def same(self, x, y):
        return self.find(x) == self.find(y)
 
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
 
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

n,m,k=map(int,input().split())
uf=UF(n)
F=[set()for _ in range(n)]
B=[0]*n
for i in range(m):
      a,b=map(int,input().split())
      uf.union(a-1,b-1)
      F[a-1].add(b-1)
      F[b-1].add(a-1)
for i in range(k):
      c,d=map(int,input().split())
      if uf.same(c-1,d-1):
            B[c-1]-=1
            B[d-1]-=1
L=[]
for i in range(n):
      L.append(uf.size(i)-1-len(F[i])+B[i])
print(*L)

Measured memory_bytes: 123500
#include <bits/stdc++.h> 
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll;ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
 ll n,T,ans=MM,c,t; cin>>n>>T;
  rep(i,n){
  cin>>c>>t;
    if(t<=T) ans=min(ans,c);
  }
  if(ans==MM)cout<<"TLE"<<endl;
else cout<<ans<<endl;
}

Measured memory_bytes: 256
N = int(input())
pt, px, py = 0, 0, 0
flag = True
for i in range(N):
    t, x, y = map(int, input().split())
    d = abs(px - x) + abs(py - y)
    dt = t - pt
    if d <= dt and dt % 2 == d % 2:
        pt, px, py = t, x, y
        continue
    flag = False
    break

if flag:
    print('Yes')
else:
    print('No')

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

using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n - 1); }
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;

struct UnionFind {
    V<int> p, r;
    int gn;
    UnionFind(int n = 0) : p(n, -1), r(n, 1), gn(n) {}
    void merge(int a, int b) {
        int x = group(a), y = group(b);
        if (x == y) return;  // same
        gn--;
        if (r[x] < r[y]) {
            p[x] = y;
        } else {
            p[y] = x;
            if (r[x] == r[y]) r[x]++;
        }
    }
    int group(int a) {
        if (p[a] == -1) return a;
        return p[a] = group(p[a]);
    }
    bool same(int a, int b) { return group(a) == group(b); }
};

bool test(int n, V<int> a, V<int> b) {
    UnionFind uf(n);
    int nw = 0;
    for (int d: a) {
        for (int i = 0; i < d / 2; i++) {
            uf.merge(nw + i, nw + d - 1 - i);
        }
        nw += d;
    }
    assert(nw == n);
    nw = 0;
    for (int d: b) {
        for (int i = 0; i < d / 2; i++) {
            uf.merge(nw + i, nw + d - 1 - i);
        }
        nw += d;
    }
    assert(nw == n);
    return uf.gn == 1;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << setprecision(20) << fixed;

    int sm, n;
    cin >> sm >> n;
    V<int> vo, ve;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (x & 1) vo.push_back(x);
        else ve.push_back(x);
    }

    if (int(vo.size()) > 2) {
        cout << "Impossible" << endl;
        return 0;
    }

    V<int> res_a;
    if (int(vo.size()) >= 1) {
        res_a.push_back(vo[0]);
    }
    res_a.insert(res_a.end(), ve.begin(), ve.end());
    if (int(vo.size()) > 1) {
        res_a.push_back(vo[1]);
    }

    V<int> res_b;
    if (n == 1) {
        res_b = {res_a[0] - 1, 1};
    } else {
        res_b = res_a;
        res_b[0]--;
        res_b.back()++;
    }
    if (res_b[0] == 0) res_b.erase(res_b.begin());

    assert(accumulate(res_a.begin(), res_a.end(), 0) == sm);
    assert(accumulate(res_b.begin(), res_b.end(), 0) == sm);
    assert(test(sm, res_a, res_b));

    for (int d: res_a) cout << d << " ";
    cout << endl;
    cout << res_b.size() << endl;
    for (int d: res_b) cout << d << " ";
    cout << endl;
    return 0;
}

Measured memory_bytes: 1024
def main():
  import sys
  import numpy as np
  from scipy.sparse import csr_matrix
  from scipy.sparse.csgraph import floyd_warshall as f
  t=np.fromstring(sys.stdin.buffer.read(),'i',sep=' ')
  n,m,l=t[:3]
  m=m*3+3
  print('\n'.join((f(f(csr_matrix((t[5:m:3],(t[3:m:3],t[4:m:3])),[n+1]*2),0)<=l)[t[m+1::2],t[m+2::2]].clip(0,n)%n-1).astype(str).tolist()))
main()

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template < typename T >
void vprint(T &v){
	REP(i, v.size()){
		cout << v[i] << " ";
	}
	cout << endl;
}

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

    string S;
    cin >> S;

    ll res = 0;
    ll sum = 0;
    REP(i, S.size()) sum += (S[i] == 'W');
    REP(i, S.size()){
    	if(S[i] == 'B'){
    		res += sum;
    	}else{
    		sum--;
    	}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <climits>
#include <cfloat>

using namespace std;

//start of 0uts1de's library

int cin_int_arr(vector<int>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cin >> arr.at(i);
    }
    return 0;
}

int cin_int_arr(vector<int>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cin >> arr.at(i);
    }
    return 0;
}

int cin_double_arr(vector<double>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cin >> arr.at(i);
    }
    return 0;
}

int cin_double_arr(vector<double>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cin >> arr.at(i);
    }
    return 0;
}


int cout_int_arr(vector<int>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}

int cout_int_arr(vector<int>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}

int cout_double_arr(vector<double>& arr){
    for (int i = 0; i < arr.size(); ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}

int cout_double_arr(vector<double>& arr, int n){    //overload
    for (int i = 0; i < n; ++i){
        cout << arr.at(i) << endl;
    }
    return 0;
}


int max_int_arr(std::vector<int>& arr){    //data mode
    int maxVal = INT_MIN;       //min of int
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            maxVal = arr.at(i);
        }
    }
    return maxVal;
}

int max_int_arr(std::vector<int>& arr, int mode){    //overload index mode
    int maxVal = INT_MIN;       //min of int
    int maxIndex = 0;
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            maxVal = arr.at(i);
            maxIndex = i;
        }
    }
    return maxIndex;
}

double max_double_arr(std::vector<double>& arr){    //data mode
    double maxVal = -DBL_MAX;       //min of double
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            maxVal = arr.at(i);
        }
    }
    return maxVal;
}

int max_double_arr(std::vector<double>& arr, int mode){    //overload index mode
    double maxVal = -DBL_MAX;       //min of double
    int maxIndex = 0;
    for (int i = 0; i < arr.size(); ++i){
        if (arr.at(i) > maxVal){
            maxVal = arr.at(i);
            maxIndex = i;
        }
    }
    return maxIndex;
}

//end of 0uts1de's library

int main(){
    long long int k, a, b;
    long long int bis = 1, yen = 0;
    cin >> k >> a >> b;
    auto k2 = k;
    
    if (bis < a){
        k -= a - 1;
        bis = a;
    }
    while (k > 1){
        bis -= a;
        ++yen;
        --k;
        bis += b;
        --yen;
        --k;
    }
    bis += k;
    
    if (bis < k2 + 1) bis = k2 + 1;
    
    cout << bis << endl;
    return 0;
}

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

  int k;
  int a;
  int b;
  int x;
  int c = 0;

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

  for (x = a; x <= b; x++){
    if (x % k == 0) c= 1;
  }

  if (c == 1) printf("OK");
  else printf("NG");

  return 0;

}


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

using namespace std;

int main(){
    int64_t k;
    cin >> k;
    int64_t S = 0;
    for (int64_t i = 1; i <= k; i++){
        for (int64_t j = 1; j <= k; j++){
            for (int64_t l = 1; l <= k; l++){
                S += gcd(i, gcd(j, l));
            }
        }
    }

    cout << S << endl;
}

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

namespace AtCoderTest001
{
    class Program
    {
        static void Main(string[] args)
        {
            new Program().Calc();
        }

        void Calc()
        {            
            // read
            int n = int.Parse(Console.ReadLine());

            // Count
            int ret = n;

            for (int i = 1; i <= n / 2 + 1; i++)
            {
                int sum = GetSumDigit(i) + GetSumDigit(n - i);

                if(sum < ret)
                {
                    ret = sum;
                }
            }

            Console.WriteLine(ret);



        }

        int GetSumDigit(int n)
        {
            int tmp;

            tmp = n / 10;

            if(n == 0)
            {
                return n % 10;
            }
            else
            {
                return n % 10 + GetSumDigit(n / 10);
            }
            
        }


    }
}


Measured memory_bytes: 11092
# Problem C - Typical Stars

# input process
N , M = map(int, input().split())
hole_list = [0]*(N+1)
for i in range(M):
    hole_i = int(input())
    hole_list[hole_i] = 1

# initialization
cost_list = [0]*(N+1)
cost_list[0] = 1
MOD = 10**9 + 7

# cumulative sum process
for i in range(1, N+1):
    if hole_list[i]==1: # if current pos is hole
        continue

    if hole_list[i-1]==0:
        cost_list[i] += cost_list[i-1]
        cost_list[i] %= MOD

    if i-2>=0:
        if hole_list[i-2]==0:
            cost_list[i] += cost_list[i-2]
            cost_list[i] %= MOD

# output process
print(cost_list[N])


Measured memory_bytes: 45912
#ABC054C
import copy
N,M=map(int,input().split())
C={}
for m in range(M):
	a,b=list(map(int,input().split()))
	C[b]=C.get(b,[])+[a]
	C[a]=C.get(a,[])+[b]
def Search(a,check):
	ans=0
	if all(check):
		return 1
	else:
		check[a-1]=1
		for b in C[a]:
			tmp=copy.deepcopy(check)
			if check[b-1]!=1:
				tmp[b-1]=1
				ans+=Search(b,tmp)
		return ans
print(Search(1,[0]*N))


Measured memory_bytes: 3444
#include<iostream>
using namespace std;
int main(){

long n,m,l;
cin>>n>>m>>l;

long a[n][m];
long b[m][l];

/*a,b入力*/

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

for(int i=0;i<m;i++){
    for(int j=0;j<l;j++){
        cin>>b[i][j];
    }
}

/*c初期化*/

long c[n][l];

for(int i=0;i<n;i++){
    for(int j=0;j<l;j++){
        c[i][j]=0;
    }
}

/*計算*/

for(int g=0;g<n;g++){
    for(int h=0;h<l;h++){
        for(int i=0;i<m;i++){
            c[g][h]+=a[g][i]*b[i][h];
        }
    }
}

for(int i=0;i<n;i++){
    for(int j=0;j<l-1;j++){
        cout<<c[i][j]<<" ";
    }
    cout<<c[i][l-1]<<endl;
}


}


Measured memory_bytes: 3336
#include <stdio.h>
#define MIN(a,b) ((a)<(b)?(a):(b))
#define MAX(a,b) ((a)>(b)?(a):(b))
#define ll long long

int main(void){
	int a,b,c,d;
	scanf("%d %d %d %d",&a,&b,&c,&d);
	printf("%d\n",MAX(a*b,c*d));
    return 0;
}

Measured memory_bytes: 128
#include <cstdio>
#include <iostream>
using namespace std;
int main(){
    int x, y, ax, ay;
    scanf("%d %d", &x, &y);
    ax = max(x, -x); ay = max(y, -y);
    int cnt = 0;
    if(ax < ay){
        if(x < 0) ++cnt;
        cnt += ay - ax;
        if(y < 0) ++cnt;
        printf("%d\n", cnt);
    }
    else if(ax > ay){
        if(x > 0) ++cnt;
        cnt += ax - ay;
        if(y > 0) ++cnt;
        printf("%d\n", cnt);
    }
    else printf("%d\n", ((int) (x != y)));
}


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

using namespace std;

int main(){
	string s;
	string ss;
	cin>>s>>ss;
	int len=s.size();
	for(int i=0;i<len;i++)
	{
		if(s[i] != ss[i])
		{
			puts("No");
			exit(0);
		}
	}
	puts("Yes");
	return 0;
}

Measured memory_bytes: 3632
#include"stdio.h"
#include <string.h>
int main()
{
	int N;
	int s[100];
	int i;
	int min = 101;
	int sum = 0;
	char flag = 1;// 0 = 10の倍数以外がある 1 = すべて10の倍数
	scanf("%d\n", &N);

	for (i = 0; i < N; i++) {
		scanf("%d\n", &(s[i]));
		if ((min > s[i]) && (s[i] % 10 != 0)) { min = s[i]; }//最小値を保持
		sum += s[i];
		if ((s[i] % 10 > 0) && (flag == 1 ))  { flag = 0; }//すべて10の倍数ならばflagは1のまま
	}
	if (min == 101) { 
		printf("0\n");
		return 0;
	}

	if ((flag == 1) || (sum < 1)){ 
		printf("0\n"); 
	}else if (sum % 10 > 0) {
		printf("%d\n", sum);
	}
	else {
		printf("%d\n", (sum - min));
	}
	return 0;

}


Measured memory_bytes: 128
def dfs(i, f, sum, s):
    if i == 3:
        if sum == 7:
            print(f+"=7")
            exit()
        return

    dfs(i+1, f+"-"+s[i+1], sum - int(s[i+1]), s)
    dfs(i+1, f+"+"+s[i+1], sum + int(s[i+1]), s)

def main():
    s = input()

    dfs(0, s[0], int(s[0]), s)
    
if __name__ == '__main__':
    main()


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

void printarray(vector<int> p) {
  for (auto it = p.begin(); it != p.end(); it++) {
    cout << *it;
  }
  cout << endl;
}
int main() {
  int n, m;
  cin >> n >> m;
  vector<int> k(m), p(m);
  vector<vector<int>> s(m);

  for (int i = 0; i < m; i++) {
    cin >> k[i];
    s[i].resize(k[i]);
    for (int j = 0; j < k[i]; j++) {
      cin >> s[i][j];
    }
  }

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

  int ans = 0;
  for (int bit = 0; bit < (1 << n); bit++) {
    vector<int> on;
    for (int i = 0; i < n; ++i) {
      if (bit & (1 << i)) {
        on.push_back(i);
        // 列挙に i が含まれるか
      }
    }  // bit end
    // printarray(on);
    bool flag = true;
    for (int j = 0; j < m; j++) {
      int count = 0;
      for (int l = 0; l < s[j].size(); l++) {
        if (find(on.begin(), on.end(), s[j][l] - 1) != on.end()) {
          count++;
        }
      }
      if (count % 2 != p[j]) {
        flag = false;
      }
    }
    if (flag) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define deb(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;
typedef long long int ll;
typedef string str;

int main ()
{
	// ios::sync_with_stdio(0);
 //    cin.tie(0);
 //    cout.tie(0);
	ll t,n,m,k,i,j;
	cin >> n;
	ll a[n+2],b[n+2],arr[n+2];
	for(i=0;i<n;i++)
	{
		cin >> arr[i];
	}
	a[0]=0;
	b[n-1]=0;
	for(i=1;i<n;i++)
	{
		a[i]=a[i-1]^arr[i-1];
		b[n-i-1]=b[n-i]^arr[n-i];
	}
	for(i=0;i<n;i++)
	{
		arr[i]=a[i]^b[i];
		// deb(a[i],b[i],i);
		cout << arr[i] << " ";
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 8236
#!/usr/bin/env python3
import sys


def solve(X: int, Y: int):
    ans = []

    cur = X
    while cur <= Y:
        ans.append(cur)
        cur *= 2

    print(len(ans))
    return


# Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    Y = int(next(tokens))  # type: int
    solve(X, Y)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <math.h>
#include <stdio.h>
#include <string>
#include <set>

using namespace std;

int main()
{
    int a=10000, b=5000, c=1000;
    int N,Y;
    scanf("%d%d", &N, &Y);
    for (int i=0; i <=N; i++)
        for (int j=0; j<=N; j++)
                if (N-i-j>=0 && i*a+j*b+(N-i-j)*c==Y)
                    if (printf("%d %d %d", i, j ,N-i-j))
                        return 0;
    printf("-1 -1 -1");
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define INF 1e9
#define EPS 1e-9
#define MOD (1e9+7)
void put(string d){}template<class H,class...T>void put(string d,H&h,T&...t){cout<<h;if(sizeof...(t))cout<<d;put(d,t...);}
template<class T>void puti(T&a,string d=" "){bool f=1;for(auto&_:a)cout<<(exchange(f,0)?"":d)<<_;cout<<endl;}
template<class T>void putii(T&a,string d=" "){for(auto&_:a)puti(_,d);}

int main(){
	int n;
	cin>>n;
	vi a(n);
	for(auto&i:a)cin>>i;
	auto b=a;
	sort(all(b));
	rep(i,n){
		if(a[i]<b[n/2]) cout<<b[n/2]<<endl;
		else cout<<b[n/2-1]<<endl;
	}
	
	return 0;
}


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

#define rep(i,n) for(long long i=0; i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s); i<(long long)(n);i++)
#define mod 1000000007
typedef long long ll;

int main() {
    string s;cin>>s;
    int ans=0;

    rep(i,3){
        if(s[i]=='1'){
            ans++;
        }
    }
    cout<<ans<<endl;
}



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

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

//C++14 (GCC 5.4.1)
int main() {
    int K,S;
    cin >>K>>S;
    //-----------------------------------
    int cnt=0;
    for(int x=0;x<=K;x++){
        for(int y=0;y<=K;y++){
            int z=S-(x+y);
            if(0<=z && z<=K){
                cnt++;
            }
        }
    }

    cout << cnt <<endl;
    return (0);
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <string>
#include <bitset>
#include <set>

using ll = long long;
using namespace std;

int main(void) {
	int n;
	cin >> n;
	
	bool yes = true;
	for(int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		
		if( a % 2 == 0 && a % 3 != 0 && a % 5 != 0 ) {
			yes = false;
			break;
		}
	}
	
	if( yes ) cout << "APPROVED" << endl;
	else cout << "DENIED" << endl;
	
	return 0;
}


Measured memory_bytes: 256
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()

def fct(n):
    if n == 1:
        return 1
    return n * fct(n-1)

def main():
    N = I()
    pos = []
    ans = 0
    G = [[0 for __ in range(N)] for _ in range(N)]
    for _ in range(N):
        x, y = LF()
        pos.append((x, y))
    for i in range(N):
        x = pos[i][0]
        y = pos[i][1]
        for j in range(N):
            jx = pos[j][0]
            jy = pos[j][1]
            dist = math.sqrt((x - jx)**2 + (y - jy)**2)
            ans += dist * fct(N-1) 
    print(ans / fct(N))
main()



Measured memory_bytes: 6440
#include <bits/stdc++.h>
using namespace std;
typedef long long int llint;
llint mod = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<vector<int>> c(3, vector<int>(0));
  string s;
  cin >> s;
  for (int i = 0; i < n; i++) {
    if (s.at(i) == 'R') {
      c[0].push_back(i);
    }
    else if (s.at(i) == 'G') {
      c[1].push_back(i);
    }
    else {
      c[2].push_back(i);
    }
  }
  int r = c[0].size();
  int g = c[1].size();
  int b = c[2].size();
  llint count = 0;
  for (int i = 0; i < r; i++) {
    for (int j = 0; j < g; j++) {
      int M = 2 * max(c[0][i], c[1][j]) - min(c[0][i], c[1][j]);
      int m = 2 * min(c[0][i], c[1][j]) - max(c[0][i], c[1][j]);
      int p = 0;
      if (m >= 0) {
        if (s.at(m) == 'B') {
          p--;
        }
      }
      if (n > M) {
        if (s.at(M) == 'B') {
          p--;
        }
      }
      if ((M+m)%2==0 && s.at((M+m)/2)=='B') {
        p--;
      }
      p += b;
      count += p;
    }
  }
  printf("%lld\n", count);
} 

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

using namespace std;

const int N = 1e5 + 5;

int a[N];
int n;
vector <int> v;

int main()
{
        cin >> n;
        for (int i=1; i<=n; i++) cin >> a[i];
        for (int i=1; i*i<=a[1]; i++)
        {
                if (a[1]%i==0)
                {
                        v.push_back(i);
                        if (a[1]/i!=i) v.push_back(a[1]/i);
                }
        }
        for (int i=1; i*i<=a[2]; i++)
        {
                if (a[2]%i==0)
                {
                        v.push_back(i);
                        if (a[2]/i!=i) v.push_back(a[2]/i);
                }
        }
        sort(v.begin(), v.end(), greater<int>());
        //for (int i=0; i<v.size(); i++) cout << v[i] << " ";
        for (int i=0; i<v.size(); i++)
        {
                int cnt = 0;
                for (int j=1; j<=n; j++)
                {
                        if (a[j]%v[i]) cnt++;
                        if (cnt>=2) break;
                        else if (j==n)
                        {
                                cout << v[i];
                                return 0;
                        }
                }
        }
        return 0;
}


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

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

    cout << min(n*a, b) << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n;
string s;
int main(){
	cin>>n>>s;
	if(n%2!=0) {cout<<"No";return 0;}
	for(int i=0,j=n/2;i<n/2,j<n;i++,j++)
	    if(s[i]!=s[j]) {cout<<"No";return 0;}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 256