akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;
using ll = long long;

ll A, B;
int main(){
    cin >> A >> B;
    char d[80][50];
    for(int i = 0; i < 80; ++i)
    for(int j = 0; j < 50; ++j){
        if(i < 40) d[i][j] = '.';
        else d[i][j] = '#';
    }

    for(int i = 0; i < B-1; ++i){
        int x = 2 * (i % 20);
        int y = 2 * (i / 20);
        d[x][y] = '#';
    }

    for(int j = 0; j < A-1; ++j){
        int x = 41 + 2 * (j % 20);
        int y = 2 * (j / 20);
        d[x][y] = '.';
    }

    cout << 80 << " " << 50 << endl;
    for(int i = 0; i < 80; ++i){
        for(int j = 0; j < 50; ++j){
            cout << d[i][j];
        }
        cout << endl;
    }

}


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

int main(){
  int h,w;
  cin >> h >> w;
  vector<vector<char>> data(h,vector<char>(w));
  rep(i,h){
    rep(j,w){
      cin >> data.at(i).at(j);
      //cout << data.at(i).at(j);
    }
  }
  veci(x,100);
  veci(y,100);
  int xn=0;
  int yn=0;
  
  rep(i,h){
    rep(j,w){
      if(data.at(i).at(j) == '#'){
        x.at(xn) = i;
        xn++;
        break;
      }
    }
  }
  
  rep(i,w){
    rep(j,h){
      if(data.at(j).at(i) == '#'){
        y.at(yn) = i;
        yn++;
        break;
      }
    }
  }
  int p,q;
  rep(i,xn){
    p = x.at(i);
    rep(j,yn){
      q = y.at(j);
      //cout << p << q;
      cout << data.at(p).at(q);
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int top,S[1000];
void push(int x){
S[++top]=x;
}
int pop(){
top--;
return S[top+1];
}
int main(){
int a,b;
top =0;
char s[100];
while(cin>>s){
if(s[0]=='+'){
a = pop();
b = pop();
push(a+b);
}else if(s[0]=='-'){
b = pop();
a = pop();
push(a-b);
}else if (s[0]=='*'){
a = pop();
b = pop();
push(a*b);
}else{
push(atoi(s));
}
}
cout<<pop()<<endl;
return 0;
}

Measured memory_bytes: 1152
#include<cstdio>
#include<cstring>
#include<vector>
#include<set>
#include<iostream>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<stdlib.h>
#define M 500005
#define N 100
#define ll long long
#define oo 1000000000
#define mod 555555555
using namespace std;
int n,m;
int B[M],A[M],L,R;
int main(){
	int i,j;
	cin>>n;
	for(i=1;i<=n;i++){
		scanf("%d",&A[i]);
	}
	L=250000;
	B[L]=A[1];
	R=250000;
	for(i=2;i<=n;i++){
		if(i%2==0){
			B[++R]=A[i];
		}else B[--L]=A[i];
	}
	if(i%2==1){
		for(i=R;i>=L;i--){
			printf("%d ",B[i]);
			
		}
	}else {
		for(i=L;i<=R;i++){
			printf("%d ",B[i]);
			
		}
	}
	return 0;
}
	

Measured memory_bytes: 3712
n, m, q = map(int, input().split())
X = [list(map(int, input().split())) for _ in range(q)]

ans = 0

from itertools import combinations_with_replacement

for _x in combinations_with_replacement(range(1,m+1), n):
    _ans = 0
    for (a, b, c, d) in X:
        if _x[b-1] - _x[a-1] == c:
            _ans += d
    ans = max(ans, _ans)

print(ans)


Measured memory_bytes: 68032
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    int a, b;
    cin >> a >> b;

    if (a == 1 || b == 1) {
        if (a < b) {
            cout << "Alice" << endl;
        } else if (a > b) {
            cout << "Bob" << endl;
        } else {
            cout << "Draw" << endl;
        }
    } else {
        if (a < b) {
            cout << "Bob" << endl;
        } else if (a > b) {
            cout << "Alice" << endl;
        } else {
            cout << "Draw" << endl;
        }
    }

    return 0;
}


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

/* If you don't get my code, I am not responsible */
/* Proceed at your own risk */

#define PI acos(-1)
#define F first
#define S second
#define mod 1000000007
#define mod1 998244353
#define INFF 1000000000000000005LL
#define len length()
#define pb push_back
#define input(a,n)  for(long long int cx=0;cx<n;cin>>a[cx++]);
#define out(a,n)  for(long long int cx=0;cx<n;cout<<a[cx++]<<" ");
#define itr iterator
#define all(a)		        a.begin(),a.end()
#define sorta(a)    sort(a.begin(),a.end())
#define sortd(a)    sort(a.rbegin(),a.rend())
#define mkpr make_pair
// #define debug(x) cerr <<"#"<< #x << " = " << x << endl;
#define mem(x) memset(x,0,sizeof(x))
#define bits(x) _builtin_popcount(x)
#define ctz(x) __builtin_ctz(x)
#define deci(n) cout<<fixed<<setprecision(n);
#define pq priority_queue
// #define endl "\n"

#define fori(n)  for (ll i=0; i<n; i++)
#define forj(n)  for (ll j=0; j<n; j++)
#define fork(n)  for (ll k=0; k<n; k++)
#define rep(i,n)  for (ll i=0; i<n; i++)
#define repr(i,n)  for (ll i=n-1; i>=0; i--)
#define repm(it, mp)  for(it= mp.begin(); it!= mp.end();it++)

typedef long long ll;
typedef long double ld;
typedef vector <ll> vll;
typedef vector <int> vi;
typedef pair<ll,ll> pll;
typedef map<ll,ll> mll;
typedef vector <pair<ll,ll> > vpll;

int dir8x[8] = { -1, 0, 0, 1, -1, -1, 1, 1 }; 
int dir8y[8] = { 0, 1, -1, 0, -1, 1, -1, 1 };
int dir4x[4] = { -1, 0, 0, 1 }; 
int dir4y[4] = { 0, 1, -1, 0 };

#ifdef DEBUG
#define debug(...) __f(#__VA_ARGS__,__VA_ARGS__)
template<typename Arg1>
void __f(const char* name,Arg1&& arg1){
	cout<<"#"<<name<<" = "<<arg1<<endl;
}
template<typename Arg1,typename... Args>
void __f(const char* names,Arg1&& arg1,Args&&... args){
		const char* comma=strchr(names+1,',');cout<<"#";cout.write(names,comma-names)<<" = "<<arg1<<" | ";__f(comma+1,args...);
}
#else
#define debug(...) 36
#endif

/**************************************/
int isPrime(ll num)
{
    if(num <= 1) return 0; 
    for (ll i = 2; i * i <= num; i++)
        if (num % i == 0) return 0;
    return 1;
}

ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
    x = x % p;  // Update x if it is more than or  
                // equal to p 
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p;   
    } 
    return res; 
}

const int M = 1e5+5;

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

    ll tc,m,n,k,ans=0,total=0,count=0;

    cin >> n;
    ll a[n+1];
    for(ll i=1; i<=n; i++)cin >> a[i];

    ll dp[n+1];

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

    for(ll i=3; i<=n; i++)
    {
        dp[i] = min(dp[i-1] + abs(a[i]-a[i-1]), dp[i-2] + abs(a[i]-a[i-2]));
    }

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

// g++ -std=c++14 code.cpp
// g++ -std=c++14 -DDEBUG code.cpp

Measured memory_bytes: 1792
import sys

# import numpy as np

input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

INF = 10 ** 18


def main():
    N, W = map(int, input().split())
    w = []
    v = []
    for i in range(N):
        weight, value = map(int, input().split())
        w.append(weight)
        v.append(value)

    """    
    dp[ i ] : 価値 i における重さの最小値
    　
    品物一つ w,v を見ていくたびに、
    dp[ i ] = (その品物を使うパターン) or (その品物を使わないパターン)
    = min( dp[i -v] + w , dp[ i ] ) 
    を更新していけばよい。
    """

    dp = [0] + [INF] * 10 ** 5

    for i in range(N):
        for j in range(10 ** 5, v[i] - 1, -1):
            dp[j] = min(dp[j - v[i]] + w[i], dp[j])

    # print(dp[:30])

    ans = 0

    for i, j in enumerate(dp):
        if j <= W:
            ans = i
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 40304
h, w = map(int, input().split())
a = [list(input()) for i in range(h)]

for i in range(h-1,-1,-1):
    if not '#' in a[i]:
        del a[i]
h = len(a)
for j in range(w-1, -1, -1):
    res = True
    for i in range(h):
        if a[i][j] == '#':
            res = False
    if res:
        for i in range(h):
            del a[i][j]

for i in range(len(a)):
    print("".join(a[i]))



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

int main(){
    int n,a[10005]={},cnt=0;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>a[i];
        while(!(a[i]&1)){
            cnt++;
            a[i] = a[i] >> 1;
        }
    }
    cout<<cnt<<endl;
}

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

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

  map<int, int> m;
  map<int, int> m2;

  for (int i = 0; i < n; i++) {
    int v;
    cin >> v;

    if (i % 2 == 0) {
      if (m.count(v)) {
        m.at(v)++;
      } else {
        m[v] = 1;
      }
    } else {
      if (m2.count(v)) {
        m2.at(v)++;
      } else {
        m2[v] = 1;
      }
    }
  }

  int first = 0;
  int firstCount = 0;
  int secondCount = 0;
  for (auto x : m) {
    if (x.second > firstCount) {
      secondCount = firstCount;
      first = x.first;
      firstCount = x.second;
    } else if (x.second > secondCount) {
      secondCount = x.second;
    }
  }

  int first2 = 0;
  int firstCount2 = 0;
  int secondCount2 = 0;
  for (auto x : m2) {
    if (x.second > firstCount2) {
      secondCount2 = firstCount2;
      first2 = x.first;
      firstCount2 = x.second;
    } else if (x.second > secondCount2) {
      secondCount2 = x.second;
    }
  }

  if (first != first2) {
    cout << n - firstCount - firstCount2 << endl;
  } else {
    if (firstCount + secondCount2 > secondCount + firstCount2) {
      cout << n - firstCount - secondCount2 << endl;
    } else {
      cout << n - secondCount - firstCount2 << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <cstdio>
#include <queue>
#include <deque>
#include <map>
#include <stack>
#include <set>
#include <utility>
#include <functional>
using namespace std;
typedef pair<int, int> pii;
typedef pair<string, int> P;
typedef long long ll;
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
const int MAXN = 100000;
const int MAXE = 100000;
const int MAXV = 10000;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
int main(){
    int n;cin>>n;
    vector<int> d(n),c(13,0);
    for(int i=0;i<n;++i){
        cin>>d[i];
        c[d[i]]++;
    }
    for(int i=0;i<=12;++i){
        if(c[i]>=3){
            cout<<0<<endl;
            return 0;
        }
    }
    vector<int> t;
    int sw=0;
    for(int i=0;i<=12;++i){
        if(c[i]==2){
            t.push_back(i);
            t.push_back(24-i);
        }else if(c[i]==1){
            if(sw==1){
                t.push_back(24-i);
            }else t.push_back(i);
            sw=1-sw;
        }
    }
    t.push_back(0);
    sort(t.begin(),t.end());
    int ans=24;
    for(int i=0;i<=n;++i){
        for(int j=i+1;j<=n;++j){
            ans=min(ans,min(t[j]-t[i],24-(t[j]-t[i])));
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3600
n = int(input())
mod = 10**9+7
part1 = 10 **n 
part2 = 8 ** n
part3 = 2 * (9 ** n) #-
part1 %= mod
part2 %= mod
part3 %= mod
print((part1 +part2 - part3)%mod)

Measured memory_bytes: 11428
#include <iostream>
#include <vector>
#include <string>
using namespace std;
const long long MAXN= 1e10000;
string str;
int pos1,pos2;
int main()
{
    pos1=0,pos2=1;
    cin>>str;
    int cnt=0;
    while(pos2<=str.size() && cnt<MAXN )
    {
        while (!(str[pos1] == 'S' && str[pos2] == 'T')) {
            pos1++, pos2++;
            if (pos2 > str.size()) break;
        }
        if (pos2 > str.size()) break;
        str.erase(pos1, 2);
        cnt++;
        if(pos1>0)
            pos1--,pos2--;
    }
    cout<<str.size();
    return 0;
}

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define size 100005

int main() {
    int N, A[size], h[size], x, rnd, K;

    cin >> N >> K;

    for(int i=0; i<N; i++)
    {
        cin >> h[i];
    }
    A[0] = 0;

    for(int i=1; i<N; i++) {

        A[i] = A[i-1] + abs(h[i]-h[i-1]);

        for(int j=2; j<=K; j++) {
            if(i-j < 0)
                break;
            rnd = A[i-j] + abs(h[i]-h[i-j]);

            if(rnd < A[i])
                A[i] = rnd;    
        }
    }

    cout << A[N-1] << endl;
    return 0;
}

Measured memory_bytes: 1024
/*** akshaykumar99 ***/
 
#include<bits/stdc++.h> 
using namespace std;
 
const long long MOD = 1e9+7;
const long double PI = acos(-1);
const long long N = 2e9;
 
typedef long long ll;
typedef long double ld;

void test_case()
{
	ll x;
	cin >> x;
	cout << 1- x;
	
}
 
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL); 
    ll tc=1;
    // cin>>tc;
    while(tc--)
        test_case();
    return 0;
}


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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
typedef pair<int,int> P;

//-----------------------------------------------------------------------
int calc(int a){
    string s=to_string(a);
    int res=0;
    for(int i=1;i<s.size();i++){
        int t=stoi(s.substr(0,i))*stoi(s.substr(i));
        res=max(res,t);
    }
    return res;
}

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

    int n; cin>>n;
    REP(i,n){
        int a; cin>>a;
        int cnt=0;
        while(10<=a){
            a=calc(a);
            cnt++;
        }
        cout<<cnt<<endl;
    }
}




Measured memory_bytes: 3244
#include <bits/stdc++.h>
#include <cmath>
#include <numeric>
using namespace std;
#define rep(i,a,b) for(int64_t i=(a); i<(b); ++i) // a ≦ i < b 
#define Rrep(i,a,b) for(int64_t i=(a);i>=(b);--i) // reverse repeat. a から b まで減少．
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend() //逆イテレータ
#define INF 10000000000000
#define MOD 1000000007LL
#define RANGE(a,b,c) (a).begin()+(b),(a).begin()+(c) // [b,c) イテレータ
using PII = pair<int64_t, int64_t>;
using VI = vector<int64_t>;
using VVI = vector<VI>;
using VS = vector<string>;
using VP = vector<PII>;
using i64 = int64_t;
// input vector
template<typename T>
void invec(vector<T> &A){for(T& a : A) cin >> a;}


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

int N; cin >> N;
VI P(N), Q(N); invec(P), invec(Q);

int a = 0, b = 0;

VI ini; rep(i, 1, N+1) ini.push_back(i);
do {
    bool f = true;
    rep(i, 0, N) if (P[i] != ini[i]) f = false;
    if (f) break;
    else ++a;
}while(next_permutation(ALL(ini)));

ini.clear(); rep(i, 1, N+1) ini.push_back(i);
do {
    bool f = true;
    rep(i, 0, N) if (Q[i] != ini[i]) f = false;
    if (f) break;
    else ++b;
}while(next_permutation(ALL(ini)));


cout << abs(a - b) << "\n";
}
// 書いて考える．場合分け
// 境界，出力文字列 チェック．行末にスペース入れない．
// 可読性優先．高速化次点．
// まずは全探索，次にDP
// 制限を見る．境界に注意．求めたい量の変域．動かせる量．
// 偶奇，逆から，ソート，出現回数，出現位置，DP， 余事象，包除
// データ構造． 問題の特徴量．単調性，二分探索
// 存在判定：構成方法，入力の特徴
// gcd, lcm ,素因数分解．
// 例外を十分に含む一般化．想像力の限界
// 小さい系から例示
// 代数的処理．前処理によるクエリ高速化．
// 始めは過剰に例示・場合分けしてもいい．各場合を確実に対処．
// 自明な例から処理，除外．
// 小数のときは，精度の設定する．doubel 変数に数値を入力するときは 123. とする．
// テストケース作成は数表あり
// 実行エラー：vector添え字超え．0割り．



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

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();

        if (t.Remove(t.Length - 1) == s) Console.WriteLine("Yes");
        else Console.WriteLine("No");

    }
}

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

int main() {
  std::cin.tie(0); std::ios::sync_with_stdio(false);
  std::string S; std::cin >> S;
  fin(S.substr(0, 3));
  return 0;
}


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

using namespace std;

int main() {
	int a,AC,WA,TLE,RE;
	AC = 0;
	WA = 0;
	TLE = 0;
	RE = 0;
	cin >> a;
	for(int i=0;i<a;i++) {
		string test;
		cin >> test;
		if(!(test.compare("AC")))
			AC++;
		else if((!test.compare("WA")))
			WA++;
		else if((!test.compare("TLE")))
			TLE++;
		else if((!test.compare("RE")))
			RE++;
	}
	cout << "AC x " << AC << "\n";
		cout << "WA x " << WA << "\n";
			cout << "TLE x " << TLE << "\n";
			cout << "RE x " << RE << "\n";

}

Measured memory_bytes: 3624
s = input()
n = len(s)
ans = 'No'
sulice1 = s[0:(n-1)//2]
sulice2 = s[(n+1)//2:n+1]
if s == s[::-1] and  sulice1 == sulice1[::-1] and sulice2 == sulice2[::-1]:
  ans = 'Yes'
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++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
 
int main() {
  int A, j = 0, l = 0, k= 0, f = 0;
  cin >> A;
 
  // ここにプログラムを追記
    rep(i ,A) {
        string op;
        cin >> op;
      
      
        if (op == "P") {
         j = 1;
        }
        else if (op == "W") {
         l = 1;
        }
        else if (op == "G") {
         k = 1;
        }
        else if (op == "Y") {
         f = 1;
        }
        else {
          cout << "error" << endl;
          break;
        }
      
  	}
  	if (j + l + k + f == 4) {
    	cout << "Four";
    }
  	else if (j + l + k + f == 3) {
    	cout << "Three";
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
string s,t,u;
int a,b;
int main()
{
	cin>>s>>t;
	cin>>a>>b;
	cin>>u;
	if(u==s) a--;
	if(u==t) b--;
	cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 256
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
#include<bitset>
#include<functional>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<random>
#include<ctime>
#include<complex>
using namespace std;
typedef long long LL;
mt19937 gene(233);
typedef complex<double> Complex;
#define fi first
#define se second
#define ins insert
#define pb push_back
inline char GET_CHAR(){
	const int maxn = 131072;
	static char buf[maxn],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
}
inline int getInt() {
	int res(0);
	char c = getchar();
	while(c < '0') c = getchar();
	while(c >= '0') {
		res = res * 10 + (c - '0');
		c = getchar();
	}
	return res;
}

inline LL fastpo(LL x, LL n, LL mod) {
	LL res(1);
	while(n) {
		if(n & 1) {
			res = res * (LL)x % mod;
		}
		x = x * (LL) x % mod;
		n /= 2;
	}
	return res;
}
inline string itoa(int x, int width = 0) {
  string res;
  if(x == 0) res.push_back('0');
  while(x) {
    res.push_back('0' + x % 10);
    x /= 10;
  }
  while((int)res.size() < width) res.push_back('0');
  reverse(res.begin(), res.end());
  return res;
}
const int _B = 131072;
char buf[_B];
int _bl = 0;
inline void flush() {
	fwrite(buf, 1, _bl, stdout);
	_bl = 0;
}
__inline void _putchar(char c) {
	if(_bl == _B) flush();
	buf[_bl++] = c;
}
inline void print(LL x, char c) {
	static char tmp[20];
	int l = 0;
	if(!x) tmp[l++] = '0';
	else {
		while(x) {
			tmp[l++] = x % 10 + '0';
			x /= 10;
		}
	}
	for(int i = l - 1; i >= 0; i--) _putchar(tmp[i]);
	_putchar(c);
}
const int N = 300033;
const int LOG = 20;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int cnt[N];
int main() {
	int n;
	cin >> n;
	LL sum = 0;
	for(int i = 1; i <= n; i++) {
		int x;
		cin >> x;
		sum += x;
		cnt[x] ++;
	}
	int Q;
	cin >> Q;
	for(int i = 1; i <= Q; i++) {
		int x, y;
		cin >> x >> y;
		sum += (LL)(y - x) * cnt[x];
		cnt[y] += cnt[x];
		cnt[x] = 0;
		cout << sum << endl;
	}

}






Measured memory_bytes: 3952
#define _CRT_SECURE_NO_WARNINGS

#pragma comment(linker, "/STACK:250000000")

#include <iostream>
#include <fstream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <bitset>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <complex>
#include <functional>
#include <numeric>
#include <random>
#include <cstring>
#include <ctime>
#include <cassert>

#define y1 klfjvkldfngldf

using namespace std;

typedef long long LL;

string s;

int main()
{
	cin >> s;

	set<int> sc;
	for (char c : s)
		sc.insert(c);

	int res = (int)s.size() - 1;
	if (sc.size() == 1)
		res = 0;
	for (char c : sc)
	{
		string old = s;
		for (int i = (int)s.size() - 1; i >= 1; --i)
		{
			string news = "";
			for (int j = 0; j < i; ++j)
			{
				char add = old[j];
				if (old[j + 1] == c)
					add = c;
				news += add;
			}
			old = news;
			if (old == string(i, c))
				res = min(res, (int)s.size() - i);
		}
	}

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

Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<algorithm>

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

int dfs(int l,int r,int n,const int *bit){
	if(l==r-1) return l;

	putchar('?');
	rep(i,n){
		if     (l<=i && i<(l+r)/2) putchar('0'+bit[i]);
		else if(i<=(l+r)/2 && i<r) putchar('0');
		else                       putchar('0');
	}
	putchar('\n'); fflush(stdout);

	int v; scanf("%d",&v);
	return v?dfs(l,(l+r)/2,n,bit):dfs((l+r)/2,r,n,bit);
}

int main(){
	srand(777);
	int n,k; scanf("%d%d",&n,&k);
	int ans[10];
	rep(t,k){
		int bit[10000];
		while(1){
			putchar('?');
			rep(i,n){
				if(count(ans,ans+t,i)) bit[i]=0;
				else                   bit[i]=rand()&1;
				putchar('0'+bit[i]);
			}
			putchar('\n'); fflush(stdout);

			int v; scanf("%d",&v);
			if(v) break;
		}

		ans[t]=dfs(0,n,n,bit);
	}

	printf("!");
	rep(t,k) printf("%d%c",ans[t]+1,t<k-1?' ':'\n');

	return 0;
}

Measured memory_bytes: 780
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    string a,b;
    cin >> a >> b;
    if(a==b)cout<<"H";else cout <<"D";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define F first
#define S second
#define PB push_back
#define REP(i,a,b) for (int i = a ; i <= b ; i++)
#define REPI(i,a,b) for (int i = a ; i >= b ; i--)
using namespace __gnu_pbds;
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef pair<ll,ll> pi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> indexed_set;

const int OO = 1e9+7;
const int MOD = 1e9+7;
const int N = 1e5+7;

ll a[N],b[N];

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    //freopen("teleport.in","r",stdin);
    //freopen("teleport.out","w",stdout);

    int n,m;
    ll ans = 0;
    cin >> n >> m;
    vector<pi> vec;
    REP(i,0,n-1)
    {
        cin >> a[i] >> b[i];
        vec.PB({a[i],b[i]});
    }
    sort(vec.begin(),vec.end());
    REP(i,0,n-1)
    {
        ans += min((ll)m,vec[i].S)*vec[i].F;
        m -= min((ll)m,vec[i].S);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3568
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Data;
using System.Linq;
using System.Numerics;
using System.Text.RegularExpressions;

class Program
{
    static long[] ReadLongs()
        => Console.ReadLine()
            .Split(new[] { ' ', '\t' }, StringSplitOptions.RemoveEmptyEntries)
            .Select(s => long.Parse(s))
            .ToArray();

    static void Main(string[] args)
    {
        string s = Console.ReadLine();
        if (s.ToLower() == s)
        {
            Console.WriteLine('a');
        }
        else
        {
            Console.WriteLine('A');
        }
    }
}

Measured memory_bytes: 26300
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using u64 = unsigned long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

void solve(int n){
    vector<vector<int>> grid(5, vector<int>(5*n+1));
    for (int i = 0; i < 5; ++i) grid[i].back() = n+1;
    vector<int> alive(5*n+1);
    vector<int> cnt(5*n+1);
    iota(alive.begin(),alive.end(), 0);
    stack<int> X;
    for (int _ = 0; _ < n; ++_) {
        int d, p, q;
        cin >> d >> p >> q; q--;
        if(d == 1){
            for (int i = 1; i < grid[0].size(); ++i) {
                int ok = 1;
                for (int j = q; j < q+p; ++j) {
                    if(grid[j][alive[i]]) ok = 0;
                }
                if(!ok){
                    for (int j = q; j < q+p; ++j) {
                        int a = alive[i-1];
                        grid[j][a] = _+1;
                        cnt[a]++;
                        if(cnt[a] == 5) X.emplace(a);
                    }
                    break;
                }
            }
        }else {
            for (int i = 1; i+p-1 < grid[0].size(); ++i) {
                int ok = 1;
                for (int j = i; j < i+p; ++j) {
                    if(grid[q][alive[j]]) ok = 0;
                }
                if(!ok){
                    for (int j = i; j < i+p; ++j) {
                        int a = alive[j-1];
                        grid[q][a] = _+1;
                        cnt[a]++;
                        if(cnt[a] == 5) X.emplace(a);
                    }
                    break;
                }
            }
        }
        while(!X.empty()){
            alive.erase(lower_bound(alive.begin(),alive.end(), X.top())); X.pop();
        }
    }
    int ans = 0;
    for (auto &&j : alive) {
        for (int i = 0; i < 5; ++i) {
            if(grid[i][j] && grid[i][j] <= n) ans++;
        }
    }
    cout << ans << "\n";
}

int main() {
    int n;
    while(cin >> n, n){
        solve(n);
    }
    return 0;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,a,b) for(int i=a; i<=b; i++)
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define INF 1000000000000
#define MOD 1000000007
#define PI 3.14159265359
#define dij priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>
typedef long long ll;
//
int main(){
  ll n,x,m;cin>>n>>x>>m;
  vector<ll> v(100001);
  v[0]=x;
  FOR(i,1,100000){
    v[i]=(v[i-1]*v[i-1])%m;
  }
  map<ll,ll> mp;
  ll co=0;
  rep(i,1000001){
    mp[v[i]]++;
    co++;
    if(mp[v[i]]==2)break;
  }
  co--;
  //rep(i,10)cout<<v[i]<<" ";
  //cout<<endl;
  //cout<<co;
  ll co2=0;
  rep(i,v.size()){
    if(v[i]==v[co]){
      co2=i;
      break;
    }
  }
  //cout<<co<<" "<<co2<<endl;;
  ll dif=co-co2;
  ll dd=0;
  FOR(i,co2,co-1){
    dd+=v[i];
  }
  ll da=0;
  FOR(i,0,co2-1){
    da+=v[i];
  }
  //cout<<dd<<" "<<da;
  ll ans=0;
  if(n<co2){
    rep(i,n)ans+=v[i];
  }else{
    rep(i,co2)ans+=v[i];
    n=n-co2;
    ans+=(n/dif)*dd;
    FOR(i,co2,co2+n%dif-1)ans+=v[i];
  }
  //cout<<dif<<endl;
  cout<<ans<<endl;
}

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

#define v vector
#define ll long long 
#define vpll vector<pair<long long,long long> > 
#define F first
#define S second
#define mp make_pair
#define ld long double
#define pb push_back
#define pii pair<int,int>
#define pci pair<char,int>
 
using namespace std; 



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,m;
    cin>>n>>m;
    v<ll> a(n,0);
    for(int i = 0 ; i < n ; i++)
    cin>>a[i];
    sort(a.begin(),a.end());
    v<pair<ll,ll> >x;
    for(int i = 0 ; i < m ; i++)
    {
        ll p,q;
        cin>>p>>q;
        x.pb(mp(q,p));
    }
    sort(x.rbegin(),x.rend());
    int i = 0;
    int j = 0;
    while(i < n && j < m && x[j].S)
    {
        if(a[i] >= x[j].F)
        {
            i++;
        }
        else 
        {
            a[i] = x[j].F;
            i++;
            if(x[j].S == 1)
            {
                x[j].S--;
                j++;
            }
            else
            {
                x[j].S--;
            }   
        }
    }
    ll sum = 0;
    for(int i = 0 ; i < n ; i++)
    sum += a[i];
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int k, n;
	char s[11];
	cin >> n;
	cin >> s;
	cin >> k;
	for (int i = 0; i < n; i++)
		if (s[i] != s[k - 1])
			s[i] = '*';
	cout << s;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long dp[101][(int)pow(10, 5) + 1]={0};
int value[101];
int weight[101];
int main()
{
    int n, w;
    cin>>n>>w;
    for(int i=0;i<n;i++)
        cin>>weight[i]>>value[i];
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=w; j++)
        {
            dp[i][j]=dp[i-1][j];
            if(j - weight[i-1] >=0)
            {
                dp[i][j]=max(dp[i-1][j], dp[i-1][j - weight[i-1]] + value[i-1]);
            }
        }
    }
    cout<<dp[n][w]<<endl;
    return 0;
}


Measured memory_bytes: 78464
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);
		StringBuilder S = new StringBuilder(sc.next());
		String T = sc.next();
		String ans = "No";
		for (int i = 0; i < S.length(); i++) {
			S.insert(0, S.substring(S.length() - 1));
			S.delete(S.length() - 1, S.length());
			if (S.toString().equals(T)) {
				ans = "Yes";
				break;
			}
		}
		System.out.println(ans);

	}

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define pi 3.14159265359
using namespace std;
const long long INF=1e9+7;
const string alp="abcdefghijklmnopqrstuvwxyz"; //26
const string ALP="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
//const ll MOD=998244353LL;
//const ll MOD=1777777777LL;


int main() {
  ll H,W,K;  
  cin>>H>>W>>K;
  char c[H][W],d[H][W];
  rep(i,H){
    rep(j,W){
      cin>>c[i][j];
      d[i][j]=c[i][j];
    }
  }
  ll ans=0;
  for(int tmp=0;tmp<(1<<H+W);tmp++){
    for(int i=0;i<H;i++){
      if(tmp & (1<<i)){
        for(int j=0;j<W;j++){
          d[i][j]='0';
        }
      }
    }
    for(int i=0;i<W;i++){
      if(tmp & (1<<(i+H))){
        for(int j=0;j<H;j++){
          d[j][i]='0';
        }
      }
    }
    ll count=0;
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        if(d[i][j]=='#'){
          count++;
        }
      }
    }
    if(count==K){
      ans++;
    }
    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
        d[i][j]=c[i][j];
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3648
s = int(input())

def f(n):
    if n % 2 ==0:
        return n/2
    else:
        return 3 *n +1

a = [s]
for i in range(1000000):
    a_new = f(a[i])
    if a_new in a:
        print(i+2)
        exit(0)
    a.append(a_new)  

Measured memory_bytes: 2940
#include<stdio.h>
int main(){
  int a,b,c,d,e,f;
  int tempa,tempb;
  int i,j;
  char cc;
  scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f);
  scanf("%c",&cc);
  while(1){
    scanf("%c",&cc);
    if(cc=='\n')break;
    if(cc=='S'){
      tempa=a;
      a=e;
      e=f;
      f=b;
      b=tempa;
    }
    else if(cc=='N'){
      tempa=a;
      a=b;
      b=f;
      f=e;
      e=tempa;
    }
    else if(cc=='W'){
      tempa=a;
      a=c;
      c=f;
      f=d;
      d=tempa;
    }
    else if(cc=='E'){
      tempa=a;
      a=d;
      d=f;
      f=c;
      c=tempa;
    }
  }
  printf("%d\n",a);
  return(0);
}

Measured memory_bytes: 596
K,*as=$<.read.split.map(&:to_i)

if as[-1] != 2
  puts -1
  exit 0
end

min = 2
max = 3
(K-2).downto(0) do |i|
  min = ((min-1)/as[i]+1)*as[i]
  max = max/as[i]*as[i] + as[i] - 1
  if max < min
    puts -1
    exit 0
  end
end

puts [min,max].join(' ')

Measured memory_bytes: 9340
#include<iostream>
using namespace std;
bool f(int p)
{
	if(p<2)return 0;
	for(int i=2;i*i<=p;i++)
	{
		if(p%i<1)return 0;
	}
	return 1;
}
int n;
main()
{
	while(cin>>n,n)
	{
		int cnt=0;
		for(int i=n;i++<n*2;)cnt+=f(i);
		cout<<cnt<<endl;
	}
}



Measured memory_bytes: 3068
import sys
input = sys.stdin.readline
n,m=map(int, input().split(' '))
p = list(map(int, input().split(' ')))
ab = [list(map(int, input().split())) for i in range(m)]
graph = [[] for i in range(n+1)]
visited = [0]*(n+1)
conlist = [0]*(n+1)
for a,b in ab:
    graph[a].append(b)
    graph[b].append(a)
stack = []
cnt = 0
append = stack.append
pop = stack.pop
for i in range(1,n+1):
    if visited[i] != 1:
        cnt += 1
        append(i)
    while stack:
        x = pop()
        visited[x] = 1
        conlist[x] = cnt
        for y in graph[x]:
            if visited[y] != 1:
                append(y)
ans = 0
for i in range(1,n+1):
    if conlist[p[i-1]] == conlist[i]:
        ans+=1
print(ans)

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

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

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

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

  ll N;
  cin >> N;
  ll ans = 0;
  for(ll i = 1; i * i <= N; i++){

    if((N-i) % i == 0){
      ll m = (N-i) / i;
      if(m > i) ans += m;
    }
  }

  cout << ans << endl;

  return 0;
}


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

using namespace std;

const int N = 1e5; int h[N], min_cost[N], n;

int main()
{
    ios_base::sync_with_stdio(false), cin.tie(nullptr), cout.tie(nullptr), cin >> n;

    for(int i = 0; i < n; ++i)
        cin >> h[i];

    min_cost[1] = abs(h[1] - h[0]);

    for(int i = 0, j = 1, k = 2; k < n; i = j, j = k++)
        min_cost[k] = min(  min_cost[i]+abs(h[k]-h[i]),
                            min_cost[j]+abs(h[k]-h[j]));

    cout << min_cost[n-1];
}


Measured memory_bytes: 1024
from collections import *
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
p.sort(reverse=True)
q=list(map(int,input().split()))
q.sort(reverse=True)
r=list(map(int,input().split()))
r.sort(reverse=True)
r=r+p[:x]+q[:y]
r.sort(reverse=True)
r=r[:x+y]
print(sum(r))


Measured memory_bytes: 105264
#include <cstdio>
#include <algorithm>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <string>
#include <string.h>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <map>
#include <set>
#include <iostream>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define gep(i,g,j) for(int i = g.head[j]; i != -1; i = g.e[i].next)
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define rng(a) a.begin(),a.end()
#define maxs(x,y) x = max(x,y)
#define mins(x,y) x = min(x,y)
#define pb push_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcount
#define uni(x) x.erase(unique(rng(x)),x.end())
#define snuke srand((unsigned)clock()+(unsigned)time(NULL));
#define df(x) int x = in()
#define dame { puts("-1"); return 0;}
#define show(x) cout<<#x<<" = "<<x<<endl;
#define PQ(T) priority_queue<T,vector<T>,greater<T> >
#define bn(x) ((1<<x)-1)
#define newline puts("")
#define v(T) vector<T>
#define vv(T) vector<vector<T>>
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
inline int in() { int x; scanf("%d",&x); return x;}
inline void priv(vi a) { rep(i,sz(a)) printf("%d%c",a[i],i==sz(a)-1?'\n':' ');}
template<typename T>istream& operator>>(istream&i,vector<T>&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T>string join(const vector<T>&v)
{stringstream s;rep(i,sz(v))s<<' '<<v[i];return s.str().substr(1);}
template<typename T>ostream& operator<<(ostream&o,const vector<T>&v)
{if(sz(v))o<<join(v);return o;}
template<typename T1,typename T2>istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<typename T1,typename T2>ostream& operator<<(ostream&o,const pair<T1,T2>&v)
{return o<<v.fi<<","<<v.se;}
const int MX = 100005, INF = 1001001001;
const ll LINF = 1e18;
const double eps = 1e-10;

// Binary Indexed Tree
struct bit {
  typedef int TT;
  int n; vector<TT> d;
  bit() {}
  bit(int mx): n(mx), d(mx) {}
  void add(int i, TT x=1) {
    for (++i;i<n;i+=i&-i) d[i] += x;
  }
  TT sum(int i) {
    TT x = 0;
    for (++i;i;i-=i&-i) x += d[i];
    return x;
  }
};
//

// coordinate compression
struct X {
  typedef ll T;
  vector<T> d;
  void add(T x) { d.pb(x);}
  void init() {
    sort(rng(d));
    d.erase(unique(rng(d)), d.end());
  }
  int size() const { return sz(d);}
  int operator[](int i) const { return d[i];}
  int operator()(T x) const { return upper_bound(rng(d),x)-d.begin()-1;}
};
//



int main() {
  int n,x;
  scanf("%d%d",&n,&x);
  vl a(n);
  cin>>a;
  rep(i,n) a[i] -= x;
  rep(i,n-1) a[i+1] += a[i];
  X xs;
  rep(i,n) xs.add(a[i]);
  xs.add(0);
  xs.init();
  bit d(sz(xs)+1);
  d.add(xs(0));
  ll ans = 0;
  rep(i,n) {
    ans += d.sum(xs(a[i]));
    d.add(xs(a[i]));
  }
  cout<<ans<<endl;
  return 0;
}






















Measured memory_bytes: 4208
n = int(input())
a = list(map(int,input().split()))

a.insert(0,0)
a.append(0)
d = [abs(a[i]-a[i+1]) for i in range(n+1)]
s = sum(d)
for i in range(1,n+1):
    print(s+abs(a[i-1]-a[i+1])-(abs(a[i-1]-a[i])+abs(a[i]-a[i+1])))

Measured memory_bytes: 65004
#include<stdio.h>
#include<string.h>

int a[85],b[85];

int reverse(int *p,int length)
{
	int i,t;

	for(i=1;i<=length/2;i++)
	{
		t=p[i];
		p[i]=p[length+1-i];
		p[length+1-i]=t;
	}

	return 0;
}

int main()
{
	int N,i,la,lb,lmax,carry,t;
	char ch;
	
	scanf("%d%*c",&N);
	
	while(N--)
	{
		la=0;
		lb=0;
		carry=0;
		memset(a,0,sizeof(a));
		memset(b,0,sizeof(b));

		while(1)
		{
			ch=getchar();

			if(ch>='0'&&ch<='9')
			{
				la++;
				a[la]=ch-'0';
			}

			else if(ch=='\n')
			{
				break;
			}
		}
	
		while(1)
		{
			ch=getchar();
			
			if(ch>='0'&&ch<='9')
			{
				lb++;
				b[lb]=ch-'0';
			}

			else if(ch=='\n')
			{
				break;
			}
		}
	
		if(la>80||lb>80)
		{
			printf("overflow\n");
			continue;
		}

		reverse(a,la);
		reverse(b,lb);

		lmax=la>lb?la:lb;

		for(i=1;i<=lmax+1;i++)
		{
			t=a[i];
			a[i]=(t+b[i]+carry)%10;
			carry=(t+b[i]+carry)/10;
		}

		for(i=lmax+1;i>=1;i--)
		{
			if(a[i]!=0)
			{
				t=i;
				break;
			}
		}

		if(t>80)
		{
			printf("overflow\n");
			continue;
		}

		if(i==0)
		{
			printf("0\n");
			continue;
		}

		for(i=t;i>=1;i--)
		{
			printf("%d",a[i]);
		}

		printf("\n");
	}
	
	return 0;
}

Measured memory_bytes: 1044
N = int(input())
h = list(map(int,input().split()))
DP = [float('inf')]*(N)
DP[0] = 0
for i in range(N-1):
    DP[i+1] = min(DP[i+1],DP[i]+abs(h[i]-h[i+1]),DP[i-1]+abs(h[i+1]-h[i-1]))
print(DP[-1])

Measured memory_bytes: 13908
#include <bits/stdc++.h>
typedef long long ll;

using namespace std;

int main() {
	array<ll, 3> x;
	bool can = true;
	for (int i = 0; i < 3; i++) {
		cin >> x[i];
		if (x[i]%2 == 1) {
			can = false;
		}
	}

	if (!can) {
		cout << 0 << endl;
		return 0;
	}

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

	if ((x[1] == x[0]) && (x[1] == x[2])) {
		cout << -1 << endl;
		return 0;
	}

	ll res = 0;
	while (true) {
		res++;
		ll a = (x[1] + x[2]) / 2;
		ll b = (x[0] + x[2]) / 2;
		ll c = (x[0] + x[1]) / 2;

		if ((a%2 == 1) || (b%2 == 1) || (c%2 == 1)) {
			break;
		}

		x[0] = a;
		x[1] = b;
		x[2] = c;

		if (res > 1e9) {
			return 0;
		}
	}

	cout << res << endl;

	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
int main()
{
    int K, A, B;
    cin >> K >> A >> B;

    int v = K * (A / K);
    bool ok = false;
    while (v <= B) {
        if (A <= v && v <= B) {
            ok = true;
            break;
        }
        v += K;
    }
    if (ok) {
        cout << "OK" << endl;
    }
    else {
        cout << "NG" << endl;
    }

    return 0;
}

Measured memory_bytes: 3604
#include "bits/stdc++.h"
using namespace std ;
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL)
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
//const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
void go(int n){
	if(n>0){
		n-- ;
		go(n/26) ;
		cout << char(n%26+'a') ;
	}
}
 
void solve(){
	int n ;
	cin >> n ;
	go(n) ;
}

int32_t main(){
	#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
	#endif
	FAST_IO ;
	int tt = 1;
//	cin >> tt ;
	while(tt--){
		solve() ;
	}
}


Measured memory_bytes: 3620
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <limits>
#include <math.h>
#include <map>

using namespace std;
typedef long long ll;

int main() {
  int N;
  ll x;
  scanf("%d %lld", &N, &x);
  vector<ll> a(N);
  for (int i = 0; i < N; ++i) scanf("%lld", &a[i]);

  ll ans = 0;
  for (int i = 0; i < N - 1; ++i) {
    if (a[i] + a[i + 1] > x) {
      ll diff = (a[i] + a[i + 1]) - x;
      ans += diff;
      a[i + 1] = max(0LL, a[i + 1] - diff);
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1024
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N,K,Q = map(int, sys.stdin.readline().split())

# list_score = [K]*N
list_score = [0]*N

list_A = [list(map(int,list(sys.stdin.readline().split()))) for i in range(Q)]

for i in range(Q):
    list_score[list_A[i][0]-1] += 1

for i in range(N):
    # print(list_score[i] - (Q-K))
    if(list_score[i] - (Q-K) <= 0):
        print('No')
    else:
        print('Yes')

# print(list_score)
# print(list_A)


Measured memory_bytes: 27856
#include <bits/stdc++.h>
using namespace std;
int N;
int main() {
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i ++) {
        cin >> A[i];
    }
    
    sort(A.begin(), A.end());
    
    int avalue = A[N-1] - A[0];
    
    cout << avalue << endl;;

}


Measured memory_bytes: 256
from math import ceil,floor,comb,factorial,gcd,pow,sqrt,log2,cos,sin,tan,pi,inf
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heappop,heappush
from copy import deepcopy
from time import time
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def LIST()  : return list(MAP())

n = INT()
c = [0]*4

for i in range(n):
    s = input()
    if s == "AC":
        c[0] += 1
    elif s == "WA":
        c[1] += 1
    elif s == "TLE":
        c[2] += 1
    elif s == "RE":
        c[3] += 1

print("AC x",c[0])
print("WA x",c[1])
print("TLE x",c[2])
print("RE x",c[3])

Measured memory_bytes: 10116
N = int(input())
A = list((int(x) for x in input().split()))

beforeAi=0
counter=0

for Ai in range(N):
    if beforeAi>A[Ai]:
        counter+=beforeAi-A[Ai]
        A[Ai]=beforeAi
    beforeAi=A[Ai]

print(counter)
        
    

Measured memory_bytes: 32224
#include <bits/stdc++.h>
#define REP(i,n) for (long i=0;i<(n);i++)
#define FOR(i,a,b) for (long i=(a);i<(b);i++)
#define RREP(i,n) for(long i=n;i>=0;i--)
#define RFOR(i,a,b) for(long i=(a);i>(b);i--)
#define dump1d_arr(array) REP(i,array.size()) cerr << #array << "[" << (i) << "] ==> " << (array[i]) << endl;
#define dump2d_arr(array) REP(i,array.size()) REP(j,array[i].size()) cerr << #array << "[" << (i) << "]" << "[" << (j) << "] ==> " << (array[i][j]) << endl;
#define dump(x)  cerr << #x << " => " << (x) << endl;
#define CLR(vec) { REP(i,vec.size()) vec[i] = 0; } 
#define llINF (long long) 9223372036854775807
#define loINF (long) 2147483647
#define shINF (short) 32767
#define SORT(c) sort((c).begin(),(c).end())
#define MIN(vec) *min_element(vec.begin(), vec.end());
#define MAX(vec) *max_element(vec.begin(), vec.end());
#define UNIQ(vec) vec.erase(unique(vec.begin(), vec.end()),vec.end());
#define IN(n,m)  (!(m.find(n) == m.end()))
#define TO_INT(vec,s) REP(i,s.length()){vec.push_back(s[i] - ‘0’);}
#define ENUM_v(vec) for (auto e : vec)
#define dump_MAP(m) for(auto itr = m.begin(); itr != m.end(); ++itr) { cerr << itr->first << " --> "  << itr->second << endl; }
#define FINDL(vec,x) (lower_bound(vec.begin(),vec.end(),x) - vec.begin())
#define FINDU(vec,x) (upper_bound(vec.begin(),vec.end(),x) - vec.begin())
#define ROUND(N) setprecision(N)

using namespace std;
typedef long long LL;
typedef vector<long> VI;
typedef vector<VI> VVI;
typedef pair<long,long> pr;
typedef vector<pr> VP;
typedef vector<string> VS;
struct Order {
	bool operator() (pr const& a,pr const& b) const {
		return a.first > b.first || ((a.first == b.first) && (a.second > b.second));
	}
};
constexpr short dx[4] = {1,0,-1,0};
constexpr short dy[4] = {0,1,0,-1};

int main(void) {
	short H,W;
	cin >> H >> W;
	VS s(H);
	REP(i,H) cin >> s[i];
	REP(i,H) {
		REP(j,W) {
			if (s[i][j] == '#') {
				bool flg = false;
				REP(k,4) {
					if (i + dy[k] >= 0 && i + dy[k] < H && j + dx[k] >= 0 && j + dx[k] < W && s[i + dy[k]][j + dx[k]] == '#') flg = true;
				}
				if (!flg) {
					cout << "No" << endl;
					exit(0);
				}
			}
		}	
	} 
	cout << "Yes" << endl;

}

Measured memory_bytes: 256