akhauriyash/Code-Regression huggingface dataset:
//package AtCoderRecommendations;
import java.io.*;
import java.math.*;
import java.util.*;
public class Main {  
 
	public static void main(String[] args) { 
		FastScanner I = new FastScanner(); //Input
		OutPut O = new OutPut(); //Output
		int A = I.nextInt();
		int B = I.nextInt();
		int C = I.nextInt();
		boolean[] vis = new boolean[B]; //All modulos achieved so far
		int cur = 0;
		boolean found = false;
		while (true) {
			int mod = cur%B;
			if (vis[mod]) break;
			vis[mod]=true;
			if (mod==C) {
				found=true;
				break;
			}
			cur+=A;
		}
		O.pln(found?"YES":"NO");
	}
	public static boolean Prime(long N) {
		if (N==0) return true;
		if (N==1) return false;
		for (int i = 2; i <= Math.sqrt(N); i++) {
			if (N%i==0) return false;
		}
		return true;
	}
	public static long ceil(long num, long den) {long ans = num/den; if (num%den!=0) 
	ans++; return ans;}
	public static long GCD(long a, long b) {
		if (a==0||b==0) return Math.max(a,b);
		return GCD(Math.min(a, b),Math.max(a, b)%Math.min(a, b));
	}
	public static long FastExp(long base, long exp, long mod) {
		long ans=1;
		while (exp>0) {
			if (exp%2==1) ans*=base;
			exp/=2;
			base*=base;
			base%=mod;
			ans%=mod;
		}
		return ans;
	}
	public static long ModInv(long num,long mod) {return FastExp(num,mod-2,mod);}
	public static int pop(long x) { //Returns number of bits within a number
		int cnt = 0;
		while (x>0) {
			if (x%2==1) cnt++;
			x/=2;
		}
		return cnt;
	}
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		int nextInt() {return Integer.parseInt(next());}
		long nextLong() {return Long.parseLong(next());};
	}
	static class OutPut{
		PrintWriter w = new PrintWriter(System.out);
		void pln(double x) {w.println(x);w.flush();}
		void pln(boolean x) {w.println(x);w.flush();}
		void pln(int x) {w.println(x);w.flush();}
		void pln(long x) {w.println(x);w.flush();}
		void pln(String x) {w.println(x);w.flush();}
		void pln(char x) {w.println(x);w.flush();}
		void pln(StringBuilder x) {w.println(x);w.flush();}
		void pln(BigInteger x) {w.println(x);w.flush();}
		void p(int x) {w.print(x);w.flush();}
		void p(long x) {w.print(x);w.flush();}
		void p(String x) {w.print(x);w.flush();}
		void p(char x) {w.print(x);w.flush();}
		void p(StringBuilder x) {w.print(x);w.flush();}
		void p(BigInteger x) {w.print(x);w.flush();}
		void p(double x) {w.print(x);w.flush();}
		void p(boolean x) {w.print(x);w.flush();}
	}
}







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

using namespace std;

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

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvll = vector<vll>;
using vvd = vector<vd>;
using vvvi = vector<vvi>;
using vvvll = vector<vvll>;
using vvvd = vector<vvd>;

const double pi=acos(-1);
const ll MOD=1e9+7;
const ll INF=(1LL<<60);

int main() {
    int n,k;
    cin>>n>>k;
    char s[n];
    rep(i,n)cin>>s[i];
    vi d;
    int nowc=1;
    char now=s[0];
    for (int i=1;i<n;i++){
        if (now!=s[i]){
            d.push_back(nowc);
            nowc=1;
            now=s[i];
        }
        else nowc+=1;
    }
    d.push_back(nowc);
    int num=d.size();
    if (k>=num/2 && s[0]=='1'){
        cout<<n<<endl;
    }
    else if (s[0]=='0' && k>=double(num)/2.0){
        cout<<n<<endl;
    }
    else{
        if (s[0]=='1'){
            int ans=0;
            int ans1=0;
            rep(i,k){
                ans1+=d[2*i];
                ans1+=d[2*i+1];
            }
            ans1+=d[2*k];
            ans=ans1;
            for (int i=1;i+2*k+1<num;i+=2){
                ans1-=d[i-1];
                ans1-=d[i];
                ans1+=d[i+2*k];
                ans1+=d[i+2*k+1];
                ans=max(ans1,ans);
            }
            if (num%2==0){
                int ans2=0;
                rep(i,k){
                    ans2+=d[num-2*i-1];
                    ans2+=d[num-2*i-2];
                }
                ans=max(ans,ans2);
            }
            cout<<ans<<endl;
        }
        else{
            int ans=0;
            int ans1=0;
            rep(i,k){
                ans1+=d[2*i];
                ans1+=d[2*i+1];
            }
            //ans1+=d[2*k];
            ans=ans1;
            ans1-=d[0];
            ans1+=d[2*k];
            ans1+=d[2*k+1];
            ans=max(ans1,ans);
            for (int i=0;i+2*k+3<num;i+=2){
                //cout<<"!"<<endl;
                ans1-=d[i+1];
                ans1-=d[i+2];
                ans1+=d[i+2*k+2];
                ans1+=d[i+2*k+3];
                ans=max(ans1,ans);
            }
            int ans2=0;
            if(num%2==1){
            rep(i,k){
                ans2+=d[num-2*i-1];
                ans2+=d[num-2*i-2];
            }
            ans=max(ans,ans2);}
            
            cout<<ans<<endl;
        }
    }
    


    return 0;
}

Measured memory_bytes: 1020
#include<iostream>
#include<string>
using namespace std;
string s;
int n,m,ans,b,j;
int main()
{
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]=='C')
		{
			b=1;
			j=i;
			break;
		}
	}
	if(b==0)
	{
		cout<<"No";
		return 0;
	}
	else
	{
		for(;j<s.size();j++)
		{
			if(s[j]=='F')
			{
				cout<<"Yes";
				return 0;
			}
		}
		cout<<"No";
		return 0;
	}
}

Measured memory_bytes: 256
from numpy import*;I=lambda:map(int,input().split());W,H,N=I();m=zeros((H,W))
for i in range(N):x,y,a=I();m[y*(a>3):H*(a!=3)or y,x*(a==2):W*~-a or x]=1
print(W*H-int(sum(m)))

Measured memory_bytes: 12500
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
using ll = long long;
using namespace std;
constexpr ll MOD = 1e9 + 7;

ll n, a[300010];

int main()
{
	cin >> n;
	for (int i = 0; i < n; ++i) cin >> a[i];
	
	ll ans = 0;
	for (int i = 0; i < 60; ++i) {
		ll cnt = 0;
		for (int j = 0; j < n; ++j) {
			if (a[j] >> i & 1) ++cnt;
		}
		ans = (ans + (1LL << i) % MOD * (n - cnt) % MOD * cnt % MOD) % MOD;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
#define SIZE_OF_ARRAY(array) (sizeof(array)/sizeof(array[0]))

int main(){
  int n, i;
  cin >> n;
  vector<int> a(n);
  for(i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a.begin(), a.end(), greater<int>());
  int ans = 0;
  for(i = 0; i < n; i += 2){
    ans += a[i];
  }
  for(i = 1; i < n; i += 2){
    ans -= a[i];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <unordered_map>

using namespace std;

auto main() -> int {
  
  string input;
  
  cin >> input;
  
  const auto result = [] (const string & s) {
    auto odd = true;
  	for (const auto & c : s) {
  	  if (odd && c == 'L') {
  	    return "No";
  	  }
  	  if (!odd && c == 'R') {
        return "No";
  	  }
  	  odd = !odd;
  	}
    return "Yes";
  }(input);
  
  std::cout << result;
  
  return 0;
}


Measured memory_bytes: 256
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;


typedef long long ll;
typedef pair<int, int> pii;
const int MOD = 1e9 + 7;

#define rep(i,b) for(i=0;i<b;++i)
#define repp(i,a,b) for(i=a;i<b;++i)

bool isPrime(ll n)
{
    // Corner case
    if (n <= 1)
        return false;

    // Check from 2 to n-1
    for (ll i = 2; i < n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int main() {
    ll n, cnt = 0;
    cin >> n;
    ll a = round(sqrt(n));
    while(n % a > 0){
        a--;
    }
    ll b= n/a;
    if(a == 1) cout << n -1;
    else cout << (a + b - 2);
  return 0;
}


Measured memory_bytes: 256
use std::io;
use std::collections::HashMap;


fn main() {
    let n = read_one::<usize>();
    let an = read::<usize>();
    let mut hm = HashMap::new();
    for a in an {
        *hm.entry(a).or_insert(0) += 1;
    }

    let mut cnt = n;
    let mut co = 0;
    let mut hm = hm.values().collect::<Vec<_>>();
    hm.sort();
    hm.reverse();
    for &v in hm {
        let mut x = v;
        if co > 0 && x >= 2 { co -= 1; x -= 1; }
        if x >= 3 {
            let t = (x - 1) / 2;
            // println!("t: {}", t);
            cnt -= t * 2; x -= t * 2;
        }
        if x == 2 { cnt -= 2; co += 1; }
    }
    println!("{}", cnt);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

Measured memory_bytes: 12540
#include<bits/stdc++.h>
using namespace std;
int main(){
  string a;
  cin>>a;
  int b;
  int count=0;
  b=a.size();
  for(int i=0;i<b/2;i++){
    if(a[i]!=a[b-i-1]){
      count++;
    }
  }
  cout<<count<<"\n";
  return(0);
}

Measured memory_bytes: 256
data1, data2 = [],[]
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data1.append(n) 
    except:
        break
while True:
    try:
        n,day = map(int, raw_input().split(","))
        data2.append(n)
    except:
        break
data = sorted(list(set(data1)))
for i in data:
    if data2.count(i) > 0:
        print i, data1.count(i)+data2.count(i)
        

Measured memory_bytes: 4220
#include<iostream>
#include<vector>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#include<deque>
#include<map>
#include<iomanip>

using namespace std;
using ll = long long;

#define rep(i, n) for(int i = 0;i < (n);i++)
#define repr(i, n) for(int i = (n);i >= 0;i--)
#define repf(i, m, n) for(int i = (m);i < (n);i++)

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;}
int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0};
//////////////////////////////////////////////////


int main() {
    int n;
    cin >> n;
    vector<double> p(n);
    rep(i, n) cin >> p[i];
    vector<vector<double>> dp(n+1, vector<double>(n+1, 0.0));
    dp[0][0] = 1.0;
    rep(i, n) dp[i+1][0] = dp[i][0] * (1 - p[i]);
    rep(i, n) {
        rep(j, i+1) {
            dp[i+1][j+1] = dp[i][j] * p[i] + dp[i][j+1] * (1 - p[i]);
        }
    }
    double ans = 0;
    for (int i = n; i >= (n + 1) / 2; --i) {
        ans += dp[n][i];
    }
    cout << setprecision(10) << ans << endl;
    return 0;
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define d double
#define INF INT_MAX
#define output for(int i=0;i<sizex;i++) { for(int j=0;j<sizey;j++) { cout << moveChart[i][j] << " "; }cout<<endl; }cout<<endl;

int n, m;
vector < vector<int> > adj(100001);
vector <int> emptyVector;
int dp[100001];

int solve( int idx ){

    // cout << idx << endl;

    if( dp[idx] != -1 ) return dp[idx];

    int res = 0;
    for(int i=0;i<adj[idx].size();i++) res = max( res, solve( adj[idx][i] ) );
    return dp[idx] = res+1;

}

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

    memset( dp, -1, sizeof dp );

    cin >> n >> m;
    adj.assign( n, emptyVector );

    int x, y;
    for(int i=0;i<m;i++){
        cin >> x >> y;
        x--; y--;
        adj[x].push_back( y );
    }

    int maxRes = 0;
    for(int i=0;i<n;i++){
        maxRes = max( maxRes, solve(i) );
        // cout << endl;
    }
    cout << maxRes-1 << endl;

}

Measured memory_bytes: 8192
#include "bits/stdc++.h"
using namespace std;
 
int main() {
 
	int n;
	cin >> n;
	
	int gen[n-1];
	for (int i=0; i<n-1; i++) cin >> gen[i];
	
	int x = 0;
	
	x += gen[0];
	for (int i=1; i<n-1; i++) {
		x += min(gen[i], gen[i-1]);
	}
	x += gen[n-2];
 
	cout << x << endl;
 
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>

template <class T>
inline void read(T &x) {
    x = 0;
    int f = 0;
    char ch = getchar();
    while (!isdigit(ch))    { f |= ch == '-'; ch = getchar(); }
    while (isdigit(ch))     { x = (x << 1) + (x << 3) + (ch ^ 48); ch = getchar(); }
    x = f ? -x : x;
    return;
}

typedef long long LL;

LL n, ans;

int main() {
    read(n);
    for (int i = 1; i <= n; ++i)    ans += i % 3 != 0 && i % 5 != 0 ? i : 0;
    printf("%lld\n", ans);
    return 0;
}

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

int main() {
    string S;
    cin >> S;
    string T = "CODEFESTIVAL2016";
    int ans;
    for (int i=0; i<16; i++) {
        if (S.at(i) != T.at(i)) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.math.*;
import java.io.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;

public class Main{
	Scanner sc=new Scanner(System.in);

	long INF=1L<<60;
	double EPS=1e-12;

	int n;
	int[] x;

	void run(){
		n=sc.nextInt();
		x=new int[n];
		for(int i=0; i<n; i++){
			x[i]=sc.nextInt();
		}
		solve();
	}

	void solve(){
		SegTree seg=new SegTree(n);
		for(int i=0; i<n; i++){
			seg.update(x[i], seg.query(0, x[i]+1)+x[i]);
		}
		println((long)n*(n+1)/2-seg.query(0, n+1)+"");
	}

	// root = 1
	// par(k) = k/2
	// left(k) = 2*k
	// right(k) = 2*k+1
	class SegTree{
		int n;

		long[] a;

		SegTree(int n){
			this.n=Integer.highestOneBit(n)<<1;
			a=new long[this.n*2];
		}

		void update(int k, long x){
			a[n+k]=x;
			for(int i=(n+k)>>1; i>0; i>>=1){
				a[i]=max(a[2*i], a[2*i+1]);
			}
		}

		// [s, t)
		long query(int s, int t){
			return query(s, t, 1, 0, n);
		}

		long query(int s, int t, int k, int l, int r){
			// debug(s,t,k,l,r);
			if(r<=s||l>=t){
				// 範囲外
				return -1;
			}else if(s<=l&&r<=t){
				// a[k]
				return a[k];
			}else{
				return max(query(s, t, k*2, l, (l+r)/2),
						query(s, t, k*2+1, (l+r)/2, r));
			}
		}
	}

	class Scanner{
		BufferedReader br;
		StringTokenizer st;

		Scanner(InputStream in){
			br=new BufferedReader(new InputStreamReader(in));
			eat("");
		}

		void eat(String s){
			st=new StringTokenizer(s);
		}

		String nextLine(){
			try{
				return br.readLine();
			}catch(IOException e){
				throw new IOError(e);
			}
		}

		boolean hasNext(){
			while(!st.hasMoreTokens()){
				String s=nextLine();
				if(s==null)
					return false;
				eat(s);
			}
			return true;
		}

		String next(){
			hasNext();
			return st.nextToken();
		}

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

	void debug(Object... os){
		System.err.println(Arrays.deepToString(os));
	}

	void print(String s){
		System.out.print(s);
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 15000
#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)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> par;

  UnionFind(int n) : par(n + 1, -1) { }

  int root(int x) {
    if (par[x] < 0) return x;
    else return par[x] = root(par[x]);
  }

  bool same(int x, int y) {
    return root(x) == root(y);
  }

  bool merge(int x, int y) {
    x = root(x); y = root(y);
    if (x == y) return false;

    if (par[x] > par[y]) swap(x, y);
    par[x] += par[y];
    par[y] = x;

    return true;
  }

  int size(int x) {
    return -par[root(x)];
  }
};

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

  int N,M; cin >> N >> M;

  UnionFind uf(N);

  rep(i, M) {
    int x,y,z; cin >> x >> y >> z;
    uf.merge(x,y);
  }

  set<int> G;
  rep(i, N) {
    G.insert(uf.root(i+1));
  }

  cout << G.size() << endl;
}

// x,y,z のうちzが奇数なら　x,yは偶数or奇数
// x,y,z のうちzが偶数なら　x,yは全て奇数or全て偶数


Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;long n,m,a,b,e[1<<17];vector<int>G[1<<17];int f(int u,int s=1){e[u]=1;for(int v:G[u])e[v]||(s+=f(v));return s;}main(){cin>>n>>m;for(;cin>>a>>b;G[a].push_back(b))G[b].push_back(a);a=min(f(1),f(2));cout<<n*~-n/2-a*(n-a)-m;}

Measured memory_bytes: 10624
import java.util.*;
public class Main{
	static String ChooseI(int p, int q, int r){
		int gcd = 1;
		int ph = Math.max(p, q);
		int qh = Math.min(p, q);
		for( ; ; ){
			gcd = ph % qh;
			if(gcd==0){
				gcd = qh;
				break;
			}
			if(qh%gcd==0)break;
			ph = qh;
			qh = gcd;
		}
		if(r%gcd==0)return "YES";
		else return"NO";
	}

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		System.out.println(ChooseI(a, b, c));
	}
}

Measured memory_bytes: 23636
a = []
b = []
n,m, l = gets.split.map(&:to_i)
n.times {a << gets.split.map(&:to_i)}
m.times {b << gets.split.map(&:to_i)}

n.times do |ni|
  l.times do |li|
    sum = 0
    m.times do |mi|
      sum += a[ni][mi] *b[mi][li]
    end
    print ' ' if li != 0
    print sum
  end
  puts
end

Measured memory_bytes: 9048
#include<bits/stdc++.h>
#define sz 200002
#define pb push_back
#define ff first
#define ln '\n'
#define ss second
#define ll long long
#define VEC vector<ll int>v
#define TEST() int test;cin>>test; while(test--)
#define FAST() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;

//ll int LCM(ll int a,ll int b) { ll int gcd=__gcd(a,b);ll int lcm=a*b/gcd;return lcm;}
//ll int bigmod(ll int b, ll int p, ll int m){if(p==0)return 1;if(p%2!=0) return b%m*fun(b,p-1,m)%m;if(p%2==0){ ll int res=fun(b,p/2,m);return (res%m*res%m)%m;}}
//void seive() { prime[np++]=2;for(i=3; i<=sz; i+=2){if(mark[i]==0){ prime[np++]=i;for(j=i*i; j<=sz; j+=i) mark[j]=1; } }}



int main()
{
    int n;
    cin>>n;
    cout<<(n+1)/2<<endl;

    return 0;
}


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

int main() {
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	if (a[0] == 5 && a[1] == 5 && a[2] == 7)cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
char s[N];
int num[3000];
int main(){
	num[0]=1;scanf("%s",s);
	long long ans=0;int l=strlen(s),now=0,d=1;
	for(int i=l-1;~i;i--){
		(now+=d*(s[i]-'0'))%=2019,(d*=10)%=2019;
		ans+=num[now]++;
	}
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 4024
#define _CRT_SECURE_NO_WARNINGS

#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <math.h>
#include <cmath>
#include <queue>
#include <stack>
#include <list>
#include <functional>
#include <numeric>
#include <iostream>
#include <string>
#include <time.h>

using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }

int N, A[23], x[23][23], y[23][23];

int main() {

	cin >> N;

	rep(i, N) {
		cin >> A[i];
		rep(j, A[i]) {
			cin >> x[i][j] >> y[i][j];
		}
	}

	int ans = 0;

	for (int b = 0; b < 1 << N; ++b) {
		bool able = true;
		rep(i, N) {
			if ((b >> i) & 1) {
				rep(j, A[i]) {
					if (y[i][j] == 1) {
						if (((b >> (x[i][j] - 1)) & 1) == 0) {
							able = false;
						}
					}
					else {
						if ((b >> (x[i][j] - 1)) & 1) {
							able = false;
						}
					}
				}
			}
		}
		if (able) {
			int c = 0;
			rep(i, N) {
				if ((b >> i) & 1) {
					c++;
				}
			}
			ans = max(ans, c);
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
<?php
  fscanf(STDIN,"%s",$s);
$re = "";
 for($i=0;$i<strlen($s);$i++){
   switch ($s[$i]) {
     case "0":
       $re .= "0";
       break;
     case "1":
       $re .= "1";
       break;
     case "B":
           

       if($re!=""){
         $re = substr($re, 0, -1);
        
       }
       break;
   }
 }



echo $re."\n";
 

Measured memory_bytes: 4728
#include <iostream>
#include <vector>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>

#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;


int main() {
    long long int X;
    scanf("%lld", &X);
    long long int i = 100;
    long long int year = 0;

    while (1) {
        year++;
        i = i * 1.010;
        if (i >= X) {
            printf("%lld", year);
            return 0;
        }

    }
}

Measured memory_bytes: 3816
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1LL << 61);
const int inf = 1001001001;
const int mod = 1000000007;

ll dp[105][100005];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, W;
	cin >> n >> W;
	vector<int> w(n), v(n);
	rep(i, n) cin >> w[i] >> v[i];
	rep(i, n)
		for (int j = 0; j <= W; ++j) {
			dp[i + 1][j] = dp[i][j];
				if (j - w[i] >= 0)
					dp[i + 1][j] = max(dp[i][j], dp[i][j - w[i]] + v[i]);
		}
	cout << dp[n][W] << endl;
	return 0;
}

Measured memory_bytes: 79360
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename TYPE>
void print_vec(const vector<TYPE>& v){
	for(int i=0; i<v.size(); i++){
		cout << v[i] << " ";
	}
	cout << endl;
}

template <typename TYPE>
void print_vec2(const vector<vector<TYPE>>& v){
  cout << endl; cout << "       ";
  for(int i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(int i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(int j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}



int main(){
	ll N, D;
	cin >> N >> D;

	vector<ll> X(N), Y(N);
	for(int i=0; i<N; i++) cin >> X[i] >> Y[i];


	ll ans = 0;
	for(int i=0; i<N; i++){
		if(X[i]*X[i] + Y[i] * Y[i]  <= D * D) ans++;
	}

	cout << ans << endl;

	return 0;
}



Measured memory_bytes: 6424
#include<bits/stdc++.h>;
using namespace std;
int main(){
int a[5];
for( int s = 0; s < 5; s++){
 cin >> a[s];
}
sort( a, a + 5, greater<int>());
for(int i = 0; i < 5; i++){
if( i < 4 ){
cout << a[i] << " ";
}else{
cout << a[i] << endl;
}
}
return 0;
}

Measured memory_bytes: 3156
#include <stdio.h>
int main(void){
    /* 変数宣言，ちゃんと初期化しよう */
    int A = 0;
    int B = 0;
    int ans = 0;
    /* 変数宣言終わり */
    
    /* 入力を受け付ける部分*/
    
    // %dはdecimalの略．つまり，入力を10進数として扱うよという意味．
    scanf("%d %d", &A, &B);
    
    /* 入力を受け付ける部分終わり*/
    
    
    /* 何か処理*/
    
    
    
    if(A == B){
      /* 真の場合の処理 */
      printf("Yes");
    }else{
      /* 偽の場合の処理 */
      printf("No");
    }
    
    for(int i = 0; i < 10; i++){ 
      // i = 0,1,2,3,4,5,6,7,8,9のとき処理される
      
    }
    
    /* 何か処理終わり*/
    
    
    /* 出力する部分*/
    
    // printf("%d", ans); // %dの部分にansの値が表示される
    
    /* 出力する部分*/
    
    
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define F first
#define S second
#define $ ios::sync_with_stdio(0);
#define endl '\n'
using namespace std;
using ll = long long int;
using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using graph = vector<vi>;
const int INF = 0x3f3f3f3f;
const ll INFL = 0x3f3f3f3f3f3f3f3f;
const int MAXN = 3123;
int dp[MAXN][MAXN];
int main() {$
    int n, m;
    string s, t;
    cin >> s >> t;
    n = s.size();
    m = t.size();
    s = '0'+s;
    t = '0'+t;
    for (int i = 1; i<=n; ++i) {
        for (int j = 1; j<=m; ++j) {
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if (s[i] == t[j]) dp[i][j] = max(dp[i][j], dp[i-1][j-1]+1);
        }
    }

    int i = n, j = m;
    string r = "";
    if (dp[i][j] == 0) {
        cout << "" << endl;
        return 0;
    }
    while (i > 0 && j > 0) {
        if (dp[i-1][j] == dp[i][j]) i--;
        else if (dp[i][j-1] == dp[i][j]) j--;
        else r+=s[i], i--, j--;
    }
    reverse(r.begin(), r.end());
    cout << r << endl;
}


Measured memory_bytes: 37120
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  for(int i=0;i<n;i++){
    int a;
    cin >> a;
    p[i]=a;
  }
  sort(p.begin(),p.end());
  int ans=0;
  for(int i=0;i<k;i++){
    ans = ans + p[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 3600
#include <cstdio>
#include <algorithm>
#include <map>
#include <utility>

using i8 = std::int8_t;
using u8 = std::uint8_t;
using i16 = std::int16_t;
using u16 = std::uint16_t;
using i32 = std::int32_t;
using u32 = std::uint32_t;
using i64 = std::int64_t;
using u64 = std::uint64_t;
using i128 = __int128_t;
using u128 = __uint128_t;
using usize = std::size_t;

using pair = std::pair<i64, i64>;

constexpr i64 MOD = 1000000007;

bool used[101];
auto main() -> i32 {
	i32 x, n;
	scanf("%d%d", &x, &n);
	for (i32 i = 0; i < n; ++i) {
		i32 p;
		scanf("%d", &p);
		used[p] = true;
	}
	for (i32 i = 0; true; ++i) {
		if (!(x - i >= 1 && x - i <= 100) || !used[x - i]) {
			printf("%d\n", x - i);
			break;
		}
		if (!(x + i >= 1 && x + i <= 100) || !used[x + i]) {
			printf("%d\n", x + i);
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 1676
#include <bits/stdc++.h>
#define int long long
#define endl '\n'
#define FOR(i, a, n) for (int i = (a); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
using namespace std;

int Q, N;

int next(int x) {
    string s = to_string(x);
    int res = 0;
    for (int i = 1; i < s.size(); ++i) {
        int a = stoll(s.substr(0, i));
        int b = stoll(s.substr(i, s.size() - i));
        res = max(res, a * b);
    }
    return res;
}

void solve() {
    cin >> N;
    set<int> st;
    int ans = 0;
    while (N >= 10) {
        if (st.count(N)) {
            ans = -1;
            break;
        }
        st.insert(N);
        N = next(N);
        ans++;
    }
    cout << ans << endl;
}

void _main() {
    cin >> Q;
    REP (i, Q) solve();
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


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

int D;
const int M = 26;
vector<int> C;
vector<vector<int>> S;
vector<int> T;

const int INF = 1<<30;

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

std::mt19937 mt{ std::random_device{}() };

int randint(int lower, int upper)
{
    std::uniform_int_distribution<int> dist(lower, upper);
    return dist(mt);
}

int calc_score(int N=D)
{
    int ans = 0;
    vector<int> last(M, -1);
    for(int i=0; i<N; i++)
    {
        ans += S[i][T[i]];
        last[T[i]] = i;
        for(int j=0; j<M; j++)
        {
            ans -= C[j] * (i - last[j]);
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> D;
    C.resize(M);
    for(int i=0; i<M; i++) cin >> C[i];
    S.resize(D);
    for(int i=0; i<D; i++)
    {
        S[i].resize(M);
        for(int j=0; j<M; j++)
        {
            cin >> S[i][j];
        }
    }

    T.resize(D);
    for(int i=0; i<D; i++)
    {
        int score = -INF;
        int idx = -1;
        for(int j=0; j<M; j++)
        {
            T[i] = j;
            int nscore = calc_score(i+1);
            if(chmax(score, nscore)) idx = j;
        }
        T[i] = idx;
    }
    for(int i=0; i<D; i++)
    {
        cout << T[i] + 1 << '\n';
    }
    return 0;
}


Measured memory_bytes: 3716
#include <bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define endl        '\n'
#define hell        1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>=b;i--)
#define int long long
#define sz(x) (int)x.size()
#define mp make_pair
#define fi first
#define se second
#define io ios_base::sync_with_stdio(false),cin.tie(NULL)
using namespace std;
#define INF 1e7

signed main()
{
	io;
	int n;
	cin >> n;
	int x[n],y[n];
	rep(i,0,n)
	{
		cin >> x[i]>>y[i];
	}
	int max1=INT_MIN,mini1=INT_MAX;
	int x1,y1,x2,y2;
	rep(i,0,n)
	{
		if(max1<x[i]+y[i])
		{
			max1 = x[i]+y[i];
			x1=x[i];
			y1=y[i];
		}
		if(mini1>x[i]+y[i])
		{
			mini1 = x[i]+y[i];
			x2=x[i];
			y2=y[i];
		}
	}
	int ans = abs(x1-x2)+abs(y1-y2);
	max1 = INT_MIN,mini1=INT_MAX;
	rep(i,0,n)
	{
		if(max1<x[i]-y[i])
		{
			max1 = x[i]-y[i];
			x1=x[i];
			y1=y[i];
		}
		if(mini1>x[i]-y[i])
		{
			mini1 = x[i]-y[i];
			x2=x[i];
			y2=y[i];
		}
	}
	ans = max(ans,abs(x1-x2)+abs(y1-y2));
	cout << ans <<endl;



}
 
	
		



Measured memory_bytes: 6776
#include <iostream>

using namespace std;

int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;

    int count = 0;
    for (int a = 0; a <= A * 500; a += 500) {
        if (a > X) {
            break;
        }
        for (int b = 0; b <= B * 100; b += 100) {
            if (a + b > X) {
                break;
            }
            for (int c = 0; c <= C * 50; c += 50) {
                int sum = a + b + c;
                if (sum >= X) {
                    if (sum == X) {
                        count++;
                    }
                    break;
                }
            }
        }
    }

    cout << count << endl;
    return 0;
}

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

int main(){
    int n;
    cin>>n;
    vector<string> w(n);
    for (int i = 0; i < n; ++i) {
        cin>>w[i];
    }
    for (int i = 1; i < n; ++i) {
        if(w[i-1][w[i-1].length()-1]!=w[i][0]){
            cout<<"No"<<endl;
            return 0;
        }
        for (int j = 0; j < i; ++j) {
            if(w[i]==w[j]){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<map>
#include<set>
#include<cstring>
#include<string>
#define pb push_back
#define mp make_pair
#define fir first
#define sec second
#define SZ(a) (int)((a).size())
using namespace std;
typedef long long ll;
typedef double db;
typedef pair <int, int> Pii;
typedef pair <ll, int> Pli;
typedef unsigned long long ull;
const double eps = 1e-8;
const ll infll = 0x7fffffffffffffff;
const int mod = (int)(1e9) + 7;
const int inf = 0x7fffffff;
const int maxn = (int)(2e5) + 7;
const int maxm = 300;

int N, M, Q, q[60][4], A[15] = { 1 }, res;
int check() {
	int ans = 0;
	for (int i = 1; i <= Q; i++) 
		if (A[q[i][1]] - A[q[i][0]] == q[i][2]) ans += q[i][3];
	return ans;
}
void dfs(int stp) {//step
	if (stp > N) {
		res = max(res, check());
		return;
	}
	for (int i = A[stp - 1]; i <= M; i++) {
		A[stp] = i;
		dfs(stp + 1);
		A[stp] = 0;
	}
}

int main() {
	
	scanf("%d%d%d", &N, &M, &Q);
	for (int i = 1; i <= Q; i++) 
		for (int j = 0; j < 4; j++) scanf("%d", &q[i][j]);
	dfs(1);
	printf("%d", res);

	return 0;
}		

Measured memory_bytes: 3220
#include <cmath>
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <bitset>
#include <algorithm>
#include <functional>
#include <utility>
#include <iomanip>

#define int long long int
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

typedef pair<int, int> P;

const int INF = 1e15;
const int MOD = 1e9+7;

signed main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];

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

    deque<int> d;
    int head = 0;
    int tail = n-1;
    int cnt = 1;
    d.push_back(a[head++]);
    while(cnt < n){
        d.push_front(a[tail--]);
        cnt++;
        if(cnt == n){
            break;
        }

        d.push_back(a[tail--]);
        cnt++;
        if(cnt == n){
            break;
        }

        d.push_front(a[head++]);
        cnt++;
        if(cnt == n){
            break;
        }

        d.push_back(a[head++]);
        cnt++;
    }

    int ans1 = 0;
    rep(i, n-1){
        ans1 += abs(d[i] - d[i+1]);
    }

    reverse(a.begin(), a.end());

    d = deque<int>();
    head = 0;
    tail = n-1;
    cnt = 1;
    d.push_back(a[head++]);
    while(cnt < n){
        d.push_front(a[tail--]);
        cnt++;
        if(cnt == n){
            break;
        }

        d.push_back(a[tail--]);
        cnt++;
        if(cnt == n){
            break;
        }

        d.push_front(a[head++]);
        cnt++;
        if(cnt == n){
            break;
        }

        d.push_back(a[head++]);
        cnt++;
    }
    int ans2 = 0;
    rep(i, n-1){
        ans2 += abs(d[i] - d[i+1]);
    }
    cout << max(ans1, ans2) << endl;

    return 0;
}


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

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

class Geometry:

    EPS = 10 ** -9

    def add(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return (x1+x2, y1+y2)

    def sub(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return (x1-x2, y1-y2)

    def mul(self, a, b):
        x1, y1 = a
        if not isinstance(b, tuple):
            return (x1*b, y1*b)
        x2, y2 = b 
        return (x1*x2, y1*y2)

    def norm(self, a):
        x, y = a
        return x**2 + y**2

    def dot(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return x1*x2 + y1*y2

    def cross(self, a, b):
        x1, y1 = a
        x2, y2 = b
        return x1*y2 - y1*x2

    def project(self, seg, p):
        """ 線分segに対する点pの射影 """
        p1, p2 = seg
        base = self.sub(p2, p1)
        r = self.dot(self.sub(p, p1), base) / self.norm(base)
        return self.add(p1, self.mul(base, r))

    def reflect(self, seg, p):
        """ 線分segを対称軸とした点pの線対称の点 """
        return self.add(p, self.mul(self.sub(self.project(seg, p), p), 2))

    def ccw(self, p0, p1, p2):
        """ 線分p0,p1から線分p0,p2への回転方向 """
        a = self.sub(p1, p0)
        b = self.sub(p2, p0)
        # 反時計回り
        if self.cross(a, b) > self.EPS: return 1
        # 時計回り
        if self.cross(a, b) < -self.EPS: return -1
        # 直線上(p2 => p0 => p1)
        if self.dot(a, b) < -self.EPS: return 2
        # 直線上(p0 => p1 => p2)
        if self.norm(a) < self.norm(b): return -2
        # 直線上(p0 => p2 => p1)
        return 0

    def intersect(self, seg1, seg2):
        """ 線分seg1と線分seg2の交差判定 """
        p1, p2 = seg1
        p3, p4 = seg2
        return (
            self.ccw(p1, p2, p3) * self.ccw(p1, p2, p4) <= 0
            and self.ccw(p3, p4, p1) * self.ccw(p3, p4, p2) <= 0
        )

gm = Geometry()
Q = INT()
for i in range(Q):
    x1, y1, x2, y2, x3, y3, x4, y4 = MAP()
    seg1 = ((x1, y1), (x2, y2))
    seg2 = ((x3, y3), (x4, y4))
    print(int(gm.intersect(seg1, seg2)))



Measured memory_bytes: 5764
#include<iostream>
#define M 1000000007L
long n,m,t,a;long f(long n){t=n;while(--n)t*=n,t%=M;return t;}
main(){std::cin>>n>>m;a=f(n)*f(m)%M;std::cout<<(abs(n-m)<2?n==m?a*2%M:a:0);}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE cout << -1 << endl;return 0
#define MM <<" "<<
#define Endl endl

signed main(void){
    //LからL+N-1
    int N,L;
    cin >> N >> L;
    int Sum=0;
    REP(i,N){
        Sum+=L+i;
    }
    int K=INF;
    REP(i,N){
        if(abs(K)>abs(L+i)){
            K=L+i;
        }
    }
    cout << Sum-K << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        String [] str = new String [a];
        for(int i=0;i<a;i++){str[i] = sc.next();
                            }
		Arrays.sort(str);
        int b = a;
        for(int i=1;i<a;i++){if(str[i].equals(str[i-1])){b--;
                                                 }
                            }        
		System.out.println(b);
	}
}


Measured memory_bytes: 70100
package main

import "fmt"

func pow(b, n int64) (bn int64) {
	bn = 1
	for n > 0 {
		bn *= b
		n--
	}
	return
}

func main() {
	mod := pow(10, 9) + 7

	var N int
	fmt.Scan(&N)

	var ans int64 = 1
	for i := 1; i <= N; i++ {
		ans = (ans * int64(i)) % mod
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
long long int hanshu(long long x,long long y)
{
    long long q,yu=1,j,k;
    j=x,k=y;
    if(x<y)
    {
        q=x;x=y;y=q;
    }
    while(yu)
    {
        yu=x%y;
        x=y;
        y=yu;
    }
    return j/x*k;
}
int main()
{
    long long s[105];
    int n,i;
    s[0]=1;
    scanf("%d",&n);
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&s[i]);
        s[i]=hanshu(s[i-1],s[i]);
    }
    printf("%lld\n",s[i-1]);
    return 0;
}


Measured memory_bytes: 128
n,m=map(int,input().split())
a=[list(map(int,input().split())) for i in range(m)]

l=10**(n-1)
if n==1:
    l=0
for i in range(l,10**n):
    s=str(i)
    for x,y in a:
        if s[x-1]!=str(y):
            break
    else:
        print(i)
        exit()
print(-1)


Measured memory_bytes: 3060
#include<stdio.h>
#define MAX 100005
#define NIL -1
struct Node_struct{int p, l, r;};
typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];
int H[MAX];
int deg[MAX];
int maxDepth = 0;

void print(int u, int root){
  int s;
  printf("node %d: parent = %d, ", u, T[u].p);
  if(u == root) s = -1;
  else if(T[T[u].p].l == u) s = T[T[u].p].r;
  else if(T[T[u].p].r == u) s = T[T[u].p].l;
  printf("sibling = %d, degree = %d, depth = %d, height = %d, ", s, deg[u], D[u], H[u]);
  
  if(T[u].p == NIL) printf("root\n");
  else if(T[u].l == NIL && T[u].r == NIL) printf("leaf\n");
  else printf("internal node\n");
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].l != NIL) calcDepth(T[u].l, p+1);
  if(T[u].r != NIL) calcDepth(T[u].r, p+1);
}

int calcHeight(int u){
  int h1 = 0, h2 = 0;
  if(T[u].l != NIL) h1 = calcHeight(T[u].l)+1;
  if(T[u].r != NIL) h2 = calcHeight(T[u].r)+1;
  return H[u] = (h1 > h2 ? h1: h2);
}

void calcDeg(int u){
  deg[u] = 0;
  if(T[u].l != NIL){
    deg[u]++;
    calcDeg(T[u].l);
  }
  if(T[u].r != NIL){
    deg[u]++;
    calcDeg(T[u].r);
  }
}

int main(){
  int i, id;
  int n;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;

  for(i=0; i<n; i++){
    scanf("%d", &id);
    scanf("%d %d", &T[id].l, &T[id].r);
    T[T[id].l].p = id;
    T[T[id].r].p = id;
  }

  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }

  calcDepth(root, 0);

  for(i = 0; i < n; i++){
    if(maxDepth < D[i]) maxDepth = D[i];
  }

  calcHeight(root);

  calcDeg(root);
  
  for(i=0; i<n; i++) print(i, root);

  return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
   
using namespace std;
#define ll long long
#define ld long double
#define pll pair<long long,long long>
#define vll vector<long long>
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define deb(x) cout << #x << "=" << x << endl
#define F(i,a,b) for(ll i=a;i<=b;i++)
#define RF(i,a,b) for(ll i=a;i>=b;i--)
#define in(a,n) F(i,0,n-1)cin>>a[i]
#define vi vector<int>
#define out(a,n) F(i,0,n-1)cout<<a[i]<<" ";cout<<endl
#define mod 1000000007
#define int long long
set < ll> primes;
 
int n,m;

bool isvalid(int x,int y)
{
    return (x>=0 && x<n && y>=0 && y<m);
}
int dx[]={0,0,1,-1,-1,1,1,-1};
int dy[]={1,-1,0,0,-1,1,-1,1};
void Sieve(ll n) 
{ 
    bool prime[n+1];
	for(ll i=0;i<n+1;++i)
		prime[i]=true;
    for (ll p=2;p*p<=n;++p) 
    {
        if (prime[p] == true) 
        {  
            for (ll i=2*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    }  
    for(ll p=2; p<=n; p++) 
       if (prime[p]) 
		primes.insert(p);  
}

ll gcd(ll a, ll b) 
{ 
    if (a == 0) 
        return b; 
        return gcd(b % a, a); 
} 
ll powermod(ll x, ll y){
    if(y==0)
    return 1;
        
    if(y%2==0)
    return (powermod(x,y/2)*powermod(x,y/2))%mod;
    else
    return (((powermod(x,y/2)*powermod(x,y/2))%mod)*x)%mod;
}

void solve()
{
    int n;
    cin>>n;
    
    int sum=0;
    map<int,int>m;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        sum+=x;
        
        m[x]++;
        
    }
    
    int q;
    cin>>q;
    while(q--)
    {
        int a,b;
        cin>>a>>b;
        
        int mi=m[a]*a;
        sum-=mi;
        int freq=m[a];
        sum+=m[a]*b;
        m.erase(a);
        m[b]+=freq;
        cout<<sum<<'\n';
    }
    
    
    
}
 
 

int32_t main()
{
	ios::sync_with_stdio(false);
    cin.tie(NULL);
    int t=1;
  //  cin>>t;
    while(t--)solve();
    
   
}

Measured memory_bytes: 7616
/*#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;*/
#include<algorithm>
#include <bits/stdc++.h>
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<ctype.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define S second
#define F first
#define vi vector<ll>
#define pii pair<ll,ll>
#define bc __builtin_popcountll
#define vvi vector<vi> 
#define vpii vector<pair<ll,ll>>
#define mll unordered_map<ll,ll>
#define INF LONG_LONG_MAX
#define NINF LONG_LONG_MIN
#define fo(i,a,b) for(i=a;i<=b;i++)
#define f(i,n) for(ll i=0;i<n;i++)
#define f1(i,n) for(ll i=1;i<=n;i++)
#define fb(i,n) for(ll i=n-1;i>=0;i--)
#define fb1(i,n) for(ll i=n;i>0;i--)
#define endd cout<<'\n';
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define clr(x) memset(x, -1.00, sizeof(x))
#define sortall(x) sort(all(x))
#define all(x) x.begin(), x.end()
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define CASES  ll t;cin>>t;while(t--)
typedef long long ll;
typedef unsigned long long ull;
//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;
//typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
//*X.find_by_order()-->returns an iterator to the k-th largest element (counting from zero)
//X.order_of_key()-->the number of items in a set that are strictly smaller than our item.
struct cmp
{
	bool operator() (ll a,ll b){
		return (a>b);
	}
};
ll ceil(const ll &a, const ll &b)
{
    if(a%b == 0)
        return a/b;
    return a/b +1;
}
ll mod=1000000007;
const ll N=305;
double dp[N][N][N];
double go(ll x,ll y,ll z,ll n)
{
    if(x<0 || y<0 || z<0)
        return 0;
    if(x==0 && y==0 && z==0)
        return 0;
    if(dp[x][y][z]>-1.00)
        return dp[x][y][z];
    double res=n+x*go(x-1,y,z,n)+y*go(x+1,y-1,z,n)+z*go(x,y+1,z-1,n);
    ll sum=x+y+z;
    return dp[x][y][z]=res/sum;
}
int main()
{
fast;
    ll n;
    cin>>n;
    ll a[n];
    f(i,n)
        cin>>a[i];
    clr(dp);
    ll x=0,y=0,z=0;
    f(i,n)
    {
        if(a[i]==1)
            x++;
        if(a[i]==2)
            y++;
        if(a[i]==3)
            z++;
    }
    double ans=go(x,y,z,n);
    cout<<fixed<<setprecision(10)<<ans;
    return 0;
}

Measured memory_bytes: 225528
def gcd(x, y):
    if x % y == 0:
        return y
    elif x >= y:
        return gcd(y, x%y)
    else:
        return 1

x, y = map(int, input().split())
if y > x:
    x, y = y, x
    
print(gcd(x, y))


    


Measured memory_bytes: 5600
#include<iostream>
 
using namespace std;
 
int main(){
  int A=0;
  int B=0;
  int C=0;
  int d=0;
  cin>>A>>B>>C;
  d=B/A;
  if(d>C){
    cout<<C;
  }
  else{
    cout<<d;
  }
 
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  int n, m;
  cin >> n >> m;
  vector<vector<int>> g(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  vector<int> ans(n, -1);
  vector<int> que;
  que.push_back(0);
  ans[0] = 0;
  for (int i = 0; i < (int) que.size(); i++) {
    int cur = que[i];
    for (int& nbr : g[cur]) {
      if (ans[nbr] != -1) continue;
      ans[nbr] = cur;
      que.push_back(nbr);
    }
  }
  cout << "Yes\n";
  for (int i = 1; i < n; i++) {
    cout << ans[i] + 1 << '\n';
  }
  return 0;
}

Measured memory_bytes: 10624
def exchange(hand,receive):
    if(hand[0]%2==1):
        hand[0]-=1
    hand[0]/=2
    receive[0]+=hand[0]

A=[0]
B=[0]
A[0],B[0],K=map(int,input().split())


for i in range(K):
    if(i%2==0):
        exchange(A,B)
    else:
        exchange(B,A)

print("{} {}".format(int(A[0]),int(B[0])))

Measured memory_bytes: 3064
class UnionFind:
    def __init__(self, n):
        self.n = n
        self.parent = [i for i in range(n)]  # 親
        self.rank = [1] * n  # 木の高さ
        self.size = [1] * n  # size[i] は i を根とするグループのサイズ

    def find(self, x):  # x の根を返す
        if self.parent[x] == x:
            return x
        else:
            self.parent[x] = self.find(self.parent[x])  # 経路圧縮
            return self.parent[x]

    def unite(self, x, y):  # x, y の属する集合を併合する
        x = self.find(x)
        y = self.find(y)
        if x != y:
            if self.rank[x] < self.rank[y]:
                self.parent[x] = y
                self.size[y] += self.size[x]
            else:
                self.parent[y] = x
                self.size[x] += self.size[y]
                if self.rank[x] == self.rank[y]:
                    self.rank[x] += 1

    def is_same(self, x, y):  # x, y が同じ集合に属するか判定する
        return self.find(x) == self.find(y)

    def group_size(self, x):  # x が属する集合の大きさを返す
        return self.size[self.find(x)]


N, M = map(int, input().split())
A, B = [0] * M, [0] * M  # 入力時に 0-index に合わせる

direct =[[] for _ in range(N)]  # 同じ集合の友達もしくはブロック関係の人
uf = UnionFind(N)  # 友達関係をまとめた UnionFind 木

for i in range(M):
    A[i], B[i] = map(int, input().split())
    A[i] -= 1
    B[i] -= 1
    direct[A[i]].append(B[i])
    direct[B[i]].append(A[i])
    uf.unite(A[i], B[i])

ans = [0] * N
for i in range(N):
    ans[i] = uf.group_size(i)
print(max(ans))

Measured memory_bytes: 113696
import sys

sys.setrecursionlimit(10 ** 7)
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    N = int(input())

    for h in range(1, 3501):
        for n in range(1, 3501):
            if 4 * h * n - N * n - N * h > 0:
                w = (N * h * n) / (4 * h * n - N * n - N * h)
                if w.is_integer() and w > 0 and 4 * h * n * w == N * n * w + N * h * w + N * h * n:
                    print(h, n, int(w))
                    exit()


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 3060
n = int(input())

cnt = [0] * (n+1)

for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            val = x ** 2 + y ** 2 + z ** 2 + x * y + y * z + z * x
            if val > n:
                continue
            cnt[val] += 1

for i in range(1, n+1):
    print(cnt[i])


Measured memory_bytes: 69032