akhauriyash/Code-Regression huggingface dataset:
import sys
import copy
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline

in_n = lambda: int(readline())
in_nn = lambda: map(int, readline().split())
in_nl = lambda: list(map(int, readline().split()))
in_na = lambda: map(int, read().split())
in_s = lambda: readline().rstrip().decode('utf-8')


def main():
    N = in_n()
    A = sorted(in_nl())

    while True:
        B = []
        B.append(A[0])
        for i in range(1, len(A)):
            x = A[i] % A[0]
            if x:
                B.append(x)

        if len(B) == 1:
            break
        else:
            B.sort()
            A = copy.copy(B)

    print(B[0])


if __name__ == '__main__':
    main()


Measured memory_bytes: 19104
import math

an = []
for i in range(5):
    temp = input()
    an.append(int(temp))

mi = an[0]
for a in an[1:]:
    if  a%10 < mi % 10 and a%10 != 0:
        mi = a
an.remove(mi)
hoge = []
for i in an:
    temp = int(math.ceil(i/10))*10
    hoge.append(temp)
ans = sum(hoge) + mi
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);

int N, Q;
int S[100000];

class BinarySearch{

public:
	// 0?????????1????????????????????????x??????????????????????????£????????????????????????
	static int cond(int i, ll x){
		if(S[i] >= x) return 1;
		return 0;
	}

	// ?????????cond???1?????????x?????????
	static int binarySearch(ll x){
		auto _cond = cond;
		int left = 0;
		int right = N;

		if(_cond(0, x) == 1) return 0;
		if(_cond(N-1, x) == 0) return N;

		while (left + 1 < right){
			int mid = (left + right) / 2;
			if(_cond(mid, x) == 0) {
				left = mid;
			}
			else{
				right = mid;
			}
		}
		return right;
	}

	static bool is_exist(ll x){
		int i = binarySearch(x);
		return (i < N && S[i] == x);
	}

};

int main() {
	cin >> N;
	rep(i, N) cin >> S[i];
	sort(&S[0], &S[N]);

	int ret = 0;
	cin >> Q;
	rep(i, Q){
		int x; cin >> x;
		if(BinarySearch::is_exist(x)) ret++;
	}
	cout << ret << endl;
}

Measured memory_bytes: 3464
#include <iostream>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <string>
#include <functional>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cmath>
typedef long long ll;
const int INF = 100000000, mod = 1000000007;
const ll LLINF = 1LL << 50;
using namespace std;

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if (a + b == c + d) cout << "Balanced" << endl;
    else if (a + b > c + d)cout << "Left" << endl;
    else cout << "Right" << endl;
    return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;

#define FOR(i, a, n) for(int i = (int)(a); i < (int)(n); ++i)
#define REP(i, n) FOR(i, 0, n)

#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

// gcd: 最大公約数, lcm: 最小公倍数
template<typename T>
T euclidean(T a, T b){
    if(a < b) swap(a, b);
    T r = a % b;
    while(r != 0){
        a = b; b = r; r = a % b;
    }
    return b;
}
template<typename T>
T gcd(T a, T b){
    return euclidean(a, b);
}
template<typename T>
T lcm(T a, T b){
    T g = gcd(a, b);
    return a / g * b;
}


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

    int n;
    cin >> n;
    cout << lcm(n, 2) << endl;

}


Measured memory_bytes: 256
from itertools import combinations
N = int(input())
P = [tuple(map(int,input().split())) for _ in range(N)]

total = sum(((x0-x1)**2+(y0-y1)**2)**(1/2) for (x0,y0),(x1,y1) in combinations(P,2))

print(2*total/N)


Measured memory_bytes: 9376
n, x = map(int, input().split())
a_lst = list(map(int, input().split()))

if a_lst[0] > x:
  cnt = a_lst[0] - x
  a_lst[0] = x
else:
  cnt = 0

for i in range(n-1):
  if a_lst[i] + a_lst[i+1] > x:
    if a_lst[i+1] - (x - a_lst[i]) >= 0:
      cnt += a_lst[i+1] -(x - a_lst[i])
      a_lst[i+1] = x - a_lst[i]
  else:
    pass
    
print(cnt)

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

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
#define all(a) begin(a),end(a)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}
template<class T> void cout_h(const vector<T>& c, int n=INT_MAX)
{ rep(i, min(n, (int)c.size())) cout << c[i] << (i==c.size()-1?"\n":" "); }
template<class T> inline bool chmin(T& a, T b) {return a>b?a=b,true:false;}
template<class T> inline bool chmax(T& a, T b) {return a<b?a=b,true:false;}
#define D1(a) cout<<#a<<":"<<a<<"\n"
#define D2(a,b) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<endl 
#define D3(a,b,c) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c <<endl
#define D4(a,b,c,d) cout<<#a<<":"<<a<<","<<#b<<":"<<b<<","<<#c<<":"<<c<<","<<#d<<":"<<d<<endl 
#define MOD 1000000007

int main()
{
    ll N; cin >>N;
    ll sum = 0;
    ll sqrtn = sqrt((double)N);
    for (ll r = 1; r <= sqrtn; r++) {
        if (N % r == 0) {
            ll m = N / r - 1;
            if (r < m) sum += m;
        }
    }

    cout << sum << endl;
}

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

const string YES = "Yes";
const string NO = "No";

void solve(std::string S){

    std::string ans = NO;

    int l = S.length();
    if(l%2 != 0){
        cout << "No" << endl;
        return;
    }

    for(int i=0; i < l; i+=2){
        if(S[i] == 'h' && S[i+1] == 'i'){
            ans = YES;
        }else{
            ans = NO;
            break;
        }
    }

    cout << ans << endl;

}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <stdlib.h>
#define Fi for (i = 0; i < n; i++) 
int compare_int(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}
int data[100000000];
int main()
{
	int n;
	long long sum=0;
	scanf("%d",&n);
    
    int i;
    Fi{
        scanf("%d",&data[i]);
        sum+=data[i];
    }
    qsort(data, n, sizeof(int), compare_int);
//Fi{
    printf("%d %d %lld\n", data[0],data[n-1],sum);
//}
    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
template<class T>inline bool chmax(T &a, const T &b){if(a < b){a = b; return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(a > b){a = b; return 1;}return 0;}
typedef long long ll;

bool isPrime(int n){
  if(n == 1) return false;
  if(n == 2) return true;
  if(n%2 == 0) return false;
  for(int i = 3; i <= sqrt(n); i += 2){
    if(n%i == 0) return false;
  }
  return true;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // ARC067C - Factors of Factorial
  int N; cin >> N;

  vector<int> p; // Nまでの素数の配列を作る
  for(int i = 2; i <= N; i++){
    if(isPrime(i)) p.push_back(i);
  }

  vector<int> cnt(p.size(), 0); // 各素数が何回使われるかを記録する
  for(int i = 1; i <= N; i++){
    int tmp = i;
    REP(j, p.size()){
      if(tmp == 1) break;
      while(tmp%p[j] == 0){
        tmp /= p[j];
        cnt[j]++;
      }
    }
  }

  ll ans = 1, mod = 1e9 + 7;
  REP(i, p.size()){
    ans *= (cnt[i] + 1);
    ans %= mod;
  }

  cout << ans << endl;
}

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

#define froop1(a,n) for(long long i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	long long N,M,limit;
  cin >> N >> M >> limit;
  vector<long long> N1(N + 1);
  vector<long long> M1(M + 1);
  froop1(1,N + 1){
    long long a;
	cin >> a;
    N1.at(i) = a;
      N1.at(i) += N1.at(i - 1);

  }
  froop1(1,M + 1){
long long a;
    cin >> a;
        M1.at(i) = a;
      M1.at(i) += M1.at(i - 1);
  }
 
  long long m = 0,best = M;
  froop1(0,N + 1){
    long long j = best;
    if(N1.at(i) > limit)break;
      while(N1.at(i) + M1.at(j) > limit && j > 0){
       j--;
        best--;
      }
    m = max(m,i + j);
  }
  cout << m << endl;
}
  

Measured memory_bytes: 6396
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define LOOP(i) while(i--)
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	string S=in<string>();
	reverse(ALL(S));
	vector<string> L={"dream","dreamer","erase","eraser"};
	for(auto& x:L) reverse(ALL(x));
	
	auto itr=S.begin();
	while(itr!=S.end()){
		auto temp = itr;
		int offset = distance(S.begin(),itr);
		for(auto& x:L){
			int ls = x.size();
			if(S.substr(offset,ls)==x){
				itr+=ls;
			}
		}
		if(temp==itr){
			out("NO");
			return 0;
		}
	}
	out("YES");
	return 0;
}


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

int main(){
  int N,K;
  cin>>N >> K;
  vector<int> h(N);
  for(int i = 0; i<N; i++){
    cin >> h.at(i);
  }
  
  int count = 0;
  for(int i = 0; i<N; i++){
    if(h.at(i)>=K){
      count++;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
using p=pair<int,int>;
#define int long long
#define rep(i,N) for(int i=1;i<=N;i++)

signed main(){
  int A,B,C;
  cin>>A>>B>>C;
  int num=0;
  rep(i,B*A){
    num=A*i;
    if(num%B==C){
      cout<<"YES"<<endl;
      return 0;
    }
  }
  cout<<"NO"<<endl;
  return 0;
}

Measured memory_bytes: 3600
def knapsack_weight(W, items):
    '''
        W (int): the capacity of a knapsack
        items (list of tuples): i-th element is a tuple (weight, value)
    '''
    N = len(items)
    # dp[n][w] = the maximum value when the capacity is w and only items 1, 2, ..., n are used.
    dp = [[0 for j in range(W+1)] for i in range(N+1)]
    for i in range(1, N+1):
        w, v = items[i-1]
        for j in range(W+1):
            if j - w >= 0:
                dp[i][j] = max(dp[i-1][j-w] + v, dp[i-1][j])
            else:
                dp[i][j] = dp[i-1][j]
    return dp[N][W]

N, W = map(int, input().split())
items = []
for _ in range(N):
    v, w = map(int, input().split())
    items.append((w, v))
print(knapsack_weight(W, items))


Measured memory_bytes: 42368
import numpy as np
from itertools import permutations

# Input
menus = []
for i in range(5):
  menus.append(int(input()))

# Main
def calc(menus):
  t = 0
  for i, menu in enumerate(menus):
    t += menu
    if i < 4:
	    t = np.ceil(t / 10) * 10
  return t

minima = np.inf
for menu in permutations(menus):
  minima = min(minima, calc(menu))
print(int(minima))

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

int main(){
  int i,j,N;
  cin >> N;
  long long ans=0;
  int A,tmp;
  map<int,int> Am;
  vector<int> Ap(N);
  for(i=0; i<N; i++){
    cin >> A;
    Ap[i] = A+i;
    if(Am.count(-A+i)){
      tmp = Am[i-A];
    }
    else tmp = 0;
    tmp++;
    Am[i-A] = tmp;
  }
  for(i=0; i<N; i++){
     if(Am.count(Ap[i])){
       ans += (long long)Am[Ap[i]];
     }
  }
  cout << ans;
  return 0;
}

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

int main()
{
    int e;
    vector<int> answer;
    while (cin >> e && e != 0)
    {
        int min = 0;
        for (int i = 0; i * i * i <= e; i++)
        {
            for (int j = 0; j * j <= e - i * i * i; j++)
            {
                if (min == 0)
                {
                    min = i + j + (e - i * i * i - j * j);
                }
                else if (min > i + j + (e - i * i * i - j * j))
                {
                    min = i + j + (e - i * i * i - j * j);
                }
            }
        }
        answer.push_back(min);
    }
    for (int i = 0; i < answer.size(); i++)
    {
        cout << answer.at(i) << endl;
    }
    return 0;
}



Measured memory_bytes: 3092
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int a[]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
int main()
{
    int n;
    scanf("%d",&n);
    printf("%d\n",a[n-1]);
}


Measured memory_bytes: 256
#include<stdio.h>

int dp[50];

int fib(int n){
    if(n==0 || n==1) return dp[n]=1;
    if(dp[n] != -1) return dp[n];
    return dp[n] = fib(n-1) + fib(n-2);
}

int main(){
    int n, i;
    for(i=0; i<50; i++) dp[i] = -1;

    scanf("%d", &n);
    printf("%d\n", fib(n));

    return 0;
}



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

using namespace std;

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

using i64 = long long;
using pii = pair<i64, i64>;

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

constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD = int(1e9) + 7;

signed main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);

  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;

  int cnt = 0;
  int f = 1;
  for (auto e : s) {
    if (e == 'a') {
      if (cnt < a + b) {
        cout << "Yes" << "\n";
        ++cnt;
      }
      else cout << "No" << "\n";
    }

    else if (e == 'b') {
      if (cnt < a + b && f <= b) {
        cout << "Yes" << "\n";
        ++cnt;
      }
      else cout << "No" << "\n";
      ++f;
    }

    else {
      cout << "No" << "\n";
    }
  }

  return 0;
}

Measured memory_bytes: 848
h, w = map(int, input().split())
if (h%3)*(w%3)==0:
    print(0)
    exit(0)
def solve(a, b):
    ans = 10**10
    s1 = a*(b//3)
    s2 = (a//2)*(b-b//3)
    s3 = ((a+1)//2)*(b-b//3)
    s4 = a*((b+2)//3)
    ans = min(ans, max(s1, s2, s3)-min(s1, s2, s3))
    ans = min(ans, max(s1, s4)-min(s1, s4))
    s1 = a*((b+2)//3)
    s2 = (a//2)*(b-(b+2)//3)
    s3 = ((a+1)//2)*(b-(b+2)//3)
    ans = min(ans, max(s1, s2, s3)-min(s1, s2, s3))
    return ans
print(min(solve(h, w), solve(w, h)))

Measured memory_bytes: 3064
#include <iostream>
#include <set>
int main()
{
  std::set<int> d;
  int n, tmp;

  std::cin >> n;
  for (int i = 0; i < n; i++)
  {
    std::cin >> tmp;
    d.insert(tmp);
  }

  std::cout << d.size() << std::endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(void){
	int X,Y;
	int i = 0;

	while (1){
		cin >> X>>Y;

		if (X == 0&&Y==0){
			break;
		}

		if (X <= Y){
			cout << X<<" "<<Y << endl;

		} else{
			cout << Y << " " << X << endl;
		}
	}


	//system("pause");
	return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define rep(i,s,n) for(int i=s;i<n;i++)
#define pb push_back
#define all(x) (x).begin(),(x).end()
using namespace std;
using P=pair<int,int>;
using G=vector<vector<int>>;
using ll=long long;




int main(){
    int a,b,c; 
    int x[3];
    rep(i,0,3){
        cin>>x[i];
    }

    sort(x,x+3);

    if(x[0]+x[1]==x[2]){
        cout<<"Yes"<<endl;
    }
    else{
        cout<<"No"<<endl;
    }

    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
    int n;cin>>n;
    vector <int> vect(n);
    for(int i=0;i<n;i++)
        cin>>vect[i];
    sort(vect.begin(),vect.end());
    long double num=0.00;
    num = vect[0] +vect[1];
    for(int i=2;i<n;i++)
    {
        num =num + ((long long )pow(2,i-1))*vect[i];
    }
    cout<<fixed<<setprecision(10)<<(num/((long long)pow(2,n-1)));
}

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

int main(){
  int64_t n, d, ans=0;
  cin >> n >> d;
  int64_t x, y;
  for(int i=0; i<n; i++){
    cin >> x >> y;
    if(x*x+y*y<=d*d) ans++;
  }
  cout << ans;
  return 0;
}

Measured memory_bytes: 3592
#include<cstdio>
#include<cstring>
#include<algorithm>

using namespace std;

char s1[2000005],s2[20000005];

int main()
{
	scanf("%s%s",s1,s2);
	for(int i=0; i<max(strlen(s1),strlen(s2)); i++)
	{
		printf("%c",s1[i]);
		if(s2[i]!=0)	printf("%c",s2[i]);
	}
	return 0;
}


//ios::sync_with_stdio(false);
//freopen("in.in","r",stdin);
//freopen("out.out","w",stdout);


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

int main() 
{
    int N;
    cin >> N;
    
    for (int i = 1; i <= 9; i++) {
        for (int j = 1; j <= 9; j++) {
            int sum = i * j;
            if (N == sum) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}

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

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

#define pb push_back
#define fr first
#define sc second

static ll N;
static vector<P> G[100010];

static P par[100010];
vector<ll> vs;
void dfs(ll v,P p){
	par[v] = p;
	for(int i = 0 ; i < G[v].size() ; i ++){
		if(G[v][i] == p)continue;
		dfs(G[v][i].sc,P(G[v][i].fr,v));
	}
	vs.pb(v);
}

int main(){
	static ll A[100010];
	static ll a[100010],b[100010];
	scanf("%d",&N);
	for(int i = 1 ; i <= N ; i ++){
		scanf("%lld",&A[i]);
	}
	for(int i = 1 ; i <= N-1 ; i ++){
		scanf("%lld%lld",&a[i],&b[i]);
	}
	
	for(int i = 1 ; i <= N-1 ; i ++){
		G[a[i]].pb(P(i,b[i]));
		G[b[i]].pb(P(i,a[i]));
	}
	static ll root = 0;
	for(int i = 1 ; i <= N ; i ++){
		if(G[i].size() >= 2)root = i;
	}
	if(root == 0){
		if(A[1] == A[2])puts("YES");
		else puts("NO");
		return 0;
	}
	dfs(root,P(0,0));
	
	static ll c[100010];
	static ll d_ha = 0;
	for(int i = 0 ; i < vs.size() ; i ++){
		ll v = vs[i];
		if(G[v].size() == 1){
			c[par[v].fr] = A[v];
			d_ha += A[v];
		}
		else if(v != root){
			c[par[v].fr] = 2*A[v];
			for(int j = 0 ; j < G[v].size() ; j ++){
				if(G[v][j].fr == par[v].fr)continue;
				c[par[v].fr] -= c[G[v][j].fr];
			}
		}
		else {
			ll cnt = 0;
			for(int j = 0 ; j < G[v].size() ; j ++){
				cnt += c[G[v][j].fr];
			}
			if(cnt != 2*A[v]){
				puts("NO");
				return 0;
			}
		}
	}
	if(d_ha%2 != 0){
		puts("NO");
		return 0;
	}
	
	for(int i = 0 ; i < N ; i ++){
		for(int j = 0 ; j < G[i].size() ; j ++){
			if(A[i] < c[G[i][j].fr] || c[G[i][j].fr] < 0){
				puts("NO");
				return 0;
			}
		}
	}
	puts("YES");
}



Measured memory_bytes: 17140
import java.util.HashSet;
import java.util.Scanner;


	public class Main {
		
		

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);
			
			char[] s = sc.next().toCharArray();
			HashSet<Character> m = new HashSet<Character>(); 
			
			for(int i=0;i<s.length;i++) {
				m.add(s[i]);
			}
			
			if(m.size()==1) {
				System.out.println(0);
				return;
			}
			
			int ret = Integer.MAX_VALUE ;
			
			
			for(Character c : m) {
				int n = s.length;
				int count = 0;
				char[] t = new char[n];
				for(int j=0;j<n;j++) {
					t[j] = s[j];
				}
				while(true) {
					
					HashSet<Character> set = new HashSet<Character>();
					for(int i=0;i<n-1;i++) {
						 
						if(t[i+1]==c) {
							t[i]=c;
						}
						set.add(t[i]);
					}
					count++;
					n--;
					if(set.size()==1) {
						break;
					}
					set.clear();
				}
				ret = Math.min(ret, count);
				
			}
			
			
			
			System.out.println(ret);
	    }
				
	}
	


Measured memory_bytes: 38064
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
using namespace std;
set<pair<int,int>>sp[20],st,yo ;
pair<int,int>ar[100009] ;
int n,m,k,ans[12] ;
map<pair<int,int>,int>mp ;
bool check(int x , int y , int ct)
{
    if(x+2>n || y+2>m) return 0 ;
    int cc=0 ;
    for(int i = x ; i <= x+2 ; i++)
    {
        for(int j = y ; j <= y+2 ; j++)
        {
            if(st.find({i,j})!=st.end()) cc++ ;
        }
    }
    if(cc) sp[cc].insert({x,y}) ;
    if(cc) yo.insert({x,y}) ;
    return cc==ct ;
}
int32_t main()
{
    ios_base::sync_with_stdio(0) ; cin.tie(0) ; cout.tie(0) ;
    cin>>n>>m>>k ;
    for(int i = 0 ; i < k ; i++)
    {
        cin>>ar[i].F>>ar[i].S ;
        st.insert({ar[i].F,ar[i].S}) ;
    }
    sort(ar,ar+k) ;
    for(int i = 0 ; i < k ; i++)
    {
        int x=ar[i].F,y=ar[i].S ;
        int p,q,r,s ;
        p=x ; q=y ;
        if(p-1>=1) p-- ; if(p-1>=1)p-- ;
        if(q-1>=1) q-- ; if(q-1>=1)q-- ;
        for(int i1 = p ; i1 <= x ; i1++)
        {
            for(int j1 = q ; j1 <= y ; j1++)
            {
                check(i1,j1,0);
            }
        }
    }
    for(int i = 1 ; i < 10 ; i++) ans[i]=sp[i].size() ;
    int tot=(n*m)-(2*m)-(2*n)+4 ;
    ans[0]=tot-yo.size() ;
    for(int i = 0 ; i < 10 ; i++) cout<<ans[i]<<endl ;
}


Measured memory_bytes: 123976
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <bitset>
#include <iomanip>
#include <numeric>

using namespace std;

int main(){
    int N;
    cin >> N;

    vector<double> X(N);
    vector<double> Y(N);

    for(int i=0; i<N; i++){
        int x, y;
        cin >> x >> y;
        X[i] = x;
        Y[i] = y;
    }

    vector<int> nums(N);
    std::iota(nums.begin(), nums.end(), 0);

    double dist = 0;
    int cnt = 0;
    do{
        for(int i=1; i<N; i++){
            int a = nums.at(i);
            int b = nums.at(i-1);
            dist += sqrt( pow( (X[a]-X[b] ), 2.0 ) + pow( (Y[a]-Y[b]), 2.0 ) );
        }
        cnt++;
    }while(next_permutation(nums.begin(), nums.end()));

    cout << std::setprecision(10) << dist/(double)cnt << endl;

    return (0);

}

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

int main()
{
    int n, k;
    cin >> n >> k;
    cout << k * (int)pow(k - 1, n - 1) << endl;
    return 0;
}

Measured memory_bytes: 3896
#if 1
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_set>
#include <unordered_map>
#include <functional>

using namespace std;
#define int long long
constexpr int mod = 1000000007;

#define LOADVEC(type,name,N) std::vector<type>name(N); \
for (int nnn = 0; nnn < N; ++nnn) { \
	cin >> name[nnn]; \
}

#define LOAD(type,name) type name; \
cin >> name;



signed main() {
	ios::sync_with_stdio(false);
	LOAD(int, N);
	LOADVEC(int, A, N);
	int res = 0;
	for (int n = 0; n < N; ++n) {
		res += A[n] / 2;
		A[n] %= 2;
		if (A[n] == 1 && n + 1 < N && A[n + 1] > 0) {
			A[n]--;
			A[n + 1]--;
			++res;
		}
	}
	cout << res << endl;
	return 0;
}
#endif


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
	int H,W;
	scanf("%d %d\n",&H,&W);
	char pix[W];
	for(int i = 0; i < H; ++i){
		for(int j = 0; j < W; ++j) scanf("%c\n",&pix[j]);
		for(int k = 0; k < 2; ++k){
			for(int j = 0; j < W; ++j) printf("%c",pix[j]);
			printf("\n");
		}
	}
	return 0;
}

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

int main(){
  int N,M;
  int tmp1,tmp2;
  cin >>N>>M;
  vector <int> hasi(N);

    for(int i=0;i<M;i++){
    cin >> tmp1>>tmp2;
    hasi.at(tmp1-1)++;
    hasi.at(tmp2-1)++;
  }
  
  for(int i=0;i<N;i++)
    cout << hasi.at(i)<<endl;
}

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

int main() {
    int n;
    scanf("%d", &n);
    vector< int> v(n);
    for (int &a : v) cin >> a;
    long long res = 0;

    int sum = 0;
    for(int l = 0, r = 0; l < n; ++l) {
        while(r < n and (sum & v[r]) == 0) {
            sum ^= v[r];
            r++;
        }
        res += r - l;
        sum ^= v[l];
    }
    cout << res << endl;
}

Measured memory_bytes: 1152
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func scanInt() int {
	sc.Scan()
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func intMax(x, y int) int {
	return int(math.Max(float64(x), float64(y)))
}

func main() {
	sc.Split(bufio.ScanWords)

	N := scanInt()
	A := [2][]int{}
	A[0], A[1] = make([]int, N), make([]int, N)
	for i := 0; i < 2; i++ {
		for j := 0; j < N; j++ {
			A[i][j] = scanInt()
		}
	}
	for i := 1; i < N; i++ {
		A[0][i] += A[0][i-1]
	}
	for i := N - 2; i >= 0; i-- {
		A[1][i] += A[1][i+1]
	}

	ans := 0
	for i := 0; i < N; i++ {
		ans = intMax(ans, A[0][i]+A[1][i])
	}

	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
#define lli long long int   //used int to avoid mle
#define ulli unsigned long long int 
#define ld long double
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define loop(i,a,b) for(lli i=a;i<b;i++)
#define initialize(array,size,value) for(lli i=0;i<size;i++) array[i]=value
#define couta(array,size) for(lli i=0;i<size;i++) cout<<array[i]<<" "
#define vl vector<lli>
#define vp vector< pair <lli,lli> >
#define sl set<lli>
#define spl set<pll>
#define msl multiset <lli>
#define msp multiset <pll>
#define pll pair<lli, lli>
#define mll map<lli, lli>              //for( map<lli, lli>::iterator i=temp.begin();i!=temp.end();i++)cout<<i->fi<<" "<<i->se<<endl;
#define mvl map<lli, vl>
#define umll unordered_map<lli, lli>
#define vt vector<pair<lli, pll >  >
#define vf vector<pair<pll,pll > >
#define qu queue<lli>
#define pq priority_queue<lli>
#define dq deque <lli>
#define ptr vector<lli>::iterator
#define bs(array,x) binary_search(array.begin(),array.end(),x)
#define lb(array,x) lower_bound(array.begin(),array.end(),x)
#define ub(array,x) upper_bound(array.begin(),array.end(),x)
#define nobw(array,i,j) upper_bound(array.begin(), array.end(), j)-lower_bound(array.begin(), array.end(), i) //number of numbers between i & j
#define vc clear()
#define endl '\n'
#define sp system("pause");
#define INF 9223372036854775807
#define MINF -9223372036854775808
#define start_routine() int begtime = clock();
#define end_routine() int endtime = clock(); cerr << endl << "Time elapsed: " << (endtime - begtime)*1000/CLOCKS_PER_SEC << " ms"; return 0
lli mod=1000000007;
//string s=bitset<32>(n).to_string();
vl adj[100001];
lli n,t,a;
bool visited[100001];
vl path;
bool dfs(lli v){
	visited[v]=true;
	if(v==t)return true;
	for(auto u:adj[v]){
		if(visited[u])continue;
		if(dfs(u)){
			path.pb(u);
			return true;
		}
	}
	return false;
}
lli dfs2(lli v){
	//cout<<v<<endl;
	visited[v]=true;
	lli t=1;
	for(auto u:adj[v]){
		if(visited[u])continue;
		t=max(t,1+dfs2(u));
	}
	return t;

}
int main()
{
 	ios::sync_with_stdio(0);
    cin.tie(0);
  
        cin>>n>>t>>a;
        for(lli i=0;i<n-1;i++){
        	lli a,b;
        	cin>>a>>b;
        	adj[a].pb(b);
        	adj[b].pb(a);
        }
        for(lli i=0;i<=n;i++)visited[i]=false;
        bool x=dfs(a);
    	path.pb(a);
    	reverse(path.begin(),path.end());
    	lli s=path[(path.size()+1)/2],l=path[(path.size()+1)/2 -1];
    	//auto pl=adj[s].begin();
    	//while(*pl!=l)pl++;
    	//adj[s].erase(pl);
    	//adj[l].erase(s);
    	for(lli i=0;i<=n;i++)visited[i]=false;
    	visited[l]=true;
    	lli md;
    	md=dfs2(s);
    	lli ani=md+(path.size()+1)/2;
    	cout<<ani-2;
	return 0;
}

Measured memory_bytes: 11252
def floyd_warshall(d):
    v = len(d)
    for k in range(v):
        for i in range(v):
            for j in range(v):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])

while True:
    n = int(input())
    if n == 0:
        break
    info = []
    num_cities = 1
    for i in range(n):
        a, b, c = map(int, input().split())
        num_cities = max(num_cities, a+1, b+1)
        info.append((a, b, c))

    d = [[0 if i == j else float('inf') for j in range(num_cities)] for i in range(num_cities)]
    for a, b, c in info:
        d[a][b] = d[b][a] = c

    floyd_warshall(d)
    total = [sum(d[i]) for i in range(num_cities)]
    min_dist = min(total)
    print(total.index(min_dist), min_dist)



Measured memory_bytes: 5616
#include <bits/stdc++.h>
#define ll long long
#define sc scanf
#define pr printf
using namespace std;
int main()
{
	int x;
	sc("%d", &x);
	int ans = x / 500 * 1000 + (x % 500) / 5 * 5;
	pr("%d", ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

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

		int max = 0;

		for (int i = 0; i < Math.ceil(Math.sqrt(x)); i++) {
			for (int j = 0; j<6; j++) {
				if (Math.pow(i, j) > max && Math.pow(i, j)<=x)
					max = (int) Math.pow(i, j);
			}
		}
		System.out.println(max);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;

int k;
string s;

void input()
{
    cin >> k >> s;
}

void solve()
{
    int length = static_cast<int>(s.size());
    
    if (length <= k)
    {
        cout << s << endl;
        return;
    }
    
    cout << s.substr(0, k) + "..." << endl;
}

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

    input();
    solve();
}


Measured memory_bytes: 3656
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  (n : _) <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  bs <- map unsafeSignedDecimal . T.words <$> T.getLine :: IO [Int]
  let
    cs = uncurry (maybe id (:)) . foldr step (Nothing, []) $ bs
    step b (Nothing, []) = (Just b, [b])
    step b (Just b', bs') = (Just b, min b b' : bs')
  print $ sum cs

unsafeSignedDecimal :: T.Text -> Int
unsafeSignedDecimal s = case T.signed T.decimal s of
  Right (n, _) -> n


Measured memory_bytes: 508
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const int INF = 1 << 28;
const ll MOD = 1000000007;
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;
}

struct mint {
    ll v;
    ll mod;
    mint() : v(0) {}
    mint(signed v, ll mod = MOD) : v(v), mod(mod) {}
    mint(ll t, ll mod = MOD) : mod(mod) {
        v = t % mod;
        if (v < 0)
            v += mod;
    }

    mint pow(ll k) {
        mint res(1), tmp(v);
        while (k) {
            if (k & 1)
                res *= tmp;
            tmp *= tmp;
            k >>= 1;
        }
        return res;
    }

    static mint add_identity() { return mint(0); }
    static mint mul_identity() { return mint(1); }

    mint inv() { return pow(mod - 2); }

    mint &operator+=(mint a) {
        v += a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator-=(mint a) {
        v += mod - a.v;
        if (v >= mod)
            v -= mod;
        return *this;
    }
    mint &operator*=(mint a) {
        v = 1LL * v * a.v % mod;
        return *this;
    }
    mint &operator/=(mint a) { return (*this) *= a.inv(); }

    mint operator+(mint a) const { return mint(v) += a; };
    mint operator-(mint a) const { return mint(v) -= a; };
    mint operator*(mint a) const { return mint(v) *= a; };
    mint operator/(mint a) const { return mint(v) /= a; };

    mint operator-() const { return v ? mint(MOD - v) : mint(v); }

    bool operator==(const mint a) const { return v == a.v; }
    bool operator!=(const mint a) const { return v != a.v; }
    bool operator<(const mint a) const { return v < a.v; }
};

int main() {
    string k;
    cin >> k;
    int d;
    cin >> d;
    int n = k.size();
    vector<vector<mint>> dp1(n + 1, vector<mint>(d, 0));
    vector<vector<mint>> dp2(n + 1, vector<mint>(d, 0));
    dp1[0][0] = 1;
    for (int i = 0; i < n; ++i) {
        int ki = stoi(k.substr(i, 1));
        for (int j = 0; j < d; ++j) {
            dp1[i + 1][(j + ki) % d] += dp1[i][j];
            for (int k = 0; k < ki; ++k) {
                dp2[i + 1][(j + k) % d] += dp1[i][j];
            }
            for (int k = 0; k < 10; ++k) {
                dp2[i + 1][(j + k) % d] += dp2[i][j];
            }
        }
    }
    mint ret = dp1[n][0] + dp2[n][0] - mint(1);
    cout << ret.v << "\n";
    return 0;
}

Measured memory_bytes: 32256
#include<stdio.h>
#define MAX 100001
int parent(int);
int left(int);
int right(int);
int main(){
  int n,A[MAX],i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i)>=1) printf("parent key = %d, ",A[parent(i)]);
    if(left(i)<=n)printf("left key = %d, ",A[left(i)]);
    if(right(i)<=n)printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
  return 0;
}
int parent(int i){
return i/2;
}
int left(int i){
  return 2*i;
}
int right(int i){
  return 2*i+1;
}
  



Measured memory_bytes: 2048
#include <bits/stdc++.h>
#define ALL(V) (V).begin(),(V).end()
using namespace std;
using ll = int64_t;
template <typename T> using V = vector<T>;

ll zero = 0;

bool is_op(char c) {
    return c == '+' ||
           c == '-' ||
           c == '*' ||
           c == '/';
}

bool is_dig(char c) { return '0' <= c && c <= '9'; }

ll solve(string S) {
    V<ll> op_idx;
    for(ll i = 0; i < S.size(); i++) if(is_op(S[i])) op_idx.push_back(i);
    const auto id_lis = op_idx;

    auto get_op_id = [&](ll idx) {
        return distance(id_lis.begin(),
                        lower_bound(ALL(id_lis), idx));
    };

    V<ll> depth(op_idx.size());
    
    {
        ll d = 0;
        for(ll i = 0; i < S.size(); i++) {
            if(S[i] == '(') d++;
            else if(S[i] == ')') d--;
            if(!is_op(S[i])) continue;
            depth[get_op_id(i)] = d;
        }
    }

    V<ll> op_idx_rev(op_idx.size());
    bool suc = true;

    function<ll(ll, ll)> calc_substr = [&](ll l, ll r) {
        ll first_op = -1;
        for(ll i = l; i < r; i++) {
            if(!is_op(S[i])) continue;
            if(first_op == -1) first_op = i;
            else if(op_idx_rev[get_op_id(i)] <
                    op_idx_rev[get_op_id(first_op)]) first_op = i;
        }
        if(first_op == -1) {
            ll ret = 0;
            for(ll i = l; i < r; i++) if(is_dig(S[i])) ret = ret * 10 + (S[i] - '0');
            return ret;
        }
        ll lv = calc_substr(l, first_op);
        ll rv = calc_substr(first_op + 1, r);
        if(!suc) return zero;
        switch(S[first_op]) {
            case '+': return lv + rv;
            case '-': return lv - rv;
            case '*': return lv * rv;
            case '/':
                if(rv == 0) {
                    suc = false;
                    return zero;
                } else {
                    return lv / rv;
                }
                break;
        }
        suc = false;
        return zero;
    };

    set<ll> results;
    do {
        suc = true;
        for(ll i = 0; i < op_idx.size(); i++) op_idx_rev[get_op_id(op_idx[i])] = i;
        for(ll i = 0; i < op_idx.size(); i++) {
            ll id1 = get_op_id(op_idx[i]);
            for(ll j = i; j < op_idx.size(); j++) {
                ll id2 = get_op_id(op_idx[j]);
                if(depth[id2] < depth[id1]) {
                    suc = false;
                    break;
                }
            }
        }
        ll ret = (suc ? calc_substr(0, S.size()) : 0);
        if(suc) results.insert(ret);
    } while(next_permutation(ALL(op_idx)));

    return results.size();
}

int main() {
    while(true) {
        string S;
        cin >> S;
        if(S == "#") break;
        cout << solve(S) << endl;
    }
    return 0;
}



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

#define pb push_back
#define ll long long
#define maxn 200005
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define ms(i) memset(i,0,sizeof(i));
#define ms1(i) memset(i,-1,sizeof(i));
#define F first
#define S second

int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n,k;
	while(cin >> n >> k){
		if(n < k){
			printf("0");
		}
		else{
			printf("10");
		}
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <cstdio>
#include <stdlib.h>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;
int cnt;

void merge(int a[],int left,int mid ,int right){
  int n1=mid-left,n2=right-mid;
  int l[n1+1],r[n2+1];
  for(int i=0;i<n1;i++)
    l[i]=a[left+i];
  for(int i=0;i<n2;i++)
    r[i]=a[mid+i];
  l[n1]=r[n2]=1+pow(10,9);
  int i=0,j=0,k;
  for(k=left;k<right;k++){
    if(l[i]<=r[j]){
      a[k]=l[i];
      i++;
    }
    else{
      a[k]=r[j];
      j++;
    }
    cnt++;
  }
}
void mergesort(int a[],int left,int right){
  int mid;
  if(left+1<right){
    mid = (left +right)/2;
    mergesort(a,left,mid);
    mergesort(a,mid,right);
    merge(a,left,mid,right);
  }
}

int main(){
  int n,i;
  cin>>n;
  int s[n];
  for(i=0;i<n;i++)
    cin>>s[i];
  mergesort(s,0,n);
  for(i=0;i<n-1;i++)
    cout<<s[i]<<" ";
  cout<<s[i]<<endl<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 6992
def calc(expression):
    result = int(expression[0])
    i = 1
    while i < len(expression):
        c = expression[i]
        if c == "+":
            i+=1
            result+=int(expression[i])
        elif c == "-":
            i+=1
            result-=int(expression[i])
        i+=1
    return result

S=input()
ex=[S[0]]

for s in S[1:]:
    tmp=ex
    ex=[]
    for e in tmp:
        ex.append(e + "+" + s)
        ex.append(e + "-" + s)

for e in ex:
    if calc(e) == 7:
        print(e+"=7")
        break



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

int main(){
    int n, h;
    while(cin >> n >> h, n+h){
        set<pair<int,pair<int,int>>> s;
        string axis;
        int a, b;
        while(h-- > 0){
            cin >> axis >> a >> b;
            if(axis == "xy"){
                for(int i = 1; i <= n; i++)  s.insert({a,{b,i}});
            }else if(axis == "xz"){
                for(int i = 1; i <= n; i++)  s.insert({a,{i,b}});
            }else if(axis == "yz"){
                for(int i = 1; i <= n; i++)  s.insert({i,{a,b}});
            }
        }
        cout << n*n*n - s.size() << endl;
    }
    return 0;
}


Measured memory_bytes: 6268
#include<stdio.h>
long int alp(long int n)
{
    long int s=0,p;
    while (n!=0)
    {
        p=n%10;
        s+=p;
        n/=10;
    }
    return s;
}
int main()
{
    long int n,p;
    scanf ("%ld",&n);
    p=alp(n);
    if (n%p==0)
    {
        printf ("Yes\n");
    }
    else if (n%p!=0)
    {
        printf ("No\n");
    }


    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

vector<vector<int>> G;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    
    int N, M;
    cin >> N >> M;
    G.resize(N);
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a--, b--;
        G[a].pb(b);
        G[b].pb(a);
    }
    
    bool ok = false;
    for(int a: G[0]){
        for(int b: G[a]){
            if(b == N - 1){
                ok = true;
            }
        }
    }
    if(ok){
        output("POSSIBLE");
    }
    else{
        output("IMPOSSIBLE");
    }
    
    
    
    return 0;
}

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

typedef pair<int, int> P;

P f(int x) {
  int a = x % 10;
  int b = 0;
  while (x) {
    b = x;
    x /= 10;
  }
  return P(a, b);
}

int main() {
  int n; cin >> n;
  map<P, int> mp;
  rep(i, n) mp[f(i + 1)]++;
  ll ans = 0;
  rep(i, 9) rep(j, 9)
      ans += mp[{i + 1, j + 1}] * mp[{j + 1, i + 1}];
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <string>
#include <iostream>
#include<list>
#include<array>
#include<vector>
#include <algorithm>
#include <functional>
using namespace std;

bool IsAllDifferent(int a, int b, int c) {
	if (a == b or b == c or c == a) {
		return false;
	}
	else {
		return true;
	}
}

bool Can_Make_Triangle(int a, int b, int c) {
	if ((a + b) > c and (b + c) > a and (c + a) > b) {
		return true;
	}else {
		return false;
	}
}


int main()
{
	int N;
	vector<int> L ;
	cin >> N;
	for (int i = 0; i < N; i++) {
		int tmp;
		cin >> tmp;
		L.push_back(tmp);
	}

	int count = 0;
	for (int i = 0; i < N - 2; i++) {
		for (int j = i + 1; j < N - 1; j++) {
			for (int k = j + 1; k < N; k++) {
				int a = L[i];
				int b = L[j];
				int c = L[k];
				if (IsAllDifferent(a, b, c) and Can_Make_Triangle(a, b, c)) {
					count++;
				}
			}
		}
	}

	cout << count;

	return 0;
}



Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=100000000000000000;


int main() {
    int a,b;
    cin >> a >> b;
    if (a>9 || b>9) cout << -1 << endl;
    else cout << a*b << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
inline int read(){
	int x=0,f=1;char ch=getchar();
	for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
	for(;isdigit(ch);ch=getchar())x=(x<<3)+(x<<1)+(ch^'0');
	return x*f;
}
int n;
int a[202];
int Ans;
int main(){
	n=read();
	for(register int i=1;i<=2*n;++i)
		a[i]=read();
	sort(a+1,a+2*n+1);
	for(register int i=1;i<=2*n;i+=2)
		Ans+=a[i];
	cout<<Ans<<endl;
	return 0;
}


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

ll cnt_divisors(ll N) {
  ll res = 0;
  for (ll i = 1; i * i <= N; ++i) {
    if (N % i == 0) {
      res++;
      if (N/i != i) res++;
    }
  }
  return res;
}

int main() {
  ll n;
  cin >> n;
  ll ans = 0;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      ll k = n;
      while(k % i == 0) k /= i;
      if (k % i == 1) ans++;
    }
  }
  ans += cnt_divisors(n-1);
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3608
/*
[abc141] F - Xor Sum 3
*/

#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
#define ALL(c) (c).begin(), (c).end()

const int MAX_N = 1e5;
const int MAX_D = 60;

typedef vector<bitset<MAX_D>> Matrix;

int mat_rank(Matrix &A) {
    const int n = A.size(), m = A[0].size();
    int r = 0;
    for (int i = 0; r < n && i < m; ++i) {
        int pivot = r;
        for (int j = r; j < n; ++j) {
            if (A[j][m - i - 1]) {
                pivot = j;
                break;
            }
        }
        swap(A[pivot], A[r]);
        if (A[r][m - i - 1] == 0) {
            continue;
        }
        for (int j = r + 1; j < n; ++j) {
            if (A[j][m - i - 1]) {
                A[j] ^= A[r];
            }
        }
        ++r;
    }

    return r;
}

int N;
Matrix A;

ll solve() {
    bitset<MAX_D> s;

    for (int i = 0; i < N; i++) {
        s ^= A[i];
    }

    for (int i = 0; i < N; i++) {
        A[i] &= ~s;
    }
    mat_rank(A);

    bitset<MAX_D> x;
    for (int i = 0; i < N; i++) {
        if ((x ^ A[i]).to_ullong() > x.to_ullong()) {
            x ^= A[i];
        }
    }

    ll ans = (x | s).to_ullong() + x.to_ullong();
    return ans;
}

int main() {
    cin >> N;
    A.resize(N);
    for (int i = 0; i < N; i++) {
        ll a;
        cin >> a;
        A[i] = bitset<MAX_D>(a);
    }

    cout << solve() << endl;

    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <array>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;

constexpr double EPS = 1e-7;

template <typename T>
constexpr T INF = numeric_limits<T>::max();

template <class T>
constexpr T PI = static_cast<T>(3.14159265358979323846);

constexpr int MOD = 1e9 + 7;

template <class T>
bool chmin(T &a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}

template <class T>
bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}

template <typename T>
std::vector<T> table(int n, T v) { return std::vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
	auto val = table(args...);
	return std::vector<decltype(val)>(n, std::move(val));
}

int main(int argc, char const *argv[]) {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);

	int N;
	cin >> N;

	auto A = table(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	sort(A.begin(), A.end());

	bool ans = true;
	for (int i = 0; i < N - 1; i++) {
		if (A[i] == A[i + 1]) {
			ans = false;
		}
	}
	if (ans) {
		cout << "YES" << endl;
	} else {
		cout << "NO" << endl;
	}

	return 0;
}


Measured memory_bytes: 1024
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)

	N, K := nextInt(), nextInt()
	A := make([]int, N)
	maxA := -1
	for i := 0; i < N; i++ {
		A[i] = nextInt()
		maxA = max(maxA, A[i])
	}

	gcdA := Gcd(A)

	if K <= maxA && K%gcdA == 0 {
		fmt.Println("POSSIBLE")
	} else {
		fmt.Println("IMPOSSIBLE")
	}

}

func max(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func Gcd(args []int) int {
	b := args[0]

	for _, a := range args {
		b = gcdBase(a, b)
	}
	return b
}

func gcdBase(a, b int) int {
	if b == 0 {
		return a
	}

	return gcdBase(b, a%b)
}


Measured memory_bytes: 3072
#include <bits/stdc++.h>
#define re return
#define ll long long
#define ld long double
#define f first
#define s second
#define pi acos(-1)
#define oo (int)1e9
#define OO (ll)1e18
#define EPS 1e-7
#define FX(n) fixed<<setprecision(n)
#define mm(o,k) memset(o,k,sizeof o)
#define IO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
using namespace std;
const int maxn=505;

int main()
{
    IO;
    string s;
    cin >> s;
    cout<<s[0];
    cin >> s;
    cout<<s[1];
    cin >> s;
    cout<<s[2];
    re 0;
}


Measured memory_bytes: 256