akhauriyash/Code-Regression huggingface dataset:
import java.util.*

fun concatenate(a: String, b: String): String{
    return a + b
}
fun rotate(concatenatedString: String, afterRotated:String): String{
    val wordLength: Int = afterRotated.length
    val sameAsAfterRotated = (1..(concatenatedString.length - wordLength)).map{
        it -> concatenatedString.slice(it..(it+wordLength - 1))
    }.filter{
        it == afterRotated
    }
    return if (sameAsAfterRotated.isEmpty()){
        "No"
    } else{
        "Yes"
    }
}

fun main(args: Array<String>) {
    val scn = Scanner(System.`in`)
    val before: String = scn.nextLine()
    val after: String = scn.nextLine()

    val concatenatedString: String = concatenate(before, before)
    println(rotate(concatenatedString, after))
}

Measured memory_bytes: 31380
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,fma,abm,mmx,avx,avx2,tune=native")
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#ifdef rd
#define trace(...) cout<<"Line:"<<__LINE__<<" "; __f(#__VA_ARGS__, __VA_ARGS__)
template<typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
	cout<<name<<" : "<<arg1<<endl;
}
template<typename Arg1, typename ... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
	const char *comma=strchr(names+1,',');
	cout.write(names,comma-names)<<" : "<<arg1<<" | ";
	__f(comma+1,args...);
}
#else
#define trace(...)
#define endl '\n'
#endif
#define pb push_back
#define fi first
#define se second
#define int long long
typedef long long ll;
typedef float f80;
#define double long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define sz(x) ((long long)x.size())
#define fr(a,b,c) for(int a=b; a<=c; a++)
#define rep(a,b,c) for(int a=b; a<c; a++)
#define trav(a,x) for(auto &a:x)
#define all(con) con.begin(),con.end()
const ll infl=0x3f3f3f3f3f3f3f3fLL;
const int infi=0x3f3f3f3f;
//const int mod=998244353;
const int mod=1000000007;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> oset;
auto clk=clock();
mt19937_64 rang(chrono::high_resolution_clock::now().time_since_epoch().count());
int rng(int lim) {
	uniform_int_distribution<int> uid(0,lim-1);
	return uid(rang);
}
int powm(int a, int b, int mod) {
	int res=1;
	while(b) {
		if(b&1)
			res=(res*a)%mod;
		a=(a*a)%mod;
		b>>=1;
	}
	return res;
}
 
int a[200005];
void solve() {
	int n;
	cin>>n;
	int ma=0,mb=0;
	fr(i,1,n) {
		cin>>a[i];
		if(ma<a[i]) {
			mb=ma;
			ma=a[i];
		} else if(mb<a[i])
			mb=a[i];
	}
	fr(i,1,n) {
		if(a[i]==ma)
			cout<<mb<<endl;
		else
			cout<<ma<<endl;
	}
}
 
signed main() {
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
	cout<<fixed<<setprecision(10);
	int t=1;
//	cin>>t;
	fr(i,1,t) {
		solve();
	}
#ifdef rd
	cout<<endl<<endl<<endl<<endl<<"Time elapsed: "<<(double)(clock()-clk)/CLOCKS_PER_SEC<<endl;
#endif
	return 0;
}


Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
 
#define fr(i,a,b) for(int (i)=(int) a;(i)<=(int)(b);++(i))
#define li list<int>
#define ll long long
#define mp make_pair
#define mod 1000000007
#define pb push_back
#define pi pair<int ,int >
#define pr printf
#define vi vector<ll>
#define vpi vector< pi > 
int ww=0,ss=0,a,b,c,d,e,f;
double dens=0.0;

int main()
{
	
	cin>>a>>b>>c>>d>>e>>f;
	b*=100;
	a*=100;
	int i,j,k,l;
	for(i=0;b*i<=f;i++)
	{
		for(j=0;i*b+j*a<=f;j++)
		{
			int s,w;
			w=i*b+j*a;
			if(w==0) continue;
			for(k=0;k*d+w<=f;k++)
			{
				for(l=0;w+k*d+l*c<=f;l++)
				{
					s=k*d+l*c;
					if(s>(w*e)/100) break;;
					double den=(double)(s*10000)/((double)(s+w));
					if(den>=dens)
					{
						ww=w;
						ss=s;
						dens=den;
					}
					
				}
			}
		}

	}
	cout<<ss+ww<<" "<<ss;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  int ans=0,cnt=0;
  for(int i=1;i<=N;i++){
    int a;
    cin>>a;
    if(a==i)cnt++;
    else ans+=(cnt+1)/2,cnt=0;
  }
  cout<<ans+(cnt+1)/2<<endl;
}

Measured memory_bytes: 3596
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
set<int> dp[1<<11];

int main(void){
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		for(int i=0;i<(1<<10);i++){
			dp[i].clear();
		}
		string str;
		cin >> str;
		int bits=0;
		bool flag=true;
		int v2=-1;
		for(int i=0;i<str.size();i++){
			if(str[i]=='u'){
				bits=0;
				v2=-1;
			}else{
				if(v2==-1){
					v2=str[i]-'0';
					bits=(1<<v2);
					continue;
				}
				int v=str[i]-'0';
				if((bits>>v) & 1)flag=false;
				dp[bits].insert(1<<v);
				bits|=(1<<v);
			}
		}
		for(int i=0;i<(1<<10);i++){
			if(!flag)break;
			for(int j=0;j<i;j++){
				if((i&j)==j){
					set<int>::iterator it=dp[j].begin();
					for(;it!=dp[j].end();it++){
						set<int>::iterator it2=dp[i-j].begin();
						for(;it2!=dp[i-j].end();it2++){
							int v=(*it)|(*it2);
							dp[i].insert(v);
						}
					}
				}
			}
			set<int>::iterator it=dp[i].begin();
			for(;it!=dp[i].end();it++){
				bool ok=false;
				for(int k=0;k<10;k++){
					if((!(i>>k & 1)) && ((*it)>>k & 1))ok=true;
				}
				if(!ok)flag=false;
			}
		}
		printf("%s\n",flag?"SAFE":"UNSAFE");
	}
	return 0;
}

Measured memory_bytes: 5848
#include <bits/stdc++.h>
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
#define m_p make_pair
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef pair<int,int> pii;
typedef vector<pii> vpii;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;
typedef vector<vector<int>> vvi;
const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x * y / gcd(x, y); }

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if  (num % i == 0)
        {
            return false;
        }
    }
    return true;
}

int main()
{
    ll n,sum=0;
    cin >> n;
    vll p(n);
    rep(i,n){
        cin >> p[i];
        sum+=p[i];
    }
    sort(rall(p));
    cout << sum-(p[0]/2) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <ctype.h>

int main() {
    
    char p[1];
    scanf("%s", p);
    char c = p[0];
    
    if (islower(c) != 0)
        printf("%c\n", 'a');
    else
        printf("%c\n", 'A');
    
    return 0;
}

Measured memory_bytes: 1728
package main

import (
	"fmt"
)

func min(a,b int) int {
	if a< b {
		return a
	}
	return b
}

func main() {
	var p,q,r int
	fmt.Scan(&p, &q, &r)
	ans := min(min(p+q, p+r), q+r)
	fmt.Println(ans)
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        String input = new Scanner(System.in).nextLine();
        String[] i = input.split("\\s+");

        int w = Integer.parseInt(i[0]);
        int h = Integer.parseInt(i[1]);
        int x = Integer.parseInt(i[2]);
        int y = Integer.parseInt(i[3]);
        int r = Integer.parseInt(i[4]);
        if (x + r > w || y + r > h || x - r < 0 || y - r < 0) {
            System.out.println("No");
        } else {
            System.out.println("Yes");
        }
    }
}


Measured memory_bytes: 26264
def egcd(a, b):
    if a == 0:
        return b, 0, 1
    else:
        g, y, x = egcd(b % a, a)
        return g, x - (b // a) * y, y

def modinv(a, m):
    g, x, y = egcd(a, m)
    if g != 1:
        raise Exception('modular inverse does not exist')
    else:
        return x % m
def combination(n, r, mod=10**9+7):
    r = min(r, n-r)
    res = 1
    for i in range(r):
        res = res * (n - i) * modinv(i+1, mod) % mod
    return res


def power_func(a,n,p):
    bi = str(format(n,"b"))#2進表現に
    res = 1
    for i in range(len(bi)):
        res = (res*res) %p
        if bi[i] == "1":
            res = (res*a) %p
    return res



n,a,b=[int(i) for i in input().split()]
mod=10**9+7

print((power_func(2,n,mod)-1-combination(n, a, mod)-combination(n, b, mod))%mod)


Measured memory_bytes: 9244
#include<iostream>
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>
#include<string>
#include<cmath>
#include<numeric>
#include<queue>
using namespace std;

long long int mod = 1000000007;

int main(void) {

  int n, m, t;
  cin >> n >> m >> t;

  vector<bool> a(10000+5, false);
  for(int i=1; i<n+1; i++){
    int tmp;
    cin >> tmp;
    for(int j=max(0, tmp-m); j<min(10005, tmp+m); j++) a[j] = true;
  }

  int cnt = 0;
  for(int i=0; i<t; i++){
    cnt += a[i];
  }
  cout << t - cnt << endl;

  return 0;
}





//

Measured memory_bytes: 3092
#include <cstdlib>
#include <cstdio>
#include <cstdint>
#include <cstring>

inline int64_t area(int w) { return (int64_t)w*(w+1)/2; }

int main(int argc, char* argv[])
{
  int N=5e5+1;
  char s[N+1];
  int l[N+1];
  int i=scanf("%s",s);
  int g=0;
  l[g]=1;
  for (char* p=s+1;*p;p++) {
    if (*(p-1) == *p) {
      l[g]++;
    } else {
      l[++g]=1;
    }
  }

  int64_t sum=0;
  int* q=l;
  if (s[0] == '>') {
    sum = area(*q++);
  }
  for (;q<l+g;) {
    auto w1=*q++, w2=*q++;
    if (w1 < w2) { w1--; } else { w2--; }
    sum += area(w1) + area(w2);
  }
  if (*q) {
    sum += area(*q);
  }
  printf("%ld\n", sum);
  return 0;
}

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

int n;
int a[200];
int res;

int main(){
  cin >> n;
  rep(i, n){
    cin >> a[i];
  }
  int min = 1000000000;
  for(int y = -100; y <= 100; y++){
    int sum = 0;
    for(int i = 0; i < n; i++){
      int tmp = abs(y - a[i]);
      sum += pow(tmp, 2);
    }
    //cerr << y << " : " <<sum << endl;
    if(min > sum){
      min = sum;
    }
  }
  cout << min << 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++)

int main() {
  int N, C;
  cin >> N ;
  C = 0;
  vector<int> A(N);
  vector<int> B(N);
  rep(i , N){
    cin >> A[i];
    B[i] = i+1;
    if (A[i] != B[i])
      C++;
  }
  if (C == 2 || C == 0)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
    
}

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

int main(){
	string S, T; cin>>S>>T;
	vector<int> start(26, -1), goal(26, -1);
	for(int i=0; i<S.size(); ++i){
		int s = S[i]-'a', t = T[i]-'a';
		if(start[s] > -1 || goal[t] > -1){
			if(start[s] != t || goal[t] != s){ puts("No"); return 0; }
		}
		else start[s] = t, goal[t] = s;
	}
	puts("Yes");
}

Measured memory_bytes: 776
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;

#define io(F) string t_="";ifstream fin(t_+F+".in");ofstreamfout(t_+F+".out")
#define qio ios_base::sync_with_stdio(false); cin.tie(NULL)
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
#define graph unordered_map<int, unordered_set<int>>
typedef long long ll;

int main() {
	double ans = 3.1415926535;
	double r; cin >> r;
	ans *= 2*r;
	println(ans);
}


Measured memory_bytes: 3776
#include<cstdio>
#include<functional>
#include<algorithm>
#include<cstring>
using namespace std;
int main(void)
{
	int n,d,x,y;
	scanf("%d %d",&n,&d);
	y=d*2+1;
	x=n/y;
	if(n%y!=0)	x++;
	printf("%d\n",x);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<map>

#define REP(n) for(int i = 0;i < n;i++)
#define LLREP(n) for(long long int  i = 0;i < n;i++)
typedef long long int ll;
using namespace std;
#define MAX_A 1000000007

int main(){

    int n,m;
    string tmp;
    cin >> n;
    map<string,int> blue,red;
    for(int i = 0;i < n;i++){
        cin >> tmp;
        blue[tmp]++;
    }
    cin >> m;
    for(int i = 0;i < m;i++){
        cin >> tmp;
        red[tmp]++;
    }

    map<string,int>::iterator itr;
    int ans = 0;

    for(itr = blue.begin();itr != blue.end();itr++){
        ans = max(ans,blue[itr->first]-red[itr->first]);
    }

    cout << ans << endl;

    return 0;
}

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

#pragma warning(disable: 4996)

#define MAX_N 500000

int N, C;

int v[MAX_N], dp[MAX_N + 7];

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

	dp[N] = 1;

	for (int i = (N + 2) / 2; i > 1; i--)
	{
		dp[i] = dp[2 * i - 1] + 2 * dp[2 * i] + dp[2 * i + 1];
	}

	for (int i = 2; i <= N; i++)
	{
		C += dp[i] * i;
	}

	for (int i = 0; i < N; i++)
	{
		scanf("%d", &v[i]);
	}

	std::sort(v, v + N);

	for (int i = 0; i < N; i++)
	{
		if (i) { printf(" "); }

		printf("%d", v[i]);
	}

	printf("\n");

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

	return 0;
}

Measured memory_bytes: 5504
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  int a[100000];
  rep(i,n) cin>>a[i];
  deque<int> b;
  b.push_back(a[0]);
  repi(i,1,n){
    auto itr=lower_bound(b.begin(),b.end(),a[i]);
    if(itr==b.begin() ){
      b.push_front(a[i]);
    }else{
      itr--;
      *itr=a[i];
    }
  }
  cout<<b.size()<<endl;
	

  return 0;
}


Measured memory_bytes: 1920
import java.util.*;
import java.io.*;
import java.math.BigInteger;

public class Main {	

	private static void solve(){
		//Implement solution here.
		long A = nl();
		char[] Bca = next().toCharArray();
		long B = 0;
		int dig = 2;
		for(char c:Bca) {
			if(c != '.') {
				B += (long)Character.getNumericValue(c) * (long)Math.pow(10, dig);
				dig--;
			}
		}
//		System.out.println(B);
//		System.out.println(A * B);
		System.out.println(A*B/100L);
	}
	
	//Switch input source (stdin/file)
	private static BufferedReader br;
	public static void main(String[] args){
		br = new BufferedReader(new InputStreamReader(System.in));
		String debugDataPath = System.getenv("DD_PATH");        
		if(debugDataPath != null){
			try{
				br = new BufferedReader(new InputStreamReader(new FileInputStream(new File(debugDataPath))));
			}catch(Exception e){
				throw new RuntimeException(e);
			}
		}
		boolean hasNext = true;
		while(hasNext){
			solve();	
			try{
				br.mark(1);
				if(br.read() > 0){
					br.reset();			
					System.out.println("---");
				} else {
					hasNext = false;
				}
			}catch(Exception e){
				throw new RuntimeException(e);
			} 
		}
	}

	//Input read utility
	private static StringTokenizer tokenizer = null;
	public static String next() {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(br.readLine());
			} catch (Exception e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}
	//Get next single int
	private static int ni() {
		return Integer.parseInt(next());
	}
	//Get next single long
	private static long nl() {
		return Long.parseLong(next());
	}
	//Get next single double
	private static double nd() {
		return Double.parseDouble(next());
	}
	//Get next int array from one line
	private static int[] na(int n) {
		int[] a = new int[n];
		for (int i = 0; i < n; i++)
			a[i] = ni();
		return a;
	}
	//Get next char array from one line
	private static char[] ns() {
		return next().toCharArray();
	}
	//Get next long array from one line
	private static long[] nal(int n) {
		long[] a = new long[n];
		for (int i = 0; i < n; i++)
			a[i] = nl();
		return a;
	}
}


Measured memory_bytes: 25428
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


n = int(input())
x = list(map(int, input().split()))
l = int(input())
q = int(input())
ps = [None]*n
# ps2 = [None]*n
j = 0
for i in range(n):
    if j<i:
        j = i
    while j+1<n and x[j+1]-x[i]<=l:
        j += 1
    ps[i] = j
# ダブリング
def double(ps):
    # global: n=psのサイズ
    k = 0
    n = len(ps)
    while pow(2,k)<n:
        k += 1
    prev = [[None]*n for _ in range(k)] # ノードjから2^i個上の上司
    for j in range(n):
        prev[0][j] = ps[j]
    for i in range(1,k):
        for j in range(n):
            p = prev[i-1][j]
            if p>=0:
                prev[i][j] = prev[i-1][p]
            else:
                prev[i][j] = p
    return prev
dl = double(ps)
ans = [None]*q
for i in range(q):
    a,b = map(lambda x: int(x)-1, input().split())
    a,b = min(a,b), max(a,b)
#     print(a,b)
    res = 0
    tmp = float("inf")
    for k in range(len(dl)-1, -1, -1):
        if dl[k][a]<b:
            a = dl[k][a]
            res += pow(2,k)
#         elif dl[k][a]==b:
#             tmp = res+pow(2,k)
#             break
        else:
            tmp = min(tmp, res+pow(2,k))
    ans[i] = tmp
write("\n".join(map(str, ans)))

Measured memory_bytes: 109032
n = input()

count = 0

l = len(n)

if l % 2:
  num = n[0:l]
  tmp = 1
  for i in range(l-1):
    tmp *= 10
  count += int(num) - tmp + 1
  l -= 1

for i in range(l):
  tmp = 1
  if (i+1) % 2:
    for j in range(i+1):
      tmp *= 10
    tmp -= int(float(tmp) / float(10))
    count += tmp
    
print(count)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=101010;
static const ll MOD=1e9+7;



int main(void) {
  ll i, j, k;
  ll N, K;
  cin >> N >> K;
  ll a[MAX], b[MAX];
  
  for(i=0; i<N; i++) {
    cin >> a[i] >> b[i];
  }
  
  
  ll ans=0;
  for(i=0; i<N; i++) if((K|a[i])==K) ans+=b[i];
  
  for(i=30; i>=0; i--) {
    if(!(K>>i&1)) continue;
    
    //例 K=101001(2)
    //i=3 -> S=100111
    //i=5 -> S=011111
    ll S=(K-(1<<i))|((1<<i)-1);
    
    ll t=0;
    for(j=0; j<N; j++) if((S|a[j])==S) t+=b[j];
    
    chmax(ans, t);
  }
  
  
  pt(ans);
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
#define ALL(x) x.begin(),x.end()
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N;
vector<ll> A;
ll allMax,allMin;
const ll INF = 2e18;

ll f(double m,ll& mx,ll& mn)
{
	double res = 0.0;
	mx = -INF;
	mn = INF;
	FOR(i,0,N){
		if(allMin == i){
			chmax(mx,A [i + N]);
			chmin(mn,A [i + N]);
			chmax(res,abs(A [i + N] - m));
			continue;
		}
		if(allMin == i + N){
			chmax(mx,A [i]);
			chmin(mn,A [i]);
			chmax(res,abs(A [i] - m));
			continue;
		}
		if(allMax == i){
			chmax(mx,A [i + N]);
			chmin(mn,A [i + N]);
			chmax(res,abs(A [i + N] - m));
			continue;
		}
		if(allMax == i + N){
			chmax(mx,A [i]);
			chmin(mn,A [i]);
			chmax(res,abs(A [i] - m));
			continue;
		}
		if(abs(A [i] - m) <= abs(A [i + N] - m)){
			chmax(mx,A [i]);
			chmin(mn,A [i]);
			chmax(res,abs(A [i] - m));
		}
		else{
			chmax(mx,A [i + N]);
			chmin(mn,A [i + N]);
			chmax(res,abs(A [i + N] - m));
		}
	}
	return res;
}

int main()
{
	scanf("%lld",&N);
	A.assign(N * 2,0);
	FOR(i,0,N){
		scanf("%lld%lld",&A [i],&A [i + N]);
	}
	allMax = max_element(A.begin(),A.end()) - A.begin();
	allMin = min_element(A.begin(),A.end()) - A.begin();
	bool flag = false;
	FOR(i,0,N){
		if(A [i] == A [allMax] && A [i + N] != A [allMin]){
			flag = true;
			break;
		}
		if(A [i + N] == A [allMax] && A [i] != A [allMin]){
			flag = true;
			break;
		}
		if(A [i] == A [allMin] && A [i + N] != A [allMax]){
			flag = true;
			break;
		}
		if(A [i + N] == A [allMin] && A [i] != A [allMax]){
			flag = true;
		}
	}

	ll ans = INF;
	if(flag){
		ll rMax = A [allMax],rMin = A [allMin];
		double lo = 0.0,hi = 1e18,mid1,mid2;
		ll l,r;
		FOR(i,0,200){
			mid1 = (lo + lo + hi) / 3;
			mid2 = (lo + hi + hi) / 3;
			if(f(mid1,r,l) <= f(mid2,r,l)){
				hi = mid2;
			}
			else{
				lo = mid1;
			}
		}
		f((lo + hi) / 2,r,l);
		chmin(ans,(rMax - rMin) * (r - l));
	}
	{
		ll rMax = A [allMax],rMin = INF;
		ll bMax = -INF,bMin = A [allMin];
		FOR(i,0,N){
			if(A [i] >= A [i + N]){
				chmax(rMax,A [i]);
				chmin(rMin,A [i]);
				chmax(bMax,A [i + N]);
				chmin(bMin,A [i + N]);
			}
			else{
				chmax(rMax,A [i + N]);
				chmin(rMin,A [i + N]);
				chmax(bMax,A [i]);
				chmin(bMin,A [i]);
			}
		}
		chmin(ans,(rMax - rMin) * (bMax - bMin));
	}

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

	return 0;
}


Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define FOR(i,l,r) for(i=l;i<r;i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
#define P pair<ll,ll>
#define F first
#define S second
signed main(){
  ll N,K,i,j,c=0,ans=-1;cin>>N>>K;ll A[N],F[N];
  REP(i,N){F[i]=-1;cin>>A[i];A[i]--;}i=0;
  while(F[i]==-1){
    if(K==c){
      ans=i;break;
    }
    F[i]=c;i=A[i];c++;
  }
  if(ans==-1){
    K-=c;K%=c-F[i];j=0;
    while(F[j]!=F[i]+K)j++;
    ans=j;
  }
  cout<<ans+1<<endl;
  return 0;
}

Measured memory_bytes: 6764
while True:
    n = int(input())
    if n == 0:
        break
    data = [0] * 4001
    order = []
    for _ in range(n):
        e, p, q = map(int, input().split())
        data[e] += p*q
        if e not in order:
            order.append(e)

    flag = True
    for e in order:
        if data[e] >= 1000000:
            print(e)
            flag = False
    if flag:
        print("NA")

Measured memory_bytes: 5828
#include <algorithm>
#include <iostream>
#include <string>
#include <sstream>
#include <stack>
#include <vector>

std::stack<int> merge(
    std::stack<int>& merged,
    const int left_end,
    std::stack<std::pair<int, int>>& ponds)
{
    if (ponds.empty()) {
        return merged;
    }

    const auto& pond = ponds.top();
    if (left_end >= pond.first) {
        merged.push(0);
    }
    merged.top() += pond.second;
    ponds.pop();

    return merge(
        merged,
        std::min(left_end, pond.first),
        ponds);
}

std::stack<int> merge(std::stack<std::pair<int, int>>& ponds)
{
    std::stack<int> merged;
    if (ponds.empty()) {
        return merged;
    }
    return merge(
        merged,
        ponds.top().first,
        ponds);
}

int aggregate(std::stringstream& stream, std::stack<int>& merged) {
    if (merged.empty()) {
        return 0;
    }

    if (merged.size() == 1) {
        stream << merged.top();
        return merged.top();
    }
    
    const int t = merged.top();
    merged.pop();
    stream << t << " ";
    return t + aggregate(stream, merged);
}

void solve(const std::string& input) {
    std::stack<int> slope;
    std::stack<std::pair<int, int>> ponds;
    for (std::size_t i = 0; i < input.size(); ++i) {
        if ('\\' == input[i]) {
            slope.emplace(i);
        }
        if ('/' == input[i] && !slope.empty()) {
            ponds.emplace(slope.top(), i - slope.top());
            slope.pop();
        }
    }

    std::stack<int> merged = merge(ponds);
    const std::size_t size = merged.size();
    std::stringstream stream;
    std::cout << aggregate(stream, merged) << std::endl;
    std::cout << size;
    if (size > 0) {
        std::cout << " " << stream.str();
    }
    std::cout << std::endl;

    return;
}
int main()
{
    std::string input;
    getline(std::cin, input);
    solve(input);

    return 0;
}

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


int main()
{
    int n,l[105],ans=0;
    scanf("%d",&n);
    for(int i=1;i<=n;++i) scanf("%d",l+i);
    for(int i=1;i<=n;++i) 
        for(int j=i+1;j<=n;++j)
            for(int k=j+1;k<=n;++k) {
                if(l[i]==l[j]||l[j]==l[k]||l[k]==l[i]) continue;
                if(l[i]+l[j]<=l[k]||l[i]+l[k]<=l[j]||l[k]+l[j]<=l[i]) continue;
                ans++;
            }
    cout<<ans;
}

Measured memory_bytes: 3696
n,m=map(int,input().split());a=[input()for i in range(n)];b=[input()for i in range(m)];ans="No"
for i in range(n-m+1):
  for j in range(n-m+1):
    c=[a[i+k][j:j+m]for k in range(m)]
    if b==c:ans="Yes"
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

vi a;
ll dp[410][410];

ll dfs(int l,int r) {
    if(dp[l][r]) return dp[l][r];
    if(r-l == 1) return 0;
    ll ret = linf;
    rep2(i,l+1,r) chmin(ret,dfs(l,i)+dfs(i,r));
    rep2(i,l,r) ret += a[i];
    return dp[l][r] = ret;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    a.resize(n);
    cin >> a;
    cout << dfs(0,n) << endl;
}


Measured memory_bytes: 1536
MAX_D = 300000001


def main():
    N, K, *xn = map(int, open(0).read().split())
    if 0 < xn[0]:
        print(xn[K - 1])
        return
    if xn[N - 1] < 0:
        print(abs(xn[N - K]))
        return
    ans = MAX_D
    for i in range(N - K + 1):
        if xn[i + K - 1] < 0 and i + K <= N - 1 and 0 < xn[i + K]:
            ans = min(ans, abs(xn[i]))
        elif 0 < xn[i]:
            if 0 != i:
                if xn[i - 1] < 0:
                    ans = min(ans, abs(xn[i + K - 1]))
                else:
                    break
        elif 0 <= xn[i + K - 1]:
            ans = min(ans,
                      2 * abs(xn[i]) + abs(xn[i + K - 1]),
                      abs(xn[i]) + 2 * abs(xn[i + K - 1]))
    print(ans)
    return


main()


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

using namespace std;

vector<int> G[110];

int timer;
int d[110],f[110];

bool used[110];

void dfs(int x)
{
    used[x]=true;
    d[x]=++timer;

    for(int i=0;i<G[x].size();i++)
    {
        if(!used[G[x][i]])
        {
            dfs(G[x][i]);
        }
    }

    f[x]=++timer;
}


int main()
{

    int n;

    cin>>n;

    for(int i=0;i<n;i++)
    {
        int a,b,c;

        cin>>a>>b;

        for(int i=0;i<b;i++)
        {
            cin>>c;

            G[a].push_back(c);
        }
    }

    timer=0;
    memset(used,0,sizeof(used));

    for(int i=1;i<=n;i++)
    {
        if(!used[i])
        {
            dfs(i);
        }
    }

    for(int i=1;i<=n;i++)
    {
        cout<<i<<" "<<d[i]<<" "<<f[i]<<endl;
    }

    return 0;
}



Measured memory_bytes: 3152
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#define ll long long
using namespace std;
const int maxn=1e5+100;
ll a[maxn];
ll ans[maxn];
int n;
int main()
{
    scanf("%d",&n);
    ll sum=0;
    for(int i=1;i<=n;i++)
    {
        scanf("%lld",&a[i]);
        if(i%2==0)
            sum-=a[i];
        else
            sum+=a[i];
    }
    ans[1]=sum;
    a[1]-=ans[1]/2;
    for(int i=2;i<=n;i++)
    {
        ans[i]=a[i-1]*2;
        a[i]-=ans[i]/2;
    }
    for(int i=1;i<=n;i++)
        printf("%lld ",ans[i]);
    printf("\n");
}


Measured memory_bytes: 2816
#include <bits/stdc++.h>
using namespace std;
#define REP(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) REP(i, 0, n)
#define rrep(i, n) for (int i = (int)(n-1); i >= 0; i--)
#define sz(x) int(x.size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF 2e9
#define LINF 1e18
template<class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> P;

int main() {
    vector<char> c1(3), c2(3);
    rep(i, 3) cin >> c1[i];
    rep(i, 3) cin >> c2[i];
    cout << (c1[0]==c2[2]&&c1[1]==c2[1]&&c1[2]==c2[0] ? "YES" : "NO") << endl;

}

Measured memory_bytes: 256
def resolve():
    n, g = map(int, input().split())
    a = list(map(int, input().split()))
    ar = [-1] * n
    k = 0
    now = 0
    for i in range(n+1):
        if ar[now] == -1:
            ar[now] = k
            now = a[now]-1
            k += 1
        else:
            start = ar[now]
            startnode = now
            end = k
    if g <= start:
        ans = 0
        for i in range(n):
            if ar[i] == g:
                ans = i+1
    else:
        g -= start
        g %= (end-start)
        now = startnode
        for i in range(g):
            now = a[now]-1
        ans = now + 1
    print(ans)
resolve()

Measured memory_bytes: 92220
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace(); input_inner!{iter, $($r)*} }; } 
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

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

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

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

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

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

fn gcd(a: i64, b: i64) -> i64 {
    if b == 0 {
        a
    } else {
        gcd(b, a % b)
    }
}

use std::cmp::max;

fn main() {
    input! {
        n: usize,
        a: [i64; n],
    }

    let mut gcd_l = vec![0; n];
    let mut gcd_r = vec![0; n];

    gcd_l[0] = a[0];
    gcd_r[n-1] = a[n-1];
    for i in 1..n {
        gcd_l[i] = gcd(a[i], gcd_l[i-1]);
        gcd_r[n - i - 1] = gcd(a[n - i - 1], gcd_r[n - i]);
    }

    let mut  ans = max(gcd_l[n-2], gcd_r[1]);
    for i in 1..n-1 {
        ans = max(ans, gcd(gcd_l[i-1], gcd_r[i+1]));
    }
    println!("{}", ans);
}

Measured memory_bytes: 8444
import numpy as np


def sum_to_num(num):
    if num == 0:
        return 0
    
    elif num == 1:
        return 1
    elif num == 2:
        return 3
    elif num == 3:
        return 0

    base = 2 ** (len('{:b}'.format(num)) - 1)

    if num % 2 == 0:
        return sum_to_num(num - base) + base
    else:
        return sum_to_num(num - base)

A, B = map(int, input().split())
if A == 0:
    print(sum_to_num(B))
else:
    print(np.bitwise_xor(sum_to_num(B), sum_to_num(A - 1)))


Measured memory_bytes: 14516
#include <iostream>
#include <vector>
#include <tuple>


using namespace std;


using ll = long long;


bool check(ll grid[][3], tuple<ll, ll, ll> a, tuple<ll, ll, ll> b)
{
    ll as[3];
    ll bs[3];

    as[0] = get<0>(a); as[1] = get<1>(a); as[2] = get<2>(a);
    bs[0] = get<0>(b); bs[1] = get<1>(b); bs[2] = get<2>(b);

    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            if (grid[i][j] != as[i] + bs[j]) {
                return false;
            }
        }
    }
    return true;
}


int main()
{
    vector<tuple<ll, ll, ll>> a;
    for (int i = 0; i <= 100; i++)
        for (int j = 0; j <= 100; j++)
            for (int k = 0; k <= 100; k++)
                a.push_back(make_tuple(i, j, k));

    ll grid[3][3];
    for (int i = 0; i < 3; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> grid[i][j];
        }
    }

    bool feasible = false;
    for (auto t : a) {
        ll b1, b2, b3;
        b1 = grid[0][0] - get<0>(t);
        b2 = grid[1][1] - get<1>(t);
        b3 = grid[2][2] - get<2>(t);
        if (check(grid, t, make_tuple(b1, b2, b3))) {
            feasible = true;
            break;
        }
    }
    if (feasible)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}


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

int main(){
    int N;
    int W[103];
    int s1 = 0;
    int s2 = 0;
    cin >> N;
    for(int i=1;i<=N;i++){
        cin >> W[i];
        s2 += W[i];
    }
    int ans = 1e6;

    for(int t=1;t<=N;t++){
        s1 += W[t];
        s2 -= W[t];
        ans = min(ans, abs(s2-s1));
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

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

    int ans = 0;
    int tmp = 0;
    int preH;
    cin >> preH;
    for (int i = 1; i < n; i++) {
        int h;
        cin >> h;

        if (preH >= h) {
            tmp++;
        } else {
            ans = max(ans, tmp);
            tmp = 0;
        }

        preH = h;
    }
    ans = max(ans, tmp);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include"bits/stdc++.h"
using namespace std;
using ll=long long;
using ull=unsigned long long;
template<typename T>using pqg=priority_queue<T,vector<T>,greater<T>>;
constexpr auto inf=static_cast<ll>(1e18);
template<typename T=ll>inline T in(){T ret;cin>>ret;return ret;}
template<typename T=ll>inline vector<vector<T>>vec2(size_t h,size_t w,T v=T()){return vector<vector<T>>(h,vector<T>(w,v));}
inline void setp(int n){cout<<fixed<<setprecision(n);}
inline void delnl(){cin.ignore(numeric_limits<streamsize>::max(),'\n');}

int main()
{
    ll a=in(),b=in();
    cout<<(b-1+a-2)/(a-1)<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define pb push_back
#define fi first
#define se second
const int N = 3e5+6;
const int M = 998244353;
const ll inf = 1e18;
const ld pi = acos(-1.0);
void solve(){
   int n;
   cin>>n;
   n%=10;
   if(n==3)cout<<"bon"<<endl;
   else if (n==0 or n==1 or n==6 or n==8)cout<<"pon"<<endl;
   else cout<<"hon"<<endl;
}
int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    int t=1;
 //   cin>>t;
    while(t--)solve();
    return 0;
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<algorithm> // sort
#include<map> // pair
#include<cmath>
using namespace std;
using ll = long long;
const ll mod = 1e9+7;
ll x,y,z,k,count=0,sum;
ll a[1000],b[1000],c[1000];
void print(ll x,ll y,ll z){
  cout << a[x]+b[y]+c[z];

}
int main(){
  string s;
  cin >> s;
  ll maximum=0,x=0;
  ll n=s.length();
  for(int i=0;i<n;i++){
    switch(s[i]){
      case'A':
      case'T':
      case'G':
      case'C':
      x++;
      break;

      default:
      maximum = max(x,maximum);
      x=0;
      break;
    }
  }
  maximum = max(x,maximum);
  cout << maximum;
}


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

#define int         long long 
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define all(v)      v.begin(),v.end()
#define ff          first
#define ss          second
#define endl        "\n"
#define mod         1000000007
#define PI          3.14159265 
#define FIO         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define print(x)    for(auto el: x) cout<<el<<" ";cout<<endl;





void solve(){
    
    int n, W;
    cin >> n >> W ;

    int wt[n] , val[n] ;
    for(int i = 0; i < n; i++)
        cin >> wt[i] >> val[i] ;

    int dp[n+1][W+1];

    for(int i = 0; i <= n; i++)
        for(int j = 0; j <= W; j++)
            if(i == 0 || j == 0)
                dp[i][j] = 0;
            else if(wt[i-1] <= j)
                dp[i][j] = max(dp[i-1][j], val[i-1] + dp[i-1][j-wt[i-1]]);
            else
                dp[i][j] = dp[i-1][j];

    // for(int i=0; i<=n; i++){
    //     print(dp[i]);
    // }

    cout<<dp[n][W];

    return;    
}




int32_t main() 
{
    
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    FIO;
    int test;

    // cin>>test;
    test = 1;
    
    while(test--)
        solve();

    return 0;
}

Measured memory_bytes: 82492
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<functional>
#include<math.h>

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

ll gcd(ll a, ll b) {
	if (b == 0)return a;

	return gcd(b, a%b);
}

int main() {
	ll x;
	cin >> x;

	ll ans = 0;
	if (x <= 6) {
		cout << 1 << endl;
		return 0;
	}
	else if (x <= 11) {
		cout << 2 << endl;
		return 0;
	}
	ll y = x / 11;
	ll z = x % 11;
	ans += y * 2;
	if (0 < z&&z <= 6) {
		ans ++;
	}
	else if (z > 6) {
		ans += 2;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,e) for(int i = a;i < e;++i)
using LL = long long;

int main() {
	int N; cin >> N;
	vector<int> a(N);
	for (int i = 0; i < N; ++i) {
		cin >> a[i];
	}
	priority_queue<double, vector<double>, greater<double>>q;
	FOR(i, 0, N) {
		q.push(a[i]);
	}
	while (q.size() > 1) {
		double x = q.top(); q.pop();
		double y = q.top(); q.pop();
		double s = (x+y) / 2.0;
		q.push(s);
	}
	double ans = q.top();
	cout << fixed << setprecision(10) << ans << endl;

}




Measured memory_bytes: 256
use proconio::input;

fn main() {
	input!(n: usize);
	input!(a: [i64; n]);
	input!(q: usize);
	input!(bc: [(i64, i64); q]);

	let mut bu: Vec<i64> = vec![0; 100001];
	let mut sum: i64 = 0; 
	for i in 0..n {
		bu[a[i] as usize] += 1;
		sum += a[i];
	}

	for i in 0..q {
		sum += (bc[i].1-bc[i].0)*bu[bc[i].0 as usize];
		println!("{}", sum);
		bu[bc[i].1 as usize] += bu[bc[i].0 as usize];
		bu[bc[i].0 as usize] = 0;
	}
}



Measured memory_bytes: 6908
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();
    if ((a+b)<10) {
      System.out.println(a+b);
    }else{
      System.out.println("error");
    }
  }
}


Measured memory_bytes: 23636
import sys
input = lambda: sys.stdin.readline().rstrip()

def main():
    x, n = map(int, input().split())
    p = list(map(int, input().split()))

    if x not in p:
        print(x)
    else:
        off = 1
        for i in range(200):
            k = x - off
            if k not in p and -99 < k <= 200:
                print(k)
                break
            k = x + off
            if k not in p and -99 < k <= 200:
                print(k)
                break
            off += 1

if __name__ == '__main__':
    main()


Measured memory_bytes: 61936
#include<stdio.h>
long long int max(long long int n, long long int tmp[], long long int *num, long long int *M) {
	long long int max_memo = tmp[0];
	long long int max_num = 0;
	for (int i = 1; i < n; i++) {
		if (max_memo < tmp[i]) {
			max_memo = tmp[i];
			max_num = i;
		}
	}
	*num = max_num;
	*M = max_memo;
	return 0;
}
int main() {
	long long int n;
	long long int num, m;
	int result = 0;
	long long int s[10];
	scanf("%lld", &n);
	for (int i = 0; i < n; i++){
		scanf("%lld", &s[i]);
		result += s[i];
	}
	max(n, s, &num, &m);
	printf("%d",result - (m / 2));
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define endl '\n'

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;


int main()
{
    char a[3][3];
    ll i,j;
    for(i=0;i<3;i++)
    {
        for(j=0;j<3;j++)
        {
            cin>>a[i][j];
        }
    }
    cout<<a[0][0]<<a[1][1]<<a[2][2]<<endl;
    return 0;
}


Measured memory_bytes: 3580
parseInt(x::String) = parse(Int, x)
parseInt(x::SubString{String}) = parse(Int, x)
parseInt(x::Char) = parse(Int, x)
parseInt(x::Float64) = trunc(Int, x)
parseFloat(x::String) = parse(Float64, x)
parseFloat(x::Int) = trunc(Float64, x)
parseFloat(x::SubString{String}) = parse(Float64, x)
parseFloat(x::Char) = parse(Float64, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)

function main()
    c=readline()[1]
    if c in ['a','i','u','e','o']
        println("vowel")
    else
        println("consonant")
    end
end
main()

Measured memory_bytes: 163848
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include<math.h>
int main()
{
   int n,m,X,Y,i,min=101,max=-101,x,y;
   scanf("%d%d%d%d",&n,&m,&X,&Y);
   if(X>Y)
   {
       printf("War");
       return 0;
   }
   for(i=0;i<n;i++)
   {
       scanf("%d",&x);
       if(x>max)
        max=x;
   }
   if(X>max)
    max=X;
   for(i=0;i<m;i++)
   {
       scanf("%d",&y);
       if(y<min)
       {
           min=y;
       }
   }
   if(Y<min)
    min=Y;
    if(max<min)
    {
        printf("No War");
    }
    else{
        printf("War");
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  for(int i=0;i<n;i++) cin >> s[i];

  for(int i=0;i<n;i++){
    sort(s[i].begin(),s[i].end());
  }

  vector<vector<int>> table(n,vector<int>(26));
  for(int i=0;i<n;i++){
    char prev = s[i][0];
    int cnt = 1;
    for(int j=1;j<s[i].size();j++){
      if(s[i][j] != prev){
        table[i][prev-'a'] = cnt;
        prev = s[i][j];
        cnt = 1;
      }else{
        cnt++;
      }
    }
    table[i][prev-'a'] = cnt;
  }

  string ans = "";
  for(int i=0;i<26;i++){
    int ap = 100;
    for(int j=0;j<n;j++){
      ap = min(ap,table[j][i]);
    }
    for(int k=0;k<ap;k++){
      ans += ('a'+i);
    }
  }

  cout << ans << endl;
}


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

using namespace std;

char a;

int main()
{
    scanf("%c",&a);
    if(a == 'A')
        printf("T\n");
    else if(a == 'T')
        printf("A\n");
    else if(a == 'G')
        printf("C\n");
    else
        printf("G\n");
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>
#include <string>
#include <sstream>
#include <complex>
#include <cmath>
#include <algorithm>
using namespace std;



int main(){
    long h,w;
    cin  >> h >> w;
    vector< vector<char> > a(h,vector<char>(w,'.'));

    for (int i = 0; i < h; ++i){
      for(int j=0;j<w;j++){
        cin >> a[i][j];
      }
    }

    // vector< vector<bool> > isWhite(h,vector<bool>(w,false));

    vector<bool>  isWhiteRow(h,false);
    vector<bool>  isWhiteCol(w,false);


    for (int i = 0; i < h; ++i){
      bool isAllwhite =true;
      for(int j=0;j<w;j++){
         if (a[i][j] =='#')isAllwhite=false;
      }
      if (isAllwhite)isWhiteRow[i]=true;
    }

    for (int i = 0; i < w; ++i){
      bool isAllwhite =true;
      for(int j=0;j<h;j++){
         if (a[j][i] =='#')isAllwhite=false;
      }
      if (isAllwhite)isWhiteCol[i]=true;
    }

    for (int i = 0; i < h; ++i){
      if (isWhiteRow[i])continue;
      for(int j=0;j<w;j++){
        if (isWhiteCol[j])continue;
        cout << a[i][j];
      }
      cout << endl;
    }



    
    return 0;
}

Measured memory_bytes: 256
# https://atcoder.jp/contests/abc164/tasks/abc164_d

import sys
input = sys.stdin.readline


S = input().rstrip()

res = 0

x = 0
p = 1
L = len(S)
MOD = 2019
reminder = [0]*2019
reminder[0] = 1
for s in reversed(S):
    """ 累積和 """
    x = (int(s)*p + x)%MOD
    p = p*10%MOD
    reminder[x] += 1

for c in reminder:
    res += c*(c-1)//2

print(res)

Measured memory_bytes: 73772
#include <iostream>

using namespace std;

int main()
{
   long long int a,b,x;
    cin>>a>>b>>x;
    long long res;
    if(a>0)
        res = (b/x) - (a-1)/x;
    else
        res = (b/x) + 1;
    cout<<res<<endl;
        return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl 	"\n"

typedef vector< ll > 	vi;
typedef vector< vi > 	vvi;
typedef pair< ll,ll > 	ii;
#define pb 		push_back
#define all(c) 		(c).begin(),(c).end()
#define tr(c,i) 	for(typeof((c).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) 	((c).find(x) != (c).end())

#define MOD 	1000000007
#define INF 	(int)1e9
#define MEM(a, b) memset(a, (b), sizeof(a))

int main()
{	 ios_base::sync_with_stdio(false);
	 cin.tie(NULL);
	

	ll n;
	cin>>n;
	ll a[n];
	for (ll i = 0; i < n; ++i)
	{
		cin>>a[i];
		/* code */
	}
	 ll  final1=999999999,ans=0;
	ll m = *max_element(a, a+n);
	for(ll p=1; p<=m; p++)
	{
	for(ll i=0; i<n; i++)
	{
		ans+= (a[i]-p)*(a[i]-p); 
	 }
	 final1= min(final1,ans);
	 ans=0;
	 //cout<<final1<<endl;
	}
	cout<<final1;

	return 0;
}

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

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

   if (S == "Sunny")
      cout << "Cloudy" << endl;
   else if (S == "Cloudy")
      cout << "Rainy" << endl;
   else
      cout << "Sunny" << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007;
#define pi 3.14159265358979323846
#define Endl endl
#define LINF 100000000000000007LL
#define ll long long
using namespace std;
signed main(){
	int n,m;
	cin>>n>>m;
	int ans = n * (n-1) / 2 + m * (m-1)/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) {
        try (Scanner s = new Scanner(System.in)) {
            int n = s.nextInt();
            int m = s.nextInt();
            s.nextLine();
            int[] h = Arrays.stream(s.nextLine().split(" "))
                            .mapToInt(Integer::parseInt)
                            .toArray();
            var way = new HashMap<Integer, Set<Integer>>();
            for (int i = 0; i < m; i++){
                int a = s.nextInt() - 1, b = s.nextInt() - 1;
                way.computeIfAbsent(a, k -> new HashSet<>()).add(b);
                way.computeIfAbsent(b, k -> new HashSet<>()).add(a);
            }
            long good = (n - way.size()) + way.entrySet().stream()
                .filter(e -> e.getValue().stream().allMatch(v -> h[e.getKey()] > h[v]))
                .count();
            System.out.println(good);
        }
    }
}

Measured memory_bytes: 98092