akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define pii pair<ll, ll>
#define SZ(x) ((int)(x).size())
#define endl "\n"
ll mod = 1e9 + 7;
//const double pi = acos(-1.0);
/*
ll kmp(string x)
{
    ll n= x.length();
    //cout<<x<<endl;
    vector<ll> lcp(x.length(), 0);
    for(ll i=1;i<n;i++)
    {
        ll j=lcp[i-1];
        while(j>0 && x[j]!=x[i])
            j=lcp[j-1];
        if(x[i]==x[j])
            j++;
        lcp[i]=j;
    }
    return lcp[n-1];
}

int N = 1000002;
int ar[100002];
void sieve()
{
    for(int i=1;i<=N;i++)
        ar[i] = 1;
    ar[0] = 0;
    for(int i=2;i*i<=N;i++)
    {
        if(ar[i] && i*i<=N)
        {
            for(int j = i*i; j<=N;j+=i)
                ar[j] = 0;
        }
    }
}

ll modex(ll a,ll b){
    if(b<=0){
        return 1;
    }
    if(b%2==0)
    {
        ll x = modex(a, b/2);
        return ((x*x)%mod);
    }
    else
        return ((a%mod * modex(a, b-1))%mod);
}

ll c[1010][1010];

ll combina(ll i, ll j){
        for (int i=0;i<=1005;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==i||j==0)
                c[i][j]=1;
            else
            c[i][j]=c[i-1][j-1]+c[i-1][j];
            c[i][j]%=mod;
        }
        return c[i][j];
}
void find_fac(int x){
    vector<ll> di;
    for(ll i = 2; i*i <= x; i++)
    {
        if(x%i==0){
            di.push_back(i);
            while(x%i==0)
                x/=i;
        }
    }
    if(x > 1)
        di.push_back(x);
}
*/
int n, x;
vector<vector<ll> > dp;
vector<int> w;
vector<int> v;
ll recur(int i, int j){
    if(i<0)
        return 0;
    if(j<0)
        return 0;
    if(dp[i][j]!=-1)
        return dp[i][j];
    ll x = recur(i-1, j);
    if(w[i]<=j){
        x = max(x, v[i] + recur(i-1, j-w[i]));
    }
    dp[i][j] = x;
    return dp[i][j];
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    cout<<fixed;
    cout.precision(12);
    cin>>n>>x;
    w.resize(n);v.resize(n);
    int s = 0;
    for(int i=0;i<n;i++){
        cin>>w[i]>>v[i];
        s += v[i];
    }
    dp.resize(n);
    for(int i=0;i<n;i++){
        dp[i].resize(x+1);
        for(int j=0;j<=x;j++)
            dp[i][j]=-1;
    }
    ll an = recur(n-1, x);
    cout<<an<<endl;
    return 0;
}


Measured memory_bytes: 81448
#include <bits/stdc++.h>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)

int main(){
    LL N, A, B;
    cin >> N >> A >> B;
    LL min_sum = (N-2)*A;
    LL max_sum = (N-2)*B;

    if(min_sum > max_sum){
        cout << 0 << endl;
    }else{
        cout << max_sum - min_sum + 1 << endl;
    }
    return 0;

}

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

using namespace std;


int main() {
	int N, M;
	int count = 0;
	int count_max = -100;
	string search_word;

	cin >> N;

	vector<string> s(N);
	for (int i = 0; i < N; i++) {
		cin >> s.at(i);
	}

	cin >> M;

	vector<string> t(M);
	for (int i = 0; i < M; i++) {
		cin >> t.at(i);
	}

	for (int i = 0; i < N; i++) {
		count = 0;
		search_word = s.at(i);

		for (int j = 0; j < N; j++) {
			if (s.at(j) == search_word) {
				count++;
			}
		}

		for (int j = 0; j < M; j++) {
			if (t.at(j) == search_word) {
				count--;
			}
		}

		if (count > count_max) {
			count_max = count;
		}
	}

	if (count_max < 0) {
		count_max = 0;
	}

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

Measured memory_bytes: 256
from collections import Counter
    
n = int(input())
v = list(map(int, input().split()))
odd = v[::2]
even = v[1::2]
    
c_even = Counter(even).most_common(2)
c_odd = Counter(odd).most_common(2)

    
if(c_even[0][0] != c_odd[0][0]):
    print(n - c_even[0][1] - c_odd[0][1])
else:
    if(len(c_even) == 1):
        print(n//2)
    else:
        # second = max[c_even[1][1], c_odd[1][1]]
        # print(n - c_even[0][1] - second)
        print(n - max(c_odd[1][1], c_even[1][1]) - c_even[0][1])

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

int main(int argc, const char * argv[]) {
//    vector<char> w;
    string w;
    cin >> w;
    vector<char> w2(w.begin(),w.end());
    
    sort(w2.begin(),w2.end());
    
    int count = 0;
    bool flag = true;
    
    if(w2.size()==1){
        cout << "No" << endl;
        return 0;
    }else{
        
        for(int i=0;i<w2.size();i++){
            if(i==0){
                count++;
            }else{
                if(w2[i]==w2[i-1]) count++;
                else{
                    if(count%2!=0)flag=false;
                    count++;
                }
                if(i==w2.size()-1 &&count%2!=0)flag=false;
            }
        }
        
    }
    if(flag) cout << "Yes" <<endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
#coding:utf-8
n,x = map(int,input().split())
ls_candy = list(map(int,input().split()))
ls_candy.sort()
#print (n,x)
#print (ls_candy)
sum = 0
answer = 0
just = 0
for i,candy in enumerate(ls_candy):
    sum += candy
    if x > sum:
        answer = i
    elif x < sum:
        answer = i
        break
    else:
        answer = i+1
        break
print (answer)


Measured memory_bytes: 3060
#define _USE_MATH_DEFINES

#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <ctime>
////
//#include <random>//
/////////

typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;

////定数
const int INF = (int)1e9 + 10;
const LL MOD = (LL)1e9 + 7;
const LL LINF = (LL)4e18 + 20;
const LD PI = acos(-1.0);
const double EPS = 1e-9; 
/////////
using namespace::std;
//////////////

void solve() {
	LL N;
	cin >> N;
	
	vector<int> num(101);
	for (int i = 0; i <= 100; ++i) {
		num[i] = i;
	}
	vector<bool> primeFld(101, true);
	vector<int> prime;
	for (int i = 2; i <= 100; ++i) {
		if (primeFld[i]) {
			prime.push_back(i);
			for (int j = i + i; j <= 100; j += i) {
				primeFld[j] = false;
			}
		}
	}
	int pLen = prime.size();
	vector<int> S(prime.size(), 0);
	for (int i = 1; i <= N; ++i) {
		int temp = i;
		for (int j = 0; j < pLen; ++j) {
			if (temp < prime[j]) {
				break;
			}
			while (temp && temp % prime[j] == 0) {
				S[j]++;
				temp /= prime[j];
			}
		}
	}
	LL A = 0;
	LL B = 0;
	LL C = 0;
	LL D = 0;
	LL E = 0;
	LL F = 0;
	LL G = 0;
	
	for (int i = 0; i < prime.size(); ++i) {
		if (S[i] >= 5-1) {
			++A;
		}
		if (S[i] >= 3-1) {
			++B;
		}
		if (S[i] >= 15 - 1) {
			++C;
		}
		if (S[i] >= 5 - 1) {
			++D;
		}

		if (S[i] >= 25 - 1) {
			E++;
		}
		if (S[i] >= 3-1) {
			F++;
		}

		if (S[i] >= 75-1) {
			G++;
		}
	}
	LL ans = 0;
	ans += A * (A - 1) * (B-2)/2;
	ans += C * (D-1);
	ans += E * (F-1);
	ans += G;
	cout << ans << endl;
	
}

signed main(void) {
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define int long long
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = (int)1e18 * 5;

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

    string s;
    cin >> s;
    puts(s.find('C') < s.rfind('F') && s.rfind('F') != string::npos ? "Yes" : "No");
    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
//#include <bits/stdc++.h>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <complex>
#include <deque>
#include <iomanip>
#include <ios>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>

using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)


void solve(long long X){
	long long uresisa=(X/500)*1000;
	X-=(X/500)*500;
	uresisa+=(X/5)*5;
	cout<<uresisa<<endl;
}

int main(){
  long long X;
  scanf("%lld",&X);
  solve(X);
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define pb push_back
#define MP make_pair
#define mod 1000000007

int main(){
    int x,n;
    cin>>x>>n;
    int arr[n];
    map<int,int> mp;
    for(int i=0;i<n;i++){
        cin>>arr[i];
        mp[arr[i]] = 1;
    }
    int mn=INT_MAX,ans=-1;
    for(int i=0;i<105;i++){
        if(!mp[i] && abs(x-i)<mn){
            mn = abs(x-i);
            ans = i;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3636
N = int(input())
P = list(map(int,input().split()))

Pc = [i+1 for i in range(N)]

pal = 0
for i in range(N):
    if(P[i]!=Pc[i]):
        pal += 1


if((pal == 2)or(pal==0)):
    print("YES")
else:
    print("NO")
    

Measured memory_bytes: 38256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vpii = vector<pair<int,int>>;
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};



int main(void) {
  ll h;
  cin >> h;
  ll cnt = 2;
  
  while(h>1){
    h /= 2;
    cnt *= 2;
  }
  cnt --;
  cout << cnt << endl;
  
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define rep(i,n) for(int i=0, i##_len=(int)(n); i<i##_len; i++)
#define reps(i,n) for(int i=1 , i##_len=(int)(n);i<=i##_len;i++)
#define rrep(i,n) for(int i=((int)(n)-1);i>=0;i--)
#define rreps(i,n) for(int i=((int)(n));i>0;i--)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
typedef vector<long long> V;
typedef vector<V> VV;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1;} return 0;}
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1;} return 0;}
const long long INFLL = 1LL<<60;
const int INF = 1<<28;
void solve(int a){cout<<( a?"Yes":"No")<<endl;}
int main(){
	int n;
	ll ans=0;
	cin >>n;
	ll c=1;
	ll pp=0,pq=0;
	vector<int>p(n,0);
	vector<int> q(n, 0);
	vector<int> a(n, 0);
	rep(i,n){
		cin>>p[i];
	}
	rep(i, n){
		cin >> q[i];
	}
	a=p;
	sort(all(a));
	do{
		if(a==p){
			pp=c;
		}
		if(a==q){
			pq=c;
		}
		if(pp!=0 and pq!=0){
			break;
		}
		c++;
	}while(next_permutation(all(a)));
	cout<<abs(pp-pq)<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static final int MAX = 10000;
	static final int NIL = -1;
	static Node T[] = new Node[MAX];
	static int n;
	static int []D = new int[MAX];
	static int []H = new int[MAX];

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		for(int i = 0; i < n; i++) {
			T[i] = new Node(NIL, NIL, NIL);
		}
		for(int i = 0; i < n; i++) {
			int v = scan.nextInt();
			int l = scan.nextInt();
			int r = scan.nextInt();
			T[v].setL(l);
			T[v].setR(r);
			if(l != NIL) T[l].setP(v);
			if(r != NIL) T[r].setP(v);
		}
		scan.close();

		int root = 0;
		for(int i = 0; i < n; i++) {
			if(T[i].getP() == NIL) {
				root = i;
			}
		}

		setDepth(root, 0);
		setHeight(root);
		for(int i = 0; i < n; i++) {
			disp(i);
		}

	}
	static void setDepth(int u, int d) {
		if(u == NIL) {
			return;
		}
		D[u] = d;
		setDepth(T[u].getL(), d + 1);
		setDepth(T[u].getR(), d + 1);
	}
	static int setHeight(int u) {
		int h1 = 0;
		int h2 = 0;
		if(T[u].getL() != NIL) {
			h1 = setHeight(T[u].getL()) + 1;
		}
		if(T[u].getR() != NIL) {
			h2 = setHeight(T[u].getR()) + 1;
		}
		return H[u] = Math.max(h1, h2);
	}
	// 節点uの兄弟を返す
	static int getSibling(int u) {
		if(T[u].getP() == NIL) {
			return NIL;
		}
		if(T[T[u].getP()].getL() != u && T[T[u].getP()].getL() != NIL) {
			return T[T[u].getP()].getL();
		}
		if(T[T[u].getP()].getR() != u && T[T[u].getP()].getR() != NIL) {
			return T[T[u].getP()].getR();
		}
		return NIL;
	}
	static void disp(int u) {
		System.out.print("node " + u + ": ");
		System.out.print("parent = " + T[u].getP() + ", ");
		System.out.print("sibling = " + getSibling(u) + ", ");
		int deg = 0;
		if(T[u].getL() != NIL) deg++;
		if(T[u].getR() != NIL) deg++;
		System.out.print("degree = " + deg + ", ");
		System.out.print("depth = " + D[u] + ", ");
		System.out.print("height = " + H[u] + ", ");

		if(T[u].getP() == NIL) {
			System.out.println("root");
		}else if(T[u].getL() == NIL && T[u].getR() == NIL) {
			System.out.println("leaf");
		}else {
			System.out.println("internal node");
		}
	}
}
class Node {
	private int p, l ,r;
	public Node(int p, int l, int r) {
		this.p = p;
		this.l = l;
		this.r = r;
	}
	int getP() {
		return p;
	}
	int getL() {
		return l;
	}
	int getR() {
		return r;
	}
	void setR(int r) {
		this.r = r;
	}
	void setL(int l) {
		this.l = l;
	}
	void setP(int p) {
		this.p = p;
	}
}


Measured memory_bytes: 26548
#include <iostream>
#include <fstream>
#include <cassert>
#include <typeinfo>
#include <vector>
#include <stack>
#include <cmath>
#include <set>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#include <random>
#include <complex>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<29;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-7;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

int x,k,q;
vi a;

int main(){
	cin>>x>>k;
	a=vi(k+1);
	for(int i=1;i<=k;i++) cin>>a[i];
	cin>>q;
	int l=0,L=0,r=x,R=x,I=0;
	for(int i=0;i<q;i++){
		int t,A;
		cin>>t>>A;
		while(I<k&&t>=a[I+1]){
			if(I<=k&&t>=a[I]){
				int s=a[I+1]-a[I];
				if(I%2==0){
					L-=s;
					R-=s;
					if(L<0){
						l-=L;
						L=0;
					}
					if(R<0) R=0;
				}
				else{
					L+=s;
					R+=s;
					if(R>x){
						r-=R-x;
						R=x;
					}
					if(L>x) L=x;
				}
				I++;
			}
		}
		t-=a[I];
		int res;
		if(l<A&&A<r) res=L+A-l;
		if(A<=l) res=L;
		if(r<=A) res=R;
		if(I%2==0) res-=t;
		else res+=t;
		if(res<0) res=0;
		if(res>x) res=x;
		cout<<res<<endl;
	}
}

Measured memory_bytes: 1536
def main_B1():
  N, K = [int(i) for i in input().split()]
  h = [int(i) for i in input().split()]

  inf = float("inf")
  cost = [inf]*N


  cost[0] = 0
  for i in range(1, N):
    cost[i] = min([cost[j] + abs(h[i] - h[j]) for j in range(max(0, i-K), i)])
  print(cost[-1])

if __name__ == "__main__":
  main_B1()

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

using namespace std;

template<int mod> class modint {
public:
  int x;
  modint(): x(0) {}
  modint(int a) { x = a % mod; if (x < 0) x += mod; }
  modint &operator+=(modint that) { x = (x + that.x) % mod; return *this; }
  modint &operator-=(modint that) { x = (x + mod - that.x) % mod; return *this; }
  modint &operator*=(modint that) { x = (long long) x * that.x % mod; return *this; }
  modint &operator/=(modint that) { return *this *= that.inverse(); }
  modint operator-() { return modint(-this->x); }
  friend ostream& operator<<(ostream &out, modint m) { return out << m.x; }
  modint inverse() {
    int a = x, b = mod, u = 1, v = 0;
    while (b) { int t = a / b; a -= t * b; u -= t * v; swap(a, b); swap(u, v); }
    return modint(u);
  }
#define op(o, p) modint operator o(modint that) { return modint(*this) p that; }
  op(+, +=) op(-, -=) op(*, *=) op(/, /=)
#undef op
#define op(o) bool operator o(modint that) { return x o that.x; }
  op(==) op(!=) op(<) op(<=) op(>) op(>=)
#undef op
};

typedef modint<1000000007> mint;

mint rec(int l, int n, int b = 1, int s = 0, vector<int> v = vector<int>()) {
  if (s == n) {
    map<int, int> cnt;
    for (int i = 0; i < v.size(); i++) {
      cnt[v[i]]++;
    }
    int nn = l;
    mint m = 1;
    for (auto c: cnt) {
      nn = nn - c.second;
      for (int i = 1; i <= c.second; i++) {
        m *= nn + i;
        m /= i;
      }
    }
    return m;
  }
  mint ret = 0;
  for (int i = b; i <= n; i++) {
    if (i + s > n) break;
    s += i;
    v.push_back(i);
    ret += rec(l, n, i, s, v);
    v.pop_back();
    s -= i;
  }
  return ret;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  map<int, int> prime;
  prime[2] = 0;
  prime[3] = 0;
  for (int i = 5; i < 1e5; i += 2) {
    bool is = true;
    for (int j = 3; j * j <= i; j += 2) {
      if (i % j == 0) {
        is = false;
        break;
      }
    } 
    if (is) {
      prime[i] = 0;
    }
  }
  int n, m;
  cin >> n >> m;
  for (auto p: prime) {
    int num = p.first;
    while (m % num == 0) {
      m /= num;
      prime[num]++;
    }
  }
  if (m != 1) {
    prime[m] = 1;
  }
  mint ans = 1;
  for (auto p: prime) {
    if (p.second == 0) {
      continue;
    }
    ans *= rec(n, p.second);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 768
# coding:utf-8
w,h,x,y,r=map(int,input().split())
ans=True

def f(px,py):#外ならtrue
    flag=False
    if px<0 or py<0 or px>w or py>h:
        flag=True
    return flag

if f(x-r,y-r) or f(x-r,y+r) or f(x+r,y-r) or f(x+r,y+r):
    ans=False
if ans:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 5604
def cmb(n, r, mod):
    if (r < 0 or r > n):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n - r] % mod


x, y = map(int, input().split())
mod = 10 ** 9 + 7

if (x + y) % 3 != 0:
    print(0)
    exit()

a = (2 * y - x) // 3
b = (2 * x - y) // 3

if a < 0 or b < 0:
    print(0)
    exit()

n = a + b
r = min(a, b)

g1 = [1, 1]
g2 = [1, 1]
inv = [0, 1]

for i in range(2, n + 1):
    g1.append((g1[-1] * i) % mod)
    inv.append((-inv[mod % i] * (mod//i)) % mod)
    g2.append((g2[-1] * inv[-1]) % mod)

print(cmb(n, r, mod))

Measured memory_bytes: 82448
#ifdef _DEBUG
#include "MyLib.h"
#else
#define main_C main
#include "bits/stdc++.h"
#include <regex>
#define _USE_MATH_DEFINES
#include <math.h>
#define FOR(i,s,e) for (int i = int(s); i < int(e); ++i)
#define REP(i,e) FOR(i,0,e)
#define INF (INT_MAX/2)
#define EPS (1.0e-8)
#define LINF (LLONG_MAX/2)
const int MGN = 8;
const int ARY_SZ_MAX = 10000000;
using namespace std;
using ll = long long; using ull = unsigned long long;
using vi = vector<int>; using vvi = vector<vi>; using vvvi = vector<vvi>;
using vb = vector<bool>; using vvb = vector<vb>; using vvvb = vector<vvb>;
using vl = vector<ll>; using vvl = vector<vl>;
using vd = vector<double>; using vs = vector<string>;
using pii = pair<int, int>; using pll = pair<ll, ll>;
using psi = pair<string, int>;
// functions

#endif


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

    int N; cin >> N;
    vi A(N); REP(i, N) cin >> A[i];

    map<int, int> mp;
    REP(i,N){
        mp[A[i]] = 1 - mp[A[i]];
    }

    int ans = 0;
    for(auto p : mp) {
        ans += p.second;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5376
#include <bits/stdc++.h>
using namespace std;
int n,m;
int X[4] = {0,1,0,-1};
int Y[4] = {1,0,-1,0};

int bfs(char **mat,int sx,int sy,int ex,int ey,int moves,bool **vis){
    
    if(sx==ex && sy==ey){
        return 0;
    }
    
    queue<pair<int,pair<int,int>>> q;
    q.push(make_pair(0,make_pair(sx,sy)));
    
    while(!q.empty()){
        
        pair<int,pair<int,int>> p = q.front();
        q.pop();
        
        int move = p.first;
        pair<int,int> curr = p.second;
        
        if(curr.first==ex && curr.second==ey)
        return  move;
        
        if(vis[curr.first][curr.second])
        continue;
        
        vis[curr.first][curr.second] = true;
        
        for(int i=0;i<4;i++)
        {
            int x = curr.first+X[i];
            int y = curr.second+Y[i];
            
            if(x>=0 && y>=0 && x<n && y<m && !vis[x][y] && mat[x][y]=='.'){
                q.push(make_pair(move+1,make_pair(x,y)));
            }
            
            
        }
        
        
        
        
    }
    
    return 0;
    
    
}

void erase(bool **vis){
    
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    vis[i][j]=false;
    
    
}

int main() {
    
    cin>>n>>m;
    
    char ** mat = new char*[n];
    bool **vis = new bool*[n];
    for(int i=0;i<n;i++){
    mat[i] = new char[m];
    vis[i] = new bool[m];
    }
    
    for(int i=0;i<n;i++)
    for(int j=0;j<m;j++)
    cin>>mat[i][j];
    
    int ans = 0;
    
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++){
            for(int I=0;I<n;I++){
                for(int J=0;J<m;J++){
                    erase(vis);
                    if(mat[i][j]=='.' && mat[I][J]=='.')
                    ans = max(ans,bfs(mat,i,j,I,J,0,vis));
                    
                }
            }
        }
    }
    
    
    std::cout << ans << std::endl;
    
	return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-
N, M = map(int, input().split())
if N == 1 or M == 1:
    r = max(N - 2, M - 2)
else:
    r = (N - 2) * (M - 2)

if N + M == 2:
    print(1)
else:
    print(r)

Measured memory_bytes: 3060
N,M = map(int, input().split())
B = []
C = []

for _ in range(M):
  tmp1,tmp2 = map(int,input().split())
  B.append(tmp1)
  C.append(tmp2)

p = max(B)
q = min(C)
res = q - p + 1
if res < 0:
  res = 0
print(res)

Measured memory_bytes: 11052
import java.util.*;

class Main {
  public static void main (String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int m = sc.nextInt();
    ArrayList<ArrayList<Integer>> paths = new ArrayList<ArrayList<Integer>>();
    int[][] given = new int[m][2];
    for(int i = 0; i < n; i++) {
      paths.add(new ArrayList<Integer>());
    }
    for(int i = 0; i < m; i++) {
      int a = sc.nextInt();
      int b = sc.nextInt();
      paths.get(a-1).add(b-1);
      paths.get(b-1).add(a-1);
      given[i][0] = a-1;
      given[i][1] = b-1;
    }
    /*for(int i = 0; i < n; i++) {
      for(int j = 0; j < paths.get(i).size(); j++) {
        System.out.print(paths.get(i).get(j) + " ");
      }
      System.out.println();
    }*/
    int bridges = 0;
    for(int i = 0; i < m; i++) {
      paths.get(given[i][0]).remove((Object)given[i][1]);
      paths.get(given[i][1]).remove((Object)given[i][0]);
      boolean[] visited = new boolean[n];
      dfs(0, visited, paths);
      for(int j = 0; j < n; j++) {
        if(!visited[j]) {
          bridges++;
          break;
        }
      }
      paths.get(given[i][0]).add(given[i][1]);
      paths.get(given[i][1]).add(given[i][0]);
    }
    System.out.println(bridges);
  }
  
  private static void dfs(int u, boolean[] visited, ArrayList<ArrayList<Integer>> list) {
    visited[u] = true;
    for(int i = 0; i < list.get(u).size(); i++) {
      int curr = list.get(u).get(i);
      if(!visited[curr]) {
        dfs(curr, visited, list);
      }
    }
  }
}


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

using namespace std;

int main(int argc, char *argv[]) {
	int x, a, b;
	cin >> x >> a >> b;

	int da = static_cast<int>(abs(x - a));
	int db = static_cast<int>(abs(x - b));

	if (da < db) {
		cout << 'A' << endl;
	}
	if (da > db) {
		cout << 'B' << endl;
	}

	return 0;
}


Measured memory_bytes: 256
n=int(input())
Ai=[int(i) for i in input().split()]
Bi=[]
for i in range(n):
    Bi.append(Ai[i]-(i+1))
Bi.sort()
b=Bi[n//2]
ans=0
for i in range(n):
    ans+=abs(Bi[i]-b)
print(ans)

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

int main() {
int X;
  cin>>X;
  
  int ans=0;
  for(int i=1; i<=33; i++){
   for(int j=2; j<=10; j++){
    int n=pow(i,j);
    if(n>X){break;}
    if(n>ans){ans=n;} 
   }
  }
  cout<<ans<<endl;
}
     

Measured memory_bytes: 256
import java.util.Scanner;


	public class Main {

		public static void main(String[] args) {

			Scanner sc = new Scanner(System.in);

			int n = sc.nextInt();
			int y = sc.nextInt();
			int man = 10000;
			int go = 5000;
			int sen = 1000;
			
			
			String no = "-1 -1 -1";
			
			if(y>man*n) {
				System.out.println(no);
				return;
			}
			
			for(int i=0;i<=y/man;i++) {
				int x = ((y-man*i)/sen+i-n);
				if(x%4==0&&(n-x/4-i>=0)&&x/4>=0) {
					System.out.println(i+" "+x/4+" "+(n-i-x/4));
					return;
					
				}
			}
			
			System.out.println(no);
		}

	}


Measured memory_bytes: 23764
import math

A, B, H, M = list(map(int, input().split()))

h = H * 30 + M * 0.5
m = M * 6

s = min(360 - abs(h - m), abs(h - m))

ans = math.sqrt(A**2 + B**2 - 2 * A * B * math.cos(math.radians(s)))

print(ans)



Measured memory_bytes: 9500
s = input()

length = len(s)

a = [0] * (length + 1)
b = [0] * length
y = 0
for i in range(length):
    if s[i] == '/':
        y += 1
    elif s[i] == '\\':
        y -= 1
    a[i + 1] = y

m = -30000
for i in range(length, 0, -1):
    m = max(m, a[i])
    b[i - 1] = m

i = 0
memory = []
while i < length:
    if a[i] > b[i]:
        i += 1
        continue

    start = a[i]
    i += 1
    base = 1
    d_from = s[i - 1]
    ws_part = 0
    while i < length + 1 and a[i] < start:
        d_to = s[i]
        ws_part += base
        if d_from == '\\' and d_to == '\\':
            base += 2
        if d_from == '\\' and d_to == '_':
            base += 1
        if d_from == '/' and d_to == '/':
            base -= 2
        if d_from == '/' and d_to == '_':
            base -= 1
        if d_from == '_' and d_to == '\\':
            base += 1
        if d_from == '_' and d_to == '/':
            base -= 1
        d_from = d_to
        i += 1

    if ws_part > 0:
        ws_part += 1
        memory.append(ws_part // 2)

print(sum(memory))
if memory:
    print(len(memory), ' '.join(map(str, memory)))
else:
    print(len(memory))



Measured memory_bytes: 6460
using static System.Math;
using System;

public class Hello
{
    public static int INF = 999;
    public static int[] dx, dy;
    public static int h, w;
    public static bool[,] map;
    public static void Main()
    {
        dx = new int[] { 0, 1, 0, -1 };
        dy = new int[] { 1, 0, -1, 0 };
        string[] line = Console.ReadLine().Trim().Split(' ');
        h = int.Parse(line[0]);
        w = int.Parse(line[1]);
        map = new bool[h, w];
        for (int i = 0; i < h; i++)
        {
            var s = Console.ReadLine().Trim();
            for (int j = 0; j < w; j++)
                if (s[j] == '.') map[i, j] = true;
        }
        var dp = makeDp();
        goWarshall(dp);
        var ans = 0;
        for (int i = 0; i < h * w; i++)
            for (int j = 0; j < h * w; j++)
                if (dp[i, j] != INF) ans = Max(ans, dp[i, j]);
        Console.WriteLine(ans);
    }
    static int[,] makeDp()
    {
        var hw = h * w;
        var map2 = new int[h, w];
        var p = 0;
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                map2[i, j] = p++;
        var dp = new int[hw, hw];
        for (int i = 0; i < hw; i++)
            for (int j = 0; j < hw; j++)
                if (i != j) dp[i, j] = INF;
        for (int i = 0; i < h; i++)
            for (int j = 0; j < w; j++)
                if (map[i, j])
                    for (int k = 0; k < 4; k++)
                    {
                        var nx = i + dx[k];
                        var ny = j + dy[k];
                        if (nx >= 0 && nx < h && ny >= 0 && ny < w && map[nx, ny])
                        {
                            dp[map2[i, j], map2[nx, ny]] = 1;
                            dp[map2[nx, ny], map2[i, j]] = 1;
                        }
                    }
        return dp;
    }
    static void goWarshall(int[,] dp)
    {
        var n = dp.GetLength(0);
        for (int i = 0; i < n; i++)
            for (int j = 0; j < n; j++)
                for (int k = 0; k < n; k++)
                    dp[j, k] = Math.Min(dp[j, k], dp[j, i] + dp[i, k]);
    }

}


Measured memory_bytes: 13536
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  vector<int> H(N);
  for(int i=0; i<N; i++)cin>>H[i];
  int m=0,c=0;
  for(int i=0; i<N; i++){
    if(m<=H[i]){
      c++;
      m=H[i];
    }
  }
  cout<<c<<endl;
}

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

int main()
{
  string w;
  cin >> w;
  int buf[ 100 ] = { 0 };

  for( int i = 0; i < w.size(); i++ ) {
    int idx = w[ i ] - 'a';
    buf[ idx ] += 1;
  }

  bool isb = true;
  for( int i = 0; i < 100; i++ ) {
    if( buf[ i ] % 2 != 0 ) {
      isb = false;
      break;
    }
  }

  cout << (( isb == true )? "Yes" : "No") << endl;
  return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int,int>pa;

const int N=2e5+100;
const int mod=1e9+7;

int x[N],y[N];
int main()
{
   ios::sync_with_stdio(0);cin.tie(0);
   int n;cin>>n;
   for(int i=1;i<=n;i++){
     cin>>x[i]>>y[i];
   }
   sort(x+1,x+1+n);
   sort(y+1,y+1+n);
   if(n&1){
    cout<<y[n/2+1]-x[n/2+1]+1<<endl;
   }
   else{
    cout<<y[n/2]+y[n/2+1]-x[n/2]-x[n/2+1]+1;
   }
  return 0;
}



Measured memory_bytes: 5176
use proconio::input;
 
fn main() {
  input! {
    x: isize,
    k: isize,
    d: isize
  }
  let times = x / d;
  if times.abs() > k {
    println!("{}", (x.abs() - (k * d).abs()).abs());
  } else {
    let left = x.abs() % d;
    if (k - times) % 2 == 0 {
      println!("{}", left.abs());
    } else {
      println!("{}", (left.abs() - d.abs()).abs());
    }
  }
}

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

typedef long long ll;

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

    int n,k;
    cin >> n >> k;
    vector<int> x(n);
    for(int i=0;i<n;i++) cin >> x[i];
    int ans = 0;
    for(int i=0;i<n;i++){
        ans += 2*min(x[i],k-x[i]);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define INIT  ios_base :: sync_with_stdio(0); cin.tie(); cout.tie();mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define mp make_pair
#define pb push_back
#define ft first
#define sc second
#define ll long long
#define pii pair<int, int>
#define int ll



int a, c, b, k;



int32_t main(){
INIT
cin>>a>>b>>c>>k;
int sum=0;

sum+=min(a, k); k-=min(a, k);
k-=min(b, k);

sum-=min(c, k); k-=min(k, c);
cout<<sum<<"\n";

return 0;
}



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

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

using namespace std;

#define min_3(a, b, c) min(a, min(b, c))
typedef long long ll;
const long long INF = 1e9;

int main()
{
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for(int i = 0; i < n; i++) cin >> h[i];

  vector<int> dp(n + 100, INF);
  dp[0] = 0;
  for (int i = 0; i < n; i++)
  {
    for (int j = 1; j <= k; j++)
    {
      chmin(dp[i + j], dp[i] + abs(h[i] - h[i + j]));
    }
  }
  cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<stdlib.h>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
  long long a,b,k;
  cin>>a>>b>>k;
  for(long long i=0;i<k;i++){
    if(i%2==0){
      if(a%2==1)a--;
      long long hoge1=a/2;
      a/=2;
      b+=hoge1;
    }
    else{
      if(b%2==1)b--;
      long long hoge2=b/2;
      b/=2;
      a+=hoge2;
    }
  }
  cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int lli;
typedef unsigned long long int ulli;
typedef long double ldb;
 
#define endl '\n'
#define loop(i, m, n) for (lli i = m; i < n; i++)
#define loope(i, m, n) for (lli i = m; i <= n; i++)
#define epool(i, m, n) for (lli i = m; i >= n; i--)
#define pool(i,m,n) for(lli i=m; i>n; i++)
#define maxe *max_element
#define mine *min_element
#define plli pair<lli, lli>
#define mod 1000000007
#define mod2 998244353
#define vt vector<lli>
#define fi first
#define se second
#define pb push_back
#define umap unordered_map
#define mmap multimap
#define mpp make_pair
#define inp1(a) cin >> a
#define inp2(a, b) cin >> a >> b
#define inp3(a, b, c) cin >> a >> b >> c
#define inp4(a, b, c, d) cin >> a >> b >> c >> d
#define inp5(a, b, c, d, e) cin >> a >> b >> c >> d >> e
#define inp6(a, b, c, d, e, f) cin >> a >> b >> c >> d >> e >> f
#define pr0() cout << " "
#define pr1(a) cout << a << " "
#define pr2(a, b) cout << a << " " << b << " "
#define pr3(a, b, c) cout << a << " " << b << " " << c << " "
#define pr4(a, b, c, d) cout << a << " " << b << " " << c << " " << d << " "
#define emp emplace //used to push a pair etc..
#define empf emplace_front
#define empb emplace_back
#define ret(x) return cout << x, 0;
#define all(v) v.begin(),v.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
//especially for deque both sides dynamic
#define pf push_front
//list doubly linked lists can insert at mid. splice fn can be used
#define fast_io                       \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
using namespace std;
 
lli gcd(lli a, lli b){
    if(a==0) return b;
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
 
lli lcm(lli a, lli b){
    return (a * b) / gcd(a, b);
}
 
lli modi(lli n,lli m=mod){ 
    if(n==0) return 0;
    n%=m;
    n+=m;
    n%=m;
    return n;
}
 
lli mpow(lli base, lli exp){
    base %= mod;
    lli result = 1;
    while (exp > 0){
        if (exp & 1)
            result = ((lli)result * base) % mod;
        base = ((lli)base * base) % mod;
        exp >>= 1;
    }
    return result;
}
const lli INF=1e18;
const lli N=2e5+5;
const ldb pi=4*atan(1);

lli n,m,k,t;
//lli a,b,c,d;
lli p,q,l,r;
lli arr[N];
//lli a[N],b[N],c[N],d[N];
lli a,b,c,d;
lli x[1000005],y[1000005];
map<char,lli> m1,m2;
string s,s1,s2,s3;
vector<lli> v,v1,v2;
lli pre[N],suff[N];
//lli vis[N]={0};
char grid[11][11];
vector<pair<lli,lli>> pl;

bool sortbysec(const pair<lli,lli> &a, pair<lli,lli> &b){
    return (a.se>b.se);
}

int32_t main(){
    fast_io
    lli i = 0,j=0;
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    //cout << fixed << setprecision(22);
    

    cin >> n;
    map<lli,lli> mp;
    loop(i,0,n-1){
        cin >> a;
        v.pb(a);
        mp[a]++;
    }

    loope(i,1,n) cout << mp[i] << endl;


}

Measured memory_bytes: 17292
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		
		String result = new String();
		
		if(a == b){
			result = "Draw";
		}else if(a ==1 && b <=13){
			result = "Alice";
		}else if(a != 1 && b !=1 && b < a){
			result = "Alice";
		}else if(b ==1 && a <=13){
			result = "Bob";
		}else if(b != 1 && a !=1 && b > a ){
			result = "Bob";
		}	
		System.out.println(result);
	}
}

Measured memory_bytes: 22740
#include<stdio.h>
int main(void){
    long long int a,b,c,d,max;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    max=a*c-1;
    if(max<a*c) max=a*c;
    if(max<a*d) max=a*d;
    if(max<b*c) max=b*c;
    if(max<b*d) max=b*d;
    printf("%lld\n",max);
    return 0;
}

Measured memory_bytes: 1732
use proconio::input;

fn main() {
    abc173_a()
}

fn abc173_a() {
    input!(n: u16);
    if n % 1000 == 0 {
        println!("0")
    } else {
        println!("{}", ((n / 1000) + 1) * 1000 - n)
    }
}


Measured memory_bytes: 2124
N, Ma, Mb = map(int, input().split())
A, B, C = [], [], []
for i in range(N):
    ai, bi, ci = map(int, input().split())
    A.append(ai)
    B.append(bi)
    C.append(ci)

INF = float('inf')
dp = [[[INF]*401 for i in range(401)] for j in range(N+1)]
dp[0][0][0] = 0

for i in range(N):
    for a in range(401):
        for b in range(401):
            if dp[i][a][b] == INF:
                continue
            dp[i+1][a][b] = min(dp[i+1][a][b], dp[i][a][b])
            if a + A[i] <= 400 and b + B[i] <= 400:
                dp[i+1][a+A[i]][b+B[i]] = min(dp[i+1][a+A[i]][b+B[i]], dp[i][a][b]+C[i])

ans = INF
for i in range(1, 401):
    target_a = Ma * i
    target_b = Mb * i
    if target_a > 400 or target_b > 400:
        break
    ans = min(ans, dp[N][target_a][target_b])

print(ans if ans != INF else -1)



Measured memory_bytes: 59412
s = input()

#print(len(s))

for i in range(len(s)):
    if i % 2 == 0:
        if (s[i] == 'R') or (s[i] == 'U') or (s[i] == 'D'):
            if i+1 == len(s):
                print('Yes')
                break
            else:
                pass
        else:
            print('No')
            break
    else:
        if (s[i] == 'L') or (s[i] == 'U') or (s[i] == 'D'):
            if i+1 == len(s):
                print('Yes')
                break
            else:
                pass
        else:
            print('No')
            break


Measured memory_bytes: 3060
#include <algorithm>
#include <iostream>
#include <stdio.h>

typedef long long ll;

using namespace std;

int X[3];

int main() {
  int N;
  for (int i = 0; i < 3; ++i) {
    cin >> X[i];
  }
  cin >> N;
  sort(X, X + 3);
  ll cnt = 0;
  int N2 = (int)(N / X[2]);
  int N1 = (int)(N / X[1]);
  for (int i = 0; i <= N2; ++i) {
    for (int j = 0; j <= N1; ++j) {
      if (X[2] * i + X[1] * j + X[0] * max(0, (N - X[2] * i - X[1] * j) / X[0]) == N) {
        ++cnt;
      }
    }
  }
  printf("%lld\n", cnt);
}

Measured memory_bytes: 3232
#!/usr/bin/env python3
import sys


def solve(N: int):
    s_n = str(N)
    keta = len(s_n)

    if N == 10**(keta-1):
        print(10)
        return
    answer = 0
    for i in range(keta):
        answer += int(s_n[i])
    print(answer)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

long long int a[200000];

int main()
{
    int i,n;
    long long int max1=0,sum=0;
    cin >> n;
    for(i = 0;i < n;i++)
        cin >> a[i];
    for(i = 0;i < n;i++)
    {
        if(a[i] > max1)
            max1 = a[i];
        else
            sum += (max1-a[i]);
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 5132
import java.util.Scanner;

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

        Scanner sc = new Scanner(System.in);
        
        int h =  sc.nextInt();
        int a = sc.nextInt();

        int count = 0;
        while(h > 0) {
            h -= a;
            count++;
            // System.out.println(count);
        }

        System.out.println(count);

        sc.close();
    }
}


Measured memory_bytes: 21844
package main

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

const mod = 1000000007

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

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

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

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

func main() {
	A, B, C, x := nextInt(), nextInt(), nextInt(), nextInt()

	res := 0
	for a := A; a >= 0; a-- {
		for b := B; b >= 0; b-- {
			for c := C; c >= 0; c-- {
				if 500*a+100*b+50*c == x {
					res++
				}
			}
		}
	}

	fmt.Println(res)
}


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

typedef long long ll;

int main(){
  ll A,B,Q;
  cin >> A >> B >> Q;
  vector<ll> s(A), t(B);
  for (int i=0; i<A; i++) cin >> s[i];
  for (int i=0; i<B; i++) cin >> t[i];
  for (int i=0; i<Q; i++){
    ll x; cin >> x;
    ll jin = lower_bound(s.begin(), s.end(), x) - s.begin();
    ll ter = lower_bound(t.begin(), t.end(), x) - t.begin();
    ll jin_lef=-1, jin_rig=-1, ter_lef=-1, ter_rig=-1;
    if (jin>0) jin_lef = s[jin-1];
    if (jin<A) jin_rig = s[jin];
    if (ter>0) ter_lef = t[ter-1];
    if (ter<B) ter_rig = t[ter];
    ll ans = 1e16;
    if (jin_lef>0&&ter_lef>0) ans = min(ans, x-min(jin_lef, ter_lef));
    if (jin_rig>0&&ter_lef>0) ans = min(ans, jin_rig-ter_lef+min(jin_rig-x, x-ter_lef));
    if (jin_lef>0&&ter_rig>0) ans = min(ans, ter_rig-jin_lef+min(ter_rig-x, x-jin_lef));
    if (jin_rig>0&&ter_rig>0) ans = min(ans, max(jin_rig, ter_rig)-x);
    cout << ans << endl;
  }
}


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

int main()
{ 
  int k, s ;
  cin >> k >> s ;

  int count = 0 ;
  for(int x = 0 ; x <= k ; x++)
  {
    for(int y = 0 ; y <= k ; y++)
    {
      int z = s - (x + y) ;
      if( z >= 0 && z <= k )
      {
        count++ ;
        //cout << x << " " << y << " " << s -(x + y) << endl;
      }
    }
  }

  cout << count << endl ;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  string S;
  cin >> S;
  ll K;
  cin >> K;
  ll N[S.size()];
  for (int i = 0; i < S.size(); i++) {
    N[i] = (123 - S[i]) % 26;
  }
  for (int i = 0; i < S.size(); i++) {
    if (N[i] <= K) {
      S[i] = 'a';
      K -= N[i];
    }
  }
  K = K % 26;
  S[S.size() - 1] += K;
  cout << S << endl;
  return 0;
}


Measured memory_bytes: 1408
def examA():
    N = I()
    ans = N//2 + N%2
    print(ans)
    return

def examB():
    A = [LI()for _ in range(3)]
    N = I()
    B = [I()for _ in range(N)]
    grid = [[False]*3 for _ in range(3)]
    ans = "No"
    for b in B:
        for i in range(3):
            for j in range(3):
                if A[i][j]==b:
                    grid[i][j] = True
    for i in range(3):
        flag = True
        for j in range(3):
            if not grid[i][j]:
                flag = False
        if flag:
            ans = "Yes"
    for i in range(3):
        flag = True
        for j in range(3):
            if not grid[j][i]:
                flag = False
        if flag:
            ans = "Yes"
    flag = True
    for i in range(3):
        if not grid[i][i]:
            flag = False
    if flag:
        ans = "Yes"
    flag = True
    for i in range(3):
        if not grid[i][2-i]:
            flag = False
    if flag:
        ans = "Yes"
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

import sys,copy,bisect,itertools,heapq,math,random
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = 10**(-12)
alphabet = [chr(ord('a') + i) for i in range(26)]

if __name__ == '__main__':
    examB()

"""

"""

Measured memory_bytes: 5988
import math
n = int(input())
ll = [list(map(int,input().split())) for _ in [0]*n]
dist = 0
for i in range(n):
  for j in range(i+1,n):
    dist += math.sqrt((ll[i][0]-ll[j][0])**2 + (ll[i][1]-ll[j][1])**2)
print(dist*2/n)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	int n;
	while(cin >> n, n){
		vi cnt(26);
		bool fin = 0;
		rep(i, n){
			char x; cin >> x;
			if(fin) continue;
			
			int idx = x - 'A';
			cnt[idx]++;
			
			int mxi = max_element(all(cnt)) - cnt.begin();
			bool ok = 1;
			
			rep(j, 26) if(j != mxi && cnt[mxi] <= cnt[j] + n - i - 1) ok = 0;
			if(ok){
				cout << (char)('A' + mxi) << " " << i+1 << endl;
				fin = 1;
			}
		}
		if(!fin) cout << "TIE" << endl;
	}
	return 0;
}

Measured memory_bytes: 3204
// https://atcoder.jp/contests/abc069/tasks/arc080_a
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define REP(i, n) FOR(i, 0, n)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    map<int, int> mp;
    REP(i, n) {
        int t;
        cin >> t;
        if (t % 4 == 0) {
            mp[4]++;
        } else if (t % 2 == 0) {
            mp[2]++;
        }
    }
    int cnt = mp[4] + mp[2] / 2;
    if (cnt >= n / 2) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#define MAXN 55
int a[MAXN][2], b[MAXN][2];
int main() {
    int n, m, mn, k;
    scanf("%d%d", &n, &m);
    for(int i = 1; i <= n; i++)
        scanf("%d%d", &a[i][0], &a[i][1]);
    for(int i = 1; i <= m; i++)
        scanf("%d%d", &b[i][0], &b[i][1]);
    for(int i = 1; i <= n; i++) {
        mn = 0x7fffffff;
        k = 1;
        for(int j = 1; j <= m; j++) {
            int t = abs(a[i][0] - b[j][0]) + abs(a[i][1] - b[j][1]);
            if(mn > t) {
                mn = t;
                k = j;
            }
        }
        printf("%d\n", k);
    }

    return 0;
}


Measured memory_bytes: 128
/*|In The Name Of Allah|*/

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

const int N = 2e5+5;
const int mod = 1e9+7;

ll n;
ll k;
ll ways[N];
ll ans;

int fastP(int b, int e){
    if(!e)
        return 1;
    if(e & 1)
        return b * 1ll * fastP(b * 1ll * b % mod, e >> 1) % mod;
    return fastP(b * 1ll * b % mod, e >> 1) % mod;
}

int main(){
    scanf("%d%d" , &n , &k);
    for(int i = k; i >= 1; i--){
        ll all = k / i;
        ways[i] = fastP(all , n);
        for(int j = i+i; j <= k; j += i){
            ways[i] -= ways[j];
        }
        assert(ways >= 0);
        ans += (((1LL * ways[i] * i) % mod));
    }
    cout << ans%mod << endl;
}


Measured memory_bytes: 4440