akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <math.h>
#include <string>
#include <set>

using namespace std;
typedef long long ll;
static const double EPS = 1e-9;
static const double PI = acos(-1.0);

#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, s, n) for (int i = (s); i < (int)(n); i++)
#define FOREQ(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define DEC(i, s) for (int i = (s); i >= 0; i--)

#define SIZE(v) (int)((v).size())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define FIND(m, w) ((m).find(w) != (m).end())

int main() {
  int test;
  cin >> test;
  while (test--) {
    set<string> open;
    string str;
    cin >> str;
    int n = (int)str.size();
    FOREQ(i, 1, n - 1) {
      string left, right;
      left = str.substr(0, i);
      right = str.substr(i, n);
      open.insert(left + right);
      open.insert(right + left);
      reverse(left.begin(), left.end());
      open.insert(left + right);
      open.insert(right + left);
      reverse(right.begin(), right.end());
      open.insert(left + right);
      open.insert(right + left);
      reverse(left.begin(), left.end());
      open.insert(left + right);
      open.insert(right + left);
    }
    cout << open.size() << endl;
  }
}

Measured memory_bytes: 1000
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;

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

    int ans = 0;
    rep(j,1000){
        string s2;
        if(j < 10)
            s2 = "00" + to_string(j);
        else if(j < 100)
            s2 = "0" + to_string(j);
        else
            s2 = to_string(j);
        
        
        int cnt = 0;
        rep(i,n){
            if(s[i] == s2[cnt]){
                cnt++;
                if(cnt == 3){
                    ans++;
                    continue;
                }
            }
        }
    }

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

Measured memory_bytes: 3748
/**
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⢀⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⣠⡖⠁⠀⠀⠀⠀⠀⠀⠈⢲⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⣼⡏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢹⣧⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣸⣿⠁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⣿⣇⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⣿⣿⡇⠀⢀⣀⣤⣤⣤⣤⣀⡀⠀⢸⣿⣿⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⢻⣿⣿⣔⢿⡿⠟⠛⠛⠻⢿⡿⣢⣿⣿⡟⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣀⣤⣶⣾⣿⣿⣿⣷⣤⣀⡀⢀⣀⣤⣾⣿⣿⣿⣷⣶⣤⡀⠀⠀⠀⠀
⠀⠀⢠⣾⣿⡿⠿⠿⠿⣿⣿⣿⣿⡿⠏⠻⢿⣿⣿⣿⣿⠿⠿⠿⢿⣿⣷⡀⠀⠀
⠀⢠⡿⠋⠁⠀⠀⢸⣿⡇⠉⠻⣿⠇⠀⠀⠸⣿⡿⠋⢰⣿⡇⠀⠀⠈⠙⢿⡄⠀
⠀⡿⠁⠀⠀⠀⠀⠘⣿⣷⡀⠀⠰⣿⣶⣶⣿⡎⠀⢀⣾⣿⠇⠀⠀⠀⠀⠈⢿⠀
⠀⡇⠀⠀⠀⠀⠀⠀⠹⣿⣷⣄⠀⣿⣿⣿⣿⠀⣠⣾⣿⠏⠀⠀⠀⠀⠀⠀⢸⠀
⠀⠁⠀⠀⠀⠀⠀⠀⠀⠈⠻⢿⢇⣿⣿⣿⣿⡸⣿⠟⠁⠀⠀⠀⠀⠀⠀⠀⠈⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣼⣿⣿⣿⣿⣧⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠐⢤⣀⣀⢀⣀⣠⣴⣿⣿⠿⠋⠙⠿⣿⣿⣦⣄⣀⠀⠀⣀⡠⠂⠀⠀⠀
⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠉⠀⠀⠀⠀⠀⠈⠉⠛⠛⠛⠛⠋⠁⠀⠀
 *    author:  Daredevil666
 *    institution: IIT Patna
**/
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define nl cout<<"\n";
#define ll long long int
#define REP(i,a,n) for(i=a;i<=n;i++)
#define F(i,a,b) for(i=a;i<b;i++)
#define RF(i,b,a) for(i=b;i>=a;i--)
#define IOS  ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const ll mod=1e9+7;
const ll MAXN=300001;
const ll M=3000000;
ll i,j,mask,test;
vector<ll> tree(M),A(MAXN);
void update(ll node, ll start, ll ends, ll idx, ll val)
{
    if(start == ends)
    {
        // Leaf node
        A[idx] = val;
        tree[node] = val;
    }
    else
    {
        int mid = (start + ends) / 2;
        if(start <= idx && idx <= mid)
        {
            // If idx is in the left child, recurse on the left child
            update(2*node, start, mid, idx, val);
        }
        else
        {
            // if idx is in the right child, recurse on the right child
            update(2*node+1, mid+1, ends, idx, val);
        }
        // Internal node will have the sum of both of its children
        tree[node] = max(tree[2*node] , tree[2*node+1]);
    }
}
ll query(ll node, ll start, ll ends, ll l, ll r)
{
    if(r < start || ends < l)
    {
        // range represented by a node is completely outside the given range
        return 0;
    }
    if(l <= start && ends <= r)
    {
        // range represented by a node is completely inside the given range
        return tree[node];
    }
    // range represented by a node is partially inside and partially outside the given range
    int mid = (start + ends) / 2;
    int p1 = query(2*node, start, mid, l, r);
    int p2 = query(2*node+1, mid+1, ends, l, r);
    return max(p1,p2);
}
int main()
{
IOS
/*#ifndef ONLINE_JUDGE
   freopen("input.txt","r",stdin);
   freopen("output.txt","w",stdout);
#endif // ONLINE_JUDGE*/
ll n,k;
cin>>n>>k;
while(n--)
{
    ll x;
    cin>>x;
    ll p=query(1,0,MAXN-1,max((ll)0,x-k),min(MAXN-1,x+k));
    update(1,0,MAXN-1,x,p+1);
}
ll maxx=0;
F(i,0,MAXN)
{
    maxx=max(maxx,A[i]);
}
cout<<maxx;
return 0;
}


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

#define fast_io ios_base::sync_with_stdio(false); cin.tie(0);
#define ll long long
#define en "\n"
#define eps 1e-9
#define VECT(v) vector<int>v
#define SCAN(v) for(int i=0; i<n; i++) {int temp; cin>>temp; v.push_back(temp);}
#define PRINT(v) for(int i = 0; i < v.size(); i++) cout << v[i] << " "; cout << en;
#define SORT(v) sort(v.begin(), v.end());
#define CASEP(v) cout<<"Case "<<c<<": "<<v<<"\n"

int main(void)
{
	#ifndef ONLINE_JUDGE
		freopen("in.txt", "r", stdin);
		freopen("out.txt", "w", stdout);
	#endif

	fast_io
	
	string s;
	cin >> s;

	int cnt = 0, big = 0;
	bool streak = false;
	for(int i = 0; i < s.size(); i++)
	{
		if(s[i] == 'R')
		{
			cnt++;
			big = cnt;
		}
		else
			cnt = 0;
	}
	cout << big << en;

	return 0;
}

Measured memory_bytes: 3640
//******* It's LEVI_17 ***************

#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;

#define ff first
#define ss second
#define MP make_pair
#define mset(x,a) memset(x,a,sizeof(x))
#define max3(x,y,z) max(x,max(y,z))
#define min3(x,y,z) min(x,min(y,z))
#define sqr(a) (a)*(a)
#define all(x) (x).begin(), (x).end()
#define f(i, n) for (int i = 0; i < n; i++)
#define f1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define vvll vector<vector<ll>>  
#define vll vector<ll> 
#define pll pair<ll,ll>
#define vpll vector<pll>
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define cases ll t;cin >> t;while(t--)
#define rr return 0
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

#define deb(a)			std::cerr<<#a<<"="<<(a)<<"\n"
#define deb2(a,b)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<"\n"
#define deb3(a,b,c)		std::cerr<<#a<<"="<<(a)<<", "<<#b<<"="<<(b)<<", "<<#c<<"="<<(c)<<"\n"
const int MOD = 1000 * 1000 * 1000 + 7;

//syntax for priority queue
// max queue -> priority_queue<ll>
// min queue -> priority_queue<ll,vector<ll>,greater<ll>>

//##############################################################################################


void solve()
{
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    ll ans1 = a * c;
    ll ans2 = a * d;
    ll ans3 = b * c;
    ll ans4 = b * d;

    cout << max(ans1, max(ans2, max(ans3, ans4))) << "\n";
}

//###############################################################################################

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


//Watashi wa tsuyoku modotte kimasu

Measured memory_bytes: 3576
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

BIG_NUM = 2000000000
MOD = 1000000007
EPS = 0.000000001


N = int(input())
table = list(map(int,input().split()))

MAX = 2000
check = [False]*(MAX+1)

def recursive(index,tmp_sum):
    global N

    if index == N:
        check[tmp_sum] = True
        return

    recursive(index+1,tmp_sum)
    if tmp_sum+table[index] <= MAX:
        recursive(index+1,tmp_sum+table[index])

recursive(0,0)

num_query = int(input())
for num in list(map(int,input().split())):
    if check[num]:
        print("yes")
    else:
        print("no")



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

int main() {
	int a, b, c, d, n, i, x, y;
	cin >> n;
	for(i = 1; i <= n; i++) {
		cin >> a >> b >> c >> d;
		if (c >= 5 && d >= 2) {
			cout << (a * c + b * d) - ((a * c + b * d) * 0.2) << endl;
		}else{
			x = a * c + b * d;
			if (c < 5){
				c = 5;
			}
			if (d < 2){
				d = 2;
			}	
			y = (a * c + b * d) - ((a * c + b * d) * 0.2);
			if (x < y) {
				cout << x << endl;
			}else{
				cout << y << endl;
			}
		}
 	} 
}


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

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	string S;
	int k;
	cin >> S >> k;
	set<string> res;
	vector<string> ans;
	ll a = S.size();
	for (int i = 0; i < a; ++i) {
		for (int j = 1; j <= k; ++j) {
			res.insert(S.substr(i, j));
		}
	}
	for (auto&& string  : res) ans.push_back(string);
	sort(ans.begin(), ans.end());
	cout << ans[k - 1] << endl;
	return 0;
}

Measured memory_bytes: 1920
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <string>
#include <vector>

using namespace std;

#define debug(x) (cout << # x ": " << x << endl)
#define ll long long int
#define repeat(n) for (int i = 0; i < n; ++i)
#define all(x) x.begin(), x.end()

int main() {
    ll a, b ,n;
    cin >> a >> b >> n;
    
    ll x = min(b - 1, n);
    cout << a * x / b;

    return 0;
}


Measured memory_bytes: 3168
#include <iostream>

using namespace std;
int main(int argc, char *argv[]) {
	int yen = 500;
	int num = 0;
	int total = 0;
	
	cin >> num >> total;
	
	if (num * yen >= total){
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	vector <pair<int,int>>jun(N);
	for (int i=0;i<N;i++){
		cin >> jun.at(i).first;
		jun.at(i).second=i+1;
	}
	sort(jun.begin(),jun.end());
	for (int i=0;i<N;i++){
		if(i!=N-1){
			cout << jun.at(i).second<<" ";
		}
		else {
			cout << jun.at(i).second<<endl;
		}
		
	}
	
}



Measured memory_bytes: 1664
import numpy as np
a,b,h,m=map(int, input().split())
min = h*60 + m

rada = np.radians(90-min*0.5)
acos = np.cos(rada)
x1 = a * acos
asin = np.sin(rada)
y1 = a * asin

radb = np.radians(90-m*6)
bcos = np.cos(radb)
x2 = b * bcos
bsin = np.sin(radb)
y2 = b * bsin

A = np.array([x1, y1])
B = np.array([x2, y2])
u = B-A
print(np.linalg.norm(u))

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

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

using namespace std;

typedef long long ll;

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(20)<<fixed;

  int n; cin >> n;
  double ans = n-n/2;

  cout << ans/n << endl;

  return 0;
}

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

int count(int (*common)[1001], char *x, char *y, int n1, int n2){
    if(n1*n2==0)return 0;
    else if(common[n1][n2]<0){
        if(x[n1]==y[n2])common[n1][n2] = 1 + count(common,x,y,n1-1,n2-1);
        else common[n1][n2] = std::max(count(common,x,y,n1-1,n2),count(common,x,y,n1,n2-1));
    }
    return common[n1][n2];
}

int main(){
    int i, j, k, q;
    char c;
    char x[1002], y[1002];
    int common[1001][1001];
    scanf("%d",&q);
    for(i=0;i<q;i++){
        scanf("%s",x+1);
        scanf("%s",y+1);
        int n1 = strlen(x+1);
        int n2 = strlen(y+1);
        for(j=1;j<=n1;j++){
            for(k=1;k<=n2;k++){
                common[j][k] = -1;
            }
        }
        printf("%d\n",count(common,x,y,n1,n2));
    }
    return 0;
}



Measured memory_bytes: 6724
#include <cstdio>
#include <algorithm>

using namespace std;

#define MOD (1000 * 1000 * 1000 + 7)

inline int fact(int n) {
    int ans = 1;
    for (int i = 2; i <= n; i++)
        ans = 1LL* ans * i % MOD;
    return ans;
}

int main(){
    int n, m;
    scanf("%d%d", &n, &m);

    if(n > m)
        swap(n, m);

    int ans = 0;
    if(n == m) {
        ans = 2LL * fact(n) * fact(m) % MOD;
    }else if (n == m - 1)
        ans = 1LL* fact(n) * fact(m) % MOD;

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

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <cmath>

#include <string>
#include <cmath>
 
int main(void) {
  int N;
  int A[100];

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

  int max = 0;
  for (size_t i = 0; i < N; i++) {
    for (size_t j = 0; j < N; j++) {
      auto diff = abs(A[i] - A[j]);
      if (diff > max) {
        max = diff;
      }
    }
  }

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


  return 0;
}


Measured memory_bytes: 764
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stack>
#include <queue>
#include <numeric>
#include <iomanip>
#include <map>
#include <set>
#include <deque>
#include <utility>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define MOD 1e9 + 7
#define INF 1e9
#define SENTINEL 2e9
#define PIE 3.1415926535

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;}
template <class T>
inline T GCD(T a, T b){if (b == 0) return a; else return GCD(b, a % b);}
template <class T>
inline T LCM(T a, T b) {return (a * b) / GCD(a, b);}

int main(){
    string s;
    cin >> s;
    int n = s.size();
    rep(i, n - 1) cout << 'x';
    cout << 'x' << endl;
}

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

template<typename T>
T get_value(std::istream& is);

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

  const auto N {get_value<int>(cin)};

  auto res {numeric_limits<int>::max()};
  for (auto A {1}; A < N; ++A) {
    const auto B {N - A};
    const auto f {[](auto e){
      auto res {0};
      do {
        res += e % 10;
      } while(e /= 10);
      return res;
    }};
    res = min(f(A) + f(B), res);
  }

  cout << res;
  return 0;
}

template<typename T>
inline T get_value(std::istream& is)
{
  T v;
  is >> v;
  return v;
}


Measured memory_bytes: 256
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
 
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, N = MAP()
L = [LIST() for i in range(N)]
A = []
B = []
for a, b in L:
    A.append(a)
    B.append(b)

v = H + max(A)

dp = [[INF] * (v + 1) for i in range(N+1)]
dp[0][0] = 0

for i in range(N):
    for j in range(v):
        if j-A[i] >= 0:
            dp[i+1][j] = min(dp[i+1][j-A[i]]+B[i], dp[i][j])
        dp[i+1][j] = min(dp[i+1][j], dp[i][j])

print(min(dp[N][H:]))

# for i in range(1, N+1):
#     for j in range(1, v+1):
#         if j-A[i-1] >= 0:
#             # i
#             dp[i][j] = min(dp[i-1][j-A[i-1]]+B[i-1], dp[i][j])
#         dp[i][j] = min(dp[i-1][j], dp[i][j])

# print(dp[N][H:])




Measured memory_bytes: 321500
import sys

li1 = list(map(int,input().split()))
li2 = list(map(int,input().split()))
li3 = list(map(int,input().split()))
n=int(input())
call = [int(input()) for i in range(n)]

li1.extend(li2)
li1.extend(li3)

bingo=[0,0,0,0,0,0,0,0,0]

for num in call:
    if num in li1:
        ind = li1.index(num)
        bingo[ind] = 1

if bingo[0] == bingo[1] == bingo[2] == 1:
    print('Yes')
    sys.exit()

if bingo[3] == bingo[4] == bingo[5] == 1:
    print('Yes')
    sys.exit()

if bingo[6] == bingo[7] == bingo[8] == 1:
    print('Yes')
    sys.exit()

if bingo[0] == bingo[3] == bingo[6] == 1:
    print('Yes')
    sys.exit()

if bingo[1] == bingo[4] == bingo[7] == 1:
    print('Yes')
    sys.exit()

if bingo[2] == bingo[5] == bingo[8] == 1:
    print('Yes')
    sys.exit()

if bingo[0] == bingo[4] == bingo[8] == 1:
    print('Yes')
    sys.exit()

if bingo[2] == bingo[4] == bingo[6] == 1:
    print('Yes')
    sys.exit()

print('No')




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

using namespace std;
using ll = long long;


int main()
{
	string k; cin >> k;
	string s = k;
	ll cnt = 0;
	ll n = k.size(), t; cin >> t;

	if(count(k.begin(), k.end(), k.front()) == n) {
		cout << (t * n) / 2 << endl;
		return 0;
	}
	
	for(int i = 1; i < n; i++) {
		if(s[i - 1] == s[i]) {
			s[i] = 0;
			cnt++;
		}
	}

	if(k.front() != k.back()) {
		cout << t * cnt << endl;
	}else {
		ll a = 1, b = 1;
		for(int i = 1; i < n; i++) {
			if(k[i] == k[i - 1])a++;
			else break;
		}
		for(int i = n - 2; i >= 0; i--) {
			if(k[i] == k[i + 1])b++;
			else break;
		}

		cout << (t * cnt) - ((a / 2) + (b / 2) - ((a + b) / 2)) * (t - 1) << endl;
	}

}

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

typedef vector<int> vi;
#define rep(var,n)  for(int var=0;var<(n);++var)

int main() {
    int N; scanf("%d", &N);
    vi a(N);
    rep(i,N) scanf("%d", &a[i]);

    int odd = 0;
    rep(i,N) if (a[i] % 2) ++odd;

    cout << (odd > 0? "first" : "second") << endl;
    return 0;
}


Measured memory_bytes: 640
/*
* welcome to my code!
* ------------------------------------------
* author : lynmisakura(twitter : @andoreiji11)
*/

#include<bits/stdc++.h>
using namespace std;

using ll = long long;

// macro templates

#define rrep(i,n) for(int i = n - 1;i >= 0;i--)
#define rep(i,n) for(int i = 0;i < n;i++)
#define dv(TYPE,VAL) TYPE VAL;cin >> VAL;
#define vi(TYPE,NAME,SIZE,INIT) vector<TYPE> NAME(SIZE,(INIT))
#define vin(TYPE,NAME,SIZE) vector<TYPE> NAME(SIZE);rep(i,SIZE)cin >> NAME[i]
#define vout(ARRAY) for(auto i : ARRAY)cout << i << ' ';cout << '\n'
#define vvi(TYPE,NAME,LOW,COL,INIT) vector<vector<TYPE>> NAME(LOW,vector<TYPE>(COL,INIT))
#define vpi(T1,T2,NAME,SIZE,I1,I2) vector<pair<T1,T2>> NAME(SIZE,make_pair(I1,I2))
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define dup(x,y) (x + y - 1)/(y)
#define sz(v) (int64_t)v.size()
#define CUM(arr,cum) vector<ll> cum(sz(a)+1,0); rep(i,sz(a)) cum[i+1] = cum[i] + 1
#define PY(COND) if(COND){cout << "YES" << '\n';return;}
#define PN(COND) if(COND){cout << "NO" << '\n';return;}
#define PYN(COND) cout << ((COND) ? "YES" : "NO") << '\n';
#define Py(COND) if(COND){cout << "Yes" << '\n';return;}
#define Pn(COND) if(COND){cout << "No" << '\n';return;}
#define Pyn(COND) cout << ((COND) ? "Yes" : "No") << '\n';return

#define mp make_pair
#define pb push_back
#define eb emplace_back
#define pi acos(-1)
#define fi first
#define se second
#define pq priority_queue

#define MULTITEST; int t;cin >> t;rep(_,t)main2();
#define IOB; cin.tie(0);ios::sync_with_stdio(false);

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

// templates end

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

    int64_t x,n;cin >> x >> n;
    map<int64_t ,int64_t > M;
    rep(i,n){
        int64_t p;cin >> p;
        M[p]++;
    }
    int64_t ans = INT_MAX;
    int64_t res = INT_MAX;
    for(int64_t i = 200;i >= 0;i--){
        if(!M[i]){
            if(abs(i - x) <= ans){
                ans = abs(i - x);
                res = i;
            }
        }
    }
    cout << res << '\n';
}

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

int h, w, k;
char g[10][10];

void solve(){
    cin >> h >> w >> k;
    for(int i = 0; i < h; ++i){
        for(int j = 0; j < w; ++j){
            cin >> g[i][j];
        }
    }

    int ways = 0;
    for(int i = 0; i < (1<<h); ++i){
        for(int j = 0; j < (1<<w); ++j){
            int cnt = 0;
            for(int k = 0; k < h; ++k){
                for(int l = 0; l < w; ++l){
                    if(((i>>k) & 1) && ((j>>l) & 1)){
                        if(g[k][l]=='#') cnt++;
                    }
                }
            }
            if(cnt == k){
                ++ways;
            }
        }
    }

    cout << ways << '\n';
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define rep(i, n) for(ll i=0; i<(n); ++i)
#define rep1(i,n) for(ll i=1; i<=(n); ++i)
#define repi(i,a,b) for(ll i=a; i<=(b); ++i)
#define rrep(i,n) for(ll i=(n-1); i>=0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define RALL(obj) (obj).rbegin(), (obj).rend()
#define pb push_back
#define mp make_pair
#define to_s to_string
#define sz(v) (int)v.size()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define pr(x) cout<<(x)<<'\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
using Edge = pair<int,long long>;
using Graph = vector<vector<Edge>>;
typedef pair<ll,ll> P;
struct aaa{aaa(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}aaaaaaa;
int MOD = 1e9 + 7;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return (a*b)/gcd(a,b);}
ll devc(ll x, ll y){return 1 + (x-1)/y;}

string BASE_CONVERSION(ll num, ll base, ll digit){
    string s = "";
    ll x = pow(base,digit-1);
    for(ll i = 0; i < digit; i++) s += to_s(num / x), num %= x, x /= base;
    return s;
}

ll solve(ll N, ll A, ll B, ll C, vector<ll>& L){
    
    ll ans = 1e15;
    rep(i,pow(4,N)){
        ll a = 0, b = 0, c = 0, MP = 0;
        string s = BASE_CONVERSION(i,4,N);
        
        rep(j,N){
            if(s[j] == '1'){
                if(a != 0) MP += 10;
                a += L[j];
            }
            if(s[j] == '2'){
                if(b != 0) MP += 10;
                b += L[j];
            }
            if(s[j] == '3'){
                if(c != 0) MP += 10;
                c += L[j];
            }
        }
        
        if(a*b*c == 0) continue;
        
        ans = min(ans,abs(A-a)+abs(B-b)+abs(C-c)+MP);
    }
    
    return ans;
}

int main(){
    ll N,A,B,C; cin >> N >> A >> B >> C;
    vector<ll> L(N); rep(i,N) cin >> L[i];
    
    pr(solve(N,A,B,C,L));
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using System.Runtime.CompilerServices;
using static MyUtil;

class MyUtil
{
    public static int[] ReadIntArray()
    {
	return ReadLine().Split().Select(x => int.Parse(x)).ToArray();
    }
}

class Program
{
    static int n;
    static double[,,] dp;

    // メモ化再帰
    static double rec(int x, int y, int z)
    {
	if (dp[x,y,z] != -1.0) return dp[x,y,z];

	// 空でない皿にあたるまでの試行回数の期待値
	double r = 1.0 * n / (x + y + z);

	// 条件付きの遷移確率 * 遷移後の期待値
	if (x > 0)　r += rec(x-1, y+1, z) * x/(x+y+z);
	if (y > 0)　r += rec(x, y-1, z+1) * y/(x+y+z);
	if (z > 0)　r += rec(x, y, z-1) * z/(x+y+z); 

	return dp[x,y,z] = r;
    }

    public static void Main()
    {
	n = int.Parse(ReadLine());
	int[] a = ReadIntArray();
	int[] c = new int[4];
	for (int i = 0; i < n; i++) c[a[i]]++;

	dp = new double[301,301,301];
	for (int i = 0; i < 301; i++)
	    for (int j = 0; j < 301; j++)
		for (int k = 0; k < 301; k++)
		    dp[i,j,k] = -1.0;

	dp[0,0,0] = 0;
	WriteLine(rec(c[3],c[2],c[1]));
    }
}


Measured memory_bytes: 226388
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
using namespace std;
 
int main(){
    int n,c=0;
    cin>>n;
    vector<int> s(n);
    vector<int> l;
    rep(i,n) cin>>s[i];
    rep(i,n-1){
        l.push_back(s[i]);
        sort(ALL(l));
        if (l[i]<=s[i+1]) c++;
    }
    cout<<c+1<<endl;
    return 0;
}

Measured memory_bytes: 256
/*C - Vacation*/
#include <bits/stdc++.h>

using namespace std;
using Long = long long;

vector <Long> cero;
vector <Long> uno;
vector <Long> dos;

vector <vector <Long> > memo;

Long maxHappiness(Long dias, Long anterior);

int main(){

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

	Long dias;

	cin >> dias;

	cero = vector <Long>(dias);
	uno = vector <Long>(dias);
	dos = vector <Long>(dias);

	memo = vector<vector <Long> >(dias + 1, vector<Long> (4, -1));

	for (int i = 0; i < dias; ++i)
	{
		cin >> cero[i] >> uno[i] >> dos[i];
	}

	Long ans;

	ans = maxHappiness(dias - 1, 3ll);

	cout << ans;

	return 0;
}

Long maxHappiness(Long dias, Long anterior){

	if(dias < 0ll){
		return 0ll;
	}

	if(memo[dias][anterior] != -1){
		return memo[dias][anterior];
	}

	Long ans;


	if(anterior == 3ll){

		ans = maxHappiness(dias - 1, 0) + cero[dias];
		ans = max(ans, maxHappiness(dias-1, 1) + uno[dias]);
		ans = max(ans, maxHappiness(dias-1, 2) + dos[dias]);
	}

	else if(anterior == 0){
		ans = maxHappiness(dias-1, 2) + dos[dias];
		ans = max(ans, maxHappiness(dias-1, 1) + uno[dias]);
	}
	else if(anterior == 1){
		ans = maxHappiness(dias - 1, 0) + cero[dias];
		ans = max(ans, maxHappiness(dias-1, 2) + dos[dias]);
	}
	else{
		ans = maxHappiness(dias-1, 1) + uno[dias];
		ans = max(ans, maxHappiness(dias-1, 0) + cero[dias]);
	}

	memo[dias][anterior] = ans;

	return ans;

}

Measured memory_bytes: 14336
#include <stdio.h>
#include <limits.h>

int main(void) {
  long i, n, temp, sum = 0;
  long min = LONG_MAX, max = LONG_MIN;

  scanf("%ld", &n);

  for (i = 0; i < n; i++) {
    scanf("%ld", &temp);

    sum += temp;

    if (temp < min)
      min = temp;
    if (temp > max)
      max = temp;
  }

  printf("%ld %ld %ld\n", min, max, sum);

  return 0;
}

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


const int num = 16, ud[] = { -1, 0, 1, 0 }, lr[] = { 0, -1, 0, 1 }, nd = 4;
const char wa[] = { 'u', 'l', 'd', 'r' };
int md[num][num];
vector<int> way;
int lm;


struct puzzle {
    int sp, p[num], mdp;
    string way;
    bool operator < (const puzzle &pu) const {
        for (int i = 0; i < num; i++) {
            if (p[i] == pu.p[i]) continue;
            return p[i] < pu.p[i];
        }
        return false;
    }
};

puzzle pu;

bool dfs(int de, int pr) {
    if (de + pu.mdp > lm) return false;
    if (pu.mdp == 0) return true;
    int sx = pu.sp / nd;
    int sy = pu.sp % nd;
    int tx, ty, ns;
    puzzle tmp;
    for (int r = 0; r < nd; r++) {
        if (max(r, pr) - min(r, pr) == 2) continue;
        tx = sx + ud[r];
        ty = sy + lr[r];
        tmp = pu;
        if (tx >= nd || tx < 0 || ty >= nd || ty < 0) continue;
        ns = tx * nd + ty;
        pu.mdp -= md[ns][pu.p[ns]- 1];
        pu.mdp += md[pu.sp][pu.p[ns] - 1];
        pu.sp = ns;
        swap(pu.p[ns], pu.p[sx * nd + sy]);
        if (dfs(de + 1, r)) {
            way.push_back(r);
            return true;
        }
        pu = tmp;
    }
    return false;
}

int main() {
    puzzle p;
    int sum = 0;
    for (int i = 0; i < num; i++) {
        cin >> p.p[i];
        if (!p.p[i]) { p.sp = i; p.p[i] = num; }
    }
    for (int i = 0; i < num; i++)
        for (int j = 0; j < num; j++)
            md[i][j] = abs(i / nd - j / nd) + abs(i%nd - j%nd);
    for (int i = 0; i < num; i++) {
        if (p.p[i] == num) continue;
        sum += md[i][p.p[i] - 1];
    }
    p.mdp = sum;
    pu = p;
    for (lm = p.mdp; lm < 100; lm++) {
        if (dfs(0, -5/*, pu*/)) {
            cout << way.size() << endl; return 0;
        }
    }
}


Measured memory_bytes: 3196
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#include <unordered_map>
#include <iomanip>
//#pragma GCC optimize("Ofast")
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
//#define int ll
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define floatprec(dig) fixed << setprecision(dig)
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int;
#define invar(typ, var) typ var; cin >> var;
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;} return 0;}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;} return 0;}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX / 2;
const ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
const double EPS = 1e-9;

signed main(void) {
  cin.tie(0); ios::sync_with_stdio(false);
  
  int N, K;
  cin >> N >> K;
  vi sn(N);
  rep(i, K) {
    int d;
    cin >> d;
    rep(i, d) {
      int A;
      cin >> A;
      A--;
      sn[A] = 1;
    }
  }
  
  int n = 0;
  rep(i, N) {
    if(sn[i] == 0) n ++;
  }
  fin(n);
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define stoi stoll
using pii=pair<int,int>;
#define all(c) begin(c),end(c)
#define rall(c) rbegin(c),rend(c)
#define fore(x,c) for(auto &&x:c)
#define rep(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define rrep(i,n) for(int i=(int)(n);i>=0;--i)
#define sz(c) ((int)c.size())
#define contains(c,x) (c.find(x)!=end(c))
#define inseg(l,x,r) ((l)<=(x)&&(x)<(r))
#define dump(...)
#define pb push_back
#define _ 0
const signed INF_=1001001001; const long long INF=1001001001001001001LL;
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) os<<*i<<(i==end(v)-1?"":" ");return os;}
template<class T> istream& operator>>(istream &is,vector<T> &v) {
    for (auto i = begin(v); i != end(v); i++) is>>*i;return is;}
template<class T,class U> istream& operator>>(istream &is, pair<T,U> &p) {
    is>>p.first>>p.second;return is;}
template<class T, class U> bool chmax(T &a,const U &b){return a<b?a=b,1:0;}
template<class T, class U> bool chmin(T &a,const U &b){return a>b?a=b,1:0;}
template <class T> void psum(T& c) {partial_sum(begin(c), end(c), begin(c));}
template<class T> using heap=priority_queue<T,vector<T>,greater<T>>;
struct before_main_function {
    before_main_function() {
        cin.tie(0); ios::sync_with_stdio(0);
        cout << setprecision(15) << fixed;
        // #define endl "\n"
    }
} before_main_function;
//------------------8<------------------------------------8<--------------------

signed main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, 0, N) {
        cin >> A[i];
    }
    sort(rall(A));

    int ans = 0;
    map<int, int> cnt;
    rep(i, 0, N) {
        cnt[A[i]]++;
    }
    rep(i, 0, N) {
        if (cnt[A[i]] == 0) {
            continue;
        }

        int k = 1;
        while (k <= A[i]) k <<= 1;
        if (k <= A[i] * 2) {
            int x = k - A[i];
            cnt[A[i]]--;
            if (A[i] >= x && cnt[x] > 0) {
                cnt[x]--;
                ans++;
            }
        }
    }
    cout << ans << endl;
    return (0^_^0);
}



Measured memory_bytes: 26880
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <functional>
#include <string>
#include <cstdlib>
#include <numeric>
#include <cstdbool>
#include <map> 
using namespace std;

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

const long long INF = 1LL << 60;
char s[60][60];
int bomb[60][60];
int main()
{
	long long a,b,x;
	cin >> a >> b >> x;
	long long res = 0;
	if (a) a = (a - 1) / x + 1;
	b = b / x + 1;
	cout << b - a << endl;
}


Measured memory_bytes: 256
N,K = map(int, input().split())
h= list(map(int, input().split()))
INF=float('inf')
dp=[INF]*(N)
dp[0]=0
dp[1]=abs(h[0]-h[1])

for i in range(2,N):
    for k in range(1,K+1):
        dp[i]=min(dp[i-k]+abs(h[i]-h[i-k]),dp[i])
print(dp[-1])

Measured memory_bytes: 85552
T = list(map(int,input().split()))



a = [[0,1,2],[0,2,1],[1,2,0],[2,1,0],[1,0,2],[2,0,1]]
A = sum(T)
for i in a:
    A = min(A,abs(T[i[2]] - T[i[1]]) + abs(T[i[1]]-T[i[0]]))

print(A)


Measured memory_bytes: 3064
/* Those who cannot remember the past are condemned to repeat it.*/
/* author:Ajeet */

#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
const int sz=1e3+5;
#define mod 1000000007
#define ull unsigned long long int

int main()
{
        fast_cin();
    int n;
    cin>>n;
    string s;
    cin>>s;
    //cout<<s.substr(n/2,n)<<endl;
    if(n%2) cout<<"No"<<endl;
    else if(s.substr(0,n/2)==s.substr(n/2,n)) cout<<"Yes"<<endl;
    else cout<<"No" <<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
#include <set>
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };
const double PI = 3.14159265358979323846;


int main() {
	
	int k, a, b;
	cin >> k >> a >> b;

	if ((b / k) > (a > k)) {
		cout << "OK" << endl;
	}
	else if ((b % k) == 0) {
		cout << "OK" << endl;
	}
	else {
		cout << "NG" << endl;
	}
	
	return 0;
	
}



Measured memory_bytes: 3628
import java.util.*;
import java.io.*;
 
public class Main {
    public static void main (final String[] args) {
        final Scanner s = new Scanner(System.in);
        int n = s.nextInt();
      	int temp = 0;
      
      	for (int i = 0; i < n; i++) {
          temp = s.nextInt();
          if (temp%2 == 0) {
            if (temp%3 != 0 && temp%5 != 0) {
              System.out.println("DENIED");
              System.exit(0);
            }
          }
        }
      	System.out.println("APPROVED");
    }
}

Measured memory_bytes: 23124
#include<iostream>
#include<cstdlib>
using namespace std;
int main(){
    int n,m;
    cin >> n >> m;
    int i,j;
    int k[n+1],a[n+1][m+1];
    for(i=1;i<=n;i++){
        cin >> k[i];
        for(j=1;j<=k[i];j++){
            cin >> a[i][j];
        }
    }
    int ans=0,l,x=0,fav=0;
    for(i=1;i<=m;i++){
        for(j=1;j<=n;j++){
            for(l=1;l<=k[j];l++){
                if(a[j][l]==i){
                    fav++;
                    break;
                }
            }
        }
        if(fav==n){
            fav=0;
            ans++;
        }
      else fav=0;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math


def find(lst):
    lst2 = []
    for li in lst:
        x = li % 10
        if x == 0:
            lst2.append(10)
        else:
            lst2.append(x)

    min_ = lst2[0]
    min_i = 0
    for i in range(len(lst2)):
        if lst2[i] < min_:
            min_ = lst2[i]
            min_i = i
    return min_i


F = []
for i in range(5):
    F.append(int(input()))

min_i = find(F)

ans = 0
for i, fi in enumerate(F):
    if i == min_i:
        continue
    # ans += math.ceil(fi)
    ans += (math.ceil(fi / 10)) * 10

ans += F[min_i]
print(ans)


Measured memory_bytes: 3064
A, B = map(int, input().split())


def f(n):
    if n % 4 == 0:
        return n
    elif n % 4 == 1:
        return 1
    elif n % 4 == 2:
        return n + 1
    else:
        return 0


print(f(B) ^ f(A - 1))


Measured memory_bytes: 2940
#include<bits//stdc++.h>
using namespace std;
int main() {
    int n, a, b; char c; string s; long long int d = 0;
    cin >> n;
    vector<tuple<int, int,char,long long int, string>> v(n);
    for (int i = 0; i < n; i++) {
        cin >> a >> b >> c >> d >> s;
        get<0>(v[i]) = a; get<1>(v[i]) = b;
        get<2>(v[i]) = c; get<3>(v[i]) = d;
        get<4>(v[i]) = s;
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n; i++) {
        cout << get<0>(v[i]) << " " << get<1>(v[i]) << " ";
        cout << get<2>(v[i]) << " " << get<3>(v[i]) << " ";
        cout << get<4>(v[i]) << endl;
    }
}


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

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

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<math.h>
#include <iterator>
#include <map>
#include<cmath>
using namespace std;


int main (){
 long long int r,d,x,sum=0;;
 cin>>r>>d>>x;
 for(int i=0;i<10;i++){
    sum=r*x-d;
    cout<<sum<<endl;
    x=sum;

 }
return 0;
}

















Measured memory_bytes: 256
#include <iostream>
#include <map>
#define rep(i,n) for(int i=0;i<(n);++i)
using namespace std;
using ll = long long;

int main() {
  map<int, int> mp;
  int N; cin >> N;
  ll res = 0;
  rep(i,N){
    int a; cin >> a;
    mp[a]++;
    res += a;
  }
  int Q; cin >> Q;
  rep(i,Q){
    int b, c; cin >> b >> c;
    res += (c-b)*mp[b];
    mp[c] += mp[b];
    mp[b] = 0;
    cout << res << endl;
  }
  return 0;
}

Measured memory_bytes: 8040
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<set>
#include<tuple>
#include<ctime>
#include<functional>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> p; 
#define rep(i,n) for(ll i=0;i<(n);i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))

int main(){
    long double A,B;
    ll ans;
    cin>>A>>B;
    ans=A*B;
    p(ans);
}

Measured memory_bytes: 3692
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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;}

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    int n;
    cin>>n;
    int m;
    cin>>m;
    vpii pref[n];
    vpii ans(m);
    rep(i,0,m){
        int p,y;
        cin>>p>>y;
        p--;
        pii t=make_pair(y,i);
        pref[p].push_back(t);
    }
    rep(i,0,n)sort(pref[i].begin(),pref[i].end());
    rep(i,0,n){
        int cnt=0;
        for(pii t:pref[i]){
            cnt++;
            pii in=make_pair(i+1,cnt);
            ans[t.second]=in;
        }
    }
    rep(i,0,m){
        printf("%06d%06d\n",ans[i].first,ans[i].second);
    }
    return 0;
}




Measured memory_bytes: 7680
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <tuple>
#include <utility>
#include <vector>
#define ll long long
#define itn int
#define endl '\n'
#define co(ans) cout<<ans<<endl
#define COYE cout<<"YES"<<endl
#define COYe cout<<"Yes"<<endl
#define COye cout<<"yes"<<endl
#define CONO cout<<"NO"<<endl
#define CONo cout<<"No"<<endl
#define COno cout<<"no"<<endl
#define FORE(i,a) for(auto &i:a)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define FFOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n)  FFOR(i,1,n)
#define PB push_back
#define MP make_pair
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort((V).begin(),(V).end())
#define REVERSE(V) reverse((V).begin(),(V).end())
#define EACH(V,i) for(typeof((V).begin()) i=(V).begin();i!=(V).end();++i)
#define equals(a,b) (fabs((a)-(b))<EPS)
#define INF ((1LL<<62)-(1LL<<31))
#define EPS 1e-10
#define PI 3.141592653589793238
#define MOD 1000000007
#define MAX 5100000
using namespace std;
using Edge=pair<int,int>;
using Graph=vector<vector<int>>;
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>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int main(){
  ll A;
  cin>>A;
  co(A*(A-1)/2);
  return 0;
}

Measured memory_bytes: 3640
# D - Multiple of 2019

s = input()

# pow[k] = 10 ** k % 2019
pow = [1]
while len(pow) <= 1 or pow[-1] > 1:
    pow.append(pow[-1] * 10 % 2019)
n = len(pow) - 1  # 10 ** n == 1 mod 2019

# memo[i % n][m] = (int(s[:i+1]) % 2019 == mであるiの個数)
memo = [[0] * 2019 for i in range(n)]
memo[n - 1][0] = 1  # memo[-1][0] = 1

count = 0  # int(s[i:j+1]) == 0 mod 2019 である(i,j)の個数
mod = 0
for j, c in enumerate(s):
    mod = (mod * 10 + int(c)) % 2019  # mod = int(s[:j+1]) % 2019
    for i in range(1, n + 1):
        m = mod * pow[n - i] % 2019  # m == mod * 10 ** (-i) mod 2019
        count += memo[(j - i + n) % n][m]
    memo[j % n][mod] += 1

print(count)


Measured memory_bytes: 71952
package main

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

func oneInt() int {
	var a int
	fmt.Scan(&a)
	return a
}
func oneStr() string {
	var a string
	fmt.Scan(&a)
	return a
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func scanNums() (nums []int) {
	s := nextLine()
	numStr := strings.Split(s, " ")

	for _, n := range numStr {
		i, _ := strconv.Atoi(n)
		nums = append(nums, i)
	}
	return nums
}

func scanStrings() (strs []string) {
	s := nextLine()
	list := strings.Split(s, " ")
	strs = append(strs, list...)
	return strs
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func sortAsc(a []int) []int {
	sort.Ints(a)
	return a
}

func sortDesc(a []int) []int {
	sort.Sort(sort.Reverse(sort.IntSlice(a)))
	return a
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	if a == 0 && b == 0 {
		return 0
	}
	return a * b / gcd(a, b)
}

var sc = bufio.NewScanner(os.Stdin)

func calc(nums []int) int {
	if len(nums) == 1 {
		return 0
	}

	if len(nums) == 2 {
		if nums[0] == nums[1] {
			return 1
		} else {
			return 0
		}
	}

	ans0 := 0
	ans1 := 0
	for i := 0; i < len(nums); i++ {

		if i == 0 {
			if nums[0] == 0 {
				ans1++
			} else {
				ans0++
			}
		}

		if i == 1 {
			if nums[1] == 0 {
				ans0++
			} else {
				ans1++
			}
		}

		// 0スタート
		if i != 0 && i != 1 && i%2 != 0 && nums[i] == 0 {
			ans0++
		}
		if i != 0 && i != 1 && i%2 == 0 && nums[i] == 1 {
			ans0++
		}

		//1
		if i != 0 && i != 1 && i%2 != 0 && nums[i] == 1 {
			ans1++
		}
		if i != 0 && i != 1 && i%2 == 0 && nums[i] == 0 {
			ans1++
		}
	}

	return min(ans0, ans1)
}

func main() {
	a := oneInt()
	b := oneInt()
	t := oneInt()

	ans := (t / a) * b

	fmt.Println(ans)
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
#define ll long long
using namespace std;

void factor(int a,map<int,ll>& factors){
    for(int i=2;i*i<=a;i++){
        if(0==a%i)
        while(0==a%i){
            a/=i;
            factors[i]++;
        }
    }
    if(1!=a) factors[a]++; 
    return;
}
int main(){
    int n;
    cin>>n;
    map<int,ll> factors;
    for(int i=1;i<=n;i++){
        factor(i,factors);
    }
    ll ans=1;
    for(const auto& item: factors){
        ans*=(item.second+1);
        ans%=1000000007;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
import sys
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

from collections import deque

N,K,*P=map(int,sys.stdin.read().split())

Kmin = []
deq = deque()
for i in range(K):
    while deq and P[deq[-1]] > P[i]:
        deq.pop()
    deq.append(i)
Kmin.append(deq[0])
for i in range(K,N):
    if deq[0] == i-K:
        deq.popleft()
    while deq and P[deq[-1]] > P[i]:
        deq.pop()
    deq.append(i)
    Kmin.append(deq[0])

Kmax = []
deq = deque()
for i in range(K):
    while deq and P[deq[-1]] < P[i]:
        deq.pop()
    deq.append(i)
Kmax.append(deq[0])
for i in range(K,N):
    if deq[0] == i-K:
        deq.popleft()
    while deq and P[deq[-1]] < P[i]:
        deq.pop()
    deq.append(i)
    Kmax.append(deq[0])

is_new_seq = [Kmin[i] != i or Kmax[i+1] != i+K for i in range(N-K)]

is_new_seq

import itertools
incr = [1 if x<y else 0 for x,y in zip(P,P[1:])]
incr_cum = [0] + list(itertools.accumulate(incr))
is_stable = [y-x==K-1 for x,y in zip(incr_cum,incr_cum[K-1:])]

is_new_seq = [x&(not y) for x,y in zip(is_new_seq,is_stable[1:])]

answer = sum(is_new_seq)
if not is_stable[0]:
    answer += 1
    if any(is_stable):
        answer += 1
else:
    answer += 1
print(answer)

Measured memory_bytes: 43832