akhauriyash/Code-Regression huggingface dataset:
# coding: utf-8
# submission # - User: herp_sy
# https://atcoder.jp/contests/
#
# lang: Python3 (3.4.3)

import math
import statistics
import numpy as np
import queue

n = int(input())
s,t = map(str, input().split(' '))
for i in range(n):
  print(s[i], end = '')
  print(t[i], end = '')
print('')


Measured memory_bytes: 21808
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    int mod = 1000000007;
    long long sum = 0;
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        sum += A[i];
        sum %= mod;
    }
    long ans = 0;
    for (int i = 0; i < N; i++)
    {
        sum -= A[i];
        if (sum < 0) sum += mod;
 
        ans += A[i] * sum;
        ans %= mod;
    }
 
    cout << ans << endl;
}


Measured memory_bytes: 4048
#include <bits/stdc++.h>
using namespace std;
#define DEBUG 0
#define nl          '\n'
#define fori(n)			for(int i = 0; i < n; ++i) 
#define forj(n)			for(int j = 0; j < n; ++j)
#define fork(n)			for(int k = 0; k < n; ++k)
#define forl(n)			for(int l = 0; l < n; ++l)
#define pq priority_queue
#define umap unordered_map
#define uset unordered_set
#define ppb push_back
typedef long long ll;typedef pair<int,int> pii;typedef vector<bool> vbool;
typedef vector<int> vint;typedef vector<ll> vll;typedef long double ld;
typedef vector<vector<int>> vvi; typedef vector<vbool> vvb;

const ll N = 100010;
const ll INF = 0x3f3f3f3f;
const ll MOD = 1e9 + 7;

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, k; cin >> n >> k;
	vint p(n); fori(n) cin >> p[i];
	vector<ld> dp(1001);
	dp[1] = 1.0;
	for(int i = 2; i < 1001; i++) 
		dp[i] = dp[i-1] + 0.5;
	
	ld sum = -1, cur = 0;
	for(int i = 0; i < n; i++) 
		if (i < k) {
			cur+=dp[p[i]];
			sum = cur;
		} else {
			cur += dp[p[i]];
			cur -= dp[p[i-k]];
			sum = max(sum, cur);
		}
	cout << setprecision(10) << fixed << sum << nl;
	#if DEBUG
	cerr << "Time: " << (ld)clock() / CLOCKS_PER_SEC << " s" << nl;
	#endif
	return 0;
}


Measured memory_bytes: 1024
while str=gets
    a=Array.new(13,0)
    str.split(",").each do |b|
        a[b.to_i-1]+=1
        end
    str=a.join
    a.delete(0)
    a.sort!

    case a
        when [1,1,1,2]
            puts "one pair"
        when [1,2,2]
            puts "two pair"
        when [1,1,3]
            puts "three card"
        when [1,1,1,1,1]
            if (str=~/1{5}/)||(str=~/10{8}1{4}/)
                puts "straight"
            else
                puts"null"
            end
        when [2,3]
            puts "full house"
        when [1,4]
            puts "four card"
    end
end

Measured memory_bytes: 6100
# -*- coding: utf-8 -*-
s = input()
l = len(s)-1

for i in range(1 << l):
    op = [s[0], '', s[1], '', s[2], '', s[3]]
    for j in range(l):
        if ((i >> j) & 1) == 1:
            op[2*j+1] = '+'
        else:
            op[2*j+1] = '-'
    if eval(''.join(op)) == 7:
        print(''.join(op) + '=7')
        break


Measured memory_bytes: 3060
/* {{{ */
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};
    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}
/* }}} */

fn main() {
    input! {
        n: usize
    }
    let n = n % 10;
    println!("{}",
        match n {
            2|4|5|7|9 => "hon",
            0|1|6|8   => "pon",
            3         => "bon",
            _         => panic!()
        }
    );
}
/* vim:set foldmethod=marker: */


Measured memory_bytes: 2172
n, a, b = map(int, input().split())

if (n == 1 and a != b) or a > b:
    ans = 0
else:
    min_num = b + (a * (n - 1))
    max_num = a + (b * (n - 1))
    ans = max_num - min_num + 1

print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);i++)
typedef long long ll;

int main() {
	int N; cin >> N;
	vector<int> A(N);
	int64_t now=1000;
	REP(i,N) {
		cin >> A[i];
	}
REP(i,N){
		if (i > 0 && A[i] > A[i-1]){
			now=(A[i]*(now/A[i-1])+now%A[i-1]);
		}
	}
	cout << now << '\n';
	return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main(){
    int n;
    cin >> n;
    string b[4]={"AC","WA","TLE","RE"};
    map<string,int> a;
    rep(i,n){
        string s;
        cin >> s;
        a[s]++;
    }
    rep(i,4) cout << b[i] <<" x " << a[b[i]] << endl; 
}


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

using _i64 = int64_t;
using _u64 = uint64_t;
using _f64 = double;

#define _for(i, start, end) for(_i64 i = (_i64)start; i < (_i64)end; ++i)
#define _rep(i, number) _for(i, 0, number)
#define _foreach(e, data) for(auto& e : data)
#define _all(data) data.begin(), data.end()

template<typename type>
_i64 _size(const type& data) { return static_cast<_i64>(data.size()); }
template<typename type, size_t size>
_i64 _size(const type (&)[size]) { return static_cast<_i64>(size); }

enum _flag : bool { able = true, disable = false };

struct _time {
    _time(_flag flag) { check = flag; if(!check) { return; } gettime(start); }
    ~_time() {
        if(!check) { return; }; gettime(end);
        _i64 elapse = chrono::duration_cast<chrono::milliseconds>(end - start).count();
        cout << endl << "Time: " << elapse << " ms" << endl;
    }
    private:
    using _timer = chrono::time_point<chrono::system_clock>;
    _timer start, end; bool check;
    void gettime(_timer& time) { time = chrono::system_clock::now(); }
};

struct _ini { _ini() { ios::sync_with_stdio(false); cin.tie(nullptr); } } _ini;

int main() {
    {
        _time time(disable);
        string str; vector<_i64> count(26, 0); const char base = 'a';
        while(getline(cin, str) && str[0] != '\r' && str[0] != '\n'){
            _foreach(e, str) { if(isalpha(e)) { e = tolower(e); count[e - base]++; } }
        }
        _rep(i, 26) { cout << (char)(base + i) << " : " << count[i] << endl; }
    }
    return 0;
}


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

int main()
{
    string x;
    cin >> x;
    // int hi = atoi(x.substr(0, 2).c_str());
    // int lo = atoi(x.substr(2).c_str());
    int xdigit = atoi(x.c_str());
    int hi = xdigit / 100;
    int lo = xdigit % 100;
    bool chi = hi > 0 && hi < 13;
    bool clo = lo > 0 && lo < 13;
    // cout << hi << endl;
    // cout << lo << endl;
    if (chi && clo)
    {
        cout << "AMBIGUOUS" << endl;
    }
    else if (chi && !clo)
    {
        cout << "MMYY" << endl;
    }
    else if (!chi && clo)
    {
        cout << "YYMM" << endl;
    }
    else
    {
        cout << "NA" << endl;
    }
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

void solve_abc() {
	ll n;

	ll a[3][3];

	rep(i, 3)rep(j, 3) {
		cin >> a[i][j];
	}

	cin >> n;

	V b(n);
	rep(i, n) {
		cin >> b[i];
	}

	bool t[3][3];
	rep(i, 3)rep(j, 3) {
		t[i][j] = false;
	}
	rep(i, 3)rep(j, 3) {
		rep(k, n) {
			if (a[i][j] == b[k]) {
				t[i][j] = true;
			}
		}
	}

	string ans = "No";
	if (t[0][0]) {
		if (t[1][0] && t[2][0]) {
			ans = "Yes";
		}
		else if (t[0][1] && t[0][2]) {
			ans = "Yes";
		}
		else if (t[1][1] && t[2][2]) {
			ans = "Yes";
		}
	}
	
	if (t[1][0]) {
		if (t[1][1] && t[1][2]) {
			ans = "Yes";
		}
	}
	
	if (t[2][0]) {
		if (t[2][1] && t[2][2]) {
			ans = "Yes";
		}
		else if (t[1][1] && t[0][2]) {
			ans = "Yes";
		}
	}
	
	if (t[0][1]) {
		if (t[1][1] && t[2][1]) {
			ans = "Yes";
		}
	}
	
	if (t[0][2]) {
		if (t[1][2] && t[2][2]) {
			ans = "Yes";
		}
	}

	cout << ans << "\n";
}

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

	solve_abc();

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
typedef struct Dice{
	int d[6];
	int r[6];
	int b[6];
}dice;
int main(){
	int n,i,c,c2;
	dice nums[100];
	scanf("%d",&n);
	for(i=0;i<n;i++){
		for(int j=0;j<6;j++){
			scanf("%d",&nums[i].d[j]);
		}
	}
	for(i=0;i<n;i++){
		for(int l=i+1;l<n;l++){
			for(int k=0;k<6;k++){
				nums[i].b[k]=nums[i].d[k];
			}
			c=0;
			c2=0;
			for(int k=0;k<6;k++){
				nums[i].r[k]=nums[i].d[k];
			}
			for(int j=0;j<4;j++){
				for(int k=0;k<6;k++){
					nums[i].r[k]=nums[i].b[k];
				}
				if(nums[i].b[0]==nums[l].d[0]){
					c=1;
					break;
				}
				nums[i].r[2]=nums[i].b[0];
				nums[i].r[3]=nums[i].b[5];
				nums[i].r[5]=nums[i].b[2];
				nums[i].r[0]=nums[i].b[3];
				for(int k=0;k<6;k++){
					nums[i].b[k]=nums[i].r[k];
				}
				if(nums[i].b[0]==nums[l].d[0]){
					c=1;
					break;
				}
			}
			if(c==0){
				for(int j=0;j<4;j++){
					for(int k=0;k<6;k++){
						nums[i].r[k]=nums[i].b[k];
					}
					if(nums[i].b[0]==nums[l].d[0]){
						c=1;
						break;
					}
					nums[i].r[1]=nums[i].b[0];
					nums[i].r[4]=nums[i].b[5];
					nums[i].r[5]=nums[i].b[1];
					nums[i].r[0]=nums[i].b[4];
					for(int k=0;k<6;k++){
						nums[i].b[k]=nums[i].r[k];
					}
					if(nums[i].b[0]==nums[l].d[0]){
						c=1;
						break;
					}
				}
			}
			for(int j=0;j<4;j++){
				for(int k=0;k<6;k++){
					nums[i].r[k]=nums[i].b[k];
				}
				if(nums[i].b[1]==nums[l].d[1]&&nums[i].b[4]==nums[l].d[4]&&nums[i].b[3]==nums[l].d[3]){
					c2=1;
					break;
				}
				nums[i].r[1]=nums[i].b[3];
				nums[i].r[4]=nums[i].b[2];
				nums[i].r[2]=nums[i].b[1];
				nums[i].r[3]=nums[i].b[4];
				for(int k=0;k<6;k++){
					nums[i].b[k]=nums[i].r[k];
				}
				if(nums[i].b[1]==nums[l].d[1]&&nums[i].b[4]==nums[l].d[4]&&nums[i].b[3]==nums[l].d[3]){
					c2=1;
					break;
				}
			}
			if(c==1&&c2==1){
				if(nums[i].r[2]==nums[l].d[2]&&nums[i].r[3]==nums[l].d[3]&&nums[i].r[4]==nums[l].d[4]&&nums[i].r[5]==nums[l].d[5]){
					printf("No\n");
					return 0;
				}
			}
		}
	}
	printf("Yes\n");
	return 0;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
using namespace std;
#define fast                                                                   \
ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int long long
#define ll long long
#define f(i, n) for (int i = 0; i < n; i++)
#define ff(i, n) for (int i = 1; i <= n; i++)
#define F first
#define S second
#define pii pair<int,int>
#define sz size()
#define all(v) v.begin(),v.end()
#define pb push_back
#define pf push_front    
#define PB pop_back
#define pll pair<long long, long long>
#define vl vector<int>
#define mp make_pair
#define mod 1000000007
typedef unsigned long long ull;
const int N = 500005;
const int MOD = 998244353 ;




void solve(){
    int a, b, c;
    cin>>a>>b>>c;
    a += b;
    a += c;
    if(a >= 22)cout<<"bust";
    else cout<<"win";
}


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


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
ans = 0

while len(H) :
    if not H[0] :
        H.pop(0)
    else :
        ans += 1
        for i in range(len(H)) :
            if H[i] :
                H[i] -= 1
            else :
                break
print(ans)


Measured memory_bytes: 2940
#include<string>
#include<iostream>
#include<cctype>
using namespace std;
typedef string::const_iterator State;

int number(State &begin) {
  int ans = 0;
  bool flag = false;
  if (*begin == '-') flag = true, begin++;
  while (isdigit(*begin)) ans = ans * 10 + (*begin - '0'), begin++;
  if (flag) ans = -ans;
  return ans;
}

int expression(State &begin);

int factor(State &begin) {
  int ans;
  if (*begin == '(') begin++, ans = expression(begin), begin++;
  else ans = number(begin);
  return ans;
}

int term(State &begin) {
  int ans = factor(begin);
  while (1) {
    if (*begin == '*') begin++, ans *= factor(begin);
    else if (*begin == '/') begin++, ans /= factor(begin);
    else return ans;
    //begin++;
  }
}

int expression(State &begin) {
  int ans = term(begin);
  while (1) {
    if (*begin == '+') begin++, ans += term(begin);
    else if (*begin == '-') begin++, ans -= term(begin);
    else return ans;
    //begin++;
  }
}

int main() {
  int n;
  string s;
  cin >> n;
  for (int i = 0; i < n; i++) {
    cin >> s;
    State temp = s.begin();
    cout << expression(temp) << endl;
  }
}



Measured memory_bytes: 3184
#include <iostream>
#include <string.h>
using namespace std;

int main(int argc, const char * argv[])
{
    int a,b,c,d;
    int n;
    cin >> n;
    a = n/1000;
    b = (n - a*1000)/100;
    c = (n - a*1000-b*100)/10;
    d = n%10;
    while(1)
    {
        if( a+b+c+d == 7){
            cout << a << "+" << b << "+" << c << "+" << d << "=7" << endl;
            break;
        }
        else if( a+b+c-d == 7){
            cout << a << "+" << b << "+" << c << "-" << d << "=7" << endl;
            break;
        }
        else if( a+b-c+d == 7){
            cout << a << "+" << b << "-" << c << "+" << d << "=7" << endl;
            break;
        }
        else if( a+b-c-d == 7){
            cout << a << "+" << b << "-" << c << "-" << d << "=7" << endl;
            break;
        }
        else if( a-b+c+d == 7){
            cout << a << "-" << b << "+" << c << "+" << d << "=7" << endl;
            break;
        }
        else if( a-b+c-d == 7){
            cout << a << "-" << b << "+" << c << "-" << d << "=7" << endl;
            break;
        }
        else if( a-b-c+d == 7){
            cout << a << "-" << b << "-" << c << "+" << d << "=7" << endl;
            break;
        }
        else if( a-b-c-d == 7){
            cout << a << "-" << b << "-" << c << "-" << d << "=7" << endl;
            break;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
using namespace std;
const string alp = "abcdefghijklmnopqrstuvwxyz";
const string ALP = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define all(x) (x).begin(),(x).end()
#define SORT(c) sort(all(c))
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define SUM(c) accumulate(all(c),0)
#define COUNT(c,a) count(all(c), a)
#define Yn(b) puts(b?"Yes":"No")
#define YN(b) puts(b?"YES":"NO")
#define VSTIN(c,n) int (n); cin >> (n); vector<string> (c)(n); REP(i,n) cin >> (c)[i]
#define VINTIN(c,n) int (n); cin >> (n); vector<int> (c)(n); REP(i,n) cin >> (c)[i]
 
int main(){
  VSTIN(s,n);
  VSTIN(t,m);
  int a = 0;
  REP(i,n){
    if (COUNT(s,s[i])-COUNT(t,s[i])>a) a = COUNT(s,s[i])-COUNT(t,s[i]);
  }
  cout << a;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define ALL(A) A.begin(), A.end()

using namespace std;

typedef long long ll;
typedef pair<int, int> P;
set<string> words;

int main()
{
	words.clear();
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int N; cin >> N;
	vector<string> S(N);
	rep (i, N) cin >> S[i];

	rep (i, N){
		int n = S[i].length();
		for (int len = 1; len <= min(4,n); ++len){
			for (int j = 0; j < n; ++j){
				string t = S[i].substr(j, len);
				words.insert(t);
			} // end for
		} // end for
	} // end rep

	for (int i = 0; i < 27; ++i){
		for (int j = 0; j < 27; ++j){
			for (int k = 0; k < 27; ++k){
				for (int m = 0; m < 26; ++m){
					string s = "";
					if (i != 0) s += (char)('a' + i - 1);
					if (j != 0) s += (char)('a' + j - 1);
					if (k != 0) s += (char)('a' + k - 1);
					s += (char)('a' + m);
					if (!words.count(s)){
						cout << s << endl;
						return 0;
					} // end if
				} // end for
			} // end for
		} // end for
	} // end for

	return 0;
}

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

int main()
{
    int n,y;
    int a,b,c;

    cin >> n >> y;

    a = b = c = -1;
    for (int i = 0;i <= n;++i)
        for (int j = 0;j <= n;++j) {
            int k = n - i - j;
            if (k >= 0 && k <= n)
                if (10000 * i + 5000 * j + 1000 * k == y) {
                    a = i;
                    b = j;
                    c = k;
                    goto OWARI;
                }
        }

 OWARI:
    cout << a << " " << b << " " << c << endl;

    return(0);
}


Measured memory_bytes: 3560
def main():
    K = int(input())
    l = [False] * K
    ans = 1
    now = 0
    while True:
        now = now * 10 + 7
        now %= K
        if now == 0:
            print(ans)
            break

        if l[now]:
            print(-1)
            break
        
        l[now] = True
        ans += 1

if __name__ == '__main__':
    main()

Measured memory_bytes: 70868
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int64_t INF = 1LL << 60;


int main() {
 int N1,N2,N3,N4;
 cin>>N1>>N2>>N3>>N4;
 vector<int>k(100);
 k[N1]++;
 k[N2]++;
 k[N3]++;
 k[N4]++;
 if(k[1]==1&&k[9]==1&&k[7]==1&&k[4]==1){
     cout<<"YES"<<endl;
 }
 else{cout<<"NO"<<endl;}
 return 0;
}

Measured memory_bytes: 256
#include <stdio.h>#include <string.h>
int main(void){int n;scanf("%d",&n);for(int i=1;i<=n;i++){char s[9];char *a;snprintf(s,10,"%d",i);a=strchr(s,(int)'3');if(i%3==0||a!=NULL){printf(" %d",i);}}printf("\n");}



Measured memory_bytes: 2120
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;

int Time(string t, string h, string m, string s){
  h = t.substr(0, 2);
  m = t.substr(3, 2);
  s = t.substr(6, 2);
  return atoi(h.c_str())*3600 + atoi(m.c_str())*60 + atoi(s.c_str());
}

int main(int argc, char *argv[]){
  int n;
  while(cin >> n, n){
    int table[24*3600] = {0};
    string t;
    for (int i = 0; i < n; i++) {
      cin >> t;
      string h, m, s;
      int st = Time(t, h, m, s);
      cin >> t;
      int e  = Time(t, h, m, s);
      table[st]++;
      table[e]--;
    }
    int a = 0;
    int Max = 0;
    for (int i = 0; i < 24*3600; i++) {
      a += table[i];
      Max = max(Max, a);
    }
    std::cout << Max << std::endl;
  }
  return 0;
}

Measured memory_bytes: 1564
import java.util.Scanner;

public class Main{

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		int numOfChildren = sc.nextInt();
		int sumOfCandy = 0;
		
		for(int i=1;i<=numOfChildren;i++){
			sumOfCandy +=i;
		}
		
		System.out.print(sumOfCandy);
	}
}

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

const int N = 1e5;
vector<int> g[N];

void dfs2(int i, int p, vector<int> &v) {
  v.emplace_back(g[i].size());
  for(int j : g[i]) if(j != p && g[j].size() >= 2) {
    dfs2(j, i, v);
    return;
  }
}

int main() {
  ios::sync_with_stdio(false), cin.tie(0);
  int n; cin >> n;
  if(n == 2) return (cout << "1 2" << endl, 0);
  for(int i = 0; i < n - 1; i++) {
    int a, b; cin >> a >> b;
    a--; b--;
    g[a].emplace_back(b);
    g[b].emplace_back(a);
  }
  int t = -1;
  for(int i = 0; i < n; i++) {
    if(g[i].size() >= 2) {
      int c = 0;
      for(int j : g[i]) {
        if(g[j].size() >= 2) c++;
      }
      if(c <= 1) t = i;
      if(c >= 3) return (cout << -1 << endl, 0);
    }
  }
  vector<int> v;
  dfs2(t, -1, v);
  int k = v.size();
  for(int i = 0; i < k; i++) {
    if(v[i] == v[k - 1 - i]) continue;
    if(v[i] > v[k - 1 - i]) {
      reverse(begin(v), end(v));
      break;
    }
    break;
  }
  cout << 1;
  int c = 2;
  for(int i = 0; i < k; i++) {
    if(i == k - 1) {
      int t = c++;
      for(int j = 0; j < v[i] - 2; j++) cout << " " << c++;
      cout << " " << t;
      cout << " " << c++;
    } else {
      int t = c++;
      for(int j = 0; j < v[i] - 2; j++) cout << " " << c++;
      cout << " " << t;
    }
  }
  cout << endl;
}



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

#define fst first
#define snd second
#define mp make_pair
#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 all(x) (x).begin(),(x).end()

template <typename T1, typename T2>
bool umin(T1 &x, const T2 &y) {return (x>y ? (x=y,true):false);}
template <typename T1, typename T2>
bool umax(T1 &x, const T2 &y) {return (x<y ? (x=y,true):false);}

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef unsigned long long ull;

const int N = (int)1e2+3;
const int INF = (int)1e9+17;
const ll mod = (ll)1e9+7;
const ll LLINF = (ll)1e18+17;
const ld pi = (ld)acos(-1.0);


int n, m;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll n, a, b;
    cin >> n >> a >> b;
    cout << ((b-a-1) % 2 == 0 ? "Borys" : "Alice") << endl;

#ifdef TIME
    cerr << "TIME = " << 1. * clock() / CLOCKS_PER_SEC;
#endif

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main()
{
	int A;
	int B;
	int s,t,u,v;	
	int answer = 0;

	cin >> A >> B;

	for (int i = A; i <= B; i++) {
	
		s = i % 10;
		t = i / 10000 % 10;

		u = i / 10 % 10;
		v = i / 1000 % 10;

		if ( s == t && u == v ) 
			answer++;
	}
	
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Concurrent;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var N = cin.ReadInt;
			var R = Enumerable.Range(1, N).Where(x => x % 3 != 0 && x % 5 != 0).Sum(x=>(long)x);
			Console.WriteLine(R);
		}
	}
	static class ExtendClass {
		public static void Swap<T>(this T[] A, int x, int y) {
			var tmp = A[x];
			A[x] = A[y];
			A[y] = tmp;
		}
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);
	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}

}


Measured memory_bytes: 28396
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <functional>
#include <string>
#include <stack>
#include <queue>
#include <map>

typedef long long ll;
ll mod = 1e9 + 7;
  
using namespace std;

int main()
{
	int n;
	cin >> n;
 
    vector<char> str(n+1);
    vector<int> dot(n+1, 0);
    vector<int> sharp(n+1, 0);
    int dot_num = 0;
    int sharp_num = 0;
    for(int i = 1; i < n+1; i++)
    {
        char c;
        cin >> c;
        str[i] = c;
        
        if(c == '.')
            dot_num ++;
        else
        {
            sharp_num++;
        }
        dot[i] = dot_num;
        sharp[i] = sharp_num;
    }

    int ans = n;
    for(int i = 1; i < n+1; i++)
    {
        if(ans > sharp[i-1] + dot_num - dot[i])
            ans = sharp[i-1] + dot_num - dot[i];
    }

    cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#define rep(i,n) for(int (i) = 0;(i) < (n);(i)++)
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout << endl;
using namespace std;
typedef long long ll;

int dp[100005];
//dp[i] := 足場iにたどり着くまでに支払うコスト

int main(void) {
  int n;
  cin >> n;
  int h[n + 1];
  rep (i, n) cin >> h[i + 1];

  dp[1] = 0;
  dp[2] = abs(h[2] - h[1]);

  for (int i = 3; 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] << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define filename "vacation"
#define int long long
#define N 100005

using namespace std ;

struct vacation
{
    /* data */
    int a , b , c ;
} a[N] , f[N] ;
int n ;

void open()
{
    //freopen(filename".inp","r",stdin) ;
    //freopen(filename".out","w",stdout) ;
    ios_base::sync_with_stdio(0) ;
    cin.tie(0) ;
    cout.tie(0) ;
}
void readin()
{
    cin >> n ;
    for (int i = 1 ; i <= n ; i++)
        cin >> a[i].a >> a[i].b >> a[i].c ;
}
void process()
{
    for (int i = 1 ; i <= n ; i++)
    {
        f[i].a = max(f[i-1].b , f[i-1].c) + a[i].a ;
        f[i].b = max(f[i-1].a , f[i-1].c) + a[i].b ;
        f[i].c = max(f[i-1].a , f[i-1].b) + a[i].c ;
    }
    cout << max(f[n].a , max(f[n].b , f[n].c)) ;
}
signed main()
{
    open() ;
    readin() ;
    process() ;
}

Measured memory_bytes: 8300
X, N = map(int, input().split())
p = list(map(int, input().split()))
tmp = 101
ans = 101
for i in range(-200, 201):
    if i not in p:
        if tmp == abs(X-i):
            if ans > i:
                ans = i
        elif tmp >= abs(X-i):
            ans = i
            tmp = abs(X-i)
print(ans)


Measured memory_bytes: 9100
<?php

$sc = new Scanner();
$S = $sc->next();
$T = $sc->next();

$map = [];
$map2 = [];
$f = true;

for($i = 0; $i < strlen($S); $i++) {
    if (isset($map[$S[$i]]) && $map[$S[$i]] !== $T[$i]) {
        $f = false;
        break;
    }
    if (isset($map2[$T[$i]]) && $map2[$T[$i]] !== $S[$i]) {
        $f = false;
        break;
    }
    $map[$S[$i]] = $T[$i];
    $map2[$T[$i]] = $S[$i];
}
echo $f ? 'Yes' : 'No' . PHP_EOL;

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}


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

using namespace std;

int n, ans = 1;
string s;

int main()
{
    cin >> n >> s;
    for (int i = 1; i < s.length(); i++) if (s[i] != s[i - 1]) ans++;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 512
from collections import deque

h,w = map(int, input().split())
s = [input() for _ in range(h)]

inf = 10 ** 6

dx = [1,0,-1,0]
dy = [0,1,0,-1]
q = deque([[0,0]])
d = [[inf] * w for _ in range(h)]
d[0][0] = 0

while q:
    v = q.popleft()
    if v == [h-1, w-1]:
        break
    for i in range(4):
        x = v[0] + dx[i]
        y = v[1] + dy[i]
        if x>=0 and x<h and y>=0 and y<w and s[x][y]==".":
            if d[x][y] == inf:
                q.append([x,y])
                d[x][y] = d[v[0]][v[1]] + 1

if d[h-1][w-1] == inf:
    print(-1)
else:
    numw = 0
    for i in range(h):
        numw += s[i].count(".")
    print(numw - d[h-1][w-1] -1)

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

int debug = 0;

int main()
{
    deque<string> s;
    int q;
    int n, f;
    string c;

    string tmp1;
    cin >> tmp1;
    s.push_back(tmp1);

    cin >> q;
    vector<tuple<int, int, string>> op;

    rep(i,q){
        cin >> n;
        if(n==1){
            op.emplace_back(1, -1, "");
        }else{
            cin >> f >> c;
            op.emplace_back(2, f, c);
        }
    }    

    if(debug){
        for(auto x:op){
            cout << "<" << get<0>(x) << "," << get<1>(x) << "," << get<2>(x) << ">";
            cout << endl;
        }
    }


    bool rev = false;

    for(auto x:op){
        if(get<0>(x)==1){ // reverse
            //reverse(s.begin(), s.end());
            if(rev)
                rev = false;
            else
                rev = true;
        }else if(get<1>(x)==1){ // head
            if(rev) // tail
                s.push_back(get<2>(x)) ;
            else //head
                s.push_front(get<2>(x));

        }else if (get<1>(x) == 2){ // tail
            if(rev) // head
                s.push_front(get<2>(x));
            else // tail
                s.push_back(get<2>(x)) ;
        }
    }

    string tmp="";
    for(auto x:s){
        tmp = tmp + x;
    }

    if(rev){
        reverse(tmp.begin(), tmp.end());
        cout << tmp << endl;
    }else
        cout << tmp << endl;

    return 0;
}

Measured memory_bytes: 16364
N=int(input())
T,A=map(int,input().split())
H=list(map(int,input().split()))
ans=10**9
index=-1
for i in range(N):
  if abs(T-H[i]*0.006 -A) < abs(ans -A):
    ans = T-H[i]*0.006
    index = i
print(index+1)

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

#define d(x) cerr << #x ":" << x << endl;
#define dd(x, y) cerr << "(" #x "," #y "):(" << x << "," << y << ")" << endl
#define rep(i, n) for (int i = (int)(0); i < (int)(n); i++)
#define repp(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define all(v) v.begin(), v.end()
#define dump(v)                  \
    cerr << #v ":[ ";            \
    for (auto macro_vi : v) {    \
        cerr << macro_vi << " "; \
    }                            \
    cerr << "]" << endl;
#define ddump(v)                           \
    cerr << #v ":" << endl;                \
    for (auto macro_row : v) {             \
        cerr << "[";                       \
        for (auto macro__vi : macro_row) { \
            cerr << macro__vi << " ";      \
        }                                  \
        cerr << "]" << endl;               \
    }
using lint       = long long;
const int INF    = 1e9;
const lint LINF  = 1e18;
const lint MOD   = 1e9 + 7;
const double EPS = 1e-10;

int N, K;
vector<int> h;
vector<int> memo;

int rec(int i) {
    if (i == 0) { return 0; }

    int res = INF;
    for (int k = 1; k <= K and 0 <= i - k; k++) {
        res = min(res, rec(i - k) + abs(h[i] - h[i - k]));
    }
    return res;
}

int miii(int i) {
    if (memo[i] != INF) { return memo[i]; }

    if (i == 0) {
        return memo[i] = 0;
    } else {
        int res = INF;
        for (int k = 1; k <= K and 0 <= i - k; k++) {
            res = min(res, miii(i - k) + abs(h[i] - h[i - k]));
        }
        return memo[i] = res;
    }
}

int main() {
    cin >> N >> K;
    h    = vector<int>(N);
    memo = vector<int>(N, INF);
    rep(i, N) cin >> h[i];

    // もらうDP
    vector<int> mi(N, INF);
    mi[0] = 0;
    for (int i = 1; i < N; i++) {
        for (int k = 1; k <= K and 0 <= i - k; k++) {
            mi[i] = min(mi[i], mi[i - k] + abs(h[i] - h[i - k]));
        }
    }
    // cout << mi[N - 1] << endl;

    // 配るDP
    vector<int> mii(N + 100, INF);
    mii[0] = 0;
    for (int i = 0; i < N; i++) {
        for (int k = 1; k <= K; k++) {
            mii[i + k] = min(mii[i + k], mii[i] + abs(h[i] - h[i + k]));
        }
    }
    // cout << mii[N - 1] << endl;

    // 再起
    // cout << rec(N - 1) << endl;
    // メモ再起
    cout << miii(N - 1) << endl;

    return 0;
}

Measured memory_bytes: 12744
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
using namespace std;
#define REP(i,m,n) for(int i=(int)m ; i < (int) n ; ++i )
#define rep(i,n) REP(i,0,n)
typedef long long ll;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
    using namespace std;
 
int GCD(int a, int b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}
 
    int main(){
      int a,b,c,d;
      cin >> a >> b >> c >> d;
      cout << max(a*b,c*d) << endl;
      return 0;}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  long long  a,b, c,d;
  cin>>a>>b>>c>>d;
  long long ans=0;
  long long e=(c*d)/__gcd(c,d);
  ans+=(b/c)-(a/c)+(a%c==0)+(b/d)-(a/d)+(a%d==0)-((b/e)-(a/e)+(a%e==0));
  ans=(b-a+1)-ans;
  cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

	int a, b, c;
	cin >> a >> b >> c;
	
	if(a!=b&&a!=c&&b!=c)
		cout << 3;
	else if(a==b&&a==c&&b==c)
		cout << 1;
	else
		cout << 2;

	return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <map>
using namespace std;
#define prev prev228
#define all(x) (x).begin(), (x).end()

int n;
long long a[500000];

long long tl[500000];
long long tr[500000];
long long ans = 1e18;

signed 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];
    }
    long long cur = 0;
    set<pair<int, int> > ss;
    ss.insert({n - 1, 1e9});
    for (int i = n - 2; i >= 0; i--)
    {
        if (a[i] <= a[i + 1])
        {
            long long cnt = 0;
            long long k = a[i];
            while (k * 4 <= a[i + 1])
            {
                k *= 4;
                cnt++;
            }
            if (cnt > 0)
            {
                ss.insert({i, cnt});
            }
        }
        else
        {
            long long k = a[i + 1];
            long long cnt = 0;
            while (a[i] > k)
            {
                k *= 4;
                cnt++;
            }
            while (cnt--)
            {
                pair<int, int> s = *ss.begin();
                ss.erase(ss.begin());
                s.second--;
                if (s.second != 0)
                {
                    ss.insert(s);
                }
                cur += s.first - i;
            }
        }
        tr[i] = cur;
    }
    cur = 0;
    ss.clear();
    ss.insert({0, 1e9});
    for (int i = 1; i < n; i++)
    {
        if (a[i] <= a[i - 1])
        {
            long long cnt = 0;
            long long k = a[i];
            while (k * 4 <= a[i - 1])
            {
                k *= 4;
                cnt++;
            }
            if (cnt > 0)
            {
                ss.insert({i, cnt});
            }
        }
        else
        {
            long long k = a[i - 1];
            long long cnt = 0;
            while (a[i] > k)
            {
                k *= 4;
                cnt++;
            }
            while (cnt--)
            {
                auto it = ss.end();
                it--;
                pair<int, int> s = *it;
                ss.erase(it);
                s.second--;
                if (s.second != 0)
                {
                    ss.insert(s);
                }
                cur += i - s.first;
            }
        }
        tl[i] = cur;
    }
    /*for (int i = 0; i < n; i++)
    {
        cout << tl[i] << " ";
    }
    cout << endl;
    for (int i = 0; i < n; i++)
    {
        cout << tr[i] << " ";
    }
    cout << endl;*/
    ans = min(ans, 2 * tr[0]);
    ans = min(ans, 2 * tl[n - 1] + n);
    for (int i = 1; i < n; i++)
    {
        ans = min(ans, i + 2 * tr[i] + 2 * tl[i - 1]);
    }
    cout << ans;
}


Measured memory_bytes: 9984
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
//#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;

//ll mod = 1000000007 ;
//long double pie = acos(-1) ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void mysort(vll &a){sort(a.begin(),a.end()) ;}
//void myrev(vll &a){reverse(a.begin(),a.end()) ;}

int main(){
	ll n ; cin >> n ;
	ll x,y ; cin >> x >> y ;
	if(n==1){
		ll a ; cin >> a ;
		cout << sa(y,a) << endl ;
	}else{
		vll a(n) ;
		for(auto &i:a) cin >> i ;
		cout << max(sa(a.at(n-1),y),sa(a.at(n-2),a.at(n-1))) << endl ;
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD (long long int)(1e9+7)
#define ll long long int
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define reps(i,n) for(int i=1; i<=(int)(n); i++)
#define REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define FOR(i,a,b) for(int i=a; i<(int)(b); i++)
#define ALL(x) (x).begin(),(x).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define CLR(a) memset((a), 0 ,sizeof(a))
#define PB push_back
#define MP make_pair
#define SP << " " <<
const int INF = 1001001001;
const ll LINF = 100100100100100100;
const double EPS = 1e-10;
const long double PI  = acos(-1.0L);
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef pair<double,double> PDD;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
#define chmax(a,b) a = (((a)<(b))?(b):(a))
#define chmin(a,b) a = (((a)>(b))?(b):(a))

__attribute__((constructor))
void initial(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

signed main() {
	int n; cin>>n;
	string s; cin>>s;
	int q; cin>>q;
	while(q--){
		int k; cin>>k;
		ll ans=0LL, d=0LL, m=0LL, dm=0LL;
		cerr<< "i s[i] ans D M DM" <<endl;
		rep(i,n){
			if(s[i]=='D') d++;
			if(s[i]=='M') m++, dm+=d;
			if(s[i]=='C') ans+=dm;
			if(i>=k-1){
				if(s[i-k+1]=='D') d--, dm-=m;
				if(s[i-k+1]=='M') m--;
			}
			// cerr<< i SP s[i] SP ans SP d SP m SP dm<<endl;
		}
		cout<<ans<<endl;
	}

	return 0;
}


Measured memory_bytes: 1948
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    int N =sc.nextInt();
    int M[] =new int[N];
    int L[] =new int[100000];
    long ans =0;
    for(int i=0;i<N;i++){
      M[i]=sc.nextInt();
      ans =ans +M[i];
      L[M[i]-1]=L[M[i]-1]+1;}
    int Q =sc.nextInt();
    int B[] =new int[Q];
    int C[] =new int[Q];
    for(int j=0;j<Q;j++){
      B[j]=sc.nextInt();
      C[j]=sc.nextInt();
      ans =ans+(C[j]-B[j])*L[B[j]-1];
      L[C[j]-1]=L[C[j]-1]+L[B[j]-1];
      L[B[j]-1]=0;
      System.out.println(ans);
    }
  }
}


Measured memory_bytes: 60368
// includes
#include <cstdio>
#include <cstdint>
#include <iostream>
#include <iomanip>
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <climits>
#include <bitset>
#include <list>
#include <random>

// macros
#define ll long long int
#define pb emplace_back
#define mk make_pair
#define pq priority_queue
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())

using namespace std;

//  types
typedef pair<int, int> P;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<double, double> Pd;
 
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1e9 + 7;

// solve
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}


int main(int argc, char const* argv[])
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i, n)cin >> a[i];
  int mini = inf, maxi = 0;
  for(int i = 0; i < n; i++){
    mini = min(mini, a[i]);
    maxi = max(maxi, a[i]);
  }
  if(maxi - mini > 1){
    cout << "No" << endl;
    return 0;
  }
  if(maxi != mini){
    int cnt = 0;
    for(int i = 0; i < n; i++){
      if(a[i] == mini)cnt++;
    }
    if(cnt > maxi){
      cout << "No" << endl;
      return 0;
    }
    if(n - cnt > 0 && maxi - cnt == 0){
      cout << "No" << endl;
      return 0;
    }
    if((n - cnt) >= 2 * (maxi - cnt)){
      cout << "Yes" << endl;
      return 0;
    }else{
      cout << "No" << endl;
      return 0;
    }
  }else{
    if(n == maxi + 1){
      cout << "Yes" << endl;
      return 0;
    }
    if(n >= 2 * maxi){
      cout << "Yes" << endl;
      return 0;
    }
    cout << "No" << endl;
  }
	return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <string>
using namespace std;
int main(){
	int a,aa,aaa;
	scanf("%d %d %d",&a,&aa,&aaa);
	if (a+aa+aaa >= 22){
		printf("%s","bust");
	}else{
		printf("%s","win");
	}
}

Measured memory_bytes: 3728
#include <stdio.h>

int main(){
	int n,i,ans;

	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}

		ans = 0;
		while(n != 0){
			ans += n/5;
			n /= 5;
		}

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

	return 0;
}

Measured memory_bytes: 600
n, m, l = map(int, input().split())
A = []
B = []
C = [[0 for j in range(l)] for i in range(n)]
for i in range(n):
    A.append(list(map(int, input().split())))
for i in range(m):
    B.append(list(map(int, input().split())))
for i in range(n):
    for j in range(l):
        for k in range(m):
            C[i][j] += A[i][k] * B[k][j]
    print(*C[i])



Measured memory_bytes: 7044
n, y = [int(x) for x in input().split(' ')]

max_ten_th = int(y/10000)
for ten_th in range(min(n, max_ten_th), -1, -1):
    if y < ten_th * 10000 or n < ten_th:
        continue
    
    max_five_th = int((y-ten_th*10000)/5000)
    for five_th in range(min(n-ten_th, max_five_th), -1, -1):
        if y < ten_th*10000+five_th*5000 or n < ten_th+five_th:
            continue
            
        th = int((y-ten_th*10000-five_th*5000)/1000)
        if (y-ten_th*10000-five_th*5000) % 1000 == 0 and n == ten_th+five_th+th:
            print('{} {} {}'.format(ten_th, five_th, th))
            exit()
            
print('-1 -1 -1')

Measured memory_bytes: 3064
#define _USE_MATH_DEFINES
#define INF 0x3f3f3f3f
#include <cstdio>
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>
#include <cctype>
#include <utility>
 
using namespace std;
 
typedef long long ll;
typedef pair <int,int> P;
typedef pair <int,P > PP;
 
static const int tx[] = {0,1,0,-1};
static const int ty[] = {-1,0,1,0};
 
static const double EPS = 1e-8;

// dp[picked secret][picked standard][money] ::= max satisfaction
int dp[3][105][1005]; 

int main(){
  int money_limit;
  int total_secret_artists;
  int total_standard_artists;
  int to_pick_standard_artists;
  while(~scanf("%d %d %d %d",
               &money_limit,
               &total_secret_artists,
               &total_standard_artists,
               &to_pick_standard_artists)){
    
    if(money_limit == 0
       && total_secret_artists == 0
       && total_standard_artists == 0
       && to_pick_standard_artists == 0) break;

    memset(dp,-1,sizeof(dp));
    dp[0][0][0] = 0;
    for(int artist_idx=0;artist_idx<total_secret_artists;artist_idx++){
      string name;
      int cost;
      int satisfaction;

      cin >> name >> cost >> satisfaction;
      for(int prev_picked=1;prev_picked>=0;prev_picked--){
        for(int prev_money=1000;prev_money>=0;prev_money--){
          if(prev_money + cost > 1000) continue;

          if(dp[prev_picked][0][prev_money] == -1) continue;
          dp[prev_picked + 1][0][prev_money + cost]
            = max(dp[prev_picked][0][prev_money] + satisfaction,
                  dp[prev_picked + 1][0][prev_money + cost]);
        }
      }
    }
    for(int artist_idx=0;artist_idx<total_standard_artists;artist_idx++){
      string name;
      int cost;
      int satisfaction;
      cin >> name >> cost >> satisfaction;
      for(int picked_secret=min(2,total_secret_artists);picked_secret>=1;picked_secret--){
        for(int prev_picked_standard = artist_idx; prev_picked_standard  >= 0; prev_picked_standard--){
          for(int prev_money=1000;prev_money>=0;prev_money--){
          if(prev_money + cost > 1000) continue;

          if(dp[picked_secret][prev_picked_standard][prev_money] == -1) continue;
          dp[picked_secret][prev_picked_standard + 1][prev_money + cost]
            = max(dp[picked_secret][prev_picked_standard + 1][prev_money + cost],
                  dp[picked_secret][prev_picked_standard][prev_money] + satisfaction);
          }

        }
      }        
    }

    int res = 0;
    for(int picked_secret=min(2,total_secret_artists);picked_secret>=1;picked_secret--){
      for(int picked_standard = total_standard_artists; picked_standard  >=to_pick_standard_artists; picked_standard--){
        for(int money=money_limit;money>=0;money--){
          res = max(dp[picked_secret][picked_standard][money],res);
        }
      }
    }

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

Measured memory_bytes: 2496
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  ll n,k; cin >> n >> k;
  vector<ll> data(n); REP(i,n) cin >> data[i];
  ll sum=0; 
  sort(ALL(data),greater<int>());
  REP(i,min(k,n)){
    data[i] = 0;
  }
  REP(i,n){
    sum += data[i];
  }
  cout << sum << endl;
}

Measured memory_bytes: 4844