akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
const int INF = 1<<29;
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
int gcd(int x, int y) { return (x % y)? gcd(y, x % y): y; }
//最小公倍数
int lcm(int x, int y) { return x / gcd(x, y) * y; }
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int N; cin >> N;
    string S;
    map<string,int> mp;
    for(int i=0;i<N;i++){
        cin >> S;
        if(mp[S]==0){
            mp[S] = 1;
        }else{
            int num=mp[S];
            mp[S] = num+1;
        }
    }
    cout << mp.size() << endl;
    return 0;
}


Measured memory_bytes: 19260
#define _CRT_SECURE_NO_WARNINGS
#include <algorithm>
#include <functional>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <bitset>
#include <climits>
#include <iterator>
 
#define all(c) (c).begin(), (c).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define pb(e) push_back(e)
#define mp(a, b) make_pair(a, b)
#define fr first
#define sc second
 
const int INF=100000000;
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
using namespace std;
typedef pair<int ,int > P;
typedef long long ll;
ll cnt;

void m(vector < ll > &A, int left, int mid, int right)
{
	int n1 = mid - left;
	int n2 = right - mid;
	vector<ll> L(n1 + 1), R(n2 + 1);
	rep(i, n1) L[i] = A[left + i];
	rep(i, n2) R[i] = A[mid + i];
	L[n1] = 10e9 + 7;
	R[n2] = 10e9 + 7;
	int i = 0, j = 0;

	for (int k = left; k < right ; k++)
	{
		if (L[i] <= R[j])
		{
			A[k] = L[i];
			i++;
		}
		else
		{
			A[k] = R[j];
			j++;
		}
		cnt++;
	}
}

void mergeSort(vector<ll> &A, int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergeSort(A, left, mid);
		mergeSort(A, mid, right);
		m(A, left, mid, right);
	}
}

int main()
{
	int n; cin >> n;
	vector < ll > A(n);
	rep(i, n)cin >> A[i];
	mergeSort(A, 0, n);
	
	//copy(all(A), std::ostream_iterator<int>(cout, " "));
	cout << A[0];
	for (int i = 1; i < n; i++)
	{
			cout << " " << A[i];
	}
	cout << endl << cnt << endl;
	return 0;
}

Measured memory_bytes: 10556
#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<string>
#include<unordered_map>
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,k
#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 sort(a) sort(a.begin(),a.end())
#define push(a,b) (a).push_back(b)
#define llvec vector<vector<ll>>
#define charvec vector<vector<char>>
#define sizeoof(a,b) (a,vector<ll>(b))
#define llpvec vector<pair<ll,ll>>
/*繰り上げ除算*/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;}
ll ans=0;llfor;///////////////////////////////////////////////////////////
int main(){
 ll a,b;
 sc(a);sc(b);
  
 if(a%3==0||b%3==0||(a+b)%3==0)puts("Possible");
 else puts("Impossible");
return 0;}

Measured memory_bytes: 3608
#include<stdio.h>
//市の認識番号の小さい順にソート
int c[100002][3];
void merge(int i,int j,int s[][3]){
  if(i!=j){
    merge(i,(i+j)/2,s);
    merge((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d][0]=s[b][0];
        c[d][1]=s[b][1];
        c[d][2]=s[b][2];
        b++;
      }
      else if(j<b){
        c[d][0]=s[a][0];
        c[d][1]=s[a][1];
        c[d][2]=s[a][2];
        a++;
      }
      else if(s[a][1]<s[b][1] || (s[a][1]==s[b][1] && s[a][2]<s[b][2])){
        c[d][0]=s[a][0];
        c[d][1]=s[a][1];
        c[d][2]=s[a][2];
        a++;
      }
      else{
        c[d][0]=s[b][0];
        c[d][1]=s[b][1];
        c[d][2]=s[b][2];
        b++;
      }
    }
    for(d=i;d<=j;d++){
      s[d][0]=c[d][0];
      s[d][1]=c[d][1];
      s[d][2]=c[d][2];
    }
  }
}

void sort(int i,int j,int s[][3]){
  if(i!=j){
    sort(i,(i+j)/2,s);
    sort((i+j)/2+1,j,s);
    int a=i,b=(i+j)/2+1;
    int d;
    for(d=i;d<=j;d++){
      if((i+j)/2<a){
        c[d][0]=s[b][0];
        c[d][1]=s[b][1];
        c[d][2]=s[b][2];
        b++;
      }
      else if(j<b){
        c[d][0]=s[a][0];
        c[d][1]=s[a][1];
        c[d][2]=s[a][2];
        a++;
      }
      else if(s[a][0]<s[b][0]){
        c[d][0]=s[a][0];
        c[d][1]=s[a][1];
        c[d][2]=s[a][2];
        a++;
      }
      else{
        c[d][0]=s[b][0];
        c[d][1]=s[b][1];
        c[d][2]=s[b][2];
        b++;
      }
    }
    for(d=i;d<=j;d++){
      s[d][0]=c[d][0];
      s[d][1]=c[d][1];
      s[d][2]=c[d][2];
    }
  }
}

int main(){
  int n,m,i,j;
  scanf("%d%d",&n,&m);
  int p[m+2][3];
  for(i=1;i<=m;i++){
    p[i][0]=i;
    scanf("%d%d",&p[i][1],&p[i][2]);
  }
  merge(1,m,p);
  p[1][2]=1;
  int num=1;
  for(i=2;i<=m;i++){
    if(p[i][1]==p[i-1][1]){
      p[i][2]=num+1;
      num++;
    }
    else{
      p[i][2]=1;
      num=1;
    }
  }
  sort(1,m,p);
  for(i=1;i<=m;i++){
    for(j=1;j<=2;j++){
      int digit=0,temp=p[i][j];
      while(temp!=0){
        temp/=10;
        digit++;
      }
      int k;
      for(k=6;k>digit;k--)
        printf("0");
      printf("%d",p[i][j]);
    }
    puts("");
  }
  return 0;
}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
	
int main(){
	int A, B, C;
	cin >> A >> B >> C;
	if(A <= C && C <= B) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict

read = sys.stdin.read
readline = sys.stdin.readline

N, M, *X = map(int, read().split())
x = defaultdict(lambda: defaultdict(int))
for i in X:
    x[i % M][i] += 1

answer = 0
checked = [False] * M
for i in range(M):
    if checked[i]:
        continue
    checked[i] = True
    if i == 0 or i * 2 == M:
        answer += sum(x[i].values()) // 2
        continue
    if i not in x:
        continue
    if M - i in x:
        checked[M - i] = True
        v1 = list(x[i].values())
        v2 = list(x[M - i].values())
        cnt1 = sum(v1)
        cnt2 = sum(v2)
        if cnt1 == cnt2:
            answer += cnt1
            continue
        if cnt1 < cnt2:
            v1, v2 = v2, v1
            cnt1, cnt2 = cnt2, cnt1

        n = sum(i % 2 for i in v1)
        if n >= cnt2:
            answer += cnt2 + sum(i // 2 for i in v1)
        else:
            answer += cnt2 + (cnt1 - cnt2) // 2
    else:
        answer += sum(i // 2 for i in x[i].values())
print(answer)


Measured memory_bytes: 44756
import java.util.Scanner;
class Main {
    public static void main (String[] args) {
        Scanner sc = new Scanner(System.in);
        while (true) {
        	int a = sc.nextInt();
        int b = sc.nextInt();
        if (a==0 && b==0) break;
        for (int i=0; i<a; i++) {
        	if(i == 0 || i == a-1) {
        		for(int j=0; j<b;j++) {
        			System.out.print("#");
        			if(j == b-1) System.out.println();
        		}
        	} else {
        		for(int j=0; j<b;j++) {
        			if(j == 0 || j == b-1) {
        				System.out.print("#");
            			if(j == b-1) System.out.println();
        			} else {
        				System.out.print(".");
        			}
        		}
        	}
        	if(i == a-1) System.out.println();
        }
        }
    }
}


Measured memory_bytes: 37512
#include <iostream>
#include <cstdio>
using namespace std;
int main()
{
    double r1,r2,r3=0.0;
    cin>>r1>>r2;
    r1*=1.0;
    r2*=1.0;
    r3=1.0/r1+1.0/r2;
    printf("%.10lf",1.0/r3);
    return 0;
}

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

using namespace std;

typedef long long ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    ll h, w;
    cin >> h >> w;
    if (min(h, w) == 1) {
        cout << 1 << "\n";
        return 0;
    }
    cout << (h * w + 1) / 2 << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <queue>
#include <vector>
#include <iostream>
#include <functional>

#pragma warning(disable : 4996)

#define INF (1 << 23)

using namespace std;

int main()
{
	int N, M, s, t, u, v;

	scanf("%d", &N);
	scanf("%d", &M);
	scanf("%d", &s); s--;
	scanf("%d", &t); t--;

	vector<vector<int> > G(N);

	for (int i = 0; i < M; i++)
	{
		scanf("%d", &u);
		scanf("%d", &v);

		G[u - 1].push_back(v - 1);
		G[v - 1].push_back(u - 1);
	}

	vector<int> d1(N, INF); d1[s] = 0;
	vector<int> d2(N, INF); d2[t] = 0;

	queue<int> que;

	que.push(s);

	while (!que.empty())
	{
		int node = que.front(); que.pop();

		for (int i = 0; i < G[node].size(); i++)
		{
			if (d1[G[node][i]] == INF)
			{
				d1[G[node][i]] = d1[node] + 1; que.push(G[node][i]);
			}
		}
	}

	que.push(t);

	while (!que.empty())
	{
		int node = que.front(); que.pop();

		for (int i = 0; i < G[node].size(); i++)
		{
			if (d2[G[node][i]] == INF)
			{
				d2[G[node][i]] = d2[node] + 1; que.push(G[node][i]);
			}
		}
	}

	int shortest = d1[t];

	vector<int> r1(shortest - 1, 0); for (int i = 0; i < N; i++) { if (d1[i] < shortest - 1) r1[d1[i]]++; }
	vector<int> r2(shortest - 1, 0); for (int i = 0; i < N; i++) { if (d2[i] < shortest - 1) r2[d2[i]]++; }

	long long ret = 0;

	for (int i = 0; i < shortest - 1; i++) ret += 1LL * r1[i] * r2[shortest - i - 2];
	
	printf("%lld\n", ret);

	return 0;
}

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

#define o(output) cout << output << endl
#define priolity_queue pq
#define push p
#define top t

using namespace std;

string s;
int a,b,c,d;
char A,B;

int main(){
  cin >> a >> b;
  if(a>b)o(a-b);
  else o(0);
}

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

int main(void){
	int A,B,C,D;
	bool switchflag = true;
	cin >> A >> B >> C >> D;


	do{
		if( switchflag == true ){
			C -= B;
			switchflag = false;
		}else{
			A -= D;
			switchflag = true;
		}	
	}while( A > 0 && C > 0 );
	
	if( A <= 0 ){
		cout << "No" << endl;	
	}else if( C <= 0 ){
		cout << "Yes" << endl;		
	}
	return 0;
}

Measured memory_bytes: 3100
r, c = map(int, input().split())
a = []
for i in range(r) :
    a.append(list(map(int, input().split())))
    a[i] += [sum(a[i])]
    print(*a[i], sep = ' ')
a = list(zip(*a))
for i in range(c) :
    print(sum(a[i]), end = ' ')
print(sum(a[c]))


Measured memory_bytes: 5772
import java.util.Scanner;

/**
 * @author kawakami
 *
 */
class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner as = new Scanner(System.in);
		
		int n=as.nextInt();
		long tr,min,max,sum;
		int j = 0,k = 0;
		long jug[] = new long[n];
		
		
		
		jug[0]=as.nextInt();
		//System.out.println("test3 "+jug[0]);
		max=jug[0];
		min=jug[0];
		sum=jug[0];
		
		
		for(int i=1;i<n;i++){
			//System.out.println("test4");
			jug[i]=as.nextInt();
			sum=sum+jug[i];
			//System.out.println(sum+" test1 "+jug[i]);
		}
		while(j!=1){
			j=1;
			//System.out.println("test2");
			for(k = 0;k<n-1;k++){
				
				if(jug[k]>jug[k+1]){
					tr=jug[k];
					jug[k]=jug[k+1];
					jug[k+1]=tr;
					j=0;
				}
			}
			
			
		}
		System.out.println(jug[0]+" "+jug[k]+" "+sum);

	}

}

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

char a[10];
vector<string> s;
string t;
long long n, i, j, ans = 0;
int main(){
	cin >> n;
	for (j = 0; j < n; j++){
		for (i = 0; i < 10; i++){
			cin >> a[i];		
		}
		sort(a, a + 10);
		t = a;
		s.push_back(t);
		//cout << s;
		/*for (i = 0; i < 10; i++){
			cout << a[i];
		}*/
	}
	sort(s.begin(), s.end());
	//cout << s[0] << endl;
	j = 0;
	for (i = 0; i < n - 1; i++){
		while (j < n - 1 && (s[i] == s[j + 1] || j < i)){
			j++;
		}
		if (s[i] == s[j]) ans += j - i;
		if (i == j) j++;
	}
	cout << ans << endl;
	return 0;
}


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

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

using ll = long long int;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

    int cnt = 0;
    for (int i = 0; i < 3; i++)
    {
        if (S[i] == T[i])
            cnt++;
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define endl '\n'
#define pii pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#define fio freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define vll vector<long long int>
#define vpii vector<pair<int,int>>
#define dsc [](int a,int b)->bool {return a>b;}
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define MAX 1000000000000000000
#define test int t; cin>>t;
#define MOD 1000000007LL
#define all(x) (x).begin(),(x).end()

using namespace std;

ll nxt(){
    ll x;
    cin>>x;
    return x;
}

int main()
{
    #ifndef ONLINE_JUDGE
        fio
    #endif
    IOS
    
    string s;
    cin>>s;
    ll sum = 0;
    for(char ch: s){
        ll tmp = ch-'0';
        sum = (sum+tmp)%9;
    }
    if(!sum) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}

Measured memory_bytes: 3732
package main
 
import(
  "fmt"
  "bufio"
  "os"
  "strings"
  "strconv"
  "log"
)
 

func main(){
  a,b := 0,0
  fmt.Scan(&a)
  min,max,sum := 1000000,-1000000,0
  for i := 0; i < a; i++{
    fmt.Scan(&b)
    if b < min{
      min = b
    }
    if b > max{
      max = b
    }
    sum+=b
  }
  fmt.Println(min,max,sum)
}


var sc = bufio.NewScanner(os.Stdin)

func Rr() []string {
  sc.Scan()
  slice := strings.Split(sc.Text(), " ")
  return slice
}



//入力関係ライブラリ(Atcoder:yamanobori_oldさんのもの)
func make_liner(maxByte int) *bufio.Scanner {
  liner := bufio.NewScanner(os.Stdin)
  liner.Buffer(make([]uint8, 0, 8192), maxByte)
  return liner
}
func word_spliter() *bufio.Scanner {
  words := make_liner(8192) 
  words.Split(bufio.ScanWords)
  return words
}

func eGetLine(r *bufio.Scanner) string {
  if r.Scan() {
    return r.Text()
  }
  err := r.Err()
  if err != nil {
    log.Fatal(err)
  }
  // EOF
  return ""
}

func eGetInt(r *bufio.Scanner) int {
  line := eGetLine(r)
  return eAtoi(line)
}

func eAtoi(s string) int {
  n, err := strconv.Atoi(s)
  if err != nil {
    log.Fatal(err)
  }
  return n
}


Measured memory_bytes: 1704
import Data.List

solver::[Int]->Int->Int->Int
solver ls n m = sum (take (m-n) (dif ls))

dif::[Int]->[Int]
dif ls = let srtd = sort ls in sort (map (\(a,b)->(a-b)) (zip (tail srtd) srtd))

main::IO()
main=do
  (n:m:_)<-(return.(map read).words)=<<getLine
  ls<-(return.(map read).words)=<<getLine
  print (solver ls n m)

Measured memory_bytes: 32764
import Control.Applicative
import Data.List

main :: IO ()
main = do
  { [n] <- readLineInputs :: IO [Int]
  ; xs  <- readLineInputs
  ; print $ solve xs
  }


{- |
>>> solve [1, 4]
5
>>> solve [14, 14, 2, 13, 56, 2, 37]
2354
-}
solve :: [Int] -> Int
solve xs = iter [1 .. 100] (maxBound :: Int)
  where
    iter []     e = e
    iter (p:ps) e = iter ps (min e (foldr ((+) . (^2) . subtract p) 0 xs))

readLineInputs :: Read a => IO [a]
readLineInputs = map read . words <$> getLine


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

int main(){
    string S;
    int N, i, place, move;

    cin >> S;
    N = S.size();
    vector<int> child(N);
    vector<int> loop(N);
    for(i = 0; i < N; i++){
        child[i] = 1;
        loop[i] = 0;
    }
    place = 0;
    while(1){
        move = place;
        if(S[place] == 'R'){
            while(S[move+1] != 'L')move++;
            if((move - place) % 2 == 0){
                loop[move] += (move - place) / 2 + 1;
                loop[move+1] += (move - place) / 2;
            }else{
                loop[move] += (move - place + 1) / 2;
                loop[move+1] += (move - place + 1) / 2;
            }
            place = move + 1;
        }else{
            while(S[move+1] != 'R' && move < N - 1)move++;
            if((move - place) % 2 == 0){
                loop[place] += (move - place) / 2 + 1;
                loop[place-1] += (move - place) / 2;
            }else{
                loop[place] += (move - place + 1) / 2;
                loop[place-1] += (move - place + 1) / 2;
            }
            place = move + 1;
        }
        if(place == N)break;
    }
    for(i = 0; i < N; i++){
        printf("%d", loop[i]);
        if(i != N - 1){
            printf(" ");
        }else{
            printf("\n");
        }
    }
}

Measured memory_bytes: 1408
from functools import reduce
from collections import deque
#import operator

#解説見た

def solve(N, K, A):
    MOD = int(1e9 + 7)
    A_plus = [x for x in A if x >= 0]
    A_plus.sort(reverse=True)
    A_minus = [x for x in A if x < 0]
    A_minus.sort()
    #print('+', len(A_plus))
    #print('-',len(A_minus))
    #from collections import Counter
    #print(Counter(A_plus))
    #print(Counter(A_minus))

    if K == 1:
        return max(A) % MOD
    if K == N:
        #ans = reduce(operator.mul, A)
        ans = 1
        for t in A:
            ans *= t
            ans %= MOD
        return ans % MOD

    if len(A_plus) == 0:
        #minusだけから選ぶ場合
        if K % 2 == 1:
            #答えは負になるので、絶対値が小さい順に積を取る
            ans = 1
            for t in list(reversed(A_minus))[:K]:
                ans *= t
                ans %= MOD
            return ans
        else:
            #答えは正になるので、絶対値が大きい順に積をとる
            ans = 1
            for t in A_minus[:K]:
                ans *= t
                ans %= MOD
            return ans
    
    k = K
    S = []
    A_plus = deque(A_plus)
    A_minus = deque(A_minus)
    if k % 2 == 1:
        t = A_plus.popleft()
        S.append(t)
        k -= 1
    #kは偶数になった
    assert k % 2 == 0
    while k > 0:
        if len(A_minus) < 2:
            #print('k',k)
            #print('+', list(A_plus))
            #print('-',list(A_minus))
            t1 = A_plus.popleft()
            S.append(t1)
            t2 = A_plus.popleft()
            S.append(t2)
            k -= 2
        elif len(A_plus) < 2:
            t1 = A_minus.popleft()
            S.append(t1)
            t2 = A_minus.popleft()
            S.append(t2)
            k -= 2
        else:
            t_p = A_plus[0] * A_plus[1]
            t_m = A_minus[0] * A_minus[1]
            if t_p >= t_m:
                t1 = A_plus.popleft()
                S.append(t1)
                t2 = A_plus.popleft()
                S.append(t2)
                assert t1 * t2 == t_p
                k -= 2
            else:
                t1 = A_minus.popleft()
                S.append(t1)
                t2 = A_minus.popleft()
                S.append(t2)
                assert t1 * t2 == t_m
                k -= 2
    #print(Counter(S))
    #print(len(S), K)
    ans = 1
    for t in S:
        ans *= t
        ans %= MOD
    return ans % MOD

if __name__ == "__main__":
    #with open('ABC173E/random_mz03.txt', 'r') as f:
    #    input = f.readline
    N, K = tuple(int(c) for c in input().split())
    A = [int(c) for c in input().split()]
    ret = solve(N, K, A)
    print(ret)

Measured memory_bytes: 110900
#include<stdio.h>
int main()
{
	char map[3][3];
	int i, j;
	for (i = 0; i < 3; i++)
	{
		for (j = 0; j < 3; j++)
		{
			scanf("%c", &map[i][j]);
			while(map[i][j]<'a'||map[i][j]>'z')
				scanf("%c", &map[i][j]);
		}
	}
	printf("%c%c%c",map[0][0],map[1][1],map[2][2]);
	return 0;
}


Measured memory_bytes: 128
import java.util.*;
 
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    String T = sc.next();
    for(int i = 0; i < N; i++){
      System.out.print(S.charAt(i));
      System.out.print(T.charAt(i));
    }
    System.out.println();
  }
}
    

Measured memory_bytes: 35668
X, Y, Z, K = map(int,input().split())
A_list = sorted(list(map(int,input().split())), reverse=True)
B_list = sorted(list(map(int,input().split())), reverse=True)
C_list = sorted(list(map(int,input().split())), reverse=True)

E_list = sorted([ai+bi for ai in A_list for bi in B_list], reverse=True)[:K]
sum_list = sorted([ei+ci for ei in E_list for ci in C_list], reverse=True)[:K]

for i in range(K):
    print(sum_list[i])


Measured memory_bytes: 184800
def main():
    from sys import stdin, setrecursionlimit
    #setrecursionlimit(10**9)
    #r = input()
    #n = int(input())
    #a, b = map(int, input().split())
    #s, y = input().split()
    #a = input().split()
    #a = [int(input()) for i in range(n)]
    #a = list(map(int, input().split()))
    #a = [list(map(int, input().split())) for i in range(n)]
    #a = [int(s) - 1 for s in input().split()]
    #l=[int(input()) for _ in range(int(input()))]
    #res = 0

    n,r=map(int, input().split())
    if n < 10:
        r += 100 * (10-n)
    print(r)

if __name__ == '__main__':
    main()


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

#define ll long long
#define pb push_back
#define mp make_pair
#define all(s) s.begin(),s.end()
#define ld long double

using namespace std;

const int maxn = 1e5 + 7;
const ld eps = 1e-6;
const ll inf = 1e9 + 7;

int n;
string a,b;
ll ans = 0;

int main() {
	cin >> n;
	cin >> a;
	cin >> b;
	if (a[0] == a[1]) {
		ans = 6;
	}
	else ans = 3;
	if (ans == 6) {
		int prev = 1;
		for (int i = 2; i < a.size();) {
			if (a[i] == a[i + 1]) {
				if (prev == 1) ans *= 3ll;
				else ans *= 2ll;
				prev = 1;
				ans %= inf;
				i+=2;
			}
			else {
				if (prev == 1) ans *= 1ll;
				else ans *= 2ll;
				prev = 2;
				ans %= inf;
				i++;
			}
		}
	}
	else {
		int prev = 2;
		for (int i = 1; i < a.size();) {
			if (a[i] == a[i + 1]) {
				if (prev == 2) ans *= 2ll;
				else ans *= 3ll;
				prev = 1;
				ans %= inf;
				i+=2;	
			}	
			else {
				if (prev == 2) ans *= 2ll;
				else ans *= 1ll;
				ans %= inf;
				i++;
				prev = 2;
			}
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
using namespace std;
int n;
int a[100005], b[100005];
int cnt, flag, ok;
int main()
{
	scanf("%d", &n);
	for(int i = 1; i <= n; i++)scanf("%d", &a[i]);
	for(int i = 1; i <= n - 1; i++)
	{
		if(!ok){
			if(a[i] < a[i + 1])flag = 1, ok = 1;
			else if(a[i] > a[i + 1])flag = 2, ok = 1;
			else continue;
		}
		if(a[i] < a[i + 1]){
			if(flag == 1)continue;
			else{
				cnt++;
				flag = 1;
				ok = 0;
			}
		}
		if(a[i] > a[i + 1]){
			if(flag == 2)continue;
			else{
				cnt++;
				flag = 2;
				ok = 0;
			}
		}
	}
	printf("%d\n", cnt + 1);
}

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

int gcd(int a, int b) {
    return b ? gcd(b, a%b) : a;
}

int main() {
    int n;
    cin >> n;
    int ans = 0;
    for (int i=0; i<n; i++) {
        int a;
        cin >> a;
        ans = gcd(ans, a);
    }
    cout << ans << endl;
}

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

#define _for(i,j,N) for(int i = (j);i < (N);i++)

using namespace std;
const int maxn = 300005;

string s;

int w[maxn];
int e[maxn];

int main()
{
    int N;
    scanf("%d",&N);
    cin >> s;
    int cnt = 0;
    _for(i,0,N){
        if(s[i] == 'W'){
            w[i] = cnt++;
        }
        else{
            w[i] = cnt;
        }
    }

    cnt = 0;
    for(int i = N-1; i  >= 0;i--){
        if(s[i] == 'E'){
            e[i] = cnt++;
        }
        else{
            e[i] = cnt;
        }
    }

    int res = maxn;
    _for(i,0,N){
        res = min(w[i] + e[i],res);
    }

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

    return 0;
}

Measured memory_bytes: 2948
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <math.h>
using namespace std;
int n,i,a[100000],cnt;
int main()
{
   scanf("%d",&n);
   for(i=0;i<n;i++) scanf("%d",&a[i]);
   for(i=0;i<n;i++)
    {
        if(a[i])
       {
          if(a[a[i]-1]==i+1)
        {
            cnt++;
            a[a[i]-1]=0;
        }
       }
    }
    printf("%d",cnt);
    return 0;
}


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

const ll INF = 1001001005;

vector<int> to[200005];

int main() {
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i,n) {
    cin >> a[i];
    a[i]--;
  }
  
/*  for (ll i = 0; i < (n); ++i){
    to[a[i]].push_back(i);
  }*/
  vector<int> check(n, -1);
  ll count=0;
  ll point=0;
  while(count <k){
    if(check[point]==-1){
      check[point]=count;
      count+=1;
      point=a[point];
    }
    else{
//      cout << count << ' ' << check[point] << endl;
//      cout << count - check[point] << endl;
//      cout << (727202214173249351 -5)%3 << endl;
      int c_value= (k-count)%(count - check[point]) + check[point];
//      cout << c_value << endl;
      rep(i,n){
        if(check[i]==c_value){
          cout << i+1 << endl;
          return 0;
        }
      }
    }    
  }
  cout << point+1 << endl;
  return 0;
}


Measured memory_bytes: 10388
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<iomanip>
#include<set>
#include<queue>

using namespace std;

int main()
{
	long long n,a,b;
	cin >> n >> a >> b;
	cout << (n/(a+b)*a+min(a,n-n/(a+b)*(a+b))) << endl;




}


Measured memory_bytes: 256
n,m = map(int, input().split())
AB = []
CD = []
for _ in range(n):
    AB.append(list(map(int, input().split())))
for _ in range(m):
    CD.append(list(map(int, input().split())))

ANS = [[] for _ in range(n)]
for i, (a,b) in enumerate(AB,1):
    ans = 10**9
    for j, (c,d) in enumerate(CD,1):
        dst = abs(a-c) + abs(b-d)
        if dst < ans:
            ans = dst
            ANS[i-1] = j
for a in ANS:
    print(a)


Measured memory_bytes: 3064
n_list=[]
x_list=[]
while True:
  n, x = map(int, input().split())
  if n == 0 and x == 0:
    break
  n_list.append(n)
  x_list.append(x)


for (nlist, xlist) in zip(n_list, x_list):
  a = 0
  for i in range(1, nlist+1):
    for j in range(i+1, nlist+1):
      for k in range(j+1, nlist+1):
        if i == j or j == k or i == k:
          continue
        if i + j + k == xlist:
          a = a + 1
  print(a)


Measured memory_bytes: 5600
package main

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

func main() {
	var (
		n       int
		a       = bufio.NewScanner(os.Stdin)
		reverse [100]string
	)

	a.Split(bufio.ScanWords)
	a.Scan()
	n, _ = strconv.Atoi(a.Text())
	for i := 0; i < n; i++ {
		a.Scan()
		reverse[n-i-1] = a.Text()
	}
	fmt.Println(strings.Join(reverse[0:n], " "))
}



Measured memory_bytes: 1116
#include<bits/stdc++.h>
#define int long long
#define fi first
#define se second
#define pii pair<int,int>
#define mp make_pair

using namespace std;
const int N=2e3+5;
int n,d[N][N],cnt[N];
vector<int>adj[N];
queue<int>pq;

void bfs(int x)
{
    d[x][x]=0;
    pq.push(x);
    while(!pq.empty())
    {
        int u=pq.front();
        pq.pop();
        for(auto&v:adj[u])
        {
            if(d[x][v]==-1)
            {
                d[x][v]=d[x][u]+1;
                pq.push(v);
            }
        }
    }
}

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    memset(d,-1,sizeof d);
    int x,y;
    cin>>n>>x>>y;
    adj[x].push_back(y);
    adj[y].push_back(x);
    for(int i=1;i<n;i++)
    {
        adj[i].push_back(i+1);
        adj[i+1].push_back(i);
    }
    for(int i=1;i<=n;i++) bfs(i);
    for(int i=1;i<=n;i++)
    {
        for(int j=i+1;j<=n;j++) cnt[d[i][j]]++;
    }
    for(int i=1;i<n;i++) cout<<cnt[i]<<'\n';
}


Measured memory_bytes: 31744
#include <iostream>
#include <vector>
#include <tuple>
#include <algorithm>
#include <set>
#include <string.h>

using namespace std;


int main()
{
	char buff[32];
	cin >> buff;

	int count = 0;
	for (int i = 0; i < strlen(buff); i++)
	{
		if (buff[i] == 'x')
		{
			count++;
		}
	}

	if (count >= 8)
	{
		cout << "NO" << endl;
	}
	else
	{
		cout << "YES" << endl;
	}

	return 0;
}


Measured memory_bytes: 256
package main

import (
        "fmt"
)

func solution(n, m int, k, p []int, s [][]int) int {

        out := 0

        for a := 0; a < 1<<uint(n); a++ {
                var ok bool = true
                for i := 0; i < m; i++ {
                        c := 0
                        for _, j := range s[i] {
                                if a>>uint(j-1)&1 == 0 {
                                        c++
                                }
                        }
                        c %= 2
                        if c != p[i] {
                                ok = false
                        }
                }
                if ok {
                        out++
                }
        }
        return out
}

func main() {
        var n, m int
        fmt.Scan(&n, &m)
        k := make([]int, m)
        s := make([][]int, m)
        for i := range k {
                fmt.Scan(&k[i])
                s[i] = make([]int, k[i])
                for j := range s[i] {
                        fmt.Scan(&s[i][j])
                }
        }
        p := make([]int, m)
        for i := range p {
                fmt.Scan(&p[i])
        }
        fmt.Println(solution(n, m, k, p, s))
}

Measured memory_bytes: 1844
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define INF 1<<30
#define LINF 1LL<<60
ll N,K;
vector<ll> w,d;
bool check(ll m){
    ll cnt = 0;
    for(int i = 0; i < N;i++){
        if(m < w[i]) continue;
        cnt += (m - w[i])/d[i] + 1;
        if(cnt > K) return false;
    }
    if(cnt == K) return false;
    return true;
}
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    cin >> N >> K;
    w.resize(N); d.resize(N);
    for(int i = 0; i < N;i++) cin >> w[i] >> d[i];
    ll l = 0, r = LLONG_MAX;
    for(int kassa = 0; kassa < 100; kassa++){
        ll mid = l + (r-l)/2LL;
        if(check(mid)){
            l = mid;
        }else{
            r = mid;
        }
    }
    cout << r << endl;
    return 0;
}


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

int main() {
    ll n;
    cin>>n;
    V a(n);
    V num(3e5,0);
    rep(i,n){
        cin>>a[i];
        num[a[i]]++;
    }
    ll sum=0;
    rep(i,3e5){
        sum+=num[i]*(num[i]-1)/2;
    }
    rep(i,n){
        cout<<sum-num[a[i]]*(num[a[i]]-1)/2+(num[a[i]]-1)*(num[a[i]]-2)/2<<endl;
    }
}


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

typedef long long ll;
typedef long double ld;
typedef pair <ll, ll> pll;

#define pb push_back
#define mp make_pair
#define all(_c) _c.begin(), _c.end()

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

    string s;
    cin >> s;

    int ans = INT_MAX;

    int req_c = 0, ch = 0;
    for (auto c : s) {
        if (c != char(req_c + '0'))
            ch++;
        req_c ^= 1;
    }
    ans = min(ans, ch);

    req_c = 1, ch = 0;
    for (auto c : s) {
        if (c != char(req_c + '0'))
            ch++;
        req_c ^= 1;
    }
    ans = min(ans, ch);

    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define watch(x) cout << (#x) << " is " << (x) << endl
typedef long long ll;
using namespace std;
int static fast = [](){
  ios::sync_with_stdio(false);
  cin.tie(0); cout.tie(0); return 0;
}();
// freopen("input.txt", "r", stdin);

int main() {
    ll n, k;
    cin >> n >> k;
    ll ans = 0, mod = 1e9 + 7;
    for(ll i = k; i <= n+1; i++) {
        ll lower = (0+(i-1)) * i / 2;
        ll upper = (n + n-i+1) * i / 2;
        ans += (upper - lower+1);
        ans %= mod;
    }
    cout << ans << endl;
    return 0;
}




Measured memory_bytes: 3652
a = input()
c = 0
for i in range(2,len(a)-1):
    if a[i] == "C":
        b=a[:i]+a[i+1:]
        c +=1
if a[0]=="A" and c==1 and b[1:].islower():
    print("AC")
else:
    print("WA")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cstring>

using namespace std;

int a[31],b[31],dp[31][1<<16];

int count(int num){
  int res=0;
  for(int i=0;i<16;i++)
    if(num & (1<<i))res++;
  return res;
}

int main(void){

  int n,c,in;

  while(cin >> n >> c,n|c){
    
    fill(a,a+n,0);
    fill(b,b+c,0);

    for(int i=0;i<n;i++){
      for(int j=0;j<16;j++){
	cin >> in;
	a[i] |= in<<(15-j);
      }
    }

    for(int i=0;i<c;i++){
      for(int j=0;j<16;j++){
	cin >> in;
	b[i] |= in<<15-j;
      }
    }

    memset(dp,-1,sizeof(dp));

    dp[0][0]=0;

    for(int i=0;i<n;i++){
      for(int j=0;j<(1<<16);j++){
	if(dp[i][j]<0)continue;
	int now=a[i]|j;

	for(int k=0;k<c;k++){
	  int next=now & ~b[k];
	  dp[i+1][next]=max(dp[i+1][next],dp[i][j]+count(now & b[k]));
	}
      }
    }
    int ans=0;
    for(int i=0;i<(1<<16);i++){
      ans=max(ans,dp[n][i]);
    }
    cout << ans << endl;
  }


  return 0;
}

Measured memory_bytes: 9104
#include<iostream>
#include<algorithm>
#include<string>
#include<map>
#include<set>
#include<vector>
#include<string.h>
#include<math.h>
#include<stdio.h>
#include<queue>
#include<utility>
#include<cstdio>
#include<cstring>
#include<new>
#include<float.h>
#include<ctype.h>
#include<cfloat>
#include<cmath>
#include<cctype>
#include<errno.h>
#include<cerrno>
#include<memory>
#include<memory.h>
#include<assert.h>
#include<cassert>
#include<deque>
#include<sstream>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qui queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define sz size()
#define em empty()
#define ct continue
#define ms multiset
#define all(a) (a).begin(),(a).end()
#define pf push_front
#define ppf pop_front()
#define fi first
#define se second
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
int n,k,a[101010],b[101009];
int gcd(int x,int y){
	if(x%y==0)return y;
	return gcd(y,x%y);
}
int main()
{
	cin>>n>>k;
	fo(i,0,n)cin>>a[i];
	a[n]=k;
	sort(a,a+n+1);
	fo(i,0,n)b[i]=a[i+1]-a[i];
	sort(b,b+n);
	int ans=b[n-1];
	fo(i,0,n)if(b[i])ans=gcd(ans,b[i]);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O25")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
8
7 3 5 4 2 1 6 8
3 8 2 5 4 6 7 1
)X";
stringstream iss{text};
#endif

class CountOrder
{
	ll N{0};
	vector<ll> p, q;
	void inp( ) {
		iss >> N; p.resize(N); q.resize(N);
		rep(n, N) { iss >> p[n]; }
		rep(n, N) { iss >> q[n]; }
		//for_each(begin(p), end(p), [](auto x) { cout << x << "\n"; });
	}
	void change( ) {
		long long sa{0};
		if (p > q) swap(p, q);
		do {
			if (p == q) break;
			++sa;
		} while (next_permutation(begin(p), end(p)));
		p(sa);
	}
public:
	void procedures( ) {
		inp( );
		change( );
	}
};
//https://atcoder.jp/contests/abc145/tasks/abc145_c
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	class CountOrder a; a.procedures( );
}

Measured memory_bytes: 3632
#include <stdio.h>
#include <math.h>
#include <stdlib.h>

int sq_map[150][150];
int sq_map_index = 0;

int main()
{
	for (sq_map_index = 0; sq_map_index < 150; sq_map_index++)
		for (int i = sq_map_index; i < 150; i++)
			sq_map[sq_map_index][i] = sq_map_index * sq_map_index + i * i;

	int input1, input2, counter;
	char output;
	for (scanf("%d", &counter); counter > 0; counter--)
	{
		scanf("%d %d", &input1, &input2);
		int x, y, m, n, p, q, temp;
		p = input1 * input1;
		q = input2 * input2;
		for (m = 0; m < 150; m++)
		{
			if (sq_map[m][m] > (p + q))
				break;
			for (n = m; n < 150; n++)
			{
				if (sq_map[m][n] > (p + q))
					break;
				if (m + n <= 1)
					continue;
				if ((p + q) % (sq_map[m][n]) == 0)
				{
					temp = (p + q) / (sq_map[m][n]);
					for (x = 0; x < 150; x++)
					{
						if (sq_map[x][x] > (p + q))
							break;
						for (y = x; y < 150; y++)
						{
							if (x + y <= 1)
								continue;
							if (sq_map[x][y] > (p + q))
								break;
							if (temp == (sq_map[x][y]))
							{
								goto C_END;
							}
						}
					}
				}
			}
		}
		printf("%c\n", 'P');
		continue;
	C_END:
		printf("%c\n", 'C');
	}
	return 0;
}


Measured memory_bytes: 2008
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <stack>
#include <queue>
#include <string>
#include <sstream>
#include <unordered_set>
#include <unordered_map>

using namespace std;

int main() {
    int n;
    cin>>n;
    if (n%1000 == 0) cout<<0<<endl;
    else cout<<1000 - (n%1000)<<endl;
    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <string>

using namespace std;

int main(){
    int N; cin >> N;
    int check = 0;
    
    for (int i = 0; i < 4; i++)
    {
      check = N%10;
      if (check == 7)
      {
        cout << "Yes" << endl;
        return 0;
      }
      N /= 10;      
    }
    
    cout << "No" << endl;
    return 0;
    
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define INF 1000000000
#define LINF 1000000000000000000
#define MOD 1000000007
#define mod 1000007
#define INF63 1061109567
#define INF127 9187201950435737471
#define UINF 18446744073709551615
#define F first
#define S second
#define ll long long
#define N 200010
#define HASH 813234241
using namespace std;
ll n,a[N],b[N],dxa[N],dxb[N],phs=0,ehs=0,pres;
ll ksm(ll x,ll y)
{
	if(y==0)
	{
		return 1;
	}
	if(y==1)
	{
		return x;
	}
	ll ret=ksm(x,y/2);
	if(y%2==1)
	{
		return (((ret*ret)%MOD)*x)%MOD;
	}
	return (ret*ret)%MOD;
}
int main(){
	ll i,j,cnt=0;
	cin>>n;
	for(i=0;i<n;i++)
	{
		cin>>a[i];
	}
	for(i=0;i<n;i++)
	{
		cin>>b[i];
	}
	for(i=0;i<n;i++)
	{
		dxa[i]=a[i]^a[(i+1)%n];
		phs=(phs*HASH+dxa[i])%MOD;
	}
	for(i=0;i<n;i++)
	{
		dxb[i]=b[i]^b[(i+1)%n];
		ehs=(ehs*HASH+dxb[i])%MOD;
	}
	pres=ksm(HASH,n-1);
	for(i=0;i<n;i++)
	{
		if(phs==ehs)
		{
			cout<<i<<" "<<(a[0]^b[(n-i)%n])<<endl;
		}
		phs=(((phs-(pres*dxa[i])%MOD)%MOD)+MOD)%MOD;//减去多余的前缀 
		phs=(phs*HASH+dxa[i])%MOD;//加上第i个 
	}
	return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1e9 + 7;

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

    int n;
    long long k;
    cin >> n >> k;
    vector<long long> A(n);
    for(int i = 0; i < n; i++){
        cin >> A[i];
    }

    long long ans = 0;
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
            long long t = 0;
            if(A[i] > A[j]){
                t = k * (1 + k) / 2;
            }else if(A[i] < A[j]){
                t = k * (k - 1) / 2;
            }
            ans = (ans + t % MOD) % MOD;
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
        char a;
        cin >> a;

        if (a == 'A') {
                cout << 'T';
        }else if (a == 'G'){
                cout << 'C';
        }else if (a == 'T') {
                cout << 'A';
        }else if (a == 'C') {
                cout << 'G';
        }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REPR(i, n) for(int i = (n); i >= 0; i--)
#define FOR(i, m, n) for(int i = (m); i < (n); i++)
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << ": " << x << endl;

using namespace std;
typedef long long ll;

signed main() {
  int a, b, k;
  cin >> a >> b >> k;
  int s = max(a, b);
  vector<int> x;
  for(int n = s; n > 0; n--) {
    if(a % n == 0 && b % n == 0) x.push_back(n);
  }
  cout << x[k - 1] << endl;
  return 0;
}


Measured memory_bytes: 256
s = input()

def dfs(i,tmp,sum):
    if i == 3:
        if sum == 7:
            print(tmp + "=7")
            exit()

    else:
        dfs(i+1, tmp +"+"+ s[i+1], sum + int(s[i+1]))
        dfs(i+1, tmp +"-"+ s[i+1], sum - int(s[i+1]))

print(dfs(0,s[0],int(s[0])))

Measured memory_bytes: 9108
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define between(a,x,b) ((a)<=(x)&&(x)<=(b))
using namespace std;

int main(){
  int N, M, dx[] = {0,1,0,-1}, dy[] = {1,0,-1,0};
  while(scanf("%d", &N) && N){
    int x[32], y[32];
    rep(i, N) scanf("%d%d", x+i, y+i);
    scanf("%d", &M);
    int nx = 10, ny = 10, dis, d;
    bool field[21][21] = {};
    field[ny][nx] = true;
    char com[4];
    rep(i, M){
      scanf("%s%d", com, &dis);
      switch(com[0]){
      case 'N': d = 0; break;
      case 'E': d = 1; break;
      case 'S': d = 2; break;
      case 'W': d = 3; break;
      }
      rep(j, dis){
	nx += dx[d]; ny += dy[d];
	field[ny][nx] = true;
      }
    }
    /*    rep(i, 21){
      rep(j, 21) printf("%d ", field[i][j]?1:0);
      puts("");
      }*/
    bool f = true;
    rep(i, N)
      if(!field[y[i]][x[i]]) f = false;
    if(f) puts("Yes");
    else puts("No");
  }
  return 0;
}

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

int main(void){
  while(true){
    int r0, w, c, r;
    cin >> r0 >> w >> c >> r;
    if(r0 == 0 && w == 0 && c == 0 && r == 0){ break; }

    int x = (c * w - r0 + (r - 1)) / r;
    cout << (x > 0 ? x : 0) << endl;
  }

  return 0;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
using namespace std;
//#define cerr if (false) cerr
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << "," << #y << "=" << y << endl
#define db3(x, y, z) cerr << #x << "=" << x << "," << #y << "=" << y << "," << #z << "=" << z << endl
#define dbv(v) cerr << #v << "="; for (auto _x : v) cerr << _x << ", "; cerr << endl
#define dba(a, n) cerr << #a << "="; for (int _i = 0; _i < (n); ++_i) cerr << a[_i] << ", "; cerr << endl
template <typename A, typename B>
ostream& operator<<(ostream& os, const pair<A, B>& x) {
	return os << "(" << x.first << "," << x.second << ")";
}
typedef long long ll;
typedef long double ld;
char str[55];
int main() {
	int n;
	scanf("%d", &n);
	vector<int> ans(26, INT_MAX);
	for (int i = 0; i < n; ++i) {
		scanf("%s", str);
		vector<int> cnt(26);
		int len = strlen(str);
		for (int j = 0; j < len; ++j) {
			++cnt[str[j] - 'a'];
		}
		for (int j = 0; j < 26; ++j) ans[j] = min(ans[j], cnt[j]);
	}
	string output;
	for (int j = 0; j < 26; ++j) output += string(ans[j], j + 'a');
	printf("%s\n", output.c_str());
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
using ll=long long;
using vi=vector<int>;
using vl=vector<long long>;
using pii=pair<int,int>;
using pll=pair<long long,long long>;
#define ITR(i,c) for(auto i=begin(c);i!=end(c);++i)
#define FORE(x,c) for(auto &x:c)
#define REPF(i,a,n) for(int i=a,i##len=(int)(n);i<i##len;++i)
#define REP(i,n) REPF(i,0,n)
#define REPR(i,n) for(int i=(int)(n);i>=0;--i)
#define REPW(i,n) for(i=0;i<(int)(n);++i)
#define ALL(c) begin(c),end(c)
#define RALL(c) rbegin(c),rend(c)   // c++14
#define SZ(c) ((int)c.size())
#define EXIST(c,x) (c.find(x)!=end(c))
#define OUTOFRANGE(y,x,h,w) (y<0||x<0||y>=h||x>=w)
#define dump(...)
const int DX[9]={0,1,0,-1,1,1,-1,-1,0},DY[9]={-1,0,1,0,-1,1,1,-1,0};
#define INF (1001001001)
#define INFLL (1001001001001001001ll)
template<class T> ostream& operator << (ostream &os,const vector<T> &v) {
    ITR(i,v) os << *i << (i==end(v)-1 ? "" : "\n"); return os; }
template<class T> istream& operator >> (istream &is,vector<T> &v) {
    ITR(i,v) is >> * i; return is; }
template<class T> istream& operator >> (istream &is, pair<T,T> &p) {
        is >> p.first >> p.second; return is; }
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
//------------------------------------------------------------------------------
struct before_main_function {
    before_main_function() {
        #ifdef int
            #undef INF
            #define INF INFLL
            #define stoi stoll
        #endif
        cin.tie(0);ios::sync_with_stdio(false);
        cout<<setprecision(15)<<fixed;
    }
} before_main_function;
//------------------------------------------------------------------------------

const int MOD=1e9+7;
const int MAX_N=100010;
long long fact[MAX_N+1];
long long fact_inv[MAX_N+1];
long long bin_pow_mod(long long x,long long y) {
      if(x==0) return 0;
      long long prod=1;
      while(y>0) {
          if(y&1) {
              prod=(prod*x)%MOD;
          }
          x=(x*x)%MOD;
          y>>=1;
      }
      return prod%MOD;
}
inline long long nCr_mod(long long n,long long r) {
    if(n<r) return 0;
    return (((fact[n]*fact_inv[r])%MOD)*fact_inv[n-r])%MOD;
}
void init_fact() {
    fact[0]=1, fact_inv[0]=1;
    REPF(i,1,MAX_N+1) {
        fact[i]=(fact[i-1]*i)%MOD;
        fact_inv[i]=bin_pow_mod(fact[i],MOD-2);
    }
}
signed main() {
    init_fact();

    int n;
    cin>>n;
    int dup;
    unordered_set<int> exist;
    vi a(n+1);
    int left=-1,right;
    int t=0;
    REP(i,n+1) {
        cin>>a[i];
        if(EXIST(exist, a[i])) {
            dup=a[i];
        }
        exist.insert(a[i]);
    }
    REP(i,n+1) {
        if(a[i]==dup) {
            if(left==-1) left=t;
            else t=0;
        }
        else t++;
    }
    right=t;


    REP(i,n+1) {
        cout<<(nCr_mod(n+1,i+1)-nCr_mod(left+right,i)+MOD)%MOD<<endl;
    }
    return 0;
}


Measured memory_bytes: 7716
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		while (in.hasNext()) {
			long a = in.nextLong();
			long b = in.nextLong();
			long c = LCM(a, b);
			long d = a * b / c;
			System.out.println(c + " " + d);
		}
	}
	
	static long LCM(long a, long b) {
		if (b == 0) {
			return a;
		} else {
			return LCM(b, a % b);
		}
	}
}

Measured memory_bytes: 17216
#include<bits/stdc++.h>
using namespace std;
using ll=int64_t;
ll gcd(ll a,ll b){
  if(a%b==0)return b;
  else return gcd(b,a%b);
}

int main(){
  ll n;cin>>n;
  ll tmp1;
  cin>>tmp1;
  ll tmp2;
  for(int i=1;i<n;i++){
    cin>>tmp2;
    tmp1=tmp1/gcd(tmp1,tmp2)*tmp2;
  }
  cout <<tmp1<<endl;
}

Measured memory_bytes: 3564