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

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

    static class DIntegerCards {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int m = in.nextInt();

            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = in.nextInt();
            }

            Arrays.sort(a);

            DIntegerCards.Pair[] pairs = new DIntegerCards.Pair[m];

            for (int i = 0; i < m; i++) {
                int b = in.nextInt();
                long c = in.nextInt();
                pairs[i] = new DIntegerCards.Pair(b, c);
            }

            Arrays.sort(pairs);

            int indexA = 0;

            outer:
            for (int j = m - 1; j >= 0; j--) {
                for (int k = 0; k < pairs[j].b; k++) {
                    if (a[indexA] < pairs[j].c) {
                        a[indexA++] = pairs[j].c;
                        if (indexA >= n) {
                            break outer;
                        }
                    } else {
                        break outer;
                    }
                }
            }

            long sum = 0;
            for (long x : a) {
                sum += x;
            }

            out.println(sum);
        }

        static class Pair implements Comparable<DIntegerCards.Pair> {
            final int b;
            final long c;

            Pair(int b, long c) {
                this.b = b;
                this.c = c;
            }

            public int compareTo(DIntegerCards.Pair o) {
                return Long.compare(this.c, o.c);
            }

        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

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

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

    }
}



Measured memory_bytes: 48360
class Node():
    def __init__(self):
        self.left = -1
        self.right = -1
        self.parent = -1
        self.sibling = -1
        self.degree = -1
        self.depth = -1
        self.height = -1
        self.type = None
        
n = int(input())
A = [list(map(int, input().split())) for _ in range(n)]

T = [Node() for i in range(25)]

for (idx, left, right) in A:
    T[idx].left = left
    T[idx].right = right
    T[idx].degree = ((left!=-1) + (right!=-1))
    if left != -1:
        T[left].parent = idx
    if right != -1:
        T[right].parent = idx
    if (left!=-1) & (right!=-1):
        T[left].sibling = right
        T[right].sibling = left
        
for idx in range(n):
    if T[idx].parent == -1:
        T[idx].type = 'root'
        root = idx
    elif T[idx].degree == 0:
        T[idx].type = 'leaf'
    else:
        T[idx].type = 'internal node'
        

def set_depth(u, d):
    T[u].depth = d
    if T[u].left != -1:
        set_depth(T[u].left, d+1)
    if T[u].right != -1:
        set_depth(T[u].right, d+1)
        
def set_height(u):
    hl = hr = 0
    if T[u].left != -1:
        hl = set_height(T[u].left) + 1
    if T[u].right != -1:
        hr = set_height(T[u].right) + 1
    h = max(hl, hr)
    T[u].height = h
    return h

set_depth(root, 0)
_ = set_height(root)

for idx in range(n):
    print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(idx, T[idx].parent, T[idx].sibling, T[idx].degree, T[idx].depth, T[idx].height, T[idx].type))


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

using namespace std;

int main() {
	int n, l;
	scanf("%d %d", &n, &l);
	vector <string> a(n);
	for (int i = 0; i < n; i++) {
		string str;
		cin >> str;
		a[i] = str;
	}
	sort(a.begin(), a.end());
	string ans = "";
	for (int i = 0; i < n; i++) {
		ans += a[i];
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
<?php
  $n = trim(fgets(STDIN));
  $h = explode(' ', trim(fgets(STDIN)));

  $ans = [];
  for ($i = 0; $i < $n; $i++) {
    $ans[$h[$i] - 1] = $i + 1;
  }
  ksort($ans);
  echo implode(' ', $ans) . PHP_EOL;


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


int main(){
    int k,x;
    cin>>k>>x;
    if(k*500>=x)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 3560
#include <iostream>

using namespace std;

int main()
{
    string name;
    cin>>name;
   
    if(name=="Sunny")
    {
        cout<<"Cloudy"<<endl;
    }
    else if(name=="Cloudy")
    {
        cout<<"Rainy"<<endl;
    }
    else if("Rainy")
    {
        cout<<"Sunny"<<endl;
    }
    



    return 0;
}

Measured memory_bytes: 3532
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

ll a[225816];

int main(void){
	int n,i;
	ll t=0ll,l,ans=INFLL;
	cin >> n;
	for(i=0; i<n; ++i){
		cin >> a[i];
		t += a[i];
	}
	l = a[0];
	for(i=1; i<n; ++i){
		ans = min(ans,abs(t-l-l));
		l += a[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

ll modadd(ll x, ll y) {
    return ((x + y) % mod + mod) % mod;
}

ll modminus(ll x, ll y) {
    return (x - y + mod) % mod;
}

ll multiply(ll x, ll y) {
    return (x % mod) * (y % mod) % mod;
}

ll modpower(ll x, ll y) {
    if (y == 0) {
        return 1;
    } else if (y == 1) {
        return x % mod;
    } else if (y % 2 == 0) {
        ll p = modpower(x, y / 2);
        return p * p % mod;
    } else {
        ll p = modpower (x, y / 2);
        return (p * p) % mod * (x % mod) % mod;
    }
}

ll divide(ll x, ll y) {
    return multiply(x, modpower(y, mod - 2));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string S;
    cin >> S;
    ll cha[26];
    fill(cha, cha + 26, 0);
    REP(i, 0, N) {
        char c = S[i];
        cha[c - 'a']++;
    }
    ll ans = 1;
    REP(i, 0, 26) {
        ll num = cha[i];
        ans = multiply(ans, (num + 1));
    }
    ans--;
    cout << ans << endl;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-11
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

int mp[8][8];

void dfs(int y,int x){
  if(y<0 || y>=8 || x<0 || x>=8)return;
  if(mp[y][x]==0)return;
  mp[y][x] = 0;
  REP(i,7)dfs(y,x-3+i);
  REP(i,7)dfs(y-3+i,x);
}

int main(){
  int t;
  cin>>t;
  REP(_,t){
    REP(i,8){
      int x;
      cin>>x;
      REP(j,8){
        mp[i][7-j] = x%10;
        x/=10;
      }
    }
    int x,y;
    cin>>x>>y;
    --x;--y;
    dfs(y,x);
    cout<<"Data "<<(_+1)<<":"<<endl;
    REP(i,8){
      REP(j,8)cout<<mp[i][j];
      cout<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1160
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>

#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define MEM(a,b) memset(a,b,sizeof(a))
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807
#define LMIN -9223372036854775808

using namespace std;

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

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	int k = a % b;
	if (k == 1)return 1;
	if (k == 0)return b;
	int ans = gcd(b, k);
	return ans;
}
ll digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}

int main() {
	IOS;
	int n;
	cin >> n;
	vector<int> v(n);
	REP(i, n)cin >> v[i];
	sort(ALL(v), greater<int>());
	ll a = 0, b = 0;
	REP(i, n - 1) {
		if (v[i] == v[i + 1]) {
			if (a) {
				b = v[i]; break;
			}
			else {
				a = v[i];
				i++;
			}
		}
	}

	ll ans = a * b;

	dump(ans);
}



Measured memory_bytes: 640
package main

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

const mod = 1000000007

// 1MB
const ioBufferSize = 1 * 1024 * 1024

var sc = func() *bufio.Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	sc.Split(bufio.ScanWords)
	return sc
}()

func next() string {
	sc.Scan()
	return sc.Text()
}

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

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

func main() {
	s := next()

	// 010... 101...
	zeroStarts, oneStarts := 0, 0

	for i := 0; i < len(s); i++ {
		c := s[i]
		if c == '0' {
			if i%2 == 0 {
				oneStarts++
			} else {
				zeroStarts++
			}
		} else {
			if i%2 == 0 {
				zeroStarts++
			} else {
				oneStarts++
			}
		}
	}

	fmt.Println(min(zeroStarts, oneStarts))
}


Measured memory_bytes: 896
data = list(map(int, input().split()))
R = data[0]
G = data[1]
B = data[2]
N = data[3]

# R * a + G * b + B * c 

a = N // R + 1
b = N // G + 1
# c = N // B + 1
res = 0

def check(Ri):
    global res
    Rx = Ri * R
    if Rx > N:
        return
    for Gi in range(b):
        Gx = Gi * G
        if Rx + Gx > N:
            break
        if (N - Rx - Gx) % B == 0:
            res = res + 1

[check(Ri) for Ri in range(a)]

print(res)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int n;
  cin>>n;
  int a[n],s=0;
  for(int i=0;i<n;i++) cin>>a[i],s+=a[i];
  int m;
  cin>>m;
  for(int i=0;i<m;i++){
    int p,x;
    cin>>p>>x;
    p--;
    cout<<s-a[p]+x<<endl;
  }
  return 0;
}


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

int main(){
    int n, a, b;
    cin >> n;
    vector<int> N;
    int c;
    while(cin >> c){
        N.push_back(c);
    }
    a = *(max_element(N.begin(), N.end()));
    b = *(min_element(N.begin(), N.end()));
    cout << a - b << endl;
}

Measured memory_bytes: 256
S = int(input())

x1 = 10 ** 9
y1 = 1

x2 = 10 ** 9 - S % (10 ** 9)
y2 = S // (10 ** 9) + 1

if S == 10 ** 18:
    x1, y1 = 10 ** 9, 0
    x2, y2 = 0, 10 ** 9

print('0 0 {0} {1} {2} {3}'.format(x1, y1, x2, y2))

Measured memory_bytes: 9164
int  main(void)
{
  char a[4]="ACGT",b;
  
  scanf("%s",&b);
  
  if(b==a[0])
   printf("T");
  if(b==a[1])
   printf("G");
  if(b==a[2])
   printf("C");
  if(b==a[3])
   printf("A");
  
  return 0;
}

Measured memory_bytes: 128
package main

import (
	"fmt"
	"strconv"
)

func main() {
	var s string
	fmt.Scan(&s)

	i,_ := strconv.Atoi(s)
	yy := i/ 100
	mm := i % 100

	if (0<yy && yy<=12) && (0<mm && mm<=12) {
		fmt.Println("AMBIGUOUS")
	} else if (0<yy && yy<=12) && !(0<mm && mm<=12){
		fmt.Println("MMYY")
	}else if !(0<yy && yy<=12) && (0<mm && mm<=12){
		fmt.Println("YYMM")
	} else {
		fmt.Println("NA")
	}
}


Measured memory_bytes: 512
n,m,x,y = map(int,input().split())
xarr = list(map(int,input().split()))
yarr = list(map(int,input().split()))

xarr.sort(reverse=True)
yarr.sort()

if x+1 >= y or xarr[0] >= yarr[0] or xarr[0] >= y or yarr[0] <= x:
    print('War')
else:
    print('No War')



Measured memory_bytes: 3060
/**
 * Spreadsheet.cpp
 * Create:20180424
 * Description:r*cの要素を持つ表を読み込んで、各行と各列の合計を挿入した
 * 新しい表を出力するプログラム。
 */
#include <iostream>

int main(int argc, char* argv[]){
  int r, c;

  // 票の範囲入力
  std::cin >> c >> r;

  // 配列の作成
  int array[c + 1][r + 1];

  // 入力
  for(int i = 0; i < c; i++){
    for (int j = 0; j < r; j++){
      std::cin >> array[i][j];
    }
  }

  // 計算 行
  for(int i = 0; i < c; i++){
    int sum = 0;
    for(int j = 0; j < r; j++){
      sum += array[i][j];
    }
    array[i][r] = sum;
  }

  // 計算 列
  for(int j = 0; j < r + 1; j++){
    int sum = 0;
    for(int i = 0; i < c; i++){
      sum += array[i][j];
    }
    array[c][j] = sum;
  }

  // 表示
  for(int i = 0; i < c + 1; i++){
    for(int j = 0; j < r + 1; j++){
      std::cout << array[i][j];
      if(r != j)
        std::cout << " ";
    }
    std::cout << std::endl;
  }

  return 0;
}


Measured memory_bytes: 3136
#include<cstdlib>
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<set>
#include<stack>
#include<bitset>
#include<functional>
#include<ctime>
#include<queue>
#include<deque>
#include<complex>
#include<cassert>
using namespace std;
#define pb push_back
#define pf push_front
typedef long long lint;
typedef complex<double> P;
#define mp make_pair
#define fi first
#define se second
typedef pair<int,int> pint;
#define All(s) s.begin(),s.end()
#define rAll(s) s.rbegin(),s.rend()
#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
//問題文および制約はちゃんと確認しよう！
//サイズは10^5じゃなくて2×10^5とかかもしれないし、重要な制約・条件を見落としているかも
//とりあえずサンプルを読んでから解法を考えよう？
int main()
{
	string s;cin>>s;rep(i,(int)s.size()) s[i]='x';
	cout<<s<<endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<ctype.h>
#include<string>
#include<math.h>
#define pi 3.141592653589
#include<iomanip>
using namespace std;
#include<algorithm>
#define rep(i,a,n) for(int i=a;i<n;i++)
#define INF 1e9
#define LINF 1e17
#define ll long long
#define MOD (int)(1e9+7)
 
 
 
int main(){
    
    int n;
    ll x,a[100001],ans=0;
    
    cin>>n>>x;
    rep(i,0,n)cin>>a[i];
    rep(i,0,n){
        if(i==0){
            if(a[i]>x){
                ans+=a[i]-x;
                a[i]=x;
            }
        }
        else{
            if(a[i]+a[i-1]>x){
                ans+=a[i]+a[i-1]-x;
                a[i]=x-a[i-1];
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

 int main(void)
 {
   int r,D;
   int x_2000;
   int x=0;
   int i;
   
   scanf("%d",&r);  
   scanf("%d",&D); 
   scanf("%d",&x_2000);
   for(i=1;i<=10;i++){
     x=r*x_2000-D;
     x_2000=x;
     printf("%d\n",x);
   }
   return 0;
 }


Measured memory_bytes: 128
let () = Scanf.scanf "%d\n" @@ fun n ->
  let sts = Array.init n @@ fun _ -> Scanf.scanf "%s %d\n" @@ fun s t -> s, t in
  Scanf.scanf "%s\n" @@ fun x ->
    Printf.printf "%d\n" @@
    snd @@
    List.find (fun (s, _) -> s = x) @@
    snd @@
    Array.fold_right (fun (s, t) (sum, acc) ->
      (sum + t, (s, sum) :: acc)) sts (0, [])

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

int main(){
  int N;
  long D;
  cin >> N >> D;
  D *= D;
  vector<long> A(N), B(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i) >> B.at(i);
  }
  int ans = 0;
  for(int i = 0; i < N; i++){
    A.at(i) *= A.at(i);
    B.at(i) *= B.at(i);
    if( D >= A.at(i) + B.at(i))　ans++;
  }
  cout << ans << endl;
  
}

Measured memory_bytes: 5944
#include <iostream>
#define llint long long 
#define mod 1000000007

using namespace std;

llint n;
llint a[100005];
llint pos[100005];
llint l, r;

llint fact[200005], fact_i[200005];

llint pow(llint a, llint n)
{
	if(n == 0) return 1;
	if(n % 2){
		return ((a%mod) * (pow(a, n-1)%mod)) % mod;
	}
	else{
		return pow((a*a)%mod, n/2) % mod;
	}
}

void make_fact()
{
	llint val = 1;
	fact[0] = 1;
	for(int i = 1; i < 200005; i++){
		val *= i;
		val %= mod;
		fact[i] = val;
	}
	for(int i = 0; i < 200005; i++){
		fact_i[i] = pow(fact[i], mod-2);
	}
}

llint comb(llint n, llint k)
{
	llint ret = 1;
	ret *= fact[n];
	ret *= fact_i[k], ret %= mod;
	ret *= fact_i[n-k], ret %= mod;
	return ret;
}

int main(void)
{
	make_fact();
	
	cin >> n;
	for(int i = 1; i <= n+1; i++) cin >> a[i];
	
	for(int i = 1; i <= n+1; i++){
		if(pos[a[i]] > 0){
			l = pos[a[i]];
			r = i;
			break;
		}
		pos[a[i]] = i;
	}
	
	for(int k = 1; k <= n+1; k++){
		llint ans = 0;
		if(n-1 >= k) ans += comb(n-1, k), ans %= mod;
		ans += comb(n-1, k-2), ans %= mod;
		if(n-1 >= k-1) ans += 2 * comb(n-1, k-1), ans %= mod;
		if(l+n-r >= k-1) ans -= comb(l+n-r, k-1), ans += mod, ans %= mod;
		cout << ans << endl;
	}
	
	return 0;
}

Measured memory_bytes: 5888
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

vector<ll> divisor;
void find_divisor(ll N) {
  for(int i=1; i<=sqrt(N); i++) {
    if(N % i == 0)
      divisor.push_back(i);
  }
  int n = divisor.size();
  for(int i=n-1; i>=0; i--) {
    if(N != (ll)pow(divisor[i], 2))
      divisor.push_back(N / divisor[i]);
  }
}

int main() {
  int N;
  ll K;
  cin >> N >> K;
  vector<ll> A(N);
  rep(i, N) cin >> A[i];
  sort(A.begin(), A.end());
  ll sum = accumulate(A.begin(), A.end(), 0LL);
  find_divisor(sum);
  int M = divisor.size();
  vector<ll> R(N);
  vector<ll> S(N+1);
  rep(i, M) {
    ll div = divisor[M-i-1];
    rep(i, N) R[i] = A[i] % div;
    sort(R.begin(), R.end());
    rep(i, N) S[i+1] = S[i] + R[i];
    ll m = longinf;
    REP(i, 1, N) m = min(m, max(S[i], div*(N-i)-(S[N]-S[i])));
    if(m <= K) {
      cout << div << endl;
      break;
    }
  }
  return 0;
}



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

int main(){
  
  int N;
  int H;
  int W;
  
  cin >> N;
  cin >> H;
  cin >> W;
  
  int num = N - H + 1;
  int num2 = N - W + 1;
  
  cout << num * num2 << endl;
}


Measured memory_bytes: 256
"""
AtCoder Beginner Contest 122  D - We Like AGC

愚直解
・N文字のうち、各文字についてA,C,G,Tの4通りを取りうるので、4^N
・できた文字について、AGCを含まないか確認：N
・隣接する2文字を一回だけ入れ替えて、AGCができないか確認：N
なので、4^N * N * N ぐらいか？後ろ二つはまとめてもいいが。
また、AAAGCでNGなのがわかっているのに、AAAGCAAを作って調べる〜みたいな重複もいけてない。
このような重複を避けるには、小さい問題からメモ化で解決するDPがよいと思う

入れ替えてAGCができる時、
GAC -> AGC か、 ACG -> AGC、　AXGC -> XAGC、　AGXC -> AGCX
なので、作っている文字列の右端から3文字がわかって入れば行けそう


dp[i+1][j(i-2文字目)][k(i-1文字目)][l(i文字目)]：i文字目をl、一個手前をk、もう一個手前をjとした時の文字列の個数
とすると

遷移
・dp[i+1][A][G][C], dp[i+1][G][A][C], dp[i+1][A][C][G] :こいつらは作ってはいけない
・dp[i][A][＊][G] -> dp[i+1][*][G][C] : Aと* を入れ替えるとAGCができるのでNG
・dp[i][A][G][*] -> dp[i+1][G][*][C] : *とCを入れ替えるとAGCになるのでだめ

上の遷移はなんかややこしいので、ざっくりまとめると、　・・・pqrs　と並んでいて、pqrsについて、
A,G,*,C
A,*,G,C
*,A,G,C,
*,G,A,C
*,A,C,G
がアウトで他はOK
これをDPでやるとよい

最後に末尾3文字について、全パターン見て足し合わせる。


"""

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

# dp[i+1][j(i-2文字目)][k(i-1文字目)][l(i文字目)]：i文字目をl、一個手前をk、もう一個手前をjとした時の文字列の個数
# j,k,lについて、A=1,C=2,G=3,T=4, 初期化の都合上0もある
dp = [[[[0 for _ in range(5)] for _ in range(5)] for _ in range(5)] for _ in range(N+1)]
dp[0][0][0][0] = 1
A = 1
C = 2
G = 3
T = 4

for i in range(N):
    # 初期値をうまく利用したいので、p,q,rは0~4まで
    for p in range(5):
        for q in range(5):
            for r in range(5):
                # sをA,C,G,Tで動かす
                for s in range(1, 5):
                    # ・・・・・pqrsの並びにできるか考える
                    """
                    A,G,*,C
                    A,*,G,C
                    *,A,G,C,
                    *,G,A,C
                    *,A,C,G
                    がアウト
                    """
                    if p == A and q == G and s == C : continue
                    if p == A and r == G and s == C : continue
                    if q == A and r == G and s == C : continue
                    if q == G and r == A and s == C : continue
                    if q == A and r == C and s == G : continue

                    dp[i+1][q][r][s] += dp[i][p][q][r]
                    dp[i+1][q][r][s] %= MOD


ans = 0
for i in range(1,5):
    for j in range(1,5):
        for k in range(1,5):
            #print(i,j,k, dp[-1][i][j][k])
            ans += dp[-1][i][j][k]
            ans %= MOD


print(ans) 


Measured memory_bytes: 3572
#include <ctime>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <algorithm>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <deque>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
typedef double lf;
typedef long double Lf;
typedef pair <int,int> pii;
typedef pair <ll, ll> pll;

#define TRACE(x) cerr << #x << "  " << x << endl
#define FOR(i, a, b) for (int i = (a); i < int(b); i++)
#define REP(i, n) FOR(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define _ << " " <<

#define fi first
#define sec second
#define mp make_pair

const int MAXN = 100100;

int n, m, a, b, cnt[MAXN];

int main() {
  scanf("%d %d",&n,&m);
  REP(i, m) {
    REP(j, 2) {
      cin >> a;
      cnt[a] ^= 1;
    }
  }

  REP(i, MAXN) {
    if (cnt[i]) {
      puts("NO");
      return 0;
    }
  }

  puts("YES");
  return 0;
}


Measured memory_bytes: 640
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;
int main() {
	int N;
	char c;
	vector<char> slimes;
	scanf("%d", &N);
	for (int i = 0; i < N; ++i) {
		scanf(" %c", &c);
		if (slimes.empty() || c != slimes.back()) slimes.push_back(c);
	}
	printf("%lu", slimes.size());
	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner

import scala.collection.mutable
import scala.collection.mutable.ArrayBuffer

object Main extends App {
  val in = new Scanner(System.in)
  val V = in.nextInt()
  val E = in.nextInt()
  val dinitz = new Dinitz(V)
  for (_ <- 0 until E) {
    val s = in.nextInt()
    val t = in.nextInt()
    val c = in.nextInt()
    dinitz.addEdge(s, t, c)
  }

  val f = dinitz.maxFlow(0, V - 1)
  println(f)
}

import java.util

class Dinitz(val V: Int) {

  class Edge(var to: Int, var cap: Long, var rev: Int)

  private val graph = (for (_ <- 0 until V) yield new ArrayBuffer[Edge]()).toArray
  private val level = new Array[Int](V)
  private val iter = new Array[Int](V)


  def addEdge(from: Int, to: Int, cap: Long): Unit = {
    graph(from).append(new Edge(to, cap, graph(to).size))
    graph(to).append(new Edge(from, 0, graph(from).size - 1))
  }

  def maxFlow(source: Int, sink: Int): Long = {
    var flow = 0L

    while (true) {
      val queue = new mutable.Queue[Int]()
      util.Arrays.fill(level, -1)
      level(source) = 0
      queue.enqueue(source)
      while (queue.nonEmpty) {
        val v = queue.dequeue()
        for (e <- graph(v)) {
          if (e.cap > 0 && level(e.to) < 0) {
            level(e.to) = level(v) + 1
            queue.enqueue(e.to)
          }
        }
      }

      if (level(sink) < 0) return flow
      util.Arrays.fill(iter, 0)

      def dfs(v: Int, t: Int, f: Long): Long = {
        if (v == t) return f

        while (iter(v) < graph(v).size) {
          val e = graph(v)(iter(v))
          if (e.cap > 0 && level(v) < level(e.to)) {
            val d = dfs(e.to, t, Math.min(f, e.cap))
            if (d > 0) {
              e.cap -= d
              graph(e.to)(e.rev).cap += d
              return d
            }
          }

          iter(v) += 1
        }
        0
      }
      
      var f = 1L
      while (f > 0) {
        f = dfs(source, sink, Long.MaxValue)
        flow += f
      }
    }

    throw new IllegalStateException()
  }
}

Measured memory_bytes: 53248
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <stack>

#define INF (int)1e09

using std::cin;
using std::cout;
using std::endl;
using std::setprecision;
using std::fixed;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::string;
using std::vector;
using std::list;
using std::map;
using std::set; // insert erase find count
using std::queue;
using std::priority_queue;
using std::stack;

template <typename T> using Vec = vector<T>; // c++11
typedef pair<int, int> PII;
typedef pair<int, pair<int, int> > PIII;

int main(void) {
    int h;
    int w;
    cin >> h >> w;
    string s;
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            cin >> s;
            if (s == "snuke") {
                cout << (char)(j + 'A') << i + 1 << endl;
            }
        }
    }
    return 0;
}



Measured memory_bytes: 256
n,k = list(map(int,input().split()))
a = list(map(int,input().split()))

ng=0
ok=max(a)+1

while ok-ng>1:
    mid = (ok+ng)//2
    cur=0
    for x in a:
        cur+=(x-1)//mid
    if cur>k:
        ng=mid
    else:
        ok=mid
print(ok)


Measured memory_bytes: 30928
<?php
fscanf(STDIN, '%d %d', $n, $m);
for ($i  = 0; $i < $n; $i++) {
    fscanf(STDIN, '%d %d', $a, $b);
    $s[$a][] = $b;
}

$cnt = 0;
$q = new SplPriorityQueue();
for ($i = 1; $i <= $m; $i++) {
    if (!is_null($s[$i])) {
        foreach ($s[$i] as $v) {
            $q->insert($v, $v);
        }
    }
    if (!$q->isEmpty()) $cnt += $q->extract();
}
echo $cnt.PHP_EOL;

Measured memory_bytes: 55800
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;
typedef long long ll;
const int N = 1e2 + 10;
const int mod = 1e9 + 7;



main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    ll n, k;
    cin >> n >> k;
    n %= k;
    while (1)
    {
        if (abs(n - k) < n) n = abs(n - k);
        else break;
    }

    cout << n;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
	int n,a[100000]={0},i,j,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(i=1;i<=n;i++){
		if(a[a[i]]==i)ans++;
	}
	printf("%d\n",ans/2);
	return 0;
}

Measured memory_bytes: 512
#from statistics import median
#import collections
#aa = collections.Counter(a) # list to list
#from itertools import combinations # (string,3) 3回
#
#
# pythonで無理なときは、pypyでやると正解するかも！！
#
#

mod = 10**9 + 7

def readInts():
  return list(map(int,input().split()))
def main():
    import fractions
    n = int(input())
    A = readInts()
    g = fractions.gcd(A[0],A[1])
    for i in range(2,n):
        g = fractions.gcd(g,A[i])
    print(g)


if __name__ == '__main__':
  main()


Measured memory_bytes: 16244
def main():
    N,Q = map(int,input().split())
    S = input()
    lr = []
    for i in range(Q):
        lr.append(list(map(int,input().split())))

    cl = [0 for _ in range(len(S))]

    for i in range(1,len(S)):
        if S[i] == 'C' and S[i-1] == 'A':
            cl[i] = cl[i-1] + 1
        else:
            cl[i] = cl[i-1]


    #print(cl) 
    #print(S)

    for l,r in lr:
        res = cl[r-1] - cl[l-1] 
        print(res)


if __name__ == "__main__":
    main()


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

int main() {
  int n;
  cin >> n;
  vector<int> jug(n);

  int count = 0;
  for (int i = 1; i <= n; i++) {
    for (int j = 1; j <= n; j++) {
      if (i % j == 0 && i % 2 == 1) {
        jug.at(i-1)++;
      }  
    }
    if (jug.at(i-1) == 8) {
      count++;
    }
  } 
  cout << count << endl;
}

Measured memory_bytes: 3644
#include<iostream>
using namespace std;
int main(){
    int n;
    while(cin>>n,n){
        int P[100];
        for(int i=0;i<n;i++)cin>>P[i];
        int left=32;
        for(int i=0;;i++){
            if(i%2==0){
                left-=(left-1)%5;
                cout<<left<<endl;
            }
            else{
                left-=P[(i/2)%n];
                if(left<=0)left=0;
                cout<<left<<endl;
                if(!left)break;
            }
        }
    }
}

Measured memory_bytes: 1160
/* 

*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("avx,avx2,fma")
#include <iostream>
#include <iomanip>
#include <sstream>
#include <fstream>
#include <string>
#include <cstring>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <stack>
#include <deque>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <utility>
 
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
 
#define LSOne(S) (S & (-S))
#define EPS 1e-9
 
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> pi;
typedef pair<ll, ll> pll;
typedef pair<ll, int> pli;
typedef pair<double, double> pd;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_multiset;

const int MAXN = 1e5+5;
vector<int> graph[MAXN];
ll dpSub[MAXN], dpAll[MAXN];
int n, MOD;

void DPSub(int curr, int par)
{
    dpSub[curr] = 1;
    for(auto& neighbor : graph[curr])
    {
        if(neighbor == par) continue;
        DPSub(neighbor, curr);
        dpSub[curr] *= (dpSub[neighbor] + 1);
        dpSub[curr] %= MOD;
    }
}

void DPAll(int curr, int par)
{
    int k = graph[curr].size();
    vector<ll> pref(k+2), suff(k+2);
    pref[0] = 1, suff[k+1] = 1;
    for(int i = 1; i <= k; ++i)
    {
        int neighbor = graph[curr][i-1];
        pref[i] = (dpSub[neighbor] + 1);
        (pref[i] *= pref[i-1]) %= MOD;
    }
    for(int i = k; i > 0; --i)
    {
        int neighbor = graph[curr][i-1];
        suff[i] = (dpSub[neighbor] + 1);
        (suff[i] *= suff[i+1]) %= MOD;
    }

    for(int i = 1; i <= k; ++i)
    {
        int neighbor = graph[curr][i-1];
        if(neighbor == par) continue;

        dpAll[neighbor] = dpSub[neighbor];
        // Num ways to paint this black without considering child, plus paint this white
        ll fromThis = (pref[i-1] * suff[i+1] + 1) % MOD;
        (dpAll[neighbor] *= fromThis) %= MOD;

        dpSub[curr] = (pref[i-1] * suff[i+1]) % MOD;
        DPAll(neighbor, curr);
   }
}

int main()
{
    std::ios::sync_with_stdio(false);
    cin.tie(0); // FOR QUERY PROBLEM DON'T FORGET TO UNCOMMENT THIS
    cin >> n >> MOD;
    for(int i = 1; i < n; ++i)
    {
        int a, b;
        cin >> a >> b;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }
    DPSub(1, 1);
    dpAll[1] = dpSub[1];
    DPAll(1, 1);
    for(int i = 1; i <= n; ++i)
    {
        cout << dpAll[i] << "\n";
    }
    return 0; 
}

Measured memory_bytes: 21888
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int a[] = new int[N];
        double total = 0;
        double ave = 0;
        double distance = 0;
        double ans = 1000000;
        int x = 0;
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
        }
        for(int i = 0; i < N; i++){
            total += a[i];
        }
        ave = total / N;
        for(int i = 0; i < N; i++){
            distance = Math.abs(ave - a[i]);
            if(ans > distance){
                ans = distance;
                x = i;
            }
        }
        System.out.println(x);
    }
}


Measured memory_bytes: 35780
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  int A,B;
  cin>>A>>B;
  int n[A];
  int sum = 0;
  for(int i = 0;i<A;i++){
    n[i] = B+i;
    sum += n[i];
  }
  if(n[0]<=0 && n[A-1]>=0){
    cout << sum << endl;
  }
  else if(n[0] >=0){
    cout << sum - n[0] << endl;
  }
  else if(n[A-1] < 0){
    cout << sum-n[A-1] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);

int main()
{
  //input_from_file;
  string s1,s2,s;cin>>s1>>s2;ll n=s1.size(),m=s2.size();
  vector<vector<string>> dp(2,vector<string> (m+1,""));
  for(int i=1;i<=n;i++){
    for(int j=1;j<=m;j++){
      if(s1[i-1]==s2[j-1])  {dp[i%2][j]=dp[(i+1)%2][j-1];dp[i%2][j].pb(s2[j-1]);}  
      else{
          dp[i%2][j]=dp[(i+1)%2][j].size()>dp[i%2][j-1].size() ? dp[(i+1)%2][j]:dp[i%2][j-1];
      }
    }
  }
  cout<<dp[n%2][m];
  return 0;
}

Measured memory_bytes: 16700
#include<bits/stdc++.h> 
using namespace std;
typedef long long ll;
template<typename T1,typename T2> bool chmin(T1 &a,T2 b){if(a<=b)return 0; a=b; return 1;}
template<typename T1,typename T2> bool chmax(T1 &a,T2 b){if(a>=b)return 0; a=b; return 1;}
int dx[4]={0,1,-1,0};
int dy[4]={1,0,0,-1};

ll dp[3001][3001][4];

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

    ll r,c,k;
    cin>>r>>c>>k;
    ll a[r][c]={};
    for(int i=0;i<k;i++){
        int x,y,v;
        cin>>x>>y>>v;
        x--,y--;
        a[x][y] = v;
    }
    dp[0][0][1] = a[0][0];
    for(int i=0;i<r;i++){
        for(int j=0;j<c;j++){
            for(int k=0;k<=3;k++){
                if(i+1<r){
                    chmax(dp[i+1][j][0],dp[i][j][k]);
                    chmax(dp[i+1][j][1], dp[i][j][k] + a[i+1][j]);
                }
                if(j+1<c){
                    chmax(dp[i][j+1][k], dp[i][j][k]);
                    if(k != 3) chmax(dp[i][j+1][k+1], dp[i][j][k] + a[i][j+1]);
                }
            }
        }
    }
    ll ans = 0;
    for(int i=0;i<4;i++){
        chmax(ans,dp[r-1][c-1][i]);
    }
    cout << ans << endl;
}

Measured memory_bytes: 355132
//be naame khodaa

#include <iostream>
#include <cmath>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <cstdio>
#include <algorithm>
#include <set>
#include <cassert>
#include <iomanip>
#include <cstring>
#include <sstream>
#define fi first
#define se second
#define rep(i, x, n) for (int i = x; i < n; i++)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())
using namespace std;
typedef long long ll;
typedef pair <int, int> pii;
typedef vector <int> VI;

int main()
{
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	ll all = 1, odd = 1;
	for (int i = 0; i < n; i++){
		int x;
		cin >> x;
		all *= 3;
		if (x%2 == 0)
			odd *= 2;
	}
	cout << all - odd << endl;
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int S, h, m, s;
	
	scanf("%d", &S);
	
	s = S % 60;
	m = ((S % 3600) - s)/60;
	h = (S - s - (m*60))/3600;
	
	printf("%d:%d:%d\n",h,m,s);
	
	return 0;
}

Measured memory_bytes: 1020
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

class UnionFind {
public:
    vector<long long> parent;
    long long n;
    UnionFind(long long x) :parent(x, -1), n(x){}
    bool unite(long long x, long long y){
        x = find(x); y = find(y);
        if (x == y) return false;
        if (size(x) < size(y)) swap(x, y);
        parent[x] += parent[y]; parent[y] = x;
        return true; }
    bool same(long long x, long long y){ return find(x) == find(y); }
    long long find(long long x){ return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    long long size(long long x){ return -parent[find(x)]; }
};

int main(){
    Init();
    ll n, m, cnt = 0; cin >> n >> m;
    vector<pair<ll, ll>> edge(m);
    rep(i, m) cin >> edge[i].first >> edge[i].second;

    // i番目のエッジを除いてUnionFindを作り、要素数の差異で非連結か判断
    rep(i, m){
        UnionFind uf(n);
        rep(j, m){
            if(j == i) continue;
            ll v1 = edge[j].first-1;
            ll v2 = edge[j].second-1;
            uf.unite(v1, v2);
        }
        if(uf.size(0) != n) cnt++;
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.complex, std.container, std.math, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }


int N;
int[] A;

void main() {
  try {
    for (; ; ) {
      N = readInt();
      A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      A.sort();
      
      bool ans;
      if (N % 3 == 0) {
        ans = true;
        foreach (i; 0 .. N) {
          ans = ans && (A[i / (N / 3) * (N / 3)] == A[i]);
        }
        ans = ans && ((A[0] ^ A[N / 3] ^ A[N / 3 * 2]) == 0);
      } else {
        ans = true;
        foreach (i; 0 .. N) {
          ans = ans && (A[i] == 0);
        }
      }
      writeln(ans ? "Yes" : "No");
    }
  } catch (EOFException e) {
  }
}


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

#define rr(i, b)    for (int i = 0; i < int(b); i++)
#define vi(n, a) vector <int> a(n); rr(i, n) cin >> a[i]
#define pvec(a) rr(i, a.size()) cout << a[i] << " "; cout << endl
#define bug(x) cout << #x << " " << x << endl
#define ll long long
#define vii vector <int>

using namespace std;

bool check(int n) {
    string s = to_string(n);

    int l = 0;
    int r = s.size() - 1;

    while(l < r) {
        if(s[l] != s[r]) {
            return false;
        }
        l++;
        r--;
    }

    return true;
}

void solve() {
    int a, b;
    cin >> a >> b;

    int counter = 0;

    for(int i = a; i <= b; i++) {
        if(check(i)) counter++;
    }

    cout << counter << endl;
}
 
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    solve();
    return 0;
}

Measured memory_bytes: 3752
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

struct node {
    node *son[2];
    bool dead;

    node() {
        son[0] = son[1] = NULL;
        dead = false;
    }
};

ll n, i, L;
string s;
node *Head;
ll SG;

ll get_sg(ll x) {
    ll bit;

    return (x ^ (x - 1)) & x;

    for (bit = 1LL << 60; bit > 0; bit >>= 1) {
        if (x < bit) continue;
        if (x == bit) return x;
        x ^= bit;
    }
}

void compute() {
    int i, j, act;
    int dp[111];
    vector<int> aux;

    dp[0] = 0;
    for (i = 1; i <= 100; i++) {
        aux = {0};
        act = 0;

        for (j = i - 1; j > 0; j--) {
            act ^= dp[j];
            aux.pb(act);
        }

        sort(aux.begin(), aux.end());
        aux.resize(unique(aux.begin(), aux.end()) - aux.begin());
        aux.pb(-1);

        for (j = 0; aux[j] == j; j++);
        dp[i] = j;
        cerr << i << ' ' << dp[i] << ' ' << get_sg(i) << '\n';
    }
}

void add(string& s) {
    int id;
    node* act = Head;

    for (auto c : s) {
        id = c - '0';
        if (act->son[id] == NULL)
            act->son[id] = new node();
        act = act->son[id];
    }

    act->dead = true;
}

void dfs(node* act, ll lvl) {
    if (act->dead) return;

    if (act->son[0] != NULL) {
        dfs(act->son[0], lvl + 1);
    } else {
        SG ^= get_sg(L - lvl);
    }

    if (act->son[1] != NULL) {
        dfs(act->son[1], lvl + 1);
    } else {
        SG ^= get_sg(L - lvl);
    }
}

int main()
{
 //   freopen("test.in","r",stdin);

    //compute();
    cin >> n >> L;

    Head = new node();
    for (i = 1; i <= n; i++) {
        cin >> s;
        add(s);
    }

    dfs(Head, 0);
    if (SG)
        cout << "Alice";
    else
        cout << "Bob";


    return 0;
}


Measured memory_bytes: 4992
#include <stdio.h>

int main(void){
  int i,j,work,n,s[100],sum=0;
  
  while(1){
    scanf("%d",&n);
    if(n == 0) break;
    for(i=0;i<n;i++){
      scanf("%d",&s[i]);
    }
    for(i=0;i<n;i++){
      for(j=0;j<n-1;j++){
	if(s[i]>s[j]){
	  work = s[i];
	  s[i] = s[j];
	  s[j] = work;
	}
      }
    }
    
    
    
    for(i=1;i<n-1;i++){
      sum += s[i];
      s[i] -= s[i];
    }
    printf("%d\n",sum/(n-2));
    sum -= sum;
    
  }
  
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF=1001001001;
vector<pair<int64_t,int64_t>>pppp(int64_t x){
  vector<pair<int64_t,int64_t>>p;
  for(int64_t i=2;i*i<=x;i++){
    int cnt=0;
    if(x%i==0){
    while(x%i==0){cnt++;x/=i;}
    p.push_back(make_pair(i,cnt));
    }
  }
  if(x!=1){p.push_back(make_pair(x,1));}
  return p; 
}
 
int main() {
  int64_t N,A,B;
  cin>>N>>A>>B;
  vector<int>X(N);
  for(int i=0;i<N;i++){
   cin>>X[i];
  }
  int64_t sum=0;
  for(int i=0;i<N-1;i++){
   if((X[i+1]-X[i])*A<B){sum+=(X[i+1]-X[i])*A;}
   else{sum+=B;}
  }

  cout<<sum<<endl;
  return 0;
}

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

int main() {
  int A, B, n;
  cin >> A >> B;
  
  for(int i=A; i<=B; i++){
    if(i/10000==i%10 && i/1000%10==i/10%10)
      n++;
  }
    cout << n << endl;
}


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

int main(void) {
	int A, B, count=0;
	cin >> A >> B;
	if (A <= B) {
		count += B;
		B--;
	}
	else {
		count += A;
		A--;
	}
	if (A <= B) {
		count += B;
		B--;
	}
	else {
		count += A;
		A--;
	}
	cout << count;
	return 0;
}

Measured memory_bytes: 384