akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll n,k;
    cin>>n>>k;
    ll ar[n+1] = {0};
    while(k--)
    {
        ll d;
        cin>>d;
        while(d--)
        {
            ll x;
            cin>>x;
            ar[x] = 1;
        }
    }
    ll ans = 0;
    for(int i=1;i<=n;i++)
    {
        if(ar[i]==0)
        {
            ans++;
        }
    }
    cout<<ans<<endl;



    return 0;
}





Measured memory_bytes: 3624
#include<iostream>

using namespace std;

void call(int n){
    for (int i = 1;i <= n; i++) {
        int x = i;
        if (x %  3 == 0) {
            cout << " " << i;
            continue;
        }   
        while (x) {
            if (x % 10 == 3) {
                cout << " " << i;
                break;
            }
            x /= 10;
        }
    }
    cout << endl;
}

int main() {
    int n;
    cin >> n;
    call(n);
    return 0;
}

Measured memory_bytes: 1164
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<long long> vll;

int main(void)
{
    ll N;
    ll sum=0;
    cin>>N;
    for (ll i=1; i<=N; i++)
    {
        if (i%15 == 0)
        {
            //printf ("FizzBuzz\t");
            sum=sum;
        }

        else if ((i%3) == 0)
            {
                //printf("Fizz\t");
                sum=sum;
            }
        else if ((i%5) == 0)
        {
           // printf("Buzz\t");
           sum=sum;
        }

        else
            {
                sum+=i;

            }

    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define M 1000000007
#define U 998244353
#define N 1000005
#define int long long
#define sz(c) (int)c.size()
#define fr first
#define ll long long 
#define sc second
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define rep(i,a,n) for(int i=a ; i<n ; i++)
#define r0 return 0;
#define endl '\n'
#define INF (int)1e15
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	std::cerr << name << " : " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');std::cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#define PI acos(-1)
signed main()
{
	ios_base::sync_with_stdio(0);
	int TESTS=1;
	// cin>>TESTS;
	while(TESTS--)
	{   
		int r;
		cin >> r;
		cout << fixed << setprecision(10) << 2*PI*r;
	}
}

Measured memory_bytes: 3800
#include <iostream>
#include <string>

using namespace std;

int main(){
    string w, t;
    int count = 0;
    cin >> w;
    for(int i = 0; i < w.size(); ++i){
        if(isupper(w[i])){
            w[i] = tolower(w[i]);
        }
    }
    
    while(1){
        cin >> t;
        
        if (t == "END_OF_TEXT"){
            break;
        }
        
        for(int j = 0; j < t.size(); ++j){
            if(isupper(t[j])){
                t[j] = tolower(t[j]);
            }
        }
        
        if(t==w){
            count = count + 1;
        }
    }
    
    cout << count << endl;
    return 0;
}



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

int main(){
  long long n,k,nans=0,now,nm,step;
  cin>>n>>k;
  long long p[n],c[n],ans[n];
  for(int i=0;i<n;i++) cin>>p[i];
  for(int i=0;i<n;i++) cin>>c[i];
  vector<int> m(n*n,0);
  
  for(int i=0;i<n;i++) {
    nans=0;
    now=i+1;
    nm=c[p[now-1]-1];
    step=10000;
    for(int j=0;j<k;j++){
   		now=p[now-1];
        if(m[i*n+now-1]==0){
        nans+=c[now-1];
        nm=max(nm,nans);
        m[i*n+now-1]=1;
        }else{
        	step=j;
            break;
        }
    } 
    if(nans<=0||k<step) ans[i]=nm;
    else{
    	long long s=(k/step)-1;
        long long t=s*nans;
        ans[i]=t;
        now=i+1;
        for(long long j=s*step;j<k;j++){
          now=p[now-1];
          ans[i]=max(ans[i],t+c[now-1]);
          t+=c[now-1];
        }
    }
    
  }
  long long answ=ans[0];
  for(int i=1;i<n;i++){
  	answ=max(answ,ans[i]);
  }
  cout<<answ;
}

Measured memory_bytes: 100932
((stdin) => {
	const [k, a, b] = stdin.split(/\s/g);
	for (let i = +a; i <= +b; i++) {
		if (i % +k === 0) {
			console.log('OK');
			return;
		}
	}
	console.log('NG');
})(require('fs').readFileSync('/dev/stdin', 'UTF-8'));


Measured memory_bytes: 29492
N,W=map(int,input().split())
w,v=[],[]
for i in range(N):
  a,b=map(int,input().split())
  w.append(a)
  v.append(b)
dp=[[0]*(W+1) for i in range(N+1)]
for i in range(N):
  for j in range(W+1):
      if j-w[i]>=0:
          dp[i+1][j]=dp[i][j-w[i]]+v[i]
      dp[i+1][j]=max(dp[i+1][j],dp[i][j])
print(dp[N][W])

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

int main () {
    int N, K;
    int l[N];
    cin >> N >> K;
    for (int i = 0; i < N; i++) cin >> l[i];

    sort(l, l + N, greater<int>()); 

    int length = 0;
    for (int i = 0; i < K; i++) {
        length += l[i];
    }

    cout << length << endl;
}

Measured memory_bytes: 256
import std.ascii;
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

void main() {
    int[char] m;
    string s;
    while ((s = readln.chomp).length > 0) {
        foreach (c; s.filter!isAlpha) {
            auto d = cast(char)std.ascii.toLower(c);
            m[d]++;
        }
    }

    foreach (c; lowercase) {
        writefln("%s : %s", c, m.get(c, 0));
    }
}



Measured memory_bytes: 2520
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)
	res := 0
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		if i%2 == 0 && a%2 == 1 {
			res++
		}
	}
	fmt.Printf("%d\n", res)
}


Measured memory_bytes: 1836
import itertools

N,M = map(int, input().split())
S = [list(map(int, input().split()))[1:] for _ in range(M)]
P = list(map(int, input().split()))

switch = range(1,N+1)
pattern = [()]
for i in range(1,N+1):
    pattern.extend(tuple(itertools.combinations(switch, i)))
count = 0
for swp in pattern:
    for p, s in zip(P,S):
        match = len(set(s) & set(swp))
        if match % 2 != p:
            break
    else:
        count += 1
print(count)

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

int main(){
  string s;
  char result[10];

  cin >> s;

  int cnt = 0;
  for (auto ch : s){
    switch(ch){
    case '0':
    case '1':
      result[cnt] = ch;
      cnt++;
      break;
    case 'B':
      if(cnt > 0){
	cnt--;
      }
      break;
    default:
      break;
    }
  }
  result[cnt] = '\0';

  cout << result << "\n";
  
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <map>
#include <algorithm>
#include <sstream>

using namespace std;

int main()
{
    string str;
    int n;
    cin >> str;
    cin >> n;

    string cmd;
    int a, b;
    string p;
    stringstream prints;
    while (n--)
    {
        cin >> cmd >> a >> b;

        if(cmd == "print")
            prints << str.substr(a, b-a+1) << endl;
        if(cmd == "reverse")
            reverse(&str[a], &str[b]+1);
        if(cmd == "replace"){
            cin >> p;
            str.replace(a, b-a+1, p);
        }

    }

    cout << prints.str();
}


Measured memory_bytes: 3196
program main
	implicit none
    integer n,i
    double precision,allocatable::v(:)
    double precision ans
    read *,n
    allocate(v(n))
    read *,(v(i),i=1,n)
    call quicksort(v,1,n)
    ans=v(1)
    do i=2,n
    	ans=(ans+v(i))/2
    end do
    print '(f0.12)',ans
contains
recursive subroutine quicksort(a, first, last)
  implicit none
  real*8  a(*)
  integer first, last
  integer i, j
  real*8  x, t
 
  x = a( (first+last) / 2 )
  i = first
  j = last
  do
     do while (a(i) < x)
        i=i+1
     end do
     do while (x < a(j))
        j=j-1
     end do
     if (i >= j) exit
     t = a(i);  a(i) = a(j);  a(j) = t
     i=i+1
     j=j-1
  end do
  if (first < i - 1) call quicksort(a, first, i - 1)
  if (j + 1 < last)  call quicksort(a, j + 1, last)
end subroutine quicksort
end program main

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

int main()
{
	int H, W, h, w;
	cin >> H >> W >> h >> w;
	if (W % w) {
		cout << "Yes" << endl;
		vector<int> val(w);
		val[0] = -1 - W / w;
		val[W % w] = -val[0] + 1;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << -val[j % w] << " \n"[j == W - 1];
			}
		}
	}
	else if (H % h) {
		cout << "Yes" << endl;
		vector<int> val(h);
		val[0] = -1 - H / h;
		val[H % h] = -val[0] + 1;
		for (int i = 0; i < H; i++) {
			for (int j = 0; j < W; j++) {
				cout << -val[i % h] << " \n"[j == W - 1];
			}
		}
	}
	else {
		cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

template<class Abel> struct UnionFind {
    vector<int> par;
    vector<int> rank;
    vector<Abel> diff_weight;

    UnionFind(int n = 1, Abel SUM_UNITY = 0) {
        init(n, SUM_UNITY);
    }

    void init(int n = 1, Abel SUM_UNITY = 0) {
        par.resize(n); rank.resize(n); diff_weight.resize(n);
        for (int i = 0; i < n; ++i) par[i] = i, rank[i] = 0, diff_weight[i] = SUM_UNITY;
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        }
        else {
            int r = root(par[x]);
            diff_weight[x] += diff_weight[par[x]];
            return par[x] = r;
        }
    }

    Abel weight(int x) {
        root(x);
        return diff_weight[x];
    }

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

    bool merge(int x, int y, Abel w) {
        w += weight(x); w -= weight(y);
        x = root(x); y = root(y);
        if (x == y) return false;
        if (rank[x] < rank[y]) swap(x, y), w = -w;
        if (rank[x] == rank[y]) ++rank[x];
        par[y] = x;
        diff_weight[y] = w;
        return true;
    }

    Abel diff(int x, int y) {
        return weight(y) - weight(x);
    }
};

int main(){
    int n; cin >> n;
    UnionFind<int> uf(n);

    int q; cin >> q;
    rep(i,q){
        int q_; cin >> q_;
        if(q_ == 0){
            int x, y, z; cin >> x >> y >> z;
            uf.merge(x, y, z);
        }else{
            int x, y; cin >> x >> y;
            if(uf.issame(x, y)){
                cout << uf.diff(x, y) << endl;
            }else{
                cout << '?' << endl;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 3860
/*

░█▀▀▄ ▀█▀ ░█▄─░█ ░█▀▀▀ ░█▀▀▀█ ░█─░█ 
░█─░█ ░█─ ░█░█░█ ░█▀▀▀ ─▀▀▀▄▄ ░█▀▀█ 
░█▄▄▀ ▄█▄ ░█──▀█ ░█▄▄▄ ░█▄▄▄█ ░█─░█

*/
 
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define pf push_front
#define mp make_pair
#define mod 1000000007
#define f(i,a,b) for(ll i=a;i<b;++i)
#define fr(i,a,b) for(ll i=a;i>=b;--i)
#define fa(i,a,b) for(auto i=a;i!=b;++i)
#define beg begin()
#define end end()
#define vi vector<int>
#define vl vector<long long>
#define pi pair<int,int>
#define pl pair<long long,long long>
#define fi first
#define se second
#define fastio ios_base::sync_with_stdio(false)

 
int main()
{
    fastio;
    cin.tie(NULL);
    ll t;
    ll n;
    cin>>n;
    ll rem;
    rem=n%1000;
    if(rem!=0)
        cout<<1000-rem<<endl;
    else
        cout<<0<<endl;
    return 0;
}
         

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

int main(){
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    int ans = min(A,K);
    K -= A;
    if(K > 0) K -= B;
    if(K > 0) ans -= min(K,C);

    cout << ans << endl;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,a,b)  for(ll i=a;i<b;i++)
#define nl cout<<endl

#define pii pair<ll,ll>
#define vi  vector<ll>
#define vii vector<pii>
#define mi  map<ll,ll>
#define all(a)  (a).begin(),(a).end()

#define pb push_back
#define ff first
#define ss second
#define hell 1000000007

#define test4(x,y,z,a) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<"		a is "<<a<<endl;
#define test3(x,y,z) cout<<"x is "<<x<<"		y is "<<y<<"		z is "<<z<<endl;
#define test2(x,y) cout<<"x is "<<x<<"		y is "<<y<<endl;
#define test1(x) cout<<"x is "<<x<<endl;
#define N 300009

ll power(ll a,ll b,ll m)
{
	ll ans=1;
	while(b)
	{
		if(b&1)
			ans=(ans*a)%m;
		b/=2;
		a=(a*a)%m;
	}
	return ans;
}
stack<ll>st;
vi v[N];
bool vis[N]={0};
void topo(ll num)
{
	vis[num]=1;
	for(auto it:v[num])
	{
		if(vis[it])
			continue;
		topo(it);
	}
	st.push(num);
}
int main()
{	
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
        
	ll n,m;cin>>n>>m;
	rep(i,1,m+1)
	{
		ll l,r;cin>>l>>r;
		v[l].pb(r);
	}
	rep(i,1,n+1)
	{
		if(vis[i])
			continue;
		topo(i);
	}

	vi vv;
	while(!st.empty())
	{
		//test1(st.top());
		vv.pb(st.top());
		st.pop();
	}//nl;

	ll dp[n+2];
	rep(i,1,n+1)
		dp[i]=0;
	for(auto it:vv)
	{
		for(auto it2:v[it])
			if(dp[it2]<dp[it]+1)
				{
					dp[it2]=dp[it]+1;
					//test2(it2,dp[it2]);
				}
	}
	ll ans=0;
	rep(i,1,n+1)
		ans=max(ans,dp[i]);
	cout<<ans<<endl;
}

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

using namespace std;

using ll = long long;
constexpr int mo = 1e9+7;
constexpr int inf = 1<<30;
constexpr ll infl = 1ll<<60;


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

    int n;
    cin>>n;
    map<string,int> m;
    for(int i=0;i<n;++i){
        string s;
        cin>>s;
        m[s]++;
    }
    int ma = 1;
    for(auto a : m){
        if(a.second > ma) ma = a.second;
    }
    for(auto a : m)if(a.second == ma)cout << a.first << endl;
    return 0;
}

Measured memory_bytes: 23808
if __name__ == '__main__':
    n,k = [int(x) for x in input().split()]

    ans = 0
    for i in range(1,k//2+1):
        a=i
        b=k-i
        if (a+a)%k == 0:
            ans += ((n-a)//k+1)*((n-b)//k+1)*((n-a)//k+1)
        if a==b:
            continue
        if (b+b)%k == 0:
            ans += ((n-a)//k+1)*((n-b)//k+1)*((n-b)//k+1)
    ans += (n//k)*(n//k)*(n//k)
    print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
//#include <boost/multiprecision/cpp_int.hpp>
//using multiInt = boost::multiprecision::cpp_int;

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

const int MOD_TYPE = 1;
const ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
const int INF = (int)1e9;
const ll LINF = (ll)4e18;
const ld PI = acos(-1.0);
const ld EPS = 1e-11;

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << endl
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << endl
#define possible(n) cout << ((n) ? "possible" : "impossible") << endl
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << endl
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << endl;

vector<int> Dx = {0, 0, -1, 1, -1, 1, -1, 1, 0};
vector<int> Dy = {1, -1, 0, 0, -1, -1, 1, 1, 0};

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

  ll x;
  cin >> x;
  ll ans = 0;
  while (x >= 500)
  {
    ans += 1000;
    x -= 500;
  }
  while (x >= 5)
  {
    ans += 5;
    x -= 5;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){

  string a;

  cin >> a;

  for (int i=0; i<a.size(); i++){
    if ( a.at(i) == '9') {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  
  return 0;
}

    


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

#define MX 105
int A[MX], B[MX];

int main()
{
    int n;
    cin>>n;
    for(int i = 0; i < n-1; i++)cin>>B[i];
    A[0] = A[1] = B[0];
    for(int i = 1; i < n-1; i++)
    {
        if( B[i] < A[i] )A[i] = B[i];
        A[i+1] = B[i];
    }
    int ans = 0;
    for(int i = 0; i < n; i++)ans += A[i];
    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define RFOR(i,a,b) for(int i = (b-1);i>=(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;

signed main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n,k;
  cin >> n >> k;
  vector<int> h(n);
  REP(i,n) cin >> h[i];
  sort(h.begin(),h.end());
  int out = 0;
  RREP(i,n){
    if(h[i] < k) break;
    else out++;
  }
  cout << out << endl;
  return 0;
}

Measured memory_bytes: 1024
import sys
from collections import deque, defaultdict
import heapq

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M = lr()
A = lr()

# Aでxの根を求める
def find(A,x):
    p = A[x]
    if p == x:
        return x
    a = find(A,p)
    A[x] = a
    return a

# Aでxとyの属する集合の併合
def union(A, x, y):
    if find(A,x) > find(A,y):
        bx, by = find(A,y), find(A,x)
    else:
        bx, by = find(A,x), find(A,y)
    # 根をbxに統一
    A[by] = bx

edges = [[] for _ in range(N)]
V = [i for i in range(N)]
for _ in range(M):
    x, y = lr()
    if find(V, x) != find(V, y):
        union(V, x, y)
    edges[x].append(y)
    edges[y].append(x)

for i in range(N):
    V[i] = find(V, i)

if M == N - 1:
    print(0); exit()
elif N < 2 * (N-M-1):
    print('Impossible'); exit()

root_point = defaultdict(list)
for i in range(N):
    r = V[i]
    heapq.heappush(root_point[r], A[i])

#各グループの最小値以外で使うコストの数
answer = 0
candidates = []
for p_list in root_point:
    answer += heapq.heappop(root_point[p_list])
    candidates.extend(root_point[p_list])

remain = 2 * (N-M-1) - len(set(V))
candidates.sort()
answer += sum(candidates[:remain])
print(answer)


Measured memory_bytes: 121920
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}
//最小公倍数
ll lcm(ll a, ll b) {
    return a / gcd(a, b) * b;
}
bool isPrime(ll x){
    ll i;
    if(x < 2)return 0;
    else if(x == 2) return 1;
    if(x%2 == 0) return 0;
    for(i = 3; i*i <= x; i += 2) if(x%i == 0) return 0;
    return 1;
}

int strsum(const int n){
    string s = to_string(n);
    int b(0);
    rep(i,s.size()){
        b += s[i]-'0';
    }
    return b;
}

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

    for(int i=a;i<=b;i++){
        int x=i;
        if(x%k==0){
            puts("OK");
            return 0;
        }
    }
    puts("NG");

    return 0;
}

Measured memory_bytes: 3624
#include <iostream>

using namespace std;

int main(){
  int i;
  int h;
  int H, N;
  
  cin >> H >> N;

  int* A = new int[N];
  int* B = new int[N];
  long int* minMpH = new long int[H+1];

  for(i = 0; i < N; i++){
    cin >> A[i] >> B[i];
  }
  
  minMpH[0] = 0;
  
  for(i = 1; i <= H; i++){
    minMpH[i] = 1000000000;
  }
  
  for(h = 1; h <= H; h++){
    for(i = 0; i < N; i++){
      if(h - A[i] <= 0){
        if(minMpH[h] > B[i]){
          minMpH[h] = B[i];
        }
      }
      else{
        if(minMpH[h] > minMpH[h-A[i]] + B[i]){
          minMpH[h] = minMpH[h-A[i]] + B[i];
        }
      }
    }
  }

  cout << minMpH[H] << endl;
  
  return 0;
}

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

int main() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int ans = 0;
    for(int i = 0; i < n; i++){
        if(s[i] != t[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
  
  while(true){
    int H, W;
    cin >> H >> W;
    if(H == 0 && W == 0){
      break;
    }else{
      for(int i = 0; i < H; i++){
        if(i == 0 || i % 2 == 0){
          for(int j = 0; j < W; j++){
            if(j == 0 || j % 2 == 0){
              cout << "#";
            }else{
              cout << ".";
            }
            if(j == W-1){
              cout << endl;
            }
          }
        }else{
          for(int j = 0; j < W; j++){
            if(j % 2 != 0){
              cout << "#";
            }else{
              cout << ".";
            }
            if(j == W-1){
              cout << endl;
          }
        }

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


Measured memory_bytes: 3088
#include <iostream>
#include <stdio.h>
#include <string>
using namespace std;
int main(void){
    // Your code here!
    int a,b,x;
    string o;
    while(1){
        cin>>a>>o>>b;
        x=0;
        if(o=="?"){
            break;
        }else if(o=="+"){
            x=a+b;
        }else if(o=="-"){
            x=a-b;
        }else if(o=="*"){
            x=a*b;
        }else if(o=="/"){
            x=a/b;
        }
        
        cout<<x<<endl;
        
    }
    return 0;
}



Measured memory_bytes: 3104
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main() {
    int N, M;   cin >> N;
    string *s = new string[N];
    map<string, int> red, blue;
    for (int i = 0; i < N; i++) {
        cin >> s[i];
        blue[s[i]]++;
    }
    cin >> M;
    for (int i = 0; i < M; i++) {
        string w;   cin >> w;
        red[w]++;
    }

    int ans = 0;
    for (int i = 0; i < N; i++) {
        ans = max(ans, blue[s[i]]-red[s[i]]);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
bool c(int x, int M, vector<int> &a)
{
    int N = a.size();
    int cnt = 0, sum = 0;
    for (int i = 0; i < N; ) {
        if (a[i] > x) return 0;
 
        while (i < N && sum < x) {
            sum += a[i++];            
        }
        if (sum > x) {
            i--;
        }                 
        cnt++;
        sum = 0;
    }
    return (cnt <= M);
}
 
int main()
{
    int M, N;
    while (cin >> M >> N, M) {
        vector<int> a(N);
        for (int i = 0; i < N; i++) {
            cin >> a[i];
        }
        int l = 0, r = 1e9;
        while (r - l > 1) {
            int mid = (l + r) / 2;
            if (c(mid, M, a)) {
                r = mid;
            } else {
                l = mid;
            }
        }
        cout << r << endl;
    }
    return 0;
}

Measured memory_bytes: 1196
using System;
using System.Collections;
using System.Collections.Generic;
using System.Text;
using System.Linq;
using static MyIO;


public class A
{
    public static void Main()
    {
        int n = GetInt();
        int k = GetInt();
        int x = GetInt();
        int y = GetInt();
        int ans = 0;
        for (int i = 1; i <= n; i++)
        {
            if (k < i)
            {
                ans += y;
            }
            else
            {
                ans += x;
            }
        }
        Console.WriteLine(ans);
    }
}

public static class MyIO
{
    private static string[] args = null;
    private static int num = -1;
    private static int used = -1;

    private static string getArg()
    {
        if (used == num)
        {
            args = Console.ReadLine().Split(' ');
            num = args.Length;
            used = 0;
        }
        return args[used++];
    }

    public static int GetInt() { return int.Parse(getArg()); }
    public static long GetLong() { return long.Parse(getArg()); }
    public static double GetDouble() { return double.Parse(getArg()); }
    public static string GetString() { return getArg(); }
}


Measured memory_bytes: 13140
#include <cstdio>
#include <algorithm>
#include <climits>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <set>

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

using namespace std;

int main() {
    int N;
    int A[100002];
    scanf("%d", &N);
    REP(i, N){
        scanf(" %d", &A[i+1]);
    }
    A[0] = 0;
    A[N+1] = 0;
    int sum = 0;
    REP(i, N+1){
        sum += abs(A[i+1]-A[i]);
    }
    int B[100002];
    REP(i, N){
        if(A[i+1]>A[i] && A[i+1]>A[i+2]){
            B[i] = sum - min(abs(A[i+1]-A[i]), abs(A[i+1]-A[i+2])) * 2;
        } else if (A[i+1]<A[i] && A[i+1]<A[i+2]){
            B[i] = sum - min(abs(A[i+1]-A[i]), abs(A[i+1]-A[i+2])) * 2;
        } else {
            B[i] = sum;
        }
        //if(A[i+1]>=A[i] && A[i+1]<=A[i+2]) {
        //    B[i] = sum;
    }
    REP(i, N){
        i==N-1 ? printf("%d\n", B[i]) : printf("%d ", B[i]);
    }
    return 0;
}

Measured memory_bytes: 1920
# include<bits/stdc++.h>
using namespace std;
int m,n,a[1000][1000],b[1000],ans;
map<int ,int >mp;
map<int,bool>mp1;

int main()
{   cin>>n>>m;
    for(int i=0;i<n;i++){
        cin>>b[i];
        for(int j=0;j<b[i];j++){
            cin>>a[i][j];
            mp[a[i][j]]++;
        }

    }
    for(int i=0;i<n;i++){
        for(int j=0;j<b[i];j++){
            if(mp[a[i][j]]==n&&!mp1[a[i][j]])ans++,mp1[a[i][j]]=true;
        }

    }
    cout<<ans;
    return 0;
}



Measured memory_bytes: 384
#include <stdio.h>

int main(void){
	
	int n,m,x,a[100];
	int cost_1=0;
	int cost_2=0;
	
	scanf("%d%d%d",&n,&m,&x);
	
	for(int i=0;i<m;i++){
		scanf("%d",&(a[i]));
	}
	
	int y=x;
	
	while(y!=n){
		for(int j=0;j<m;j++){
			if(y==a[j]){
				cost_1++;
			}
		}
		y++;
	}
	
	y=x;
	
	while(y!=0){
		for(int k=0;k<m;k++){
			if(y==a[k]){
				cost_2++;
			}
		}
		y--;
	}
		
	if(cost_1<cost_2){
		printf("%d\n",cost_1);
	}else{
		printf("%d\n",cost_2);
	}
	
	return 0;
}
			
		
		

Measured memory_bytes: 128
from sys import stdin, stdout

INF = float('inf')
n = int(stdin.readline())
dp = [[-INF for j in range(3)] for i in range(n)]
price = []

for i in range(n):
    price.append(list(map(int, stdin.readline().split())))

dp[0] = price[0]

for i in range(1, n):
    for j in range(3):
        dp[i][j] = max(dp[i - 1][j - 1], dp[i - 1][j - 2]) + price[i][j]

stdout.write(str(max(dp[n - 1])))

Measured memory_bytes: 80220
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Comparator;


public class Main {
	private	static	BufferedReader	br   = null;
	private	static	int[][]			freq = null;

	static {
		br   = new BufferedReader(new InputStreamReader(System.in));
		freq = new int[100][2];
	}

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		String	strIn = null;

		for (int n = 0; n < 100; n++) {
			freq[n][0] = n + 1;
		}

		while((strIn = parseStdin()) != null) {
			freq[Integer.parseInt(strIn) - 1][1]++;
		}

		Arrays.sort(freq, new TheComparator());

		for (int n = 0; n < 100; n++) {
			if (n > 0 && freq[n-1][1] != freq[n][1]) {
				break;
			}
			System.out.println(freq[n][0]);
		}
	}

	private static String parseStdin() {
		String	strNum = null;

		try {
			String line = br.readLine();
			if (line != null) {
				if (!line.isEmpty()) {
					strNum = line;
				}
			}
		}
		catch (IOException e) {}

		return strNum;
	}
}

class TheComparator implements Comparator<int[]> {

    /** ソート対象のカラムの位置 */
    public int compare( int[] freq1, int[] freq2 ) {
        return (freq1[1] != freq2[1]) ? freq2[1] - freq1[1] : freq1[0] - freq2[0];
    }
}

Measured memory_bytes: 16876
a, b, c, k = map(int, input().split())
res=0

if not a==0:
    if a<k:
        res+=a
        k-=a
    elif a==k:
        print(a)
        exit()
    else:
        print(k)
        exit()
if not b==0:
    if b<k:
        k-=b
    elif b==k:
        print(res)
        exit()
    else:
        print(res)
        exit()
if not c==0:
    if c<k:
        print(res-c)
        exit()
    elif c==0:
        print(res-c)
        exit()
    else:
        print(res-k)
        exit()
else:
    print(res)
    exit()

Measured memory_bytes: 9160
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int n,x,y;
	cin>>n;
	x=800*n;
	y=(n/15)*200;
	cout<<x-y<<endl;
	return 0;
}


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

using namespace std;
typedef long long ll;

const ll INF = ll(1e18) + 1;

int n; ll k;
vector<ll> a;

bool f(ll x);

int main() {
    cin >> n >> k;
    a.resize(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

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

    ll l = -INF;
    ll r = INF;
    while (l + 1 < r) {
        ll x = (l + r) / 2;
        if (f(x)) l = x;
        else r = x;
    }
    cout << l << endl;
}

bool f(ll x) {
    ll count = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] >= 0) {
            int l = -1;
            int r = n;
            while(l + 1 < r) {
                int c = (l + r) / 2;
                if(a[c] * a[i] < x)  l = c;
                else r = c;
            }
            count += r;
        }
        else {
            int l = -1;
            int r = n;
            while(l + 1 < r) {
                int c = (l + r) / 2;
                if(a[c] * a[i] < x)  r= c;
                else l = c;
            }
            count += n - r;
        }
        if (a[i] * a[i] < x) count--;
    }
    count /= 2;
    return count < k;
}



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

int main() {
  int n;
  cin>>n;
  vector<int> V(n);
  for (int i=0; i<n; i++){
    cin>>V[i];
  }
  int k=0;
  for (int j=0;(V[j]%2==0 && j<n); j++){
    V[j]=V[j]/2;
    if(j==n-1){
      k++;
      j=0;
    }
  }
  cout << k <<endl;
}

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

int main()
{
multiset <int> v;

int n,a,i,as=0;
cin>>n;
for(i=1;i<n;i++)
{
	cin>>a;
	v.insert(a);
}
for(i=1;i<=n;i++)
{
	cout<<v.count(i)<<"\n";
}


}


Measured memory_bytes: 13000
#include <algorithm>
#include<stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
#include <queue>
#include<map>
#include <set>
#include<math.h>
using namespace std;
#define int long long
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define Rep(i,n) for(ll i=1;i<=n;++i)
#define loop(i,m,n) for(ll i=m;i<n;++i)
#define ggr getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define elif else if
#define P pair<ll,ll>
#define prique priority_queue<ll>
const int mod = 1000000007;
const int mod2 = 998244353;
int bin(int bina) {
	int ans = 0;
	for (int i = 0; bina > 0; i++)
	{
		ans = ans + (bina % 2) * pow(10, i);
		bina = bina / 2;
	}
	return ans;
}
bool prime(int n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x * y / gcd(x, y);
}
int kai(int x) {
	if (x == 0)return 1;
	return kai(x - 1) * x % mod;
}
int mod_pow(int x, int y, int mod) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % mod;
		}
		x = x * x % mod;
		y >>= 1;
	}
	return res;
}
long nCr(int n, int r) {
	int ans = 1;
	for (ll i = n; i > n - r; --i) {
		ans = ans * i;
	}
	for (ll i = 1; i < r + 1; ++i) {
		ans = ans / i;
	}
	return ans;
}
struct union_find {
	int par[200010], size_[200010];
	void init(int x) {
		rep(i, x) { par[i] = i; size_[i] = 1; }
	}
	int find(int x) {
		if (par[x] == x)return x;
		return par[x] = find(par[x]);
	}
	void unite(int x, int y) {
		x = find(x); y = find(y);
		if (x == y)return;
		if (size_[x] < size_[y]) {
			par[x] = y;
			size_[y] += size_[x];
		}
		else {
			par[y] = x;
			size_[x] += size_[y];
		}
	}
};

signed main() {
	double a, b, p, q, r;
	cin >> a >> b >> p >> q >> r;
	cout << fixed << setprecision(10) << b+(p*a+(b-a)*(p-q))/(q+r) << endl;
}


Measured memory_bytes: 3288
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

struct P { int v1, v2; };

template<typename T>
void sort_u(T& v) {
  std::sort(v.begin(), v.end());
  v.erase(std::unique(v.begin(),v.end()), v.end());
}

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  int R, C, N; std::cin >> R >> C >> N;
  auto f = [&](int x, int y)->int {
    if(x == 0) return C-y;
    if(y == 0) return C+x;
    if(x == R) return C+R+y;
    if(y == C) return C+C+R+R-x;
    return -1;
  };
  std::vector<P> ps;
  std::vector<int> vs;
  for(int i = 0; i < N; ++i) {
    int x1, y1, x2, y2; std::cin >> x1 >> y1 >> x2 >> y2;
    int v1 = f(x1, y1);
    if(v1 < 0) continue;
    int v2 = f(x2, y2);
    if(v2 < 0) continue;
    ps.push_back({std::min(v1, v2), std::max(v1, v2)});
    vs.push_back(v1);
    vs.push_back(v2);
  }
  sort_u(vs); int K = vs.size();
  std::vector<int> vv(K);
  // compress
  for(int i = 0; i < ps.size(); ++i) {
    vv[std::lower_bound(vs.begin(), vs.end(), ps[i].v1) - vs.begin()] = i;
    vv[std::lower_bound(vs.begin(), vs.end(), ps[i].v2) - vs.begin()] = i;
  }
  std::vector<int> st;
  for(int v: vv) {
    if(st.size() > 0 && st.back() == v) st.pop_back();
    else st.push_back(v);
  }
  if(st.size() > 0) fin("NO");
  fin("YES");
  return 0;
}


Measured memory_bytes: 3436
#include <iostream>
#include <vector>
#include <algorithm>
#define LL long long

std::string repeat(int times, char c){
	std:: string r(times,c);
	return r;
}

int main(){
	int h,w, i,j;
	std::cin >> h >> w;
    std::string s[h+2];
    std::string _s;
    for(i=0;i<h+2;i++){
		s[i].resize(w+2);

		if(i==0||i==w+1){
			s[i] = repeat(w+2,'.');
		} else {
			std::cin >> _s;
			s[i] = "." + _s + ".";
		}

    }

    for(i=1;i<=h;i++){
		for(j=1;j<=w;j++){
			if(s[i][j]=='#'){
				if(
					s[i-1][j]=='.' &&
					s[i+1][j]=='.' &&
					s[i][j-1]=='.' &&
					s[i][j+1]=='.'
				){
					std::cout << "No" << std::endl;
					return 0;
				}
			}
		}
    }

//	for(i=0;i<h+2;i++)std::cout << s[i] << std::endl;
	std::cout << "Yes" << std::endl;

	return 0;
}


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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int m[100][100];
int d[100];
int n;
const int INF = 1e8;

void bfs(int u)
{
    queue<int> q;
    q.push(u);

    d[u] = 0;

    while (!q.empty())
    {
        int t = q.front();
        q.pop();

        rep(i, n)
        {
            if (m[t][i] == 0 || d[i] != INF)
                continue;
            d[i] = d[t] + 1;
            q.push(i);
        }
    }
}

int main()
{
    cin >> n;
    rep(i, n) d[i] = INF;

    rep(i, n) rep(j, n) m[i][j] = 0;

    rep(i, n)
    {
        int u, k;
        cin >> u >> k;
        --u;
        rep(j, k)
        {
            int v;
            cin >> v;
            m[u][--v] = 1;
        }
    }

    bfs(0);

    rep(i, n)
    {
        if (d[i] == INF)
            cout << i + 1 << " " << -1 << endl;
        else
            cout << i + 1 << " " << d[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3120
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n;sc(n);
 vector<ll>a;
 ll b,k;
 rep(i,0,n){
  sc(b);push(a,b);
 }
 sort(all(a));
 //rep(i,0,n)cout<<a[i]<<" ";pnn;
 ans=0;
 rrp(i,n,0){//一番大きい辺
  rep(j,0,i){
   rep(k,j+1,i){
    if(a[i]<a[j]+a[k]){
     ans+=n-(n-i)-k;
     //cout<<i<<" "<<j<<" "<<k<<" "<<ans<<" "<<a[i]<<" "<<a[j]+a[k]<<endl;
     break;
    }
   }
  }
 }
 pr(ans);
return 0;}

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

int main(){
  
 string S,T;
 cin>>S>>T;
 
 int s=S.size(),t=T.size();
 vector<int>count(s-t+1);

 for(int i=0;i<s-t+1;i++){
   for(int j=0;j<t;j++){
     if(S[i+j]==T[j]){
       count[i]++;
     }
   }
 }

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

 cout<<t-count[s-t]<<endl;
 
}

Measured memory_bytes: 3676
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<ll, ll>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

int n, v[5], k[5];
map<int, int> m;


int main(void) {
  cin >> n;
  
  rep(i, 0, n) {
    int a;
    cin >> a;
    m[a]++;
  }
  
  if (sz(m)>3) {
    puts("No");
    return 0;
  }
  int i = 0;
  for (auto itr=m.bg; itr!=m.en; itr++) {
    k[i] = itr->first;
    v[i] = itr->second;
    i++;
  }
  
  bool ok = false;
  
  if (i==1) {
    if (k[0]==0) ok = true;
  } else if (i==2) {
    if (v[1]>v[0]) {
      swap(k[0], k[1]);
      swap(v[0], v[1]);
    }
    if (k[1]==0 && (v[0]+v[1])%3==0 && v[0]==v[1]*2) ok = true;
  } else {
  if ((k[0]^k[1])==k[2] && v[0]==v[1] && v[0]==v[2]) ok = true;
  }
  if(ok) puts("Yes");
  else puts("No");
    

    return 0;
}



Measured memory_bytes: 3840
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner((System.in));
		int n = sc.nextInt();
		int[] a = new int[n];
		int[] diff = new int[n + 1];
		int sum = 0, pre = 0;

		for (int i = 0; i < n; i++) {
			// 観光地の座標を格納
			a[i] = sc.nextInt();
			// 前の観光地からの費用を計算
			int d = pre - a[i];
			// 前の観光地からの費用を合計に加算
			sum += Math.abs(d);
			diff[i] = d;
			pre = a[i];
		}
		sum += Math.abs(a[n - 1]);
		diff[n] = a[n - 1];
		
		for (int i = 0; i < n; i++) {
			if ((diff[i] < 0 && diff[i + 1] < 0) || (diff[i] > 0 && diff[i + 1] > 0)) {
				System.out.println(sum);
			} else {
				if (Math.abs(diff[i]) <= Math.abs(diff[i + 1])) {
					System.out.println((sum - Math.abs(diff[i] * 2)));
				} else {
					System.out.println((sum - Math.abs(diff[i + 1] * 2)));
				}
			}
		}
		
		sc.close();
	}
}


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

using namespace std;

bool solve() {
  int n;
  cin >> n;
  map<int, int> m;
  int res = 0;
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    m[t]++;
    if (m[t] == 1) res ^= t;
  }
  if (m.size() == 1 && m[0]) return true;
  if (n % 3) return false;
  if (m.count(0) && m[0] == n / 3) {
    if (m.count(res) && m[res] == n / 3 * 2) {
      return true;
    }
  }
  for (auto x : m) {
    if (x.second != n / 3) return false;
  }
  return res == 0;
}

int main() {
  if (solve()) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 3840
#include<bits/stdc++.h>
using namespace std;
 
int n;
int C=0;
vector<int> G[1000];
 
void find(int id,int &x,int &y){
  for(int i=0;i<C;i++){
    for(int j=0;j<(int)G[i].size();j++){
      if(G[i][j]==id){
        x=i;
        y=j;
        return;
      }
    }
  }
}
 
void init(){
  for(int i=0;i<1000;i++){
    G[i].clear();
  }
  C=0;
}
 
void solve(int A,int B){
  if(A==B)return;
   
  int ax,ay,bx,by;
  find(A,ax,ay);
 
  if(B==0){
    if(ay==0)return;
    for(int i=ay;i<(int)G[ax].size();i++){
      G[C].push_back(G[ax][i]);
      C++;
    }
     
    G[ax].erase( G[ax].begin()+ay , G[ax].end() );
    if(G[ax].empty()){
      C--;
      G[ax]=G[C];
      G[C].clear();
    }
    return;
  }
   
  find(B,bx,by);
   
  if(ax!=bx){
    for(int i=ay+1;i<(int)G[ax].size();i++){
      G[C].push_back(G[ax][i]);
      C++;
    }
    G[ax].erase( G[ax].begin()+ay , G[ax].end() );
    G[bx].push_back(A);
    if(G[ax].empty()){
      C--;
      G[ax]=G[C];
      G[C].clear();
    }
  }else{
    if(ay<by){
      for(int i=ay+1;i<(int)G[ax].size();i++){
        G[C].push_back(G[ax][i]);
        C++;
      }
      G[ax].erase( G[ax].begin()+ay , G[ax].end() );
      if(G[ax].empty()){
        C--;
        G[ax]=G[C];
        G[C].clear();
      }
      find(B,bx,by);
      G[bx].push_back(A);
    }
  }
   
}
       
 
int main(){
  while(1){
    cin>>n;
    if(n==0)break;
    init();
    for(int i=0;i<n;i++){
      G[i].push_back(i+1);
    }
    C=n;
    while(1){
      int A,B;
      cin>>A>>B;
      if(A==0&&B==0)break;
      solve(A,B);
    }
    vector<int> ans;
    for(int i=0;i<C;i++){
      ans.push_back( G[i].size() );
    }
    sort(ans.begin(),ans.end());
    for(int i=0;i<(int)ans.size();i++){
      cout<<ans[i]<<endl;
    }
    cout<<"end"<<endl;
  }
  return 0;
}

Measured memory_bytes: 3108
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int N; cin >> N;
    int A[100100];
    reps(i,1,N) cin >> A[i];
    int ans = 0;
    reps(i,1,N){
        if(A[A[i]] == i && i < A[i]) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 4052
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

const int N = 200200;
char s[N];
int n;
ll zeroes, ones;
ll ans;

int getEven(int l, int r) {
	if (r % 2 == 0) r--;
	if (l % 2 == 0) l++;
	if (l > r) return 0;
	return (r - l) / 2 + 1;
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	scanf("%s", s);
	n = strlen(s);
	for (int i = 0; i < n; i++) {
		if (s[i] == '0')
			zeroes++;
		else
			ones++;
	}
	int pos = 0;
	for (int i = 0; i < n; i++) {
		if (s[i] == '0') {
			s[pos++] = s[i];
		} else {
			if (pos > 0 && s[pos - 1] == '1') {
				pos--;
				ans += zeroes;
			} else {
				s[pos++] = s[i];
			}
		}
	}
	int id = 0;
	for (int i = 0; i < pos; i++) {
		if (s[i] == '0') continue;
		id++;
		ans += zeroes - getEven(id, i);
	}
	for (int i = 1; i <= ones; i++)
		ans += (i + 1) / 2;
	printf("%lld\n", ans);

	return 0;
}


Measured memory_bytes: 3420
n = int(input())
citynames = set()
citydict = dict()

for i in range(n):
  s,p = input().split()
  citynames.add(s)
  if not s in citydict:
    citydict[s] = [(int(p), i)]
  else:
    citydict[s].append((int(p), i))

for name in sorted(citynames):
  for point in sorted(citydict[name], reverse=True):
    print(point[1]+1)

Measured memory_bytes: 3064
#include<stdio.h>

void sort(int A[], int N){
  int i, j, v;
  for( i = 1; i < N; i++){
    v = A[i];
    j = i - 1;
    for( ; j >= 0 && A[j] > v; j--){
      A[j + 1] = A[j];
    }
    A[j + 1] = v;
    space(A, N);
  }
}

void space(int A[], int N){
  int i;
  for( i = 0; i < N; i++){
    if( i > 0 ){
      printf(" ");
    }
    printf("%d", A[i]);
  }
  printf("\n");
}

int main(void){
  int N, i, j;
  int A[100];
  
  scanf("%d", &N);
  for(i = 0; i < N; i++){
    scanf("%d", &A[i]);
  }
  space(A, N);
  sort(A, N);
}

Measured memory_bytes: 1848
N = int(input())
loc = [list(map(int,input().split())) for i in range(N)]
dis_s = 0

import math
Nbikkuri = math.factorial(N)
metchabikkuri = math.factorial(N-1)

for i in range(N-1):
    for j in range(i+1, N):
        dis = ( (loc[i][0] - loc[j][0])**2 + (loc[i][1] - loc[j][1])**2 )**(1/2)
        dis_s += dis*metchabikkuri*2

print(dis_s / Nbikkuri)


Measured memory_bytes: 3188