akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
// #define LOG(...)
#define FOR(i, a, b) for(int i = (int)(a); i < (int)(b); ++i)
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for(int i = (int)(n - 1); i >= 0; --i)
#define RFOR(i, a, b) for(int i = (int)(b - 1); i >= (int)(a); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SQ(n) (n) * (n)
#define BIT(x, i) (((x) >> (i)) & 1)

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<pii> vpi;
typedef vector<pll> vpl;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vc> vvc;
typedef vector<vll> vvll;

char field[70][70];
string dp[70][70];

string strmax(string a, string b) {
  if (a.length() > b.length()) return a;
  if (a.length() < b.length()) return b;
  return max(a, b);
}

int dx[] = {-1, 0};
int dy[] = {0, -1};

int main() {
  int w, h;
  while(cin >> w >> h, w) {
    fill_n((char*)field, 70 * 70, ' ');
    fill_n((string*)dp, 70 * 70, "");
    REP(y, h) REP(x, w) {
      cin >> field[y][x];
      if (isdigit(field[y][x]))
        dp[y][x] = field[y][x];
    }

    string maxs = "";
    RREP(y, h) RREP(x, w) {
      REP(i, 2){
        int sx = x + dx[i];
        int sy = y + dy[i];
        if (sx < 0 || sx >= w || sy < 0 || sy >= h) continue;
        if (isdigit(field[y][x]) && isdigit(field[sy][sx])) {
          dp[sy][sx] = strmax(dp[sy][sx], field[sy][sx] + dp[y][x]);
          // maxs = strmax(maxs, dp[sy][sx]);
        }
      }
    }

    REP(y, h) REP(x, w) {
      while(*dp[y][x].begin() == '0') dp[y][x].erase(dp[y][x].begin());
      maxs = strmax(maxs, dp[y][x]);
    }
    cout << maxs << endl;
  }
}

Measured memory_bytes: 3280
import bisect
import heapq
import itertools
import math
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

# N, A, B = list(map(int, sys.stdin.readline().split()))
# print(min(A*N, B))


N, D = list(map(int, sys.stdin.readline().split()))
X = [list(map(int, sys.stdin.readline().split())) for _ in range(N)]


ans = 0
for i, j in itertools.combinations(range(N), r=2):
    a = X[i]
    b = X[j]
    r = 0
    for aa, ba in zip(a, b):
        r += (aa - ba) ** 2
    ans += int(math.sqrt(r)) ** 2 == r
print(ans)


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

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

  vector<int> a(n);
  vector<int> b(n);

  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }

  for (int i = 0; i < n; i++) {
    int j;
    for (j = n - i - 1; j >= 0; j--) {
      if (b[j] == j + 1) {
        a[i] = j + 1;
        for (int k = j; k < n - i - 1; k++) {
          b[k] = b[k + 1];
        }
        break;
      }
    }
    if (j < 0) {
      cout << "-1" << endl;
      return 0;
    }
  }

  reverse(a.begin(), a.end());
  for (int x : a) {
    cout << x << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define pll pair<LL,LL>
#define x first
#define y second
#define N 131072
#define pi acos(-1)
#define sqr(x) ((x)*(x))
#define pdd pair<double,double>
#define MEMS(x) memset(x,-1,sizeof(x))
#define MEM(x) memset(x,0,sizeof(x))
int main(){
    int n,a,b,c,d;
    scanf("%d %d %d %d %d",&n,&a,&b,&c,&d);
    char cc[200005];
    scanf("%s",cc+1);
    if(c<d){
        for(int i = b;i<=d;i++){
            if(cc[i]=='#'&&cc[i+1]=='#'){
                printf("No\n");
                return 0;
            }
        }
        for(int i = a;i<=c;i++){
            if(cc[i]=='#'&&cc[i+1]=='#'){
                printf("No\n");
                return 0;
            }
        }
        printf("Yes\n");
    }
    else{
        for(int i = a;i<=c;i++){
            if(cc[i]=='#'&&cc[i+1]=='#'){
                printf("No\n");
                return 0;
            }
        }
        int ok=0;
        for(int i = b;i<=d;i++){
            if(cc[i]=='.'&&cc[i-1]=='.'&&cc[i+1]=='.'){
                ok=1;break;
            }
        }
        if(ok){
            printf("Yes\n");
        }
        else{
            printf("No\n");
        }
    }
}
/*
0.5 0.5
0.5 0.25
0.25 0.125
0.25
*/

Measured memory_bytes: 384
a = list(input())
k,u,p,c = 0,0,0,0

for i in range(len(a)):
    if a[i]=="K":
        k += 1
    elif a[i]=="U":
        u += 1
    elif a[i]=="P":
        p += 1
    elif a[i]=="C":
        c += 1
    else:
        pass
    
print(min(k,u,p,c))


Measured memory_bytes: 5564
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <queue>

int main(){
    for(;;){
        int w,h;
        std::cin >> w >> h;
        if ( ( w == 0 ) && ( h == 0 ) ){return 0;}
        std::vector<char> map(w*h);
        std::vector<int> sw(w*h); for( auto v : sw ){ v=0; }
        std::queue<int> queue;
        int person;
        for( int i=0; i<static_cast<int>(map.size()); ++i ){ std::cin >> map[i]; if (map[i]=='@'){person=i;} }
        queue.push(person);
        while( !queue.empty() ){
            int t = queue.front(); queue.pop();
            if ( map[t] == '#' ){continue;}
            if (sw[t]){
                continue;
            } else {
                sw[t] = 1;
            }
            if ( ( (t+1)%w ) && ( t+1 < w*h ) ){ queue.push(t+1); }
            if ( t+w < w*h ){ queue.push(t+w); }
            if ( (t%w) && ( 0 <= t-1 ) ){ queue.push(t-1); }
            if ( 0 <= t-w ){ queue.push(t-w); }
        }
        std::cout << std::accumulate(sw.begin(),sw.end(),0) << std::endl;
    }
}


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

int main() {
    int N, L;
    cin >> N >> L;
    string S[N];
    for(int i = 0; i < N; i++) {
        cin >> S[i];
    }
    sort(S, S+N);
    for(int i = 0; i < N; i++) {
        cout << S[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
//DEEPANSHU RAWAT
/*************************************************************************************************************************/


#include<bits/stdc++.h>
#define ull unsigned long long
#define lld long long int
#define infi 1e9
#define ninfi LLONG_MIN
#define ff first
#define ss second
#define pb push_back    
#define mp make_pair
#define ee endl
#define mod 1000000007 
#define isPowerOfTwo(S) (!(S & (S - 1)))
#define nearestPowerOfTwo(S) ((int)pow(2.0, (int)((log((double)S) / log(2.0)) + 0.5)))
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define pq priority_queue<int,vector<int>,greater<int>>

using namespace std ;
/*************************************************************************************************************************/

vector<lld>dp(100001,-1);
lld ans=0;
lld minCost(vector<lld>& v,lld n){
	
	if(dp[n-1]!=-1){
		cout<<"edce";
		return dp[n-1];
	}
	dp[0]=0;
	dp[1]=abs(v[1]-v[0]);
	for(lld i=2;i<n;i++){
		dp[i]=min(dp[i-1]+abs(v[i-1]-v[i]),dp[i-2]+abs(v[i-2]-v[i]));

	}
	return dp[n-1];
}
/**************************************************************************************************************************/
int main()
{
       
  ios_base::sync_with_stdio(false);   
  cin.tie(NULL);
  
  
  lld n;
  cin>>n;
  vector<lld>v(n);
  for(lld i=0;i<n;i++){
  	cin>>v[i];
  }

  cout<<minCost(v,n);
}

    
   

/**************************************************************************************************************************/                                                                                                                                                                                                                                                                                                                

Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll inf=1000000007;
const ll maxinput=100005;
const ll mod=998244353;
#define mp make_pair
int main()
{
    int n;cin>>n;
    int h[n];for(int i=0;i<n;i++)cin>>h[i];

    int dp[n]; //dp[i] is the minimum cost of reaching stone i
    dp[0]=0;dp[1]=abs(h[1]-h[0]);
    for(int i=2;i<n;i++)
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i-2]-h[i]));
    cout<<dp[n-1]<<"\n";
}

Measured memory_bytes: 1024
N,M=map(int,input().split())
L=[0]*M
R=[0]*M
for i in range(M):
  L[i],R[i]=map(int,input().split())
if M==1:
  print(R[0]-L[0]+1)
else:
  for i in range(M-1):
    L[i+1]=max(L[i],L[i+1])
    R[i+1]=min(R[i],R[i+1])
  if R[M-1]>=L[M-1]:
    print(R[M-1]-L[M-1]+1)
  else:
    print(0)

Measured memory_bytes: 10996
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>
#include <iomanip>
int main()
{
    long N;
    std::cin >> N;
    std::string S;
    std::cin >> S;
    long count=0;
    std::vector<long> counters;
    for(long i=1; i<N; i++){
        if(S[i]=='E'){
            count++;
        }
    }
    counters.push_back(count);
    for(long i=1; i<N; i++){
        if(S[i]=='E'){
            count-=1;
        }
        if(S[i-1]=='W'){
            count++;
        }
        counters.push_back(count);
    }
    std::sort(counters.begin(),counters.end());
    std::cout << counters[0] << std::endl;
    return 0;
}

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

const int MAX = 100001;

struct Edge
{
    int n;
    int u;
} E[2*MAX];
int ee;

std::vector<int> V[MAX];
int C[MAX];
bool VIS[MAX];
int n, k;

void DFS(int v, int c)
{
    k = std::max(c, k);
    VIS[v] = true;
    int cc = 1;
    for (int u : V[v])
        if (!VIS[E[u].u])
        {
            if (cc == c) ++cc;
            C[E[u].n] = cc;
            DFS(E[u].u, cc);
            ++cc;
        }
}

int main()
{
    std::ios_base::sync_with_stdio(0);
    std::cin >> n;
    for (int i=1;i<n;++i)
    {
        int a,b;
        std::cin >> a >> b;
        
        E[ee] = {i, b};
        V[a].push_back(ee);
        ++ee;
        E[ee] = {i, a};
        V[b].push_back(ee);
        ++ee;
    }
    DFS(1, 0);
    std::cout << k << std::endl;
    for (int i=1;i<n;++i) std::cout << C[i] << std::endl;
    return 0;
}

Measured memory_bytes: 8832
# include <iostream>
# define MAX 100002

using namespace std;

int p[MAX] = {}; // 0: 未チェック, 1: 素数, 2: 合成数
int S[MAX]; // 2017-like numberの数の累積和
int Q;
int L[MAX], R[MAX];

int main(){
    p[2] = 1;
    for ( int i = 2; i < MAX; i++){
        if ( p[i] == 2) { continue; }
        else {
            p[i] = 1;
            for ( int j = 2; i * j < MAX; j++){ p[i*j] = 2; }
        }
    }

    S[0] = 0;
    for ( int i = 1; i < MAX; i ++ ){
        if ( i % 2 == 1 && p[i] == 1 && p[ (i + 1) / 2] == 1 ) { S[i] = S[i-1] + 1; }
        else { S[i] = S[i-1]; }
    }
    
    cin >> Q;
    for ( int i = 0; i < Q; i++) { cin >> L[i] >> R[i]; }
    
    for ( int i = 0; i < Q; i++) {
        cout << S[ R[i] ] - S[ L[i] - 1 ] << endl;
    }
    
    return 0;
}

Measured memory_bytes: 2176
n,m = map(int,input().split())
H = list(map(int,input().split()))
p = [0]*n
for i in range(m):
    a,b = map(int,input().split())
    if H[a-1] >= H[b-1]:
        p[b-1] = -1
    if H[a-1] <= H[b-1]:
        p[a-1] = -1
print(p.count(0))


Measured memory_bytes: 20032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1000000009;

int main(){
  int A,B;cin >> A >> B;
  for(int i=0;i<=10000;i++){
    if((i*8)/100==A&&i/10==B){
      cout << i << endl;
      return 0;
    }
  }
  cout << -1 << endl;
}

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

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    int ans = 0;
    for(int i = 1; i <= n; i+=2) {
        int count = 0;
        for(int j = 1; j <= i; j++) {
            if(i % j == 0) count++;
        }
        if(count == 8) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, log2
from itertools import accumulate, permutations, combinations, product, groupby
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

H, W = MAP()
C = [input() for _ in range(H)]

for i in range(H):
	print(C[i])
	print(C[i])

Measured memory_bytes: 13788
package main

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

func main() {
	N := readInt()

	if N == 2 {
		// K = 2
		fmt.Println(1)
		return
	}

	r := int(math.Sqrt(float64(N)))
	// K = N - 1, N
	result := 2
	for K := 2; K <= r; K++ {
		t := N
		for t >= K && t%K == 0 {
			t /= K
		}
		if t%K == 1 {
			result++
		}

		if (N-1)%K != 0 {
			continue
		}
		k := (N - 1) / K
		if k <= K {
			continue
		}
		t = N
		for t >= k && t%k == 0 {
			t /= k
		}
		if t%k == 1 {
			result++
		}
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}

func readInts(n int) []int {
	result := make([]int, n)
	for i := 0; i < n; i++ {
		result[i] = readInt()
	}
	return result
}


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

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

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

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
     
def main():
    N = I()
    D = []
    zoro = 0
    ans = 0
    for _ in range(N):
        d1, d2 = LI()
        if d1 == d2:
            zoro += 1
            ans = max(ans, zoro)
        else:
            zoro = 0
    if ans >= 3:
        print("Yes")
    else:
        print("No")



main()



Measured memory_bytes: 83712
#include<stdio.h>
int main(){
	int S, h, m, s;
	scanf("%d", &S);
	m = S/3600;
	h = (S-m*3600)/60;
	s = (S%3600)%60;
	printf("%d:%d:%d\n",m ,h ,s);
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
int done[200010][2], memo[200010][2], n;
char inp[200010];
int dp(int a, int b)
{
	if (a == n) return 0;
	if (done[a][b]) return memo[a][b];
	done[a][b] = 1;
	int ans = -1e9;
	if (b == 1 || inp[a] != inp[a-1]) ans = dp(a+1, 0)+1;
	if (a != n-1 && (b == 0 || (inp[a-1] != inp[a+1] || inp[a-2] != inp[a]))) ans = max(ans, dp(a+2, 1)+1);
	return memo[a][b] = ans;
}
int main()
{
	scanf(" %s", inp);
	n = strlen(inp);
	int ans = max(dp(1, 0), dp(2, 1))+1;
	printf("%d\n", ans);
}

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

int main() {
  int N,a,b,c,d;
  cin >> N;
  a = N / 1000;
  b = (N - a * 1000) / 100;
  c = (N - (a * 1000 + b * 100)) / 10;
  d = N % 10;
  if ((a == b && b == c)||(b == c && c == d)){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
# 15分程度
# 急がば回れ.たくさん回すより少し落ちつくことが大切.

d,n = map(int, input().split())

if d == 0:
    if n == 100:
        print(101)
    else:
        print(n)
elif d == 1:
    if n ==100:
        print(10100)
    else:
        print(100*n)
else:
    if n == 100:
        print(1010000)
    else:
        print(10000*n)


Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>
#include <vector>
#include <math.h>
#include <bitset>
#include <cmath>
#include <set>

#define rep(i,s,n)for(int i = s;i<n;i++)
#define repe(i,s,n)for(int i = s;i<=n;i++)
#define rep_r(i,s,n)for(int i = n-1;i>=s;i--)
#define rep_re(i,s,n)for(int i = n;i>=s;i--)
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;
static const ll INF = 1e25;
static const ll MAX_N = 100001;
static const ll MAX_M = 100001;

ll a[4001];
ll b[4001];
ll c[4001];
int main() {
	ll n, k; cin >> n >> k;
	rep(i, 0, n) {
		ll A; cin >> A;
		a[i] = A;
		a[i + n] = A;
	}
	rep(i, 0, n) {
		rep(j, i + 1, n) {
			if (a[i] > a[j]) {
				b[i]++;
			}
		}
	}
	rep(i, 0, n) {
		rep(j, 0, n) {
			if (a[i] > a[j]) {
				c[i]++;
			}
		}
	}

	//rep(i, 0, n) {
	//	rep(j, i + 1, 2 * n) {
	//		if (j < n) {
	//			if (a[i] > a[j]) {
	//				b[i]++;
	//			}
	//		}
	//		else {
	//			if (a[i] > a[j]) {
	//				c[i]++;
	//			}
	//		}
	//	}
	//}

	ll ans = 0;
	rep(i, 0, n) {
		b[i] %= MOD;
		c[i] %= MOD;
		ll K = (k * (k - 1) / 2) % MOD;
		ll B = (b[i] * k) % MOD;
		ll C = (c[i] * K) % MOD;
		ll A = (B + C) % MOD;
		ans = (ans + A) % MOD;
	}

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


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

	int n, m, mx, ans, cnt, cur;
	std::vector<int> *g;

	void dfs(int u, int par, int dist) {
		if(dist * 2 <= m) {
			++cur;
		}
		else {
			++cnt;
			return;
		}
		for (int v: g[u]) {
			if(v != par) {
				dfs(v, u, dist + 1);
			}
		}
		return;
	}

	int main() {
		scanf("%d%d", &n, &m);
		g = new std::vector<int>[n + 1];
		for (int i = 1; i < n; ++i) {
			int u, v;
			scanf("%d%d", &u, &v);
			g[u].push_back(v);
			g[v].push_back(u);
		}
		for (int u = 1; u <= n; ++u) {
			mx = cur = 0;
			for (int v: g[u]) {
				cnt = 0;
				dfs(v, u, 1);
				if(m & 1) {
					mx = std::max(mx ,cnt);
				}
			}
			ans = std::max(ans, cur + mx);
		}
		printf("%d\n", n - ans - 1);
		return 0;
	}

Measured memory_bytes: 384
import java.util.*;
import java.io.*;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st = new StringTokenizer(br.readLine());
		int n = Integer.parseInt(st.nextToken());
		int a = Integer.parseInt(st.nextToken());
		int b = Integer.parseInt(st.nextToken());
		int c = Integer.parseInt(st.nextToken());
		int d = Integer.parseInt(st.nextToken());
		String line = br.readLine();
		if(c < d){// no jump
			String sline = line.substring(a-1, c);
			String cline = line.substring(b-1, d);
			if(sline.matches(".*##.*") || cline.matches(".*##.*")){
				System.out.println("No");
			}
			else{
				System.out.println("Yes");
			}
		}
		else{
			//one jump
			String sline = line.substring(a-1, c);
			String cline = line.substring(b-2, d+1);
			if(sline.matches(".*##.*")){
				System.out.println("No");
			}
			else{
				if(cline.matches(".*\\.\\.\\..*")){
					System.out.println("Yes");
				}
				else{
					System.out.println("No");
				}
			}
		}

	}

}


Measured memory_bytes: 27220
// Author -> Preeyadarshee Dev
//
// train hard win easy :D
// nik is love
// nik is motivation
//
// do modulo operations very carefully
// try to avoid binary search, use linear search preferrably to make calculations easier
// always make your custom binary search and watch out for overflows
// read the problems carefully
// never rely on floating point calculation
#include<bits/stdc++.h>
#define mp                    make_pair
#define pb                    push_back
#define ll                    long long
#define ss                       second
#define ff                        first
#define fr(i,a,b)   for(ll i=a;i<b;i++)
#define f(i,n)                fr(i,0,n)
#define rf(i,b,a) for(ll i=b-1;i>=a;i--)
#define r(i,n)                rf(i,n,0)
#define inf                   1000000007
#define eps                   0.000000000000001
#define sz(a)                int((a).size())
#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 cpresent(c,x)        (find(all(c),x) != (c).end())
#define pi                   pair<int,int>
#define pll                  pair < ll , ll >
#define endl                 '\n'
#define PI                   3.141592653589793238462643383279502884197169399375105820974944592307816406286
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
typedef vector< int > vi;
typedef vector< vi > vvi;
int dx[8]={1,-1,0,0,-1,-1,1,1};
int dy[8]={0,0,-1,1,-1,1,-1,1};
vector<int> adj[200010],vis(200010,0),dis(200010,inf),fin(200010,0),col(200010,0),par(200010,0);
int myrandom (int i) { return std::rand()%i;}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //ifstream fin;
    //ofstream fout;
    //fin.open("input.txt");
    //fout.open("output.txt");
    int a,b;
    cin>>a>>b;
    int cnt=0,emp=1;
    while(emp<b)
    {
        cnt++;
        emp=emp+a-1;
    }
    cout<<cnt<<endl;
}


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

int main(){
    int X,N;
    cin >> X >> N;
    vector<int> vec(N);
    rep(i, N) cin >> vec[i];

    if (find(vec.begin(), vec.end(), X) == vec.end())
    {
        cout << X << endl;
        return 0;
    }

    for (int i = 1, lim = N + 5; i < lim; i++) {
        if (find(vec.begin(), vec.end(), X - i) == vec.end()) {
            cout << X - i << endl;
            return 0;
        }
        else if (find(vec.begin(), vec.end(), X + i) == vec.end())
        {
            cout << X + i << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 3628
use proconio::input;

fn main() {
    input! {
        c: char,
    };
    let ans = match c {
        'a' | 'i' | 'u' | 'e' | 'o' => true,
        _ => false,
    };
    println!("{}", if ans { "vowel" } else { "consonant" });
}


Measured memory_bytes: 2156
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <algorithm>
#include <fstream>
#include <iomanip>

typedef long double ld;
typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MOD = 1e9 + 7;

template<class T> T maximum(T head, T tail) { return std::max(head, tail); }
template<class H, class... T> H maximum(H head, T... tail) { return std::max(head, maximum(tail...)); }

template<class T> T minimum(T head, T tail) { return std::min(head, tail); }
template<class H, class... T> H minimum(H head, T... tail) { return std::min(head, minimum(tail...)); }

template<class T> std::ostream& operator << (std::ostream& os, std::vector< T > v)
{
  ll i = 0;
  for (auto x : v) {os << " [" << i++ << "]" << x; if (i % 10 == 0) os << std::endl;}
  return os;
}

template<class T, class S> std::ostream& operator << (std::ostream& os, std::vector< std::pair<T, S> > vp)
{
  ll i = 0;
  for (auto p : vp) {os << " [" << i++ << "]" << p.first << " " << p.second; if (i % 10 == 0) os << std::endl;}
  return os;
}

void print(){ std::cout << std::endl; }
template<typename H> void print(H head) { std::cout << head << std::endl; }
template<typename H, typename... T> void print(H head, T... tail){ std::cout << head << " ", print(tail...); }

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

//  bool judge = (vc == "1479");
//  if (judge) print("Yes");
//  else print("No");

  ll N, K;
  std::cin >> N >> K;

  bool judge = (N + 1) / 2  >= K;
  if (judge) print("YES");
  else print("NO");

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
#define era(t) t.erase(unique(be(t)),t.end())
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;
typedef long long ll;
using namespace std;
const ll mod=1000000007,mod9=1000000009;
template <class T>inline T lcm(T a,T b){return (a*b/__gcd(a,b));}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll x=a[0],y=a[1];
    vector<ll> v;
    for(int i=1;i*i<=x;i++){
        if(x%i==0){
            v.pb(i);
            v.pb(x/i);
        }
    }
    for(int i=1;i*i<=y;i++){
        if(y%i==0){
            v.pb(i);
            v.pb(y/i);
        }
    }
    sort(be(v));
    bool maki;
    for(int i=v.size()-1;i>=0;i--){
        maki=false;
        for(int j=0;j<n;j++){
            if(a[j]%v[i]){
                if(maki){
                    j=n;
                }
                else{
                    maki=true;
                }
            }
            if(j==n-1){
                cout << v[i]<<endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 1024
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

    static class FastReader
    {
        BufferedReader br;
        StringTokenizer st;

        public FastReader()
        {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next()
        {
            while (st == null || !st.hasMoreElements())
            {
                try
                {
                    st = new StringTokenizer(br.readLine());
                }
                catch (IOException  e)
                {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong()
        {
            return Long.parseLong(next());
        }

        double nextDouble()
        {
            return Double.parseDouble(next());
        }

        String nextLine()
        {
            String str = "";
            try
            {
                str = br.readLine();
            }
            catch (IOException e)
            {
                e.printStackTrace();
            }
            return str;
        }
    }

    public static void main (String[] args) {
        FastReader sc = new FastReader();
        int x = sc.nextInt();
        int y = sc.nextInt();
        if(x % y == 0)
            System.out.println(-1);
        else
            System.out.println(x);
    }
}


Measured memory_bytes: 23124
a, b, c, d, e, f = map(int, input().split())
a *= 100
b *= 100
water = set()
sugar = set()
for i in range(f//a + 1):
    for j in range((f - a*i)//b + 1):
        water.add(a*i + b*j)
ms = max(water) // 100 * e
for i in range(ms//c + 1):
    for j in range((ms - c*i)//d + 1):
        sugar.add(c*i + d*j)
def maxcon(x, y, z, w):
    if (z + w)*y >= (x + y)*w:
        return x, y
    else:
        return z, w
maxconwater = 100
maxconsugar = -1
for w in water:
    for s in sugar:
        if w // 100 * e >= s and w + s <= f:
            maxconwater, maxconsugar = maxcon(maxconwater, maxconsugar, w, s)
print(maxconwater + maxconsugar, maxconsugar)

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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);i++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);i--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}


void solve(){
    ll a,b,c,k;
    cin>>a>>b>>c>>k;

    ll ans=0;
    if(a>=k){
        cout<<k<<en;
        return;
    }else{
        ans+=a;
        k-=a;
    }

    if(b>=k){
        cout<<ans<<en;
        return;
    }else{
        k-=b;
    }

    cout<<ans-k<<en;

}

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

    solve();
    //ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 3644
#include <cstdio>
#include <algorithm>
#include <string>
#include <iostream>
using namespace std;
inline int read(){
    int x(0),w(1); char c = getchar();
    while(c^'-' && (c<'0'||c>'9')) c = getchar(); if(c == '-') w = -1, c = getchar();
    while(c>='0' && c<='9') x = (x<<3) + (x<<1) + c - '0', c = getchar();
	return x*w;
}
struct xxx{
	string Nm;
	int scr,idx;
}a[110];
int n;
inline bool cmp(const xxx& A, const xxx& B){
	if(A.Nm != B.Nm) return A.Nm < B.Nm;
	return A.scr > B.scr;
}
int main(){
//	freopen(".in","r",stdin);
	cin >> n;
	for(int i = 1; i <= n; ++i){
		cin >> a[i].Nm >> a[i].scr;
		a[i].idx = i;
	}
	sort(a+1,a+n+1,cmp);
	for(int i = 1; i <= n; ++i){
		cout << a[i].idx << endl;
	}
	return 0;
}

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

std::queue<char> s;
std::queue<char> t;

void input()
{
    std::string ss,tt;
    std::cin>>ss;
    std::cin>>tt;
    for(int i=0;i<(int)ss.size();i++){
        char tmp = ss[i];
        s.push(tmp);
    }
    for(int i=0;i<(int)ss.size();i++){
        char tmp = tt[i];
        t.push(tmp);
    }
}

int main()
{
    input();
    bool res = false;
    for(int i=0;i<(int)s.size();i++){
        //比較
        if(s==t)res = true;
        //文字列を回転させる
        char tmp;
        tmp = s.front();
        s.pop();
        s.push(tmp);
    }
    std::cout<<(res?"Yes":"No")<<std::endl;
}

Measured memory_bytes: 256
# 入力 : 数字4つ
A, B, C, D = map(int, input().split())

# 出力 : 重いほう
if (A+B) > (C+D) :
    print("Left")
elif (A+B) == (C+D) :
    print("Balanced")
else :
    print("Right")


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n,m,s[N],sum[N],dif[N];
int flag[N];
int get_flag(int pos) {
	return flag[pos] == pos ? pos : flag[pos] = get_flag(flag[pos]);
}
void fit(int& x) {
	if (x > n/2) x = n-x+1;
}
int fix(int x) {
	if (x<0) x = 26-(-x)%26;
	x %= 26;
	return x;
}
int main() {
	int l,r;
	for (char tmp=getchar();tmp>='a'&&tmp<='z';tmp=getchar())
		s[++n] = tmp-'a';
	for (int i=1;i<=n/2;++i)
		s[i] -= s[n-i+1],dif[i]=s[i]-s[i-1],flag[i]=i;
	dif[n/2+1] = -s[n/2];
	scanf("%d",&m);
	for (int i=1;i<=m;++i) {
		scanf("%d%d",&l,&r);
		if (n&1) {
			if (l == n/2+1&&r == n/2+1) continue;
			if (l == n/2+1) l++;
			if (r == n/2+1) r--;
		}
		if (l<=n/2&&r>n/2) {
			fit(r);
			if (l>r) swap(l,r);
			r--;
		} else {
			fit(l);fit(r);
			if (l>r) swap(l,r);
		}
		flag[get_flag(l)]=flag[get_flag(r+1)];
	}
	for (int i=1;i<=n/2+1;++i) sum[get_flag(i)] += dif[i];
	for (int i=1;i<=n/2+1;++i) if (fix(sum[i])!=0) {
		return 0*puts("NO");
	}
	puts("YES");
	return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;
#define MAXN 500000
#define LL long long
char s[MAXN+5],t[MAXN+5];
int n,m;
int bk[MAXN+5][28];
LL ans;
int main()
{
	scanf("%s",s+1);
	scanf("%s",t+1);
	n=strlen(s+1),m=strlen(t+1);
	for(int i=n;i>=1;i--){
		for(int k=0;k<27;k++)
		bk[i][k]=bk[i+1][k];
		bk[i][s[i]-'a']=i;
	}
	int pos=0;
	for(int i=1;i<=m;i++){
		if(bk[pos+1][t[i]-'a']){
			ans+=bk[pos+1][t[i]-'a']-pos;
			pos=bk[pos+1][t[i]-'a'];
		}else{
			ans+=n-pos;
			if(!bk[1][t[i]-'a']){
				printf("-1\n");
				return 0;
			}
			ans+=bk[1][t[i]-'a'];
			pos=bk[1][t[i]-'a'];
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 14592
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	int n;
	cin >> n;
	int arr[n];
	int arr2[n];
	for(int i = 0; i < n; ++i) {
		cin >> arr[i];
		arr2[i] = arr[i];
	}
	sort(arr2,arr2+n);
	int count = 0;
	for(int i = 0; i < n-1; ++i){
		if(arr[i] != arr2[i]) count++;
	}
	if(count <= 2) cout << "YES\n";
	else cout << "NO\n";
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
B=[]

for i in range(N):
    tmp=[i,A[i]]
    B.append(tmp)

B.sort(key=lambda x:(x[1]))

for i in range(N):
    print(B[i][0]+1 ,end = "")
    if i != N-1:
      print(" ",end = "")

Measured memory_bytes: 22604
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int a[] = new int[n+1];
    int sum = 0;
    int sp = n;
    for(int i = 0 ; i < n ; ++i){
      a[i] = sc.nextInt();
      sum += Math.abs(a[i] - a[sp]);
      sp = i;
    }
    
    sum += Math.abs(a[n-1]-a[n]);
    sp = n;
    
    for(int i = 0 ; i < n ; ++i){
      int pay = sum;
      pay += Math.abs(a[sp] - a[i+1]) - Math.abs(a[i] - a[sp]) - Math.abs(a[i+1] - a[i]);
      System.out.println(pay);
      sp = i;
    }
  }
}

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

int main()
{
  int N;
  cin >> N;
  vector<int> p(N);
  rep(i, N)
  {
    cin >> p[i];
  }
  sort(p.rbegin(), p.rend());
  p[0] /= 2;

  int sum = 0;
  rep(i, N)
  {
    sum += p[i];
  }

  cout << sum << endl;

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;cin >> n;
    vector<int> L(n); for (int i=0;i<n;i++) cin >> L.at(i);
    int c=0;
    sort(L.rbegin(),L.rend());
    for (int i=0;i<n-2;i++){
        int p = L.at(i);
        for (int j=i+1;j<n-1;j++){
            int q = L.at(j);
            for (int k=j+1;k<n;k++){
                int r = L.at(k);
                if (p < q+r) c ++;
                else break;
            }
        }       
    }

    cout << c << "\n";
}



Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
        int N, i;
        cin >> N;
        int a[N];
        int f[N];
        for (i=0; i<N; i++){
            cin >> a[i];
        }
        f[0] = 0;
        f[1] = abs(a[1]-a[0]);
        for (i=2;i<N;i++){
                if ( (f[i-2] + abs(a[i]-a[i-2])) > (f[i-1] + abs(a[i]-a[i-1]))){
                        f[i] = f[i-1] + abs(a[i]-a[i-1]);
                }else{
                        f[i] = f[i-2] + abs(a[i]-a[i-2]);
                }
        }
         cout << f[N-1];
}


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

int N;
vector<int> p;
vector<vector<int>> c;
vector<int> a, a_inv;
vector<int> a_sub;
vector<int> is_confirm, is_leaf, is_progeny, progeny_count, candidate_v;

int do_confirm(){
	for(int i = N - 1; i >= 0; i--){
		int count = 0;
		for(int j = 0; j < c[i].size(); j++){
			count += is_confirm[c[i][j]];
		}
		if(count == c[i].size()){
			is_leaf[i] = 1;
			if(a[i] == i){
				is_confirm[i] = 1;
			}
		}
	}
	return is_confirm[0];
}

void dfs(int a_v){
	if(is_confirm[a_v] == 0){
		is_progeny[a_inv[a_v]] = 1;
		if(is_leaf[a_v] == 0){
			for(int i = 0; i < c[a_v].size(); i++){
				dfs(c[a_v][i]);
			}
		}
	}
}

int decide(){
	if(is_leaf[a[0]] == 1){
		return a[0];
	}
	for(int i = 0; i < N; i++){
		is_progeny[i] = 0;
		progeny_count[i] = 0;
	}
	dfs(a[0]);
	for(int i = N - 1; i > 0; i--){
		progeny_count[i] += is_progeny[i];
		progeny_count[p[i]] += progeny_count[i];
	}
/*	printf("is_progeny:");
	for(int i = 0; i < N; i++){
		printf("%d ", is_progeny[i]);
	}
	printf("\n");
	printf("progeny_count:");
	for(int i = 0; i < N; i++){
		printf("%d ", progeny_count[i]);
	}
	printf("\n");
*/	candidate_v.assign(0, -1);
	for(int i = 1; i < N; i++){
		if(is_progeny[i] == 1 && progeny_count[i] == 1){
			candidate_v.push_back(i);
		}
	}
//	return candidate_v[0];
	return candidate_v[rand() % candidate_v.size()];
}

void insersion(int v){
	int V = v;
	for(; v >= 0; v = p[v]){
		a_sub[v] = a[v];
	}
	for(v = V; v > 0; v = p[v]){
		a[p[v]] = a_sub[v];
	}
	a[V] = a_sub[0];
	for(v = V; v >= 0; v = p[v]){
		a_inv[a[v]] = v;
	}
}

int main(){
//	srand((unsigned)time(NULL));
	int i;
	scanf("%d", &N);
	p.assign(N, -1);
	c.assign(N, vector<int>(0));
	for(i = 1; i < N; i++){
		scanf("%d", &p[i]);
//		p[i] = rand() % i;
//		printf("p[%d] = %d\n", i, p[i]);
		c[p[i]].push_back(i);
	}
	a.assign(N, 0);
	a_inv.assign(N, 0);
	a_sub.assign(N, 0);
/*	for(i = 0; i < N; i++){
		a[i] = i;
		swap(a[i], a[rand() % (i + 1)]);
	}
*/	for(i = 0; i < N; i++){
		scanf("%d", &a[i]);
		a_inv[a[i]] = i;
	}
	is_confirm.assign(N, 0);
	is_leaf.assign(N, 0);
	is_progeny.assign(N, 0);
	progeny_count.assign(N, 0);
	vector<int> ans(0);
	while(do_confirm() == 0){
/*		printf("a:");
		for(i = 0; i < N; i++){
			printf("%d ", a[i]);
		}
		printf("\n");
		printf("a_inv:");
		for(i = 0; i < N; i++){
			printf("%d ", a_inv[i]);
		}
		printf("\n");
		printf("is_confirm:");
		for(i = 0; i < N; i++){
			printf("%d ", is_confirm[i]);
		}
		printf("\n");
		printf("is_leaf:");
		for(i = 0; i < N; i++){
			printf("%d ", is_leaf[i]);
		}
		printf("\n");
*/		int v = decide();
//		printf("v = %d\n", v);
		ans.push_back(v);
		insersion(v);
//		printf("\n");
	}
	printf("%d\n", ans.size());
	if(ans.size() > 10000){
		return 0;
	}
	for(i = 0; i < ans.size(); i++){
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <array>
#include <queue>

#include <boost/range/algorithm.hpp>

using namespace std;

namespace brng = boost::range;

int main(void)
{
  uint64_t n, k;
  cin >> n >> k;
  uint64_t p = 1;
  for(int i = 1; i <= n - 1; i++) p *= (k - 1);

  cout << k * p << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int rows = scanner.nextInt();
        int cols = scanner.nextInt();
        String matrix[] = new String[rows];
        for (int i = 0; i < rows; i++) {
            matrix[i] = scanner.next();

        }

        System.out.println(getPath(matrix));

    }

    public static long getPath(String matrix[]) {
        long ans[][] = new long[matrix.length][matrix[0].length()];
        ans[matrix.length - 1][matrix[0].length() - 1] = 1;
        for (int j = matrix[0].length() - 1; j >= 0; j--) {
            for (int i = matrix.length - 1; i >= 0; i--) {
                if (i == matrix.length - 1 && j == matrix[0].length() - 1) {
                    continue;
                }
                if (matrix[i].charAt(j) == '#') {
                    ans[i][j] = 0;
                    continue;
                }
                if (i + 1 < matrix.length) {

                    ans[i][j] += (ans[i + 1][j] % 1000000007);
                }
                if (j + 1 < matrix[0].length()) {
                    ans[i][j] += (ans[i][j + 1] % 1000000007);
                }

            }

        }

        return ans[0][0] % 1000000007;
    }

}

Measured memory_bytes: 50064
line = input()
n = int(input())
array = [[i for i in input().split()] for i in range(n)]
for i in range(n):
    if array[i][0] == "print":
        print(line[int(array[i][1]):int(array[i][2])+1])
    elif array[i][0] == "reverse":
        if array[i][1] !="0":
            reline = line[int(array[i][2]):int(array[i][1])-1:-1]
        else:
            reline = line[int(array[i][2])::-1]
        revara = list(line)
        for i2 in range(len(reline)):
            revara[int(array[i][1])+i2] = reline[i2]
        for i2 in range(len(revara)):
            if i2 ==0:
                line = revara[i2]
            else:
                line += revara[i2]
        
    elif array[i][0] == "replace":
        repara = list(line)
        inpara = list(array[i][3])
        for i2 in range(len(inpara)):
            repara[int(array[i][1])+i2] = inpara[i2]
        for i2 in range(len(repara)):
            if i2 ==0:
                line = repara[i2]
            else:
                line += repara[i2]

Measured memory_bytes: 7816
#pragma GCC optimize("O3")
#pragma GCC target("avx2")
#pragma GCC optimization("unroll-loops")
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
}
int main()
{
    vok();
    ll n,k;
    IN n>>k;
    vll a(n);
    bitset<50> b[n];
    loop(i,0,n)
    {
        IN a[i];
        bitset<50> temp(a[i]);
        b[i]=temp;
    }
    bitset<50> ans(0);
    rloop(i,49,0)
    {
        int countt=0;
        loop(j,0,n)
        {
            if(b[j][i])
            {
                countt++;
            }
          	cout<<"";
        }
        ans[i]=1;
        if((countt*2)<n && ans.to_ullong()<=k)
        {
            //Do Nothing
        }
        else
        {
            ans[i]=0;
        }
    }
    ll fans=0LL;
    ll X=ans.to_ullong();
    loop(i,0,n)
    {
      	cout<<"";
        fans+=(X^a[i]);
    }
    OUT fans<<endl
    return 0;
}


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

using namespace std;

const int N = 100000;
const int md = 1000000007;
int a[N];
int f[N + 1];

void add(int &a, int b) {
  a += b;
  if(a >= md) {
    a -= md;
  }
}

void sub(int &a, int b) {
  a -= b;
  if(a < 0) {
    a += md;
  }
}

int mul(int a, int b) {
  return (long long)a * b % md;
}

int powmd(int n, int m) {
  int res = 1;
  while(m) {
    if(m & 1) {
      res = mul(res, n);
    }
    n = mul(n, n);
    m >>= 1;
  }
  return res;
}

int nck(int n, int k) {
  int nm = f[n];
  int dn = mul(f[k], f[n - k]);
  return mul(nm, powmd(dn, md - 2));
}

int main() {
  f[0] = 1;
  for(int i = 0; i < N; ++i) {
    f[i + 1] = mul(f[i], i + 1);
  }
  int n, k; scanf("%d %d", &n, &k);
  for(int i = 0; i < n; ++i) {
    scanf("%d", a + i);
  }
  sort(a, a + n);
  for(int i = 0; i < n; ++i) {
    if(a[i] < 0) {
      a[i] += md;
    }
  }
  int ans = 0;
  for(int i = n - 1; i - k + 1 >= 0; --i) {
    add(ans, mul(a[i], nck(i, k - 1)));
  }
  for(int i = 0; i + k - 1 < n; ++i) {
    sub(ans, mul(a[i], nck(n - i - 1, k - 1)));
  }
  cout << ans << endl;
  return 0;
}


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

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

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

mint choose(int n,int k,int type=0){
	if(k<0 || n<k) return 0;
	if(type==0){
		return fact(n)*fact_inverse(k)*fact_inverse(n-k);
	}
	else{
		if(k>n-k) k=n-k;
		mint res=fact_inverse(k);
		rep(i,k) res*=n-i;
		return res;
	}
}

mint f(int r,int c){ return choose(r+c+2,r+1); }

int main(){
	int r1,c1,r2,c2; cin>>r1>>c1>>r2>>c2;
	cout<<f(r2,c2)-f(r1-1,c2)-f(r2,c1-1)+f(r1-1,c1-1)<<'\n';
	return 0;
}


Measured memory_bytes: 22136
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int N,x;
  cin>>N;
  set<int> S;
  for(int i=0;i<N;i++){cin>>x;S.insert(x);}
  S.size()==N?cout<<"YES"<<endl:cout<<"NO"<<endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>

using namespace std;

int main()
{
   int N, M;
   int X, Y;
   cin >> N >> M;
   cin >> X >> Y;
   vector<int> x(N);
   for (int i = 0; i < N; i++){
       cin >> x.at(i);
   }
   vector<int> y(M);
   for (int i = 0; i < M; i++){
       cin >> y.at(i);
   }

    bool ans;

    int z = X + 1;
    while(z <= Y){
        for (int i = 0; i < N; i++){
            if (x.at(i) < z){
                ans = true;
            }else{
                ans = false;
                z++;
                goto LABEL;
            }
        }
        for (int i = 0; i < M; i++){
            if (y.at(i) >= z){
                ans = true;
            }else{
                ans = false;
                z++;
                goto LABEL;
            }
        }

        LABEL:
        if (ans){
            break;
        }
    }

    if (ans){
       cout << "No War" << endl;
    }else{
        cout << "War" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
/*A[N-1]から見ていって、B[N-1] > A[N-1]ならans += B[N-1]-A[N-1]
B[N-1] == A[N-1]ならans += 0, B[N-1] < A[N-1]ならans += (A/B + 1)*B - B
A[N-2]以降について、A[i] += ans として同様の操作を行う
*/


int main() {
 ll A,B,K;
 cin >> A >> B >> K;
 if(K > A){
     if(B >= K-A) B -= K-A;
     else B = 0;
     A = 0;
 }
 else if(K<=A){
     A -= K;
 }
 cout << A << " " << B << endl;
}


Measured memory_bytes: 256