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

int main() {

  long long int n, m, l;
  cin >> n >> m >> l;

  vector< vector< long long int > > a;

  for ( long long int i = 0; i < n; i++ ) {
    vector< long long int > v;
    for ( long long int j = 0; j < m; j++ ) {
      long long int in;
      cin >> in;
      v.push_back( in );
    }
    a.push_back( v );
  }

  vector< vector< long long int > > b;
  for ( long long int i = 0; i < m; i++ ) {
    vector< long long int > v;
    for ( long long int j = 0; j < l; j++ ) {
      long long int in;
      cin >> in;
      v.push_back( in );
    }
    b.push_back( v );
  }

  for ( long long int i = 0; i < n; i++ ) {

    for ( long long int k = 0; k < l; k++ ) {

      if ( k > 0 ) cout << " ";
      long long int cnt = 0;
      for ( long long int j = 0; j < m; j++ ) {
	cnt += a[i][j] * b[j][k];
      }
      cout << cnt;

    }

    cout << endl;

  }

  return 0;

}

Measured memory_bytes: 1400
N, M = map(int, input().split())
E = [[] for _ in range(N)]
for _ in range(M):
    ta, tb = map(int, input().split())
    E[ta-1].append(tb-1)
S, T = map(int, input().split())
S -= 1
T -= 1

INF = float('inf')
dist = [[INF] * N for _ in range(3)]
dist[0][S] = 0
q = [[S,0]]

while q:
    cp, cd = q.pop(0)
    nd = (cd + 1) % 3
    for np in E[cp]:
        if dist[nd][np] != INF:
            continue
        else:
            dist[nd][np] = dist[cd][cp] + 1
            q.append([np,nd])

ans = dist[0][T]
if ans == INF:
    print(-1)
else:
    print(ans//3)

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

int prime(int x) {
  if(x == 2) return true;
  for(int i = 2; i < x; ++i){
    if(x%i == 0) return false;
  }
  return true;
}

int main() {
  int X; cin >> X;
  int ans = X;
  
  while(prime(ans)==false) ans++;
  
  cout << ans << endl;
}

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

#define rep(i, n) for (int i = 0; i < int(n); i++)
#define rrep(i, n) for (int i = int(n) - 1; i >= 0; i--)
#define reps(i, n) for (int i = 1; i <= int(n); i++)
#define rreps(i, n) for (int i = int(n); i >= 1; i--)
#define repc(i, n) for (int i = 0; i <= int(n); i++)
#define rrepc(i, n) for (int i = int(n); i >= 0; i--)
#define repi(i, a, b) for (int i = int(a); i < int(b); i++)
#define repic(i, a, b) for (int i = int(a); i <= int(b); i++)
#define each(x, y) for (auto &x : y)
#define all(a) (a).begin(), (a).end()
#define bit32(x) (1 << (x))
#define bit64(x) (1ll << (x))

using namespace std;

using i64 = long long;
using f80 = long double;
using vi32 = vector<int>;
using vi64 = vector<i64>;
using vf80 = vector<f80>;
using vstr = vector<string>;

inline void yes() { cout << "Yes" << endl; exit(0); }
inline void no() { cout << "No" << endl; exit(0); }
inline i64 gcd(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); if (a % b == 0) return b; return gcd(b, a % b); }
inline i64 lcm(i64 a, i64 b) { if (min(a, b) == 0) return max(a, b); return a / gcd(a, b) * b; }
template <typename T> class pqasc : public priority_queue<T, vector<T>, greater<T>> {};
template <typename T> class pqdesc : public priority_queue<T, vector<T>, less<T>> {};
template <typename T> inline void amax(T &x, T y) { x = max(x, y); }
template <typename T> inline void amin(T &x, T y) { x = min(x, y); }
template <typename T> inline T exp(T x, i64 n, T e = 1) { T r = e; while (n > 0) { if (n & 1) r *= x; x *= x; n >>= 1; } return r; }
template <typename T> istream& operator>>(istream &is, vector<T> &v) { each(x, v) is >> x; return is; }
template <typename T> ostream& operator<<(ostream &os, vector<T> &v) { rep(i, v.size()) { if (i) os << ' '; os << v[i]; } return os; }
void solve(); int main() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(16); solve(); return 0; }

void solve() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  vstr ans(h);
  rep(i, h) ans[i] = string(w, '0');
  rep(i, h) rep(j, w) {
    if ((i < b) == (j < a)) {
      ans[i][j] = '1';
    }
  }
  rep(i, h) cout << ans[i] << endl;
}


Measured memory_bytes: 2304
#include<bits/stdc++.h>
using namespace std;
#define   ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define   ll  long long
#define   pi  pair<int,int>
#define   pb  push_back
const int N=2e5+2;
bool P(ll x)
{
    for(ll i=2;i<=(x/i);i++)
    {
        if(x%i==0)
        {
            return false;
        }
    }
    return true;
}
int main()
{
    ft
    ll t,i,j,n,m,k;
    cin>>n;
    for(i=n; ;i++)
    {
        if(P(i)==true)
        {
            cout<<i<<"\n";
            break;
        }
    }
    return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int h = l[0], w = l[1];
            var cost = new int[10][];
            var map = new int[h][];
            for (var i = 0; i < 10; i++) cost[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();
            for (var i = 0; i < h; i++) map[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

             for (int k = 0; k < 10; k++){
                 for (int i = 0; i < 10; i++) {
                     for (int j = 0; j < 10; j++) { 
                        cost[i][j] = Math.Min(cost[i][j], cost[i][k] + cost[k][j]);
                     }
                }
            }

            var total = 0L;
            for (var i = 0; i < h; i++) {
                for (var j = 0; j < w; j++) {
                    if (map[i][j] != -1)
                        total += cost[map[i][j]][1];
                }
            }

            Console.WriteLine(total);
        }
    }
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> k(n, 1);
	vector<bool> r(n, false);
	r[0] = true;
	for (int i = 0; i < m; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		k[x]--;
		k[y]++;
		r[y] = r[y] || r[x];
		r[x] = r[x] && k[x] != 0;
	}
	int c = 0;
	for (auto e : r) {
		c += e;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<ctime>

using namespace std;
const int maxn = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
typedef long long ll;
#define pb push_back

int n, m;
int dp[maxn];
int in[maxn];

int main(){
	scanf("%d%d", &n, &m);
	queue<int>q;
	vector<int> vt[maxn];
	memset(dp, 0, sizeof dp);
	int u, v;
	for(int i = 1; i <= m; ++i){
		scanf("%d%d", &u, &v);
		vt[u].pb(v);
		in[v]++;
	}
	for(int i = 1; i <= n; ++i)
		if(in[i] == 0) q.push(i);

	int now;
	int ans = 0;
	while(!q.empty()){
		now = q.front();
		q.pop();
		int len = vt[now].size();
		for(int i = 0; i < len; ++i){
			int t = vt[now][i];
			dp[t] = max(dp[t], dp[now] + 1);
			in[t]--;
			if(in[t] == 0) q.push(t);
			ans = max(ans, dp[t]);
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 9820
//
// Created by Myabu on 2020/01/03.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>

using namespace std;


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

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

    int sum = accumulate(W, W+N, 0);
    int z_sum = 0;
    int ans = sum;
    for (int i = 0; i < N; ++i) {
        sum -= W[i];
        z_sum += W[i];
        ans = min(ans, abs(sum-z_sum));
    }

    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 256
D, G = map(int, input().split())
P = []
C = []
for i in range(D):
  p, c = map(int, input().split())
  P.append(p)
  C.append(c)
ans = 10*100
for i in range(2**D):
  rest = G
  cnt = 0
  maxdgt = -1
  for j in range(D):
    if i & 1<<j:
      rest -= P[j]*(j+1)*100+C[j]
      cnt += P[j]
    else:
      maxdgt = j
  if rest <= 0:
    ans = min(ans, cnt)
  elif rest > (P[maxdgt]-1)*(maxdgt+1)*100:
    continue
  else:
    ans = min(ans, cnt+(rest/100-1)//(maxdgt+1)+1)
print(int(ans))

Measured memory_bytes: 3064
N,K=map(int,input().split())
R,S,P=map(int,input().split()) #RSP グーチョキパー
T=list(input())

c=0

def jan(a):
    if a=="r":
        return P
    elif a=="s":
        return R
    elif a=="p":
        return S
    else:
        return 0

for i in range(K,N):
    if T[i-K]==T[i]:
        T[i]="o"

for i in range(1,K+1): #modK
    for j in range(N//K+1):
        if i+K*j>N:
            continue
        c+=jan(T[i+K*j-1])

print(c)

Measured memory_bytes: 4084
object Main extends App {
  import scala.io.StdIn._

  val Array(n, m, c) = readLine.trim.split(' ').map(_.toInt)
  val b = readLine.trim.split(' ').map(_.toInt)
  println(
    Array.tabulate(n){_ ⇒
      readLine.trim.split(' ').map(_.toInt)
    }.count(_.zip(b).map{case (a, b) ⇒ a * b}.sum + c > 0)
  )
}

Measured memory_bytes: 27328
#include<bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define REPvec(itr, mp) for(auto itr = mp.begin();itr != mp.end(); itr ++)
#define all(x) x.begin(), x.end()
#define MOD 1000000007//1e9+7
using namespace std;
typedef long long ll;
typedef vector<int >    vecint;
typedef vector<ll >    vecll;
typedef vector<string > vecstr;
int main()
{
  int n;
  cin >> n;
  vecint a(n,0);
  REP(i,n)cin >> a[i];
  if(n %2 == 0){
    for(int i = n/2; i >= 1; i --){
      cout << a[2*i - 1]  << " ";
    }
    for(int i = 1; i <= n/2; i ++){
      cout << a[2*i  - 2]  << " ";
    }
    cout << endl;
    return 0;
  }else{
    for(int i = n/2; i >= 0; i --){
      cout << a[2*i]<< " ";
    }
    for(int i = 1; i <= n/2; i ++){
      cout << a[2*i - 1] << " ";
    }
    cout << endl;
    return 0;
  }
} 

Measured memory_bytes: 3452
#include<bits/stdc++.h>
using namespace std;
int main(){
	int s= 0,a,b,c;
	cin>>a>>b>>c;
	if(a ==5 && b==5 || b == 5 && c == 5 || a == 5 && c == 5){
		s ++;
	}
	if(a == 7||b==7||c==7){
		s++;
	}
	if(s == 2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
}


Measured memory_bytes: 256
gets.to_i
numbers = gets.split.map(&:to_i)

result = "Yes"
(numbers.size-1).downto(1) do |i|
  # theory numbers[i] > numbers[i-1]
  numbers[i-1] -= 1 if numbers[i] < numbers[i-1]
  result = "No" if numbers[i] < numbers[i-1]
end

puts result

Measured memory_bytes: 11012
#include <iostream>
using namespace std;
int main()
{
    long n , m ;
    cin >> n >> m;
    long r;
    if(n < m)
    {
        long t; t=n; n=m; m=t;
    }//n>=mになった
    switch (m)
    {
        case 1:
            n==1 ? r=1 : r=n-2;
            break;
        case 2: 
            r=0;
            break;
        default: 
            r=(n-2)*(m-2);
            break;
    }
    cout << r <<endl;
    return 0;
}




Measured memory_bytes: 256
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from itertools import accumulate

n ,m = li()

imos = [0]*(n+1)

for _ in range(m):
    l,r = li_()
    imos[l] += 1
    imos[r+1] -= 1

cum = list(accumulate(imos))

ans = 0
for ci in cum:
    if ci == m:
        ans += 1

print(ans)

Measured memory_bytes: 8120
#include<bits/stdc++.h>
using namespace std;
string s;
int main(){
    cin>>s;int cnt=0;int tmp=0;
    for(int i=0;i<int(s.size());i++){
        if((s[i]=='A')||(s[i]=='G')||(s[i]=='T')||(s[i]=='C')){cnt++;tmp=max(cnt,tmp);}
        else {tmp=max(tmp,cnt);cnt=0;}
    }
    cout<<tmp;
}

Measured memory_bytes: 256
/*
AizuOnline A0064
Secret Number
*/
#include <stdio.h>

long find_secret(char *s)
{
  long ret;
  char c;
  char *p;
  ret = 0;
  while(c=*s)
    {
      if(isdigit(c))
	{
	  ret += strtol(s,&p,10);
	  s = p;
	}
      else
	s++;
    }
  return(ret);
}
main()
{
  char buffer[81];
  long ret=0;
 
 while(EOF != scanf(" %s",buffer))
    {
     ret += find_secret(buffer);
    }
 printf("%ld\n",ret);
 return(0);
}

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

typedef long long int lli;
#define int lli
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<lli> vli;
typedef vector<pii> vii;

const int MOD	= 1e9 + 7;
const double PI = acos(-1.0);

#define fastio			ios_base::sync_with_stdio(0);cin.tie(0)
#define sz(a) int((a).size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define eb emplace_back
#define all(c) (c).begin(),(c).end()
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define rep(i, n)    for(int i = 0; i < (n); ++i)
#define repA(i, a, n)  for(int i = a; i <= (n); ++i)
#define repD(i, a, n)  for(int i = a; i >= (n); --i)
#define endl "\n"
#define error(x) cerr << #x << " = " << (x) << endl
#define errorp(p) cerr << #p << " = " << (p.first) << ", " << (p.second) << endl

template<typename T> T gcd(T a, T b){return(b?__gcd(a,b):a);}
template <typename T> T lcm(T a, T b){return (a*b)/gcd(a,b); }

const int mx = 50;
vi pref_sum(mx + 1);
int f(int n){
    return ((n + 1) * n) / 2;
}


bool is_prime(lli n){
    bool yeah = true;
    if( n <= 1){
        yeah = false;
    }else{
        lli temp = lli(ceil(sqrt(n)));
        for(lli i = 2; i < temp; i++){
            if(n % i == 0){
                yeah = false;
                break;
            }
        }
        if( temp * temp == n){
            yeah = false;
        }
    }

    return yeah;
}


int get_divisors(int n){
    int ans = 0;
    int temp = int(ceil( sqrt(n)));
    // error(temp);
    for(int i = 2; i < temp; i++){
        int tmp = 0;
        while(n % i == 0){
            n /= i;
            tmp++;
        }
        if(tmp > 0){
            int pos = upper_bound(all(pref_sum), tmp) - pref_sum.begin();
            pos--;
            ans += pos;
        }
    }
    if(is_prime(n)){
        ans++;
    }
    return ans;
}


void solve(){
    int N;
    cin >> N;
    pref_sum[0] = 0;
    repA(i, 1,  mx){
        pref_sum[i] = f(i);
        // cout << pref_sum[i] <<" ";
    }
    // cout << endl;
    if(N == 1){
        cout << 0 << endl;
    }else if(is_prime(N)){
        cout << 1 << endl;    
    }else{
        cout << get_divisors(N) << endl;
    }
}

signed main(){
    #ifdef DEBUG
		freopen("test", "r", stdin);
	#endif
    fastio;
    
    solve();

    return 0;
}


Measured memory_bytes: 3768
#include <bits/stdc++.h>
using namespace std;
constexpr long long MOD = 1000000007;
constexpr long long INF = 1LL << 60;
const long double PI = acosl(-1.0);
using ll = long long;
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;
}
int main() {
string t;
cin>>t;
ll n = t.size();
ll cnt = 0;
ll que = 0;
for (ll i = n-1; i >=0; i--){
    if(t[i]=='?'){
        if (t[i - 1] == 'P') t[i] = 'D';
        else if(t[i-1]=='D')
            t[i] = 'D';
        else
            t[i] = 'D';
    }
}
cout << t << endl;
}

Measured memory_bytes: 3756
#include"bits/stdc++.h"
using namespace std;


int main()
{
    int n;
    cin>>n;
    int a[n+5],b[n+5];
    for(int i=1; i<=n; i++)
    {
        cin>>a[i];
        b[i]=a[i];
    }


    sort(a+1,a+n+1);

    int c=0;
    for(int i=1; i<=n; i++)
    {
        if(a[i]!=b[i])c++;
    }
    if(c==0||c==2)
    {cout<<"YES"<<endl;}
    else{cout<<"NO"<<endl;}
  
  return 0;
}


Measured memory_bytes: 256
/*---------------------------------

 @Author:   Dicer
 @DateTime: 2019-05-15 19:53:54

---------------------------------*/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
inline ll qpow(ll a,ll b,ll mod){ll res=1;while(b){if(b&1)res = (res*a)%mod;a=(a*a)%mod;b>>=1;}return res;}
const double eps = 1e-8;
const int INF = 0x3f3f3f3f;
const int mod = 1e9+7;
const int MAXN = 1e5 + 7;

struct DSU{
	int pre[MAXN], son[MAXN], n, m;
	vector<pii > G;
	ll pairs, ans[MAXN];
	void init(){
		srand(0);
		pairs = 1ll*n*(n-1)/2;
		for(int i = 1; i <= n; ++i){
			pre[i] = i;
			son[i] = 1;
		}
	}
	int find(int x){
		if(x == pre[x])	return x;
		else	return pre[x] = find(pre[x]);
	}
	void merge(int x, int y){
		int fx = find(x);
		int fy = find(y);
		if(fx == fy)	return;
		else{
			pre[fx] = fy;
			pairs -= 1ll*son[fx]*son[fy];
			// cout << "#1 " << x << ' ' << y << endl;
			// cout << "#2 " << fx << ' ' << fy << endl;
			// cout << "#3 " << son[fx] << ' ' << son[fy] << endl;
			son[fy] += son[fx];
		}
	}
	void go(){
		cin >> n >> m;
		init();
		int u, v;
		for(int i = 1; i <= m; ++i){
			cin >> u >> v;
			G.push_back({u, v});
		}
		for(int i = m; i >= 1; --i){
			u = G[i-1].first; v = G[i-1].second;
			ans[i] = pairs;
			merge(u, v);
		}
		for(int i = 1; i <= m; ++i){
			cout << ans[i] << endl;
		}
	}
};
int main(int argc, char const *argv[])
{
	DSU dsu;
	dsu.go();
	return 0;
}

Measured memory_bytes: 3828
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int X = sc.nextInt();
    boolean flag = true;

    while(flag){
      if(X==2){
      break;
      }
      for(int i=2; i<X; i++) {
        flag = false;
        if(X % i == 0){
          X++;
          flag = true;
          break;
        }
      }
    }
    System.out.println(X);
  }
}

Measured memory_bytes: 22736
#include <bits/stdc++.h>
using namespace std;
const int maxn = 3e5+7;
string s;
int k;
set<string> ans;
int main()
{
    cin >> s >> k;
    int len = s.length();
    for(int i = 0; i < len; ++i) {
        for(int j = 1; j <= 5; ++j) {
            if(i+j-1 >= len) continue;
            ans.insert(s.substr(i, j));
        }
    }
    set<string>::iterator iter = ans.begin();
    int i = 1;
    for(; i != k; ++iter, ++i);
    cout << *iter << endl;
}

Measured memory_bytes: 1664
using System;
using System.Linq;
using static System.Math;

class C
{
	static void Main()
	{
		var h = Console.ReadLine().Split().Select(int.Parse).ToArray();
		var l = new int[h[0]].Select(_ => int.Parse(Console.ReadLine())).ToArray();
		Console.WriteLine(GetMin1(h, l, new bool[h[0]], h[0] - 2));
	}

	static int GetMin1(int[] h, int[] l, bool[] u, int p_max) =>
		Enumerable.Range(1, p_max).Min(p => 10 * (p - 1) + GetMin1(h, l, u, p, 0, p_max - p + 1));

	static int GetMin1(int[] h, int[] l, bool[] u, int k, int sum, int q_max)
	{
		if (k == 0) return Abs(sum - h[1]) + GetMin2(h, l, u, q_max);

		var m = int.MaxValue;
		for (int i = 0; i < h[0]; i++)
		{
			if (u[i]) continue;
			u[i] = true;
			m = Min(m, GetMin1(h, l, u, k - 1, sum + l[i], q_max));
			u[i] = false;
		}
		return m;
	}

	static int GetMin2(int[] h, int[] l, bool[] u, int q_max) =>
		Enumerable.Range(1, q_max).Min(q => 10 * (q - 1) + GetMin2(h, l, u, q, 0, q_max - q + 1));

	static int GetMin2(int[] h, int[] l, bool[] u, int k, int sum, int r_max)
	{
		if (k == 0) return Abs(sum - h[2]) + GetMin3(h, l, u, r_max);

		var m = int.MaxValue;
		for (int i = 0; i < h[0]; i++)
		{
			if (u[i]) continue;
			u[i] = true;
			m = Min(m, GetMin2(h, l, u, k - 1, sum + l[i], r_max));
			u[i] = false;
		}
		return m;
	}

	static int GetMin3(int[] h, int[] l, bool[] u, int r_max) =>
		Enumerable.Range(1, r_max).Min(r => 10 * (r - 1) + GetMin3(h, l, u, r, 0));

	static int GetMin3(int[] h, int[] l, bool[] u, int k, int sum)
	{
		if (k == 0) return Abs(sum - h[3]);

		var m = int.MaxValue;
		for (int i = 0; i < h[0]; i++)
		{
			if (u[i]) continue;
			u[i] = true;
			m = Min(m, GetMin3(h, l, u, k - 1, sum + l[i]));
			u[i] = false;
		}
		return m;
	}
}


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

int main()
{
    long long  n,q,a,b,c,i,j,m,bb[100005]={0},s=0;

    cin>>n;

    for(i=0;i<n;i++){
        cin>>a;
        bb[a]++;
        s=s+a;
    }
    cin>>q;

    while(q--){
        cin>>b>>c;

        m=bb[b];

        if(m>0){
            s=s-m*b;
            s=s+m*c;
            bb[b]=0;
            bb[c]=bb[c]+m;
        }
        cout<<s<<endl;
    }
    return 0;
}




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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const int inf = 999999999;
const double pi = acos(-1);

#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}

///////////////////////////////////////////////////////////////////////////
int t[100005] = {};

int main(){
	int n,c,k;
	cin >> n >> c >> k;
	rep(i,0,n)cin >>t[i];
	sort(t,t+n);
	ull time =0;
	int i = 0,ans =0;

	while(i < n){
        time = t[i] + k;
        int cnt = 0;
       // cout << "time" << time<<endl;
        while((ull)t[i] <= time){
            if(cnt >= c || i >= n)break;
           // cout << t[i] << " ";
            i++;
            cnt++;
        }
        //cout << 'i' << i << endl;
        if(cnt > 0)ans ++;
	}

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

Measured memory_bytes: 640
n=int(input())
mod=10**9+7
a=list(map(int,input().split()))
ans=[0]*(10**5+1)
flag=False
if n%2==0:
  for i in range(len(a)):
    if a[i]%2==0:
      flag=True
      break
    ans[a[i]]+=1
    if ans[a[i]]>2:
      flag=True
      break
else:
  for i in range(len(a)):
    if a[i]%2==1:
      flag=True
      break
    ans[a[i]]+=1
    if ans[0]>1:
      flag=True
      break
    if ans[a[i]]>2:
      flag=True
      break
if flag==True:
  print(0)
else:
  print(pow(2,(n//2),mod))


Measured memory_bytes: 14008
#include<stdio.h>
int main(){
  int n,m,i,j,f,a[110],d[100010]={};
  scanf("%d %d",&n,&m);
  for(i=0;i<n;i++)scanf("%d",&a[i]);
  for(i=0;i<=m;i++){
    for(j=f=0;j<n;j++){
      if(i<a[j])continue;
      if(d[i-a[j]]==0)f=1;
    }
    d[i]=f;
  }
  printf("%s\n",d[m]?"First":"Second");
  return 0;
}


Measured memory_bytes: 512
import sys
stdin = sys.stdin

sys.setrecursionlimit(10**5)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


# nの逆元のリスト
def inv_mod(n:int, mod:int) -> list:
    inv = [0,1]
    for i in range(2,n+1):
        inv.append(mod - ((mod//i)*inv[mod%i]) % mod)
    return inv
       
# nの階乗のリスト
def fact(n:int, mod:int) -> list:
    fac = [1,1]
    res = 1
    for i in range(2,n+1):
        res = res*i%mod
        fac.append(res)
    return fac

# nの階乗の逆元のリスト
def fact_inv(n:int, inv:list, mod:int) -> list:
    facInv = [1,1]
    for i in range(2,n+1):
        facInv.append(facInv[i-1]*inv[i] % mod)
    return facInv
        
# 二項係数
def nCr(n:int, r:int, mod:int, fac:list, facInv:list) -> int:
    if not (0<=r and r<=n):
        return 0
    
    return ((fac[n]*facInv[r]) % mod) * facInv[n-r] % mod

from collections import Counter

n = ni()
a = list(li())
# 2こあるものは何か
cnt = Counter(a)
two = cnt.most_common(1)[0][0]

left = a.index(two)
right = a[::-1].index(two)

# 二項係数準備
MOD = 10**9+7

inv = inv_mod(n+2,MOD)
fac = fact(n+2,MOD)
fac_inv = fact_inv(n+2,inv,MOD)

for i in range(1,n+2):
    if 1 < i < n+1:
        ans = nCr(n+1,i,MOD,fac,fac_inv)

        if left+right >= i-1:
            ans -= nCr(left+right,i-1,MOD,fac,fac_inv)
            
        if ans < 0:
            ans += MOD
            
        print(ans)
        
    elif i == 1:
        print(n)
    else:
        print(1)

Measured memory_bytes: 68188
x = int(input())


for i in range(120):
    if x>i**5:
        for j in range(-100,0):
            ans = i**5-j**5
            if ans == x:
                print("{} {}".format(i,j))
                exit()
    else:
        for j in range(0,120):
            ans = i**5-j**5
            if ans == x:
                print("{} {}".format(i,j))
                exit()
        

Measured memory_bytes: 65068
n, k, q = gets.split.map(&:to_i)

ans = Array.new(n, 0)

q.times do
  ans[gets.to_i - 1] += 1
end

n.times do |i|
  value = k - (q - ans[i])
  if value > 0
    puts 'Yes'
  else
    puts 'No'
  end
end

Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define all(V) V.begin(),V.end()

int main(){
	int N;
	cin >> N;
	vector<pair<int, int>> A(N);
	for (int i = 0;i < N;i++) {
		cin >> A[i].first;
		A[i].second = i + 1;
	}
	sort(all(A));
	for (int i = 0;i < N;i++) {
		cout << A[i].second << " ";
	}
	cout << endl;
}

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

#define MAX_SIZE 36

struct Tramp{
  char mark;
  int number;
};

void bubble_sort(Tramp array[], int size) {
  for(int i = 0; i < size - 1; i++) {
    for(int j = size - 1; j > i; j--) {
      if(array[j].number < array[j - 1].number) {
        std::swap(array[j - 1], array[j]);
      }
    }
  }
}

void selection_sort(Tramp array[], int size) {
  for(int i = 0; i < size - 1; i++) {
    int min_index = i;
    for (int j = i + 1; j < size; j++) {
      if(array[j].number < array[min_index].number) {
        min_index = j;
      }
    }

    if(i != min_index) {
      std::swap(array[i], array[min_index]);
    }
  }
}

bool check_selection_stable(Tramp bubble[], Tramp selection[], int size) {
  for(int i = 0; i < size; i++) {
    if(
      selection[i].mark != bubble[i].mark ||
      selection[i].number != bubble[i].number
    ) {
      return false;
    }
  }
  return true;
}

void print_tramp(Tramp tramps[], int size) {
  for(int i = 0; i < size; i++) {
    printf("%c%d", tramps[i].mark, tramps[i].number);
    if(i != size - 1) {
      printf(" ");
    }
  }
  printf("\n");
}

int main() {
  int size;
  Tramp bubble_array[MAX_SIZE], selection_array[MAX_SIZE];
  scanf("%d%*c", &size);

  for(int i = 0; i < size; i++) {
    scanf("%c%d ", &bubble_array[i].mark, &bubble_array[i].number);
    selection_array[i].mark = bubble_array[i].mark;
    selection_array[i].number = bubble_array[i].number;
  }

  bubble_sort(bubble_array, size);
  selection_sort(selection_array, size);

  print_tramp(bubble_array, size);
  printf("Stable\n");
  print_tramp(selection_array, size);

  bool is_selection_stable = check_selection_stable(bubble_array, selection_array, size);
  if(is_selection_stable) {
    printf("Stable\n");
  } else {
    printf("Not stable\n");
  }

}



Measured memory_bytes: 2756
s = raw_input().strip()
n = len(s)
ans = [0] * n

left = [-1] * n
right = [-1] * n

for i in xrange(n - 1, -1, -1):
    if s[i] == 'L':
        left[i] = i
    else:
        left[i] = left[i + 1]

for i in xrange(n):
    if s[i] == 'R':
        right[i] = i
    else:
        right[i] = right[i - 1]

for i in xrange(n):
    if s[i] == 'R':
        j = left[i]
        z = j - i
        if z & 1:
            ans[j - 1] += 1
        else:
            ans[j] += 1
    else:
        j = right[i]
        z = i - j
        if z & 1:
            ans[j + 1] += 1
        else:
            ans[j] += 1

print ' '.join(map(str, ans))


Measured memory_bytes: 41372
x,y = map(int,input().split())
if x==1 and ( y==2 or y==4):
  print("Yes")
else:
  if y%2==1:
    print("No")
  else:
    if y<=x*4 and (y>=(x*2)):
      print("Yes")
    else:
      print("No")

Measured memory_bytes: 9124
n = gets.chomp.to_i
n -= 1
nums = gets.chomp.split.map(&:to_i)

nums.each_with_index do |val, idx|
      if idx == n
         printf "#{val}\n"
      else
         print "#{val} "
      end
end

for i in 1..n do

   k = i - 1

   while k >= 0

      unless nums[i-1] <= nums[i]
         temp = nums[i]
         nums[i] = nums[i-1]
         nums[i-1] = temp
      end

      i -= 1
      k -= 1

   end

   nums.each_with_index do |val, idx|
      if idx == n
         printf "#{val}\n"
      else
         print "#{val} "
      end
   end

end

Measured memory_bytes: 8772
package main

import "fmt"

func main() {
	var X int
	fmt.Scan(&X)

	fmt.Println(dfs(X))
}

var memo = make(map[int]int)

func dfs(n int) int {
	if n == 0 {
		return 1
	}

	if memo[n] != 0 {
		return memo[n]
	}

	if n < 0 {
		memo[n] = -1
		return 0
	}

	for i := 100; i <= 105; i++ {
		if dfs(n-i) == 1 {
			return 1
		}
	}

	memo[n] = -1

	return 0
}


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

typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=100005;

struct rec{
    int s;
    int e;
    int c;
};

bool csort(rec a,rec b){
    if(a.c==b.c) return a.s<b.s;
    return a.c<b.c;
}

int main(){
    
    int N,C;cin>>N>>C;
    vector<rec> S(N);
    vector<int> T(100005,0);
    
    for(int i=0;i<N;i++){
        cin>>S[i].s>>S[i].e>>S[i].c;
    }
    
    sort(all(S),csort);
    
    for(int i=0;i<N;i++){
        T[S[i].s]++;
        T[S[i].e+1]--;
    }
    
    for(int i=1;i<100005;i++){
        T[i]+=T[i-1];
    }
    
    for(int i=1;i<N;i++){
        if(S[i].c==S[i-1].c){
            if(S[i-1].e==S[i].s) T[S[i-1].e]--;
        }
    }
    
    int ans=0;
    for(int i=0;i<100005;i++){
        ans=max(ans,T[i]);
    }
    
    cout<<ans<<endl;
}


Measured memory_bytes: 1792
#10e5程度ならソートしてもTLEならないらしい？
n = int(input())
dic = {}
lis = []
lis2 = []

for i in range(n):
  moji = input()
  if moji not in dic:
    dic[moji] = 0
  dic[moji] += 1
  
for i in sorted(dic.items(), key=lambda x:x[1]):
    lis.append(i)
  
lis.reverse()

for j in lis:
  if lis[0][1] == j[1]:
    lis2.append(j[0])
  else:
    break

lis2.sort()
for i in range(len(lis2)):
  print(lis2[i])

Measured memory_bytes: 45908
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int INF = 1LL << 30;
int MOD = 1e9+7;
main(){
    int N,A,B;
    cin >> N >> A >> B;
    int cnt = 0;
    for(int i = 1;i <= N;i++){
        int num = i,c = 0;
        while(num){
            c += num % 10;
            num /= 10;
        }
        cnt += (c >= A && c <= B ? i : 0);
    }
    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef pair<string,int> PP;
typedef pair<int,int> P;

map<string,int> m;

int main() {
  int n;
  cin >> n;
  PP s[n];
  for(int i=0; i<n; i++) {
    string t;
    cin >> t;
    if(t[t.size()-1]==':') {
      t=t.substr(0,t.size()-1);
      s[i]=PP(t,0);
      m[t]=i;
    } else {
      cin >> t;
      s[i]=PP(t.substr(0,t.size()-1),1);
    }
  }
  vector<P> v[n];
  for(int i=0; i<n; i++) {
    if(s[i].second) {
      v[i].push_back(P(i+1,1));
      v[i].push_back(P(m[s[i].first],0));
    } else v[i].push_back(P(i+1,0));
  }
  int d[n+1];
  fill(d,d+n+1,1<<29);
  d[0]=0;
  priority_queue<P> que;
  que.push(P(0,0));
  while(!que.empty()) {
    P p=que.top();que.pop();
    int x=p.second,c=p.first;
    if(d[x]<c||x==n) continue;
    for(int i=0; i<v[x].size(); i++) {
      int y=v[x][i].first,cc=v[x][i].second;
      if(d[y]>d[x]+cc) {
        d[y]=d[x]+cc;
        que.push(P(d[y],y));
      }
    }
  }
  cout << d[n] << endl;
  return 0;
}


Measured memory_bytes: 1232
use proconio::input;
// use num::*;

fn main() {
    input! {
        n: usize,
        a: [u64; n]
    };
    let res = a.into_iter().fold(1u64, |sum, x| sum.saturating_mul(x));
    if res <= 10u64.pow(18) {
        println!("{}", res)
    } else {
        println!("-1");
    };
}


Measured memory_bytes: 4476
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.util.HashMap;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author AnandOza
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BJudgeStatusSummary solver = new BJudgeStatusSummary();
        solver.solve(1, in, out);
        out.close();
    }

    static class BJudgeStatusSummary {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            Counter<String> counter = new Counter<>();
            String[] LIST = {"AC", "WA", "TLE", "RE"};

            int n = in.nextInt();
            for (int i = 0; i < n; i++) {
                counter.incr(in.next());
            }

            for (String s : LIST) {
                out.println(s + " x " + counter.count.getOrDefault(s, 0));
            }
        }

    }

    static class Counter<T> {
        public HashMap<T, Integer> count = new HashMap<>();

        public void incr(T key) {
            count.merge(key, 1, Integer::sum);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



Measured memory_bytes: 43832
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main() {
	int n; cin >> n;
	int l[114514];
	for (int i = 0; i < n; i++){
		cin >> l[i];
	}
	sort(l, l + n);
	cout << l[n - 1] - l[0] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include<set> 
#include<math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
int main(){
  string s;
  cin>>s;
  int ans = 0;
  rep(i,3){
    if(s[i]=='o')
      ans++;
  }
  cout<<700+100*ans<<endl;


}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		int c = Integer.parseInt(sc.next());
		int d = Integer.parseInt(sc.next());
		int e = Integer.parseInt(sc.next());
		int min = 10;
		if (a % 10 != 0) {
			if (a % 10 < min) {
				min = a % 10;
			}
			a = a / 10 * 10 + 10;
		}
		if (b % 10 != 0) {
			if (b % 10 < min) {
				min = b % 10;
			}
			b = b / 10 * 10 + 10;
		}
		if (c % 10 != 0) {
			if (c % 10 < min) {
				min = c % 10;
			}
			c = c / 10 * 10 + 10;
		}
		if (d % 10 != 0) {
			if (d % 10 < min) {
				min = d % 10;
			}
			d = d / 10 * 10 + 10;
		}
		if (e % 10 != 0) {
			if (e % 10 < min) {
				min = e % 10;
			}
			e = e / 10 * 10 + 10;
		}
		int ans = a + b + c + d + e - 10 + min;
		System.out.println(ans);
		sc.close();
	}
}

Measured memory_bytes: 22612
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int in() {int x; cin>>x; return x;}
ll lin() {ll x; cin>>x; return x;}
string sin() {string x;cin>>x;return x;}
using graph = vector<vector<int>>;
using graph2 = vector<vector<pair<int, int>>>;

int main(){
    string s;
    cin>>s;
    char a;
    if(s.size()<26){
        rep(i, 26){
            a='a'+i;
            if(s.find(a)==-1){
                break;
            }
        }
        cout<<s+a<<endl;
    }
    else{
        if(s=="zyxwvutsrqponmlkjihgfedcba"){
            cout<<-1<<endl;
        }
        else{
            int b[26];
            rep(i, 26){
                b[i]=s.at(i)-'a';
            }
            next_permutation(b, b+26);
            string t="aaaaaaaaaaaaaaaaaaaaaaaaaa";
            rep(i, 26){
                t.at(i)=b[i]+'a';
            }
            int j=0;
            rep(i, 26){
                if(s.at(i)!=t.at(i)){
                    j=i;
                    break;
                }
            }
            rep(i, j+1){
                cout<<t.at(i);
            }
            cout<<endl;
        }
    }
}

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

using namespace std;

int N, x[1009], y[1009], r[1009], ap[1009];
long double INF = 1e14, d[1009], mat[1009][1009];

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

scanf ("%d %d %d %d", &x[1], &y[1], &x[2], &y[2]);
scanf ("%d", &N);
for (int i=3; i<=N + 2; i++)
    scanf ("%d %d %d", &x[i], &y[i], &r[i]);
for (int i=1; i<=N + 2; i++)
    for (int j=i + 1; j<=N + 2; j++)
    {
        int dx = x[i] - x[j], dy = y[i] - y[j];
        double D;
        if (1LL * dx * dx + 1LL * dy * dy <= 1LL * (r[i] + r[j]) * (r[i] + r[j])) D = 0.0;
        else D = (long double) sqrt ((long double) 1.0 * dx * dx + 1.0 * dy * dy) - r[i] - r[j];
        mat[i][j] = mat[j][i] = D;
    }
for (int i=1; i<=N + 2; i++)
    d[i] = INF;
d[1] = 0.0;
while (1)
{
    double mini = INF;
    int x = -1;
    for (int i=1; i<=N + 2; i++)
        if (d[i] < mini && ap[i] == 0)
            mini = d[i], x = i;
    if (x == -1) break;
    ap[x] = 1;
    for (int i=1; i<=N + 2; i++)
        if (ap[i] == 0 && d[x] + mat[x][i] < d[i] && i != x)
            d[i] = d[x] + mat[x][i];
}
cout << setprecision (10) << d[2] << '\n';
return 0;
}


Measured memory_bytes: 16128
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);  
		int n = sc.nextInt();
		List<Integer> list = new ArrayList<Integer>();
		for(int i = 0;i < n;i++) {
			list.add(sc.nextInt());
		}
		Collections.sort(list);
		list.set(n-1,list.get(n-1) / 2);
		int sum = 0;
		for(int i:list) {
			sum += i;
		}
		System.out.println(sum);
		sc.close();
	}
}

Measured memory_bytes: 23764
#!/usr/bin/env python3
import sys


def solve(a: int, b: int, c: int, d: int, e: int, k: int):
    print('Yay!' if e - a <= k else ':(')



# Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    a = int(next(tokens))  # type: int
    b = int(next(tokens))  # type: int
    c = int(next(tokens))  # type: int
    d = int(next(tokens))  # type: int
    e = int(next(tokens))  # type: int
    k = int(next(tokens))  # type: int
    solve(a, b, c, d, e, k)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9096
n = int(input())
c0 = 0
c1 = 0
c2 = 0
c3 = 0
while n > 0:
    n = n - 1
    s = input()
    if s == "AC":
        c0 = c0 + 1
    elif s == "TLE":
        c1 = c1 + 1
    elif s == "WA":
        c2 = c2 + 1
    else:
        c3 = c3 + 1
print("AC x", c0)
print("WA x", c2)
print("TLE x", c1)
print("RE x", c3)

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

#define REP(i,n) for(int i=0; i<n; i++)
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;
 
#define mod 1000000007 //1e9+7(prime number)
#define INF 10000000000000000000 //1e18
#define SIZE 200005

using namespace std;
typedef long long ll;

int n;
ll lx, x[SIZE], ans=INF;

ll calc(int k){
	// cerr << "calc(" << k << ")\n";
	ll tmpans =  k*lx;
	int j = 1;
	for (int i=0; k*i+j<=n; i++){
		// debug(i);
		for (j=1; j<=k && k*i+j<=n; j++){
			if (i==0){
				tmpans += 5*x[n-j];
			}else{
				tmpans += (2*(i+1)+1)*x[n-(k*i+j)];
			}
			// debug(j);
			// debug(tmpans);
		}
		// debug(tmpans + lx*n);
		j = 1;
	}
	return tmpans + lx*n;
}

int main(){	
	cin >> n >> lx;
	
	REP(i,n) cin >> x[i];
	
	if (n==1){
		cout << calc(1) << endl;
		return 0;
	}else if (n==2){
		cout << min(calc(1), calc(2)) << endl;
		return 0;
	}
	
	// n >= 3
	
	int l=2, r=n;	// [l, r)
	ans = calc(1);
	
	while (r-l>1){
		// debug(r);
		// debug(l);
		int k = (r+l)/2;
		// debug(k);
		if (calc(k) - calc(k-1)<=0){
			l = k;
		}else{
			r = k;
		}
	}
	
	// cerr << "-------------\n";
	
	// debug(r);
	// debug(l);
	
	ans = min(ans, calc(l));
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1792
//BadWaper gg
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<vector>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#define inf 1e9
#define eps 1e-6
#define mp make_pair
#define N 2000010
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
inline ll read()
{
	char ch=getchar();
	ll s=0,w=1;
	while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){s=s*10+ch-'0';ch=getchar();}
	return s*w;
}
int val[N][3],ch[N][3],tot,lazy[N];
int n;char s[N];
int ans[N],cnt;
int rev[N];
inline void build()
{
	tot=1;for(register int i=1;i<=n+1;i++)tot*=3;
	tot=(tot-1)/2;
	for(register int i=1;i<=tot;i++)
	{
		if(i*3<=tot)
		{
			ch[i][0]=i*3-1;ch[i][1]=i*3;ch[i][2]=i*3+1;
			val[i][0]=0;val[i][1]=1;val[i][2]=2;
		}
	}
}
inline void pushdown(int now)
{
	if(lazy[now])
	{
		lazy[ch[now][0]]^=1;lazy[ch[now][1]]^=1;lazy[ch[now][2]]^=1;
		int x=0,y=0;
		for(register int i=0;i<3;i++)
		{
			if(val[now][i]==1)x=i;
			if(val[now][i]==2)y=i;
		}
		swap(val[now][x],val[now][y]);
		lazy[now]=0;
	}
}
void update(int now)
{
	if(now*3>tot)return ;pushdown(now);int pos=0;
	for(register int i=0;i<3;i++)
	{
		val[now][i]++;
		if(val[now][i]==3)
		{
			val[now][i]=0;
			pos=ch[now][i];
		}
	}
	update(pos);
}
void dfs(int now,int v,int p)
{
	if(now*3>tot){ans[cnt++]=v;return ;}pushdown(now);
	for(register int i=0;i<3;i++)dfs(ch[now][i],v+val[now][i]*p,p*3);
}
int main()
{
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
	n=read();scanf("%s",s+1);
	build();
	int len=strlen(s+1);
	for(register int i=1;i<=len;i++)
	{
		if(s[i]=='R')update(1);
		else lazy[1]^=1;
	}
	dfs(1,0,1);
//	for(register int i=0;i<cnt;i++)cout<<ans[i]<<" ";cout<<endl;
	for(register int i=1;i<cnt;i++)rev[i]=rev[i/3]/3+(cnt/3)*(i%3);
	for(register int i=0;i<cnt;i++)if(i<rev[i])swap(ans[i],ans[rev[i]]);
	for(register int i=0;i<cnt;i++)printf("%d ",ans[i]);
	return 0;
}


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

using namespace std;
#define  ll long long
#define ld long double
#define f first
#define s second

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

    ll n;
    cin >> n;

    if (n%1000==0) cout << "0\n";
    else 
    cout << 1000-n%1000 << '\n';


    return 0;
}

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

#define ll long long
#define For(i,a,b) for(int (i)=(a);(i) < (b); ++(i))

const int N =100;

bool isprime(int n)
{
    if (n <= 1)
        return false;
    for (int i = 2; i*i<=n; i++)
        if (n % i == 0)
            return false;

    return true;
}
int binarySearch(int arr[], int l, int r, int x)
{
    if (r >= l) {
        int mid = l + (r - l) / 2;
        if (arr[mid] == x)
            return mid;
        if (arr[mid] > x)
            return binarySearch(arr, l, mid - 1, x);
        return binarySearch(arr, mid + 1, r, x);
    }
    return -1;
}
long long lcm(long long a,long long b)
{
    long long p,r;
    p = a*b;
    r = __gcd(a, b);
    return p/r;
}
bool ispalindrome(string s)
{
    int n = s.length();
    for(int i=0;i<n/2;i++)
    {
        if(s[i]!=s[n-i-1])
            return false;
    }
    return true;
}
bool isPerfectSquare(long double x)
{
  long double sr = sqrt(x);
  return ((sr - floor(sr)) == 0);

}
ll f(ll n) {
	return n * (n - 1) / 2;
}
bool cmp(const tuple<int, string, string>& a,
               const tuple<int, string, string>& b)
{
    return (get<0>(a) < get<0>(b));
}

void solve()
{
   vector<ll>temp;
   ll a,b,c,d;
   cin>>a>>b>>c>>d;

   temp.push_back(a*c);
   temp.push_back(a*d);
   temp.push_back(b*c);
   temp.push_back(b*d);
   sort(temp.begin(),temp.end());
   int n = temp.size();
   cout<<temp[n-1]<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        solve();
    }
}


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

int main() {
    int x, y;
    cin >> x >> y;
    int groupx = 0;
    int groupy = 0;
    if(x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12){
        groupx = 1;
    } else if(x == 2){
        groupx = 3;
    } else {
        groupx = 2;
    }
    if(y == 2){
        groupy = 3;
    } else if(y == 4 || y == 6 || y == 9 || y == 11){
        groupy = 2;
    } else {
        groupy = 1;
    }
    if(groupx == groupy){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1e6+10;
int main()
{
    string a,b;
    cin>>a>>b;
    int len=a.size();
    int res=0;
    for(int i=0;i<len;i++)
        if(a[i]!=b[i]) res++;
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3836
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; ++i)
using namespace std;
using ll = int64_t;
using vi = vector<int>;
using vvi = vector<vi>;

int main() {
    map<int, int> s;
    rep(i, 3) {
        int t;
        cin >> t;
        s[t]++;
    }

    if(s[5] == 2 && s[7] == 1) {
        cout << "YES" << endl;
    } else 
    cout << "NO" << endl;
}

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

using namespace std;
using nagai = long long;
#define sz(x) int((x).size())
const int mod=1e9+7;
int su(int a,int b){
	 if((a+=b)>=mod)a-=mod;
	 return a;
}
int mu(int a,int b){
	 return (nagai)a*b%mod;
}
int pw(int a,int b,int c=1){
	 for(;b;b>>=1,a=mu(a,a))if(b&1)c=mu(c,a);
	 return c;
}

int dv(int a,int b){
	return mu(a,pw(b,mod-2));
}


const int N=200100;
int fact[N],rfact[N];
int C(int n,int k){
	return mu(fact[n],mu(rfact[k],rfact[n-k]));
}

int n,a,b,c;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	fact[0]=1;
	for(int i=1;i<N;++i)
		fact[i]=mu(fact[i-1],i);
	rfact[N-1]=dv(1,fact[N-1]);
	for(int i=N-2;i>=0;--i)
		rfact[i]=mu(rfact[i+1],i+1);
	cin>>n>>a>>b>>c;
	a=dv(a,100);
	b=dv(b,100);
	int a1=a;
	int b1=b;
	a=dv(a,su(a1,b1));
	b=dv(b,su(a1,b1));
	int ans=0;
	for(int i=0;i<n;++i){
		ans=su(ans,mu(i+n,mu(pw(a,i),mu(pw(b,n),C(n+i-1,n-1)))));
//		cerr<<ans<<'\n';
		ans=su(ans,mu(i+n,mu(pw(a,n),mu(pw(b,i),C(n+i-1,n-1)))));
//		cerr<<ans<<'\n';
	}
	ans=mu(ans,dv(1,su(a1,b1)));
	cout<<ans<<'\n';
	return 0;
}



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

int main() {
 int N;
 cin >> N;
 int ans[4] = {0,0,0,0};
 rep(i,N) {
   string S;
   cin >> S;
   if(S=="AC") ans[0]++;
   if(S=="WA") ans[1]++;
   if(S=="TLE") ans[2]++;
   if(S=="RE") ans[3]++;
 }
 cout << "AC x  " << ans[0] << endl;
 cout << "WA x  " << ans[1] << endl;
 cout << "TLE x  " << ans[2] << endl;
 cout << "RE x  " << ans[3] << endl;
}

Measured memory_bytes: 3588