akhauriyash/Code-Regression huggingface dataset:
//coded by dsingh_24
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<long long,long long>
#define vll          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (long long)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	ios
    ll n,i,j,a=0,b=0;
    cin>>n;
    ll x[n+1];
    vll v;
    map<ll,ll>m;
    for(i=0;i<n;i++)
    {
    	cin>>x[i];m[x[i]]++;
	}
    sort(x,x+n);
    reverse(x,x+n);
    v.pb(x[0]);
    j=0;
    for(i=1;i<n;i++)
    {
    	while(v[j]==x[i])i++;
    	if(i<n)
    	{
    		v.pb(x[i]);j++;
		}
	}
    for(i=0;i<v.size();i++)
    {
    	if(m[v[i]]>=4&&a==0&&b==0)
    	{
    		cout<<v[i]*v[i];return 0;
		}else
		if(m[v[i]]>=2&&a==0)a=v[i];else
		if(m[v[i]]>=2&&a!=0&&b==0)b=v[i];
	}
	cout<<a*b;;
	return 0;
}


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

// Define
using ll = int64_t;
using ul = uint64_t;
using ld = long double;
const ll MOD = 1e9 + 7;
const ll INF = LONG_MAX;
const ul MAX = ULONG_MAX;
const char nl = '\n';

#define elif else if
#define def inline auto
#define run __attribute__((constructor)) def _

// Debug
#define debug(x) cerr << (x) << " (L:" << __LINE__ << ")" << '\n'

// Loop
#define inc(i, a, n) for (ll i = (a), _##i = (n); i < _##i; ++i)
#define dec(i, a, n) for (ll i = (a), _##i = (n); i > _##i; --i)
#define rep(i, n) inc(i, 0, n)

// Stream
#define fout(n) cout << fixed << setprecision(n)
#define fasten cin.tie(0), ios::sync_with_stdio(0)

// Speed
run() { fasten, fout(10); }
#pragma GCC optimize("-O3")
#pragma GCC target("avx")

// Math
inline ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

signed main() {
    int N, M;
    cin >> N >> M;
    vector<int> cs(M);
    rep(i, M) cin >> cs[i];
    sort(begin(cs), end(cs));

    vector<ll> dp(N+1, INF);
    dp[0] = 0;
    rep(i, cs.size()) {
        rep(y, dp.size()) {
            if (y - cs[i] >= 0)
                dp[y] = min(dp[y - cs[i]] + 1, dp[y]);
        }
    }
    cout << dp[N] << nl;
}



Measured memory_bytes: 3424
parseInt(x) = parse(BigInt, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
	p = 10^9+7
	n = readline() |> parseInt
	a = readline() |> split |> parseMap
	k = lcm(a)
	s = 0
	for i in 1:n
		s = (s+div(k,a[i]))%p
	end
	println(s)
end

main()

Measured memory_bytes: 173652
#include<bits/stdc++.h>
#define ll long long

using namespace std;

const ll Mod = 1e9 + 7;
const ll Nax = 110;
ll N;

///For Easy Code
#define rep(i,v)    for(ll i=0;i<v.size();++i)
typedef vector < ll > Row;
typedef vector < Row > Matrix;

///Zero Matrix
Matrix Zero(ll n,ll m)
{
    return Matrix( n , Row(m,0) );
}

///Identity Matrix
Matrix Identity(ll n)
{
    Matrix Res = Zero(n,n);
    rep(i,Res)  Res[i][i] = 1;
    return Res;
}

///Matrix Multiplication
Matrix Muliply(const Matrix &a,const Matrix &b)
{
    Matrix Res=Zero( a.size() , b[0].size() );

    rep(i,a) rep(k,a[0])    if(a[i][k])
        rep(j,b[0])
            Res[i][j] = ( Res[i][j] + a[i][k]*b[k][j] )%Mod;

    return Res;
}

///Matrix Power
Matrix Power(const Matrix &a,ll k)
{
    if(k==0)    return Identity( a.size() );
    if(k&1)     return Muliply( a , Power(a,k-1) );
    return Power( Muliply(a,a) , k>>1LL );
}

ll Calc(ll k,Matrix Transition)
{
    Matrix Initial = Identity(N);

    Matrix Transition_k = Power(Transition,k);

    Matrix Res = Muliply( Initial , Transition_k );

    ll Ans = 0;

    for(ll i=0;i<N;i++)
        for(ll j=0;j<N;j++)
            Ans = ( Ans + Res[i][j] )%Mod;

    return Ans;
}

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

    Matrix a = Zero(N,N);

    for(ll i=0;i<N;i++)
        for(int j=0;j<N;j++)
            scanf("%I64d",&a[i][j]);

    cout<<Calc(k,a);
}


Measured memory_bytes: 1664
n = int(input())
res  = 0
for i in range(5, n+1, 2):
    ge = set([])
    for j in range(1, i+1):
        if i % j == 0:
            ge.add(i)
            ge.add(j)
    if len(ge) == 8:
        res += 1
print(res)


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <vector>
#include <string>

using namespace std;

int ht[4] = {0,-1,0,1};
int wt[4] = {-1,0,1,0};

int main(void)
{
    int h,w;
    cin >>h >>w;
    vector<string> stage;
    for(int i = 0; i < h; i++){
        string tmp;
        cin >>tmp;
        stage.push_back(tmp);
    }
    bool canDraw = true;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(stage[i][j] == '#'){
                bool canDrawSingle = false;
                for(int k = 0; k < 4; k++){
                    int ni = i + ht[k];
                    int nj = j + wt[k];
                    if(ni < 0 || ni >= h || nj < 0 || nj >= w){
                        continue;
                    }
                    if(stage[ni][nj] == '#'){
                        canDrawSingle = true;
                    }
                }
                if(!canDrawSingle){
                    canDraw = false;
                }
            }
        }
    }
    if(canDraw){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()	{
  long long x, a, b;
  cin >> x >> a >> b;
  if (a >= b)	{
    cout << "delicious" << endl;
  }
  else if (a < b && (b - a) <= x)	{
    cout << "safe" << endl;
  }
  else	{
    cout << "dangerous" << endl;
  }
  return 0;
}

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

int main() {
  long long K;
  cin >> K;
  long long n = 50, m = K/n, l = K%n, a[n];
  for (int i=0; i<n; i++) {
    a[i] = i+m;
    if (i<l)
      a[i] += n-l+1;
    else
      a[i] -= l;
  }
  cout << n << endl;
  for (int i=0; i<n; i++)
    cout << a[i] << ' ';
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main{
	public static int M = 1046527;
	public static char H[][] = new char[M][14];
	public static char x[] = new char[14];
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String cmd, s;
		for(int i = 0; i < N; i++) {
			char []str = new char[14];
			cmd = scan.next();
			s = scan.next();
			for(int j = 0; j < s.length(); j++) {
				str[j] = s.charAt(j);
			}
			if(cmd.charAt(0) == 'i') {
				insert(str);
			}else {
				if(find(str) == 1) {
					System.out.println("yes");
				}else {
					System.out.println("no");
				}
			}
		}
		scan.close();
	}

	public static int getChar(char ch) {
		if(ch == 'A') return 1;
		else if(ch == 'C') return 2;
		else if(ch == 'G') return 3;
		else if(ch == 'T') return 4;
		else return 0;
	}

	public static long getKey(char []str) {
		long sum = 0;
		long p = 1;
		for(int i = 0; i < 14; i++) {
			sum += p * (getChar(str[i]));
			p *= 5;
		}
		return sum;
	}

	public static int find(char []str) {
		long key = getKey(str);
		int h;
		for(int i = 0;; i++) {
			h = (h1(key) + i * h2(key)) % M;

			if(isCheck(H[h], str)) return 1;
			else if(H[h][0]== x[0]) return 0;
		}
	}
	public static boolean isCheck(char[] c1, char[] c2) {
		for(int i = 0; i < 14; i++) {
			if(c1[i] != c2[i]) {
				return false;
			}
		}
		return true;
	}
	public static void strcpy(char[] c1, char[] c2) {
		for(int i = 0; i < 14; i++) {
			c1[i] = c2[i];
		}
	}
	public static int insert(char str[]) {

		long key = getKey(str);
		int h;
		for(int i = 0;; i++) {
			h = (h1(key) + i * h2(key)) % M;
			if(isCheck(H[h], str)) return 1;
			else if(H[h][0]== x[0]) {
				strcpy(H[h], str);
				return 0;
			}
		}
	}
	public static int h1(long key) {
		return (int)(key % M);
	}
	public static int h2(long key) {
		return (int)(key % (M - 1));
	}
	public static void disp(char []c) {
		for(int i = 0; i < 14; i++) {
			System.out.print(c[i]);
		}
		System.out.println();
	}
}


Measured memory_bytes: 373824
#include <cmath>
#include <cstdio>

#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <numeric>
#include <string>
#include <array>

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

using namespace std;
typedef long long int ll;

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

  vector<pair<ll, ll>> a(n);
  rep(i, n) cin >> a.at(i).first;
  rep(i, n) cin >> a.at(i).second;
  ll maxa = 0;
  rep(i, n+1){
    ll suma=0;
    rep(j, n){

      if(j<=i) suma += a.at(j).first;
      if(j>=i) suma += a.at(j).second;
    }
    if(maxa < suma) maxa = suma;
  }
  cout << maxa << endl;
  return 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-

from heapq import heappush, heappop
def io_generator():
	return input()

#+++++++++++++++++++
	
class Foo(object):
	def __init__(self, value, state):
		self.state = state
		self.value = value

	def __lt__(self, other):
		return self.value > other.value

def get_c(a_state, a_mm):
	ret=[]
	for i, _ in enumerate(a_state):
		if a_state[i] >= a_mm[i]-1:
			continue
		ret.append([v + (i==j) for j,v in enumerate(a_state)])

	return ret
	
def gv(a_l,a_state):
	ret= sum([l[s] for l, s in zip(a_l, a_state)])
	return ret
	
def lss(l):
	return '_'.join([str(i) for i in l])
	
def main(io):
	x,y,z,k=map(int, io().split())
	ml=[x,y,z]
	al =list(map(int, io().split()))
	al.sort(reverse=True)
	bl =list(map(int, io().split()))
	bl.sort(reverse=True)
	cl =list(map(int, io().split()))
	cl.sort(reverse=True)
	ls=[al,bl,cl]
	ggv=lambda l : gv(ls,l)
	
	qq = []
	ol=set()
	
	init=[0,0,0]
	heappush(qq,Foo(ggv(init), init))
	ol.add(lss(init))
	
	for _ in range(k):
		ff=heappop(qq)
		print(ff.value)
		cs=ff.state
		nc=get_c(cs,ml)
		for ns in nc:
			if lss(ns) in ol:
				continue
			else:
				heappush(qq, Foo(ggv(ns), ns))
				ol.add(lss(ns))
	return 1

#++++++++++++++++++++

if __name__ == "__main__":
	io= lambda : io_generator()
	#print (main(io))
	main(io)

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

int main(){
	int K;
	int A,B;
	cin >> K;
	cin >> A >> B;
	for(int i=1; i*K<=1000; i++){
		int a = i*K;
		if(a>=A && a<=B){cout << "OK" << endl; return 0;}
	}
	cout << "NG" << endl;
	return 0;
}

Measured memory_bytes: 3636
#include <iostream>

int main()
{
    int a, b, k;
    std::cin >> a >> b >> k;

    int count = 0;
    for (int i = std::min(a, b); i >= 1; i--) {
        if (a % i == 0 && b % i == 0) {
            if (++count == k) {
                std::cout << i << std::endl;
            }
        }
    }
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  int count=0;
  int temp;
  cin >> n;
  for(int i=0;i<n;i++){
  	cin >> temp;
  	if(temp%2==1){
  	count++;}
  }
  if(count%2==1)
	cout << "NO";
  else
  	cout <<"YES";	
  
  return 0;
}

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

using namespace std;

int main()
{
	int a, b;
	int ans[8] = {0,0,0,3,0,2,1,0};
	
	cin>>a>>b;
	cout<<ans[1<<(a-1)|1<<(b-1)];
	
	return 0;
}



Measured memory_bytes: 256
/*
The year is 2050, league is played by less than 100 people. T1 has finally reached Masters,
"Macaiyla I did it!" he yells excitedly. The sound echoes through the empty trailer. Macaiyla left long ago...
 */
import java.io.*;
import java.util.*;
import java.lang.Math;
import java.math.BigInteger;

public class Main {

    static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner() {
            try {
                br = new BufferedReader(new InputStreamReader(System.in));
                st = new StringTokenizer(br.readLine());
            } catch (Exception e){e.printStackTrace();}
        }

        public String next() {
            if (st.hasMoreTokens()) return st.nextToken();
            try {st = new StringTokenizer(br.readLine());}
            catch (Exception e) {e.printStackTrace();}
            return st.nextToken();
        }

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

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

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

        public String nextLine() {
            String line = "";
            if(st.hasMoreTokens()) line = st.nextToken();
            else try {return br.readLine();}catch(IOException e){e.printStackTrace();}
            while(st.hasMoreTokens()) line += " "+st.nextToken();
            return line;
        }
    }

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter pw = new PrintWriter(System.out);
        final int MOD = 1000000007;

        int m = sc.nextInt();
        int d = sc.nextInt();

        int cnt = 0;
        //ArrayList<String> list = new ArrayList<>();
        int d10 = (d+"").charAt(0)-'0';
        for(int i=4;i<=m;i++) {
            for(int j=2;j<=d10;j++) {
                for(int k=2;k<=9;k++) {
                    if(i == j * k && Integer.parseInt(j+""+k) <= d) {
                        cnt++;
                        //list.add(j + " " + k);
                    }
                }
            }
        }
        //for(String x : list) pw.println(x);

        pw.println(cnt);
        pw.close();
    }
}

// ceil(a/b) = (a+b-1)/b
// PRO TIP: THE BEST ANSWER IS THE RIGHT ANSWER



Measured memory_bytes: 21200
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#define ll long long
using namespace std;

const ll mod = 1e9 + 7;

ll C[2005][2005];
ll dp[100005][13];


int main(){
    int ans=0;
    string S,T;
    cin >> S;
    for(int i=0; i< S.size()/2; i++){
        if(S[i] != S[S.size()-1-i])ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 200010;
const ll mod = 1e9 + 7;
struct node{
	ll val, f;
	friend bool operator < (node x, node y) {
		return x.val * x.f < y.val * y.f;
	}
};
int n, k, tmp;
ll a[N], ans = 1;
priority_queue<node> q1, q2;
ll s1[N], s2[N], top1, top2;
int main() {
	cin >> n >> k;
	tmp = k;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] > 0) q1.push(node{a[i], 1});
		else q2.push(node{a[i], -1});
	}
	while (k) {
		if (!q1.empty() && !q2.empty()) {
			node x = q1.top();
			q1.pop();
			node y = q2.top();
			q2.pop();
			if (x.val * x.f > y.val * y.f) {
				s1[++top1] = x.val;
				q2.push(node{y.val, y.f});
			} else {
				s2[++top2] = y.val;
				q1.push(node{x.val, x.f});
			}
		} else if (!q1.empty()) {
			node x = q1.top();
			q1.pop();
			s1[++top1] = x.val;
		} else if (!q2.empty()) {
			node x = q2.top();
			q2.pop();
			s2[++top2] = x.val;
		}
		k--;
	}
//	for (int i = 1; i <= top1; i++) cout << s1[i] << " ";
//	cout << endl;
//	for (int i = 1; i <= top2; i++) cout << s2[i] << " ";
//	cout << endl;
	if (top2 % 2) {
		if (top1) {
			if (!q1.empty() && !q2.empty()) {
				if (q2.top().val * s2[top2] > q1.top().val * s1[top1]) {
//					puts("zcr");
					top1--;
					s2[++top2] = q2.top().val;
				} else {
//					puts("zsy");
					top2--;
					s1[++top1] = q1.top().val;
				}
			} else if (!q1.empty()) {
				top2--;
				s1[++top1] = q1.top().val;
			} else if (!q2.empty()) {
				top1--;
				s2[++top2] = q2.top().val;
			}
		} else {
			if (!q1.empty()) {
				top2--;
				s1[++top1] = q1.top().val;
			} else {
				sort(a + 1, a + n + 1);
				top2 = 0;
				for (int i = n; i >= n - tmp + 1; i--) {
					s2[++top2] = a[i];
				}
			}
		}
	}
//	for (int i = 1; i <= top1; i++) cout << s1[i] << " ", ans = (ans * s1[i]) % mod;
//	cout << endl;
//	for (int i = 1; i <= top2; i++) cout << s2[i] << " ", ans = (ans * s2[i]) % mod;
//	cout << endl;
	for (int i = 1; i <= top1; i++) ans = (ans * s1[i]) % mod;
	for (int i = 1; i <= top2; i++) ans = (ans * s2[i]) % mod;
	cout << (ans % mod + mod) % mod;
	return 0;
}

Measured memory_bytes: 9832
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n,cnt=1;
    int a[900000];
    cin >>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
        if(a[i]==cnt){
            cnt++;
        }
    }
    if(cnt==1){
        cout << -1;
        return 0;
    }
    cout << n-cnt+1;
}


Measured memory_bytes: 3072
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <math.h>
#include <numeric>
#include <deque>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <queue>
using namespace std;

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

    for(int i = 0; i < s.length(); ++i)
    {
        if( i % 2 == 0)
        {
            if(s[i] == 'L')
            {
                cout << "No";
                return 0;
            }
        }
        else
        {
            if(s[i] == 'R')
            {
                cout << "No";
                return 0;
            }
        }
    }

    cout << "Yes";
    return 0;
}


Measured memory_bytes: 888
#include <iostream>

int main() {
  int n;
  std::cin >> n;

  int count = 0;
  for (int i = 1; i <= 10000; i *= 10) {
    count += ((n % i * 10) / i == 2) ? 1 : 0;
  }
  std::cout << count << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include<map>
#include<cstring>
using namespace std;
#define inRange(x,a,b) (a <= x && x < b)
int di[4] = {-1, 1, 0, 0};
int dj[4] = {0, 0, -1, 1};

int room[2][500][500];
bool visit[2][500][500];

int main(){
    int r;
    while(cin >> r, r){
        int w[2], h[2], x[2], y[2];
        memset(room, 0, sizeof(room));
        memset(visit, 0, sizeof(visit));
        for(int s = 0; s < 2; s++){
            cin >> w[s] >> h[s] >> x[s] >> y[s];
            x[s]--, y[s]--;
            for(int i = 0; i < h[s]; i++){
                for(int j = 0; j < w[s]; j++){
                    cin >> room[s][i][j];
                }
            }
        }
        map<int,int> m[2], n[2];
        for(int s = 0; s < 2; s++){
            int tmplevel = 0;
            priority_queue<pair<int,pair<int,int>>> pq;
            pq.push({-room[s][y[s]][x[s]], {y[s], x[s]}});
            visit[s][y[s]][x[s]] = true;
            int cnt = 0;
            while(!pq.empty()){
                auto p = pq.top();  pq.pop();
                int val = -p.first, i = p.second.first, j = p.second.second;
                tmplevel = max(tmplevel, val);
                m[s][tmplevel] = ++cnt;
                for(int k = 0; k < 4; k++){
                    int ni = i + di[k], nj = j + dj[k];
                    if(inRange(ni, 0, h[s]) && inRange(nj, 0, w[s]) && !visit[s][ni][nj]){
                        visit[s][ni][nj] = true;
                        pq.push({-room[s][ni][nj], {ni, nj}});
                    }
                }
            }
            for(auto p : m[s]){
                n[s][p.second] = p.first;
            }
            n[s][0] = 0;   // sentinel
        }
        int ans = 1<<30;
        for(auto p : n[0]){
            int residual = r-p.first;
            auto it = n[1].lower_bound(residual);
            if(it != n[1].end()){
                ans = min(ans, p.second + n[1].lower_bound(residual)->second);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


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

int main(){
	int n;
    cin >> n;
  	double ans = 0.0;
  	for(int i = 0; i < n; i++){
      double d;
      cin >> d;
      ans += (1.0/d);
    //   cout << ans;
    }
	printf("%.6f", 1/ans);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = unsigned long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define VI vector<int>
#define VII vector<vector<int>>
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int N,K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    FOR(i,1,N) A[i] += A[i-1];
    vector<ll> B;

    rep(i,N){
        B.push_back(A[i]);
        for(int j = 0;j < i; ++j){
            B.push_back(A[i]-A[j]);
        }
    }

    ll ans = 0; 
    for(int i=45;i>=0;--i){
        int cnt = 0;
        for(int j=0;j<B.size();++j){
            if(((ans+(1ll<<i))&B[j]) == (ans+(1ll<<i))) ++cnt;
        }
        if(cnt >= K) ans += (1ll<<i);
    }
    cout << ans << endl;

}

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

ll beki(ll a, ll b) {
  if (b == 0) return 1;
  ll ret = beki(a, b / 2);
  ret = ret * ret % MOD;
  if (b & 1) ret = ret * a % MOD;
  return ret;
}

const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k) {
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
  ll N, M, K;
  cin >> N >> M >> K;
  ll ans = 0;
  COMinit();
  for (ll k = 0; k <= K; k++) {
    ll tmp = 0;
    tmp = (tmp + M * beki(M - 1, N - k - 1)) % MOD;
    tmp = tmp * COM(N - 1, k) % MOD;
    ans = (ans + tmp) % MOD;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 15596
#include<stdio.h>
int main(void)
{
	int a,b,c,x,y;
	scanf("%d %d %d",&a,&b,&c);
	x=0;	y=0;	
	while(1){
		if(x>=c) break;
		x+=a;
		y++;
		if(y%7==0)  x+=b;
	}
	printf("%d\n",y);
	return 0;
}


Measured memory_bytes: 2748
#include <stdio.h>

int abs(int n){
  if(n < 0)
    return -1 * n;

  return n;
}

unsigned long fac(int n){
  unsigned long res = 1;
  int i;
  for(i = 1; i <=n;i++){
    res = (res * i) % 1000000007;
  }
  return res;
}

int main(void){
  int dog,mon;

  scanf("%d %d",&dog,&mon);

  if(abs(dog - mon) > 1){
    printf("0\n");
    return 0;
  }

  long dogFac,monFac,total;
  
  dogFac = fac(dog);
  monFac = fac(mon);

  total = dogFac * monFac;
  
  if(dog == mon)
    total = total * 2;

  printf("%ld\n",total % (1000000000 + 7));

  return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
Created on Mon May 20 23:18:56 2019

@author: Yamazaki Kenichi
"""

N = int(input())
uvw = [list(map(int,input().split())) for i in range(N-1)]

import sys
sys.setrecursionlimit(10**6)

class UnionFind(object):

    def __init__(self, size):
        self.table = [-1 for _ in range(size)]

    def find(self, x):
        if self.table[x] < 0:
            return x
        else:
            self.table[x] = self.find(self.table[x])
            return self.table[x]

    def union(self, x, y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] <= self.table[s2]:
                self.table[s1] += self.table[s2]
                self.table[s2] = s1
            else:
                self.table[s2] += self.table[s1]
                self.table[s1] = s2
            return True
        else:
            return False

uf = UnionFind(N*2 + 1)

for c in uvw:
    if c[2] % 2 == 0:
        uf.union(c[0],c[1])
        uf.union(c[0]+N, c[1]+N)
    else:
        uf.union(c[0]+N, c[1])
        uf.union(c[0], c[1]+N)
for i in range(N*2+1):
    uf.find(i)
tmp1,tmp2 = 0, 0
for i in range(1,N+1):
    if uf.table[i] == tmp1 or i == tmp1:
        print(1)
    elif uf.table[i] == tmp2 or i == tmp2:
        print(0)
    elif tmp1 == 0:
        tmp1 = max(uf.table[i],i)
        print(1)
    else:
        tmp2 = max(uf.table[i],i)
        print(0)
#    print(i,tmp1,tmp2)



Measured memory_bytes: 33996
// B

#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll mod=1e9+7;
#define pa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};

int main(){
  ll x,y;
  cin>>x>>y;
  if (y > x){
    ll tmp;
    if (y >= 0 && x >= 0 || y <= 0 && x <= 0){
      tmp = y - x;
    }else if (abs(x) > abs(y)){
      tmp = -y - x + 1;
    }else{
      tmp = y + x + 1;
    }
    cout << tmp << endl;
  }else{
    ll tmp(0);
    if (x == 0 || y == 0){
      cout << x - y + 1 << endl;
      return 0;
    }
    if (y <= 0 && x <= 0){
      tmp = x - y + 2;
    }else if(y >= 0 && x >= 0){
      tmp = x - y + 2;
    }else if (abs(y) > abs(x)){
      tmp = -y - x + 1;
    }else{
      tmp = y + x + 1;
    }
    cout << tmp << endl;
  }
}




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

using namespace std;

typedef pair<int, int> pii;

bool cmp( pii a, pii b){
      return a.first < b.first;
}

int main(){
  int N, M;
  cin >> N >> M;
  vector<pii> v;
  priority_queue<int> que;

  for(int i = 0; i < N; i++){
    int a,b;
    cin >> a >> b;
    v.push_back(make_pair(a,b));
  }

  // Aが小さい順にソートする
  sort(v.begin(), v.end(), cmp);

  cerr << v[0].first << "," << v[0].second << endl;

  int index = 0;
  int ans = 0;
  for(int i = 1; i <= M; i++){
    // Aiがi以下であれば、候補としてqueueにいれる 
    while(index < N && v[index].first <= i){
      que.push(v[index].second);
      index++;
    }
    // queueから報酬最大のものを選んで、i日目の仕事とする
    if(!que.empty()){
      ans += que.top();
      que.pop();
    }
  }

  cout << ans << endl;


}

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

int main() {
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        a[i]--;
    }
    int ans = 0;
    for (int i = 0; i < N; i++) {
        if (a[a[i]] == i) {
            ans++;
        }
    }
    cout << ans / 2 << endl;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define fastIO (cin.tie(0), cout.tie(0), ios::sync_with_stdio(false))
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define precise(i) fixed << setprecision(i)
using namespace std;

int main() {
    fastIO;
    int n, m;
    cin >> n >> m;
    vector<int> likes(m);
    rep(i, m) likes.at(i) = 0;

    rep(K, n) {
        int k;
        cin >> k;
        rep(i, k) {
            int a;
            cin >> a;
            likes.at(a - 1) += 1;
        }
    }

    int sum = 0;
    rep(i, m) {
        if (likes.at(i) == n)
            sum++;
    }
    cout << sum << endl;
}

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

const int MAX = 555;

int n;

int c[MAX], f[MAX], s[MAX];

void solve(int id) {
    int cur = 0;
    for (int i = id; i < n - 1; ++i) {
        cur = max(s[i], (cur + f[i] - 1) / f[i] * f[i]) + c[i];
    }
    cout << cur << "\n";
}

int main() {
#ifdef LOCAL
    freopen("xxx.in", "r", stdin);
    freopen("xxx.out", "w", stdout);    
#endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cin >> n;
    for (int i = 0; i < n - 1; ++i) {
        cin >> c[i] >> s[i] >> f[i];
    }
    for (int i = 0; i < n; ++i) {
        solve(i);
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<string>
#include<climits>
#include<deque>

using namespace std;

int m,INF=30000000;
stack<int,vector<int> >A,B,C;
stack<int,vector<int> >A2,B2,C2;

int func(string p){
  
  int cnt=0;

  for(int i=0;i<m;i++){
    
    if(B.empty() && (C.empty()||A.empty()))return cnt;
    
    if(!A.empty() && (B.empty() || A.top()>=B.top()) && p!="BA"){
      B.push(A.top());
      A.pop();
      cnt++,p="AB";
    }
    
    if(!B.empty() && (C.empty() || B.top()>=C.top()) && p!="CB"){
      C.push(B.top());
      B.pop();
      cnt++,p="BC";
    }
    
    if(!B.empty() && (A.empty() || B.top()>=A.top()) && p!="AB"){
      A.push(B.top());
      B.pop();
      cnt++,p="BA";
    }
    
    if(!C.empty() && (B.empty() || C.top()>=B.top()) && p!="BC"){
      B.push(C.top());
      C.pop();
      cnt++,p="CB";
    }
    
  }

  return INF;
}

int main(void){
  int n,ans,s,t;
  
  while(cin >> n >> m,n|m){
    while(!A.empty())A.pop();
    while(!B.empty())B.pop();
    while(!C.empty())C.pop();
    while(!A2.empty())A2.pop();
    while(!B2.empty())B2.pop();
    while(!C2.empty())C2.pop();


    cin >> s;
    for(int i=0;i<s;i++){
      cin >> t;
      A.push(t);
    }
    cin >> s;
    for(int i=0;i<s;i++){
      cin >> t;
      B.push(t);
    }
    cin >> s;
    for(int i=0;i<s;i++){
      cin >> t;
      C.push(t);
    }
    
    A2=A,B2=B,C2=C;
    ans=func("CB");
    
    A=A2,B=B2,C=C2;
    ans=min(ans,func("AB"));
    
    A=A2,B=B2,C=C2;
    ans=min(ans,func("BA"));
    
    A=A2,B=B2,C=C2;
    ans=min(ans,func("BC"));
    
    if(ans==INF)cout << -1 << endl;
    else cout << ans << endl;

  }
  return 0;
}

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

typedef unsigned long long  ULL;
typedef long long LL;

#define pb push_back
#define mp make_pair
#define reset(a, b) memset(a, b, sizeof(a))
#define rep(i,b) for(int i=0; i<b; i++)
#define F first 
#define S second

 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int T;
//    cin>>T;
    T=1;
    while(T--){
       
       int n;
       cin>>n;
       
       ULL sum=0;
       for(int i=1; i<=n; i++){
           if(i%3==0 || i%5==0) continue;
           else sum+=i;
       }
       
       cout<<sum;
    }
    
    return 0;
}

Measured memory_bytes: 3652
// C - Unification
// https://atcoder.jp/contests/abc120/tasks/abc120_c
#include <bits/stdc++.h>
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000 //10^12
#define MOD 10000007      //10^9+7
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define eb emplace_back
using namespace std;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
using vp = vector<P>;
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a = 0, b = 0, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> s;
  rep(i, 0, s.size())
  {
    if (0 == s[i] - '0')
    {
      a++;
    }
    else if (1 == s[i] - '0')
    {
      b++;
    }
  }
  ans = a + b;
  if (a > b)
  {
    cout << b * 2 << endl;
  }
  else if (a == b)
  {
    cout << ans << endl;
  }
  else
  {
    cout << a * 2 << endl;
  }
}

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

using namespace std;

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

  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a = min(a, abs(n + 1 - a));
    b = min(b, abs(n + 1 - b));
    if (b > a) b = a;
    cout << (b % 3 == 0 ? 3 : b % 3) << endl;
  }

  return 0;
}


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

int main()
{
    ll X;
    cin >> X;
    for(ll i=-118;i<=119;i++){
        for(ll j=-119;j<=118;j++){
            if(i*i*i*i*i-j*j*j*j*j==X){
                cout << i << " "<< j << endl;
                return 0;
            }
        }
    }

}

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

using namespace std;

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

    int A, B;
    cin >> A >> B;
    int length = A - B * 2;
    if (length < 0) cout << 0 << '\n';
    else cout << length << '\n';
}

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

using namespace std;

int main(){
    int h, w;
    int a, sum = 0;
    vector<vector<long long>> c;
    cin >> h >> w;
    c.resize(10);

    for(vector<vector<long long>>::iterator i = c.begin(); i < c.end(); i++){
        (*i).resize(10);
        copy_n(istream_iterator<long long>(cin), 10, (*i).begin());
    }

    
    for(int i = 0; i < 10; i++)
        for(int j = 0; j < 10; j++)
            for(int k = 0; k < 10; k++)
                c[j][k] = min(c[j][i] + c[i][k], c[j][k]);
    /*
    for_each(c.begin(), c.end(), [](vector<long long> i){ 
            for_each(i.begin(), i.end(), [](long long i){ cout << i << " "; }); cout << endl;
            });
            */
    
    for(int i = 0; i < h * w; i++){
        cin >> a;
        if(a != -1)
            sum += c[a][1];
    }

    cout << sum << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>

#define LEN 10

int main(void) {
    char today[LEN];
    int n;
    scanf("%s", today);
    if (strcmp(today, "Sunny") == 0) {
        n = -1;
    } else if (strcmp(today, "Cloudy") == 0) {
        n = 0;
    } else {
        n = 1;
    }
    n++;

    switch (n) {
        case 0: {
            puts("Cloudy");
            break;
        }
        case 1: {
            puts("Rainy");
            break;
        }
        case 2: {
            puts("Sunny");
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
template<class T> inline bool chmax(T &a, T b) { if (a<b) {a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a, T b) { if (b<a) {a=b; return 1;} return 0;}

struct Sieve {
    int n;
    vector<int> f, primes;
    
    Sieve(int n=1) : n(n), f(n+1) {
        f[0] = f[1] = -1;
        for (long long i = 2; i <= n; ++i) {
            if (f[i]) continue;
            primes.push_back(i);
            f[i] = i;
            for (long long j = i*i; j <= n; j += i) {
                if (!f[j]) f[j] = i;
            }
        }
    }

    bool isPrime(int x) { return f[x] == x;}

    vector<int> factorList(int x) {
        vector<int> res;
        while (x != 1) {
            res.push_back(f[x]);
            x /= f[x];
        }
        return res;
    }

    vector<pair<int, int>> factor(int x) {
        vector<int> fl = factorList(x);
        if (fl.size() == 0) return {};
        vector<pair<int, int>> res(1, pair<int, int>(fl[0], 0));
        for (int p : fl) {
            if (res.back().first == p) {
                res.back().second++;
            } else {
                res.emplace_back(p, 1);
            }
        }
        return res;
    }
};

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    cin >> n;
    Sieve sieve(55555);
    vi num;
    for (auto&& p : sieve.primes) {
        if (p == 2 || ((p-1)/2) % 5 == 1) num.pb(p); 
    }
    rep(i, n) {
        cout << num[i] << (i == n-1 ? "\n" : " ");
    }
}

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

#define int long long
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define DESYNC ios::sync_with_stdio(0); cin.tie(0);
#define deb(x) cerr << ">> " << #x << " : " << x << "\n";
#define print(a) for(auto x : a) cout << x << " "; cout << "\n";

const int inf = 1e18 + 5;

// +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+

void solve()
{
    char a, b;
    cin >> a >> b;
    string aa = "", bb = "";
    for(int i = 0; i < (b - '0'); i++)
        aa += a;
    for(int i = 0; i < (a - '0'); i++)
        bb += b;
    if(aa > bb) cout << bb << endl;
    else cout << aa << endl;
}

int32_t main()
{
    DESYNC
    int t = 1;
    // cin >> t;
    while(t--)
        solve();
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<vector>
#include<cmath>

using namespace std;


bool isPrime(int num){
	if (num < 2) return false;
	if (num == 2) return true;
	for (int i = 2; i <= (int)(sqrt(num) + 1); i++){
		if (num % i == 0) return false;
	}
	return true;
}
int main(){
	while(1){
		int n; cin >> n;
		if (n == 0) break;
		int ans = 0;
		for (int i = n + 1; i <= 2 * n; i++){
			if(isPrime(i)){
				ans++;
			}
		}
		cout << ans << endl;
	}
return 0;
}

Measured memory_bytes: 3012
from collections import deque

n = int(input())
matches = []
for _ in range(n):
    matches.append(list(map(lambda x: int(x)-1, input().split())))

q = deque(range(n))

days = [0]*n  # 各選手の現在の日付

while q:
    x = q.popleft()  # 試合する人
    if len(matches[x]) == 0:  # 試合が全て終わってる?
        continue
    y = matches[x][0]  # xの次の対戦相手
    if matches[y][0] == x:
        day = max(days[x], days[y])+1
        days[x] = day
        days[y] = day
        q.append(x)
        q.append(y)
        _ = matches[x].pop(0)
        _ = matches[y].pop(0)

if not any(matches):  # 全ての試合をしょうか
    print(max(days))
else:
    print(-1)


Measured memory_bytes: 71516
package main

import (
	"fmt"
	"math"
	"strings"
)

func main() {
	var n, cnt int
	var s string
	fmt.Scan(&n, &s)

	sa := strings.Split(s, "")

	for i := 1; i < n; i++ {
		x := sa[:i]
		y := sa[i:]

		xm := make(map[string]string)
		ym := make(map[string]bool)

		for _, v := range x {
			xm[v] = v
		}
		for _, v := range y {
			ym[v] = true
		}

		var tc int
		for _, v := range xm {
			if ym[v] {
				tc++
			}
		}

		cnt = int(math.Max(float64(tc), float64(cnt)))
	}

	fmt.Println(cnt)
}


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

#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
using lll = long long;
using ull = unsigned long long;
using namespace std;

bool check(vector<int> aa[],int t1,int t2,int t3){
  int p1,p2,p3;
  int ii,jj,kk;

  p1=-1;
  p2=-1;
  p3=-1;
  if(aa[t1].empty()||aa[t2].empty()||aa[t3].empty()){
    return false;
  }
  
  p1 = aa[t1][0];

  for(ii=0;ii<aa[t2].size();ii++){
    if(aa[t2][ii]>=p1+1){
      p2=aa[t2][ii];
      break;
    }
  }
  if(p2 ==- 1){
    return false;
  }

  for(ii=0;ii<aa[t3].size();ii++){
    if(aa[t3][ii]>=p2+1){
      p3 = aa[t3][ii];
    }
  }

  if(p3 == -1){
    return false;
  }
  else{
    return true;
  }

}

int main(){
  lll ii,jj,kk;
  lll ll,mm,nn;
  vector<int> ret;
  int n;
  string s;
  cin >> n;
  cin >> s;

  vector<int> aa[10];
  char c[2];
  c[1] = '\0';
  int val;
  int cnt=0;
  for(ii=0;ii<n;ii++){
    c[0] = s[ii];
    val = atoi(c);
    aa[val].push_back(ii);
  }

  int p1,p2,p3;
  for(ii=0;ii<=9;ii++){
    for(jj=0;jj<=9;jj++){
      for(kk=0;kk<=9;kk++){


        if(check(aa,ii,jj,kk)){
          cnt++;
        }
      }
    }
  }
  
  cout << cnt << endl;
  
  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
#define rep1(i,n) for (int i = 1; i <= (n); i++)
#define repm(i,m,n) for (int i = m; i < (n); i++)
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;

int main() {
  vector<char> S(4);
  rep(i,4) cin >> S.at(i);
  
  cout << count(S.begin(), S.end(), '+') - count(S.begin(), S.end(), '-') << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int[] ans = new int[n];
		int ninzuu = 0;
		for (int i = 0; i < n; i++) {
			ninzuu = Integer.parseInt(sc.next());
			ans[n - ninzuu] = i + 1;
		}

		System.out.print(ans[n - 1]);
		for (int i = n - 2; i >= 0; i--) {
			System.out.print(" " + ans[i]);
		}
		System.out.println();

	}

}


Measured memory_bytes: 48144
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    int Y = sc.nextInt();
    if (X % Y == 0) {
      System.out.println(-1);
    } else {
      System.out.println(X);
    }
  }
}

Measured memory_bytes: 23124
#include <cassert>
#include <iostream>
#include <map>
#include <vector>
using namespace std;
using ll = long long;
#define repl(i, l, r) for (int i = l; i < r; i++)
#define rep(i, n) repl(i, 0, n)
int main() {
	int n;
	cin >> n;
	map<ll, ll> mp;
	rep(i, n) {
		ll a;
		cin >> a;
		mp[a]++;
	}
	if (mp.size() == 1 and mp.begin()->first == 0) {
		cout << "Yes" << endl;
		return 0;
	}
	if (n % 3) {
		cout << "No" << endl;
		return 0;
	}
	if (mp.size() == 2) {
		vector<pair<ll, ll>> a;
		for (auto p : mp) a.push_back({p.first, p.second});
		if ((a[0].first == 0 and a[0].second * 3 == n) or (a[1].first == 0 and a[1].second * 3 == n))
			cout << "Yes" << endl;
		else
			cout << "No" << endl;
	} else if (mp.size() != 3) {
		cout << "No" << endl;
	} else {
		vector<pair<ll, ll>> a;
		for (auto p : mp) a.push_back({p.first, p.second});
		if (a[0].second * 3 == n and a[1].second * 3 == n and a[2].second * 3 == n) {
			ll p = a[0].first;
			rep(i, 2) p ^= a[i + 1].first;
			if (p == 0)
				cout << "Yes" << endl;
			else
				cout << "No" << endl;
		} else
			cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 5120
#include<bits/stdc++.h>
using namespace std;
#define watch(x) cout<<(#x)<<" is "<<(x)<<endl;
#define mod 1000000007
#define pb push_back
#define endl '\n'




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

	
	char x;
	cin>>x;
	if(x == 'z') x = 'a';
	else x = (x + 1);

	cout<<x<<endl;









	


}

Measured memory_bytes: 256
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <regex>
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,j,n) for(int i = j; i < n; i++)
#define rrep(i,j,n) for(int i = j-1; i >= n; i--)
#define prec(n) fixed << setprecision(n)
#define print_array(v) rep(__k, v.size()) { cout << v[__k]; if(__k != v.size()-1) cout << " "; else cout << endl; }
#define YesorNo(a) printf(a?"Yes\n":"No\n")
#define fi first
#define se second
using namespace std;

int inf = 2147483647;
int64_t inf64 = 9223372036854775807;
int mod = 1e+7;

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

  int A, B, M;
  cin >> A >> B >> M;
  vector<int> a(A);
  vector<int> b(B);
  int mina = inf;
  int minb = inf;
  rep(i,A) {cin >> a[i]; mina = min(mina, a[i]);}
  rep(i,B) {cin >> b[i]; minb = min(minb, b[i]);}

  int res = mina + minb;
  rep(i,M) {
    int x, y, c;
    cin >> x >> y >> c;
    x--; y--;
    res = min(res, a[x]+b[y]-c);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")

#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()

using ll = long long;
using ull = unsigned long long;
using namespace std;

int main() {
  int N, K, result = 0;
  cin >> N >> K;
  vector<int> p(N);
  REP(i, N) {
    cin >> p[i];
  }
  sort(ALL(p));
  REP(i, K) {
    result += p[i];
  }
  cout << result << endl;
  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ri register int
#define fi first
#define se second
using namespace std;
inline int read(){
	#define gc getchar
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return ans;
	#undef gc
}
typedef long long ll;
typedef pair<int,int> pii;
const int mod=1e9+7;
inline int add(const int&a,const int&b){return a+b>=mod?a+b-mod:a+b;}
inline int dec(const int&a,const int&b){return a>=b?a-b:a-b+mod;}
inline int mul(const int&a,const int&b){return (ll)a*b%mod;}
inline void Add(int&a,const int&b){a=a+b>=mod?a+b-mod:a+b;}
inline void Dec(int&a,const int&b){a=a>=b?a-b:a-b+mod;}
inline void Mul(int&a,const int&b){a=(ll)a*b%mod;}
inline int ksm(int a,int p){int ret=1;for(;p;p>>=1,a=mul(a,a))if(p&1)Mul(ret,a);return ret;}
inline bool check(int x){
	int ret=0;
	while(x)x/=10,++ret;
	return ret&1;
}
const int N=1e5+5;
int n,a[N];
int main(){
	bool f=1;
	n=read();
	for(ri i=1;i<=n;++i){
		a[i]=read();
		if(i==1){
			--a[i];
			continue;
		}
		if(a[i]<a[i-1]){f=0;break;}
		if(a[i]!=a[i-1])--a[i];
	}
	puts(f?"Yes":"No");
	return 0;
}

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

using namespace std;

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

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

	int ans = 1;

	vector < int >D(N + 1);
	D[0] = 0;
	for (int i = 1; i < N + 1; i++) {
		D[i] = D[i - 1] + L[i - 1];
		if (D[i] <= X) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}


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

	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);

		int n = scan.nextInt();
		int[] a = new int[n];

		boolean handan = true;
		for(int i= 0;i<n;i++) {

			a[i] = scan.nextInt();


		if(a[i]%2 == 0) {
			if(a[i]%3 != 0 && a[i]%5 != 0) {

				handan = false;
			}
		}
		}

		System.out.println(handan?"APPROVED":"DENIED");

		scan.close();

	}

}


Measured memory_bytes: 21844
c = [list(map(int, input().split())) for _ in range(3)]

count = 0
for i in range(3):
    for j in range(3):
        if c[i][j] + c[j][i] == c[i][i] + c[j][j]:
            count += 1
if count == 9:
    print('Yes')
else:
    print('No')


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

int main(int argc, char const *argv[]) {
        map<int, int> mp;
        int n, mp_ind, mp_inp;
        int top = 100001, mid, bottom = -1;
        cin >> n;

        for (int i = 0; i < n; i++) {
                cin >> mp_ind >> mp_inp;
                if (top > mp_ind) {
                        top = mp_ind;
                }
                if (bottom < mp_ind) {
                        bottom = mp_ind;
                }
                mid = bottom - top + 1;
                mp[mp_ind] = mp_inp;
        }
        int rtn = (top - 1) + mid + mp[bottom];
        cout << rtn << endl;

        return 0;
}


Measured memory_bytes: 4992
fun main(args: Array<String>) = abc155c()
private inline fun printAnswer(function: StringBuilder.() -> Unit) = print(StringBuilder().apply(function))

fun abc155c() = printAnswer {
    val n = readLine()!!.toInt()
    val list = (1..n).map { readLine()!! }

    val map = list.groupBy { it }.map { it.key to it.value.size }
    val max = map.maxBy { it.second }!!.second

    map.filter { it.second == max }.map { it.first }.sorted().forEach { appendln(it) }
}


Measured memory_bytes: 111976
#include<iostream>
#include<map>
#include<vector>
#include<algorithm>

using namespace std;

typedef pair<int,int> P;

int main(void){
	int i,n;
	int m,a,b;
	while(1){
		map<int,int> sc;
		cin >> n;
		if(n==0)break;
		for(i=0;i<n;i++){
			cin >> m >> a >> b;
			sc[a]+=m;
			sc[b]-=m;
		}
		vector<P> v;
		for(map<int,int>::iterator iter=sc.begin();iter!=sc.end();iter++){
		  v.push_back(P(iter->first,iter->second));
		}
		sort(v.begin(),v.end());
		int w = 0;
		for(i=0;i<v.size();i++){
		  w += v[i].second;
		  if(w > 150){
			break;
		  }
		}
		cout<<(i==v.size() ? "OK" : "NG")<<endl;
	}
	return 0;
}

Measured memory_bytes: 0