akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int h, w; cin >> h >> w;
    int n; cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];

    int dx[4] = { 1, 0, -1, 0 };
    int dy[4] = { 0, 1, 0, -1 };
    int d = 0;

    int board[100][100];
    rep(y, 100) rep(x, 100) board[x][y] = -1;

    int x = 0, y = 0;
    rep(i, n) {
        rep(cnt, a[i]) {
            board[x][y] = i + 1;
            int nx = x + dx[d];
            int ny = y + dy[d];
            if(nx < 0 || w <= nx || ny < 0 || h <= ny || board[nx][ny] != -1)
                d = (d + 1) % 4;
            x += dx[d];
            y += dy[d];
        }
    }
    rep(y, h) {
        rep(x, w) {
            cout << board[x][y];
            if(x != w-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <fstream>
#include <cmath>

using namespace std;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
typedef long long ll;
const ll INF = 1ll << 60;

int main()
{

    int x, y;
    cin >> x;
    cin >> y;

    int ans = -19999;
    ans = max(x * y, ans);
    ans = max(x + y, ans);
    ans = max(x - y, ans);

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

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;


vector<int> dist(100010,MOD);
bool f = true;

void dfs(const Graph &node, int N){
 
  REP(i,node[N].size()){
    P p = node[N][i];  // ノードのエッジ情報をとる．
    ll next = p.first;  // 次のノード番号

    if(dist[next] == MOD){ //　未訪問なら距離を計算
      dist[next] = dist[N] + p.second;   // 現在置に重みを加算
	  dfs(node,next);
    }
    
    else if(dist[next] != dist[N] + p.second){  // 訪問済みなら矛盾チェック
      f = false; return;
    }

  }

  return;
}
    

int main(){

  int n,m;
  cin >> n >> m;
  
  Graph node(n);
  
  REP(i,m){
    int a,b,v;
    cin >> a >> b >> v;
    a--;b--;
    node[a].push_back(P(b,v));
    node[b].push_back(P(a,-v));
  }
  
  REP(i,n){
    if(dist[i] == MOD){ // 新しい部分木ならば，それを０に初期化
      dist[i] = 0;
    dfs(node,i);  // 条件を満たさないと打ち切られる
    }
  }
  
  if(f)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  
 return 0;
}

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

int main() {

    string str1,str2,str3,str4;
    cin >> str1;
    str2 = str1;
    size_t size = str1.length();
    int i,j,k,h =0;
    
    for(i=0,j = size; i < j; i++,j-- ){
	str3 = str1.substr(i,1);
	str4 = str2.substr(j-1,1);	
	
      
      if(str3!=str4){
      h+=1;
      }
	
	}
	cout << h <<endl;

}


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

int main(void)
{
    int m, n;
    int i;
    int s[100001];
    int ans;
    int now, move;
    
    scanf("%d%d", &n, &m);
    
    s[0] = 0;
    for (i = 1; i < n; i++){
        scanf("%d", &s[i]);
        
        s[i] += s[i - 1];
    }
    
    now = move = 0;
    
    for (i = 0; i < m; i++){
        scanf("%d", &move);
        
        ans += (abs(s[now + move] - s[now]));
        ans %= 100000;
        now += move;
    }
    
    printf("%d\n", ans);
    return (0);
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <sstream>
#include <queue>
#include <map>
#include <vector>
#include <set>
#include <cstdlib>
#include <stack>

using namespace std;

typedef long long LL;
typedef double db;
#define FAST ios::sync_with_stdio(false);
#define gcd(a,b) __gcd(a,b)
#define sqre(x) (x)*(x)
#define mem(x,y) memset(x,t,sizeof(x))
const int MaxN = 1005;
const int inf = 1e8;
const double PI = acos(-1);


int main()
{
	string a,b; cin >> a >> b;
	int len1 = a.length(), len2 = b.length();
	if(a == b) 
	cout << "EQUAL" << endl;
	else{
	if(len1 < len2)cout << "LESS" << endl;
	else if(len1 > len2)cout << "GREATER" << endl;
	else{
		for(int i = 0 ; i < len1 ; i++){
			if(a[i] == b[i])continue;
			if(a[i] > b[i]){cout << "GREATER" << endl;break;}
			if(a[i] < b[i]){cout << "LESS" << endl;break;}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>

using namespace std;

int main(){

  string S, T; cin >> S >> T;

  bool ans = false;
  for (int i = S.length() - T.length(); i >= 0; i--){
    bool flag = true;

    for (int j = 0; j < T.length(); j++){
      if (S[i + j] != T[j] && S[i + j] != '?'){
        flag = false;
        break;
      }
    }

    if (flag == true){
      ans = true;
      for (int j = 0; j < T.length(); j++){
        S[i + j] = T[j];
      }
      break;
    }
  }

  if (ans == true){
    for (int i = 0; i < S.length(); i++){
      if (S[i] == '?'){
        S[i] = 'a';
      }
    }
  }else{
    S = "UNRESTORABLE";
  }
  cout << S << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); ++i)
int main(void) {
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(0, b + c - a) << endl;
  return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    string S;
    cin>>S;

    if((S[0]==S[S.size()-1])==S.size()%2){
        cout<<"Second"<<endl;
    }
    else{
        cout<<"First"<<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
int main(void){
    string S;
    cin >> S;
    string T = "keyence",S1 = " ", S2 = " ",T1;
    int k = 0;
    bool flag = true;
    for(int i = 0; i < S.size(); i++){
        if(S[i] != T[k] && flag == true){
            flag = false;
            S1 = S.substr(0,i);
            reverse(T.begin(),T.end());
            T1 = T.substr(0,7-k);
        }
        /*else if(S[i] == T[k] && flag == false){
            S2 = S.substr(i,S.size()-i);
            break;
        }
        k++;
        //else if(flag == true && k == 7) break;*/
        k++;
    }
    //cout << T1 << endl;
    if(flag == false){
        reverse(S.begin(),S.end());
        if(S.substr(0,T1.size()) == T1){
            S2 = T1;
            reverse(S2.begin(),S2.end());
        }
        /*for(int i = 0; i < S.size() - T.size(); i++){
            if(S.substr(0,T1.size()) == T1){
                S2 = T1;
                reverse(S1.begin(),S2.begin());
                cout << "YES" << endl;
                exit(0);
            }
        }*/
    }
    reverse(T.begin(),T.end());
    reverse(S.begin(),S.end());
    string S3 = S1 + S2;
    //cout << S1 << " " << S2 << " " << S3 << endl;
    if(S1 == T || S2 == T || S3 == T || S == T) cout << "YES" << endl;
    else cout << "NO" << endl;
}

Measured memory_bytes: 3612
//BISMILLAH
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ve vector<int>
#define FOR(n)          for(int i=0; i<(int)(n); ++i)

int main( )
{
   double d,t,s;
   cin>>d>>t>>s;
   double res=d/s;
   if(res<=t) cout<< "Yes"<<endl;
   else cout<< "No"<<endl;

  return 0;
}

Measured memory_bytes: 3720
#include <cstdio>

using namespace std;

int
main (
  )
{
  int n;

  scanf ( "%d", &n );
  while ( n-- )
  {
    int y, m, d;
    int res = 0;

    scanf ( "%d%d%d", &y, &m, &d );
    while ( y != 1000 || m != 1 || d != 1 )
    {
      ++d;

      if ( y % 3 == 0 )
      {
        if ( d > 20 )
        {
          d = 1;
          ++m;
        }
      }
      else
      {
        if ( m % 2 == 0 )
        {
          if ( d > 19 )
          {
            d = 1;
            ++m;
          }
        }
        else
        {
          if ( d > 20 )
          {
            d = 1;
            ++m;
          }
        }
      }

      if ( m > 10 )
      {
        ++y;
        m = 1;
      }

      ++res;
    }

    printf ( "%d\n", res );
  }

  return ( 0 );
}

Measured memory_bytes: 756
N = gets.to_i
A = gets.split(" ").map { |item| item.to_i }
A.freeze

# for i in 0..N-1 do
#   array = A.dup
#   array.delete_at(i+1)
#   ryohi = array[0].abs
#   for j in 0..N-2 do
#     ryohi += (array[j+1] - array[j]).abs
#   end
#   ryohi += array[N-1].abs
#   puts ryohi
# end

all = A[0].abs
for i in 0..N-2 do
  all += (A[i+1] - A[i]).abs
end

for i in 0..N-1 do
  if i==0
    ryohi = all - (A[0]).abs - (A[1]-A[0]).abs + (A[1]).abs + A[N-1].abs
  elsif i == N-1
    ryohi = all - (A[i]-A[i-1]).abs + A[N-2].abs
  else
    ryohi = all - (A[i]-A[i-1]).abs - (A[i+1]-A[i]).abs + (A[i+1]-A[i-1]).abs + A[N-1].abs
  end
  puts ryohi
end




Measured memory_bytes: 11544
#include <iostream>
#include <vector>
#include <algorithm>

#define MOD 1000000000 + 7
#define MAX 100000

using namespace std;

int H, W, A, B;

long long fact[MAX+MAX-1];
long long fact_inv[MAX+MAX-1];

long long power(long long n_fact, long long exp){
    long long ret = 1;
    while(exp != 0){
        if(exp & 1){
            ret *= n_fact;
            ret %= MOD;
        }
        n_fact *= n_fact;
        n_fact %= MOD;
        exp >>= 1;
    }

    return ret;

}

int main(){
    cin >> H >> W >> A >> B;

    fact[0] = 1;

    for(int i = 1; i <= H+W-2; i++){
        fact[i] = fact[i-1] * i;
        fact[i] %= MOD;
    }

    fact_inv[H+W-2] = power(fact[H+W-2], MOD-2);

    for(int i = H+W-3; i >= 0; i--){
        fact_inv[i] = fact_inv[i+1] * (i+1);
        fact_inv[i] %= MOD;
    }
    
    long long ans = 0;
    long long temp;
    
    for(int i = B; i < W; i++){
        temp = fact[H-A-1+i] * fact_inv[H-A-1];
        temp %= MOD;
        temp *= fact_inv[i];
        temp %= MOD;
        temp *= fact[(A-1)+(W-i-1)];
        temp %= MOD;
        temp *= fact_inv[A-1];
        temp %= MOD;
        temp *= fact_inv[W-i-1];
        temp %= MOD;
        ans += temp;
        ans %= MOD;
    }

    cout << ans << endl;

    return 0;
}

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

void input()
{
    #ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
    #endif
}
#define endl "\n"
#define ll long long int
#define vll vector<ll>
#define pb push_back
#define pll pair<ll,ll>
#define mp(a,b) make_pair(a,b)
#define ff first
#define ss second
#define tll tuple<ll,ll,ll>
#define mt make_tuple
#define INF LONG_LONG_MAX
#define mod 1000000007
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define cases ll t; cin>>t; while(t--)
#define array(a,n) vll a(n); rep(i,0,n) cin>>a[i];
#define sortall(a) sort(a.begin(),a.end())
#define printall(a) rep(i,0,a.size()) cout<<a[i]<<" "; cout<<endl;

// --------------- My Template End --------------- //
bool isprime(ll n)
{
    if(n%2==0)return false;
    for(int i=3;i<=sqrt(n);i+=2)
    {
        if(n%i==0)return false;
    }
    return true;
}

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    //input();
    ll n;
    cin>>n;
    array(a,n);
    ll temp=0;
    vector<ll>ans(n);
    	rep(j,0,n)
    	{
    		temp^=a[j];
    	}
    	
    rep(i,0,n)
    {
    	ans[i]=temp^a[i];
    }
    
    printall(ans);
}





Measured memory_bytes: 6332
#include <algorithm>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
// const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

int A, B;

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

  int ans = A - B * 2 < 0 ? 0 : A - B * 2;

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define oo 0x3f3f3f3f
#define ooLL 0x3f3f3f3f3f3f3f3f
#define fastio() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int mod = 1e9+7;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> ii;
 
int main(){
    int n;
    ull k;
    scanf("%d%llu", &n, &k);
    vector<int> v(n+1);
    for(int i = 1; i <= n ; ++i){
        scanf("%d", &v[i]);
    }
    int pos = 1, start = 1;
    ull ntimes = 0ULL;
    ull ori = k;
    vector<ll> freq(n+1, -1);
    int cnt = 0;
    while(k > 0){
        pos = v[pos];
        k--;
        ntimes++;
        if(freq[pos] != -1) k = (k % (ntimes-freq[pos]));
        freq[pos] = ntimes;
    }
    printf("%d\n", pos);
    return 0;
}

Measured memory_bytes: 5652
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
int main(){
    int x;
    cin >> x;
    string ans ="NO";
    if(x==7||x==5||x==3){
        ans = "YES";
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for(ll i = a; i > b; i--)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    ll N;
    cin >> N;
    for(ll i = N; i > 0; i--) {
        int root = (int)sqrt(i);
        if(pow(root, 2) == i) {
            cout << i << "\n";
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <iomanip>
#include <functional>
#include <cassert>

using namespace std;

typedef long long ll;

int main() {
  ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef LOCAL
  freopen("input.txt", "r", stdin);
#endif
  int A, B, M;
  cin >> A >> B >> M;
  vector <int> a(A);
  int ma = 1e9;
  for (int i = 0; i < A; ++i) {
    cin >> a[i];
    ma = min(ma, a[i]);
  }
  vector <int> b(B);
  int mb = 1e9;
  for (int i = 0; i < B; ++i) {
    cin >> b[i];
    mb = min(mb, b[i]);
  }
  int ans = ma + mb;
  for (int i = 0; i < M; ++i) {
    int x, y, z;
    cin >> x >> y >> z;
    --x, --y;
    ans = min(ans, a[x] + b[y] - z);
  }
  cout << ans << '\n';
}



Measured memory_bytes: 1024
#define dbg(fmt,...) fprintf(stderr,fmt,__VA_ARGS__)
#define dpri(x) dbg(#x ": %d\n", x)
#define dprs(x) dbg(#x ": %s\n", x)
#include <stdio.h>
const int INF = 1e9+7;

void swap(int *x, int *y)
{
	int tmp = *x;
	*x = *y;
	*y = tmp;
}

int main(int argc, char **argv)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if (a > b) swap(&a, &b);
	if (b > c) swap(&b, &c);
	if (a > b) swap(&a, &b);
	printf("%d %d %d\n", a, b, c);
	return 0;
}

Measured memory_bytes: 596
#!/usr/bin/env python3
import sys
from math import *
from itertools import *
from collections import *
from functools import *
try:
    from math import gcd
except Exception:
    from fractions import gcd


def solve(S: str):
    y, m, d = [int(x) for x in S.split('/')]
    if y < 2019:
        return 'Heisei'
    if y == 2019 and m <= 4:
        return 'Heisei'
    return 'TBD'


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    S = next(tokens)  # type: str
    result = solve(S)
    print(result)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = 3.14159265358979323846;

int main(){
    int n,m;cin>>n>>m;int a[n][m],b[m];
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin>>a[i][j];
        }
    }
    for(int i=0;i<m;i++) cin>>b[i];
    for(int i=0;i<n;i++){
        int sum=0;
        for(int j=0;j<m;j++){
            sum+=b[j]*a[i][j];
        }
        cout<<sum<<endl;
    }
}


Measured memory_bytes: 3108
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  long N;
  vector<long> t;

  cin >> N;
  for (int i = 0; i < 5; ++i) {
    long k;
    cin >> k;
    t.push_back(k);
  }
  long min = *min_element(begin(t), end(t));
  cout << ((N - 1) / min) + 5 << endl;
  return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod 1000000007
#define pb push_back
#define in(a) int a;cin>>a;
#define in2(a,b)in(a)in(b)
#define out(x) cout<<x<<endl;
#define out2(x,y) cout<<x<<" "<<y<<endl;

int32_t main()
{
    in(n);
    int a[n+1];
    for(int i=1;i<=n;i++){
    	cin>>a[i];
    }
    int dp[n+1]={0};
 	dp[2]=abs(a[2]-a[1]);
 	for(int i=3;i<=n;i++){
 		int num1=dp[i-1]+abs(a[i]-a[i-1]);
 		int num2=dp[i-2]+abs(a[i]-a[i-2]);
 		dp[i]=min(num1,num2);
 	}
 	out(dp[n])
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
using namespace std;

int p2(int n) {
	if (n == 0) return 1;
	return 2 * p2(n-1);
}

int main() {
	
	int n;
	cin >> n;
	int x = p2(n);
	int arr[x];
	multiset<int> av, slimes;
	for (int i=0; i<x; i++) {
		cin >> arr[i];
	}
	
	sort(arr, arr+x);
	/*for (int i=0; i<x; i++) {
		cout << arr[i] << ' ';
	}
	cout << endl;*/
	
	slimes.insert(arr[x-1]);
	for (int i=0; i<x-1; i++) {
		av.insert(arr[i]);
	}
	
	for (int i=0; i<n; i++) {
		multiset<int> nextgen;
		for (multiset<int>::iterator x=slimes.begin(); x!=slimes.end(); ++x) {
			// cout << i << " " << *x << endl;
			int th = *x;
			multiset<int>::iterator f=av.lower_bound(th);
			if (f == av.begin()) {
				cout << "No" << endl;
				exit(0);
			}
			--f;
			nextgen.insert(*f);
			av.erase(f);
		}
		for (multiset<int>::iterator x=nextgen.begin(); x!=nextgen.end(); x++) {
			slimes.insert(*x);
		}
	}
	
	
	cout << "Yes" << endl;
	
	
	
}


Measured memory_bytes: 19712
fun main(args: Array<String>) {
    // Your code here!
    var (n,k) = readLine()!!.split(" ").map{it.toLong()}
    var calc:Long = 0
    var res:String = ""
    
    
    while(n >= k){
        calc = n%k
        res = res + calc.toString()
        n = n/k
    }
    res = res + n.toString()
    println(res.length)
}


Measured memory_bytes: 35984
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) (x).begin(),(x).end()
using ll = long long;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }



int main() {
	
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	
	int a, b; cin >> a >> b;
	
	for(int i = 1;i < 1000000; i++){
		int aa = i * 0.08;
		int bb = i * 0.10;
		if(aa == a && bb == b){
			cout << i << endl;
			return 0;
		}
	}
	
	
	cout << -1 << endl;
	
	return 0;
}


Measured memory_bytes: 256
// Ver19.02
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#define INF 1 << 29
#define LLINF 4545454545454545454
#define MOD 1000000007
#define ll long long
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
int upll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? -1 : *(ll *)a > *(ll *)b ? 1 : 0; }
int downll(const void *a, const void *b) { return *(ll *)a < *(ll *)b ? 1 : *(ll *)a > *(ll *)b ? -1 : 0; }
void sortup(ll *a, int n) { qsort(a, n, sizeof(ll), upll); }
void sortdown(ll *a, int n) { qsort(a, n, sizeof(ll), downll); }

int main()
{
  int a, b, c;
  scanf("%d%d%d", &a, &b, &c);
  puts(b - a == c - b ? "YES" : "NO");
  return 0;
}

Measured memory_bytes: 128
using System;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Diagnostics;
using System.Numerics;
using Enu = System.Linq.Enumerable;

public class Program
{
    public void Solve()
    {
        int N = Reader.Int();
        var A = Reader.IntArray(N);
        Console.WriteLine(Enu.Range(-100, 201).Min(x => A.Sum(a => (a - x) * (a - x))));
    }
}


class Entry { static void Main() { new Program().Solve(); } }
class Reader
{
    static TextReader reader = Console.In;
    static readonly char[] separator = { ' ' };
    static readonly StringSplitOptions op = StringSplitOptions.RemoveEmptyEntries;
    static string[] A = new string[0];
    static int i;
    static void Init() { A = new string[0]; }
    public static void Set(TextReader r) { reader = r; Init(); }
    public static void Set(string file) { reader = new StreamReader(file); Init(); }
    public static bool HasNext() { return CheckNext(); }
    public static string String() { return Next(); }
    public static int Int() { return int.Parse(Next()); }
    public static long Long() { return long.Parse(Next()); }
    public static double Double() { return double.Parse(Next()); }
    public static int[] IntLine() { return Array.ConvertAll(Split(Line()), int.Parse); }
    public static int[] IntArray(int N) { return Range(N, Int); }
    public static int[][] IntTable(int H) { return Range(H, IntLine); }
    public static string[] StringArray(int N) { return Range(N, Next); }
    public static string[][] StringTable(int N) { return Range(N, () => Split(Line())); }
    public static string Line() { return reader.ReadLine().Trim(); }
    public static T[] Range<T>(int N, Func<T> f) { var r = new T[N]; for (int i = 0; i < N; r[i++] = f()) ; return r; }
    static string[] Split(string s) { return s.Split(separator, op); }
    static string Next() { CheckNext(); return A[i++]; }
    static bool CheckNext()
    {
        if (i < A.Length) return true;
        string line = reader.ReadLine();
        if (line == null) return false;
        if (line == "") return CheckNext();
        A = Split(line);
        i = 0;
        return true;
    }
}

Measured memory_bytes: 2904
#include<stdio.h>
int main(){
  int num,i=0,j=0,k=0,key;
  scanf("%d",&num);
  int stuck[num];
  for(i=0;i<num;i++){
    scanf("%d",&stuck[i]);
  }
  for(k=0;k<num;k++){
    if(k==num-1) printf("%d\n",stuck[k]);
    else  printf("%d ",stuck[k]);
  }
  for(i=1;i<num;i++){
    key=stuck[i];
    j=i-1;
    while(j>=0 && stuck[j]>key){
      stuck[j+1]=stuck[j];
      j--;
    }
    stuck[j+1]=key;
    for(k=0;k<num;k++){
      if(k==num-1)printf("%d\n",stuck[k]);
      else printf("%d ",stuck[k]);
    } 
  }

  return 0;
}



Measured memory_bytes: 2064
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;

signed main(void)
{
	int n, k;
	string s;
	long long ans, cnt, tmp;
	vector<long long> sum;
	char look;

	cin >> n >> k >> s;
	look = '1';
	cnt = 0;
	rep(i, n)
	{
		if (look == s[i])
			cnt++;
		else
		{
			sum.push_back(cnt);
			look = s[i];
			cnt = 1;
		}
	}
	if (cnt != 0) 
		sum.push_back(cnt);
	if (s[n - 1] == '0') 
		sum.push_back(0);
	rep(i, sum.size() - 1) 
		sum[i + 1] += sum[i];

	ans = sum[0];
	for(int i = 0; i < sum.size(); i+=2)
	{
		int index  = min((int)i + 2 * k, (int)sum.size() - 1);
		tmp = sum[index];
		if (i - 1 >= 0)
			tmp -= sum[i - 1];
		ans = max(ans, tmp);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1528
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    map<string, ll> m;
    ll countMax = 0;
    string S;
    rep(i, N){
        cin >> S;
        if(m.find(S) == m.end()){
            m[S] = 1;
        }else{
            m[S]++;
        }
        countMax = max(countMax, m[S]);
    }

    for(auto itr = m.begin(); itr != m.end(); itr++){
        if(itr->second == countMax){
            cout << itr->first << endl;
        }
    }

    return 0;
}

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

int main(){
  string str;
  cin >> str;
  int max = 0;
  int tmp = 0;
  for (auto ss:str){
    if (ss == 'A' || ss == 'C' || ss == 'G' || ss == 'T'){
      tmp++;
    }else{
      if (tmp > max){
        max = tmp;
      }
      tmp = 0;
    }
  }
  if (tmp > 0 && tmp > max){
     max = tmp;
  }
  cout << max << endl;
  return 0;
}


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

immutable long MOD = 10^^9 + 7;
long[] F, G;

void main() {
    auto s = readln.split.map!(to!int);
    auto H = s[0];
    auto W = s[1];
    auto N = s[2];
    auto RC = N.iota.map!(_ => readln.split.map!(x => x.to!int-1).array).array;
    RC.sort();
    RC ~= [H-1, W-1];
    N += 1;

    F = new long[](H+W+5);
    G = new long[](H+W+5);
    F[0] = F[1] = G[0] = G[1] = 1;
    foreach (i; 2..H+W+5) F[i] = F[i-1] * i % MOD;
    foreach (i; 2..H+W+5) G[i] = powmod(F[i], MOD-2, MOD);


    auto dp = new long[](N);

    foreach (i; 0..N) {
        dp[i] = comb(RC[i][0] + RC[i][1], RC[i][0]);
        foreach (j; 0..i) {
            if (RC[j][0] <= RC[i][0] && RC[j][1] <= RC[i][1]) {
                dp[i] -= dp[j] * comb(RC[i][0] - RC[j][0] + RC[i][1] - RC[j][1], RC[i][0] - RC[j][0]) % MOD;
                dp[i] %= MOD;
            }
        }
    }

    dp[N-1] = (dp[N-1] + MOD) % MOD;
    dp[N-1].writeln;
}

long comb(long n, long r) {
    return F[n] * G[r] % MOD * G[n-r] % MOD;
}

long powmod(long a, long x, long m) {
    long ret = 1;
    while (x) {
        if (x % 2) ret = ret * a % m;
        a = a * a % m;
        x /= 2;
    }
    return ret;
}


Measured memory_bytes: 4476
from collections import deque
H,W = map(int, input().split())
A = 0
dp = [None] * H
mat = deque()
for h in range(H):
    s = list(input())
    for w, x in zip(range(W), s):
        if x == "#":
            mat.append((h, w, 0))
    dp[h] = s

while len(mat):
    h, w, cnt = mat.popleft()

    for t, h, w, cnt in [(h > 0, h - 1, w, cnt),(h < H-1, h + 1, w, cnt),(w > 0, h , w - 1, cnt),(w < W-1, h , w + 1, cnt)]:
        if t and dp[h][w] == ".":
            mat.append((h, w, cnt+1))
            dp[h][w] = "#"

print(cnt)


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

const int maxn = 1e5 + 10;

int n;
int a[maxn];
int chooseN;
int chooseR;


int main() {

  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    chooseN = max(chooseN, a[i]);
  }

  int mid = chooseN/2;
  int dst = INT_MAX;

  for (int i = 0; i < n; i++) {
    if (a[i] == chooseN) continue;

    int curdst = abs(mid - a[i]);
    if (curdst < dst) {
      chooseR = a[i];
      dst = curdst;
    }
  }

  cout << chooseN << " " << chooseR << endl;
  return 0;
}


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

using namespace std;

int N, M;
int mat[9][9];
int rest[9];

int rec(int team, int enemy) {
  if(team == N) return 1;
  if(enemy == N) return rec(team + 1, 0);
  if(~mat[team][enemy]) return rec(team, enemy + 1);
  int ret = 0;
  if(rest[team] > 0) {
    rest[team]--;
    mat[team][enemy] = 1;
    mat[enemy][team] = 0;
    ret += rec(team, enemy + 1);
    mat[team][enemy] = -1;
    mat[enemy][team] = -1;
    rest[team]++;
  }
  if(rest[enemy] > 0) {
    rest[enemy]--;
    mat[team][enemy] = 0;
    mat[enemy][team] = 1;
    ret += rec(team, enemy + 1);
    mat[team][enemy] = -1;
    mat[enemy][team] = -1;
    rest[enemy]++;
  }
  return ret;
}

int main() {
  while(cin >> N, N) {
    cin >> M;
    memset(mat, -1, sizeof(mat));
    for(int i = 0; i < M; i++) {
      int x, y;
      cin >> x >> y;
      --x, --y;
      mat[x][y] = 1;
      mat[y][x] = 0;
    }
    bool flag = false;
    for(int i = 0; i < N; i++) {
      rest[i] = N / 2;
      mat[i][i] = 2;
      for(int j = 0; j < N; j++) {
        if(mat[i][j] == 1) rest[i]--;
      }
      if(rest[i] < 0) flag = true;
    }
    if(flag) cout << 0 << endl;
    else cout << rec(0, 0) << endl;
  }
}


Measured memory_bytes: 3012
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007; // 998244353
using ll = long long;
using namespace std;

// res[k] := k を gcd として持つようなタプルの個数
ll res[100010];

ll power( ll a, ll b ){
	ll res = 1;
	while( b > 0 ){
		if( b & 1 ) res = res*a % mod;
		a = a*a % mod;
		b >>= 1;
	}
	return res;
}

int main(){
	int n; ll k; cin >> n >> k;
	ll ans = 0;
	// 上から結果を計算することで x の倍数が gcd になる場合を除外できる
	for( ll x = k; x >= 1; --x ){
		res[x] = power(k/x, n);
		ll m = 2;
		while( m*x <= k ){
			res[x] += ( mod - res[m*x] ) % mod;
			res[x] %= mod;
			++m;
		}
		ans += ( x * res[x] ) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 4404
inf = float('inf')

n, *goal = map(int, input().split())
l = [int(input()) for _ in range(n)]

ans = inf
for q in range(4 ** n):
    m = [[] for _ in range(4)]
    lm = 0
    for j in range(n):
        idx = (q // (4 ** j)) % 4
        m[idx].append(l[j])
    if any(len(m[idx]) == 0 for idx in range(3)):
        continue

    cost = 0
    for idx in range(3):
        merge_time = len(m[idx]) - 1
        cost += merge_time * 10
        cost += abs(sum(m[idx]) - goal[idx])

    ans = min(ans, cost)

print(ans)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

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

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

ll nCr(int n, int r)
{
    if (n == r or n == 0)
        return 1;
    if (n < r)
        return 0;
    if (r == 1)
        return n;
    return nCr(n - 1, r - 1) + nCr(n - 1, r);
}

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    string S; cin >> S;

    if(S=="ABC") cout << "ARC" << endl;
    else cout << "ABC" << endl;    


    return 0;
}


Measured memory_bytes: 3656
#define _CRT_SECURE_NO_WARNINGS
//#define _USE_MATH_DEFINES
#include<stdio.h>
//#include<stdlib.h>
//#include<math.h>
//#include<string.h>
//#include<time.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)

int main() {
	int a, b, c, d, e, ans = 0;
	fscanf(stdin, "%d%d%d%d%d", &a, &b, &c, &d, &e);
	if (a < 0)ans += -a*c + d, a = 0;
	ans += (b - a)*e;
	P(d, ans);
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
typedef long long ll;

const int INF = 1e9;
ll n;

int main() {
  cin >> n;
  vector<int> v(n);
  rep(i, n) cin >> v[i];
  sort(v.begin(), v.end());
  double ans = (v[0] + v[1]) / 2.0;
  if (n > 2)
    for (int i = 2; i < n; i++) ans = (ans + v[i]) / 2;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

MOD = 10 ** 9 + 7


def func(q, A):
    return sum(q % a for a in A)


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N = ii()
    A = il()
    q = 1
    for a in A:
        q *= a
    ret = func(q - 1, A)
    print(ret)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
n = int(input())
a = list(map(int, input().split()))
m = []
_sum = 0
for i in range(n - 1):
    _sum += (-1) ** (i + 1) * a[i]
m.append((a[-1] - _sum) // 2)
for i in range(1, n):
    m.append(a[i - 1] - m[i - 1])
print(' '.join(map(lambda k: str(k * 2), m)))

Measured memory_bytes: 19148
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define INF 1100000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007
#define Decimal fixed << setpresicion(20)


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


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

  ll ans = 0;
  if (B <= C) {
    ans += 2*B;
    C -= B;
    B = 0;
  } else {
    ans += 2*C;
    B -= C;
    C = 0;
  }

  if (A <= C) {
    ans += A;
    C -= A;
    A = 0;
  } else {
    ans += C;
    A -= C;
    C = 0;
  }
  if (C > 0) ans++;
  if (B > 0) ans += B;

  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstring>
#include <utility>
#include <numeric>

using namespace std;

const int MOD = 1e9 + 7;

long long dp[100][100000];

int main(){

    int N, K;
    cin >> N >> K;

    vector<pair<int, int>> sector;

    int upper = N;
    for(int i = 1; i <= N; i++){
        if(i * i > N){
            break;
        }

        sector.push_back(make_pair(i, i));
        
        if(upper != i){
            int temp = N / (i + 1);
            sector.push_back(make_pair(temp + 1, upper));
            upper = temp;
        }
        
    }

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

    // for(int i = 0; i < (int)sector.size(); i++){
    //     auto temp = sector[i];
    //     cout << temp.first << " " << temp.second << endl;
    // }

    int L = (int)sector.size();
    vector<int> sectorLen(L);
    for(int i = 0; i < L; i++){
        auto sect = sector[i];
        sectorLen[i] = sect.second - sect.first + 1;
    }
    dp[0][0] = sectorLen[0];
    for(int i = 1; i < L; i++){
        auto sect = sector[i];
        dp[0][i] = (dp[0][i - 1] + sectorLen[i]) % MOD;
    }

    for(int i = 1; i < K; i++){
        dp[i][0] = (dp[i - 1][L - 1] * sectorLen[0]) % MOD; 
        for(int j = 1; j < L; j++){
            dp[i][j] = (dp[i][j - 1] + (dp[i - 1][L - j - 1] * sectorLen[j]) % MOD) % MOD;
        }
    }

    cout << dp[K - 1][L - 1] << endl;

    return 0;
}

Measured memory_bytes: 78200
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long[] A = new long[N];
		for(int i=0; i<N; i++)
			A[i] = sc.nextLong();

		final long MOD = 1000000007;
		
		int[] bit = new int[60];
		long[] counter = new long[60];
		for(int i=0; i<N; i++) {
			for(int j=0; j<60; j++) {
				if((A[i]&(1l<<j))==0) {
					counter[j] += bit[j];
				} else {
					counter[j] += i-bit[j];
					bit[j]++;
				}
			}
		}
		
		long ans = 0;
		for(int i=0; i<60; i++) {
			ans = (ans * 2) % MOD;
			ans = (ans + counter[60-i-1]) % MOD;
		}
		
		System.out.println(ans);
		sc.close();
	}
}


Measured memory_bytes: 98328
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
using namespace std;

#define ll long long int

const int MOD = 1000000007;

int max(int a, int b) {

	if (a > b)return a;
	else return b;

}
int main() {

	int N, x, a[100005];
	ll ball = 0, eall = 0;

	cin >> N >> x;
	for (int i = 0; i < N; i++) {

		cin >> a[i];
		ball += a[i];

	}

	if (a[0] > x)a[0] = x;
	for (int i = 0; i < N - 1; i++) {

		if (a[i] + a[i + 1] > x)a[i + 1] = x - a[i];

	}
	for (int i = 0; i < N; i++) {

		eall += a[i];

	}

	cout << ball - eall << endl;

	return 0;
}

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

using namespace std;

int main()
{
	deque<int> que;
	bool num[200001];
	fill(num,num+200001,false);
	int n,m;
	cin>>n>>m;
	for(int i=1;i<n+1;i++)
		que.push_back(i);
	for(int i=0;i<m;i++)
	{
		int e;
		cin>>e;
		que.push_front(e);
	}

	while(!que.empty())
	{
		int t=que[0];
		que.pop_front();
		if(!num[t])
		{
			cout<<t<<endl;
			num[t]=true;
		}
	}
	return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#ifdef LOCAL
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#define dassert(...) assert(__VA_ARGS__)
#else
#define dump(x)
#define debug(x)
#define dassert(...)
#endif
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;
const long double EPS = 1e-8;

void solve(long long N, std::vector<long long> A){
    // dp[used num is larger than 2/n][until i]
    vector<vector<ll>> dp(3, vector<ll> (N+1));
    rep(i,0,N) {
        if (i % 2 == 0) {
            dp[2][i+1] = (i>0 ? dp[2][i-1] : 0) + A[i];
            dp[1][i+1] = max((i>0 ? dp[1][i-1] : 0) + A[i], dp[1][i]);
        } else {
            dp[1][i+1] = max((i>0 ? dp[1][i-1] : 0) + A[i], dp[2][i]);
            dp[0][i+1] = max((i>0 ? dp[0][i-1] : 0) + A[i], dp[1][i]);
        }
    }
    cout << dp[1][N] << endl;
}

signed main(){
    // ios_base::sync_with_stdio(false);
    // cin.tie(NULL);
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 11200
// KNOW NOTHING!
#include <bits/stdc++.h>
#define ll long long int
#define F(i,j,k,in) for(int i=j;i<k;i+=in)
#define DF(i,j,k,in) for(int i=j;i>=k;i-=in)
#define feach(it,l) for (auto it = l.begin(); it != l.end(); ++it)
#define fall(a) a.begin(),a.end()
#define sz(x) (int)x.size()
#define szs(x) (int)s.length()
#define pb push_back
#define ub upper_bound
#define lb lower_bound
#define eq equal_range
#define fs first
#define ss second
#define ins insert
#define mkp make_pair
#define endl "\n"
using namespace std;
typedef vector<ll> vll;
typedef vector<int> vin;
typedef vector<char> vch;
typedef vector<string> vst;
typedef set<ll> sll;
typedef set<int> sint;
typedef set<char> sch;
typedef set<string> sst;
typedef queue<ll> qll;
typedef queue<int> qin;
typedef deque<ll> dqll;
typedef deque<int> dqint;
typedef priority_queue<ll> pqll;
typedef priority_queue<int> pqin;
typedef map<ll,ll> mpll;
typedef map<int,int> mpin;
typedef pair<ll,ll> pll;
typedef pair<int,int> pin;
const ll MOD=1000000007;
const long double PI=3.1415926535897932384626433832795;
ll pwr(ll b,ll p){ll res=1;while(p){if(p&1) {res*=b; p--;}else{b*=b; p>>=1;}}return res;}

int main()
{
/*
freopen ("input.txt","r","stdin");
freopen ("output.txt","w","stdout");
*/
ios_base::sync_with_stdio(false) , cin.tie(NULL) , cout.tie(NULL);
ll n; cin>>n;
vll A (n);
mpll mp;
F (i,0,n,1) {cin>>A[i]; ++mp[A[i]];}
ll q; cin>>q;
ll sum = 0;
sum = accumulate (fall(A),0LL);
F (i,0,q,1) {
	ll a , b; cin>>a>>b;
	sum=sum-mp[a]*a+mp[a]*b;
	mp[b]+=mp[a];
	mp.erase(a);
	cout<<sum<<endl;
}

return 0;
}
/* What we know is a drop , but what we don't know is an ocean !*/

Measured memory_bytes: 7940
//#include <bits/stdc++.h>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>

using namespace std;

typedef long long ll;
const ll nmax = 1e9 + 7;
const ll mod = 998244353;
const double PI = 2 * asin(1);


int main(){
  int N; ll M, V, P;
  cin >> N >> M >> V >> P;

  vector <ll> A(N);
  for (int i = 0; i < N; i++) cin >> A[i];
  sort(A.begin(), A.end(), greater<ll>());

  int L = P - 1, R = N;
  while (true){
    int now = (L + R) / 2;

    if (A[now] + M < A[P - 1]){
      R = now;
      if (now == (L + R) / 2) break;
      continue;
    }

    ll rest = M * (V - P + 1);
    rest -= M * (N - now);

    ll C = A[now] + M;
    for (int i = P - 1; i < now; i++){
      rest -= C - A[i];
    }
    
    if (rest <= 0) L = now;
    else R = now;
    
    if (now == (L + R) / 2) break;
  }
  cout << R << endl;

  return 0;
}


Measured memory_bytes: 1024
import itertools
import math
import fractions
import functools
n, m = map(int, input().split())
l = []
for i in range(m):
    l.append(list(map(int, input().split())))


for i in range(m):
    if n == 1:
        l[i][0] = 0
    if n == 2:
        if l[i][0] == 2:
            l[i][0] = 0
    if n == 3:
        if l[i][0] == 1:
            l[i][0] = 2
        elif l[i][0] == 2:
            l[i][0] = 1
        elif l[i][0] == 3:
            l[i][0] = 0

count = {"1nokurai": 10, "10nokurai": 10, "100nokurai": 10}
for i in range(m):
    if l[i][0] == 0:
        if count["1nokurai"] == 10 or count["1nokurai"] == l[i][1]:
            count["1nokurai"] = l[i][1]
        else:
            print(-1)
            quit()
    elif l[i][0] == 1:
        if count["10nokurai"] == 10 or count["10nokurai"] == l[i][1]:
            count["10nokurai"] = l[i][1]
        else:
            print(-1)
            quit()
    elif l[i][0] == 2:
        if count["100nokurai"] == 10 or count["100nokurai"] == l[i][1]:
            count["100nokurai"] = l[i][1]
        else:
            print(-1)
            quit()

if n == 3:
    if count["100nokurai"] == 0:
        print(-1)
        quit()
    if m == 0:
        print("100")
        quit()
if n == 2:
    if count["10nokurai"] == 0:
        print(-1)
        quit()
    if m == 0:
        print("10")
        quit()
if n == 1:
    if m == 0:
        print("0")
        quit()


if count["1nokurai"] == 10:
    count["1nokurai"] = 0
if count["10nokurai"] == 10:
    if n == 2:
        count["10nokurai"] = 1
    if n == 3:
        count["10nokurai"] = 0

if count["100nokurai"] == 10:
    count["100nokurai"] = 1

if n == 3:
    print(str(count["100nokurai"]) +
          str(count["10nokurai"])+str(count["1nokurai"]))
if n == 2:
    print(str(count["10nokurai"])+str(count["1nokurai"]))
if n == 1:
    print(str(count["1nokurai"]))


Measured memory_bytes: 63980
import bisect
INF = 10 ** 9 + 7
N, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
aset = set(a)
bset = set(b)
ablst = [0] * ((N * M) + 1)
a.sort(), b.sort()

if len(aset) != len(a) or len(bset) != len(b):
    print(0)
    exit()

for i in range(N):
    ablst[a[i]] += 1

for j in range(M):
    ablst[b[j]] += 1

ans = 1
for i in range(N * M, 0, -1):
    ac = bisect.bisect_left(a, i)
    bc = bisect.bisect_left(b, i)
    if ablst[i] == 2:
        ans *= 1
    elif ablst[i] == 1 and ac < N and a[ac] == i:
        ans *= (M - bc)
    elif ablst[i] == 1 and bc < M and b[bc] == i:
        ans *= (N - ac)
    else:
        acnt = bisect.bisect_left(a, i)
        bcnt = bisect.bisect_left(b, i)
        ans *= (N - ac) * (M - bc) - (N * M - i)
    ans %= INF
print(ans % INF)

Measured memory_bytes: 10996
# C
n = int(input())
if n==1:
    a, b =map(int, input().split())
    print(a)
else:
    def return_a(n):
        return n[0]
    def return_b(n):
        return n[1]
    ab = [[0] * 3 for i in range(n)]
    for i in range(n):
        ab[i][0], ab[i][1] = map(int, input().split())
        ab[i][2] = ab[i][0] + ab[i][1]
    ab = sorted(ab, key=lambda x: x[2], reverse=True)
    print(sum(map(return_a, ab[0::2])) - sum(map(return_b, ab[1::2])))

Measured memory_bytes: 25252
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:https://atcoder.jp/contests/abc160/tasks/abc160_a>
 問題文============================================================
 A - Coffee
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    string S; cin >> S;
    if(S[2]==S[3]&&S[4]==S[5]) return "Yes";
    else return "No";
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<string>() << endl;
    return 0;
}


Measured memory_bytes: 256
S = list(map(int, list(input())))
even = [0]*2
odd = [0]*2
for i, s in enumerate(S):
  if i % 2 == 0:
    even[s] += 1
  else:
    odd[s] += 1
ans = min(even[0]+odd[1], even[1]+odd[0])
print(ans)

Measured memory_bytes: 4652
def make_divisors(n):
    from collections import deque
    divisors = deque([])
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)
    lst_divisors = list(divisors)
    lst_divisors.sort()
    return lst_divisors

a, b = map(int,input().split())

ya = set(make_divisors(a))
yb = set(make_divisors(b))

cand = list(ya&yb)
cand.sort()

#print(cand)

ans = []
if len(cand) > 1:
    for n in cand[1:]:
        if ans:
            for waru in ans:
                if n%waru == 0:
                    break
            else:
                ans.append(n)
        else:
            ans.append(n)
#print(ans)
print(len(ans)+1)

Measured memory_bytes: 74576