akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <vector>
#include <string.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 2e9
#define ALL(v) v.begin(), v.end()
 
using namespace std;
typedef long long ll;

int main(){
  int n;
  cin >> n;
  switch (n%10){
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    default:
      cout << "bon" << endl;
      break;
  }
  return 0;
}

Measured memory_bytes: 3612
#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;
const ll MOD = 1000000007;
const int MAX = 100000;

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;
}
//最大公約数
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; }


int main(){
    string s;
    cin >> s;
    vector<char> ss(s.size());
    for(int i=0;i<s.size();i++){
        ss[i] = s[i];
    }
    string t; cin >> t;
    vector<char> tt(t.size());
    for(int i=0;i<t.size();i++){
        tt[i] = t[i];
    }
    sort(ss.begin(),ss.end());
    sort(tt.begin(),tt.end(),greater<char>());
    s="";
    for(int i=0;i<ss.size();i++){
        s += ss[i];
        //cerr << ss[i];
    }
    //cerr << "\n";
    t = "";
    for(int i=0;i<tt.size();i++){
        t += tt[i];
        //cerr << tt[i];
    }
    //cerr << "\n";
    if(s<t){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}


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


const int mod = 1e9+7;

signed main() {
	int n, m;
	cin >> n >> m;
	bool t[n + 1];
  int as[n];
	int bs[n];
	for (int i = 0; i < m; ++i) {
		t[i + 1] = false;
		cin >> as[i] >> bs[i];
	}
	for (int i = 0; i < m; ++i) {
		int a = as[i], b = bs[i];
		if (a == 1 || a == n) {
			if (t[b]) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
      t[b] = true;
		}
		if (b == 1 || b == n) {
			if (t[a]) {
				cout << "POSSIBLE" << endl;
				return 0;
			}
			t[a] = true;
		}
	}
	cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 2048
N = int(input())
num_lis = list(map(int, input().split()))
ok = True
for i in num_lis:
  if not i % 2:
    if i % 3 == 0 or i % 5 == 0:
      None
    else:
      ok = False
      
if ok:
  print("APPROVED")
else:
  print("DENIED")

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main(){
	while(1){
		int n,x,cnt=0;
		cin >> n>> x;
		if(n==0&&x==0) return 0;
		for(int i=1;i<=n;i++){
			for(int j=1;j<=n;j++){
				for(int k=1;k<=n;k++){
					if(i==j||j==k||i==k) continue;
					else if(i+j+k==x){ 
					cnt++;
					//cout<<i<<" "<<j<<" "<<k<<endl;
					}
				}
			}
		}
		cout<<cnt/6<<endl;
	}
	return 0;
}

Measured memory_bytes: 3052
package main

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

// Scan Standard Input
var sc = bufio.NewScanner(os.Stdin)

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

func main() {
	N, err1 := strconv.Atoi(nextLine())
	if err1 != nil {
		panic("convert error")
	}

	s := strings.Split(nextLine(), " ")
	A := convertI(s)

	// sort
	R, count := bubbleSort(A, N)

	// output result
	fmt.Println(strings.Join(convertA(R), " "))
	fmt.Println(count)
}

func convertA(target []int) (r []string) {
	for _, v := range target {
		n := strconv.Itoa(v)
		r = append(r, n)
	}
	return
}

func convertI(target []string) (r []int) {
	for _, v := range target {
		n, _ := strconv.Atoi(v)
		r = append(r, n)
	}
	return
}

func bubbleSort(A []int, N int) ([]int, int) {
	flag := 1
	count := 0
	for flag == 1 {
		flag = 0
		for j := N - 1; j > 0; j-- {
			if A[j] < A[j-1] {
				tmp := A[j]
				A[j] = A[j-1]
				A[j-1] = tmp
				flag = 1
				count++
			}
		}
	}
	return A, count
}



Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main(void) {
    int n,k;
    char c;
    cin >> n >> k;

    for (int i=1; i<=n; i++) {
        cin >> c;
        if ( k == i ) {
            c = tolower(c);
        }
        cout << c;
    }
    cout << endl;
}


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

int main(void){
	int H, W;
    int A[25][25];
    int min_distance_sum = 0, distance_sum = 0, distance_we, distance_ns;
	int i, j, m, n;
	
	scanf("%d %d", &H, &W);
	for(i = 0; i < H; i++){
		for(j = 0; j < W; j++){
            scanf("%d", &A[i][j]);
        }
	}

    for(i = 1; i <= H; i++){
		for(j = 1; j <= W; j++){
            distance_sum = 0;
            for(m = 1; m <= H; m++){
                for(n = 1; n <= W; n++){
                    distance_we = abs(i - m) * A[m-1][n-1];
                    distance_ns = abs(j - n) * A[m-1][n-1];
                    if(distance_we < distance_ns){
                        distance_sum += distance_we;
                    }else{
                        distance_sum += distance_ns;
                    }
                }
            }
            if(distance_sum < min_distance_sum || (i == 1 && j == 1)){
                min_distance_sum = distance_sum;
            }
        }
	}	

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

	return 0;
}


Measured memory_bytes: 2108
#include <set>
#include <vector>
#include <iostream>

using namespace std;
struct _ { ios_base::Init i; _() { ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL); } } _;

int n;
set<int> s;
vector<int> a, ans;
vector<vector<int>> gr;

void dfs(int curr, int par) {
	auto it = s.lower_bound(a[curr]);
	int temp = 0;
	if (it != s.end()) temp = *it, s.erase(it);
	s.insert(a[curr]);

	ans[curr] = s.size();

	for (auto child : gr[curr]) if (child != par) dfs(child, curr);

	s.erase(a[curr]);
	if (temp) s.insert(temp);
	return;
}

int main() {

	cin >> n;
	a.resize(n + 1, 0); for (int i = 1; i <= n; i++) cin >> a[i];
	gr.resize(n + 1);
	for (int i = 1; i <= n - 1; i++) {
		int u, v; cin >> u >> v;
		gr[u].push_back(v);
		gr[v].push_back(u);
	}

	ans.resize(n + 1, 0);
	dfs(1, 1);

	for (int i = 1; i <= n; i++) cout << ans[i] << "\n";

	return 0;
}

Measured memory_bytes: 27304
N = int(input())
word = []
flag = 0
for i in range(N):
    S = input()
    if i == 0:
        word.append(S)
    else:
        if S in word:
            print("No")
            flag += 1
            break
        else:
            if word[i-1][len(word[i-1])-1] == S[0]:
                word.append(S)
            else:
                print("No")
                flag += 1
                break
if flag == 0:
    print("Yes")

Measured memory_bytes: 3064
# include <cstdio>
# include <iostream>
# include <algorithm>
# include <cstring>
# include <queue>
# include <map>
# include <set>
# include <vector>
# include <cmath> 
# define R register int
# define ll long long 

using namespace std;

const int maxn=100005;
int n,m,x,y,num[maxn],vis[maxn];

int read()
{
	R x=0,f=1;
	char c=getchar();
	while (!isdigit(c)) { if(c=='-') f=-f; c=getchar(); }
	while (isdigit(c)) x=(x<<3)+(x<<1)+(c^48),c=getchar();
	return x;
}

int main()
{
    n=read(),m=read();
    for (R i=1;i<=n;++i) num[i]=1;
    vis[1]=1;
    for (R i=1;i<=m;++i)
    {
        x=read(),y=read();
        if(num[x]==1&&vis[x]==1)
        {
            vis[x]=0;
            vis[y]=1;
            num[y]++;
            num[x]--;
        }
        else
        {
            num[x]--;
            num[y]++;
            if(vis[x]) vis[y]=1;
        }
    }
    int ans=0;
    for (R i=1;i<=n;++i)
        if(vis[i]) ans++;
    printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
//Radhe Radhe
#include<bits/stdc++.h>
#define ll long long
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mod 1000000007
using namespace std;

int main()
{
    fast_io
    ll i,j,a[3],ans;
    string s;
    cin>>a[0]>>a[1]>>a[2];
    sort(a,a+3);
    ans=a[2]*10+a[1];
    return cout<<ans+a[0]<<endl,0;
    return 0;
}





Measured memory_bytes: 3600
import java.util.*;

class Main{
	
	public static void main(String args[]){

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int arr[] = new int[N];
		int min=-1,max=-1;
		for(int n=0;n<N;n++){
			arr[n] = sc.nextInt();
			if(min==-1){
				min = arr[n];
				max = arr[n];
			}
			if(min > arr[n]) min = arr[n];
			if(max < arr[n]) max = arr[n];
		}

		System.out.println(max-min);

	}
}

Measured memory_bytes: 23764
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100000
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define vi(a)	  vector<ll>a
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "


int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
        ll a,b,c;
        sll(a),sll(b),sll(c);
        if(a+b+c>=22) cout << "bust" << endl;
        else cout << "win" << endl;
		return 0;
}


Measured memory_bytes: 3704
#include <iostream>
#include <cstdio>

using namespace std;

void binPrint(int x, int bits){
  for (int i=bits-1; i>=0; i--){
    cout << (x&(1<<i)?1:0);
  }
  cout << endl;
}
int main(void){
  unsigned x;
  cin >> x;
  binPrint(x, 32);
  binPrint(~x, 32);
  binPrint(x<<1, 32);
  binPrint(x>>1, 32);
  
  return 0;
}



Measured memory_bytes: 3108
from collections import deque
from heapq import heappush,heappop
import re

def int_raw():
    return int(input())

def ss_raw():
    return input().split()

def ints_raw():
    return list(map(int, ss_raw()))

INF = 1<<29
N,K = ints_raw()
S = input()

def main():
    ans =""
    for i in range(N):
        ans += S[i] if i!= K-1 else S[i].lower()
    return ans

print(main())


Measured memory_bytes: 38352
#include <iostream>
#include <iomanip>
#include <cmath>
using namespace std;

int main(){
    double r, l, s;
    
    cin >> r;
    s = r * r * M_PI;
    l = 2 * r * M_PI;
    cout << fixed;
    cout << setprecision(5) << s << " " << setprecision(5) << l << endl;
    
    return 0;
}


Measured memory_bytes: 3288
#include <iostream>
#include<algorithm>
#include<string>
#include<vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>

using namespace std;

int main()
{
	int cnt = 0;
	string s1,s2,s3;
	cin >> s1 >> s2 >> s3;
	while (true) {
	   A:
		   if (s1 == ""){cout << "A" << endl; return 0;}
		   if (s1[cnt] == 'a') { s1.replace(cnt, 1, ""); goto A; }
		   else if (s1[cnt] == 'b') { s1.replace(cnt, 1, ""); goto B; }
		   else if (s1[cnt] == 'c') { s1.replace(cnt, 1, ""); goto C; }
	   
	   B: 
		   if (s2 == "") { cout << "B" << endl; return 0; }
		   if (s2[cnt] == 'a') { s2.replace(cnt, 1, ""); goto A; }
		   else if (s2[cnt] == 'b') { s2.replace(cnt, 1, ""); goto B; }
		   else if (s2[cnt] == 'c') { s2.replace(cnt, 1, ""); goto C; }
		
	   C: 
		   if (s3 == "") { cout << "C" << endl; return 0; }
		   if (s3[cnt] == 'a') { s3.replace(cnt, 1, ""); goto A; }
		   else if (s3[cnt] == 'b') { s3.replace(cnt, 1, ""); goto B; }
		   else if (s3[cnt] == 'c') { s3.replace(cnt, 1, ""); goto C; }
	}
}

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

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

  int a, b, c; cin >> a >> b >> c;
  if (a <= c and c <= b) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


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

using namespace std;

#define pb push_back

const int maxi = 1e6+10;
string s;
vector<int> v[maxi];
int n;
long long a[maxi];


void dfs(int x, int pred)
{
    a[x]+=a[pred];

    for (int i:v[x])
        if (i!=pred) dfs(i,x);
}
int main()
{
     cin>>n;

     for (int i=1;i<=n;i++)
        scanf("%lld",&a[i]);

    double sum = 1;

    double down = 0;

    for (int i=1;i<=n;i++)
        down+=1.00/a[i];

    printf("%.6f",sum/down);


    return 0;
}
//pisacu joj pisma duga
//iz Zagore iz Drnisa
//razglednice tople s juga
//z Banata poslije Nisa

//ti si sunce moga neba
//tebi mogu reci
//ti si jedina od svih
//koja tajne moje cuva
//ti si moja ljubav prva <3


Measured memory_bytes: 25344
// https://atcoder.jp/contests/abc161/tasks/abc161_b
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<int> v(N);
    for (auto &x : v) {
        cin >> x;
    }
    // 降順
    sort(ALLR(v));
    int sum = accumulate(ALL(v), 0LL);
    double avg = (double)sum / M / 4;
    if (v[M - 1] >= avg) {
        cout << "Yes\n";
    } else {
        cout << "No\n";
    }

    return 0;
}


Measured memory_bytes: 256
/*
 ***
 Question Name:
 ***
 Question Link:
 ***
 Idea:
 */

#include <memory.h>
#include <ctime>
#include <random>
#include <iomanip>
#include <algorithm>
#include <iostream>
#include <iterator>
#include <numeric>
#include <sstream>
#include <fstream>
#include <cassert>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cstdio>
#include <vector>
#include <cmath>
#include <functional>
#include <queue>
#include <deque>
#include <stack>
#include <list>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>

#define REP(i,s,n) for(int (i)=s; (i)<(int)(n);(i)++)
#define RIT(it,c) for(__typeof(c.begin()) it = c.begin();it!=c.end();it++)
#define ALL(x) x.begin(), x.end()
#define SZ(x) (int)(x).size()
#define MSET(m,v) memset(m,v,sizeof(m))

using namespace std;

typedef long double ld;
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<int,int> ii;
typedef pair<long, long> ll;
typedef unordered_set<int> ui;

int N;

int main(){
    std::ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    cin>>N;
    for(int n=max(1,N/4);n<=3500;++n) for(int m=n;m<=3500;++m){
        long de = (long)4*n*m - (long)N*m - (long)N*n;
        if(de <= 0) continue;
        long nu = (long)N*m*n;
        if(!(nu%de)){
            cout<<n<<' '<<m<<' '<<nu/de<<endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
import itertools

N,M,X = [int(a) for a in input().split()]
C = []
A = []
for _ in range(N):
    in_ = [int(a) for a in input().split()]
    C.append(in_[0])
    A.append(in_[1:])

ans = []
for n in range(N):
    all_list = itertools.combinations(range(N), n+1)
    for c in all_list:
        scores = [0 for _ in range(M)]
        price = 0
        for i in c:
            for j in range(M):
                scores[j] += A[i][j]
            price += C[i]
        clear = True
        for j in range(M):
            if scores[j] < X:
                clear = False
        if clear:
            ans.append(price)

if len(ans) == 0:
    print(-1)
else:
    print(min(ans))

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

int main(){
    int N, X;
    cin >> N >> X;

    //残り
    int rem = X;
    //最小必要お菓子量
    int minmin = 1001;
    //求めたい数
    int ans = N;

    vector<int> M(N);
    for (int i = 0; i < N; i++){
        cin >> M.at(i);
        rem -= M.at(i);
        if (minmin > M.at(i)) minmin = M.at(i);
    }

    while(rem >= minmin){
        ans++;
        rem -= minmin;
    }

    cout << ans << endl;

    return 0;
}

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

using namespace std;

// こういうのは平方分割なんですよね　初見さん

#define int long long

signed main() {
  int N, M;
  scanf("%lld %lld", &N, &M);
  int ukunichia_chan[101][101] = {{}};
  int beet_ikiruna[100001] = {}, beet_sz = 0, add = 0;
  for(int i = 0; i < M; i++) {
    int a, b;
    scanf("%lld %lld", &a, &b);
    if(b < 101) {
      ukunichia_chan[a][b]++;
    } else {
      // 1個ずつ増える項
      add += a + 1;
      beet_sz++;
      int ret = 0;
      for(int j = b - a - 1; j < N; j += b) {
        ++ret;
        beet_ikiruna[j] += b;
      }
    }
  }

  int X[100000] = {};
  int cost = 0;
  for(int i = 0; i < N; i++) {
    add -= beet_ikiruna[i];
    X[i] += cost;
    X[i] += add;
    cost += beet_sz;
  }

  for(int i = 0; i <= 100; i++) {
    for(int j = i + 1; j <= 100; j++) {
      int latte = i + 1;
      if(ukunichia_chan[i][j] == 0) continue;
      if(latte == j) latte -= j;
      for(int k = 0; k < N; k++) {
        X[k] += latte * ukunichia_chan[i][j];
        latte++;
        if(latte == j) latte -= j;
      }
    }
  }


  for(int i = 0; i < N; i++) printf("%lld\n", X[i]);
}




Measured memory_bytes: 4864
from collections import deque
 
#入力受け取り
H,W=map(int,input().split())
Ch,Cw=[int(x)-1 for x in input().split()]
Dh,Dw=[int(x)-1 for x in input().split()]
maze=[input() for i in range(H)]
 
dirs=[-2,-1,0,1,2] #ワープ移動できる縦横の範囲
#初期化
dist=[[float('inf')]*W for _ in range(H)] #distには各点への到達コストを格納
dist[Ch][Cw]=0
dq=deque()
dq.append((0,Ch,Cw)) #キューには(コスト、x座標、y座標)を追加していく
ok=False

while dq:
    k,i,j=dq.popleft()
    if k>dist[i][j]:
        continue
    if i==Dh and j==Dw:
        ok=True
        break
    for di in dirs:
        for dj in dirs:
            if di==dj==0:
                continue
            ni,nj=i+di,j+dj #移動後の座標(ni,nj)
            if not (0<=ni<H and 0<=nj<W):
                continue
            if maze[ni][nj]=='#': #移動先が壁の中
                continue
            if abs(di)+abs(dj)==1: #歩行圏内(コスト:0)
                append=dq.appendleft
                nk=k
            else: #歩行圏外(コスト:1)
                append=dq.append
                nk=k+1
            if k>=dist[ni][nj]:
                continue
            dist[ni][nj]=nk
            append((nk,ni,nj))      
if ok:
    ans=dist[Dh][Dw]
else:
    ans=-1
print(ans)

Measured memory_bytes: 228556
#pragma region
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <list>
#include <iomanip>
#include <cstdint>
#include <bitset>

using namespace std;
typedef long long ll;
//#define rep(i, s, e) for (int(i) = (s); (i) < (e); ++(i))
#define rep(i, e) for (int(i) = 0; (i) < (e); ++(i))
#define rrep(i, s) for (int(i) = (s) - 1; (i) >= 0; --(i))
#define all(x) x.begin(),x.end()

#pragma region UnionFind
struct UnionFind
{
	vector<int> par;

	UnionFind(int n) : par(n, -1) {}
	void init(int n) { par.assign(n, -1); }

	int root(int x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool issame(int x, int y)
	{
		return root(x) == root(y);
	}

	bool merge(int x, int y)
	{
		x = root(x); y = root(y);
		if (x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	int size(int x)
	{
		return -par[root(x)];
	}
};
#pragma endregion
#pragma region GCD
ll gcd(ll a, ll b)
{
	if (b == 0)return a;
	return gcd(b, a%b);
}
#pragma endregion
#pragma region LCM
ll lcm(ll a, ll b)
{
	return a / gcd(a, b) * b;
}
#pragma endregion
#pragma region chmin
template<class T> inline bool chmin(T& a, T b)
{
	if (a > b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma region chmax
template<class T> inline bool chmax(T& a, T b)
{
	if (a < b)
	{
		a = b;
		return true;
	}
	return false;
}
#pragma endregion
#pragma endregion


int main()
{
	int n; cin >> n;
	ll k; cin >> k;
	vector<int> a(n + 1); rep(i, n)cin >> a[i + 1];
	vector<int> passed(n + 1, -1);
	passed[1] = 0;
	int loop_size = 0;
	int cnt = 0;
	int now = 1;
	while (true)
	{
		++cnt;
		if (cnt > k)
		{
			cout << now << endl;
			return 0;
		}
		if (passed[a[now]] != -1)
		{
			k -= cnt;
			loop_size = passed[now] + 1 - passed[a[now]];
			now = a[now];
			break;
		}
		passed[a[now]] = passed[now] + 1;
		now = a[now];
	}
	k %= loop_size;
	rep(i, k)now = a[now];
	cout << now << endl;
}

Measured memory_bytes: 4828
#include<stdio.h>
int main() {
	int a,i;
	scanf("%d", &a);
	while (1) {
		if(a == 111)
			break;
		if (a == 222)
			break;
		if (a == 333)
			break;
		if (a == 444)
			break;
		if (a == 555)
			break;
		if (a == 666)
			break;
		if (a == 777)
			break;
		if (a == 888)
			break;
		if (a == 999)
			break;
		a++;

	}
	printf("%d\n", a);
}

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

vector<int> to[MAX];
int main(){
    int n, m;
    cin >> n >> m;
    rep(i, m){
        int a, b; cin >> a >> b;
        a--; b--;
        to[a].push_back(b);
        to[b].push_back(a);
    }

    queue<int> q; q.push(0);
    vector<int> ans(n,-1); vector<bool> used(n,false);
    while(!q.empty()){
        int s = q.front(); q.pop();
        used[s] = true;
        for(int t : to[s]){
            if(used[t]) continue;
            used[t] = true;
            if(ans[t]==-1) ans[t]=s;
            q.push(t);
        }
    }
    out("Yes");
    rep(i, n-1){
        out(ans[i+1]+1);
    }
}

Measured memory_bytes: 12496
#include <iostream>
#include <string>
using namespace std;
 
int main(){
    string s; cin >> s;
    int N=s.size(), cnt=0;
    for(int i=0;i<N;i++){
        if(s[i]=='p') cnt++;
    }
    cout << N/2-cnt << endl;
    return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,x,y;
  x = 0; y = 0;
  vector<int> a(120);
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  reverse(a.begin(), a.end());
  for (int i = 0; i < N; i += 2) {
    x += a[i];
    y += a[i+1];
  }
  cout << x - y << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
	int N, i;
	cin >> N >> i;
	cout << N - i + 1;

	return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main(){
    int a,b; cin>>a>>b;
    a--; b--;
    cout<<a*b<<endl;
}


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

#define all(x) (x).begin(),(x).end()
#define init() \
  ios::sync_with_stdio(false); \
  cin.tie(0)

#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long;

#ifdef LOCAL

template<typename T>
void show(vector<T>& v) {
    cout << '[';
    for (const T& e : v) {
        cout << e << ',';
    }
    cout << ']' << endl;
}

#endif

template<typename M, typename N>
constexpr common_type_t<M, N> gcd(M a, N b) {
  return a == 0 ? b
    : b == 0 ? a
    : gcd(b, a % b);
}

template <typename M, typename N>
constexpr common_type_t<M, N> lcm(M a, N b) {
  return a * b / gcd(a, b);
}

template <long long MAX>
class CombinationCalculator {
  long long mod_;
  long long fac[MAX];
  long long finv[MAX];
  long long inv[MAX];

public:
  CombinationCalculator(long long mi = MOD): fac(), finv(), inv() {
    mod_ = mi;
    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 c(long long n, long long k) const {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % mod_) % mod_;
  }
};

template <long long MAX = 210000>
using CC = CombinationCalculator<MAX>;

template<typename T>
T modpow(T a, T n, T mod = MOD) {
    T res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

template<typename T>
T modinv(T a, T m = MOD) {
    T b = m, u = 1, v = 0;
    while (b) {
        T t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m; 
    if (u < 0) u += m;
    return u;
}

template<typename T>
vector<T> read_n(const size_t n) {
    T dummy;
    vector<T> v(n);
    for (size_t i = 0; i < n; i++) {
        cin >> dummy;
        v[i] = dummy;
    }
    return v;
}

template<typename T>
vector<T> read_n() {
    size_t n;
    cin >> n;
    return read_n<T>(n);
}

int main() {
  init();

  string p;
  cin >> p;

  ll offset = 0;
  ll res = 0;
  for (int i = p.length() - 1; i >= 0; i--) {
      if (p[i] == 'B') {
          res += p.length() - i - 1 - offset;
          offset++;
      }
  }
  cout << res << endl;

  return 0;
}


Measured memory_bytes: 3752
#include<iostream>
#include<algorithm>

const int N = 3;

int main(){
  int a[N];
  
  for(int i = 0; i < N; i++){
    std::cin >> a[i];
  }

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

  std::cout << a[0];
  for(int i = 1; i < N; i++){
    std::cout << " " << a[i];
  }
  std::cout << std::endl;

  return 0;
}



Measured memory_bytes: 3088
n=int(input())
s = list(input())
wd = list("abcdefghijklmnopqrstuvwxyz")
ans=0
for i in range(n):
  s1 = set(s[:i])
  s2=set(s[i:])
  tmp=0
  for w in wd:
    if w in s1 and w in s2:
      tmp+=1
  ans=max(ans,tmp)
print(ans)
  

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

#define int long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define dbg(x) cerr << #x << ": " << x << endl;
#define dbg2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define dbg3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define dbgB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

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; }

template<typename T>
void print1(T begin, T end) {
	while (begin != end) {
		cerr << (*begin) << " ";
		*begin++;
	}
	cerr << endl;
}

template<typename T>
void print2(T Array, int height, int width) {
	for (int i = 0; i < height; i++) {
		for (int j = 0; j < width; j++) {
			cerr << " " << Array[i][j];
		}
		cerr << endl;
	}
}

void print() { std::cerr << endl; }
template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
	std::cerr << head << " ";
	print(std::forward<Tail>(tail)...);
}

template<class T>
void Add(T &a, const T &b, const T &mod=1000000007) {
	int val = ((a % mod) + (b % mod)) % mod;
	if (val < 0) { val += mod; }
	a = val;
}

template <typename X, typename T> auto vectors(X x, T a) { return vector<T>(x, a); }
template <typename X, typename Y, typename Z, typename... Zs> auto vectors(X x, Y y, Z z, Zs... zs) { auto cont = vectors(y, z, zs...); return vector<decltype(cont)>(x, cont); }

// ------------------------------------------------------------------------------------------

int N, P;
string S;

signed main() {
	cin >> N >> P >> S;

	if (P == 2 or P == 5) {
		int ans = 0;
		rep (i, N) {
			if ((S[i] - '0') % P == 0) {
				ans += i + 1;
			}
		}
		cout << ans << endl;
		return 0;
	}

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

	for (int i = N-1; i >= 0; i--) {
		s[i] += s[i+1];
		s[i] %= P;
	}

	int ans = 0;
	map<int, int> mp;
	mp[0] = 1;
	for (int i = N-1; i >= 0; i--) {
		ans += mp[s[i]];
		mp[s[i]]++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 2564
#include "bits/stdc++.h"

using namespace std;

typedef long double ld;
typedef long long ll;

#define sz(x) (int)(x).size()
#define pb push_back
#define mp make_pair
#define f first
#define s second

template<typename T, typename U> bool ckmin(T &a, U b){ return b < a ? a = b, true : false; }
template<typename T, typename U> bool ckmax(T &a, U b){ return b > a ? a = b, true : false; }

const double I = 1e40;
const ll INF = 1e18;

ll x, k, d, ex = 0;
pair<double, ll> res = {I, INF};
double f(double y){
    return abs((y * 2 + ex) * d - abs(x));
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> x >> k >> d;
    if(k & 1) ex++;
    k >>= 1;
    ll l = 0, r = k;
    while (r - l > 3) {
        ll m1 = l + (r - l) / 3;
        ll m2 = r - (r - l) / 3;
        double f1 = f(m1);      //evaluates the function at m1
        double f2 = f(m2);      //evaluates the function at m2
        if (f1 > f2)
            l = m1;
        else
            r = m2;
    }
    for(ll x = l; x <= r; ++x){
        ckmin(res, mp(f(x), x));
    }
    cout << abs((res.s * 2 + ex) * d - abs(x));
    return 0;
}

Measured memory_bytes: 3648
package main

import "fmt"

func main() {
	var n, count int
	fmt.Scan(&n)
	m := make([]int, n)
	for i := 0; i < n; i++ {
		fmt.Scan(&m[i])
		if m[i] != i+1 {
			count++
		}
	}
	if count <= 2 {
		fmt.Print("YES")
	} else {
		fmt.Print("NO")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long int LL;
typedef long double LD;

const int MOD = 1e9 + 7;
const int MAXS = 1 << 16;

int main() {
	int N, X, Y, Z;
	cin >> N >> X >> Y >> Z;

	int xyz = (1 << (X + Y + Z - 1)) | (1 << (Y + Z - 1)) | (1 << (Z - 1));
	int mask = (1 << (X + Y + Z)) - 1;
	int mask2 = mask >> 1;

	int dp[2][MAXS];
	int idx = 0, _idx;
	dp[idx][0] = 1;
	for (int k = 0; k < N; ++k) {
		_idx = idx;
		idx ^= 1;
		memset(dp[idx], 0, sizeof(dp[idx]));
		for (int i = 0; i <= mask2; ++i) {
			if (dp[_idx][i] > 0) {
				for (int j = 1; j <= 10; j++) {
					int _i = ((i << j) | (1 << (j-1))) & mask;
					if ((_i&xyz) != xyz) (dp[idx][_i&mask2] += dp[_idx][i]) %= MOD;
				}
			}
		}
	}
	long res = 1;
	for (int i = 0; i < N; ++i) (res *= 10) %= MOD;
	for (int i = 0; i <= mask2; ++i) (res -= dp[idx][i]) %= MOD;

	cout << (res + MOD) % MOD << endl;

	return 0;
}

Measured memory_bytes: 768
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    println!(
        "{}",
        if rl().chars().filter(|&c| c == 'x').count() < 8 {
            "YES"
        } else {
            "NO"
        }
    )
}


Measured memory_bytes: 4352
/* Volume0 */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      for(int i = 1; i <= 9; i++){
        for(int j = 1; j <= 9; j++){
          System.out.println(i + "x" + j + "=" +  i*j);
        }
      }
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

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

const int maxn = 1e5+5;
int n, a[maxn];

pair<int, int> get_mayor_cuenta(map<int, int>& m, int prohibido){
	pair<int, int> ret = {-1, 0};

	for(pair<int, int> p: m) 
		if (p.first != prohibido && p.second>ret.second)
			ret = p;
	
	return ret;
}

int main(){
	scanf("%d", &n);
	for(int i = 0; i<n; i++) scanf("%d", &a[i]);
	map<int,int> cuenta_pares, cuenta_impares;
	for(int i = 0; i<n; i++){
		if (i%2) cuenta_pares[a[i]]++;
		else cuenta_impares[a[i]]++;
	}
	pair<int, int> pares_max = get_mayor_cuenta(cuenta_pares, -1);
	pair<int, int> pares_max2 = get_mayor_cuenta(cuenta_pares, pares_max.first);

	pair<int, int> impares_max = get_mayor_cuenta(cuenta_impares, -1);
	pair<int, int> impares_max2 = get_mayor_cuenta(cuenta_impares, impares_max.first);

	int ans = 10000000;
	if (pares_max.first != impares_max.first)
		ans = n - pares_max.second - impares_max.second;

	ans = min(ans, n - pares_max.second - impares_max2.second);
	ans = min(ans, n - pares_max2.second - impares_max.second);

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


Measured memory_bytes: 5376
#include <iostream>
#include <stdlib.h>
using namespace std;

int compare_int(const void *a,const void *b){
    return *(int*)b-*(int*)a;
}

int main(){
    int n;
    int alice=0, bob=0;
    cin>>n;

    int a[n];
    for(int i=0; i<n; i++) cin>>a[i];

    qsort(a,n,sizeof(int),compare_int);

    for(int i=0; i<n; i++){
        if(i%2==0) alice+=a[i];
        else bob+=a[i];
    }

    cout<<alice-bob<<endl;

}



Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <limits.h>
#include <math.h>
using namespace std;

int main()
{
	int N;
	cin >> N;
	vector<int> H(N);

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

	int ret = 1;
	for (int i = 1; i < N; ++i)
	{
		for (int j = 0; j < i; ++j)
		{
			if (H[i] < H[j])
				break;

			if (j == i - 1)
			{
				++ret;
				break;
			}
		}
	}

	cout << ret << endl;

	return 0;
}

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

using namespace std;

int main(){
  int n;
  cin >> n;
  int count1=0, count2=0;
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    if(a[i]%4==0) count1++;
    else if(a[i]%2==0) count2++;
  }
  
  string ans="No";
  if(count1>=n/2){
    cout << "Yes";
    return 0;
  }
  
  if(n%2==0){
    for(int i=1;i<=n/2;i++){
      if(count1==n/2-i){
        if(count2>=2*i){
          ans="Yes";
          break;
        }
      }
    }
  }else{
    for(int i=1;i<=n/2;i++){
      if(count1==n/2-i){
        if(count2>=2*i+1){
          ans="Yes";
          break;
        }
      }
    }
  }
  
  cout << ans;
  
  
  return 0;
}

Measured memory_bytes: 640
#include <iostream>
using namespace std;
#define INF 100000000
int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int w[n + 1] = {0}, e[n + 1] = {0};
    for (int i = 1; i <= n; i++)
    {
        if (s[i - 1] == 'W')
        {
            w[i] = w[i - 1] + 1;
            e[i] = e[i - 1];
        }
        else
        {
            e[i] = e[i - 1] + 1;
            w[i] = w[i - 1];
        }
    }
    // for (int i = 1; i <= n; i++)
    //     cout << w[i] << " ";
    // cout << endl;
    // for (int i = 1; i <= n; i++)
    //     cout << e[i] << " ";
    // cout << endl;
    int ans = INF;
    for (int i = 1; i <= n; i++)
    {
        ans = min(ans, e[n] - e[i] + w[i - 1]);
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
  int a,b;
  cin>>a>>b;
  if(a==b) cout<<0;
  else if((a+b)%2==0){
    cout<<(a+b)/2;
  }else{
    cout<<"IMPOSSIBLE";
  }
  cout<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
#include <iomanip>
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;
}
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;

void print(const std::vector<long long> &v) {
    std::for_each(v.begin(), v.end(),
                  [](long long x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;cin >> N;
    vector<long long> a(3 * N);
    REP(i, 3 * N) cin >> a[i];
    vector<long long> S(N * 2 + 1, 0);
    priority_queue<long long, vector<long long>, greater<long long>> que1;
    for(int i = 0; i < N; i++) { //はじめにN個で初期化計算
        S[i + 1] = S[i] + a[i];  //累積和
        que1.push(a[i]);
    }
    for(int i = N; i < N * 2; i++) {
        long long mi = que1.top();
        if(a[i] > mi) {
            S[i + 1] = S[i] + a[i] - mi;
            que1.pop();
            que1.push(a[i]);
        } else
            S[i + 1] = S[i];
    }

    vector<long long> T(N * 2 + 1, 0);
    priority_queue<long long> que2;
    //初期化処理
    for(int i = 0; i < N; i++) {
        T[i + 1] = T[i] + a[N * 3 - 1 - i];
        que2.push(a[N * 3 - 1 - i]);
    }
    for(int i = N; i < N * 2; ++i) {
        long long ma = que2.top();
        if(a[N * 3 - 1 - i] < ma) {
            T[i + 1] = T[i] - ma + a[N * 3 - 1 - i];
            que2.pop();
            que2.push(a[N * 3 - 1 - i]);
        } else
            T[i + 1] = T[i];
    }
    long long res = -INF;
    for(int i = N; i <= N * 2; i++) {
        res = max(res, S[i] - T[N * 3 - i]);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 8052
import java.util.ArrayList;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
Scanner sc=new Scanner(System.in);
		
		int n=sc.nextInt();
		
		ArrayList<Integer>nanido=new ArrayList<>();
		for(int i=0;i<n;i++) {
			nanido.add(sc.nextInt());
		}
		Collections.sort(nanido);
		int hanbun=nanido.size()/2;
		
		int answer=(nanido.get(hanbun))-(nanido.get(hanbun-1));
		
		System.out.println(answer);
		
		/*int answer=(nanido.size()/2)-(nanido.size()/2-1);
		System.out.println(answer);*/
	}

}


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

bool solve();

int main()
{
	if (solve()) puts("APPROVED");
	else puts("DENIED");

	return 0;
}

bool solve()
{
	int N;
	scanf("%d", &N);
	for (int i{}; i < N; i++)
	{
		int A;
		scanf("%d", &A);
		if (A % 2 != 0) continue;
		if (A % 3 != 0 && A % 5 != 0) return false;
	}
	return true;
}

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

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

  int value=700;
  if(menu[0]=='o') value = value+100;
  if(menu[1]=='o') value = value+100;
  if(menu[2]=='o') value = value+100;

  cout << value;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;

int main(){
    long long int n,k=0;
    string s="abcdefghijklmnopqrstuvwxyz";
    cin>>n;
    vector<int>b(10000);
    for(long long int i=0;n>0;i++){
        n=n-1;
        b[i]=n%26;
        k=i;
        n=n/26;
    }
    for(long long int i=k;i>=0;i--){
        cout<<s[b[i]]<<flush;
    }
    cout<<endl;
}


Measured memory_bytes: 3608
#include <stdio.h>
#include <stdlib.h>
#include <vector>
#include <utility>

#define MAX_P (1000000000000L)
#define MAX_SQRTP (1000000L)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  long N, P;
  scanf("%ld %ld", &N, &P);

  // prime decomposition
  vector<pair<long, long>> ps;
  for (long i = 2L; i <= MAX_SQRTP; i++) {
    long num_div = 0L;
    while (P % i == 0L) {
      P /= i;
      num_div++;
    }
    if (num_div > 0L) {
      ps.push_back(pair<long, long>(i, num_div));
    }
  }
  if (P != 1) {
    ps.push_back(pair<long, long>(P, 1));
  }

  // solve
  long ans = 1L;
  for (const pair<long, long> &p : ps) {
    const long prime = p.first, cnt = p.second;
    for (long i = 0, i_end = cnt / N; i < i_end; i++) {
      ans *= prime;
    }
  }
  printf("%ld\n", ans);
  
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll INF = 1LL<<60;
const ll MOD = 1e9 + 7;

int main() {
    ll N;
    cin >> N;
    string S;
    cin >> S;
    vector<ll> R;
    vector<ll> G;
    vector<ll> B;
    ll rko = 0;
    ll gko = 0;
    ll bko = 0;
    for (ll i = 0;i<N;i++) {
        if (S.at(i) == 'R') {
            R.push_back(i);
            rko++;
        }
        if (S.at(i) == 'G') {
            G.push_back(i);
            gko++;
        }
        if (S.at(i) == 'B') {
            B.push_back(i);
            bko++;
        }
    }

    ll ans = 0;

    for (ll i = 0;i<R.size();i++) {
        for (ll j = 0;j<G.size();j++) {
            ll r = R.at(i);
            ll g = G.at(j);
            ll d = abs(r-g);
            ll M = max(r,g);
            ll m = min(r,g);
            ll sakujo = 0;
            if (M+d <= N-1) {
                if (S.at(M+d) == 'B') sakujo++;
            }
            if (m-d >= 0) {
                if (S.at(m-d) == 'B') sakujo++;
            }
            if ((M+m)%2 == 0) {
                if (S.at((M+m)/2) == 'B') sakujo++;
            }
            ans += bko;
            ans -= sakujo;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3668
#include <bits/stdc++.h>
using namespace std;
int main(void) {
    std::deque<string> deq;
    string s;
    while (cin>>s) {
        deq.emplace_back(s);
    }
    for (int i=0;i<deq.size();i++) {
        if (deq[i].find("peach")!=string::npos) {
            deq[i].replace(deq[i].find("peach"),5,"apple");
            cout<<deq[i];
        } else if (deq[i].find("apple")!=string::npos) {
            deq[i].replace(deq[i].find("apple"),5,"peach");
            cout<<deq[i];
        } else {
            cout<<deq[i];
        }
        if (i==deq.size()-1) {
            cout<<endl;
        } else {
            cout<<" ";
        }
    }
}


Measured memory_bytes: 3132
N = int(input())
ln = list(map(int, input().split()))
ln = sorted(ln, reverse = True)
if N %2 == 1:
    n =int(((N-1)/2)+1)
    print(sum(ln[:n-1]) + sum(ln[1:n]))
else:
    n = int((N/2)+1)
    print(sum(ln[:n-1]) + sum(ln[1:n-1]))

Measured memory_bytes: 31628
{-# OPTIONS_GHC -O2 #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE TupleSections #-}
module Main where

import           Data.List
import           Control.Monad
import           Debug.Trace
import qualified Data.ByteString.Char8         as BC
import           Data.Maybe                     ( fromJust, fromMaybe )
import qualified Data.Set                      as S
import qualified Data.IntMap.Strict            as IM
import qualified Data.IntMap.Lazy            as IML
import qualified Data.Map.Strict               as M
import           Data.Char
import qualified Data.Array.IArray as A
import qualified Data.Array.Unboxed as UA
import Data.Bits
import Control.Monad.State.Strict
import qualified Data.Array.ST as STA
import qualified Data.Array.IO as IOA
import qualified Data.Array.MArray as MA
import Control.Monad.ST
import System.IO (stdin)
import Control.Arrow
import qualified Data.Vector as V
import qualified Data.Vector.Unboxed as UV
import qualified Data.Vector.Generic as GV
import qualified Data.Vector.Mutable as MV
import Data.Ix
import Data.Ord (Down(Down))
import qualified Data.Sequence as Seq
import Data.Foldable (toList)
-- import Control.Lens

debug = False

ts :: Show a => a -> a
ts a = if debug then traceShowId a else a


readTuple2 :: IO (Int, Int)
readTuple2 = do
    [a, b] <- readInts
    return (a, b)

readTuple3 :: IO (Int, Int, Int)
readTuple3 = do
    [a, b, c] <- readInts
    return (a, b, c)


readInt :: IO Int
readInt = fst . fromJust . BC.readInt <$> BC.getLine

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

split :: (a -> Bool) -> [a] -> [[a]]
split f [] = []
split f as =
    let (fo, la) = span f as
        las      = case la of
            [] -> []
            xs -> split f $ tail xs
    in  case fo of
            [] -> las
            xs -> xs : las

solve :: Int -> Int -> Int -> Int -> Int
solve a b c x = length $ do
  let maxFH = min a $ x `div` 500
  fh <- [0..maxFH]
  let rem = x - fh * 500
  let maxH = min b $ rem `div` 100
  h <- [0..maxH]
  let rem' = rem - h * 100
  guard $ rem' `div` 50 <= c
  pure ()

main :: IO ()
main = do
  a <- readInt
  b <- readInt
  c <- readInt
  x <- readInt
  print $ solve a b c x





Measured memory_bytes: 380