akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define INF 1e9
#define llINF 1e18
#define MOD 1000000007
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long
#define ull unsigned long long
#define vi vector<ll>
#define vvi vector<vi>
#define BITLE(n) (1LL<<((ll)n))
#define BITCNT(n) (__builtin_popcountll(n))
#define SUBS(s,f,t) ((s).substr((f)-1,(t)-(f)+1))
#define ALL(a) (a).begin(),(a).end()
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll n;cin>>n;
  if(n%2)cout<<0<<endl;
  else{
    ll ans=0;
    for(ll i=10;i<=n;i*=5){
      ans+=n/i;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import heapq
n,m=map(int,input().split())
work=[[] for i in range(m)]
for i in range(n):
    a,b=map(int,input().split())
    a-=1
    if a>=m:continue
    heapq.heappush(work[a],-b)
#print(work)
ans=0
nowwork=[]
for i in range(m):
    for j in work[i]:
        heapq.heappush(nowwork,j)
    #print(nowwork)
    if nowwork==[]:
        continue
    ans+=heapq.heappop(nowwork)
print(-ans)


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

int gcd(int x, int y){
    if(x == 0 || y == 0) return std::max(x, y);
    if(y > x){
        int tmp = x;
        x = y;
        y = tmp;
    }
    int r;
    do{
        r = x % y;
        x = y;
        y = r;
    }while(r > 0);
    return x;
}

 int main(){
    int N;
    vector<int> A;

    cin >> N;
    A.resize(N);
    for(int i=0; i<N; i++)
        cin >> A[i];
    
    vector<int> gcd_L(N), gcd_R(N);
    gcd_L[0] = 0;
    gcd_R[N-1] = 0;

    for(int i=1; i<N; i++){
        gcd_L[i] = gcd(gcd_L[i-1], A[i-1]);
    }
    for(int i=N-2; i>=0; i--){
        gcd_R[i] = gcd(gcd_R[i+1], A[i+1]);
    }

    int gcd_max = 0;
    for(int i=0; i<N; i++){
        int tmp = gcd(gcd_L[i], gcd_R[i]);
        if(tmp > gcd_max) gcd_max = tmp;
    }
    
    cout << gcd_max << endl;
 }

Measured memory_bytes: 1408
N = int(input())
data = input().split()
data = data[:N]

color = [0, 0, 0, 0, 0, 0, 0, 0]
count = 0

for i in data:
	i = int(i)
	if(i< 400):				#灰色
		if(color[0] == 0):
			color[0] = 1
	elif(i < 800):			#茶色
		if(color[1] == 0):
			color[1] = 1
	elif(i < 1200):			#緑色
		if(color[2] == 0):
			color[2] = 1
	elif(i < 1600):			#水色
		if(color[3] == 0):
			color[3] = 1
	elif(i < 2000):			#青色
		if(color[4] == 0):
			color[4] = 1
	elif(i < 2400):			#黄色
		if(color[5] == 0):
			color[5] = 1
	elif(i < 2800):			#橙色
		if(color[6] == 0):
			color[6] = 1
	elif(i < 3200):			#赤色
		if(color[7] == 0):
			color[7] = 1
	else:					#3200以上
		count += 1

flag = sum(color)
if(flag == 0):
	min = 1
	max = count
else:
	min = flag
	max = min + count

print(min, max)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<iostream>
#include<string>
#include<vector>
#define ll long long
#define MAX 1000003
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define endl "\n"
#define all(a) (a).begin(),(a).end()
#define input(a) for(int i=0;i<n;i++) cin>>a[i];
using namespace std;

int main(){
	IOS;
	int n; cin>>n;
	vector<int> l(n);
	input(l);
	sort(all(l));
	ll sum=0;
	for(int i=0;i<n-1;i++){
		sum+=l[i];
	}	


	if(sum<=l[n-1])
		cout<<"No"<<endl;
	else cout<<"Yes"<<endl;

return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cmath>
#include <numeric>
#include<map>
 
 
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 1e13
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
typedef long long int ll;
#define MOD 1000000007


/*nまでの素数を列挙して配列に保持*/
vector<int> Eratosthenes(int n,vector<int>& arr){

	for(int i = 0; i < n;i++){
		arr[i] = 1;
    }
    arr[0] = arr[1] = 0;

	for(int i = 2; i < sqrt(n); i++){
		if(arr[i]){
			for(ll j = 0; i * (j + 2) < n; j++){
				arr[i *(j + 2)] = 0;
			}
		}
    }
    return arr;
}


int main(){


    int n;
    int tmp = 1000000;
    vector<int> arr(tmp);


    arr = Eratosthenes(tmp,arr);/*50000までの素数を列挙*/
    
    while(cin >> n,n){
        int count = 0;
        for(int i = 2;i <= n/2;i++){

            if(i <= n-i && arr[i] && arr[n-i]){
                count++;
            }
        }
        cout << count << endl;
    }
    
    
    return 0;
}


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

typedef long long ll;

ll gcd( ll x, ll y );
ll lcm( ll x, ll y );

ll p[65535], j[65535];

int main()
{
    ll n, i, sum, ans;

    scanf("%lld", &n );

    while ( n != 0 ) {
        sum = 0;
        ans = 0;

        for ( i = 0; i < n; ++i ) {
            scanf("%lld", &p[i] );
            sum += p[i];
        }

        ans = sum * n;

        for ( i = 0; i < n - 1; ++i ) {
            scanf("%lld", &j[i] );
        }

        sort( j, j + ( n - 1 ));

        ll tmp = 0;

        for ( i = 0; i < n - 1; ++i ) {
            tmp += j[ n - i - 2 ];
            if ( ans < ( sum + tmp ) * ( n - i - 1 ) ) {
                ans = ( sum + tmp ) * ( n - i - 1 );
            }
        }

        printf("%lld\n", ans );

        scanf("%lld", &n );
    }
    return 0;
}

ll gcd( ll x, ll y )
{
    if ( y == 0 ) return x;
    return gcd( y, x % y );
}

ll lcm( ll x, ll y )
{
    return x / gcd( x, y ) * y;
}



Measured memory_bytes: 4148
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
using namespace std;
typedef long long int ll;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}



int main() {
    string s;
    cin >> s;
    int ss = s.size();
    ll MOD = 1000000007;
    ll z[ss];
    ll o[ss];
    z[0] = 1;
    o[0] = 2;

    srep(i,1,ss){
        if(s[i]=='0'){
            z[i] = (z[i-1]*3) % MOD;
            o[i] = o[i-1];
        }else{
            z[i] = (z[i-1]*3 + o[i-1]) % MOD;
            o[i] = (o[i-1] * 2) % MOD;
        }
    }

    cout << (z[ss-1]+o[ss-1])%MOD << endl;

    return 0;
}
 
 


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

int main(){
    int n, m; cin >> n >> m;

    vector<vector<int> > sw(m);
    rep(i,m) {
        int k; cin >> k;
        rep(j,k) {
            int a; cin >> a; --a;
            sw[i].push_back(a);
        }
    }

    vector<int> p(m);
    rep(i,m) cin >> p[i];

    ll ans = 0;

    for(int bit = 0; bit < (1 << n); bit++){
        bool jud = true;

        rep(i,m){
            int tmp = 0;
            
            for(auto v: sw[i]){
                if(bit & (1 << v)) tmp++;
            }

            if(tmp %2 != p[i]) jud = false;

        }

        if(jud) ans++;
    }

    dunk(ans);
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
from itertools import product

class thee(int):
    def __add__(self, that):
        return thee(max(int(self), int(that)))

    def __mul__(self, that):
        return thee(min(int(self), int(that)))
    
    def __neg__(self):
        T = [2, 1, 0]
        return thee(T[int(self)])

S = input()
while S != ".":
    for x in list("012PQR"):
        S = S.replace(x, "thee({})".format(x))
    ans = 0
    for P, Q, R in product(range(3), repeat=3):
        ans += 2 == int(eval(S))
    print(ans)
    S = input()



Measured memory_bytes: 5680
n, y = map(int, input().split())

y //= 1000

if 10*n < y:
    print(-1, -1, -1)
    exit()

for i in range(n+1):
    for j in range(n-i+1):
        otoshidama = 10*i + 5*j
        otoshidama_1 = n-i-j if n-i-j > 0 else 0
        otoshidama += otoshidama_1
        if otoshidama == y and i+j+otoshidama_1:
            print(i, j, otoshidama_1)
            exit()
else:
    print(-1, -1, -1)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
//#define kk
#define int long long
#define FOR(a, b) for(int i=a; i<=b; i++)
#define REP(i, a, b) for(int i=a; i<=b; i++)
#define ff first
#define ss second
#define ll long long
#define inf 1000000000
#define pb push_back
#define mod 1000000007
 
const ll INF=1e18+5;
const int maxN=2e5+5;
typedef pair<int, int> pi;

int fact[maxN], inv_fact[maxN];

int power(int a, int n){
	int res=1;
	
	while(n){
		if(n%2) res=(res%mod*a%mod)%mod, n--;
		else a=(a%mod*a%mod)%mod, n/=2;
	}
	return res;
}

void init(){
	fact[0]=inv_fact[0]=1;
	
	for(int i=1; i<maxN; i++){
		fact[i]=(i*fact[i-1])%mod;
		inv_fact[i]=power(fact[i], mod-2)%mod;
	}
}

int combinator(int a, int b){
	if(a<0 || b<0 || a<b) return 0;
	
	return (fact[a]%mod*inv_fact[b]%mod*inv_fact[a-b]%mod)%mod;
}

void solve(){
	int h, w, n;
	cin>>h>>w>>n;
	
	vector<pi> arr(n);
	
	for(int i=0; i<n; i++){
		int a,b;
		cin>>a>>b;
		arr[i]={a-1,b-1};
	}
	arr.pb({h-1, w-1});
	
	sort(arr.begin(), arr.end(), [](pi a, pi b){
		return a.ff+a.ss<b.ff+b.ss;
		});
		
	init();
	
	vector<int> dp(n+1, 0);
	
	for(int i=0; i<=n; i++){
		int a=arr[i].ff, b=arr[i].ss;
		int f=combinator(a+b, b);
		
		for(int j=0; j<i; j++){
			int c=arr[j].ff, d=arr[j].ss;
			if(c<=a && d<=b){
				f=(f-((dp[j]%mod*combinator(a-c+b-d, b-d)%mod)%mod)+mod)%mod;
			}
		}
		dp[i]=f;
	}
	cout<<dp[n]<<endl;
}
 
signed main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	
	cout<<fixed<<setprecision(6);
	
	#ifdef kk
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	
	int T=1;
	//cin>>T;
	
	while(T--){		
		solve();
	}
}


Measured memory_bytes: 6860
#include <cstdio>
#include <cstring>
#include <algorithm>
#define MAXN 200010
#define MAXS 1000010
using namespace std;

int read(){
    char c;
    while(((c=getchar())<'0' || c>'9') && c!='-');
    int flag=1;
    int res=c-'0';
    if(c=='-'){
        flag=-1;
        res=0;
    }
    while((c=getchar())>='0' && c<='9') res=res*10+c-'0';
    return res*flag;
}

int n,m,v0,maxs;
int a[MAXN];
int lim[MAXN];
int f1[MAXS],f2[MAXS];
int p[20][MAXN][2];
int c[MAXN];

void calcP(int l){
    int last=1;
    for(int i=1;i<=n;i++){
        if(i==n || a[i+1]-a[i]>lim[l]){
            for(int j=last;j<=i;j++){
                p[l][j][0]=last;
                p[l][j][1]=i;
            }
            last=i+1;
        }
    }
    p[l][0][0]=1;
    p[l][n+1][1]=n;
}

void dp(){
    f1[0]=0; f2[0]=n+1;
    for(int s=1;s<maxs;s++){
        f2[s]=n+1;
        for(int i=1,l=1;i<=m;i++,l<<=1)
            if(s&l){
                f1[s]=max(f1[s],p[i][f1[s^l]+1][1]);
                f2[s]=min(f2[s],p[i][f2[s^l]-1][0]);
            }
    }
}

int main(){
#ifdef DEBUG
    freopen("g012e.in","r",stdin);
#endif
    n=read(); v0=read();
    for(int i=1;i<=n;i++) a[i]=read();
    lim[0]=v0;
    while(v0) lim[++m]=(v0/=2);
    maxs=1<<m;
    for(int i=0;i<=m;i++) calcP(i);
    dp();
    memset(c,-1,sizeof c);
    for(int i=0;i<maxs;i++)
        c[f2[i]]=max(c[f2[i]],f1[(maxs-1)^i]);
    int cur=-1,now=-1;
    for(int i=1;i<=n;i++)
        if(p[0][i][0]==i){
            while(cur<p[0][i][1]+1) now=max(now,c[++cur]);
            if(now>=i-1)
                for(int j=p[0][i][0];j<=p[0][i][1];j++)
                    puts("Possible");
            else
                for(int j=p[0][i][0];j<=p[0][i][1];j++)
                    puts("Impossible");
        }
    return 0;
}

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

namespace ABCTemplate_A
{
    public class Program
    {
        static void Main(string[] args)
        {
            var a = new ProblemA();
		}
    }

    public class ProblemA
    {
        public ProblemA()
        {
            
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            int a = int.Parse(input[0]);
            int b = int.Parse(input[1]);
            int c = int.Parse(input[2]);

            var work = a;
            a = b;
            b = work;
            var work2 = a;
            a = c;
            c = work2;
            //出力
            Console.WriteLine($"{a} {b} {c}");
        }
    }
}


Measured memory_bytes: 13140
#include <stdio.h>
#include <math.h>

int main(void){
  long long int a,b,c,na,nb,nc;
  double m = pow(10,9);
  
  int i=0;
  scanf("%lld %lld %lld", &a, &b, &c);
  while(1){
    if(a%2 || b%2 || c%2) break;
  	if(a==b && b==c){
    	printf("-1\n");
    	return 0;    
  	}
    na = b/2+c/2;
    nb = a/2+c/2;
    nc = a/2+b/2;
    a=na;b=nb;c=nc;
    i++;
  }    
      

        printf("%d", i);


  
  return 0;
}
    
  

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

int main() {
  int N, T, A;
  cin >> N >> T >> A;
  vector<int> H(N);
  for (int i=0; i<N; i++) {
    cin >> H.at(i);
  }
  vector<double> ave(N);
  for (int i=0; i<N; i++) {
    ave.at(i) = T-H.at(i)*0.006;
  }
  double diameter = 100000;
  for (int i=0; i<N; i++) {
    diameter = min(diameter, abs(ave.at(i)-A));
  }
  int answer;
  for (int i=0; i<N; i++) {
    if (diameter == abs(ave.at(i)-A)) {
      answer = i+1;
      break;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
s = input()

ans = []
for i in range(len(s)):
  if s[i] == "0":
    ans.append(s[i])
  if s[i] == "1":
    ans.append(s[i])
    
  if s[i] == "B":
    if len(ans) == 0:
      continue
    else:
      del ans[-1]
      
      
print("".join(ans))

Measured memory_bytes: 3060
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define pi acos(-1.0)
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//cout << fixed << setprecision (20);   小数点以下2０桁まで
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'0'+=16;        で大文字に
//'大文字'+=32;    で小文字に
//s[i]-'0'でchar文字→int数に;
//string s = to_string(int数);
//int n = stoi(string文字列)
//実行時間制約2秒では２×10^8回くらいまで計算できる


int main() {
  int a,b;
  cin >> a>>b;
  
  repo(i,2000){
    if(i*8/100==a && i/10==b) {
    cout << i << endl;
    return 0;
    }
    if(i==1999) cout << -1 << endl;
  }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

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

Measured memory_bytes: 3668
using System;
    using System.Linq;
    using System.Collections.Generic;
    using static System.Math;

    public class Program
    {
        public static void Main(string[] args)
        {
            int num = int.Parse(Console.ReadLine());
            List<int> input = Console.ReadLine().Split(' ').Select(int.Parse).ToList();
            int count = 0;

            while (input.Where(y => y % 2 == 0).Count() == num)
            {
                count++;
                input = input.Select(x => x / 2).ToList();
            }

            Console.WriteLine(count);
        }
    }

Measured memory_bytes: 13396
#include <stdio.h>

int main ()
{
    int A, B;
    int Ad, S, M;

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

    Ad = A + B;
    S = A - B;
    M = A * B;

    if (Ad > S && Ad > M)
    {
        printf("%d\n", Ad);
    }
    else if (S > Ad && S > M)
    {
        printf("%d\n", S);
    }
    else if (M > Ad && M > S)
    {
        printf("%d\n", M);
    }
    else
    {
        printf("%d\n", A);
    }

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static final int MOD = 1000000007;

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        if (n == 0) {
            System.out.println(1);
        } else {
            System.out.println(0);
        }
    }
}

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

using namespace std;

int main(void){

    int n, x;
    cin >> n >> x;
    
    vector<int> m(n);
    for(int i=0; i<n; i++) {
        cin >> m[i];
        x -= m[i];
    }
    
    int min = *min_element(m.begin(), m.end());
    int count = x/min;
    
    cout << n + count << endl;
    
    return 0;
    
}


Measured memory_bytes: 256
// ABC057 B - Checkpoints
#include <stdio.h>
#include <stdlib.h>

int distance(int a, int b, int c, int d)
{
    return abs(a - b) + abs(c - d);
}

int main(void)
{
    int N, M;
    scanf("%d %d", &N, &M);
    int a[N], b[N];
    int c[M], d[M];
    int i, j;
    for (i = 0; i < N; i++) {
        scanf("%d %d", &a[i], &b[i]);
    }
    for (i = 0; i < M; i++) {
        scanf("%d %d", &c[i], &d[i]);
    }

    for (i = 0; i < N; i++) {
        int near = ~(1 << 31);
        int point = -1;
        for (j = 0; j < M; j++) {
            int dist = distance(a[i], c[j], b[i], d[j]);
            if (dist < near) {
                near = dist;
                point = j + 1;
            }
        }
        printf("%d\n", point);
    }

    return 0;
}

Measured memory_bytes: 384
import java.math.BigDecimal;
import java.math.MathContext;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {
    static Scanner sc = new Scanner(System.in);
    static double A = sc.nextDouble();
    static double B = sc.nextDouble();
    static double H = sc.nextDouble();
    static double M = sc.nextDouble();

    public static void main(String[] args) {
        //角度を求める
        double kHour = (H + (M / 60)) * 30;
        double kMin = M * 6;
        double kakudo = Math.abs(kHour - kMin);
        double dC = Math.pow(A, 2) + Math.pow(B, 2) - 2 * A * B * Math.cos(Math.toRadians(kakudo));
        BigDecimal x = new BigDecimal(Math.sqrt(dC));
        MathContext mc = new MathContext(50, RoundingMode.UP);
        BigDecimal result = x.round(mc);
        System.out.print(result);



    }

}

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

int main() {

  int N,K;
  string S;
  cin >> N >> K >> S;

  vector<int> c(0);
  int num = 1;
  for(int i = 0;i < N;i++) {
    if(i == N-1) {
      if(S.at(i) == '0') c.push_back(-num);
      else c.push_back(num);
    }else if(S.at(i) != S.at(i+1)) {
      if(S.at(i) == '0') c.push_back(-num);
      else c.push_back(num);
      num = 1;
    }else num++;
  }

  long long sum = 0,ans = 0;
  int top = 0,last = 0,k = K;
  if(c.at(0) > 0) last++;

  while(k >= 0) {
    if(top >= c.size()) break;
    if(c.at(top) > 0) sum += c.at(top);
    else {
      if(k == 0) break;
      sum -= c.at(top);
      k--;
    }
    
    top++;
  }

  ans = sum;
  while(top < c.size()) {
    if(top < c.size()-1) sum += c.at(top+1);
    sum -= c.at(top);
    top+=2;
    if(last > 0) sum -= c.at(last-1);
    sum += c.at(last);
    last+=2;

    ans = max(sum,ans);
  }

  cout << ans << endl;

}

Measured memory_bytes: 1020
#include <iostream>
#include <cstdio>
#include <cmath>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;
const int N=1e5+5;
struct edge{
	int v,Next;
}e[N<<2];
int head[N],cnt,n,root,ans=1;
long long a[N],d[N];
void addedge(int u,int v){
	e[++cnt].v=v;
	e[cnt].Next=head[u];
	head[u]=cnt;
}
void dfs(int p,int fa){
	long long Maxn=0,Sum=0;
	for(int ne=head[p];ne;ne=e[ne].Next){
		if(e[ne].v==fa) continue;
		dfs(e[ne].v,p);
		Sum+=a[e[ne].v];
		Maxn=max(Maxn,a[e[ne].v]);
	}
	if(d[p]==1) return ;
	long long x=Sum-a[p],y=2*a[p]-Sum;
	if(x<0||y<0||x>min(Sum-Maxn,Sum/2)||(fa==0&&y)) ans=0;
	a[p]=y;
}
int main(){
	scanf("%d",&n);
	rep(i,1,n) scanf("%lld",&a[i]);
	rep(i,2,n){
		int u,v;
		scanf("%d%d",&u,&v);
		addedge(u,v);addedge(v,u);
		d[u]++;d[v]++;
	}
	rep(i,1,n) if(d[i]>1) root=i;
	if(root) dfs(root,0); else ans=a[1]==a[2];
	if(ans) puts("YES"); else puts("NO");
	return 0;
}


Measured memory_bytes: 9984
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

        Scanner sc = new Scanner(System.in);
        
        int N = sc.nextInt();
        String[] S = new String[N];
        int[] P = new int[N];
        
        for(int i = 0 ; i < N; i++){
            S[i] = sc.next();
            P[i] = sc.nextInt();
        }
        int[] key = new int[N];
        for(int i = 0; i < N; i++){
            int count = 1;
            for(int j = 0; j < N; j++){
                if(S[i].compareTo(S[j]) > 0){
                    count++;
                }else if(S[i].compareTo(S[j]) == 0){
                    if(P[i] < P[j]){
                        count++;
                    }
                }
            }
            key[i] = count;
        }
        
        Map<Integer,Integer> map = new TreeMap<Integer,Integer>();
        for(int i = 0; i < N; i++){
            map.put(key[i], i+1);
        }
        
        for(Integer val : map.values()){
            System.out.println(val);
        }
    }
}

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

using mint = modint998244353;

struct S{
    mint value;
    mint size;
};
using F = mint;

const mint div9 = mint(1)/9;

S op(S a, S b){ return {a.value*b.size+b.value, a.size*b.size}; }
S e(){ return {0, 1}; }
S mapping(F f, S x){
    if(f != 0) x.value = f*(x.size-1)*div9;
    return x;
}
F composition(F f, F g){ return (f == 0 ? g : f); }
F id(){ return 0; }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, q, l, r, d;
    cin >> n >> q;
    lazy_segtree<S, op, e, F, mapping, composition, id> seg(n);
    rep(i, n) {
        seg.set(i, {1, 10});
    }
    cout << endl;
    rep(i, q) {
        cin >> l >> r >> d;
        seg.apply(l-1, r, d);
        cout << seg.all_prod().value.val() << endl;
    }
}

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

int64 sqrt(int64 x) {
  int64 l = 1, r = 1e9;
  while (l < r) {
    int64 m = (l + r) / 2 + 1;
    if (m * m <= x) l = m;
    else r = m - 1;
  }
  return l;
}

int64 solve(int64 a, int64 b) {
  if (a == 1 && b == 1) return 0;
  int64 x = a * b - 1;
  int64 o = sqrt(x);
  int64 ans = 2 * o - (x / o == o);
  if (a <= o || b <= o) --ans;
  return ans;
}

int main() {
  int q;
  scanf("%d", &q);
  while (q--) {
    int a, b;
    scanf("%d%d", &a, &b);
    printf("%lld\n", solve(a, b));
  }
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz size
#define f first
#define s second

int main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n, k;

    string input;

    cin >> n >> k >> input;
    
    input[k - 1] += 32;

    cout << input;

    return 0;
}


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

public class Main {

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line[] = br.readLine().split(" ");
		int a = Integer.parseInt(line[0]);
		int b = Integer.parseInt(line[1]);
		String ans = "Yes";

		if (a % 2 == 0 || b % 2 == 0) {
			ans = "No";
		}

		System.out.println(ans);
	}
}


Measured memory_bytes: 21076
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define rrep(ri,n) for(int ri = (int)(n-1); ri >= 0; ri--)
#define rep2(i,x,n) for(int i = (int)(x); i < (int)(n); i++)
#define repit(itr,x) for(auto itr = x.begin(); itr != x.end(); itr++)
#define rrepit(ritr,x) for(auto ritr = x.rbegin(); ritr != x.rend(); ritr++)
#define ALL(x) x.begin(), x.end()
using ll = long long;
using namespace std;

int main(){
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  rep(snip_i, h) cin >> s.at(snip_i);
  int dj[] = {1, 1, 0, -1, -1, -1, 0, 1}, di[] = {0, 1, 1, 1, 0, -1, -1, -1};
  vector<vector<int>> ans(h, vector<int>(w, 0));
  rep(i, h){
    rep(j, w){
      if(s.at(i).at(j) == '#'){
        ans.at(i).at(j) = -1;
        continue;
      }
      int co = 0;
      rep(k, 8){
        int ni = i + di[k], nj = j + dj[k];
        if(nj < 0 || w <= nj || ni < 0 || h <= ni) continue;
        if(s.at(ni).at(nj) == '#')co++;
      }
      ans.at(i).at(j) = co;
    }
  }
  rep(i, h){
    rep(j, w){
      if(ans.at(i).at(j) == -1) cout << '#';
      else cout << ans.at(i).at(j);
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,x,y=map(int,input().split())
x-=1;y-=1
dist=[0]*(n-1)
for i in range(n-1):
  for j in range(i+1,n):
    d=min(abs(x-i)+abs(y-j)+1,j-i)
    dist[d-1]+=1
for i in dist:print(i)

Measured memory_bytes: 47196
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <tuple>
#include <stack>

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define print(s) cout << s << endl
typedef long long ll;
using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main() {
	int n,k; cin >> n >> k;
	int x = 1;
	for (int i = 0; i < n; i++){
		if (x>k){
			x += k;
		}else {
			x *= 2;
		}
	}
	cout << x << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstring>
#include <cmath>
const int MOD = 1e9 + 7;
const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, 1, -1};
using namespace std;
typedef long long ll;
int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	int odd = 0, even = 0;
	long a;
	for(int i = 0; i < n; i++)
	{
		cin >> a;
		if(a % 2)
			odd++;
		else
			even++;
	}
	int tmp_odd = odd;
	int tmp_even = even;
	while(1)
	{
		if(tmp_odd <= 1)
			break;
		tmp_odd -= 2;
		tmp_even++;
	}
	if(tmp_odd == 0)
		cout << "YES" << endl;
	else 
		cout << "NO" << endl;
	return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int h,w;
	cin >> h >> w;
	int srow,scol,erow,ecol;
	cin >> srow >> scol;
	cin >> erow >> ecol;
	--srow,--scol,--erow,--ecol;
	string grid[h];
	for(int i = 0; i < h;++i){
		cin >> grid[i];
	}
//	bool ok = false;
	deque<pair<int,int> > dq;
	int dist[h][w];
	for(int i = 0; i < h;++i){
		for(int j = 0; j < w;++j){
			dist[i][j] = 1e7;
		}
	}
	dist[srow][scol] = 0;
	dq.push_back({srow,scol});
	while(!dq.empty()){
		pair<int,int> cur_node = dq.front();
		dq.pop_front();
		int row = cur_node.first;
		int col = cur_node.second;
//		if(row == erow && col == ecol){
//			ok = true;
//			break;
//		}
		for(int dx = -2;dx <= 2;++dx){
			for(int dy = -2;dy <= 2;++dy){
				int nrow = row + dx;
				int ncol = col + dy;
//				if(nrow == row && ncol == col)
//					continue;
				if(nrow < 0 || ncol < 0 || nrow >= h || ncol >= w ||(!dx && !dy) || grid[nrow][ncol] == '#')
					continue;
				int w = 1;
//				if(grid[nrow][ncol] == '#')
//					continue;
//				if((abs(nrow-row) == 1 && abs(ncol-col) == 0) || (abs(ncol-col) == 1 && abs(nrow-row) == 0))
//					w = 0;
                if((abs(dx) == 1 && dy == 0) || (abs(dy) == 1 && dx== 0))
                    w = 0;
				if(dist[nrow][ncol] > dist[row][col] + w){
					dist[nrow][ncol] = dist[row][col] + w;
					if(w == 0)
						dq.push_front({nrow,ncol});
					else
						dq.push_back({nrow,ncol});
				}
			}
		}
	}
//	if(!ok)
//		dist[erow][ecol] = -1;
//	cout << dist[erow][ecol] << "\n";
    cout<<(dist[erow][ecol] == 1e7?-1: dist[erow][ecol]);
    return 0;
}

Measured memory_bytes: 8612
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    
    long long int n;
    
    cin >> n;
    n++;   vector<int> ans;
    int cur = 1;
    long long buf = 0;
    int ket = 0;
    for(int i = 0; 60 > i; i++){
        if(n & (1LL << i))
            ket = max(i,ket);
    }
    for(int i = ket-1; i >= 0; i--){
            ans.insert(ans.begin() + ans.size() / 2, cur);
            ans.insert(ans.begin(), cur);
        cur++;
        if((n >> i) & 1){
            ans.insert(ans.begin(), cur);
            ans.push_back(cur);
            cur++;
        }
        
        
    }
    cout<< ans.size() << endl;
    
    for(auto itr : ans)
        cout << itr << " ";
    cout << endl;
}


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<random>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int> tp;
typedef vector<tp> vt;
typedef vector<vt>vvt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
int dx[]={-1,0,1,0};
int dy[]={0,1,0,-1};
#define yes cout<<"Yes\n"
#define no cout<<"No\n"


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

	int x,n;
	cin>>x>>n;
	vi in(110);
	rep(i,n){
		int a;cin>>a;
		in[a]=1;
	}
	rep(i,102){
		if(in[x-i]==0){
			cout<<x-i<<endl;
			return 0;
		}
		if(in[x+i]==0){
			cout<<x+i<<endl;
			return 0;
		}
	}
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <unordered_set>
#include <unordered_map>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	const int mod = 1e9 + 7;
	int N; cin >> N;
	vector<ll> v(N), psum(N + 1);

	for (int i = 0; i < N; i++) cin >> v[i];
	for (int i = 0; i < N; i++) psum[i + 1] = (psum[i] + v[i]) % mod;

	ll ans = 0;
	for (int i = 0; i < N; i++)
		ans = (ans + v[i] * (psum[N] - psum[i + 1] + mod) % mod) % mod;
	cout << ans << '\n';
	return 0;
}


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

const double EPS = 1e-10;
const ll INF = 100000000;
const ll MOD = 1000000007;

int a, b;
char out[100][100];

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

int main() {
    cin >> a >> b;
    rep(i,50) rep(j,100) out[i][j] = '#';
    rep(i,50) rep(j,100) out[i+50][j] = '.';
    a--; b--;
    for (int i = 1; i < 49; i++) for (int j = 1; j < 99; j++) {
        if (a == 0) break;
        bool ok = true;
        rep(k,8) {
            if (out[i+dx[k]][j+dy[k]] == '.') {
                ok = false;
                break;
            }
        }
        if (ok) {
            out[i][j] = '.';
            a--;
        }
    }
    for (int i = 1; i < 49; i++) for (int j = 1; j < 99; j++) {
        if (b == 0) break;
        bool ok = true;
        rep(k,8) {
            if (out[i+50+dx[k]][j+dy[k]] == '#') {
                ok = false;
                break;
            }
        }
        if (ok) {
            out[i+50][j] = '#';
            b--;
        }
    }
    cout << 100 << " " << 100 << endl;
    rep(i,100) {
        rep(j,100) cout << out[i][j];
        cout << endl;
    }
}
































Measured memory_bytes: 256
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG abc/abc112/dfix.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    int n, m;
    cin >> n >> m;
    if(n == 1){
        cout << m << "\n";
        return 0;
    }
    int p = 1;
    for(int i = 1; i <= sqrt(m); i++){
        if(m % i == 0){
            int j = m/i;
            if(m/i >= n && p < i){
                p = i;
            }
            if(m/j >= n && p < j){
                p = j;
            }
        }
    }
    cout << p << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef struct {
	int key, id;
} data;

void merge_sort(data x[], int n)
{
	static data y[100001] = {};
	if (n == 1) return;
	merge_sort(&(x[0]), n/2);
	merge_sort(&(x[n/2]), (n+1)/2);
	
	int i, p, q;
	for (i = 0, p = 0, q = n/2; i < n; i++) {
		if (p >= n/2) y[i] = x[q++];
		else if (q >= n) y[i] = x[p++];
		else y[i] = (x[p].key < x[q].key)? x[p++]: x[q++];
	}
	for (i = 0; i < n; i++) x[i] = y[i];
}

int main()
{
	int i, N;
	data A[100001];
	scanf("%d", &N);
	for (i = 0; i < N; i++) {
		scanf("%d", &(A[i].key));
		A[i].id = i;
	}
	merge_sort(A, N);
	
	int ans = 0;
	for (i = 0; i < N; i++) ans += (A[i].id + i) % 2;
	
	printf("%d\n", ans / 2);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h> 
using namespace std; int a,b; int main(){ cin >>a >>b; vector<int>data(a); for(int& i : data) cin >> i; sort(data.begin(),data.end()); int sum = 0; for(int i = 0;i<b;i++) sum += data[i]; cout << sum; return 0; } 


Measured memory_bytes: 3584
def valid(x):
    prev = 0
    while x > 0:
        p = x & 1
        if p == 1 and prev == 1:
            return False
        prev = p
        x >>= 1
    return True

def mult(A, x):
    n = len(x)
    r = [0] * n
    for i in range(n):
        for j in range(n):
            r[i] = (r[i] + A[i][j] * x[j]) % MOD
    return r

MOD = 10**9 + 7
h, w, k = map(int, input().split())

A = [[0] * w for i in range(w)]
for i in range(2**(w-1)):
    if not valid(i): continue
    prev = 0
    for j in range(w):
        b = i & 1
        if b == 1:
            A[j][j+1] += 1
            A[j+1][j] += 1
        elif prev == 0:
            A[j][j] += 1
        prev = b
        i >>= 1

x = [1] + [0] * (w-1)
for i in range(h):
    x = mult(A, x)

print(x[k-1])


Measured memory_bytes: 3064
/* To Kaise Hain Aaplog*/

#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) (x).begin(), (x).end()

void shuru_krte_hai_bina_kisi_bakchodi_ke()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}

const int m = 1e9+7;

int32_t main()
{
    //shuru_krte_hai_bina_kisi_bakchodi_ke();
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    int suff[n-1];
    suff[n-2] = a[n-1];
    for(int i=n-3;i>=0;i--){
        suff[i] = (a[i+1]+suff[i+1])%m;
    }
    int ans = 0;
    for(int i=0;i<n-1;i++){
        ans = (ans+(suff[i]*a[i])%m)%m;
    }
    cout<<ans<<" ";

    return 0;
}

Measured memory_bytes: 6688
ai = lambda: list(map(int, input().split()))
ai_ = lambda: [int(x) - 1 for x in input().split()]

n, m, X, Y = ai()
x = ai()
y = ai()
if max(x) < min(y) and X < max(x)+1 <= Y:
    print('No War')
else:
    print('War')

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> vs(n);
    for (auto& v : vs) {
        cin >> v;
    }
    auto calc = [&](int l, int r) {
        if (l + r > n || l + r > k) return 0;
        multiset<int> jewels;
        int current_sum = 0;
        auto add = [&](int v) {
            current_sum += v;
            jewels.insert(v);
        };
        for (int i = 0; i < l; ++i) {
            add(vs[i]);
        }
        for (int i = 1; i <= r; ++i) {
            add(vs[n-i]);
        }
        for (int i = 0; i < k - (l+r); ++i) {
            if (*jewels.begin() < 0) {
                current_sum -= *jewels.begin();
                jewels.erase(jewels.begin());
            }
        }
        return current_sum;
    };
    int best = 0;
    for (int l = 0; l <= max(k, n); ++l) {
        for (int r = 0; r <= max(k, n); ++r) {
            best = max(best, calc(l, r));
        }
    }
    cout << best << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
using ll=long long;
using namespace std;

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

    if(s=="RRR"){
        cout<<3<<endl;
    }else if(s=="RRS"|| s=="SRR"){
        cout<<2<<endl;
    }else if(s=="SSS"){
        cout<<0<<endl;
    }else{
        cout<<1<<endl;
    }

    return 0;
}

Measured memory_bytes: 3592
def f(n):
    return n * (n + 1) // 2


def solve(string):
    n = int(string)
    return str(f(n) - 3 * f(n // 3) - 5 * f(n // 5) + 15 * f(n // 15))


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 9176
#include <iostream>
#include <cstdio>
#include <stack>
#include <queue>

#define MAX 100
#define WHITE 0
#define GRAY 1
#define BLACK 2

#define NO -1

using namespace std;


int adjacencyList[MAX + 1][MAX + 1];
int color[MAX + 1];
int d[MAX + 1];
int n;



void bfs(int o)
{
	queue<int> S;
	S.push(o);
	color[o] = GRAY;
	d[o] = 0;

	int fr;

	while (S.size() > 0) {
		fr = S.front();
		S.pop();
		color[fr] = BLACK;
		for (int i = 1; i <= n; i++) {
			if (color[i] == WHITE && adjacencyList[fr][i] != NO) {
				S.push(i);
				color[i] = GRAY;
				d[i] = d[fr] + 1;
			}
		}
	}

}

int main(void)
{

	int u;
	int k;
	int v;


	cin >> n;

	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= n; j++) {
			adjacencyList[i][j] = NO;
		}
	}

	for (int i = 0; i < n; i++) {
		cin >> u >> k;

		for (int j = 0; j < k; j++) {
			cin >> v;
			adjacencyList[u][v] = 1;
		}

	}

	bfs(1);

	for (int i = 1; i <= n; i++) {
		cout << i << " ";
		if (color[i] == BLACK) {
			cout << d[i];

		}
		else {			
			cout << -1;
		}
		cout << endl;
	}


	return 0;
}

Measured memory_bytes: 3156
from operator import mul
from functools import reduce
def ncr(n, r):
    r = min(r, n - r)
    if r == 0: return 1;
    if r == 1: return n;
    numerator = [n - r + i + 1 for i in range(r)]
    denominator  = [i + 1 for i in range(r)]
    for p in range(2, r + 1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p - 1, r, p):
                numerator[k - offset] //= pivot
                denominator[k] //= pivot
    result = 1
    for k in range(r):
        if numerator[k] > 1: 
            result *= numerator[k]
    return result%(10**9+7)

x, y = map(int, input().split())
if (y+x)%3 != 0 or y > 2*x or x > 2*y:
  print("0")
else:
  n = (y+x)//3
  r = (n-abs(x-y))//2
  a = ncr(n,r)
  print(a)

Measured memory_bytes: 29928
#include <cstdio>
void swap(int &x, int &y) {
	int t = x;
	x = y;
	y = t;
}
int main() {
    int a, b, c;
    scanf("%d%d%d", &a, &b, &c);
    if(a > b) swap(a, b);
    if(a > c) swap(a, c);
    if(b > c) swap(b, c);
	printf("%d\n", a + b);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main(void){
    int n; cin >> n;
    vector<ll>s(n);
    set<ll>rest;
    for(int i=0;i<n;i++){
        cin >> s[i];
        if(s[i]%10!=0) rest.insert(s[i]);
    }
    ll ans = accumulate(s.begin(),s.end(),0);
    if(ans%10==0){
        if(rest.size()==0){
            cout << 0 << endl;
            return 0;
        } 
        else ans -= *rest.begin();
    }
    cout << ans << endl;


    return 0;
}

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

struct P {
    ll taste;
    int a;
    int b;
    int c;

    bool operator<(const P &d) const {
        if (a == d.a && b == d.b && c == d.c) {
            return taste < d.taste;
        } else if (a != d.a) {
            return a < d.a;
        } else if (b != d.b) {
            return b < d.b;
        } else {
            return c < d.c;
        }
    };
};

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<ll> A(X + 2000, -10000000000);
    vector<ll> B(Y + 2000, -10000000000);
    vector<ll> C(Z + 2000, -10000000000);
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];
    sort(rall(A));
    sort(rall(B));
    sort(rall(C));

    auto compare = [](P a, P b) {
      return a.taste < b.taste;
    };

    priority_queue<P,vector<P>,decltype(compare)> pq {compare};
    P init = {A[0] + B[0] + C[0], 0, 0, 0};
    pq.push(init);
    map<P, int> cnt;
    cnt[init]++;
    vector<ll> ans;

    while (!pq.empty() && ans.size() < K) {
        P q = pq.top();
        pq.pop();
        ans.push_back(q.taste);
        P newq1 = {A[q.a + 1] + B[q.b] + C[q.c], q.a + 1, q.b, q.c};
        P newq2 = {A[q.a] + B[q.b + 1] + C[q.c], q.a, q.b + 1, q.c};
        P newq3 = {A[q.a] + B[q.b] + C[q.c + 1], q.a, q.b, q.c + 1};

        if (cnt[newq1] == 0) {
            pq.push(newq1);
            cnt[newq1]++;
        }
        if (cnt[newq2] == 0) {
            pq.push(newq2);
            cnt[newq2]++;
        }
        if (cnt[newq3] == 0) {
            pq.push(newq3);
            cnt[newq3]++;
        }
    }
    rep(i, K) cout << ans[i] << endl;
}


Measured memory_bytes: 1024
// includes {{{
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<random>
#include<cassert>
#include<bitset>
#include<cstdlib>
// #include<deque>
// #include<multiset>
// #include<cstring>
// #include<bits/stdc++.h>
// }}}
using namespace std;
using ll = long long;

int main() {
  std::ios::sync_with_stdio(false), std::cin.tie(0);
  int a,b,c,d,e,f,g,n,m;
  cin >> n;
  cout << n * n * n << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define pi M_PI
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int w, h;
    int dx[] = {1, -1, 0, 0}, dy[] = {0, 0, 1, -1};
    while (cin >> w >> h && h){
        int d[30][30] = {}, wx[30][30], wy[30][30];
        REP(i,2*h-1){
            if (i % 2 == 0){
                REP(j,w-1) cin >> wy[i/2][j];
            }else{
                REP(j,w) cin >> wx[i/2][j];
            }
        }
        d[0][0] = 1;
        queue<P> que;
        que.push(make_pair(0, 0));
        while (!que.empty()){
            P p = que.front();
            que.pop();
            int x = p.first, y = p.second;
            REP(k,4){
                int i = x+dx[k], j = y+dy[k];
                if (i<0 || j<0 || i>=h || j>=w || d[i][j] > 0) continue;
                if (k == 0 && wx[x][y]) continue;
                if (k == 1 && wx[x-1][y]) continue;
                if (k == 2 && wy[x][y]) continue;
                if (k == 3 && wy[x][y-1]) continue;
                d[i][j] = d[x][y] + 1;
                que.push(make_pair(i, j));
            }
        }
        cout << d[h-1][w-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 3064
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int main() {
    int n;
    double x[11];
    string u[11];
    double ans = 0;

    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> x[i] >> u[i];
        if (u[i] == "JPY") {
            ans += x[i];
        }
        else {
            ans += 380000.0 * x[i];
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import sys,math,collections,itertools
input = sys.stdin.readline

N,M=list(map(int,input().split()))
P = list(map(int,input().split()))
bridge = [[] for i in range(N+1)]
for _ in range(M):
    x,y = map(int,input().split())
    bridge[x].append(y)
    bridge[y].append(x)
#-行き来できる数字の組み合わせを作る-#
memo = [-1]*(N+1)
q = collections.deque([])
novisit = set(range(1,N+1))
tmp = 0
while novisit:
    q.append(novisit.pop())
    tmp+=1
    while q:
        now = q.pop()
        memo[now]=tmp
        for bri in bridge[now]:
            if bri in novisit:
                q.append(bri)
                novisit.discard(bri)
#-memoが同じ数字だったら入れ替え可能-#
cnt = 0
for i in range(N):
    if i+1 == P[i]:
        cnt += 1
    elif i+1 != P[i] and memo[P[i]] == memo[i+1] :
        cnt += 1
print(cnt)


Measured memory_bytes: 40300
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

int main() {
  ll n, m;
  cin >> n >> m;
  string s, t;
  cin >> s >> t;

  ll l = lcm(n, m);
  bool ok = true;
  rep(i, 0, gcd(n, m)) ok &= s[(l / m * i) % n] == t[(l / n * i) % m];
  cout << (ok ? l : -1) << '\n';
  return 0;
}

Measured memory_bytes: 3760