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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

ll asum[100005];
ll csum[100005];
int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;

	priority_queue<int, vector<int>, greater<int> > a;
	vector<int> b;
	priority_queue<int> c;

	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		a.push(t);
		asum[0] += t;
	}
	b.pb(0);
	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		b.pb(t);
	}

	for(int i=0; i<n; i++){
		int t;
		cin >> t;
		c.push(t);
		csum[n+1] += t;
	}

	for(int i=1; i<=n; i++){
		asum[i] = asum[i-1];
		if(b[i] > a.top()){
			asum[i] -= a.top();
			a.pop();
			a.push(b[i]);
			asum[i] += b[i];
		}
	}
	for(int i=n; i>=1; i--){
		csum[i] = csum[i+1];
		if(b[i] < c.top()){
			csum[i] -= c.top();
			c.pop();
			c.push(b[i]);
			csum[i] += b[i];
		}
	}

	ll ma = -INF;
	for(int i=0; i<=n; i++){
		ma = max(ma, asum[i] - csum[i+1]);
	}


	cout << ma << endl;
	
	return 0;
}


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main(){
  string S;cin>>S;long x=0,y=0;
  for(char c:S){
    if(c=='A'||c=='T'||c=='C'||c=='G')x++;
    else {y=max(y,x);x=0;}
  }y=max(y,x);
  cout<<y;
}

Measured memory_bytes: 3644
#include<stdio.h>
int main(){
	char s[10];
  	int i,n=0,x=0;
  
	scanf("%s",s);
  
	for(i=0;i<10;i++){
	 if(s[i]=='\0') break;
 	 else{
 	if(s[i]=='A'||s[i]=='C'||s[i]=='G'||s[i]=='T'){
 	 n++;
 	if(n>x) 
 	 x=n;
 	}
	 else n=0;
 	} 
	}
           
  	printf("%d",x);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
using namespace std;
int a,n,t;
bool isprime(int a)
{
	int i;
	for(i=2;i<=int(sqrt(a));i++)
	{
		if(a%i==0)
		return false;
	}
	if(i>=sqrt(a))
	return true;
	else
	return false;
 } 
int main()
{
	cin>>n;
	while(n--)
	{
		cin>>a;
		if(isprime(a))
		t++;
	}
	cout<<t<<endl;
	return 0;
 } 


Measured memory_bytes: 3100
<?php
fscanf(STDIN,"%s",$str);

$str_arr = str_split($str);

for($i=0;$i<count($str_arr)-1;$i++){
    if($str_arr[$i] === 'A' && $str_arr[$i+1] === 'C'){
        echo "Yes";
        return;
    }
}

echo "No";
?>

Measured memory_bytes: 4728
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int h,w,k;
vector<int> dp[75][75],ans;

vector<int> Max(vector<int> a,vector<int> b){
	if(a.size()>b.size())return a;
	if(a.size()<b.size())return b;
	rep(i,a.size()){
		if(a[i]>b[i])return a;
		if(a[i]<b[i])return b;
	}
	return a;
}//a???b?????§?????????

int main(){
	while(cin>>w>>h&&h+w){
	rep(i,h)rep(j,w)dp[i][j].clear();
	rep(i,h)rep(j,w){
		char z;cin>>z;
		if(isdigit(z)){
			if(z!='0'||dp[i][j].size()){
			dp[i][j].push_back(z-'0');
			dp[i+1][j]=Max(dp[i+1][j],dp[i][j]);
			dp[i][j+1]=Max(dp[i][j+1],dp[i][j]);
			}
		}
	}
	ans.clear();
	rep(i,h)rep(j,w)ans=Max(ans,dp[i][j]);
	rep(i,ans.size())cout<<ans[i];cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 3344
fun main(args: Array<String>) {
    val (a, b, q) = readLine()!!.split(' ').map(String::toInt)
    val aList = DoubleArray(a) { readLine()!!.toDouble() }.sorted().toTypedArray()
    val bList = DoubleArray(b) { readLine()!!.toDouble() }.sorted().toTypedArray()
    val xList = DoubleArray(q) { readLine()!!.toDouble() }
    for (x in xList) {
        val ta = aList.search(x)
        val ra = if (ta == a) -1 else ta
        val la = if (ra == -1) a - 1 else if (ra == 0) -1 else ra - 1
        val tb = bList.search(x)
        val rb = if (tb == b) -1 else tb
        val lb = if (rb == -1) b - 1 else if (rb == 0) -1 else rb - 1

        var min = Long.MAX_VALUE
        if (ra >= 0 && rb >= 0) min = Math.min(min, Math.max(aList[ra], bList[rb]).toLong() - x.toLong())
        if (la >= 0 && lb >= 0) min = Math.min(min, x.toLong() -  Math.min(aList[la], bList[lb]).toLong())
        if (ra >= 0 && lb >= 0) min = Math.min(min, (aList[ra] - x + aList[ra] - x + x - bList[lb]).toLong())
        if (rb >= 0 && la >= 0) min = Math.min(min, (bList[rb] - x + bList[rb] - x + x - aList[la]).toLong())
        if (la >= 0 && rb >= 0) min = Math.min(min, (x - aList[la] + x - aList[la] + bList[rb] - x).toLong())
        if (ra >= 0 && lb >= 0) min = Math.min(min, (x - bList[lb] + x - bList[lb] + aList[ra] - x).toLong())
        println(min)
    }

}

fun Array<Double>.search(target: Double, d: Double = 0.0000001): Int {
    val binarySearch = this.binarySearch(target - d)
    return if (binarySearch >= 0) binarySearch else Math.abs(binarySearch) - 1
}

Measured memory_bytes: 61436
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1e9+7;
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long LL;
typedef vector<int> VI;
typedef vector<string> VS;

int main(){
    int N, cnt1, cnt2 = 0;
    cin >> N;
    for (int i = 1; i <= N; i+=2){
        cnt1 = 0;
        for (int j = 1; j <= i; j+=2){
            if (i % j == 0){
                cnt1++;
            }
        }
        if (cnt1 == 8){
            cnt2++;
        }
    }
    cout << cnt2 << endl;
}

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

int main()
{
	int X, A, B;
	cin >> X >> A >> B;
	if (A >= B)
	{
		cout << "delicious" << endl;
	}
	else if (A + X >= B)
	{
		cout << "safe" << endl;
	}
	else
		cout << "dangerous" << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = input()
ans = 0
for i in range(N):
    x,y = S[0:i+1], S[i+1:]
    tmp = 0
    al = []
    for xi in x:
        if xi in y and not xi in al:
            al.append(xi)
            tmp += 1
    ans = max(ans,tmp)
print(ans)

Measured memory_bytes: 39152
#include<bits/stdc++.h>
using namespace std;
int i[11111111];
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  long long a,b,c,d=0,e=1,f=0;
  cin >>a;
  for(int n=1;n<=a;n++) cin >>i[n],d+=i[n];
  cin >>b;
  for(int n=0;n<b;n++){
    cin >>c>>e;
    f=d;
    f-=i[c];
    cout <<f+e<<'\n';
  }
  return (0);
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int student;
	float kg;
	float m;
	
	while (scanf("%d,%f,%f", &student, &kg, &m) != EOF){
		if (kg / (m * m) >= 25){
			printf("%d\n", student);
		}
	}
	
	return (0);
}

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

int main(){
    char h,d;
    cin >> h >> d;
    if(h == 'H'){
        if(d == 'H'){
            cout << 'H' << endl;
        }else{
            cout << 'D' << endl;
        }
    }else{
        if(d == 'H'){
            cout << 'D' << endl;
        }else{
            cout << 'H' << endl;
        }
    }
}


Measured memory_bytes: 256
import java.util.*;


public class Main {
    public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int line = sc.nextInt();
		int a[] = new int[line];
		for (int i = 0; i < line; i++) {
		    a[i] = sc.nextInt();
		}
		
		for (int i = a.length - 1; i >= 0; i--) {
		    if (i == a.length - 1) {
		        System.out.print(a[i]);
		    } else {
		        System.out.print(" " + a[i]);
		    }
		    
		}
		System.out.println();
    }
}


Measured memory_bytes: 26188
S = input()
T = input()

alphabets = 'abcdefghijklmnopqrstuvwxyz'

S_list = []
T_list = []

for i in alphabets:
    Scnt = S.count(i)
    Tcnt = T.count(i)
    if Scnt > 0:
        S_list.append(Scnt)
    if Tcnt > 0:
        T_list.append(Tcnt)

if sorted(T_list) == sorted(S_list):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3632
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0112
"""
import sys


W = [0]                         #  ??????x???????????§??????????????????????????????????????????????????°?????????????????§0?????????
def solve(data):
    global W
    total = 0
    data.sort()
    for i, t in enumerate(data):
        W.append(W[i] + t)      #  ??????????¬?????????????????????? = ??????????????????????????§??????????????????????¨? + ???????????????
    W[-1] = 0                   #  ????????????????¬???????????????¨??????????????§???????????°??????0?????????
    return sum(W)               #  ??¨?????????????????????????¨?


def main(args):
    global W
    while True:
        n = int(input())
        if n == 0:
            break
        data = [int(input()) for _ in range(n)]
        result = solve(data)
        print(result)
        W = [0]


if __name__ == '__main__':
    main(sys.argv[1:])

Measured memory_bytes: 8056
#include <iostream>
#include <algorithm>
#include <math.h>

using namespace std;

int nabeatsu(int n){
    int a, x, y, s;
    for ( int i = 1; i <= n; i++ ){
        a = 0, s = 0;
        x = i;
        while (x){
            y = x % 10;
            if (y == 3) a = 1;
            s += y;
            x /= 10;
        }
        if (s % 3 == 0) a = 1;
        if (a == 1) cout << " " << i;
    }
    cout << endl;
    return 0;
}

int main(){
    int n;
    cin >> n;
    nabeatsu(n);
    return 0;
}



Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define rep(i,n)for(long long i=0;i<(long long)(n);++i)
#define all(a) a.begin(), a.end()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
  
const int MOD=1e9+7;
const ll INF=1e18;
const ll inf=1e9;
const double pi=acos(-1);
int dx[8] = {1,0,-1,0,1,1,-1,-1};
int dy[8] = {0,1,0,-1,-1,1,1,-1};
 
const int MAX=100010;
      
 
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false); 
   
  int n,c;
  cin >> n >> c;
  vector<vector<int>> imos(c,vector<int>(MAX,0));
  rep(i,n){
    int s,t,x;
    cin >> s >> t >> x;
    s--;
    x--;
    imos[x][s]++;
    imos[x][t]--;
  }
  rep(i,c)rep(j,MAX) imos[i][j+1] += imos[i][j];
  
  int ans = 0;
  rep(j,MAX){
    int cnt = 0;
    rep(i,c){
      if(imos[i][j])cnt++;
    }
    ans=max(ans,cnt);
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 15344
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    string A, B, C;
    cin >> N >> A >> B >> C;
    ll ans = 0;
    for (ll i = 0; i < N; i++) {
        set<char> st;
        st.insert(A[i]);
        st.insert(B[i]);
        st.insert(C[i]);
        ans += st.size() - 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
#include <string>
#include <math.h>
#include <map>
using namespace std;
int k;
int main(){
    cin >> k;
    int count=0;
    for(int i=1; i<=k; i+=2){
        for(int j=2; j<=k; j+=2){
            count++;
        }
    }
    cout << count << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <queue>
#include <set>
#include <stack>
#include <map>
#include <unordered_map>
#include <cmath>
#include <utility> // pair make_pair
#include <algorithm>
#include <functional>
#include <iomanip>
#include <climits> // LLONG_MAX, LLONG_MIN, INT_MIN, INT_MAX
#include <assert.h>

#define m0(x) memset(x,0,sizeof(x))
#define m1(x) memset(x,63,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define ll long long
//#define int ll
#define INF INT_MAX/10

using namespace std;
using Pi = pair<int, int>;
using Graph = vector<vector<int> >;
using WeightGraph = vector<vector<Pi> >;

int Input[100100];

int main() {
  int N, L; cin >> N >> L;
  int sum = 0;
  for (int i = 0; i < N; i++) {
    sum += L + i;
    Input[i] = L+i;
  }
  // cout << sum << endl;
  if (Input[N-1] < 0) {
    cout << sum - Input[N-1] << endl;
  } else if (Input[0] > 0){
    cout << sum - Input[0] << endl;
  } else {
    cout << sum << endl;
  }
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,k;
int main()
{
    cin>>a>>b>>k;
    if(a+b<=k){
        cout<<0<<" "<<0;
    }
    else{
        if(a>=k){
            cout<<a-k<<" "<<b;
        }
        else{
            k=k-a;
            a=0;
            cout<<a<<" "<<b-k;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int N;
    cin >> N;
    vector<int> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];
    bool oddExist = false;
    for (int i = 0; i < N; i++) {
        if (a[i] % 2 == 1) oddExist = true;
    }
    if (oddExist) cout << "first" << '\n';
    else cout << "second" << '\n';
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const ll INF = 1e17;
// https://atcoder.jp/contests/abc143/submissions/8034843

int main() {
    // input
    ll N;
    cin >> N;

    ll ans=INF;
    for (int i=1; i<sqrt(N)+1; i++)
    {
        if (N%i == 0)
        {
            ans = min(ans, i-1 + N/i -1 );
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#define INF (INT_MAX / 2)
//#define DEBUG true
#define DEBUG false
#define MAX_N 100000
#define MAX_LOG 20
using namespace std;

class edge{
  public:
    int u, v, c;
    edge(){}
    edge(int u, int v, int c): u(u), v(v), c(c){}
};

vector< vector< edge > > tree;

void dfs(int v, int p, long long d, long long dist[]){
  dist[v] = d;
  for(edge e: tree[v]){
    int w = e.v;
    if(w != p){
      dfs(w, v, d + e.c, dist);
    }
  }
}

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

  int n;
  cin >> n;
  int a[n - 1], b[n - 1], c[n - 1];
  for(int i = 0; i < n - 1; i++){
    cin >> a[i] >> b[i] >> c[i];
  }
  int q, k;
  cin >> q >> k;
  int x[q], y[q];
  for(int i = 0; i < q; i++){
    cin >> x[i] >> y[i];
  }
  tree.resize(n);
  for(int i = 0; i < n - 1; i++){
    int s = a[i] - 1, t = b[i] - 1;
    tree[s].emplace_back(edge(s, t, c[i]));
    tree[t].emplace_back(edge(t, s, c[i]));
  }

  long long dist[n];
  dfs(k - 1, -1, 0, dist);

  string ans;
  for(int i = 0; i < q; i++){
    long long d = dist[x[i] - 1] + dist[y[i] - 1];
    ans += to_string(d) + "\n";
  }

  cout << ans;

  return 0;
}

Measured memory_bytes: 17924
import math

H = int(input())

if H == 1:
  print(1)
  exit()

root = math.floor(math.log2(H))

total = 1
#print(math.log2(H))
mem = [1 for _ in range(root+1)]

for i in range(1, root+1):
  mem[i] = mem[i-1] * 2
  total += mem[i]
  
print(total)

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

using namespace std;

typedef long long ll;

const int maxn = 22;

bool buf;
int n, k, len;
int bn[maxn];
vector<int> d;
bool bad[maxn];

int main() {

	buf = scanf("%d%d", &n, &k);
	for (int i = 1; i <= k; i++) {
		int x;
		buf = scanf("%d", &x);
		bad[x] = true;
	}

	while (n > 0) {
		bn[++len] = n%10;
		n /= 10;
	}

	bool chg = false;
	for (int i = len; i >= 1; i--) {
		if (chg) {
			bn[i] = 0;
			while (bad[bn[i]])
				bn[i]++;
		} else if (bad[bn[i]]) {

			int j = i;
			int c = 1;
			while (c) {
				c = 0;
				do {
					bn[i] ++;
					if (bn[i] > 9) {
						bn[i] = 0;
						c = 1;
					}
				} while (bad[bn[i]]);
				i += c;
				len = max(i, len);
			}

			i = j;
			chg = true;
		}
	}

	for (int i = len; i >= 1; i--) 
		printf("%d", bn[i]);
	putchar('\n');

	return 0;
}

Measured memory_bytes: 3804
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <cmath>
using namespace std;
using ll = long long;

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

    int N;
    cin >> N;
    vector<ll> A(N);
    vector<ll> B(N);

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

    sort(B.begin(), B.end());

    ll res = 0;
    for (int i = 0; i < N; i++) {
        res += abs(B[i]-B[N/2]);
    }

    cout << res << '\n';    

    
    return 0;
}

Measured memory_bytes: 3328
<?php
fscanf(STDIN, "%d%d", $N, $M);
for($i = 0; $i < $N; $i++){
  $danger[] = intval(trim(fgets(STDIN)));
}
foreach($danger as $d){
  $map[$d] = true;  
}

$dp[-1] = 0;
$dp[0] = 1;
for($i = 1; $i <= $N; $i++){
  if(isset($map[$i])){
    $dp[$i] = 0;
  }else{
    $dp[$i] = $dp[$i-2] + $dp[$i-1];
  }
  $dp[$i] %= 10**9+7;
}
printf("%d\n", $dp[$N]);


Measured memory_bytes: 21232
import sys
readline = sys.stdin.readline
from heapq import heappop as hpp, heappush as hp
class MinCostFlowwithDijkstra:
    INF = 1<<60
    
    def __init__(self, N):
        self.N = N
        self.Edge = [[] for _ in range(N)]
    
    def add_edge(self, st, en, cap, cost):
        self.Edge[st].append([en, cap, cost, len(self.Edge[en])])
        self.Edge[en].append([st, 0, -cost, len(self.Edge[st])-1])
    
    def get_mf(self, so, si, fl):
        N = self.N
        INF = self.INF
        res = 0
        Pot = [0]*N
        geta = N
        
        
        prv = [None]*N
        prenum = [None]*N
        while fl:
            dist = [INF]*N
            dist[so] = 0
            Q = [so]
            
            while Q:
                cost, vn = divmod(hpp(Q), geta)
                if dist[vn] < cost:
                    continue
                
                for enum in range(len(self.Edge[vn])):
                    vf, cap, cost, _ = self.Edge[vn][enum]
                    cc = dist[vn] + cost - Pot[vn] + Pot[vf]
                    if cap > 0 and dist[vf] > cc:
                        dist[vf] = cc
                        prv[vf] = vn
                        prenum[vf] = enum
                        hp(Q, cc*geta + vf)
            
            if dist[si] == INF:
                return -1
            
            for i in range(N):
                Pot[i] -= dist[i]
            
            cfl = fl
            vf = si
            while vf != so:
                cfl = min(cfl, self.Edge[prv[vf]][prenum[vf]][1])
                vf = prv[vf]
            
            fl -= cfl
            res -= cfl*Pot[si]
            vf = si
            while vf != so:
                e = self.Edge[prv[vf]][prenum[vf]]
                e[1] -= cfl
                self.Edge[vf][e[3]][1] += cfl
                vf = prv[vf]
        return res


N, K = map(int, readline().split())

MAX = 10**9+7

A = [list(map(int, readline().split())) for _ in range(N)]

T = MinCostFlowwithDijkstra(2*N+2)
st = 2*N
en = st+1

T.add_edge(st, en, MAX, MAX)
for i in range(N):
    T.add_edge(st, i, K, 0)
    T.add_edge(N+i, en, K, 0)

for i in range(N):
    for j in range(N):
        T.add_edge(i, N+j, 1, MAX-A[i][j])

ff = N//K * K*K + (N%K)**2 

print(MAX*MAX - T.get_mf(st, en, MAX))
dot = ord('.')
cross = ord('X')
Ans = [[dot]*N for _ in range(N)]

cnt = 0
for j in range(N):
    for vf, cap, _, _ in T.Edge[N+j]:
        if cap == 1 and vf != en:
            Ans[vf][j] = cross
print('\n'.join(''.join(map(chr, a)) for a in Ans))


Measured memory_bytes: 72424
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long; 
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
//constexpr long long MOD = 998244353LL;
template<class T, class U> inline bool chmax(T &a, U b) { if (a < b) { a = b; return true;} return false; }
template<class T, class U> inline bool chmin(T &a, U b) { if (a > b) { a = b; return true;} return false; }
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    
    ll a,b,k; cin >> a >> b >> k;
    
    if(a>=k) cout << a-k << " " << b << ln;
    else if(a+b>k) cout << 0 << " " << a+b-k << ln;
    else cout << 0 << " " << 0 << ln;
    
    return 0;
 }

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

#define loop(i,a,b) for(int i=(a); i<int(b); i++)
#define rep(i,b) loop(i,0,b)

int main(){
    int n;
    while(cin >> n && n){
        vector<pair<int,int>> v;
        rep(i,n){
            int g; cin >> g;
            int cnt = 0;
            if(i&1){
                while(v.size() && v.back().first!=g){
                    cnt+=v.back().second;
                    v.pop_back();
                }
                if(v.size()==0) v.push_back(make_pair(g,0));
                v.back().second++;
                v.back().second += cnt;
            } else {
                if(v.size() && v.back().second==g){
                    cnt+=v.back().second;
                    v.pop_back();
                }
                v.push_back(make_pair(g,cnt+1));
            }
        }
        int ans = 0;
        rep(i,v.size())if(v[i].first==0){
                ans+=v[i].second;
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1196
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll=long long;

int main() {
    int N; cin>>N;
    vector<bitset<30>> a(N);
    vector<bitset<30>> ans(N);
    int mx=0;
    for (int i = 0; i < N; i++){
        int tmp; cin>>tmp;
        a[i]=tmp;
        mx=max(tmp,mx);
    }
    int mxbit=0;//最大ビット数
    int tmp=2;
    while(mx/tmp>0){
        tmp*=2;
        mxbit++;
    }
    for (int i = 0; i <= mxbit; i++){
        int sum=0;
        for (int j = 0; j < N; j++){
            sum=(sum+a[j][i])%2;
        }
        for (int j = 0; j < N; j++){
            ans[j][i]=(sum+a[j][i])%2;
        }
    }
    for (int i = 0; i < N; i++){
        cout<<ans[i].to_ulong()<<" ";
    }
}

Measured memory_bytes: 6208
#include<algorithm>
#include<iostream>
#include<functional>
#include<cmath>
#include<iomanip>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if(a+b==15)
    cout<<"+"<<endl;
  else if(a*b==15)
    cout<<"*"<<endl;
  else
    cout<<"x"<<endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>

#define mod 1000000007

using namespace std;

int DP[2001];

int main()
{
    int S, i, j;

    scanf("%d", &S);

    DP[0] = 1;
    DP[1] = 0;
    DP[2] = 0;
    for(i = 3; i <= S; ++i){
        DP[i] = 0;
        for(j = 3; j <= i; ++j)
            DP[i] = (DP[i] + DP[i - j]) % mod;
    }

    printf("%d", DP[S]);

    return 0;
}


Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define loop(n)  for(int i=0;i<n;i++)
#define loop1(i,a,n)  for(int i=a;i<n;i++)
#define m 1000000007
using namespace std;
int main()
{
    fastio;
    int h,w;
    cin>>h>>w;
    long long a[h+1][w+1]={};
    a[1][1]=1;
    char c;
    cin>>c;
    for(int j=2;j<=w;j++)
    {
      cin>>c;
      if(c=='.')
      {
        a[1][j]=a[1][j-1];
      }
      else
      {
        a[1][j]=0;
      }
    }
    for(int i=2;i<=h;i++)
    {
      for(int j=1;j<=w;j++)
      {
        cin>>c;
        if(c=='.')
        {
          a[i][j]=(a[i][j-1]+a[i-1][j])%m;
        }
        else
        {
          a[i][j]=0;
        }
      }
    }
    cout<<a[h][w];
    return 0;
}

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

int main(){
  string str, t;
  cin >> str >> t;

  for(int i = str.size()-1; i >= 0; i--){
    //if(str[i] == t[0] || str[i] == '?'){
    for(int j = 0; j < t.size(); j++){
      if(str[i-j] != t[t.size()-1-j] && str[i-j] != '?') {break;}
	if(j+1 == t.size()){
	  //cout << "in" << endl;
	  str.replace(i-j, t.size(), t);
	  for(int k = 0; k < str.size(); k++) if(str[k]=='?') str[k] = 'a';
	  cout << str << endl;
	  return 0;
	}
      }
      //}
  }
  cout << "UNRESTORABLE" << endl;
}

      


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

using namespace std;

int main() {
	int c1x, c1y, c1r;
	int c2x, c2y, c2r;

	cin >> c1x;
	cin >> c1y;
	cin >> c1r;

	cin >> c2x;
	cin >> c2y;
	cin >> c2r;

	int X = (c1x - c2x) * (c1x - c2x);
	int Y = (c1y - c2y) * (c1y - c2y);

	double dis;
	double  sumR, difR;

	dis = sqrt(X+Y);
	sumR = c1r + c2r;

	if (c1r > c2r)
		difR = c1r - c2r;
	else
		difR = c2r - c1r;


	if (dis > sumR)
		cout << 4 << endl;

	else if (dis == sumR)
		cout << 3 << endl;

	else if (difR < dis && dis < sumR)
		cout << 2 << endl;

	else if (dis == difR)
		cout << 1 << endl;

	else
		cout << 0 << endl;

	return 0;

}




Measured memory_bytes: 3120
import java.util.*;

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

        Scanner sc = new Scanner(System.in);
        
        int A = sc.nextInt();
        int B = sc.nextInt();
        int add = A + B;
        int sub = A - B;
        int mul = A * B; 
        int max = 0;
        
        if(add >= sub && add >= mul) max = add;
        if(sub >= add && sub >= mul) max = sub;
        if(mul >= add && mul >= sub) max = mul;

        System.out.println(max);
    }
}
 

Measured memory_bytes: 21844
using System;
using System.Linq;
using System.Collections.Generic;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        var input = ReadLine().Split(' ');
        var a = int.Parse(input[0]);
        var b = int.Parse(input[1]);

        if (b < a) { a--; }
        WriteLine(a.ToString());

    }

}

Measured memory_bytes: 11092
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a) = min((a), (b)))
#define chmax(a, b) ((a) = max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const double pi = acos(-1);
const double eps = 1e-10;

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

int main(){
    string s; cin>>s;
    int n = s.size();
    vector<vector<ll>> dp(n+1, vector<ll>(2, 0LL));
    dp[0][0] = 1;

    for(int i=0; i<n; i++){
        if(s[i] == '0'){
            // (0, 0)
            (dp[i+1][0] += dp[i][0]) %= MOD;
        }
        else{
            // (0, 1), (1, 0)
            (dp[i+1][0] += dp[i][0] * 2) %= MOD;
            // (0, 0)
            (dp[i+1][1] += dp[i][0]) %= MOD;
        }

        // (0, 0), (0, 1), (1, 0)
        (dp[i+1][1] += dp[i][1] * 3) %= MOD;
    }

    cout << (dp[n][0] + dp[n][1]) % MOD << endl;
}

Measured memory_bytes: 5760
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <iostream>
#include <sstream>
#include <string>
#include <iomanip>
#include <set>
#include <map>

using namespace std;

#define EPS 1e-14
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define REP(i,n) FOR(i, 0, n)
#define PI 2*acos(0.0)
#define ALL(a) (a).begin(),(a).end()
#define DEBUG(x) cout<<#x <<": "<< x << "\n"
#define DEBUG_ARR(a) REP(i, size(a)){ cout << #a << "[" << i << "]: " << a[i] << "\n"; }
const int VX[] = { 0, 1, 0, -1 };
const int VY[] = { 1, 0, -1, 0 };
const long MOD = 1000000007;

int pre[51];
int low[51];
int m[51][51];

int N, M;

int dfs(int v, int count, int from, int& ret)
{
	pre[v] = count++;
	low[v] = pre[v];

	for (int i = 0; i < N; i++)
	{
		if (m[v][i] == 0) continue;

		if (pre[i] == -1)
		{
		  low[v] = min(low[v], dfs(i, count, v, ret));
		  if (low[i] == pre[i]) ret++;
		} else {
		  if (from == i)
		  {
			continue;
		  }
		  low[v] = min(low[v], low[i]);
		}
	  }

	return low[v];
}

int main() {
	//	--- I/O 高速化 ---
	cin.tie(0);
	ios::sync_with_stdio(false);
	// --- ここまで ---

	int a, b, ret = 0;
	cin >> N >> M;

	REP(i, 51)
	{
		pre[i] = -1;
		low[i] = -1;
		REP(j, 51)
		{
			m[i][j] = 0;
		}
	}

	REP(i, M)
	{
		cin >> a >> b;
		a--; b--;
		m[a][b] = 1;
		m[b][a] = 1;
	}

	dfs(0, 0, -1, ret);

	cout << ret << "\n";

	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int ans[] = new int[n];

		for (int i = 0; i < n; i++) {
			int num = sc.nextInt();
			ans[num - 1] = i + 1;
		}

		for (int num : ans) {
			System.out.println(num);
		}

	}
}


Measured memory_bytes: 63012
#include <cstdio>
#include <algorithm>
using namespace std;

int insertionSort(int A[], int N) {
    int min;
    int flag;
    int count = 0;
    
    for (int i = 0; i < N; i++) {
        flag = 0;
        min = i;
        for (int j = i+1; j < N; j++) {
            if (A[min] > A[j]) {
                min = j;
                flag = 1;
            }
        }
        swap(A[min], A[i]);
        if (flag == 1) count++;
    }
    
    return count;
}

int main(void){
    // Your code here!
    int N;
    scanf("%d", &N);
    int A[100];
    
    for (int i = 0; i < N; i++) scanf("%d", &A[i]);
    
    int count = insertionSort(A, N);
    
    for (int i = 0; i < N; i++) {
        printf("%d", A[i]);
        if (i == N-1) {
            printf("\n");
        }
        else {
            printf(" ");
        }
    }
    printf("%d\n", count);
}



Measured memory_bytes: 2736
import java.util.Scanner;

public class Main 
{
	public static void main(String args[])
	{
		Scanner sc = new Scanner(System.in);
		int a,b;
		int ans;
		a=sc.nextInt();
		b=sc.nextInt();
		ans=a*b;
		if(ans%2==1)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}


Measured memory_bytes: 20948
n, k = map(int, input().split())
p = list(map(int, input().split()))

class SegmentTree:
    def __init__(self, n, func=lambda x, y: min(x, y), ide=float("inf")):
        self.n = 2 ** (n-1).bit_length()
        self.data = [ide] * (self.n*2)
        self.func, self.ide = func, ide
    
    def build(self, data):
        for i, x in enumerate(data):
            self.data[self.n+i] = x
        for i in range(self.n-1, 0, -1):
            self.data[i] = self.func(self.data[i*2], self.data[i*2+1])

    def update(self, i, x):
        i += self.n
        self.data[i] = x
        while i > 1:
            i //= 2
            self.data[i] = self.func(self.data[i*2], self.data[i*2+1])

    def query(self, l, r):
        l += self.n; r += self.n 
        res = self.ide
        while l < r:
            if l & 1:
                res = self.func(res, self.data[l])
                l += 1
            if r & 1:
                res = self.func(res, self.data[r-1])
            l //= 2; r //= 2
        return res
    
    def get(self, i):
        return self.data[self.n + i]

minst, maxst = SegmentTree(n), SegmentTree(n, lambda x, y: max(x, y), -float("inf"))
minst.build(p)
maxst.build(p)

ans = n - k + 1
for i in range(n-k):
    j = i + k
    if minst.query(i, j+1) == p[i] and maxst.query(i, j+1) == p[j]:
        ans -= 1

srted = [1] * n
cnt = 0
for i in range(n):
    if p[i] > p[i-1]: srted[i] = srted[i-1] + 1
    if srted[i] == k: cnt += 1

if cnt > 1: ans -= cnt - 1

print(ans)


Measured memory_bytes: 132856
// Problem : D - Wide Flip
// Contest : AtCoder Regular Contest 088
// URL : https://atcoder.jp/contests/arc088/tasks/arc088_b
// Memory Limit : 256 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define cerr if(1)cerr
#define size(x) (int)x.size()
#define all(x) x.begin(), x.end()
#define temptts template <class T, class... Ts>

const int N = 1e6 + 1, mod = 1e9 + 7, inf = 2e9;

int n;
bool a[N];

bool wrong(int k) {
	if (k + k <= n) {
		return 0;
	}
	bool zero = 0, one = 1;
	for (int i = n - k + 1; i <= k; i++) {
		zero |= a[i];
		one &= a[i];
	}
	return !(!zero || one);
}

int main() { cin.tie(0)->sync_with_stdio(0);
	char c;
	while (true) {
		c = getchar();
		if (c == '\n') {
			break;
		}
		a[++n] = c - '0';
	}
	int ans = 0;
	for (int i = log2(n); i >= 0; i--) {
		ans += 1 << i;
		if (ans > n || wrong(ans)) {
			ans -= 1 << i;
		}
	}
	cout << ans;
}


Measured memory_bytes: 384
s1 = raw_input().split(' ')
n, m = int(s1[0]), int(s1[1])
i2il = {}
for _ in range(m):
    s = raw_input().split(' ')
    if s[0] in i2il:
        i2il[s[0]].append(s[1])
    else:
        i2il[s[0]] = [s[1]]
    if s[1] in i2il:
        i2il[s[1]].append(s[0])
    else:
        i2il[s[1]] = [s[0]]
if '1' not in i2il or s1[0] not in i2il:
    print 'IMPOSSIBLE'
else:
    mid = i2il['1']
    bhit = False
    for m in mid:
        if s1[0] in i2il[m]:
            print 'POSSIBLE'
            bhit = True
            break
    if not bhit:
        print 'IMPOSSIBLE'

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

typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(int i=a;i<b;i++)
#define rlo(i,n) for(int i=n-1;i>=0;i--)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()
#define mem(a,b) memset(a,b,sizeof(a))
#define pr(a) {for(auto x:a)cout<<x<<" ";cout<<nl;}
#define yes cout<<"Yes"<<nl
#define no cout<<"No"<<nl
#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

void f()
{
  string s,t;
  cin>>s>>t;
  int n=sz(s);
  lo(i,0,n)
  {
    if(s==t)
    {
      yes;
      return;
    }
    s=s[n-1]+s;
    s.pop_back();
  }
  no;
}

int main()
{
    su;
    f();
    return 0;
}


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

int main() {
  int N, M;
  cin >> N;
  M = N;
  
  int f_N = 0;
  while (M) {
    f_N += M % 10;
    M /= 10;
  }
  
  if (N % f_N == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

vector<pair<ll,ll>> pfact(ll n)
{
    vector<pair<ll,ll>> pf;
    ll t = n, cnt;
    
    for(ll i=2; i*i<=t; ++i) {
        cnt = 0;
        if(t % i != 0) continue;
        while(t % i == 0) {
            t /= i;
            ++cnt;
        }
        pf.pb(make_pair(i, cnt));
    }
    
    if(t != 1) pf.pb(make_pair(t, 1));
    
    return pf;
}

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

    vec C(N+1, 0);
    REP(i,2,N+1) {
        auto P = pfact(i);
        FORR(p,P) C[p.first] += p.second;
    }

    ll cnt = 1;
    REP(i,2,N+1) cnt = (cnt * (C[i] + 1)) % MOD;
    PR(cnt);

    return 0;
}

/*



*/

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

int main(){
    using namespace std;
    constexpr unsigned long MOD = 998244353;

    constexpr unsigned long mx = 1000001;
    vector<vector<unsigned long>> fact(mx, {1});
    for(unsigned long i = 2; i < mx; ++i)for(unsigned long j = i; j < mx; j += i)fact[j].push_back(i);

    vector<unsigned long> inv(mx, 1);
    for(unsigned long i = 2; i < mx; ++i)inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;

    vector<unsigned long> sieve(mx, 1);
    for(unsigned long i = 2; i < mx; ++i)if(sieve[i])for(unsigned long j = i; j < mx; j += i){
        sieve[j] = 0;
        (inv[j] *= MOD + 1 - i) %= MOD;
    }

    unsigned long N;
    cin >> N;

    vector<unsigned long> hoge(mx);
    for(unsigned long _ = 0, i; _ < N; ++_){
        cin >> i;
        for(const auto& j : fact[i])hoge[j] += i;
    }
    for(auto& i : hoge)i %= MOD;

    unsigned long ans{MOD - hoge[1]};
    for(unsigned long i = 1; i < mx; ++i)if(hoge[i])ans += inv[i] * hoge[i] % MOD * hoge[i] % MOD;
    ans %= MOD;
    (ans += MOD * (ans & 1)) >>= 1;
    cout << ans << endl;

    return 0;
}

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

int main() {
  int A, B, C, X, Y;
  cin >> A >> B >> C >> X >> Y;

  int sum = 0;
  int sum2 = 0;
  if (A + B >= 2 * C) {
    if (X > Y) sum = Y * 2 * C + (X - Y) * A;
    else sum = X * 2 * C + (Y - X) * B;
  }
  else sum = A * X + B * Y;

  sum2 = 2 * C * max(X, Y);
  if (sum2 < sum) sum = sum2;
  cout << sum << endl;
}


Measured memory_bytes: 256
N = int(input())
S = list(input())
S = list(map(ord, S))
for i in range(len(S)):
    S[i] -= 65
    S[i] += N
    S[i] %= 26
    S[i] += 65
S = list(map(chr, S))
print(''.join(S))
    

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

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


int main (){
  
    ll n; cin >> n;
    if(n%2 != 0){
        cout << 0 << endl;
        return 0;
    }
    ll ans = 0;
    for(ll i=5; i<=n; i *= 5){
     
        ans += n/(i*2);
    }
    cout << ans << endl;
    
}


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

#define ll long long
#define str string
#define pii pair<int, int>
#define pll pair<ll, ll>
#define fi first
#define se second

#define vc vector<char>
#define vvc vector<vc>
#define vi vector<int>
#define vll vector<ll>
#define vvi vector<vi>
#define vvll vector<vll>
#define vvvll vector<vvll>
#define vs vector<str>
#define vvs vector<vs>
#define vpii vector<pii>
#define vvpii vector<vpii>
#define vpll vector<pll>
#define vvpll vector<vpll>
#define vb vector<bool>
#define vvb vector<vb>
#define rep(i, a, b) for (int i = (a); i < int(b); i++)
#define repi(i, a, b) for (int i = (a); i <= int(b); i++)


using namespace std;
ll INF = LONG_LONG_MAX;
ll mod = 1000000000 + 7;

template <typename T, typename L>
void read(vector<T> & _data, L & _size, bool _shift) {
    _data.resize(_size + (ll)_shift);
    for (ll i = (ll)_shift; i < _size + (ll)_shift; i++)
        cin >> _data[i];
}

template <typename T, typename L>
void read(vector<vector<T>> & _data, L & _rows, L & _cols, bool _shiftRows, bool _shiftCols) {
    _data.resize(_rows + (ll)_shiftRows);
    for (ll i = 0; i < _rows + (ll)_shiftRows; i++)
        _data[i].resize(_cols + (ll)_shiftCols);
    for (ll i = (ll)_shiftRows; i < _rows + (ll)_shiftRows; i++)
        for (ll j = (ll)_shiftCols; j < _cols + (ll)_shiftCols; j++)
            cin >> _data[i][j];
}

template <typename T>
void write(vector<T> & _data, bool _shift) {
    for (ll i = (ll)_shift; i < _data.size(); i++)
        cout << _data[i] << " ";
    cout << endl;
}


//TODO: SOLUTION


void solve() {
    ll n, k, q;
    cin >> n >> k >> q;
    vll a; read(a, n, 0);
    ll ans = INF/2;

    for (auto x : a) {
        vvll split;
        int i = 0;
        while (i < n) {
            while (i < n && a[i] < x)
                i++;
            if (i >= n)
                break;

            split.push_back({});
            while (i < n && a[i] >= x) {
                split[split.size() - 1].push_back(a[i]);
                i++;
            }
        }

        vll all;

        for (auto v : split) {
            sort(v.begin(), v.end());
            int j = 0;
            while (j < (int)v.size() - k + 1) { // v.size() is unsigned integer
                all.push_back(v[j]);
                j++;
            }
        }

        sort(all.begin(), all.end());

        if ((ll)all.size() >= q)
            ans = min(ans, all[q - 1] - all[0]);
    }

    cout << ans << endl;
}


int main() {

    // TODO: Set value of this variable manually
    bool _multipleTestCases = false;

    if (_multipleTestCases) {
        ll t; cin >> t;
        while (t--)
            solve();
    }
    else {
        solve();
    }

    return 0;
}

Measured memory_bytes: 3736
//#include <bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<numeric>
#include<cstdio>
#include<cmath>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<queue>
#include<ctype.h>
#include <fstream>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;
typedef long long ll;//int64
typedef unsigned long long ull;
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a*b/gcd(a,b);}
int dy[4]={0,1,0,-1};
//----------program from here----------

int main(){
  int a=0,b=0,c=0;

  cin >> a >> b >> c;
  cout << (b-a==c-b?"YES":"NO") << endl;

  return 0;
}

Measured memory_bytes: 256
class Dice:
    same_dice_index = ((0, 1, 2, 3, 4, 5), (0, 2, 4, 1, 3, 5), (0, 3, 1, 4, 2, 5),
                       (0, 4, 3, 2, 1, 5), (1, 0, 3, 2, 5, 4), (1, 2, 0, 5, 3, 4),
                       (1, 3, 5, 0, 2, 4), (1, 5, 2, 3, 0, 4), (2, 0, 1, 4, 5, 3),
                       (2, 1, 5, 0, 4, 3), (2, 4, 0, 5, 1, 3), (2, 5, 4, 1, 0, 3),
                       (3, 0, 4, 1, 5, 2), (3, 1, 0, 5, 4, 2), (3, 4, 5, 0, 1, 2),
                       (3, 5, 1, 4, 0, 2), (4, 0, 2, 3, 5, 1), (4, 2, 5, 0, 3, 1),
                       (4, 3, 0, 5, 2, 1), (4, 5, 3, 2, 0, 1), (5, 1, 3, 2, 4, 0),
                       (5, 2, 1, 4, 3, 0), (5, 3, 4, 1, 2, 0), (5, 4, 2, 3, 1, 0))

    def __init__(self, str_list):
        self.faces = str_list

    def is_same(self, dice):
        for i in Dice.same_dice_index:
            for n, j in enumerate(i):
                if dice.faces[n] != self.faces[j]:
                    break
            else:
                return True
        return False

    def is_unique(self, dices_list):
        for i in dices_list:
            if self.is_same(i):
                return False
        return True

import sys

n = int(sys.stdin.readline())

dices = []

for i in range(n):
    str_list = sys.stdin.readline().split()
    new_dice = Dice(str_list)
    if not new_dice.is_unique(dices):
        print('No')
        break
    dices.append(new_dice)
else:
    print('Yes')

Measured memory_bytes: 7896
import java.util.Arrays;
import java.util.Scanner;

class Main{
	static long mod=1000000007; // 10e9 + 7
	static long pow(long a, long x){
		if(x == 0) return 1;
		if(x == 1) return a % mod;
		else if(x % 2 == 0) return pow((a * a) % mod, x / 2) % mod;
		else return (a * pow((a * a) % mod, x / 2)) % mod;
	}
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		int[] B = new int[N];
		for(int i = 0; i < N; i++) A[i] = sc.nextInt();
		if(N % 2 == 0) {
			for(int i = 0; i + 1 < N; i += 2) {
				B[i] = i + 1; B[i + 1] = i + 1;
			}
		}else {
			B[0] = 0;
			for(int i = 1; i + 1 < N; i += 2) {
				B[i] = i + 1; B[i + 1] = i + 1;
			}
		}
		Arrays.sort(A);
		boolean check = true;
		long ans = pow(2, (long)(N / 2));
		for(int i = 0; i < N; i++) if(B[i] != A[i]) check = false;

		System.out.println(check ? ans : 0);

	}
}

Measured memory_bytes: 58812
n = int(input())
a = list(map(int, input().split()))

total = 0

for i in range(n):
    total = total + a[i]
ts = total * total

iss = 0

for i in range(n):
    iss += a[i] * a[i]
ans = (ts - iss) // 2
print(ans % (10**9 + 7))


Measured memory_bytes: 31608
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
#define __builtin_popcount __builtin_popcountll

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 (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
    os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const map<S, T> &t) {
    os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    while(cin >> n){
        vector<vi> g(n);
        REP(i, n - 1) {
            int u, v;
            cin >> u >> v; u--; v--;
            g[u].push_back(v);
            g[v].push_back(u);
        }
        vi d(n);
        REP(i, n) cin >> d[i];
        sort(ALL(d));
        queue<int> q;
        q.push(0);
        vi ans(n, -1);
        ll sum = accumulate(ALL(d), 0ll) - d.back();
        while(!q.empty()) {
            int u = q.front(); q.pop();
            ans[u] = d.back(); d.pop_back();
            for (int v : g[u]) {
                if (ans[v] == -1) q.push(v);
            }
        }
        cout << sum << endl;
        REP(i, n) cout << ans[i] << " \n"[i + 1 == n];
    }
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int A,B,M;
  cin >> A >> B >> M;
  int a[A],b[B],C[M+1]={0};
  for(int i = 0; i < A; i++) cin >> a[i];
  for(int i = 0; i < B; i++) cin >> b[i];
  int min_a[A],min_b[B];
  memcpy(min_a, a, sizeof(a));
  memcpy(min_b, b, sizeof(b));
  sort(min_a, min_a + (sizeof(min_a)/sizeof(min_a[0])));
  sort(min_b, min_b + (sizeof(min_b)/sizeof(min_b[0])));
  C[0] = min_a[0] + min_b[0];
  for(int i = 1; i < M+1; i++){
    int x,y,c;
    cin >> x >> y >> c;
    C[i] = a[x-1] + b[y-1] - c;
  }
  sort(C, C + (sizeof(C)/sizeof(C[0])));
  cout << C[0] << endl;
}

Measured memory_bytes: 2176