akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;


//repetition
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define euc_dis(x, y) sqrt(x*x + y*y)

#define pb push_back
#define mp make_pair
#define INF 999999999
#define MOD 1000000007
#define sp ' '
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()

//typedef
typedef long long ll;
typedef pair<int, int> pint;
typedef map<int, int> mint;
typedef vector<int> vint;
typedef vector<char> vchr;
typedef vector<long long> vll;
typedef vector<string> vstr;


int mod(int a, int b){return (a%b+b)%b;}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
void Yes(){cout << "Yes" << endl;}
void No(){cout << "No" << endl;}
void Judge(bool b){b?Yes():No();}
void YES(){cout << "YES" << endl;}
void NO(){cout << "NO" << endl;}
void JUDGE(bool b){b?YES():NO();}
ll powMod(ll a, ll b){ll ans=1; rep(i, b){ans=ans*a%MOD;} return ans;}

template<typename T>
void ppp(T n){cout << n << endl;}
template<typename T>
void dpp(T n){cerr << n << endl;}
template<typename T>
void vpp(T a){rep(i,a.size()){cout << a[i] << endl;}}
template<typename T>
void vdp(T a){rep(i,a.size()){cerr << a[i] << endl;}}

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int ddx[8] = {1,0,-1,0,1,-1,-1,1};
const int ddy[8] = {0,1,0,-1,1,1,-1,-1};




template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}


vector<string> split(const string &str, char sep)
{
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.pb(buffer);
    }
    return v;
}




int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    string a, b, c;

    cin >> a >> b >> c;

    char turn = a[0];

    int i=0, j=-1, k=-1;
    while(1){
        dpp(turn);
        switch(turn){
            case 'a':
                if(i == a.size()-1){
                    ppp('A');
                    return 0;
                }
                else{
                    ++i;
                    turn = a[i];
                }
                break;

            case 'b':
                if(j == b.size()-1){
                    ppp('B');
                    return 0;
                }
                else{
                    ++j;
                    turn = b[j];
                }
                break;

            case 'c':
                if(k == c.size()-1){
                    ppp('C');
                    return 0;
                }
                else{
                    ++k;
                    turn = c[k];
                }
                break;

        }

    }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,l,r) for(ll i=(l);i<(r);i++)
string s;
int main(void){
    int a,b,c,d,k;
    cin>>a>>b>>c>>k;
    d=max(a,max(b,c));
    cout<<(a+b+c-d+(d<<k))<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] p = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] q = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int[] arr = new int[n];
            for (int i = 0; i < n; i++)
            {
                arr[i] = i + 1;
            }

            var perms = GeneratePermutation<int>(arr);
            
            int pIndex = perms.FindIndex(e => {
                for (int i = 0; i < e.Length; i++)
                {
                    if (e[i] != p[i])
                    {
                        return false;
                    }
                }
                return true;
            }) + 1;
            int qIndex = perms.FindIndex(e => {
                for (int i = 0; i < e.Length; i++)
                {
                    if (e[i] != q[i])
                    {
                        return false;
                    }
                }
                return true;
            }) + 1;
            Console.WriteLine(Math.Abs(pIndex - qIndex));
        
        }

        static List<T[]> GeneratePermutation<T>(params T[] array) where T : IComparable
        {
            var a = new List<T>(array).ToArray();
            var res = new List<T[]>();
            res.Add(new List<T>(a).ToArray());
            var n = a.Length;
            var next = true;
            while (next)
            {
                next = false;

                int i;
                for (i = n - 2; i >= 0; i--)
                {
                    if (a[i].CompareTo(a[i + 1]) < 0)
                        break;
                }
                if (i < 0)
                    break;

                var j = n;
                do
                {
                    j--;
                } while (a[i].CompareTo(a[j]) > 0);

                if (a[i].CompareTo(a[j]) < 0)
                {
                    var tmp = a[i];
                    a[i] = a[j];
                    a[j] = tmp;
                    Array.Reverse(a, i + 1, n - i - 1);
                    res.Add(new List<T>(a).ToArray());
                    next = true;
                }
            }
            return res;
        }
    }
}


Measured memory_bytes: 18008
#include <iostream>
#include <vector>

#define MAXN 200005

int n;
std::vector<int> Adj[MAXN];
int d[MAXN];
int max;
int key;

void dfs(int u, int p)
{
	for(int v : Adj[u])
	{
		if(v != p)
		{
			d[v] = d[u] + 1;
			dfs(v, u);
			if(d[v] > max)
			{
				max = d[v];
				key = v;
			}
		}
	}
}

int main()
{
	int n;
	std::cin >> n;

	for(int i = 1; i < n; i++)
	{
		int a, b;
		std::cin >> a >> b;
		a--; b--;
		Adj[a].push_back(b);
		Adj[b].push_back(a);
	}

	d[0] = 0;
	dfs(0, -1);
	d[key] = 0;
	dfs(key, -1);

	int dp[n];
	dp[1] = true;
	dp[2] = false;

	for(int i = 3; i <= max+1; i++)
	{
		if((dp[i-1] == false) || (dp[i-2] == false))
			dp[i] = true;
		else
			dp[i] = false;
	}

	//std::cout << max << std::endl;

	if(dp[max+1])
		std::cout << "First";
	else
		std::cout << "Second";
}

Measured memory_bytes: 27648
import java.util.Scanner;
import java.lang.Character;

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

        Scanner scan = new Scanner(System.in);
        String[] str = new String[1000];
        int i = 0;
        while (true) {
            if(scan.hasNext()==false)break;
            str[i] = scan.next();
            for (int j = 0; j < str[i].length(); j++) {
                if (Character.isUpperCase(str[i].charAt(j))) {
                    str[i]=str[i].substring(0,j)+str[i].substring(j,j+1).toLowerCase()+str[i].substring(j+1);
                } else {
                    str[i]=str[i].substring(0,j)+str[i].substring(j,j+1).toUpperCase()+str[i].substring(j+1);
                }
            }
            i++;
        }
        for (int k = 0; k < i-1; k++) {
            System.out.printf("%s ", str[k]);
        }
        System.out.printf("%s\n", str[i-1]);
    }
}


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

int main() {
    string s, t;
    cin >> s >> t;
    vector<vector<int>>sp(26, vector<int>());
    for (int i = 0; i < s.size(); ++i) {
        sp[s[i] - 'a'].push_back(i+1);
    }
    ll ans = 0;
    int current = 0;
    for (int i = 0; i < t.size(); ++i) {
        if(sp[t[i] - 'a'].size() == 0){
            cout << -1;
            return 0;
        }
        auto iter = upper_bound(sp[t[i] - 'a'].begin(), sp[t[i] - 'a'].end(), current);
        if(iter == sp[t[i] - 'a'].end()){
            ans++;
            iter = sp[t[i] - 'a'].begin();
        }
        current = *iter;
    }
    ans = ans * s.size() + current;
    cout << ans;
    return 0;
}

Measured memory_bytes: 1216
N = int(input())
h = list(map(int, input().split()))
end = [0] * N

ans = 0
while h != end:
  strock = 0
  for i in range(N):
    if h[i] != 0:
      strock = 1
      h[i] -= 1
    else:
      if strock == 1:
        ans += 1
        strock = 0
  if strock == 1:
    ans += 1
  #print(h)
print(ans)
    

Measured memory_bytes: 65340
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
double ara[10][2];
double length(int n)
{
    int i,j;
    double sum=0;
    for(i=0; i<n-1; i++)
    {
        for(j=i+1;j<n;j++)
            sum+=sqrt(((ara[i][0]-ara[j][0])*(ara[i][0]-ara[j][0]))+((ara[i][1]-ara[j][1])*(ara[i][1]-ara[j][1])));

    }
    return sum;
}
int main()
{
    int i,j,ara1[50],n;
    double sum=0;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>ara[i][0]>>ara[i][1];
    }
    printf("%f\n",(length(n)*2)/(double)n);
    return 0;
}


Measured memory_bytes: 256
main = do
  [s, t] <- sequence [getLine, getLine]
  putStrLn $ ckStr s t (length s)


ckStr :: String -> String -> Int -> String
ckStr str1 str2 count
  | count == 0   = "No"
  | str1 == str2 = "Yes"
  | otherwise    = ckStr str1' str2 (count - 1)
      where str1' = (last str1):(init str1)


Measured memory_bytes: 892
#include<stdio.h>
int main(void)
{
    int n,i,j=0,a=0;
    char s[101],t[51];
    scanf("%d",&n);
    scanf("%s",s);
    for(i=0;i<n/2;i++)
        t[i]=s[i];
    t[i]='\0';
    for(i=n/2;i<n;i++){
        if(s[i]==t[j])
            a++;
        j++;
    }
    if(a*2==n)
        printf("Yes\n");
    else 
        printf("No\n");
    return 0;
}


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

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

Measured memory_bytes: 512
#include <stdio.h>

int main(void)
{
	char a[4];
	int b=0,i;
	scanf("%s",a);
	for(i=0;i<3;i++){
		if(a[i]=='1'){
			b++;
		}
	}
	printf("%d\n",b);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 200010;

// aのn乗を求める。計算量はO(logn)
ll modpow(ll a, ll n) {
    if(n == 0) {
        return 1;
    }
    if(n%2 == 1) {
        return (a * modpow(a, n-1))%mod;
    }
    return (modpow(a, n/2) * modpow(a, n/2))%mod;
}

ll inverse(ll a) {
    return modpow(a, mod-2);
}

ll inv[MAX_N];  // inv[i] : iの逆数のmod
ll fact[MAX_N];  // fact[i] : iの階乗のmod
ll invfact[MAX_N];

void init() {
    inv[0] = fact[0] = invfact[0] = 1;
    inv[1] = 1;
    for(ll i = 1; i < MAX_N; i++) {
        if(i >= 2) {
            inv[i] = mod - inv[mod%i]*(mod/i)%mod;
        }
        fact[i] = (i*fact[i-1])%mod;
        invfact[i] = inverse(fact[i]);
    }
}
 
ll Comb(ll n, ll r) {
    if(r < 0 || n < 0 || n < r) {
        return 0;
    }
    ll res = fact[n];
    res = (res * invfact[r])%mod;
    res = (res * invfact[n-r])%mod;
    return res;
}

//--- main関数でinit()を呼び出すのを忘れるな ---//
int main() {
    ll n;
    cin >> n;

    vl a(n+1);
    map<ll, ll> mp;
    rep(i, n+1) {
        cin >> a[i];
        mp[a[i]]++;
    }

    ll b;
    for(auto p : mp) {
        if(p.second == 2) {
            b = p.first;
            break;
        }
    }

    ll x = -1, y = -1;
    rep(i, n+1) {
        if(x == -1) {
            if(b == a[i]) {
                x = i;
            }
        }
        else {
            if(b == a[i]) {
                y = n-i;
            }
        }
    }

    init();

    exrep(k, 1, n+1) {
        if(k == 1) {
            out(n);
        }
        else {
            ll ans = (Comb(n+1, k) + mod - Comb(x+y, k-1))%mod;
            out(ans);
        }
    }

    re0;
}

Measured memory_bytes: 12928
//#include"cpp_kyopro.h"
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include<stdio.h>

using namespace std;

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




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

using namespace std;

#define ll long long int
#define MOD 1000000007

int main()
{
     ll i,j,k,n,m;
     cin>>n>>m>>i;
     if(n==m&&n!=i){
          cout<<"Yes"<<endl;
     }
     else if(n==i&&n!=m){
          cout<<"Yes"<<endl;
     }
     else if(m==i&&m!=n){
          cout<<"Yes"<<endl;
     }
     else{
         cout<<"No"<<endl;
     }
     
     
     
    // cout<<"YES"<<endl;
    //cout<<"NO"<<endl;
    
    
    
      return 0;
}


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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair
#define X first
#define Y second

long long f[55][55];

int main()
{
    ios_base::sync_with_stdio(false);

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    int n, p;
    int a[2];
    cin >> n >> p;
    a[0] = a[1] = 0;
    for (int i=0;i<n;i++)
    {
        int x;
        cin >> x;
        a[x & 1]++;
    }

    for (int i=0;i<55;i++)
    {
        for (int j=0;j<=i;j++)
        {
            if (!j)
            {
                f[i][j] = 1;
            }
            else
            {
                f[i][j] = f[i-1][j] + f[i-1][j-1];
            }
        }
    }

    long long ans = 0;
    for (int k=0;k<=n;k++)
    {
        for (int i=0;i<=k;i++)
        {
            if (((i & 1) != p) || (a[0] < (k - i)) || (a[1] < i)) continue;
            ans += f[a[0]][k-i] * f[a[1]][i];
        }
    }
    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	int n;
	cin >> n;
	
	vector<ll> h(n);
	for(int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	
	vector<ll> dp(n + 10, 1LL << 60);
	dp[0] = 0; 
	dp[1] = abs(h[0] - h[1]);
	
	for(int i = 2; i < n; ++i) {
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}

	cout << dp[n - 1] << endl;
	
	return 0;
}


Measured memory_bytes: 4796
S = input()
N = len(S)

def kai(s):
  n = len(s)
  ok = True
  if n % 2 == 0:
    a = 0
  else:
    a = 1
  for i in range(int((n-a)/2)):
    if s[i] != s[-(i+1)]:
      ok = False
  return ok

a = kai(S)
b = kai(S[int((N + 3) / 2 - 1):])
print('Yes' if a and b else 'No')

Measured memory_bytes: 38256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		long a = Long.parseLong(in.nextInt() + "" + in.nextInt());
		
		long s = (long) Math.sqrt(a);
		if(s * s == a) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 22612
#include <iostream>
using namespace std;
int main(){
  int year, month, day;
  scanf("%d/%d/%d",&year,&month,&day);
  if(year<2019||(year==2019&&month<=4)){
    cout << "Heisei" <<endl;
    return 0;
  }else{
    cout << "TBD" <<endl;
    return 0;
  }
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>	
#include<string>
#include<math.h>
#include <vector>
using namespace std;
int main() {
	string S;
	string fire[1000];
	int N;
	int a = 0;
	int H[100000] = { 0 };
	int ans[100000] = { 0 };
	

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	for (int i = 0; i < N-1; i++) {
		if (H[i] >= H[i + 1]) {
			ans[a]++;
		}
		else {
			a++;
		}
	}
	sort(ans, ans + N);
	
	cout << ans[N-1] << endl;
}



Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int main() {
    int n; cin >> n;
    for (int i = 0; i < n; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        if (a > b) swap(a, b);
        if (b > c) swap(b, c); //max = c
        if (c*c == (a*a + b*b) ) cout << "YES" << endl;
        else cout << "NO" << endl;
    }
    return 0;
}



Measured memory_bytes: 3004
import java.util.*;
class Main {
   public static void main(String[] args)
   {
      Scanner scan  = new Scanner(System.in);
      int     n     = scan.nextInt();
      int     count = 1;

      int[] array = new int[n];
      for(int i = 0; i < n; i++){
          array[i] = scan.nextInt();
          }
      Arrays.sort(array);
      for(int i = 1; i < n; i++){
          if(array[i - 1] != array[i]){
             count++;
             }
          }
      System.out.println(count);
   }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;
typedef double db;
const ll mod=1000000007;
ll powmod(ll a,ll b) {ll res=1;a%=mod;assert(b>=0);for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
// head
const int N=2100;
int h,w,lenflip[N][N],lennorm[N][N];
char s[N][N];
int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin>>h>>w;
	rep(i,0,h) {
		rep(j,0,w) cin>>s[i][j];
	}
	rep(i,0,h-1) {
		rep(j,0,w) {
			if(s[i][j]==s[i+1][j]) {
				lenflip[i][j]=0;
				lennorm[i][j]=(j==0?1:lennorm[i][j-1]+1);
			} else {
				lennorm[i][j]=0;
				lenflip[i][j]=(j==0?1:lenflip[i][j-1]+1);
			}
		}
	}
	// rep(i,0,h) {
	// 	rep(j,0,w) cout<<len[i][j]<<' ';
	// 	cout<<endl;
	// }
	int ans=w;
	rep(j,0,w) {
		//cout<<j<<" column\n";
		set<pii> height;
		rep(i,0,h-1) {
			if(s[i][j]==s[i+1][j]) {
				height.insert(mp(lennorm[i][j],i));
			} else {
				height.insert(mp(lenflip[i][j],i));
			}
			//height.insert(mp(len[i][j],i));
		}
		set<int> cur;
		for(auto a:height) {
			int l,r;
			auto it=cur.lower_bound(a.se);
			if(it==cur.end()) {
				r=h;
			} else r=*it+1;
			if(it==cur.begin()) {
				l=0;
			} else l=*prev(it)+1;
			// if(it==cur.begin()) r=*it,l=0;
			// else l=*prev(it)+1;
			// if(it==cur.end()) r=h;
			// else r=*next(it);
			ans=max(ans,a.fi*(r-l));
			//cout<<a.fi<<' '<<a.se<<' '<<l<<' '<<r<<' '<<a.fi*(r-l)<<endl;
			cur.insert(a.se);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 40676
//agrawal117
//chahatagrawal117
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;
#define MAX 100005
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n; cin>>n;
    ll sum=0;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                ll val=__gcd(i,j);
                val=__gcd(val,(ll)k);
                sum+=val;
            }
        }
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 3648
#include <cstdio>
#include <vector>
#include <algorithm>
#include <iostream>
#include <cstring>
using namespace std ;

typedef long long ll ;
#define rep (i , n ) for ( int i =0; i < n ; i++)
#define _sort(arg) sort(begin(arg), end(arg))
#define MOD 1000000007
#define pb push_back
#define DEBUG(x) cout << #x << ": " << x << endl;

/*
__attribute__((constructor))
void initial()
{
	cin.tie(NULL);
	ios::sync_with_stdio(false);
}
*/

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

	string s;
	int k;
	
	cin >> s >> k;
	int len = s.size();
	int a[len];

	//cout << "te" << endl;
	for (int i = 0; i < len; i++)
	{
		if (s[i] == 'a')
		{
			a[i] = 0;
		}
		else
		{
			a[i] = 'z' - s[i] + 1;
		}
		//cout << a[i] << endl;
	}

	
	int remain = k;
	//cout << "tesdfa" << endl;
	for (int i = 0; i < len; i++)
	{
		if ( remain >= a[i] && (a[i] != 0) )
		{
			remain = remain - a[i];
			a[i] = 0;
		}
		//cout << a[i] << "; remain = " << remain << endl;
	}

	if (remain > 0)
	{
		remain = remain % 26;
		if (a[len-1] - remain < 0)
		{
			a[len - 1] = a[len-1] - remain + 26;
		}
		else
		{
			a[len-1] = a[len-1] - remain;
		}
		
	}

	for (int i = 0; i < len; i++)
	{
		if (a[i] == 0)
		{
			cout << "a";
		}
		else
		{
			cout << char('z' - a[i] + 1);
		}
	}

	cout << endl;

	
	return 0;
}

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

using namespace std;


int main(){
	int N; cin >> N;
	vector<int> arr(N,0);
	vector<long long> dp(N,0);
	for(int i = 0; i < N; i++) cin >> arr[i];

	dp[0] = 0;
	dp[1] = abs(arr[1]-arr[0]);

	for(int i = 2; i < N; i++){
		dp[i] = min(dp[i-1] + abs(arr[i]-arr[i-1]), dp[i-2] + abs(arr[i]-arr[i-2]));
	}

	cout << dp[N-1] << endl;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define IFOR(i,a,b) for(int i = 0; i < b; i++)cin>>a[i];
#define OFOR(i,a,b) for(int i = 0; i < b; i++)cout<<a[i]<<" ";
#define ll  long long x;

void solve()
{

    int h,w;
    cin>>h>>w;
    int m = 1e9 + 7;
    char a[h][w];
    for(int i = 0; i < h; i++)
    {
        for(int j = 0; j < w; j++)
        {
            cin>>a[i][j];
        }
    }
    
    
    int b[h][w] = {0};
   for(int i = 0; i < h;  i++)
    {
        for(int j = 0; j < w; j++)
        {b[i][j] = 0;}}
    b[0][0] = 1;
    for(int i = 0; i < h;  i++)
    {
        for(int j = 0; j < w; j++)
        {
            if(i == 0 && j != 0 && a[i][j] == '.')
            {
                if(a[i][j-1] == '.')
                b[i][j] = b[i][j-1] % m;
            }
            else if (j == 0 && i != 0 && a[i][j] == '.')
            {
                if(a[i-1][j] == '.')
                    b[i][j] = b[i-1][j] % m;
            }
            else if(i != 0 && j != 0 && a[i][j] == '.')
            {
                
                b[i][j] = (b[i-1][j] % m + b[i][j-1] % m) % m;
            }
            
            
        }

    }
 /*for(int i = 0; i < h;  i++)
    {
        for(int j = 0; j < w; j++)
        {
            cout<<b[i][j]<<" ";
        }
        cout<<endl;
    }
    cout<<endl;*/
    cout<<b[h-1][w-1];

}



int main()
{
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    }

}

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

int main() {
    int64_t N, K;
    std::cin >> N >> K;

    if (K % 2 != 0) {
        const int64_t cnt = N / K; 
        std::cout << cnt * cnt * cnt << std::endl;
    } else {
        int64_t a = N / K;
        int64_t b = N / K;
        if ((N % K) >= (K / 2)) {
            ++b;
        }
        std::cout << a * a * a + b * b * b << std::endl;
    }

    return 0;
}



Measured memory_bytes: 256
mod=10**9+7
f=[1]
for i in range(10**6):f+=[f[-1]*(i+1)%mod]
def comb(a,b):return f[a]*pow(f[b],mod-2,mod)*pow(f[a-b],mod-2,mod)%mod

n,k=map(int,input().split())
ans=comb(n*2-1,n-1)
if k>=n-1:print(ans);exit()
for i in range(n-1,k,-1):
  #ansからi回の操作では不可能な組み合わせを引く
  #0*i + any*(n-i)
  #つまり((n-i)個の部屋にn人が入る組み合わせ)*nC(n-i)
  #各部屋には必ず1人は入る
  #つまり(n-1)Ci
  anss=comb(n-1,i)*comb(n,n-i)%mod
  ans=ans+(mod-anss)
  ans%=mod
print(ans)

Measured memory_bytes: 71628
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

signed main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    var(i64, N);
    for (i64 i = 1; i <= N; ++i) {
        if (i * (i + 1) / 2 >= N) {
            dump(i);
            vector<i64> ans;
            while (N > 0) {
                if (i <= N) {
                    ans.push_back(i);
                    N -= i;
                }
                --i;
            }
            sort(all(ans));
            for (i64 e : ans) print(e);
            return 0;
        }
    }

    return 0;
}


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

#define INF 1e9
using namespace std;
typedef long long ll;

ll permutation(ll n, ll r) {
    ll p = 1;

    for (ll i = n; i >= n-r+1; --i) {
        p *= i;
        p = p % 1000000007;
    }

    return p;
}

int main() {

    ll n, m; cin >> n >> m;

    if (abs(n - m) > 1) {
        cout << 0 << endl;
        return 0;
    }

    if (abs(n - m) == 1) {
        ll a = permutation(n, n);
        ll b = permutation(m, m);

        cout << (a * b) % 1000000007 << endl;
        return 0;
    }

    ll c = permutation(n, n);

    cout << (c * c * 2) % 1000000007 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  ios::sync_with_stdio(false);
  /* code */
  int a ;
  int b ;
  cin >> a >> b;
  
  cout << ((a-2*b>=0) ? a-2*b : 0) << "\n" ;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;


int n;
vector<pii> g[100000];
int col[100000];
 
void dfs(int v, int p)
{
	for(int i = 0; i < int(g[v].size()); i++) {
        if(g[v][i].first != p){
		    int c = (col[v]+g[v][i].second)%2;
		    col[g[v][i].first] = c;
		    dfs(g[v][i].first, v);
	    }
    }
}
 
int main()
{
	cin >> n;
 
	for (int i = 0; i < n-1; i++) {
		int u, v, w;
		cin >> u >> v >> w;
		u--; v--;
		g[u].push_back(make_pair(v, w));
		g[v].push_back(make_pair(u, w));
	}
    
	col[0] = 0;
	dfs(0, -1);
 
	for (int i = 0; i < n; i++){
		cout << col[i] << endl;
	}
 
	return 0;
}

Measured memory_bytes: 9984
#from math import sqrt
#from heapq import heappush, heappop
#from collections import deque

#a, b = [int(v) for v in input().split()]

n = input()

flag = 0
count = 0
for i in range(len(n) - 1, -1, -1):
    c = n[i]
    v = int(c) + flag

    if v == 10:
        v = 0
        flag = 1
    else:
        flag = 0
    if v < 5:
        count += v
    elif v == 5:
        if i != 0 and int(n[i-1]) >= 5:
            flag = 1
        count += 5
    else:
        count += 10 - v
        flag = 1
print(count + flag)


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

const int nax=1e5+5;

vector<vector<int> > g(nax);
vector<bool> vis(nax,false);
vector<int> indegree(nax,0);
vector<int> dist(nax,0);

void dfs(int s){
	vis[s]=true;
	for(int i=0;i<g[s].size();i++){
		dist[g[s][i]]=max(dist[g[s][i]],dist[s]+1);
		--indegree[g[s][i]];
		if(indegree[g[s][i]]==0){
			dfs(g[s][i]);
		}
	}
}



int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		g[u].push_back(v);
		++indegree[v];
	}
	for(int i=1;i<=n;i++){
		if(!vis[i] && indegree[i]==0){
			dfs(i);
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		ans=max(ans,dist[i]);
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 9600
#include<stdio.h>
#include<stdlib.h>
#include<math.h>

typedef long long int int64;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))

int *tmp;

void msort(int *a,int n){
  if(n<=1) return;
  int m=n/2;
  msort(a,m);
  msort(a+m,n-m);
  int i=0;
  int j=m;
  int k=0;
  while(i<m && j<n){
    if(a[i]<=a[j]){
      tmp[k++]=a[i++];
    } else {
      tmp[k++]=a[j++];
    }
  }
  while(i<m) tmp[k++]=a[i++];
  for(i=0;i<k;i++) a[i]=tmp[i];
  return;
}

void run(void){
  int n,k;
  scanf("%d%d",&n,&k);
  int *c=(int *)calloc(n+1,sizeof(int));
  tmp=(int *)calloc(n+1,sizeof(int));
  int i;
  for(i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    c[a]++;
  }
  msort(c,n+1);
  int s=0;
  while(c[s]==0) s++;
  int cnt=0;
  while(n+1-s>k){
    cnt+=c[s];
    s++;
  }
  printf("%d\n",cnt);
  return;
}

int main(void){
  run();
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 300001;
int grid[101][101];

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int a, b;

  cin >> a >> b;
  swap(a, b);
  for(int i = 0;i < 100;i++)
    for(int j = 0;j < 50;j++)
      grid[i][j] = 1;
  int cr = 0, cc = 0;
  cout << "100 100\n";
  for(int i = 0;i < b - 1;i++){
    grid[cr][cc] = 0;
    cr += 2;
    if(cr >= 100)
      cr = 0, cc += 2;
  }
  cr = 0;
  cc = 51;
  for(int i = 0;i < a - 1;i++){
    grid[cr][cc] = 1;
    cr += 2;
    if(cr >= 100)
      cr = 0, cc += 2;
  }
  for(int i = 0;i < 100;i++){
    for(int j = 0;j < 100;j++){
      cout << (grid[i][j] ? '#' : '.');
    }
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

int main()
{
    int n, maxw;
    cin >> n >> maxw;
    const int maxv = 1000 * n;
    vector<int> dp(maxv + 1, maxw + 5), ddp(maxv + 1, maxw + 5);
    dp[0] = ddp[0] = 0;
    for (int i = 0; i < n; i++) {
        int w, v;
        cin >> w >> v;
        for (int j = 0; j <= maxv; j++) {
            if (j >= v) dp[j] = min(ddp[j], ddp[j - v] + w);
        }
        ddp = dp;
    }
    int ans = 0;
    for (int i = 0; i <= maxv; i++) {
        if (dp[i] <= maxw) ans = i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int[] A = new int[N];
        for (int i = 0; i < N; i++) {
            A[i] = sc.nextInt();
        }

        System.out.println( solve(N, A) );
    }

    private static int solve(int N, int[] A) {
        Arrays.sort(A);

        int max = -1;
        int prev2 = 0; // 二つ前
        int prev1 = 0; // 一つ前
        int current = 0;
        int current_a = -1;

        for (int i = 0; i < N; i++) {
            int a = A[i];

            if( a != current_a ) {
                max = Math.max(prev2 + prev1 + current, max);

                if( current_a + 1 == a ) {
                    prev2 = prev1;
                    prev1 = current;
                } else if( current_a + 2 == a ) {
                    prev2 = current;
                    prev1 = 0;
                } else {
                    prev2 = 0;
                    prev1 = 0;
                }

                current_a = a;
                current = 1;

            } else {
                current++;
            }
        }

        max = Math.max(prev2 + prev1 + current, max);

        return max;
    }
}


Measured memory_bytes: 50588
#include <iostream>
#include <algorithm>
using namespace std;
int n, q, c, x, y, size_, dat[266666];
inline void update(int pos, int x) {
	pos += size_; dat[pos] = x;
	while(pos != 1) {
		pos >>= 1;
		dat[pos] = min(dat[pos * 2], dat[pos * 2 + 1]);
	}
}
inline int query(int a, int b, int k, int l, int r) {
	if(r <= a || b <= l) return 2147483647;
	if(a <= l && r <= b) return dat[k]; k <<= 1;
	int lc = query(a, b, k, l, (l + r) / 2);
	int rc = query(a, b, k + 1, (l + r) / 2, r);
	return min(lc, rc);
}
int main() {
	scanf("%d%d", &n, &q);
	for(size_ = 1; size_ < n;) size_ *= 2;
	for(int i = 0; i < size_ * 2; i++) dat[i] = 2147483647;
	for(int i = 0; i < q; i++) {
		scanf("%d%d%d", &c, &x, &y);
		if(c == 0) update(x, y);
		else printf("%d\n", query(x, y + 1, 1, 0, size_));
	}
}

Measured memory_bytes: 4256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

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

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

int main(void) {
    int n;
    int count=0;
    cin>>n;
    vector<int> p(n+1);
    FOR(i,1,n){
        cin>>p[i];
        if(p[i]!=i){
            count++;
        }
    }
    if(count==2||count==0){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using VI = vector<int>;
using VL = vector<ll>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);(i)++)
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);(i)++)
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);(i)--)
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);(i)--)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }

template<typename T> class BIT {
    int n;
    vector<T> dat;
public:
    void init(int in) {
        n = in + 1;
        dat.clear();
        dat.resize(n + 1, 0);
    }
    T sum(int i) {
        T ret = 0;
        while (i >= 0) {
            ret += dat[i];
            i = (i & (i + 1)) - 1;
        }
        return ret;
    }
    void add(int i, T x) {
        while (i <= n) {
            dat[i] += x;
            i |= i + 1;
        }
    }
};

int main() {
    int n;
    cin >> n;
    VL a(n), sorted(n);
    FOR(i, 0, n) {
        cin >> a[i];
        sorted[i] = a[i];
    }
    SORT(sorted);
    int ok = 0, ng = n;
    BIT<ll> bit;

    ll border = (((ll)n * (ll)(n + 1) / 2) + 1) / 2;
    while (ng - ok > 1) {
        int mid = (ng + ok) / 2;
        int midnum = sorted[mid];
        bit.init(2 * n + 1);
        int sum = 0;
        bit.add(sum + n, 1);
        ll result = 0;
        FOR(i, 0, n) {
            sum += (a[i] >= midnum ? 1 : -1);
            result += bit.sum(sum + n);
            bit.add(sum + n, 1);
        }
        if (result >= border)ok = mid;
        else ng = mid;
    }
    cout << sorted[ok] << endl;
}


Measured memory_bytes: 3328
while n=gets.to_i
  break if n == 0
  h = {}
  n.times{
    (n,d,c)=gets.split(/ /).map(&:to_i)
    h[n]=0 if !h.key?(n)
    h[n]+=d*c
  }
  r = h.select{|k,v| v >= 1000000}.keys

  if r.size == 0
    puts "NA"
  else
    puts r
  end
end

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

int heap[500001];
int H;

int left(int i){
	return i * 2;
}
int right(int i){
	return i * 2 + 1;
}

void maxHeapify(int* A,int i){
	int l = left(i);
	int r = right(i);

	int largest;
	if(l <= H && A[l] >= A[i]){ 
		largest = l;
	}
	else{
		largest = i;
	}
	if(r <= H && A[r] > A[largest]){
		largest = r;
	}
	if(largest != i){
		int tmp = A[i];
		A[i] = A[largest];
		A[largest] = tmp;
		maxHeapify(A,largest);
	}
}
void buildMaxHeap(int* A){
	for(int i = H / 2; i > 0; i--){
		maxHeapify(A,i);
	}
}

int main(){
	scanf("%d",&H);
	for(int i = 1; i <= H; i++){
		scanf("%d",&heap[i]);
	}
	buildMaxHeap(heap);

	for(int i = 1; i <= H; i++){
		printf(" %d",heap[i]);
	}
	printf("\n");

	return 0;
}



Measured memory_bytes: 5160
def lcs_size():
  X = raw_input()
  Y = raw_input()
  a = len(X)
  b = len(Y)
  z2 = [0 for i in range(b+1)]

  for i in range(a):
    ch = X[i]
    z1 = z2 + []
    for j in range(b):
      if ch == Y[j]:
        z2[j+1] = z1[j] + 1
      elif z2[j+1] < z2[j]:
        z2[j+1] = z2[j]

  return z2[-1]

q = input()
for k in range(q):
  print lcs_size()

Measured memory_bytes: 6504
#include<stdio.h>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<bitset>
#include<vector>
#include<math.h>
#include<stack>
#include<map>
#include<queue>
#include<set>
#define eps 1e-9
#define ls(x) (x<<1)
#define rs(x) ((x<<1)|1)
using namespace std;
int n;
int a[100005];
int cnt[100005];
int main()
{
    scanf("%d",&n);
    int ans=n;
    for(int i=1;i<=n;i++)
    {
        scanf("%d",&a[i]);
    }
    for(int i=1;i<=n;i+=2)
    {
        cnt[a[i]]++;
    }
    int mx=0,sec=0;
    for(int i=1;i<=100005;i++)
    {
        if(cnt[i]>cnt[mx])
        {
            sec=mx;
            mx=i;
        }
        else if(cnt[i]>cnt[sec])
        {
            sec=i;
        }
    }
    int mxnum=cnt[mx],secnum=cnt[sec];
    memset(cnt,0,sizeof(cnt));
    for(int i=2;i<=n;i+=2)
    {
        cnt[a[i]]++;
    }
    int mx1=0,sec1=0;
    for(int i=1;i<=100005;i++)
    {
        if(cnt[i]>cnt[mx1])
        {
            sec1=mx1;
            mx1=i;
        }
        else if(cnt[i]>cnt[sec1])
        {
            sec1=i;
        }
    }
    //cout<<mx<<' '<<mx1<<endl;
    ans-=mxnum;
    if(mx==mx1)
    {
        ans-=max(secnum,cnt[sec1]);
    }
    else ans-=cnt[mx1];
    printf("%d",ans);
}

Measured memory_bytes: 1024
numbers = input()
onenum = numbers.split()
onenum[0] = int(onenum[0])
onenum[1] = int(onenum[1])
onenum[2] = int(onenum[2])

answer = 0
i = onenum[0]
while i <= onenum[1]:
    if i % onenum[2] == 0:
        answer += 1
    i += 1

print(answer)

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

#define ll long long
#define li long int

int n;
li a[200005],f[200005];

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    sort(a+1,a+1+n);
    for(int i=2;i<=n;i++){
        if(a[i]==a[i-1]){
            cout<<"NO";
            return 0;
        }
    }
    cout<<"YES";
    return 0;
}



Measured memory_bytes: 1792
#include <iostream>
#include <chrono>
#include <cmath>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <unordered_set>
#include <vector>
#include <queue>
#include <math.h>
#include <unordered_map>
#include <fstream>
#include <functional>
#include <map>
#include <deque>
#include <string.h>
#include <set>

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(a) ((a) < 0 ? (-a) : (a))
#define YesNo(flag) ((flag) ? "Yes\n" : "No\n")
#define YESNO(flag) ((flag) ? "YES\n" : "NO\n")

constexpr auto NMAX = (int)1e5 + 20;
constexpr auto INF_ULL = 18446744073709551615;
constexpr auto INF_INT = 2147483647;
constexpr auto PI = 3.14159265359;
constexpr auto MOD = 1000000007;

using namespace std;

typedef unsigned long long ull;

int n, q;
ull numCounts[NMAX];
ull sum;

int main()
{
	cin >> n;
	for (int i = 0; i < n; i++) {
		ull aux;
		cin >> aux;

		numCounts[aux]++;
		sum += aux;
	}
	cin >> q;
	while (q--) {
		ull b, c;
		cin >> b >> c;
		sum -= numCounts[b] * b;
		sum += numCounts[b] * c;
		numCounts[c] += numCounts[b];
		numCounts[b] = 0;
		cout << sum << '\n';
	}
	return 0;
}

Measured memory_bytes: 4324
MODULE solveMod
        implicit none
        
        public
        integer(16) :: counter=0,maxDigit,k
        integer(16) :: ans(10)
        
        contains
        function numLun( digit ) result( num )
          implicit none
          integer(16),intent(in) :: digit
          integer(16) :: num,i
          logical dummy
          
          maxDigit = digit
          
          do i = 1,9
            dummy = check( i,1_16 )
            ans(1) = i
          end do
          
          num = counter
        end function numLun
        
        recursive function check( num,numCall ) result( dummy )
          implicit none
          integer(16) :: num,numCall,i
          logical :: dummy
          character(10) :: s
          
          ans(numCall) = num
          
          if( num==-1.or.num==10 )then
            dummy = .false.
            return
          else
            if( numCall==maxDigit )then
              counter = counter + 1
              if(counter==k)then
                do i = 1,maxDigit
                  write(s(i:i),'(i1)') ans(i)
                end do
                !print*,ans(1:maxDigit)
                print*,s(1:maxDigit)
                stop
              end if
              return
            else
              dummy = check( num-1,numCall+1 )
              dummy = check( num  ,numCall+1 )
              dummy = check( num+1,numCall+1 )
            end if
          end if
        end function check
          
      END MODULE solveMod
      
      PROGRAM LunlunNumber
      use solveMod
      IMPLICIT NONE
      integer(16) ::  digit,buffer
      
      read*,k
      
      digit = 1 !digit is digit
      buffer = 0
      do while(.true.)
        buffer = buffer + numLun( digit )
        digit = digit + 1
      end do 
      
      
      END PROGRAM

Measured memory_bytes: 640
package main

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

func main() {
	reader := bufio.NewReader(os.Stdin)
	S, _ := reader.ReadString('\n')
	T, _ := reader.ReadString('\n')
	var n int
	for i:=0;i<3;i++ {
		if S[i] == T[i] {
			n++
		}
	}
	fmt.Println(n)
}

Measured memory_bytes: 640
#include<iostream>
#include<cstdio>
#include<vector>
using namespace std;
int n,m;
const int inf = 0x3f3f3f3f;
vector<pair<int,int> >v;
int dp[105000];
int main(void){
	cin>>n>>m;
	for(int i = 1;i<=m;++i){
		int x,y;
		cin>>x>>y;
		v.push_back(make_pair(x,y));
	}
	dp[0] = 0;
	for(int i = 1;i<=n;++i){
		dp[i]=inf;
		for(int j = 0;j<v.size();++j){
			int t1 = v[j].first;
			int t2 = v[j].second;
			if(i-t1 <= 0) dp[i]=min(dp[i],t2);
			else dp[i]=min(dp[i],t2+dp[i-t1]);
		}
	}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	
	int N, L,m,a;
	cin >> N >> L;
	m = 10000;

	for (int i = 1; i < (N+1); i++) {
		if (m > abs(L + i - 1)) {
			m = abs(L + i - 1);
			a = L * (N - 1) + N * (N + 1) / 2 - i + 1-N;
		}
	}
	cout << a;

	return 0;
}

Measured memory_bytes: 256
N,A,B=map(int,input().split())
P=10**9+7

Q=pow(2,N,P)

def fac(n,k,p):
    ans=1
    for i in range(n-k+1,n+1):
        ans=(ans*i)%p
    return ans

def makeinv(length,p):
    L=[0,1]
    for i in range(2,length+1):
        x=p-((L[p%i]*(p//i))%p)
        L.append(x)
    return L

def comb(n,k,p):
    ans=fac(n,k,p)
    inv=makeinv(k,p)
    for i in range(1,k+1):
        ans=(ans*inv[i])%p
    return ans

R=comb(N,A,P)
S=comb(N,B,P)

print((Q-1-R-S)%P)


Measured memory_bytes: 11344
#include<iostream>
#include<stdlib.h>


using namespace std;

int main()
{
    int x,a,b;
    cin>>x>>a>>b;
    if(abs(x-a)<abs(x-b))
    {
        cout<<"A"<<endl;
    }
    else
    {
        cout<<"B"<<endl;
    }
    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;

const int nmax = 1e9 + 7;
typedef long long ll;

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

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

  bool flag = true;
  for (int i = 0; i < N; i++){
    if (D[i] != 12){
      if (flag == true){
        flag = false;
      }else{
        flag = true;
        D[i] = 24 - D[i];
      }
    }
  }
  D.push_back(0); D.push_back(24);

  sort(D.begin(), D.end(), greater<int>());

  int ans = 24;
  for (int i = 0; i < N + 1; i++){
    int A = D[i] - D[i + 1];
    if (ans > A){
      ans = A;
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
n = int(input())
d = list(map(int, input().split()))
bSum = 0
h = 1
for i in range(n):
    d[i] = d[i] * 2
    bSum = bSum + (d[i] * h)
    h = h * -1
m1 = bSum / 2

ans = [int(m1)]
for i in range(n - 1):
    ans.append(int(d[i] - ans[i]))
print(" ".join(map(str, ans)))

Measured memory_bytes: 19140
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;

int main() {
    int n, ans=0;
    cin >> n;
    vector<int> data(n);
    REP(i, n) cin >> data.at(i);
    ASORT(data);
    FOR(i, 0, n-3) {
        FOR(j, i+1, n-2) {
            FOR(k, j+1, n-1) {
                if( data.at(i) + data.at(j) > data.at(k) && data.at(i) < data.at(j) && data.at(j) < data.at(k) ) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 3632