akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <stack>
#include <istream>
#include <map>
#include <set>
#include <queue>
#define rep0(i,n) for (int i = 0; i < (n); ++i)  //0スタート
#define rep1(i,n) for (int i = 1; i < (n); ++i)  //1スタート
#define REP(i,a,b) for (int i = a; i < (b); ++i)  //aからbまで
#define mREP(i,a,b) for (int i = a; i > (b); --i)  //aからbまで
#define print(x) cout<<x<<endl  //xを改行付きで出力
#define scan(x) cin>>x //xを入力
const int INF = 1e9 + 7;  //最大値兼MOD
//  cin.tie(0);
//  ios::sync_with_stdio(false);
typedef long long ll;
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; }
int main(){
  int temp = -1;
  vector<int>v(0);
  while(temp != 0){
    cin>>temp;
    v.push_back(temp);
  }
  rep0(i,(int)v.size() - 1){
    cout<<"Case "<<i + 1<<":"<<" "<<v[i]<<endl;
  }
  return 0;
}


Measured memory_bytes: 3204
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);++i)
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(int (i)=(n)-1; (i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;

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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

int main() {
	init();

	int N; cin >> N;
	vector<pair<int, int>>vec(N);
	rep(i, N) {
		int a, b; cin >> a >> b;
		vec[i] = make_pair(b, a);
	}
	sort(all(vec));
	bool is = true;
	ll cnt = 0;
	rep(i, N) {
		cnt += vec[i].second;
		if (cnt > vec[i].first)is = false;
	}
	cout << (is ? "Yes" : "No") << "\n";
		
	return 0;
}

Measured memory_bytes: 1792
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.System.*;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {

    static void solve() throws Exception {
        int r = scanInt();
        out.print(2 * r * Math.PI);
    }

    static int scanInt() throws IOException {
        return parseInt(scanString());
    }

    static long scanLong() throws IOException {
        return parseLong(scanString());
    }

    static String scanString() throws IOException {
        while (tok == null || !tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine());
        }
        return tok.nextToken();
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) {
        try {
            in = new BufferedReader(new InputStreamReader(System.in));
            out = new PrintWriter(System.out);
            solve();
            in.close();
            out.close();
        }
        catch (Throwable e) {
            e.printStackTrace();
            exit(1);
        }
    }
}

Measured memory_bytes: 33300
from itertools import groupby

s = list(input())
ans = [0]*len(s)
ind = 0

for k,v in groupby(s):
  key,value = k,len(list(v))
  ind += value
  
  if k == 'R':
    if value%2 != 0:
      ans[ind-1] += (value//2)+1
      ans[ind] += value//2
    else:
      ans[ind-1] += value//2
      ans[ind] += value//2
  else:
    if value%2 != 0:
      ans[ind -value] += (value//2) + 1
      ans[ind-1- value] += (value//2) 
    else:
      ans[ind -value] += value//2
      ans[ind -1- value] += value//2
      
print(*ans)

Measured memory_bytes: 7116
package main

import "fmt"

func main() {
	var s string
	fmt.Scan(&s)

	var cnt int
	for i := 0; i < len(s)/2; i++ {
		if s[i] != s[len(s)-i-1] {
			cnt += 1
		}
	}
	fmt.Println(cnt)
}


Measured memory_bytes: 512
using System;
using System.IO;

class Program{
    static void Main(string[] args){
        var arr = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);
        long N = arr[0], K = arr[1];
        var answer = N;
        if (K == 1) answer = 0;
        if (!(N < Math.Abs(N - K)) && K != 1){
            var mod = N % K;
            var abs = Math.Abs(mod - K);
            answer = mod < abs ? mod : abs;}
        var writer = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(writer);
        Console.WriteLine(answer);
        Console.Out.Flush();}}

Measured memory_bytes: 27288
package main

import (
        "fmt"
)

func main() {
        var a int
        var b int
        var k int
        fmt.Scan(&a)
        fmt.Scan(&b)
        fmt.Scan(&k)
        var target int
        if a > b {
                target = b
        } else {
                target = a
        }
        var i int = 1
        var list []int
        for target >= i {
                if a%i == 0 && b%i == 0 {
                        list = append(list, i)
                }
                i++
        }
        fmt.Println(list[len(list)-k])
}

Measured memory_bytes: 512
// Problem : C - Candles
// Contest : AtCoder - AtCoder Beginner Contest 107
// URL : https://atcoder.jp/contests/abc107/tasks/arc101_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

	
/*⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⣠⣶⡾⠏⠉⠙⠳⢦⡀⠀⠀⠀
⠀⠀⠀⣴⠿⠏⠀⠀⠀⠀⠀⠀⢳⡀⠀
⠀⠀⢠⣟⣋⡀⢀⣀⣀⡀⠀⣀⡀⣧⠀
⠀⠀⢸⣯⡭⠁⠸⣛⣟⠆⡴⣻⡲⣿⠀
⠀⠀⣟⣿⡭⠀⠀⠀⠀⠀⢱⠀⠀⣿⠀
⠀⠀⠙⢿⣯⠄⠀⠀⠀⢀⡀⠀⠀⡿⠀⠀
⠀⠀⠀⠀⠹⣶⠆⠀⠀⠀⠀⠀⡴⠃⠀⠀
⠀⠀⠀⠀⠀⢸⣷⡦⢤⡤⢤⣞⣁⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⢀⣤⣴⣿⣏⠁⠀⠀⠸⣏⢯⣷⣖⣦⡀⠀⠀⠀⠀⠀⠀
⢀⣾⣽⣿⣿⣿⣿⠛⢲⣶⣾⢉⡷⣿⣿⠵⣿⠀⠀⠀⠀⠀⠀
⣼⣿⠍⠉⣿⡭⠉⠙⢺⣇⣼⡏⠀⠀⠀⣄⢸⠀⠀⠀⠀⠀⠀
⣿⣿⣧⣀⣿.........⣀⣰⣏⣘⣆⣀⠀
*/
#include <bits/stdc++.h> 
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
#define l00p(i, a, b) for (int i=a; i<(b); i++)
#define loop(i, a) for (int i=0; i<(a); i++)
#define rep1(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rep(i,a) for (int i = (a)-1; i >= 0; i--)
#define trav(a,x) for (auto& a : x)
#define uid(a, b) uniform_int_distribution<int>(a, b)(rng)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define ins insert
#define imax INT_MAX
#define imin INT_MIN
//#define MOD 998244353
 
template<class T> bool ckmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

 
const int MOD = 1000000007;
const char nl = '\n';
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
int main() { 
	ios_base::sync_with_stdio(0); cin.tie(0);
	int n,k;
	cin>>n>>k;
	vi a(n);
	loop(i,n)
	cin>>a[i];
	sort(all(a));
	int l=0;
	int r=k-1;
	int val=imax,ans=imax;
//	cout<<a[l]<<" "<<a[r]<<nl;

	while(r<n&&l<n-k+1)
	{
		val=min(abs(a[l])+abs(a[r]-a[l]),abs(a[r])+abs(a[r]-a[l]));
		ans=min(val,ans);
		r++;
		l++;	
	//	cout<<a[l]<<" "<<a[r]<<nl;
	}
	cout<<ans<<nl;
	return 0;
}
// read the question correctly (ll vs int)
// template by bqi343}

Measured memory_bytes: 3740
import sys
input = sys.stdin.readline
from fractions import gcd

Q = int(input())
Query = [list(map(int, input().split())) for _ in range(Q)]

def solve(A, B, C, D):
    if A < B or D < B:
        return False
    if C < B-1:
        if D%B != 0:
            cycle = gcd(D, B)
            if C < B-cycle:
                return False
            if A%cycle < (C+1)%cycle:
                return True
            else:
                return False
        else:
            if A%B <= C:
                return True
            else:
                return False
    else:
        return True

for A, B, C, D in Query:
    ans = "Yes" if solve(A, B, C, D) else "No"
    print(ans)

Measured memory_bytes: 5596
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>

#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e10

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 long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef std::pair<ll, ll> P;

using namespace std;

bool pairCompare(const P& f, const P& s){
    return f.first < s.first;
}

int main()
{
    string s;
    cin >> s;
    ll z = 0;
    ll o = 0;
    rep(i, s.size()){
        if(s[i] == '0') z++;
        if(s[i] == '1') o++;
    }
    ll m =  min(z, o) * 2;
    cout << m;

}

Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int n;
    scanf("%d", &n);
    int s[1000];
    for(int i=0;i<n;i++){
        scanf("%d", &s[i]);
    }
    for(int i=0;i<n;i++){
        if(s[i]%2==0){
            if(s[i]%3==0||s[i]%5==0){
            }else{
                printf("DENIED\n");
                return 0;
            }
        }
    }
    printf("APPROVED\n");
    return 0;
}

Measured memory_bytes: 128
#include <cmath>
#include <cstdio>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
 
using namespace std;
 
const int N = 4e7 + 10; 
 
typedef  long long ll;
 
 
 
int main(){
    int n , m;
    string k,a,b;
    cin>>a>>b;
    cin>>n>>m;
    cin>>k;
    if (k == a){
        printf("%d %d\n",n - 1,m);
    }
    else{
        printf("%d %d\n",n,m-1);
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
int main(){
  int n;
  cin>>n;
  long long a;
  int ind=0;
  bool flag=false;
  REP(i,n){
    cin>>a;
    if(a%2==1){
      ind--;
    }else if(a%4==0){
      ind++;
    }else{
      flag=true;
      continue;
    }
  }
  
  if(!flag){
    if(ind>=-1){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }else{
    if(ind>=0){
      cout<<"Yes"<<endl;
    }else{
      cout<<"No"<<endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
/*  -*- coding: utf-8 -*-
 *
 * d.cc: D: Flipping Signs
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

const int MAX_N = 100000;
const long long LINF = 1LL << 62;

/* typedef */

typedef long long ll;

/* global variables */

int as[MAX_N];
ll dp[MAX_N + 1][2];

/* subroutines */

inline void setmax(ll &a, ll b) { if (a < b) a = b; }

/* main */

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++) scanf("%d", as + i);

  for (int i = 0; i < n; i++) dp[i][0] = dp[i][1] = -LINF;
  dp[0][0] = 0;

  for (int i = 0; i < n; i++)
    for (int j = 0; j < 2; j++)
      for (int k = 0; k < 2; k++)
	setmax(dp[i + 1][k], dp[i][j] + ((j ^ k) ? -as[i] : as[i]));

  printf("%lld\n", dp[n][0]);
  return 0;
}


Measured memory_bytes: 2176
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    d = collections.defaultdict(int)
    for i in range(N):
        s = S()
        d[s] += 1
    for s in ['AC', 'WA', 'TLE', 'RE']:
        print('{} x {}'.format(s, d[s]))


main()



Measured memory_bytes: 80036
#include <stdio.h>

int main() {

  int x, y, r, temp;

  scanf("%d%d", &x, &y);
  
  if(x < y){
    temp = x;
    x = y;
    y = temp;
  }

  while(y>0){
    r = x%y;
    x = y;
    y = r;
  }

  printf("%d\n", x);
  
  return 0;
}

Measured memory_bytes: 592
N = int(input())
import math

n = math.sqrt(N)
if n.is_integer():
  x = round(n) - 1
  print(2 * x)
else:
  def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
      if n % i == 0:
        divisors.append(i)
        if i != n // i:
          divisors.append(n // i)
    divisors.sort()
    return divisors
  l = make_divisors(N)
  if len(l) % 2 == 0:
    x = l[len(l) // 2 - 1]
    y = l[len(l) // 2]
    print(x + y - 2)

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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;

int main() {
    stack<int> st;
    string s;

    while (cin >> s) {
        if (s == "+") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b + a);
        } else if (s == "-") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b - a);
        } else if (s == "*") {
            int a = st.top(); st.pop();
            int b = st.top(); st.pop();
            st.push(b * a);
        } else {
            st.push(stoi(s));
        }
    }
    cout << st.top() << endl;

    return 0;
}


Measured memory_bytes: 3220
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n) FOR(i,0,n)
#define repr(i,n) for(int i=(n)-1;0<=i;--i)
#define each(e,v) for(auto&& e:(v))
#define all(v) begin(v),end(v)
#define DUMP(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG(x) cerr<<#x<<": "<<(x)<<" (L"<<__LINE__<<")"<<endl
using namespace std;
using vint = vector<int>;
using vdouble = vector<double>;
using vstring = vector<string>;
using ll = long long;
template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int main() {
    int a, b; cin >> a >> b;
    cout << ((a + b) % 24) << endl;
    return 0;
}


Measured memory_bytes: 256
import math
n = int(input())

dp = [math.inf] * (n+1)

for i in range(n+1):
    dp[i] = min(dp[i],i)
    j = 6
    while(i+j<=n):
        dp[i+j] = min(dp[i+j],dp[i]+1)
        j *= 6
    j = 9
    while(i+j<=n):
        dp[i+j] = min(dp[i+j],dp[i]+1)
        j *= 9
#print(dp)
print(dp[n])
    

Measured memory_bytes: 9564
N,T = map(int,input().split())

C = []

for _ in range(N):
  c,t = map(int,input().split())
  if t <= T:
    L = [c,t]
    C.append(L)
    
C = sorted(C,key = lambda x:x[0])

if len(C) == 0:
  print("TLE")
else:print(C[0][0])

Measured memory_bytes: 3060
#include<stdio.h>

int main ()
{
    int n,i,j,sum=0;
    scanf("%d", &n);
    int a[n];
    for(i=0;i<n;i++){
        scanf("%d", &a[i]);
    }
    for(i=0;i<n;i++){
        for(j=i+1;j<n;j++){
            sum=sum+(a[i]*a[j]);
        }

    }
    printf("%d", sum);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
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; }

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

    int n,m;cin>>n>>m;
    int a[m],b[m];
    rep(i,m){
        cin>>a[i]>>b[i];
        a[i]--,b[i]--;
    }
    vector<vector<int>> v(n);
    vector<bool> check(n);
    vector<int> dis(n);
    vector<int> ans;
    int len=INF;
    //省く辺
    for(int ed=0;ed<m;ed++){
        rep(i,n){
            v[i].clear();
            dis[i]=0;
            check[i]=false;
        }
        rep(i,m){
            if(ed==i) continue;
            v[a[i]].push_back(b[i]);
        }
        queue<int> q;
        q.push(b[ed]);
        check[b[ed]]=true;
        vector<int> prev(n,-1);
        while(!q.empty()){
           int x=q.front();
           q.pop();
           for(auto y:v[x])if(!check[y]){
               check[y]=true;
               dis[y]=dis[x]+1;
               prev[y]=x;
               q.push(y);
           }
        }
        if(!check[a[ed]]) continue;

        if(chmin(len,dis[a[ed]]+1)){
            ans.clear();
            int x=a[ed];
            ans.push_back(x);
            while(x!=b[ed]){
                x=prev[x];
                ans.push_back(x);
            }
        }
    }
    if(ans.empty()){
        cout<<-1<<endl;
        return 0;
    }
    cout<<0<<endl;
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define fo(a,b,c) for (a=b; a<=c; a++)
#define fd(a,b,c) for (a=b; a>=c; a--)
#define ll long long
//#define file
using namespace std;

struct type{
	int a[100001];
} a,b,A,B,c,I;
int n,m,i,j,k,l;

type turn(type a,type b)
{
	static type c;
	int i;
	fo(i,1,n) c.a[i]=b.a[a.a[i]];
	return c;
}
type ny(type a)
{
	static type c;
	int i;
	fo(i,1,n) c.a[a.a[i]]=i;
	return c;
}
type qpower(type a,int b)
{
	static type ans;
	ans=I;
	while (b)
	{
		if (b&1) ans=turn(ans,a);
		a=turn(a,a),b>>=1;
	}
	return ans;
}
type js1(int t)
{
	type ans=qpower(turn(turn(turn(B,a),b),A),t/4);
	if (t%4>=1) ans=turn(ans,B);
	if (t%4>=2) ans=turn(ans,a);
	if (t%4>=3) ans=turn(ans,b);
	return ans;
}
type js2(int t)
{
	type ans=I;;
	if (t%4>=3) ans=turn(ans,B);
	if (t%4>=2) ans=turn(ans,A);
	if (t%4>=1) ans=turn(ans,b);
	return turn(ans,qpower(turn(turn(turn(a,B),A),b),t/4));
}

int main()
{
	#ifdef file
	freopen("agc031d.in","r",stdin);
	#endif
	
	scanf("%d%d",&n,&m);
	fo(i,1,n) scanf("%d",&a.a[i]),I.a[i]=i;
	fo(i,1,n) scanf("%d",&b.a[i]);
	
	if (m<=6)
	{
		fo(i,1,m-1)
		{
			A=ny(a);
			c=turn(A,b);
			a=b,b=c;
		}
		fo(i,1,n) printf("%d ",a.a[i]);
	}
	else
	{
		A=ny(a),B=ny(b),l=(m-1)/6;
		switch (m%6)
		{
			case 1:{j=l*4-1;k=l*4;break;}
			case 2:{j=l*4;k=l*4+1;break;}
			case 3:{j=l*4;k=l*4+2;break;}
			case 4:{j=l*4+1;k=l*4+2;break;}
			case 5:{j=l*4+2;k=l*4+3;break;}
			case 0:{j=l*4+2;k=l*4+4;break;}
		}
		c=turn(js1(j),js2(k));
		fo(i,1,n) printf("%d ",c.a[i]);
	}
	printf("\n");
	
	fclose(stdin);
	fclose(stdout);
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> d(n);
  rep(i,n) cin >> d[i];
  int now = -999;
  rep(i,n){
    if(now<=d[i]-1){
      now = d[i]-1;
    }else if(now==d[i]){
      now = d[i];
    }else{
      puts("No");
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 768
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
using namespace std;

#define MAXN 1005
#define MAXM 200005

int n,m,u,v;
int id[MAXN][MAXN],d[MAXN][MAXN],d2[MAXN][MAXN],q[MAXN][2];
int ans[MAXM];
vector<int> a[MAXN];

void dfs(int x,int fa)
{
    d[fa][x]=1;
    for(int i=0;i<(int)a[x].size();i++)
        if(d[fa][a[x][i]]==0)
            dfs(a[x][i],fa);
}

void dfs1(int x,int f,int flag)
{
    q[x][flag]=f;
    for(int i=0;i<(int)a[x].size();i++)
        if(!q[a[x][i]][flag])
            dfs1(a[x][i],f,flag);
}

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        scanf("%d%d",&u,&v);
        id[u][v]=i;
        a[u].push_back(v);
    }
    for(int i=1;i<=n;i++)
        dfs(i,i);
    for(int i=1;i<=n;i++)
    {
        memset(q,0,sizeof q);
        q[i][0]=q[i][1]=-1;
        for(int j=0;j<(int)a[i].size();j++)
            if(!q[a[i][j]][0])
                dfs1(a[i][j],j+1,0);
        for(int j=a[i].size()-1;j>=0;j--)
            if(!q[a[i][j]][1])
                dfs1(a[i][j],j+1,1);
        for(int j=0;j<(int)a[i].size();j++)
            if(q[a[i][j]][0]!=j+1||q[a[i][j]][1]!=j+1)
                d2[i][a[i][j]]=1;
    }
    for(int i=1;i<=n;i++)
        for(int j=1;j<=n;j++)
            if(d[j][i]==d2[i][j]&&id[i][j])
                ans[id[i][j]]=1;
    for(int i=1;i<=m;i++)
    {
        if(ans[i]==1)
            printf("same\n");
        else
            printf("diff\n");
    }
}


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

int main() {
    int N, X, Y;
    cin >> N >> X >> Y;
    vector<int> count(N);
    for (int i = 1; i < N + 1; i++) {
        for (int j = i + 1; j < N + 1; j++) {
            int dist = min(j - i, abs(Y - j) + abs(X - i) + 1);
            count[dist]++;
        }
    }
    for (int i = 1; i < N; i++) {
        cout << count[i] << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

//{{{ Fast IO
const int __SIZE = 1 << 18;
char ibuf[__SIZE], *iS, *iT;

#define ge (iS == iT ? (iT = (iS = ibuf) + fread(ibuf, 1, __SIZE, stdin), (iS == iT ? EOF : *iS++)) : *iS++)
#define ri read_int()
#define rl read_ll()
#define FILE(s) freopen(s"in", "r", stdin), freopen(s"out", "w", stdout)

template<typename T>
inline void read(T &x) {
	char ch, t = 0; x = 0;
	while(!isdigit(ch = ge)) t |= ch == '-';
	while(isdigit(ch)) x = x * 10 + (ch ^ 48), ch = ge;
	x = t ? -x : x;
}
inline int read_int() { int x; return read(x), x; }
inline ll read_ll() { ll x; return read(x), x; }

template<typename T> inline void chkmin(T&a, T b) { a = a < b ? a : b; }
template<typename T> inline void chkmax(T&a, T b) { a = a > b ? a : b; }
//}}}

const int MAXN = 200010;

int n;

vector<pair<int, int> >E;

struct Graph {
	int S;
	int tot;
	int fi[MAXN];
	int dep[MAXN];
	int fa[MAXN][20];
	int ne[MAXN << 1];
	int to[MAXN << 1];

	inline void Link(int u, int v) {
		tot++;
		to[tot] = v;
		ne[tot] = fi[u];
		fi[u] = tot;
	}

	inline void dfs(int x, int la) {
		fa[x][0] = la, dep[x] = dep[la] + 1;
		for(int i = 1; i < 20; i++) fa[x][i] = fa[fa[x][i - 1]][i - 1];
		for(int i = fi[x]; i; i = ne[i]) {
			int u = to[i];
			if(u == la) continue;
			dfs(u, x);
		}
	}

	inline int LCA(int x, int y) {
		if(dep[x] < dep[y]) swap(x, y);
		int k = dep[x] - dep[y];
		for(int i = 0; i < 20; i++)
		 	if(k & (1 << i)) x = fa[x][i];
		if(x == y) return x;
		for(int i = 19; ~i; --i)
			if(fa[x][i] != fa[y][i])
				x = fa[x][i], y = fa[y][i];
		return fa[x][0];
	}

	inline int dis(int u, int v) { return dep[u] + dep[v] - dep[LCA(u, v)] * 2; }
	inline int dis_S(int x) { return dep[x] - 1; }

	inline void AddEdge(int ty = 0) {
		for(int i = 1; i < n; i++) {
			int u = ri, v = ri;
			Link(u, v), Link(v, u);
			if(ty) E.push_back(make_pair(u, v));
		} dfs(S, S);
	}
}A, B;

int chk[MAXN];
int vis[MAXN];

int main() {
#ifdef LOCAL
	FILE("");
#endif

	n = ri, A.S = ri, B.S = ri;
	A.AddEdge(1), B.AddEdge();
	for(auto e : E) {
		int u = e.first, v = e.second;
		if(B.dis(u, v) > 2) {
			if(A.dep[u] < B.dep[u]) chk[u] = 1;
			if(A.dep[v] < B.dep[v]) chk[v] = 1;
		}
	} int res = B.dep[A.S] - 1;
	queue<int>q;
	q.push(A.S), vis[A.S] = 1;
	while(!q.empty()) {
		int x = q.front(); q.pop();
		for(int i = A.fi[x]; i; i = A.ne[i]) {
			int u = A.to[i];
			if(vis[u] || A.dep[u] >= B.dep[u]) continue;
			if(chk[u]) return puts("-1"), 0;
			vis[u] = 1;
			chkmax(res, B.dep[u] - 1);
			q.push(u);
		}
	}
	cout << res * 2 << endl;
	return 0;
}

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


int main () {

 int N,tmp=0;
 cin >> N;
 int T[N];
 for(int i = 0; i < N; i++) {
  cin >> T[i];
  tmp += T[i];
 }
 int M;
 cin >> M;
 int P[M],X[M];
 for(int i = 0; i < M; i++) {
  cin >> P[i] >> X[i];
  int ans = tmp;
  ans -= T[P[i]-1] - X[i];
  cout << ans << endl;
 }

 return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
using ll = long long;
const int INF = 2147483647;
const ll MOD = 1000000007;
// const ll INF = 1000000000000000000LL;

int f(int n){
    int ans = 1;
    vector<int> x(n + 1);
	int num = n; // 素因数分解する変数num 
    for (int i = 2; i <= n; i++) {
		while (num%i == 0) { // 素数で割り切れなくなるまで割っていく
			x.at(i)++;//割った個数を配列に足す
			num /= i;
		}
	}

	for (int i = 2; i <= n; i++)
	{	
		ans *= x.at(i) + 1;//それぞれを+1して掛けていく
	}
    return ans;
}

int main(){
    int n;
    cin >> n;
	vector<ll> table(n+1);
    table[1]=1;
    for(int i=2;i<=n;i++)
        table[i]=2;
    //1とその数は除く
    for(int i=2;i<=n/2;i++){
        for(int j=i;j<=n;j+=i){
            if(i!=j)
                table[j]++;
        }
    }
    ll ans=0;
    for(ll i=1;i<=n;i++){
        ans+=table[i]*i;
    }
    cout << ans << endl;
	return 0;
}

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

using namespace std;
using ll = long long;

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

    if (a.size() > b.size()) {
        cout << "GREATER" << endl;
        exit(EXIT_SUCCESS);
    } else if (a.size() < b.size()) {
        cout << "LESS" << endl;
        exit(EXIT_SUCCESS);
    }
    
    // asize == bsize
    for (int i = 0; i < a.size(); ++i) {
        if (a.at(i) == b.at(i)) continue;
        if (a.at(i) > b.at(i)) {
            cout << "GREATER" << endl;
            exit(EXIT_SUCCESS);
        }
        if (a.at(i) < b.at(i)) {
            cout << "LESS" << endl;
            exit(EXIT_SUCCESS);
        }
    }
    
    cout << "EQUAL" << endl;
  
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a,b,c;
    1<=a,b,c<=13;
    scanf("%d %d %d",&a,&b,&c);
    if(a+b+c>=22)
        printf("bust\n",a,b,c);
    else
        printf("win\n",a,b,c);
    return 0;

}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
 		Scanner sc = new Scanner(System.in);

    int a=sc.nextInt();
    int b=sc.nextInt();
    int c=sc.nextInt();

    if(a==b){
      System.out.println(c);
    }else if(a==c){
      System.out.println(b);
    }else{
      System.out.println(a);
    }

	}
}


Measured memory_bytes: 21972
import Data.List
main = do
  s <- getLine 
  let [r,c] = map (read::(String->Int)) . words $ s
  ss <-getContents
  let v = map (map read . words) . lines $ ss :: [[Int]]
  mapM_ putStrLn (map (intercalate " " . map show) $ calc v)

calc :: [[Int]] -> [[Int]]
calc v = (zipWith (++) v (transpose [hsum])) ++ [(vsum ++ [sum vsum])]
  where hsum = map sum v
        vsum = map sum $ transpose v

Measured memory_bytes: 5444
#include <iostream>
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>

using namespace std;
#define REP(i,n) FOR(i,0,n)
#define FOR(i,a,b) for(long long i=(a),i##Len_=(b);i<i##Len_;i++)
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;



int main()
{
    ll N,A,B,res;

    cin >> N >> A >> B;

    res = B;

    if(B > N*A)
    {
        res = N*A;
    }


    cout << res << endl;

}



Measured memory_bytes: 764
import math
S = int(input())
a,b,c,d = 0,0,0,0
a = 10**9
d = math.ceil(S//a)+1
if S == 10**18:
    d = 10**9
c = (a*d)-S
b = 1
if S == 10**18:
    c,d = 0,10**9
print(0,0,a,b,c,d)

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

#define INF 999999999
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(v) v.begin(), v.end()
#define pub push_back
#define pob pop_back
#ifdef LOCAL
  #define de(e) cout << "L" << __LINE__ << ": " << e << "\n" // debug echo
  #define dr(e) cout << "L" << __LINE__ << ": " << #e << " -> " << e << "\n" // debug repr
#else
  #define de(e)
  #define dr(e)
#endif
#define out(fmt, ...) printf(fmt, __VA_ARGS__); printf("\n")
int gcd(int m, int n) { if((0 == m) || (0 == n)){return 0;} while(m != n){ if(m > n){m -= n;}else{n -= m;} } return m; }
int lcm(int m, int n) { if((0 == m) || (0 == n)){return 0;} return (m / gcd(m, n)) * n; }

//
// Implementation
//

int main() {
  int A, B; cin >> A >> B;
  string s; cin >> s;
  for (int i = 0; i < A; i++) {
    if (!('0' <= s[i] && s[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (s[A] != '-') {
    cout << "No" << endl;
    return 0;
  }
  for (int i = A+1; i < A+1+B; i++) {
    if (!('0' <= s[i] && s[i] <= '9')) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      mut s: chars,
      mut t: chars,
    }
    s.sort();
    t.sort();
    let ms = s[0].clone();
    for i in 0..t.len() {
        if ms < t[i] {
            return println!("{}", "Yes");
        }
    }
    if s == t {
        return println!("{}", "No");
    }

    use std::collections::HashMap;
    let mut map = HashMap::new();
    for i in 0..t.len() {
        *map.entry(t[i]).or_insert(0) += 1;
    }
    for i in 0..s.len() {
        let e = map.entry(s[i]).or_insert(0);
        if *e == 0 {
            return println!("{}", "No");
        }
        *e-=1;
    }
    println!("{}", "Yes");
}


Measured memory_bytes: 4352
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <limits.h>
#include <cmath>
#include <map>
#define rep(i,n) for(int i=0;i<(int)n;i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;
int main(){
    int n;
    cin>>n;
    vector<int> u(n-1),v(n-1);
    rep(i,n-1){
        cin>>u[i]>>v[i];
        if(u[i]>v[i])swap(u[i],v[i]);
        u[i]--;
        v[i]--;
    }
    vector<ll> cnt(n+1,0);
    rep(i,n-1){
        cnt[0]+=n-v[i];
        cnt[u[i]+1]-=n-v[i];
    }
    for(int i=1;i<n;i++){
        cnt[i]=cnt[i-1]+cnt[i];
    }
    for(int i=1;i<n;i++){
        cnt[i]=cnt[i-1]+cnt[i];
    }
    ll all=0;
    for(int i=1;i<=n;i++){
        all+=(ll)(n-i+1)*i;
    }
    cout<<all-cnt[n-1]<<endl;
}



Measured memory_bytes: 6296
#include <bits/stdc++.h>
using namespace std;
#define ios ios_base::sync_with_stdio(false);cin.tie(0);
#define setnow clock_t tStart;
#define setTime tStart = clock();
#define time0 (double)(clock() - tStart)/CLOCKS_PER_SEC
#define setin(x) ifstream cin(x);
#define setout(x) ofstream cout(x);
#define NMAX 30
typedef long long ll;
typedef long long int lli;
typedef pair < int, int> dbl;
const int maxInt = 1e9*2;
const lli maxLong = 1e18*2;
int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if(a+b == c+d)
        return cout << "Balanced", 0;
    if(a+b > c+d)
        return cout << "Left", 0;
    if(a+b < c+d)
        return cout << "Right", 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
int main() {
	long long a[1000],n;
	a[0] = 2;
	a[1] = 1;
	cin >> n;
	for (int i = 2; i <=n; i++) {
		a[i] = a[i - 1] + a[i - 2];
	}
	cout << a[n] << endl;
	int x;
	cin >> x;
	return 0;
}

Measured memory_bytes: 256
val P = 1000000007L

val POW10S = listOf(1, 10, 100, 1000, 10000, 100000, 1000000, 10000000, 100000000, 1000000000)

data class FiniteField(val x: Long) {
  operator fun plus(o: FiniteField) = FiniteField((x + o.x) % P)
  operator fun plus(o: Int) = this + FiniteField(o.toLong())
  operator fun minus(o: FiniteField) = FiniteField((x + P - o.x) % P)
  operator fun minus(o: Int) = this - FiniteField(o.toLong())
  operator fun times(o: FiniteField) = FiniteField((x * o.x) % P)
}

fun pow10(p: Int): FiniteField {
  if (p == 0) return FiniteField(1)
  if (p % 2 == 1) {
    val x = pow10(p / 2)
    return x * x * FiniteField(10)
  } else {
    val x = pow10(p / 2)
    return x * x
  }
}

fun isValid(l: Int, s: Int): Boolean {
  var r = s
  var b = l
  for (d in 1..9) {
    if (b < POW10S[d]) {
      val count = POW10S[d] - b
      if (r <= count * d) {
        return r % d == 0
      } else {
        b = POW10S[d]
        r -= count * d
      }
    }
  }
  throw RuntimeException()
}

fun main(args: Array<String>) {
  val s = readLine()!!.toInt()

  // l in [1, 10 ^ 7) (d <= 7)
  val lowCount = (1..9999999).count { isValid(it, s) }
  var ans = FiniteField(lowCount.toLong())

  // l in [10 ^ 7, +inf) (d >= 8)
  for (d in 8..s) {
    if (s % d == 0) {
      val x0 = s / d
      // d-digits only
      ans += (pow10(d) - pow10(d - 1) - x0 + 1)
      // d-digits and (d + 1)-digits
      ans += x0 / (d + 1) - (if (x0 % (d + 1) == 0) 1 else 0)
    } else {
      val xm = s / d
      val r = s % d
      val x0 = xm - r
      if (x0 <= 0) continue
      ans += 1
      ans += x0 / (d + 1) - (if (x0 % (d + 1) == 0) 1 else 0)
    }
  }

  println(ans.x)
}


Measured memory_bytes: 41372
import java.util.*;

public class Main{

    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);

        int N = sc.nextInt();
        int L = sc.nextInt();
        int[] a = new int[N];
        int[] s = new int[N];
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
            if(i == 0)
                s[i] = a[i];
            else
                s[i] = s[i-1] + a[i];
        }
        sc.close();

        int last = 0;

        for(int i = 0; i < N-1; i++){
            if(a[i]+a[i+1] >= L){
                last = i+1;
                break;
            } else {
                if(i == N-2){
                    System.out.println("Impossible");
                    return;
                }
            }
        }
        System.out.println("Possible");
        for(int i = 1; i < last; i++){
            System.out.println(i);
        }
        for(int i = N-1; i >= last+1; i--){
            System.out.println(i);
        }
        System.out.println(last);
    }
}

Measured memory_bytes: 63520
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vl = vector<long>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvb = vector<vector<bool>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
using pll = pair<long, long>;
#define fix20 cout << fixed << setprecision(20);
#define YES cout << "Yes" << endl;
#define NO cout << "No" << endl;
#define rep(i,n) for(int i=0; i<(int)(n);i++)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define MOD 1000000007
#define all(vec) vec.begin(), vec.end()

int main(){
    int n,x,y;
    cin >> n >> x >> y;
    x--;y--;
    vector<int> ans(n,0);
    rep(i,n){
        for(int j=i+1;j<n;j++){
            int d1 = abs(i-x) + 1 + abs(j-y);
            int d2 = abs(i-y) + 1 + abs(j-x);
            int d3 = abs(i-j);
            int d = min(d1,min(d2,d3));
            ans.at(d)++;
        }
    }
    for(int i=1;i<n;i++){
        cout << ans.at(i) << endl;
    }
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void Main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];
    vector<ll> dp(K + 1, false);
    rep(i, K + 1) {
        rep(j, N) {
            ll a = A[j];
            if (i - a >= 0) {
                dp[i] |= !dp[i - a];
            }
        }
    }
    if (dp[K]) {
        cout << "First" << '\n';
    } else {
        cout << "Second" << '\n';
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

template <class T>
void debug(T& v)
{
    for(auto& x: v) cout << x << " ";
    cout << endl;
}

// ax + by = d
template <class T>
T ext_gcd(T a, T b, T& x, T& y)
{
    if(b == 0){
        x = 1; y = 0; return a;
    }
    T d = ext_gcd(b, a%b, x, y);
    T x_ = x;
    x = y;
    y = x_ - a/b * y;
    return d;
}

int main()
{
    ll N, P;
    cin >> N >> P;
    string S0;
    cin >> S0;
    vector<ll> S(N);
    for(int i=0; i<N; i++) S[i] = S0[i] - '0';

    if(P == 2){
        ll ans = 0;
        for(int i=0; i<N; i++){
            if(S[i]%2==0) ans += i+1;
        }
        cout << ans << endl;
        return 0;
    }
    if(P == 5){
        ll ans = 0;
        for(int i=0; i<N; i++){
            if(S[i]%5==0) ans += i+1;
        }
        cout << ans << endl;
        return 0;
    }
    vector<ll> ten(N+1), invten(N+1);
    ten[0] = 1;
    for(int i=0; i<N; i++){
        ten[i+1] = (ten[i] * 10) % P;
    }

    vector<ll> r(N+1);
    for(int i=0; i<N; i++){
        r[i+1] = r[i] + S[N-1-i] * ten[i];
        r[i+1] %= P;
    }

    vector<ll> v(P);
    for(int i=0; i<=N; i++) v[r[i]]++;
    ll ans = 0;
    for(int i=0; i<P; i++) ans += v[i] * (v[i]-1) / 2;

    cout << ans << endl;
}

Measured memory_bytes: 6788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;

char returnc(char c){
  if('a'<=c && c<='z'){
    if(c=='z')return 'a';
    return ++c;
  }
  return c;
}
int main(void){
  string s;
  int n;
  vector<string> ss;
  vector<vector<int> > nn;
  while(cin>>s>>n){
    if(ss.empty()){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
      continue;
    }
    bool ok = true;
    for(int i = 0 ; i < ss.size() ; i ++){
      if(ss[i] == s){
	nn[i].push_back(n);
	ok = false;
      }
    }
    if(ok){
      ss.push_back(s);
      nn.push_back(vector<int>(1,n));
      
    }
  }
  
  for(int i = ss.size() - 1 ; i >= 0 ; i --){
    for(int j = 0 ; j < i ; j ++){
      if(ss[i] < ss[j]){
	string w = ss[i];
	ss[i] = ss[j];
	ss[j] = w;
	vector<int> ws = nn[i];
	nn[i] = nn[j];
	nn[j] = ws;
      }
    }
  }
  for(int i = 0 ; i < ss.size() ; i ++){
    cout<<ss[i]<<endl;
    sort(nn[i].begin(),nn[i].end());
    for(int j = 0 ; j < nn[i].size()-1 ; j ++){
      cout<<nn[i][j]<<" ";
    }
    cout<<nn[i][nn[i].size() - 1 ]<<endl;
  }
}

Measured memory_bytes: 1244
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

vector<int> tree(1<<24,0);
vector<int> good_ball(1<<19,-1);
vector<int> c(1<<19);
vector<vector<int>> q(1<<19);
int head,N,Q;

void add(int i,int n){
  i=i+head;
  while(i>0){
    tree.at(i)+=n;
    i=i/2;
  }
}

int query(int a,int b,int k,int l,int r){
  if(a<=(l+1)&&r<=b){
    return tree.at(k);
  }else{
    int m=(l+r)/2;
    int ans=0;
    if(a<=m){
      ans+=query(a,b,k*2,l,m);
    }
    if(m<b){
      ans+=query(a,b,k*2+1,m,r);
    }
    return ans;
  }
}

int main(){
  
  cin >> N >> Q;
  for(int i=0;i<N;i++){
    cin >> c.at(i);
  }
  for(int i=0;i<Q;i++){
    int l,r;
    cin >> l >> r;
    q.at(i)={i,l,r,0};
  }
  auto comp0 = [](auto &v1,auto &v2){
    return v1.at(0)<v2.at(0);
  };
  auto comp2 = [](auto &v1,auto &v2){
    return v1.at(2)<v2.at(2);
  };
  sort(&q[0],&q[Q],comp2);
  q.at(Q)={Q,N+1,N+1,0};
  /* Qの中身確認
  for(int i=0;i<=Q;i++){
    for(int j=0;j<4;j++){
      cout << q.at(i).at(j) << " ";
    }
    cout << endl;
  }
  */
  
  head=1;
  for(int i=0;i<N;i++){
    if(N<=head){
      break;
    }
    head=(head<<1);
  }
  
  int j=0;
  for(int i=0;i<N;i++){
    if(good_ball.at(c.at(i))!=-1){
      add(good_ball.at(c.at(i)),-1);
    }
    good_ball.at(c.at(i))=i;
    add(i,1);
    /* 毎回木を出力
    for(int k=0;k<2*N;k++){
      cout << tree.at(k) << " ";
    }
    cout << endl;
    */
    while(q.at(j).at(2)<=(i+1)){
      if(q.at(j).at(2)==(i+1)){
        int a,b;
        a=q.at(j).at(1);
        b=q.at(j).at(2);
        q.at(j).at(3)=query(a,b,1,0,head);
      }
      j++;
    }
  }
  sort(&q[0],&q[Q],comp0);
  for(int i=0;i<Q;i++){
    cout << q.at(i).at(3) << endl;
  }
}


Measured memory_bytes: 101504
#include<bits/stdc++.h>
#define pb           push_back
#define pf           push_front
#define in           insert
#define ff           first
#define ss           second
#define mp           make_pair
#define int          long long
#define uint         unsigned long long
#define rep(i,x,m)   for(int i=x;i<m;i++)
#define repr(i,x,m)  for(int i=x;i>=m;i--)
#define MOD          1000000007
#define endl         "\n"
#define all(v)       v.begin(),v.end()
#define rall(v)      v.rbegin(),v.rend()
#define vi           vector<int>
#define vs           vector<string>
#define pi           pair<int,int>
#define di           deque<int>
#define sz(x)       (int)x.size()
#define pq           priority_queue<int>
#define pqs          priority_queue<int,vi,greater<int> >
#define fix(y)       fixed<<setprecision(y)
#define print(v)     for(int i=0;i<v.size();i++) cout<<v[i]<<" ";cout<<endl
#define noob         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int fac[2000005]={0};
void factorial(){ fac[0]=1; fac[1]=1; for(int i=2;i<200005;i++) fac[i]=((i%MOD)*(fac[i-1]%MOD))%MOD;}
int power(int n,int m)
{int p=1;if(m==0)return 1;p=(power(n,m/2)%MOD);p=(p%MOD*p%MOD)%MOD;
return(m&1?((p%MOD*n%MOD)%MOD):(p%MOD));}
int ncr(int n,int r){return ((fac[n]*power(fac[r],MOD-2))%MOD*power(fac[n-r],MOD-2))%MOD;}

void ram5564()
{
    int n;
    cin>>n;
    map<int,int>m1;
    int sum=0;
    rep(i,0,n)
    {
        int x;
        cin>>x;
        m1[x]++;
        sum+=x;
    }
    int q;
    cin>>q;
   // cout<<sum<<endl;
    while(q--)
    {
      int x,y;
      cin>>x>>y;
      if(m1[x]>0)
      {
        sum-=(m1[x]*x);
        //cout<<sum<<endl;
        int cnt=m1[x];
        m1.erase(x);
        m1[y]+=cnt;
        sum+=(y*cnt);
        //cout<<sum<<endl;

      }
      // for(auto x:m1)
      // {
      //   cout<<x.ff<<"::"<<x.ss<<endl;
      // }
      
      cout<<sum<<endl;
     // cout<<endl;

    }
}

signed main()
{
        noob
        // #ifndef ONLINE_JUDGE
        //  freopen("input.txt","r",stdin);
        //  freopen("output.txt","w",stdout);
        //  #endif   
        
        int t=1;
        //cin>>t;
        while(t--)
        ram5564();
        return 0;
}

Measured memory_bytes: 7816
#include<stdio.h>
#include<stdlib.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
int MOD;

//辺の情報を個別に持つタイプ
typedef struct edge{ll s,g,c;}E;
typedef struct graph{
	int vcnt,ecnt;
	E  e[200010];//適宜変える(ecnt)
	int inv[200010];//逆辺のindex(ecnt)
	int id[100010];//適宜変える(vcnt)
}G;
G g;

int esort(const void*a,const void*b){
	E*p=(E*)a,*q=(E*)b;
	if((*p).s<(*q).s)return -1;
	if((*p).s>(*q).s)return  1;
	if((*p).g<(*q).g)return -1;
	return 1;
}
void makeinvedge();
void readgraph(){
	//適宜変える
	ll n;
	scanf("%lld%d",&n,&MOD);
	rep(i,0,n-1){
		ll x,y;
		scanf("%lld%lld",&x,&y);
		x--,y--;
		g.e[i].s=x;
		g.e[i].g=y;
	}
	g.vcnt=n;
	g.ecnt=n-1;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵
}

void makeinvedge(){
	//逆辺とidx
	int added=0;
	rep(i,0,g.ecnt){
		int l=0,r=g.ecnt;
		while(r-l>1){
			int m=(l+r)/2;
			if(g.e[m].s<g.e[i].g||(g.e[m].s==g.e[i].g&&g.e[m].g<=g.e[i].s))l=m;
			else r=m;
		}
		if(g.e[l].s!=g.e[i].g||g.e[l].g!=g.e[i].s){
			g.e[g.ecnt+added].s=g.e[i].g;
			g.e[g.ecnt+added].g=g.e[i].s;
			g.e[g.ecnt+added].c=0;
			added++;
		}
	}
	g.ecnt+=added;
	qsort(g.e,g.ecnt,sizeof(E),esort);

	int p=0;
	rep(i,0,g.vcnt){
		while(p<g.ecnt&&g.e[p].s<i)p++;
		g.id[i]=p;
	}
	g.id[g.vcnt]=g.ecnt;//番兵

	rep(i,0,g.ecnt){
		int l=0,r=g.ecnt;
		while(r-l>1){
			int m=(l+r)/2;
			if(g.e[m].s<g.e[i].g||(g.e[m].s==g.e[i].g&&g.e[m].g<=g.e[i].s))l=m;
			else r=m;
		}
		g.inv[i]=l;
	}
}

//†全方位木DP†
//*
typedef struct rerooting_atai{ll a;}atai;
atai dpv[200010];//頂点に対する答え
atai dpe[400010];//辺に対する答え
atai cum[2][400010];//累積和
atai munit={1};//単位元
atai init={-1};
int isinit(atai x){return x.a==init.a;}
atai fold_e(atai x,atai y){
	atai ret;
	ret.a=x.a*y.a%MOD;
	return ret;
}
atai add_v(atai x,int v){return x;}
atai add_e(atai x,int e){x.a++;return x;}

void rrinit(){
	makeinvedge();
	rep(i,0,g.vcnt)dpv[i].a=-1;
	rep(i,0,g.ecnt)dpe[i].a=-1;
}
atai dfs_e(int);
atai dfs_v(int v){
	if(!isinit(dpv[v]))return dpv[v];
	rep(i,g.id[v],g.id[v+1]){
		if(i==g.id[v])cum[0][i]=munit;
		else cum[0][i]=fold_e(cum[0][i-1],dfs_e(i-1));
	}
	for(int i=g.id[v+1]-1;i>=g.id[v];i--){
		if(i==g.id[v+1]-1)cum[1][i]=munit;
		else cum[1][i]=fold_e(cum[1][i+1],dfs_e(i+1));
	}
	atai ret=munit;
	rep(i,g.id[v],g.id[v+1])ret=fold_e(ret,dfs_e(i));
	ret=add_v(ret,v);
	return dpv[v]=ret;
}
atai dfs_e(int e){
	if(!isinit(dpe[e]))return dpe[e];
	atai ret;
	if(!isinit(dpv[g.e[e].g])){
		ret=fold_e(cum[0][g.inv[e]],cum[1][g.inv[e]]);
	}else{
		ret=munit;
		int v=g.e[e].g;
		rep(i,g.id[v],g.id[v+1])if(g.e[i].g!=g.e[e].s)ret=fold_e(ret,dfs_e(i));
	}
	ret=add_v(ret,g.e[e].g);
	ret=add_e(ret,e);
	return dpe[e]=ret;
}
void rerootingDP(int v,int pre){
	if(pre==-1)rrinit();
	dfs_v(v);
	rep(i,g.id[v],g.id[v+1])if(g.e[i].g!=pre)rerootingDP(g.e[i].g,v);
}
//*/

int main(){
	readgraph();
	rerootingDP(0,-1);
	rep(i,0,g.vcnt)printf("%lld\n",dpv[i].a);
}

Measured memory_bytes: 21492