akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
using pll = pair<ll, ll>;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<n;++i)
#define rep2(i,n) for(ll i=0;i<n;++i)
#define rep3(i,a,b) for(ll i=a;i<b;++i)
#define rep4(i,a,b,c) for(ll i=a;i<b;i+=c)
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(i) begin(i), end(i)

const int INF = 0x3fffffff;
const ll MINF = 0x7fffffffffff;
const ld DINF = numeric_limits<ld>::infinity();
const int MOD = 1000000007;
const int MODD = 998244353;
const ld EPS = 1e-9;
const ld PI = 3.1415926535897932;

template<class T> bool chmin(T &a, const T &b){ if(a > b){ a = b; return 1; } else return 0; }
template<class T> bool chmax(T &a, const T &b){ if(a < b){ a = b; return 1; } else return 0; }
template<class T> auto min(const T& a){ return *min_element(all(a)); }
template<class T> auto max(const T& a){ return *max_element(all(a)); }

ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }
ll pow_mod(ll n,ll k,ll m){ll r = 1;for(; k > 0;k >>= 1) {if (k & 1) r = (r * n) % m; n = (n * n) % m;}return r;}

//ここから。
int main(){
    int n;
    cin >> n;
    int ans = 0;
    rep(i,n){
        int a;
        cin >> a;
        if(a & 1) ans++;
    }
    if(ans == 0) cout << "second" << endl;
    else cout << "first" << endl;
}

Measured memory_bytes: 3672
a,b,c = gets.chomp.split(" ").map(&:to_i)

hash = {}
k = 0
while true

  if (k * a) % b == c
    puts "YES"
    exit(0)
  else
    if hash[(k * a) % b] == true
      puts "NO"
      exit(0)
    else
      hash[(k * a) % b]= true
      k += 1
    end
  end
end
#print("#{a}#{b}#{c}")


Measured memory_bytes: 1788
{-# LANGUAGE OverloadedStrings #-}

import qualified Data.ByteString.Char8 as B
import Data.Attoparsec.ByteString.Char8

type Input = [Bool]

input :: Parser [Bool]
input = map f <$> many1 digit <* endOfLine
  where
    f '1' = True
    f '0' = False
    f _ = error "parse err"

main :: IO ()
main = B.interact
  $ B.pack . show . either (error "parse err") solve . parseOnly input

solve :: Input -> Int
solve xs = 2 * (ts `min` fs)
  where
    ts = length $ filter id xs
    fs = length $ filter not xs

Measured memory_bytes: 13692
#include<bits/stdc++.h>
using namespace std;
typedef long long int uli;
string t="CODEFESTIVAL2016";
int main(){
  string s;
  cin>>s;
  int ans=0;
  for(int i=0;i<int(s.size());i++)ans+=s[i]!=t[i];
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
# include <bits/stdc++.h>
 
/*
// ordered_set 
# include <ext/pb_ds/assoc_container.hpp>
# include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
# define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update> 
*/
 
using namespace std;
 
typedef long long                                        ll;
typedef long double                                      ld;
typedef pair <int, int>                                  pii;
typedef pair <pii, int>                                  ppi;
typedef pair <int, pii>                                  pip;
typedef pair <pii, pii>                                  ppp;
typedef pair <ll, ll>                                    pll;
 
# define A                                               first
# define B                                               second
# define endl                                            '\n'
# define sep                                             ' '
# define all(x)                                          x.begin(), x.end()
# define kill(x)                                         return cout << x << endl, 0
# define SZ(x)                                           int(x.size())
# define Sort(x)                                         sort(all(x))
# define InTheNameOfGod                                  ios::sync_with_stdio(0);cin.tie(0); cout.tie(0);
 
ll power(ll a, ll b, ll md) {return (!b ? 1 : (b & 1 ? a * power(a * a % md, b / 2, md) % md : power(a * a % md, b / 2, md) % md));}
 
const int xn = 1e6 + 10;
const int xm = - 20 + 10;
const int SQ = 320;
const int sq = 320 + 10;
const int inf = 1e9 + 10;
const ll INF = 1e18 + 10;
const int mod = 1e9 + 7;
const int TM = 3;
const int base = 257;

ll n, ans, fact[xn], inv[xn], res;

ll C(ll r, ll n){
	if (r < 0 || r > n) return 0;
	return fact[n] * inv[r] % mod * inv[n - r] % mod;
}

int main(){
    InTheNameOfGod;
    
    cin >> n, -- n;
    fact[0] = inv[0] = 1;
    for (int i = 1; i < xn; ++ i){
    	fact[i] = fact[i - 1] * i % mod;
    	inv[i] = power(fact[i], mod - 2, mod);
	}
	ans = fact[n];
	for (int i = 1; i <= n; ++ i){
		res = C(n - i, i - 1);
		res = (C(i, n) - res + mod) % mod;
		res = res * fact[i] % mod;
		res = res * fact[n - i] % mod;
		ans = (ans + res) % mod;
	}
	cout << ans << endl;

    return 0;
}


Measured memory_bytes: 19256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    int n = scan.nextInt();
    int a[] = new int[n];
    for (int i = 0; i < n; i++){
      int A = scan.nextInt();
      a[i] = A;
    }
    long ans = 0;
    for (int i = 1; i < n; i++){
      if (a[i-1] > a[i]){
        ans = ans + (a[i-1]-a[i]);
        a[i] = a[i-1];
      }
    }
   System.out.println(ans);
  }
}

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

using namespace std;

#define ll long long
#define pb push_back
#define vi vector<int>
#define bn(n) (n).begin(), (n).end()
#define FOR(n) for(int i = 0; i < (int)n; i++)


void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    if (c >= a && c <= b) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }
}

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

    int t = 1, i = 1;
    //cin >> t;
    while(t--) {
        //cout << "Case #" << i << ": ";
        solve();
        //i++;
    }
    return 0;
}


Measured memory_bytes: 3644
#include<stdio.h>
#include<stdlib.h>
#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;

Node root;


Node treeSearch(Node x, int k){
  if(x == NIL || k == x->key) return x;
  if(k < x->key) return treeSearch(x->left,k);
  else return treeSearch(x->right,k);

}


void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;
  while(x!=NIL){
    y=x;
    if(z->key<x->key) x = x->left;
    else x = x->right;
  }
  z->parent = y;
   
  if(y==NIL) root = z;
  else if(z->key<y->key) y->left = z;
  else y->right = z;



}

void inorder(Node u){
 if(u!=NIL){
    if(u->left!=NIL) inorder(u->left);
    
    printf(" %d",u->key);
       
    if(u->right!=NIL) inorder(u->right);
   }
}
void preorder(Node u){
   printf(" %d",u->key);
  if(u!=NIL){
    if(u->left!=NIL) preorder(u->left);
    
    if(u->right!=NIL) preorder(u->right); 
  }
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } 
  }

  return 0;
}

Measured memory_bytes: 24040
a,b,q=map(int,input().split())
s=[-10**30]+[int(input())for _ in range(a)]+[10**30]
t=[-10**30]+[int(input())for _ in range(b)]+[10**30]
x=[int(input())for _ in range(q)]
from bisect import bisect_left,bisect_right
for xx in x:
  s1=s[bisect_right(s,xx)-1]
  s2=s[bisect_right(s,xx)]
  t1=t[bisect_right(t,xx)-1]
  t2=t[bisect_right(t,xx)]
  ans=[]
  ans.append(abs(s1-t1)+min(abs(xx-s1),abs(xx-t1)))
  ans.append(abs(s1-t2)+min(abs(xx-s1),abs(xx-t2)))
  ans.append(abs(s2-t1)+min(abs(xx-s2),abs(xx-t1)))
  ans.append(abs(s2-t2)+min(abs(xx-s2),abs(xx-t2)))
  print(min(ans))

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

int main() {
    long long k,i,sum=7;
    cin>>k;
    for(i=1;i<=1000000;i++){
        if(sum%k==0){
            cout<<i<<endl;
            return 0;
        }
        sum=(sum*10+7)%k;
    }
    cout<<-1<<endl;
}


Measured memory_bytes: 3612
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
//4008802802
//4008160009
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define forn(i, a) for(register int i=0; i<a; i++)
#define Forn(i, a) for(register int i=1; i<=a; i++)
#define memINF 127
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false)
#define lid id<<1|1
#define rid (id<<1)+2
#define mid l+r>>1
#define lson lid, l, mid
#define rson rid, mid, r

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

inline int in() 
{
    int x=0, c;
    while((uint)((c=getchar())-48)>=10) 
		if(c=='-') 
			return -in();
    do 
	{ x=(x<<3)+(x<<1)+(c^48); }
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=405;
const int mod=1e7+9;
const int MAX_H=1e5+5;

int N, t, C[MAX][5];
map<ll,pair<int,int> >::iterator it;
map<ll,pair<int,int> > MP;
ll res, tt;

inline void Insert(ll H, int t)
{
    it=MP.find(H);
    if(it!=MP.end())
    {
        it->s.s+=t;
        return;
    }
    int re=H/(ll)1e6==H%(ll)1e6?(H/(ll)1e9==H%(ll)1e3?4:2):1;
    MP[H]=mp(re, t);
}

inline int Find(ll H)
{
    it=MP.find(H);
    return it->s.f*it->s.s;
}

inline ll Get_Hash(int *t, int turn)
{
    ll ret=0;
    forn(i, 4)
        ret=ret*1000+t[(i+turn)&3];
    return ret;
}

inline void Add(ll H, int t)
{
    ll tmp[4];
    forn(i, 4)
        tmp[i]=H, H=H/1000+H%1000*1000000000;
    sort(tmp, tmp+4);
    int ptr=unique(tmp, tmp+4)-tmp;
    forn(i, ptr)
        Insert(tmp[i], t);
}

inline void Add(int *T, int t)
{
    Add(Get_Hash(T, 0), t);
}

int main()
{
    N=in();
    forn(i, N)
    {
        forn(j, 4)
            C[i][j]=in();
        Add(C[i], 1);
    }
    forn(i, N)
    {
        Add(C[i], -1);
        for(int j=i+1; j<N; ++j)
        {
            Add(C[j], -1);
            reverse(C[j], C[j]+4);
            
            forn(k, 4)
            {
                tt=1;
                for(t=0; t<4; ++t)
                {
                    ll h=((C[j][(k+t)&3]*1000LL+C[j][(k+t+1)&3])*1000+C[i][(t+1)&3])*(ll)1000+C[i][t];
                    tt*=Find(h);
                    if(!tt)
                        break;
					Add(h, -1);
                }
                while(t--)
                {
                    ll h=((C[j][(k+t)&3]*1000LL+C[j][(k+t+1)&3])*(ll)1000+C[i][(t+1)&3])*(ll)1000+C[i][t];
                    Add(h, 1);
                }
                res+=tt;
            }
            reverse(C[j], C[j]+4);
            Add(C[j], 1);
        }
    }
    printf("%lld\n", res);
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <queue>
#include <utility>
#include <vector>
typedef long long ll;
using namespace std;
const ll INF = 1e9;
const ll MOD = 1e9 + 7;
#define repi(i, n, init) for (ll i = init; i < (n); i++)
int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
vector<vector<char>> s;
vector<vector<int>> dist;
int h, w;

void bfs(queue<pair<int, int>> &q, int x, int y)
{
    repi(i, 4, 0)
    {
        int nx = x + dx[i],
            ny = y + dy[i];
        if (0 <= nx && nx < w && 0 <= ny && ny < h && s[ny][nx] != '#')
        {
            if (dist[ny][nx] > dist[y][x] + 1)
            {
                dist[ny][nx] = dist[y][x] + 1;
                q.push({nx, ny});
            }
        }
    }
}

int main()
{
    cin >> h >> w;
    s.resize(h, vector<char>(w));
    dist.resize(h, vector<int>(w, INF));
    int black = 0;
    repi(i, h, 0)
    {
        repi(j, w, 0)
        {
            cin >> s[i][j];
            if (i == 0 && j == 0 || i == h - 1 && j == w - 1)
                continue;
            if (s[i][j] == '#')
            {
                black++;//黒の個数
            }
        }
    }
    queue<pair<int, int>> q;

    q.push({0, 0});
    dist[0][0] = 0;
    while (!q.empty())
    {
        pair<int, int> p = q.front();
        q.pop();
        bfs(q, p.first, p.second);
    }
    if (dist[h - 1][w - 1] == INF)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << h * w - black - dist[h - 1][w - 1] - 1 << endl;//マスの数にするために距離+1としている。
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
  int x[5],t=0;
  int i,m=9,y,a,c=4;
  for(i=0;i<5;i++){
    cin>>x[i];
    y=x[i];
      a=y/10;
      if(a==0){
        if(y<m&&y!=0){
          c=i;
          m=y;
        }
      }
    else{
      y=y-(y/10)*10;
     if(y<m&&y!=0){
          c=i;
          m=y;
        }
    }
  }
  y=x[4];
  x[4]=x[c];
  x[c]=y;
  for(i=0;i<5;i++){
    cin>>x[i];
    t+=x[i];
    while(t%10!=0&&i!=4)
      t++;
  }
  cout<<t;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    vector<ll> bits(61, 0);

    for (int i = 0; i < 60; i++)
    {
        ll s0 = 0LL, s1 = 0LL;
        for (int j = 0; j < n; j++)
        {
            (a[j] & (1LL << i)) ? s1++ : s0++;
        }
        bits[i] = s1 * s0 % MOD;
    }

    ll sum = 0LL;
    for (int i = 0; i < 60; i++)
    {
        sum = (sum + (bits[i] * ((1LL << i) % MOD)) % MOD) % MOD;
    }
    cout << sum << endl;
}

Measured memory_bytes: 2560
import heapq


class MaxHeap(object):
    def __init__(self, x):
        self.heap = [-e for e in x]
        heapq.heapify(self.heap)

    def push(self, value):
        heapq.heappush(self.heap, -value)

    def pop(self):
        return -heapq.heappop(self.heap)

N, M = list(map(lambda x:int(x), input().split(' ')))
l = list(map(lambda x:int(x), input().split(' ')))

maxheap = MaxHeap(l)

WARI = 0.5
for _ in range(0, M):
    v = int(maxheap.pop() * WARI)
    maxheap.push(v)

SUM = 0
for _ in range(0, N):
    SUM += maxheap.pop()

print(SUM)

Measured memory_bytes: 14380
#include<iostream>
#include<cstring>
using namespace std;
int main()
{
	string a;
    cin>>a;
    int len=a.length();
    int x=0,y=0,ans=0;
    for(int i=0;i<len;i++)
    {
    	if(x^y) y++,ans+=(a[i]=='g');
     	else x++,ans-=(a[i]=='p');
	}
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
//C - HSI: 
//Assunto: 
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100050
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int n, m, time, ans;
    cin >> n >> m;
    time = m*1900 + (n-m)*100;
    ans = time * pow(2, m);
    cout << ans << "\n";
}

Measured memory_bytes: 384
n = int(input())
hs = [int(s) for s in input().split()]

dp = [0] * n
dp[0], dp[1] = 0, abs(hs[1] - hs[0])

for i in range(2, n):
    dp[i] = min(
        dp[i-1] + abs(hs[i] - hs[i-1]),
        dp[i-2] + abs(hs[i] - hs[i-2]),
    )

print(dp[-1])

Measured memory_bytes: 13980
#include <iostream>

using namespace std;

#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2], R[MAX/2+2];
int count;

void merge(int A[], int n, int left, int mid, int right){
  int n1 = mid - left;
  int n2 = right - mid;

  for(int i=0; i<n1; i++){ L[i] = A[left + i]; }
  for(int i=0; i<n2; i++){ R[i] = A[mid +i]; }
  L[n1] = R[n2] = SENTINEL;

  int i=0, j=0;
  for(int k=left; k<right; k++){
    count++;
    if( L[i]<=R[j] ){
      A[k] = L[i++];
    }else {
      A[k] = R[j++];
    }
  }
}

void mergeSort(int A[], int n, int left, int right){
  if( left+1 < right ){
    int mid = (left+right)/2;
    mergeSort(A, n, left, mid);
    mergeSort(A, n, mid, right);
    merge(A, n, left, mid, right);
  }
}

int main(){
  int A[MAX];
  int n , i;
  count=0;

  std::cin >> n;
  for(int i=0; i<n; i++){ std::cin >> A[i]; }

  mergeSort(A, n, 0, n);

  for(int i=0; i<n; i++){
    if(i) std::cout << " ";
    std::cout << A[i];
  }
  std::cout << endl;
  std::cout << count << std::endl;

  return 0;
}



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

using namespace std;

typedef long long ll;

vector <ll> a;
int n;
ll m;

int main() {
  cin >> n >> m;
  a.resize(n);
  priority_queue <ll> pq;
  for(int i = 0; i < n; i++) {
    cin >> a[i];
    pq.push(a[i]);
  }
  while(m > 0) {
    ll cur = pq.top();
    pq.pop();
    cur = cur >> 1LL;
    m--;
    pq.push(cur);
  }
  ll sum = 0;
  while(!pq.empty()) {
    sum += pq.top();
    pq.pop();
  }
  cout << sum << '\n';
}


Measured memory_bytes: 2168
using System;
using System.Collections.Generic;
using System.Text;
using static System.Math;
using static System.Console;

namespace AtTest.D_Challenge
{
    class ABC_035
    {
        static void Main(string[] args)
        {
            Method(args);
            Console.ReadLine();
        }

        static void Method(string[] args)
        {
            int[] nmk=ReadInts();
            int n=nmk[0];
            int m=nmk[1];
            int k=nmk[2];
            for(int i=0;i<=n;i++)
            {
                for(int j=0;j<=m;j++)
                {
                    int val=i*m+j*n-i*j*2;
                    if(val==k)
                    {
                        WriteLine("Yes");
                        return;
                    }
                }
            }
            WriteLine("No");
        }

        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 11220
/* ex 9_1
   yy8332 */
#include <stdio.h>
#include <stdlib.h>
//スタックに格納するデータの最大数
#define SIZE 1000

//スタックの定義
typedef struct stack{
  int size;
    int count;
    char data[SIZE];
    char *top;
  } stack;

//スタックの初期化
void initialize_stack(stack *stk){
  stk->count = 0;
  stk->size = SIZE;
  stk->top = &(stk->data[SIZE]);
}

//データの追加
void push(stack *stk, char elem){
  if(stk->count >= stk->size){
    fprintf(stderr, "Error: stack overflow. (x=%c)\n", elem);
    exit(1);
  }
  else{
    stk->top--;
    *(stk->top) = elem;
    stk->count++;
  }
}

//データの取り出し
char pop(stack *stk){
  char latest;
  if(stk->count <= 0){
    fprintf(stdout, "Error: stack underflow.\n");
    exit(1);
  }
  else{
    latest = *(stk->top);
    stk->top++;
    stk->count--;
    return latest;
  }
}

int main(void){
  stack stk;
  char input[11], str1[11], str2[11];
  int len1, len2, i;
  //スタックを初期化（ポインタ渡しで関数にわたすこと）
  initialize_stack(&stk);

  //入力読み取り
  scanf("%s", &input);

  //入力文字列の長さ取得
  len1 = strlen(input);

  //入力で場合分けしてstackを操作
  for(i = 0; i < len1; i++){
    if(input[i] == 'B' && stk.count != 0){
      pop(&stk);
    }
    else if(input[i] == '0' || input[i] == '1'){
      push(&stk, input[i]);
    }
  }

  //出力文字列の長さ取得
  len2 = stk.count;

  //出力
  for(i = 0; i < len2; i++){
    str1[i] = pop(&stk);
  }
  for(i = 0; i < len2; i++){
    str2[i] = str1[(len2 - 1) - i];
  }
  str2[len2] = '\0';

  printf("%s\n", str2);

  return 0;
}


Measured memory_bytes: 1620
import numpy as np


N = int(input())
A = list(map(int, input().split()))
Q = int(input())

sumA = sum(A)
cnt_num = np.zeros(10**5 + 1)

for i in A:
    cnt_num[i] += 1

for i in range(Q):
    B, C = map(int, input().split())
    sumA += (C - B) * cnt_num[B]
    print(int(sumA))
    cnt_num[C] += cnt_num[B]
    cnt_num[B] = 0
    

Measured memory_bytes: 38740
#include<stdio.h>

#define MAX_SIZE (1000)

int main(void)
{
        char x[MAX_SIZE];
        int i, sum;

        while(1){
                scanf("%s", x);

                if(x[0] == '0'){
                        break;
                }

                sum = 0;

                for(i=0; i < MAX_SIZE; i++){
                        if(x[i] == '\0'){
                                break;
                        }

                        sum += x[i] & 0xf;
                }

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

        return 0;
}


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

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifndef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

const int mod = (int) 1e9 + 7;

void solve() {
	int n;
	cin >> n;
	vector<int> v(n);
	for (int &i : v) cin >> i;
	long long res = 0;
	for (int i = 1; i < n; i++) {
		if (v[i] < v[i - 1]) {
			res += (v[i - 1] - v[i]);
			//debug() << imie(res);
			v[i] += v[i - 1] - v[i];
		}
	}
	cout << res << "\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int tt = 1;
	//cin >> tt;
	while (tt--) {
		solve();
	}
	return 0;
}


Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define ld long double
#define ff first
#define ss second
#define mp make_pair
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb push_back
#define pii pair<int, int>
ld const pi = 3.141592653589793238462;

int power(int a,int b){
    int f=1;
    while(b>0){
        if(b&1){
            f=f*a;
            //f%=m;
        }
        a=a*a;
        //a%=m;
        b=b/2;
    }
    return f;
}

bool rev(pair<int, pii> a, pair<int, pii> b){
    return a.ff <= b.ff;
}

int const N = 3e5+5;
int a[N];
vector<int> ad[N];


int32_t main(){
    IOS;
    int n,k,i,j,l;
    cin>>n>>k;
    int a[n];
    for(i=0;i<n;i++) cin>>a[i];
    int ans=0;
    for(i=0;i<n;i++){
        for(j=i;j<=n;j++){
            vector<int> v;
            for(l=0;l<i;l++){
                v.pb(a[l]);
            }
            for(l=j;l<n;l++){
                v.pb(a[l]);
            }
            sort(v.begin(),v.end());
            int moves = v.size();
            l=0;
            while(moves < k && l<v.size()){
                if(v[l] >= 0) break;
                moves++;
                l++;
            }
            int sm=0;
            for(l=l;l<v.size();l++) sm += v[l];
            if(moves<=k)
            ans = max(ans,sm);
        }
    }
    cout<<ans<<endl;
    return 0;
}




Measured memory_bytes: 8448
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int a = in.nextInt(), b = in.nextInt(), c = in.nextInt();
		if ((a - b) == (b - c)) {
			System.out.println("YES");
		} else {
			System.out.println("NO");
		}
	}

}

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

const long long MOD=998244353;

int main(){
    long long N,K;
    cin >> N >> K;
    long long L[N+1], R[N+1];
    long long i,j;
    for(i=1; i<=K; i++){
        cin >> L[i] >> R[i];
    }

    long long  dp[N+1];
    fill(dp,dp+N+1,0);
    dp[1]=1;
    dp[2]=-1;
    for(i=1; i<N; i++){
        dp[i]+=dp[i-1];
        dp[i]%=MOD;
        for(j=1; j<=K; j++){
            if(i+L[j]<=N){
                dp[i+L[j]]+=dp[i];
                dp[i+L[j]]%=MOD;
            }
            if(i+R[j]<N){
                dp[i+R[j]+1]+=(MOD-dp[i]);
                dp[i+R[j]+1]%=MOD;
            }
        }
    }
    dp[N]+=dp[N-1];
    dp[N]%=MOD;
    cout << dp[N] << endl;
    system("pause");
    return 0;
}

Measured memory_bytes: 5260
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
typedef unsigned long long ULL;

#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

const double EPS = 1e-10;
const double PI  = acos(-1.0);

#define CLR(a) memset((a), 0 ,sizeof(a))

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

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

int main() {
  string s;

  while(cin >> s) {
    int J = 0, I = 0;
    REP(i, s.size()) {
      if(s[i+1] == 'O' && s[i+2] == 'I') {
	if(s[i] == 'J') J++;
	else if(s[i] == 'I') I++;
      }
    }
    
    cout << J << endl;
    cout << I << endl;
  }
}

Measured memory_bytes: 1196
class UnionFind:
    def __init__(self, n):
        super().__init__()
        self.rank = [0] * n
        self.parent = [i for i in range(n)]
        self.counter = [1] * n

    def print_set(self):
        print(self.parent)
        print(self.rank)

    def find_set(self, x):
        if x != self.parent[x]:
            self.parent[x] = self.find_set(self.parent[x])
        
        return self.parent[x]
    
    def unite(self, x, y):
        if self.same(x, y):
            return

        x_parent = self.find_set(x)
        y_parent = self.find_set(y)

        if self.rank[x_parent] > self.rank[y_parent]:
            self.parent[y_parent] = x_parent
            self.counter[x_parent] += self.counter[y_parent]
        else:
            self.parent[x_parent] = y_parent
            self.counter[y_parent] += self.counter[x_parent]
            if self.rank[x_parent] == self.rank[y_parent]:
                self.rank[y_parent] += 1


    def same(self, x, y):
        return self.find_set(x) == self.find_set(y)


n, m, k = map(int, input().split())
friend = UnionFind(n)
friend_list = [list(map(int, input().split())) for _ in range(m)]
block_list = [list(map(int, input().split())) for _ in range(k)]

for a, b in friend_list:
    friend.unite(a-1, b-1)

ans = [friend.counter[friend.find_set(i)]-1 for i in range(n)]

for a, b in friend_list:
    if friend.same(a-1, b-1):
        ans[a-1] -= 1
        ans[b-1] -= 1

for c, d in block_list:
    if friend.same(c-1, d-1):
        ans[c-1] -= 1
        ans[d-1] -= 1

print(*ans)


Measured memory_bytes: 60556
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
 
/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

int main(){
    int N; cin >> N;
    vector<ll> a(3*N);
    for(int i=0; i<3*N; ++i) cin >> a[i];

    vector<ll> left(3*N, 0), right(3*N, 0);
    priority_queue<ll> pq, pq2;

    ll tmp = 0;
    for(int i=0; i<N; ++i){
        tmp += a[i];
        pq.push(-a[i]);
    }

    left[N-1] = tmp;
    for(int i=N; i<2*N; ++i){
        if(-pq.top() < a[i]){
            tmp += pq.top();
            tmp += a[i];
            pq.pop();
            pq.push(-a[i]);
            left[i] = tmp;
        } else {
            left[i] = tmp;
        }
        //cout << i << " " << left[i] << endl;
    }

    tmp = 0;
    for(int i=3*N-1; i>=2*N; --i){
        tmp += a[i];
        pq2.push(a[i]);
    }

    right[2*N-1] = tmp;
    for(int i=2*N-1; i>=N; --i){
        if(pq2.top() > a[i]){
            tmp -= pq2.top();
            tmp += a[i];
            pq2.pop();
            pq2.push(a[i]);
            right[i-1] = tmp;
        } else {
            right[i-1] = tmp;
        }
        //cout << i-1 << " " << right[i-1] << endl;
    }

    ll ans = -(1LL<<59);
    for(int i=N-1; i<2*N; ++i) ans = max(ans, left[i]-right[i]);
    
    cout << ans << endl;
    return 0;

}

Measured memory_bytes: 9588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e5+5;
const int mod = 1e9+7;
ll qpow(ll a,ll b){ll res=1;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}

int main()
{
    int x,y;
    scanf("%d%d",&x,&y);
    int tmp = y-2*x;
    bool ok = true;
    if(tmp&1||tmp<0){
        ok = false;
    }
    int z = tmp/2;
    if(z>x)ok=false;
    if(!ok)printf("No\n");
    else printf("Yes\n");
    return 0;
}


Measured memory_bytes: 3660
# -*- coding: utf-8 -*-

def main():
  N = int(input())
  P = list(map(int, input().split()))
  count = 1
  n_min = P[0]
  for i in range(1, N):
    if P[i] <= n_min:
      count += 1
      n_min = P[i]
  print(count)

if __name__ == '__main__':
  main()

Measured memory_bytes: 75472
N, kona = [int(x) for x in input().strip().split()]
donats = list()
num = 0
for _ in range(N):
    donats.append(int(input()))
kona -= sum(donats)
num += len(donats)
min_donats = min(donats)
while kona >= 0:
    kona -= min_donats
    num += 1
print(num-1)

Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<algorithm>
#include<iomanip>
#include<utility>
#include<set>
#include <unordered_set>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<signed(n);i++)
#define EREP(i,n) for(int i=1;i<=signed(n);i++)
#define ALL(a) (a).begin(),(a).end()
using std::cout;
using std::vector;
using std::endl;
using std::cin;
using std::string;
using std::min;
using std::max;
//#define EVEL 1
#ifdef EVEL
#define DEB(X) cout << #X << ":" <<X<<" " ;
#define TF(f) f ? cout<<"true  " : cout<<"false ";
#define END cout<<"\n";
#else
#define DEB(X) {}
#define TF(f) {}
#define END {}
#endif
const ll MOD = 1000000007;
const ll INF = 9e9;
typedef std::pair<int,int> P;
//struct edge {int to,cost;};
#define VMAX 100+10
ll d[VMAX][VMAX];
int F[VMAX][VMAX]={};
ll N,M;
ll ans;
//最初にINFの代入忘れない！！！！！
void warshall_floyd(int n) { // nは頂点数
  for (int i = 0; i < n; i++)      // 経由する頂点
    for (int j = 0; j < n; j++)    // 開始頂点
      for (int k = 0; k < n; k++){  // 終端
        if(d[j][k]>d[j][i]+d[i][k]){
            if(F[j][k]!=-1)F[j][k]=F[k][j]=0;
        }
        d[j][k] = std::min(d[j][k], d[j][i] + d[i][k]);
      }


}


int main(){
    std::ios_base::sync_with_stdio(false);
    cin>>N>>M;
    REP(i,VMAX)REP(j,VMAX){d[i][j]=INF;F[i][j]=-1;}
    REP(i,M){
        int a,b,c;
        cin>>a>>b>>c;
        a--,b--;
        d[a][b]=d[b][a]=c;
        F[a][b]=F[b][a]=1;
    }
    warshall_floyd(N);
    REP(i,N)for(int j=i+1;j<N;j++){
        if(F[i][j]==0)ans++;
    }
    cout<<ans<<endl;
    return 0;
}


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

// Print a frame

int main(){
	int H, W;

	while(1){
		cin >> H >> W;
		if( H == 0 && W == 0) break;

		for(int i = 0; i < H; i++){
			for(int j = 0; j < W; j++){
				if(i == 0 || i == H - 1 || j == 0 || j == W - 1){
					cout << '#';
				}else{
					cout << '.';
				}
			}
			cout << endl;
		}
		cout << endl;
	}

	return 0;
}


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

int main()
{
    int a[3];
    for(int i = 0; i < 3; ++i)
    {
        cin >> a[i];
    }
    
    sort(a, a + 3);
    
    if(a[0] == 5 && a[1] == 5 && a[2] == 7)
    {
        cout << "YES" << endl;
        return 0;
    }
    
    else
    {
        cout << "NO" << endl;
        return 0;
    }
    
    
    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
    public static void main(String[] args) {
        int x = 0, s = 0, m = 1;;
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int p = n * 2;
        int[] a = new int[p];
        for (int i = 0; i < p; i++) {
            a[i] = in.nextInt();
        }
        for (int i = 0; i < p - 1; i++) {
            for (int j = 1 + i; j < p; j++) {
                if (a[i] < a[j]) {
                    int t = a[i];
                    a[i] = a[j];
                    a[j] = t;
                }
            }
        }
        for (int i = 0; i < p - 1; i++) {
            for (int j = m; j < p; j++) {
                if (a[i] > a[j] || a[i] == a[j]) {
                    x = a[j];
                    s = s + x;
                    m = m + 2;
                    break;
                }
            }
        }
        System.out.println(s);
    }
}

Measured memory_bytes: 22736
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}
func bOut(f bool, x string, y string) {
	if f {
		fmt.Println(x)
	} else {
		fmt.Println(y)
	}
}
func mod(x, d int) int {
	x %= d
	if x < 0 {
		x += d
	}
	return d
}
func iSSPrint(x []int) {
	fmt.Println(strings.Trim(fmt.Sprint(x), "[]"))
}

var lp int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, lp)
	sc.Split(bufio.ScanWords)
	n := iScan()
	p := furui(55555)
	ans := make([]int, 0, n)
	for i, v := range p {
		if v && i%5 == 1 {
			ans = append(ans, i)
		}
		if len(ans) == n {
			break
		}
	}
	iSSPrint(ans)
}
func furui(n int) []bool {
	p := make([]bool, n+1)
	for i := 2; i < n+1; i++ {
		p[i] = true
	}
	for i := 2; i < n+1; i++ {
		if p[i] {
			for j := i * 2; j < n+1; j += i {
				p[j] = false
			}
		}
	}
	return p
}


Measured memory_bytes: 1848
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<climits>
#include<cmath>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<numeric>
#include<functional>
#include<algorithm>
#include<bitset>
#include<tuple>
#include<unordered_set>
#include<unordered_map>
#include<random>
#include<array>
#include<cassert>
using namespace std;
#define INF ((1<<30)-1)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(),v.end()




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

	int a, b, c, k;
	cin >> a >> b >> c >> k;
	while (a >= b) {
		b *= 2;
		k--;
	}
	while (b >= c) {
		c *= 2;
		k--;
	}
	cout << (0 <= k ? "Yes" : "No") << endl;


	return 0;
}


Measured memory_bytes: 3648
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:i32 = read();
    let m:i32 = read();

    println!("{}", n-m+1);
    
}


Measured memory_bytes: 4352
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
    int n,a;
    scanf("%d",&n);
    int numodd=0,num2=0,num4=0;   //奇数， 2倍数 ，  4倍数
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a);
        if(a%2==0)
        {
            if(a%4==0)  num4++;
            else        num2++;
        }
        else
            numodd++;

    }
    if(num2)    num2=1;  //多个2倍数重新排列相当于一个2倍数
    if(num2+numodd-1<=num4)
        printf("Yes");
    else if(numodd==0)
        printf("Yes");
    else
        printf("No");
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(a) (a).begin(), (a).end()

using namespace std;

int nextInt() {int a; cin >> a; return a;}
char nextChar() {char a; cin >> a; return a;}
double nextDouble() {double a; cin >> a; return a;}
string nextString() {string a; cin >> a; return a;}

void inputVector(vector<int> &v, int &n) {rep(i,n){v.push_back(nextInt());}}
void inputVector(vector<double> &v, int &n) {rep(i,n){v.push_back(nextDouble());}}
void inputVector(vector<string> &v, int &n) {rep(i,n){v.push_back(nextString());}}

int dp[110][10010];

signed main() {
	int N, W;
	cin >> N >> W;

	vector<int> v, w;
	rep(i, N) {
		int a, b;
		cin >> a >> b;
		v.push_back(a);
		w.push_back(b);
	}

	for (int i = 1; i <= N; i++) {
		for (int j = 1; j <= 10000; j++) {
			dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			if (j >= w[i - 1]) {
				dp[i][j] = max(dp[i - 1][j - w[i - 1]] + v[i - 1], dp[i][j]);
			}
		}
	}

	cout << dp[N][W] << endl;

    return 0;
}

Measured memory_bytes: 10984
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,n,ctn,i;string s;
	while(cin>>n,n){
		cin>>s;
		for(a=0;a<n;a++){
			char t=s[0];ctn=1;stringstream F;
			for(i=1;i<(int)s.length();i++)if(t==s[i])ctn++;else F<<ctn<<t,ctn=1,t=s[i];
			F<<ctn<<t,s=F.str();
		}
		cout<<s<<endl;
	}
}

Measured memory_bytes: 1376
fn main() {
    let k = rv::<usize>()[3];
    let a = rv::<i64>();
    let b = rv::<i64>();
    let c = rv::<i64>();
    let mut m = Vec::with_capacity(k);
    m.push(0);
    let mut t = Vec::with_capacity(k);
    for d in &[a,b,c] {
        for &u in d {
            for &v in &m {
                t.push(u+v);
            }
            t.sort_by_key(|x|-x);
            t.truncate(k);
        }
        std::mem::swap(&mut m, &mut t);
    }
    for v in m {
        println!("{}",v);
    }
}
fn rl() -> String {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s
}
fn rv<T>() -> Vec<T> where T: std::str::FromStr, T::Err: std::fmt::Debug, {
    rl().split_whitespace().map(|x|x.parse::<T>().unwrap()).collect()
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll = long long;
using R = long double;
const R EPS = 1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r) {return (r > EPS) - (r < -EPS);}
inline R sq(R x) {return sqrt(max(x, 0.0L));}

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

// Problem Specific Parameter:

map<string, int> dict;
int total = 0;

int convert(string s) {
	if (dict.find(s) == end(dict)) {
		dict[s] = total++;
	}
	return dict[s];
}

using pii = pair<int, int>;
vector<pii> doc[1010];
bool used[1010];

bool rel[310][310];
vector<int> tri[310][310];

int main(void) {
	string p, q;
	cin >> p >> q;

	const int pidx = convert(p), qidx = convert(q);
	rel[pidx][qidx] = true;

	int n;
	cin >> n;

	rep(i, n) {
		int m;
		cin >> m;
		rep(j, m) {
			string a, b;
			cin >> a >> b;
			const int aidx = convert(a), bidx = convert(b);
			doc[i].push_back(pii(aidx, bidx));
			tri[aidx][bidx].push_back(i);
		}
	}

	queue<pii> que;
	que.push(pii(pidx, qidx));

	while (!que.empty()) {
		pii cur = que.front(); que.pop();

		for (auto &idx : tri[cur.first][cur.second]) {
			if (used[idx]) continue;
			used[idx] = true;
			for (auto &elem : doc[idx]) {
				if (rel[elem.first][elem.second]  == false) {
					rel[elem.first][elem.second] = true;
					que.push(pii(elem.first, elem.second));
				}
			}
		}

		rep(i, total) {
			if (rel[cur.second][i] == true and rel[cur.first][i] == false) {
				rel[cur.first][i] = true;
				que.push(pii(cur.first, i));
			}
		}
	}

	bool ok = true;
	rep(i, total)rep(j, total) if (rel[i][j] == true and rel[j][i] == true) ok = false;
	puts(ok ? "Yes" : "No");

	return 0;
}

Measured memory_bytes: 9160
#include <stdio.h>
int main(){
  int n,i,max=0,count=0;
  int h[100000];

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&h[i]);
  }
  
  for(i=0;i<n-1;i++){
    if(h[i]<h[i+1]){
      if(max<count){
        max=count;
      }
      count=0;
    } else {
      count++;
    }
  }
  if(max<count){
    max=count;
  }
  
  printf("%d",max);
}


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

using namespace std;
typedef long long ll;
#define MOD 1000000007
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


int main() {
    string s;
    cin >> s;

    int n = s.length();
    int cnt = 0;

    for(int i=0; i<n/2; i++) {
        if(s[i] != s[n-1-i]) cnt++;
    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, a[3], t, ans = 0;
  for(i = 0; i < 3; ++i) scanf("%lld", &a[i]);
  for(i = 0; i < 3; ++i) for(j = i + 1; j < 3; ++j) if(a[i] > a[j]) t = a[i], a[i] = a[j], a[j] = t;
  if(a[0] == a[1] && a[1] == a[2]) {
    printf("0");
    return 0;
  }
  if(a[0] == a[1]) {
    printf("%lld", a[2] - a[1]);
    return 0;
  }
  if(a[1] == a[2]) {
    if((a[0] + a[1]) % 2) printf("%lld", (a[2] - a[0] + 1) / 2 + 1);
    else printf("%lld", (a[2] - a[0]) / 2);
    return 0;
  }
  if((a[0] + a[1]) % 2) {
    if((a[0] + a[2]) % 2) ans++, a[1]++, a[2]++;
    else ans++, a[0]++, a[2]++;
  } else if((a[0] + a[2]) % 2) {
    ans++, a[0]++, a[1]++;
  }
  //printf("%lld %lld %lld\n", a[0], a[1], a[2]);
  printf("%lld", ans + (a[2] - a[0]) / 2 + (a[2] - a[1]) / 2);
  return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
const int MD = 998244353;
using ll = long long;
int n, m, a, t;
bitset<305> bt[305];
ll e(ll n){
	ll res = 1;
	for(ll b = 2; n; n/=2,(b*=b)%=MD) if(n%2) (res *= b) %= MD;
	return res;
}
int main(){
	scanf("%d%d", &n, &m);
	rep(i,n) rep(j,m){
		scanf("%d", &a);
		bt[i][j] = a;
	}
	rep(i,m){
		for(int j = t+1; j < n; j++) if(bt[j][i]){
			if(bt[t][i]) bt[j] ^= bt[t];
			else swap(bt[t], bt[j]);
		}
		if(bt[t][i]) t++;
	}
	printf("%lld\n", (e(m) - e(m-t) + MD) * e(n-1) % MD);
}

Measured memory_bytes: 256
s = input()
x = int(s[0:2])
y = int(s[2:4])

if (x > 12 and y > 12 ) or (x==0 and y==0) or (x>12 and y==0) or (y>12 and x==0):
  print("NA")
elif x<13 and (y>12 or y==0):
  print("MMYY")
elif (x>12 or x==0) and y<13:
  print("YYMM")
elif x<13 and y<13:
  print("AMBIGUOUS")

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <unordered_map>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <deque>
#include <cmath>
#include <stack>
#include <queue>

#define nl '\n'

#define PI 3.14159265

using namespace std;

string s;

int main(){
    cin >> s;
    vector<char> v;
    for(int i = 0; i < s.length(); i++){
        v.push_back(s[i]);
    }

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

    if(v[0] == v[1] && v[2] == v[3] && v[1] != v[2]){
        cout << "Yes";
    } else{
        cout << "No";
    }




}

//g++ -std=c++14 comp.cpp -o b; ./b.exe


Measured memory_bytes: 256