akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iostream>
#include<vector>
#include<math.h>
#include<queue>
#include<map>
#include<algorithm>
#include<string.h>
#include<functional>
#include<limits.h>
#include<stdlib.h>
#include<cmath>
#include<cstring>
#include<set>
#include<climits>
using namespace std;

#define intmax INT_MAX
#define lmax LONG_MAX
#define uintmax UINT_MAX
#define ulmax ULONG_MAX
#define llmax LLONG_MAX
#define ll long long
#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)
#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)
#define llfor ll i,j
#define sc(a) cin>>a
#define pr(a) cout<<a<<endl
#define pY puts("YES")
#define pN puts("NO")
#define py puts("Yes")
#define pn puts("No")
#define pnn printf("\n")
#define all(a) a.begin(),a.end()
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define size(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*pi*/double pi=acos(-1);
/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}
/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}
/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}
/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}
/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}
/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}
/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}
/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}
/*Fibonacci数列*/ll fib(ll x){ll i,fibo[x+10];fibo[0]=1;fibo[1]=1;fibo[2]=1;rep(i,3,x+1)fibo[i]=fibo[i-1]+fibo[i-2];return fibo[x];}
/*桁数*/ll dig(ll n){ll d=0,i=0;while(n/10>0){i++;d++;}return d;}
llfor;ll ans=0;////////////////////////////////////////////////////////////
int main(){
 ll n,r;
 cin>>n>>r;
 if(n<10)r+=100*(10-n);
 pr(r);
 return 0;}



Measured memory_bytes: 3468
package main

import "fmt"

type DayWeeks []string

func (d DayWeeks) Index(findStr string) int {
	for i, dayWeek := range d {
		if dayWeek == findStr {
			return i
		}
	}
	return -1
}

func main() {
	var input string
	fmt.Scanf("%s", &input)
	d := DayWeeks{"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"}
	fmt.Println(7 - d.Index(input))
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int l = Integer.parseInt(sc.next());

        int sum = 0;
        for (int i = 0; i < n; i++) {
            sum += l + i;
        }

        int res = Integer.MAX_VALUE;
        int v = 0;
        for (int i = 0; i < n; i++) {
            int tmp = sum - (l + i);
            if (res > Math.abs(sum - tmp)) {
                res = Math.abs(sum - tmp);
                v = (l + i);
            }
        }
        System.out.println(sum - v);
    }
}


Measured memory_bytes: 23892
//#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
 
//#include <x86intrin.h>
#include <algorithm>
#include <iostream>
#include <cstring>
#include <string>
#include <bitset> 
#include <vector>
#include <cmath>
#include <deque>     
#include <queue>
#include <iomanip>
#include <stack>
#include <map>
#include <set>
//#include <ordered_set>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
 
//using namespace __gnu_pbds;
using namespace std;
 
//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
     
#define F first
#define S second           
#define lb lower_bound               
#define ub upper_bound
#define pb push_back
#define pf push_front    
#define ppb pop_back
#define mp make_pair                                     
#define bpp __builtin_popcountll                                                                                        
#define sqr(x) ((x) * (x)) 
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define in insert
#define ppf pop_front
#define endl '\n'
//#define int long long
 
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair <int, int> pii;
 
const int mod = (int)1e9 + 7;
const int N = (int)3e5 + 123;
const ll inf = (ll)1e18 + 1;
 
const double pi = acos (-1.0);
const double eps = 1e-9;                  
const int dx[] = {0, 0, 1, 0, -1};
const int dy[] = {0, 1, 0, -1, 0};

int n;
ll a[N], s, x;

inline void boost () {
   ios_base :: sync_with_stdio (0);
   cin.tie (0), cout.tie (0);
}
 
inline void Solve () {
   cin >> n;
   for (int i = 1; i <= n; i ++) cin >> a[i], s += a[i];
   x = max (0ll, s - n * (n - 1));
   ll D = n + 1;
   ll have = x;
   for (int i = 1; i <= n; i ++) {
      a[i] += x;
      ll will = a[i] / D;
      if (have >= will) a[i] -= will * D, have -= will;
      else a[i] -= have * D, have = 0;
   }
   sort (a + 1, a + n + 1);
   while (a[n] >= n) {
      x ++;
      for (int i = 1; i < n; i ++) a[i] ++;
      a[n] -= n;
      sort (a + 1, a + n + 1);
   }
   cout << x;
}               
 
signed main () {                                       
  // #ifdef QWERTY
  //    freopen("input", "r", stdin);
  // #endif
// freopen (".in", "r", stdin);    
// freopen (".out", "w", stdout);              
   boost ();
   int tt = 1;
   //cin >> tt;   
   while (tt --) {
      Solve ();
   }                                               
   return 0;      
}                   

Measured memory_bytes: 3588
import java.util.*;

public class Main {
	public static void main(String args[]){
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		s = s.replaceAll("A", "-");
		s = s.replaceAll("C", "-");
		s = s.replaceAll("T", "-");
		s = s.replaceAll("G", "-");
		if (s.contains("----------")){
			System.out.println(10);
		} else if (s.contains("---------")){
			System.out.println(9);
		} else if (s.contains("--------")){
			System.out.println(8);
		} else if (s.contains("-------")){
			System.out.println(7);
		} else if (s.contains("------")){
			System.out.println(6);
		} else if (s.contains("-----")){
			System.out.println(5);
		} else if (s.contains("----")){
			System.out.println(4);
		} else if (s.contains("---")){
			System.out.println(3);
		} else if (s.contains("--")){
			System.out.println(2);
		} else if (s.contains("-")){
			System.out.println(1);
		} else{
			System.out.println(0);
		}
	}
}

Measured memory_bytes: 22740
#include <iostream>
#include <vector>
#include <array>
#include <list>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <tuple>
#include <memory>
#include <cmath>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <cfloat>
#include <cassert>
#include <random>
int factorial(int n) {
	return n == 0 ? 1 : n * factorial(n - 1);
}
bool operator==(const std::vector<int>& a, const std::vector<int>& b) {
	for (auto i = 0; i < a.size(); ++i) {
		if (a[i] != b[i]) return false;
	}
	return true;
}
int main() {
	int n; std::cin >> n;
	std::vector<int> p(n), q(n), permutation(n); 
	for (auto& pp : p) std::cin >> pp;
	for (auto& qq : q) std::cin >> qq;
	std::iota(permutation.begin(), permutation.end(), 1);
	int p_rank{ -1 }, q_rank{ -1 };
	for (auto i = factorial(n); i > 0; --i) {
		if (permutation == p) {
			p_rank = i;
		}
		if (permutation == q) {
			q_rank = i;
		}
		std::next_permutation(permutation.begin(), permutation.end());
	}
	std::cout << std::abs(p_rank - q_rank) << std::endl;
}

Measured memory_bytes: 888
void main() {
	auto ip = readAs!(int[]), A = ip[0], B = ip[1];
	auto S = rs;
	bool ok = true;
	if(S[A] != '-') ok = false;
	if(!S[0..A].isNumeric) ok = false;
	if(!S[A+1..$].isNumeric) ok = false;
	(ok ? "Yes" : "No").writeln;
 }

// ===================================

import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.range;
import std.traits;
import std.math;
import std.bigint;
import std.numeric;
import std.conv;
import std.typecons;
import std.uni;
import std.ascii;
import std.bitmanip;
import core.bitop;

T readAs(T)() if (isBasicType!T) {
	return readln.chomp.to!T;
}
T readAs(T)() if (isArray!T) {
	return readln.split.to!T;
}

T[][] readMatrix(T)(uint height, uint width) if (!isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		res[i] = readAs!(T[]);
	}
	return res;
}

T[][] readMatrix(T)(uint height, uint width) if (isSomeChar!T) {
	auto res = new T[][](height, width);
	foreach(i; 0..height) {
		auto s = rs;
		foreach(j; 0..width) res[i][j] = s[j].to!T;
	}
	return res;
}

int ri() {
	return readAs!int;
}

double rd() {
	return readAs!double;
}

string rs() {
	return readln.chomp;
}


Measured memory_bytes: 256
/*
	Author: Ritik Patel
*/


//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& STL DEBUGGER &&&&&&&&&&&&&&&&&&&&&&&&&&&

// #define _GLIBCXX_DEBUG       // Iterator safety; out-of-bounds access for Containers, etc.
// #pragma GCC optimize "trapv" // abort() on (signed) integer overflow.

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& LIBRARIES &&&&&&&&&&&&&&&&&&&&&&&&&&&

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

/*#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
template<typename T, typename V = __gnu_pbds::null_type>
using ordered_set = __gnu_pbds::tree<T, V, less<T>, __gnu_pbds::rb_tree_tag, __gnu_pbds::tree_order_statistics_node_update>; 
*/
//find_by_order()->returns an iterator to the k-th largest element(0-based indexing)
//order_of_key()->Number of items that are strictly smaller than our item

//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEFINES &&&&&&&&&&&&&&&&&&&&&&&&&&&

#define int long long int
#define all(i) i.begin(), i.end()
#define sz(a) (int)a.size()
 
// #define ld long double
// const ld PI  = 3.141592;
const int dx4[4] = {0, 1, 0, -1};
const int dy4[4] = {-1, 0, 1, 0};
const int dx8[8] = {-1, -1, -1, 0, 1, 1, 1, 0};
const int dy8[8] = {-1, 0, 1, 1, 1, 0, -1, -1};
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& DEBUG &&&&&&&&&&&&&&&&&&&&&&&&&&&
 
#define XOX
vector<string> vec_splitter(string s) {
    for(char& c: s) c = c == ','?  ' ': c;
    stringstream ss; ss << s;
    vector<string> res;
    for(string z; ss >> z; res.push_back(z));
    return res;
}
 
void debug_out(vector<string> __attribute__ ((unused)) args, __attribute__ ((unused)) int idx) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, Head H, Tail... T) {
    if(idx > 0) cerr << ", ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, T...);
}
 
#ifdef XOX
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __VA_ARGS__)
#else
#define debug(...) 42
#endif
 
 
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&& CODE &&&&&&&&&&&&&&&&&&&&&&&&&&&

int cnt[4];

int id(string s){
    if(s == "AC") return 0;
    else if(s == "WA") return 1;
    else if(s == "TLE") return 2;
    else return 3;
}

void solve(){
    int N; cin >> N;
    for(int i = 0; i < N; ++i){
        string s; cin >> s;
        cnt[id(s)]++;
    }
    string ans[4] = {"AC", "WA", "TLE", "RE"};
    for(int i = 0; i < 4; ++i){
        cout << ans[i] << " x " << cnt[i] << '\n'; 
    }
}



int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    int T = 1; 
    // cin >> T;
    for(int i = 1; i <= T; ++i){
        // brute();
        solve();
    }
    return 0;
}

/*
Sample inp
*/

Measured memory_bytes: 3656
function Main(input) {
    input = input.trim().split("\n").map(function(x) { return x.split(" ")});    
	var ABCD = input[0][0].split("").map(e => parseInt(e, 10));
	var ops = tryAndError(ABCD);
	v_ans = [ABCD[0],ops[0],ABCD[1],ops[1],ABCD[2],ops[2],ABCD[3],"=7"];
	console.log(v_ans.join(""));
}

function tryAndError(ABCD){
	if (ABCD[0] + ABCD[1] + ABCD[2] + ABCD[3] === 7) return(["+","+","+"]);
	if (ABCD[0] + ABCD[1] + ABCD[2] - ABCD[3] === 7) return(["+","+","-"]);
	if (ABCD[0] + ABCD[1] - ABCD[2] + ABCD[3] === 7) return(["+","-","+"]);
	if (ABCD[0] + ABCD[1] - ABCD[2] - ABCD[3] === 7) return(["+","-","-"]);
	if (ABCD[0] - ABCD[1] + ABCD[2] + ABCD[3] === 7) return(["-","+","+"]);
	if (ABCD[0] - ABCD[1] + ABCD[2] - ABCD[3] === 7) return(["-","+","-"]);
	if (ABCD[0] - ABCD[1] - ABCD[2] + ABCD[3] === 7) return(["-","-","+"]);
	if (ABCD[0] - ABCD[1] - ABCD[2] - ABCD[3] === 7) return(["-","-","-"]);
}


Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29572
/*2019/07/29 */
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
typedef long long int ll;
void llswap(ll *x,ll *y){ll temp;temp=*x;*x=*y;*y=temp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){return *(int*)a-*(int*)b;}
int desc(const void *a,const void *b){return *(int*)b-*(int*)a;}
int lldesc(const void *a,const void *b){return *(ll*)b-*(ll*)a;}
int casc(const void *a,const void *b){return (int)(*(char*)a-*(char*)b);}
int compare_char(const void* left, const void* right) {
    char *left_char = (char *)left;
    char *right_char = (char *)right;

    return strcmp( left_char, right_char );
}
/*
int asc_t(const void *a,const void *b){return ((user_t*)a)->score - ((user_t*)b)->score;}
int desc_t(const void *a,const void *b){return ((user_t*)b)->score - ((user_t*)a)->score;}
*/

int main(){
    int n;
    static char str[200000][20];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s",str[i]);
        qsort(str[i],10,sizeof(char),casc);
    }
    qsort(str,n,sizeof(str[0]),compare_char);

    ll cnt=0,x=0,tmp;
    for(int i=1;i<n;i++){
        tmp=1;
        if(!strcmp(str[i-1],str[i])){
            x++;
        }else{
            if(x>0){
                for(ll i=x+1;i>=x;i--){
                    tmp*=i;
                }
                cnt+=tmp/2;
                x=0;
            }
            x=0;
        }
    }
    if(x>0){
        tmp=1;
        for(ll i=x+1;i>=x;i--){
            tmp*=i;
        }
        cnt+=tmp/2;
    }
    printf("%lld\n",cnt);
    
    
   
    return 0;
}


Measured memory_bytes: 4092
/*
      @author: Charan Sai
*/
#include <bits/stdc++.h>
using namespace std;

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

int n, k;
const int MAX_N = 102, MAX_K = 1e5 + 2;
const int mod = 1e9 + 7;
int arr[MAX_N];
int dp[MAX_N][MAX_K];
int s[MAX_N][MAX_K];
// O(N*K*K) time = O(NK^2) time
// O(NK) space
int Top_Down(int i = n, int candies = k) {
    // Base Case
    if(i == 0) return (candies == 0);
    if(dp[i][candies] != -1) return dp[i][candies]%mod;
    // Choice
    int ways = 0;
    for(int x = 0; x <= arr[i]; ++x) {
        if(candies >= x)
            ways += (Top_Down(i - 1, candies - x)%mod);
    }
    return (dp[i][candies]=ways%mod);
}

int Bottom_Up() {
    // Base
    dp[0][0] = 1;
    for(int j = 1; j <= k; ++j) dp[0][j] = 0;
    for(int i = 1; i <= n; ++i) dp[i][0] = 1;
    // Choice
        
    for(int i = 1; i <= n; ++i) {
        for(int candies = 1; candies <= k; ++candies) {
            int ways = 0;
            for(int x = 0; x <= arr[i]; ++x) {
                if(candies >= x)
                ways += dp[i-1][candies-x]%mod;
            }
            dp[i][candies]=ways%mod;
        }
    }
    return dp[n][k];
}

/*
dp[0][0] = 1;
for(int j = 1; j <= k; ++j) dp[0][j] = 0;
for(int i = 1; i <= n; ++i) dp[i][0] = 1;

for(i = 1; i <= n; ++i)
{
    s[i-1][0] = dp[i-1][0];
    for(int j = 1; j <= k; ++j) {
        //compute s[i][j]
        s[i-1][j] = (dp[i-1][j] + s[i-1][j-1])%mod;
    }

    for(int j = 1; j <= k; ++j) {
       //compute dp[i][j]
       dp[i][j] = s[i-1][j]
       if(j-arr[i]-1 >= 0)
        dp[i][j] = (dp[i][j] - s[i-1][j-arr[i]-1] + mod)%mod;
    }
}
s(i,j) = T(i,0) + T(i,1) + ..... + T(i,j)
T(i,j) = s(i-1,j) - s(i-1,j-a[i]-1)

*/

int Bottom_Up2() {
    dp[0][0] = 1;
    for(int j = 1; j <= k; ++j) dp[0][j] = 0;
    for(int i = 1; i <= n; ++i) dp[i][0] = 1;
    int i, j;
    for(i = 1; i <= n; ++i)
    {
        s[i-1][0] = dp[i-1][0];
        for(j = 1; j <= k; ++j) {
            //compute s[i][j]
            s[i-1][j] = (dp[i-1][j] + s[i-1][j-1])%mod;
        }

        for(j = 1; j <= k; ++j) {
           //compute dp[i][j]
           dp[i][j] = s[i-1][j];
           if(j-arr[i]-1 >= 0)
            dp[i][j] = (dp[i][j] - s[i-1][j-arr[i]-1] + mod)%mod;
        }
    }
    return dp[n][k]%mod;
}

int32_t main() {
    IOS;
    int t=1; 
  	//cin >> t;
    while(t--) {
        memset(dp, -1, sizeof(dp));
        cin >> n >> k;
        for(int i = 1; i <= n; ++i) cin >> arr[i];
        cout << Bottom_Up2()%mod << endl;
    }
}

Measured memory_bytes: 159744
#include<bits/stdc++.h>
using namespace std;
const int N=1e6+5,P=998244353,Gi=332748118;
 
#define PII pair<int,int>
inline int add(const int &x,const int &y){return x+y>P?x+y-P:x+y;}
inline int dec(const int &x,const int &y){return x-y<0?x-y+P:x-y;}
inline int mul(const int &x,const int &y){return 1LL*x*y>P?1LL*x*y%P:x*y;}
 
int ksm(int x,int y=P-2){
    int ans=1;
    for(;y;y>>=1,x=mul(x,x))
        if(y&1)ans=mul(ans,x);
    return ans;
}
 
int lim,r[N],a[N],b[N],o[N],l;
int n,h[N],m,p[N],ans,fac[N],inv[N];
vector<int>f[N];
void init(int len){
    lim=1,l=-1;
    while(lim<=len)lim<<=1,++l;
    for(int i=1;i<lim;i++)r[i]=(r[i>>1]>>1)|((i&1)<<l);
}
void NTT(int *A,int ty){
    for(int i=0;i<lim;i++)
        if(i<r[i])swap(A[i],A[r[i]]);
    for(int p=1;p<lim;p<<=1){
        int D=p<<1,wn=ksm(ty==1?3:Gi,(P-1)/D);
        o[0]=1;
        for(int i=1;i<p;i++)o[i]=mul(o[i-1],wn);
        for(int i=0;i<lim;i+=D){
            for(int j=0;j<p;j++){
                int x=A[i+j],y=mul(A[i+j+p],o[j]);
                A[i+j]=add(x,y),A[i+j+p]=dec(x,y);
            }
        }
    }
    if(ty==-1)
        for(int i=0,INV__=ksm(lim);i<lim;i++)
            A[i]=mul(A[i],INV__);
}
int C(int x,int y){
	return mul(fac[y],mul(inv[x],inv[y-x]));
}
int A(int x,int y){
	return mul(fac[y],inv[y-x]);
}
priority_queue<PII,vector<PII>,greater<PII> >Q;
signed main(){
    scanf("%d",&n),n*=2;
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    sort(h+1,h+1+n);
    for(int i=1;i<=n;i++){
    	if(h[i]!=h[i-1])p[++m]=1;
    	else p[m]++;
	}
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=mul(fac[i-1],i);
	inv[n]=ksm(fac[n]);
	for(int i=n-1;~i;i--)inv[i]=mul(inv[i+1],i+1);
    for(int i=1;i<=m;i++){
    	for(int j=0;j<=(p[i]>>1);j++){
    		f[i].push_back(mul(mul(A(j,p[i]),C(j,p[i]-j)),ksm(ksm(2,j))));
		}
		Q.push(PII(f[i].size(),i));
	}
	while(Q.size()>1){
		int u=Q.top().second;
		Q.pop();
		int v=Q.top().second;
		Q.pop(); 
		int su=f[u].size(),sv=f[v].size();
		init(su+sv-2);
		for(int i=0;i<=lim;++i) a[i]=b[i]=0;
		for(int i=0;i<su;++i) a[i]=f[u][i];
		for(int i=0;i<sv;++i) b[i]=f[v][i];
		NTT(a,1),NTT(b,1);
		for(int i=0;i<lim;i++) a[i]=mul(a[i],b[i]);
		NTT(a,-1);
		++m;
		if(!Q.size()){
			for(int i=0;i<=su+sv-2;++i){
				ans=add(ans,mul(mul(ksm(P-1,i),a[i]),mul(A((n-2*i)>>1,n-2*i),ksm(ksm(2,(n-2*i)>>1)))))%P;
			}
			break;
		}
		for(int i=0;i<=su+sv-2;++i) f[m].push_back(a[i]);
		Q.push(PII(f[m].size(),m));
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 35316
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include<algorithm>
#include<string>
#include <map>
#include <queue>
#include <stack>
#include<set>
#include<math.h>

#define DIV 1000000007
using namespace std;
using ll = long long;

bool cmp(const pair<ll, ll>& p, const pair<ll, ll>& q) {
	if (p.second != q.second)
		return p.second > q.second;
	else
		return p.first > q.first;
}

int main(void) {
	ll N, M;
	cin >> N >> M;

	vector<pair<ll, ll>> job(N);
	for (int i = 0; i < N; i++) {
		cin >> job[i].first >> job[i].second;
	}

	sort(job.begin(), job.end(), cmp);
	
	set<int> day;
	for (int i = 0; i <= M; i++)
		day.insert(i);

	ll ans = 0;
	for (int i = 0; !day.empty() && i < N; i++) {
		auto it = day.lower_bound(job[i].first);
		if (it != day.end()) {
			ans += job[i].second;
			day.erase(*it);
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mo = 998244353;
const int N = 105;
string init;
int n;
unordered_map<string, int> f;

ll fet(string a) {
	if (a.size() == 0) return 1;
	if (a.size() == 1) return 1 + a[0] - '0';
	if (f.count(a)) return f[a];
	ll ret = 0;
	ret = (1 + a[0] - '0') * fet(string(a.begin() + 1, a.end()));
	for(int p = 1; p * 2 <= a.length(); p++) {
		string nx = string(p, '1');
		for(int i = p - 1; i < a.length(); i += p) {
			for(int j = i - p + 1, cs = 0; j <= i; j++, cs++) {
				nx[cs] = ((nx[cs] - '0') & (a[j] - '0')) + '0';
			}
			if (i > p - 1)
				ret = (ret + fet(nx) * fet(string(a.begin() + i + 1, a.end()))) % mo;;
		}
	}
	return f[a] = ret % mo;
}

int main() {
	cin >> init;
	cout << fet(init) << endl;
}


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

int main(){
  while(true){
    int n, m, t, p;
    cin >> n >> m >> t >> p;

    if(n==0 && m==0 && t==0 && p==0){
      break;
    }

    int Ori[64][64] = {{0}};
    for(int y=0; y<m; y++){
      for(int x=0; x<n; x++){
        Ori[y][x] = 1;
      }
    }

    for(int i=0; i<t; i++){
      int d, c;
      cin >> d >> c;

      if(d==1){
        for(int x=0; x<c; x++){
          for(int y=0; y<m; y++){
            Ori[y][2*c-1-x] += Ori[y][x];
            Ori[y][x] = 0;
          }
        }

          for(int x=0; x<n; x++){
            for(int y=0; y<m; y++){
              Ori[y][x] = Ori[y][x+c];
              Ori[y][x+c] = 0;
            }
          }
       }
       else{
         for(int y=0; y<c; y++){
           for(int x=0; x<n; x++){
             Ori[2*c-1-y][x] += Ori[y][x];
             Ori[y][x] = 0;
           }
         }

           for(int y=0; y<m; y++){
             for(int x=0; x<n; x++){
               Ori[y][x] = Ori[y+c][x];
               Ori[y+c][x] = 0;
             }
           }
       }
     }
     for(int i=0; i<p; i++){
       int x, y;
       cin >> x >> y;

       cout << Ori[y][x] << endl;
     }
    }
    return 0;
}



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

// #include "cxx-prettyprint/prettyprint.hpp" // vecの内容をきれいに表示

using namespace std;
typedef long long ll;

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

#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define INF ((1LL<<62)-(1LL<<31)) /*オーバーフローしない程度に大きい数*/
#define MOD 1000000007

int main(){
// ここに処理を記述

	// 入力受け取り
	int N;
	cin >> N;

	vector< vector<int> > val;
	int temp1, temp2, temp3;
	val.push_back({0, 0, 0}); // 1-indexed
	for(int i=0; i<N; i++){
		cin >> temp1 >> temp2 >> temp3;
		val.push_back({temp1, temp2, temp3}); // val[i][0] = a[0]
	}

	// dpテーブル : 
	vector< vector<int> > dp(N+1, vector<int>(3, 0));
	FOR(i,1,N+1){
		REP(j,3){
			REP(k,3){
				if(j!=k) dp[i][j] = max(dp[i][j], dp[i-1][k] + val[i][j]);
			}
		}
	}

	// cout << val << "\n";

	int ans = max(dp[N][0], max(dp[N][1], dp[N][2]));

	cout << ans << "\n";

return 0;
}

Measured memory_bytes: 11184
#include <iostream>

using namespace std;

int field[5][5];
int largest[5][5];

bool fill(int sy, int sx, int gy, int gx) {
    bool ret = true;
    for (int i = sy; i <= gy; i++) {
        for (int j = sx; j <= gx; j++) {
            if (field[i][j] == 0) {
                ret = false;
                break;
            }
        }
    }
    return ret;
}

int main() {
    int n;
    cin >> n;
    while (n--) {
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                cin >> field[i][j];
            }
        }
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
                int max_rectangle = 0;
                for (int k = i; k < 5; k++) {
                    for (int l = j; l < 5; l++) {
                        if (fill(i, j, k, l)) {
                            int count = (k-i+1)*(l-j+1); 
                            if (max_rectangle < count) {
                                max_rectangle = count;
                            }
                        }
                    }
                }
                largest[i][j] = max_rectangle;
            }
        }
        int max_rectangle = 0;
        for (int i = 0; i < 5; i++) {
            for (int j = 0; j < 5; j++) {
//                cout << largest[i][j] << ' ';
                if (max_rectangle < largest[i][j]) {
                    max_rectangle = largest[i][j];
                }
            }
//            cout << endl;
        }

        cout << max_rectangle << endl;

    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int x;
  cin >> x;
  if(x == 0)
    cout << 0 << endl;
  else if(x%3 == 0)
    cout << 3 << endl;
  else
    cout << x%3 << endl;
}


Measured memory_bytes: 256
using System;
using System.Diagnostics;
using System.IO;
using System.Text;
using System.Linq;
using System.Collections.Generic;
using System.Text.RegularExpressions;

class Program
{
    const string Yes = "Yes";
    const string No = "No";
    const char White = '.';
    const char Black = '#';
    const long Mod = 1000000007;

    static void Main(string[] args) {
#if DEBUG
        MyDebugger.Test(process, "../TextFile1.txt");
#else
        object ret = process(new StreamReader(Console.OpenStandardInput()));
        Console.WriteLine(ret);
#endif
    }

    static object process(TextReader input) {
        var n = int.Parse(input.ReadLine());
        var ary = ToIntArray(input.ReadLine(), n);

        int count = n;

        var dic = new DefaultDectionary<int, int>(0);
        foreach(var x in ary) {
            dic[x] += 1;
        }

        int pairs = 0;
        foreach(var x in dic.Keys.ToArray()) {
            while(dic[x] >= 3) {
                count -= 2;
                dic[x] -= 2;
            }

            if(dic[x] == 2) pairs++;
        }

        if(pairs % 2 == 0) {
            return count-pairs;
        } else {
            return count-pairs-1;
        }
    }

    class DefaultDectionary<Tkey, TValue> : Dictionary<Tkey, TValue>
    {
        TValue DefaultValue;
        public DefaultDectionary(TValue defaultvalue) {
            this.DefaultValue = defaultvalue;
        }
        public new TValue this[Tkey key] {
            get {
                if (this.ContainsKey(key)) return base[key];
                else return DefaultValue;
            }
            set {
                base[key] = value;
            }
        }
    }

    static int[] ToIntArray(string strs, int n) {
        var ret = new int[n];
        var spl = strs.Split(' ');
        for (int i = 0; i < n; i++)
            ret[i] = int.Parse(spl[i]);
        return ret;
    }
}


Measured memory_bytes: 23520
#include <iostream>
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <cmath>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
#define drep(i,cc,n) for(int i=cc;i>=n;--i)
typedef long long ll;
using namespace std;

int main(){
    int n;
    cin>>n;
    string s;
    s = to_string(n);
    rep(i,0,2){
        if(s[i]=='7'){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3696
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>

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

typedef int long long ll;
using namespace std;
typedef pair<int, int> P;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
const ll MOD = 1e9 + 7;
static const int MAX = 100;
static const int INF = (1 << 23);

int main() {
    
    int n;
    while(true){
        cin>>n;
        if(n==0)break;
        vector<set<int>> v(n);
        rep(i,n){
            int a;cin>>a;
            rep(j,a){
                int b;cin>>b;
                v[i].insert(b);
            }
        }
        int ansc=0,ans=0;
        int ksize;cin>>ksize;
        vector<int> k(ksize);
        rep(i,ksize)cin>>k[i];
        rep(i,n) {
            bool f = true;
            rep(j, ksize) {
                if (v[i].find(k[j]) == v[i].end()) {
                    f = false;
                    break;
                }
            }
            if (f) {
                ans = i + 1;
                ansc++;
            }
        }
        if(ansc==1){
        cout<<ans<<endl;
        }else{
            cout<<-1<<endl;
        }
        
        
        
    }

    return 0;
}



Measured memory_bytes: 3512
#include <cstdio>

int r, g, b;

int f(int i, int n) {
  int t = 0;
  switch (i) {
    case 0: 
      while (n >= 0) {
        t += f(i + 1, n);
        n -= r;
      }
      return t;
      break;
    case 1: 
      while (n >= 0) {
        t += f(i + 1, n);
        n -= g;
      }
      return t;
      break;
    case 2:
      return n % b == 0;
      break;
  }
}

int main() {
  int N;

  scanf("%d %d %d %d", &r, &g, &b, &N);
  
  printf("%d\n", f(0, N));
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long ll;
typedef long double ld;
#define INF (1LL<<60)
#define MOD1 1000000007
/*swap 交換*/
void swap(ll *a, ll *b){ll c;c=*b;*b=*a;*a=c;}
/*2つのうち大きい数を返す*/
ll max2(ll a,ll b){return a>=b?a:b;}
/*2つのうち小さい数を返す*/
ll min2(ll a,ll b){return a>=b?b:a;}
/*絶対値*/
ll ABS(ll a){return a>=0?a:(-a);}
typedef struct{
    ll aa;
    ll bb;
}frequent;
// 小大
int compare(const void *a, const void *b){return *(ll *)a - *(ll *)b;}

int main(void){
    ll n,i,ans=1;
    scanf("%lld",&n);
    char s[n+5];
    scanf("%s",s);
    ll letter[26];
    for(i=0;i<26;i++){
        letter[i]=0;
    }
    // ll a;
    for(i=0;i<n;i++){
        // a = (ll)s[i];
        letter[(ll)s[i] -97]++;
    }
    for(i=0;i<26;i++){
        ans*=letter[i]+1;
        ans%=MOD1;
    }
    printf("%lld\n",ans-1);
    return 0;
}


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

using namespace std;

#define REP(i, n) for(int i = 0; i < (n); i++)
#define SORT(v, n) sort(v, v+n);
#define SSORT(v, n) sort(v, v+n, greater<int>())

int main(){
	int n;
	cin >> n;
	if(n>999) cout << "ABD" << endl;
	else cout << "ABC" << endl;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
void swap(int& a, int& b){
int temp = a;
a = b;
b = temp;
}
 
int main(){
int a,b,c;
cin >> a >> b >> c;
 
if (a>b) swap(a,b);
if (b>c) swap(b,c);
if (a>b) swap(a,b);
 
cout << a << " " << b << " " << c << endl;
 
return 0;
}

Measured memory_bytes: 3096
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func main() {
	sc.Split(bufio.ScanWords)
	l := nextInt()
	r := nextInt()
	if r-l < 2019 {
		l = l % 2019
		r = r % 2019
	} else {
		l = l % 2019
		r = 2019
	}

	num1 := 2019

	for i := l; i < r; i++ {
		for j := i + 1; j < r+1; j++ {
			if i*j%2019 < num1 {
				num1 = i * j % 2019
			}
		}
	}

	fmt.Println(num1)
}


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

typedef long long int ll;
typedef long double ld;

#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define pll pair<ll,ll>
#define MP make_pair
#define ff first
#define ss second
#define PB push_back
#define mod 1000000007
#define lp(i,start,end) for(ll i=start;i<=end;i++) 
#define deb1(a) cout<<#a<<" = "<<(a)<<endl;
#define deb2(a,b) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<endl;
#define deb3(a,b,c) cout<<#a<<" = "<<(a)<<", "<<#b<<" = "<<(b)<<", "<<#c<<" = "<<(c)<<endl;


ll modu(ll a, ll b)
{
	ll ans =1;
	while(b>0)
	{
		if(b&1)
		ans = (ans*a)%mod;
		b/=2;
		a = (a*a)%mod;
	}
	return ans;
}

int main()
{
	fastio
	ll h,w;
	cin>>h>>w;
	ll dp[h+1][w+1]={0};
	dp[1][1]=1;
	char grid[h+1][w+1];
	lp(i,1,h)
		lp(j,1,w){
			cin>>grid[i][j];
		}
	lp(i,1,h)
		lp(j,1,w){
			if(grid[i][j]=='.'){
				if(i>1)
					dp[i][j]+=dp[i-1][j];
				if(j>1)
					dp[i][j]+=dp[i][j-1];
				dp[i][j]=dp[i][j]%mod;
				}	
		}
	cout<<dp[h][w]<<endl;

	return 0;	
}


Measured memory_bytes: 12392
#include<iostream>
#include <string>
using namespace std;
int main()
{
	string s;
	cin >> s;
	bool a = false;
	bool b = false;
	bool c = false;
	if (s.find("a") != std::string::npos) {
		a = true;
	}
	if (s.find("b") != std::string::npos) {
		b = true;
	}
	if (s.find("c") != std::string::npos) {
		c = true;
	}
	if (a && b && c){
		cout << "Yes" << endl;
	}
	else{
		cout << "No" << endl;
	}
}

Measured memory_bytes: 256
s = input()
result = True

while 0 < len(s):
  if s[-5:] == "dream" or s[-5:] == "erase":
      s = s[:-5]
  elif s[-6:] == "eraser":
      s = s[:-6]
  elif s[-7:] == "dreamer":
      s = s[:-7]
  else:
      result = False
      break

print("YES" if result else "NO")

Measured memory_bytes: 3188
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<algorithm>
#include<deque>
#include<queue>
#include<set>
#include<map>
#include<functional>

using namespace std;
#define LL long long
#define LLBIG 1999999999999999999
#define INTBIG 1111111111
#define MOD 1000000007
#define PI pair<int,int>
#define VI vector<int>
#define VVI vector<vector<int>>

int a, b, c;

int main() {
	cin >> a >> b >> c;
	bool t = false;
	if (a == b && b == c)t = true;
	cout << (t ? "Yes" : "No") << endl;

	return 0;
}


Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>

// 内部定数
#define D_VAL_MAX		3500									// 最大値

// 内部変数
static FILE *szpFpI;											// 入力
static long long slN;
static long long slh, sln, slw;

// 内部変数 - テスト用
#ifdef D_TEST
	static int siRes;
	static FILE *szpFpA;
#endif

// 算出
int
fCalc(
)
{
	// w = Nhn / 4hn-Nn-Nh
	for (slh = 1; slh <= D_VAL_MAX; slh++) {
		for (sln = 1; sln <= D_VAL_MAX; sln++) {
			long long llVal1 = slN * slh * sln;
			long long llVal2 = 4 * slh * sln - slN * sln - slN * slh;
			if (llVal2 > 0) {
				if (llVal1 % llVal2 == 0) {
					slw = llVal1 / llVal2;
					return 0;
				}
			}
		}
	}

	return 0;
}

// 実行メイン
int
fMain(
	int piTNo					// <I> テスト番号 1～
)
{
	char lc1Buf[1024], lc1Out[1024];

	// 入力 - セット
#ifdef D_TEST
	sprintf(lc1Buf, ".\\Test\\T%d.txt", piTNo);
	szpFpI = fopen(lc1Buf, "r");
	sprintf(lc1Buf, ".\\Test\\A%d.txt", piTNo);
	szpFpA = fopen(lc1Buf, "r");
	siRes = 0;
#else
	szpFpI = stdin;
#endif

	// N - 取得
	fgets(lc1Buf, sizeof(lc1Buf), szpFpI);
	sscanf(lc1Buf, "%lld", &slN);

	// 算出
	fCalc();
	
	// 結果 - セット
	sprintf(lc1Out, "%lld %lld %lld\n", slh, sln, slw);

	// 結果 - 表示
#ifdef D_TEST
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, lc1Out)) {
		siRes = -1;
	}
#else
	printf("%s", lc1Out);
#endif

	// 残データ有無
#ifdef D_TEST
	lc1Buf[0] = '\0';
	fgets(lc1Buf, sizeof(lc1Buf), szpFpA);
	if (strcmp(lc1Buf, "")) {
		siRes = -1;
	}
#endif

	// テストファイルクローズ
#ifdef D_TEST
	fclose(szpFpI);
	fclose(szpFpA);
#endif

	// テスト結果
#ifdef D_TEST
	if (siRes == 0) {
		printf("OK %d\n", piTNo);
	}
	else {
		printf("NG %d\n", piTNo);
	}
#endif

	return 0;
}

int
main()
{

#ifdef D_TEST
	int i;
	for (i = D_TEST_SNO; i <= D_TEST_ENO; i++) {
		fMain(i);
	}
#else
	fMain(0);
#endif

	return 0;
}



Measured memory_bytes: 128
def solve(s):
    n = len(s)

    if n == 1:
        return 1
    if n == 2:
        return 2 if s[0] == s[1] else 1

    ci = n // 2
    c = s[ci]
    if n & 1:
        for di in range(1, ci + 1):
            if c == s[ci - di] == s[ci + di]:
                pass
            else:
                return ci + di
        return n
    if c != s[ci - 1]:
        return ci
    for di in range(1, ci):
        if c == s[ci - di - 1] == s[ci + di]:
            pass
        else:
            return ci + di
    return n


print(solve(input()))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define print(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<_<<", "; cerr<<"]"<<endl; }
#define printpair(v) { cerr<<#v<<": [ "; for(auto _ : v) cerr<<"{"<<_.first<<","<<_.second<<"}"<<", "; cerr<<"]"<<endl; }
#define dump(x) cerr<<#x<<": "<<x<<endl;
#define bit(k) (1LL<<(k))
#define Yes "Yes"
#define No "No"
#define YES "YES"
#define NO "NO"
typedef long long ll;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

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

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = (ll)1e9+7;
const double PI = acos(-1.0);
/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    ll K,N;
    cin >> K >> N;
    vector<ll> A(N);
    ll maxx = 0;
    rep(i,N){
        cin>>A[i];
    }
    A.push_back(K);
    rep(i,N-1){
        chmax(maxx, A[i+1] - A[i]);
    }
    chmax(maxx, K - A[N-1] + A[0]);
    cout << K - maxx << endl;
}

Measured memory_bytes: 4736
import sys
input = sys.stdin.readline
from collections import defaultdict,deque
from itertools import combinations
from heapq import heappush, heappop

xs,ys,xt,yt = map(int,input().split())
N = int(input())
xyr = [list(map(int,input().split())) for i in range(N)]

#import random
#N = 1000
#xs,ys = (-10**9,-10**9)
#xt,yt = (10**9, 10**9)
#xyr = [[random.randint(-10**9, 10**9),random.randint(-10**9, 10**9),random.randint(1,10)] for i in range(N)]
#xyr = [[2*i,2*i,1] for i in range(N)]

xyr = [[xs,ys,0]] + xyr + [[xt,yt,0]]

cost = {}
for s in range(0,N+1):
    for t in range(s+1,N+2):
        x1,y1,r1 = xyr[s]
        x2,y2,r2 = xyr[t]
        R = pow((x2-x1)**2+(y2-y1)**2,0.5)
        c = max(0, R-r1-r2)
        cost[(s,t)] = c
        cost[(t,s)] = c

h = [(0,0)]
dist = [10**15] * (N+2)
dist[0] = 0
while h:
    d,v = heappop(h)
    if dist[v] < d:
        continue
    for nv in range(N+2):
        if v == nv:
            continue
        temp = d + cost[(v,nv)]
        if temp < dist[nv]:
            dist[nv] = temp
            heappush(h, (temp,nv))

print(dist[N+1])








Measured memory_bytes: 229732
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3,Ofast,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("avx,avx2,sse")
using namespace std;

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

    int n;
    cin >> n;
    map<int, int> kek;
    int tot = 0;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        kek[x]++;
        tot += x;
    }
    int q;
    cin >> q;
    for (int i = 0; i < q; i++) {
        int b, c;
        cin >> b >> c;
        tot -= b * kek[b];
        tot += c * kek[b];
        kek[c] += kek[b];
        kek[b] = 0;
        cout << tot << '\n';
    }

    fflush(stdout);
    return 0;
}


Measured memory_bytes: 9556
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

int gcd(int a, int b);
ll lcm(int a, int b);

int main(){
    int N, M;
    cin >> N >> M;
    string S, T;
    cin >> S >> T;
    
    ll len = lcm(max(N, M), min(N, M));
    
    vector<ll> s_id, t_id;
    ll n = len / N;
    ll m = len / M;
    for(int i = 0; i < N; ++i){
        s_id.push_back(n * i);      // X中の文字列Sの文字があるindex
    }
    for(int i = 0; i < M; ++i){
        t_id.push_back(m * i);      // X中の文字列Tの文字があるindex
    }
    
    vector<P> temp;
    for(int i = 0; i < N; ++i){
        auto it1 = lower_bound(t_id.begin(), t_id.end(), s_id[i]);
        auto it2 = upper_bound(t_id.begin(), t_id.end(), s_id[i]);
        if(it2 - it1 <= 0)      continue;
        temp.push_back(P(i, it1 - t_id.begin()));
    }
    
    for(int i = 0; i < temp.size(); ++i){
        P p = temp[i];
        if(S[p.first] == T[p.second])       continue;
        
        cout << -1 << endl;
        return 0;
    }
    
    cout << len << endl;
}

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

ll lcm(int a, int b){
    return (ll)a / gcd(a, b) * b;
}

Measured memory_bytes: 2744
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  double a, b, c, d, e, f;
  while (cin >> a >> b >> c >> d >> e >> f) {
    double del = 1.0 / (a * e - b * d);
    double x = (e * c - b * f) * del;
    double y = (-d * c + a * f) * del;
    if (x == -0) x = 0;
    if (y == -0) y = 0;
    printf("%.3f %.3f\n", x, y);
  }
  return 0;
}


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

signed main() {
int x,judge=0;
cin>>x;
while(1){

	for(int i=2;i<x;i++){
		if(x%i==0)judge++;
	}
	if(judge==0)break;
	judge=0;
	x++;
}
cout << x << endl;
	return 0;
}

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())

s = input()

for i in range(b, d):
    if s[i:i+2] == "##":
        print('No')
        exit()
for i in range(a, c):
    if s[i:i+2] == "##":
        print('No')
        exit()
if c < d:
    print('Yes')
else:
    for i in range(b-2, d-1):
        if s[i:i+3] == "...":
            print('Yes')
            exit()
    print('No')


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

int main() {
    int n;
    cin>>n;
    map<string,int> m;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        auto itr=m.find(s);
        if(itr!=m.end())
        {
            (itr->second)++;
        }
        else
        {
            m.insert(make_pair(s,1));
        }
    }
    long int ans=0;
    for(auto itr=m.begin();itr!=m.end();itr++)
    {
        long int x=(itr->second);
        ans+=x*(x-1)/2;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 11136
/**
 * Author: Behradm
 * Created: 19-04-2020 16:32:13
 * In the Name of God
**/
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

#define F first
#define S second
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define LOCAL

#ifdef LOCAL
	#define debugi(x) cerr << "{" << #x << "}: " << (x) << '\n'
	#define debug(v, begin, end) cerr << "{ | "; for(auto i = begin; i < end; i++){cerr << #v << "[" << i << "]: " << v[i] << " | ";} cerr << " }\n"
	#define debugp(a, b) cerr << "\n{ " << a << " " << b << " }\n"
#else
	#define debugi(x) 42
	#define debug(v, begin, end) 42
	#define debugp(a, b) 42 
#endif

int32_t main()
{
	ios_base::sync_with_stdio(false); cin.tie(0);
	cout.tie(0);
	cout.precision(6);
	int n, m;
	cin >> n >> m;
	ll res = 0;
	for(int i = 0; i < m; i++){
		ll a;
		cin >> a;
		res += a;
	}

	if(n - res < 0)
		cout << -1 << '\n';
	else
		cout << n - res << '\n';
	return 0;
}



Measured memory_bytes: 3656
n,m=map(int,input().split())

g=[[] for i in range(1+n)]
v=[0]*(1+n)
e=[]
for i in range(m):
    a,b=map(int,input().split())
    e.append((a,b))
    g[a].append(b)
    g[b].append(a)

def dfs(st,ed):
    q=[]
    q.append(st)

    while q:
        cur=q.pop()
        v[cur]=1
        if cur==ed:
            return True

        for nb in g[cur]:
            if v[nb]!=1 and (cur,nb)!=(st,ed):
                q.append(nb)
    return False

ans=0
for a,b in e:
    v=[0]*(1+n)
    if not dfs(a,b):
        ans+=1
print(ans)

Measured memory_bytes: 39152
#include <stdio.h>
int g[9][9]={0};
int visit[9]={0},n;

int DFS(int now){
	visit[now]=1; //nowを訪問済みに
	int flag=1,cnt=0;
	for(int i=1;i<=n;i++) flag*=visit[i];
	if(flag){//すべて訪問してたら1を返す
		visit[now]=0;
		return 1;
	}
	//未訪問があれば
	for(int i=2;i<=n;i++)if(g[now][i]==1 && visit[i]==0) cnt+=DFS(i);//未訪問先への道があればDFS
	visit[now]=0;//nowを訪問先にしない
	return cnt;
}

int main(void){
	int m,i,a,b;
	scanf("%d%d",&n,&m);
	for(i=0;i<m;i++){
		scanf("%d%d",&a,&b);
		g[a][b]=1;
		g[b][a]=1;
	}
	
	printf("%d",DFS(1));//頂点1が始点なのは条件
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {
	Scanner sc = new Scanner(System.in);
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}
	
	void run() {
		
		int a = sc.nextInt();
		String s = sc.next();
		System.out.println(a >= 3200 ? s: "red");
	}
}


Measured memory_bytes: 23124
//発電機がn個ある時はn-1本分電線を省略できるので、長いところから引いていけば良いという考え方
//先に教材の方を見てしまったのでわかったが、自分で考えるとなると思いつきにくそう
#include<iostream>
#include<vector>
//#include <time.h>
#include<algorithm>
using namespace std;

//バブルソート
#if 0
void sort(int* ab,int* ae){
  int f=1;
  while(f){
    f=0;
    for(auto i=ab;i<ae-1;i++){
      if(*i>*(i+1)){
        int k=*i;
        *i=*(i+1);
        *(i+1)=k;
        f=1;
      }
    }
  }
}
#endif

int main(){
  //clock_t start = clock();

  int T, N, K, X[100000+10], A[100000+10];
  vector<int> s;
  //以下で繰り返しN,K,X,Aの領域を動的に確保することもできるが、それだと遅い？→上書きしていく
  cin >> T;
  for(int i=0;i<T;i++){
    cin >> N >> K;
    //家の位置
    for(int j=0;j<N;j++) cin >> X[j];
    //家の間
    for(int j=0;j+1<N;j++) A[j] = X[j+1]-X[j];
    sort(A,A+N-1);
    int s_=0;
    for(int j=0;j<max(0,(N-1)-(K-1));j++) s_+=A[j];
    s.push_back(s_);
  }
  for(auto i=s.begin();i<s.end();i++) cout << *i << endl;

  //clock_t end = clock();

  //const double time = static_cast<double>(end - start) / CLOCKS_PER_SEC * 1000.0;
  //cout << "time"<< time << "[ms]"<< endl;
}



Measured memory_bytes: 3924
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=int(a);i<int(b);i++)
typedef long long ll;
typedef pair<ll,ll> P;

ll num[1000010];

int main(){
    ll n;cin>>n;
    ll a[200020];
    rep(i,0,n){
        cin>>a[i];
        num[a[i]]++;
    }
    ll an=0;
    rep(i,0,n){
        ll ok=0;
        if(a[i]==1&&num[1]==1){
            an++;
            continue;
        }
        for(ll j=1;j*j<=a[i];j++){
            if(a[i]%j!=0)continue;
            if(j==1){
                if(num[1]||num[a[i]]>=2)ok=1;
            }
            else if(a[i]%j==0){
                if(num[j]||num[a[i]/j])ok=1;
            }
            if(ok)break;
        }
        if(!ok){an++;}
    }
    cout<<an<<endl;
}

    









Measured memory_bytes: 12768
import sys
input = sys.stdin.readline
sys.setrecursionlimit(100000)

def dfs(v, p, c):
    color[v] = c
    for e in graph[v]:
        if e[0] == p: continue
        if e[1] % 2: dfs(e[0], v, 1-c)
        else: dfs(e[0], v, c)


n = int(input())
color = [-1 for _ in range(n)]
graph = [[] for _ in range(n)]

for i in range(n-1):
    u, v, w = [int(x) for x in input().split()]
    u, v = u - 1, v - 1
    graph[u].append((v, w))
    graph[v].append((u, w))

dfs(0, -1, 1)
for i in range(n):
    print(color[i])

Measured memory_bytes: 79320
using System;
using System.Collections.Generic;
using System.Text;
using System.Numerics;
using System.IO;




namespace SolutionCS
{
    class Program
    {
        static int gcd(int a, int b)
        {
            if (a < b)
            {
                return gcd(b, a);
            }

            while (b != 0)
            {
                int rem = a % b;
                a = b;
                b = rem;
            }

            return a;
        }

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            string[] strs = Console.ReadLine().Split(' ');

            int ans = gcd(int.Parse(strs[0]), int.Parse(strs[1]));
            for (int i = 2; i < N; i++)
            {
                ans = gcd(ans, int.Parse(strs[i]));
            }

            Console.WriteLine(ans);
        }
    }
}

Measured memory_bytes: 18528