akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int cnt[1100][1100];
int las[1100][1100];
int las2[1100][1100];

int Las[1100][1100];
int Las2[1100][1100];
int req[1100];
int main(){
	int a,b;scanf("%d%d",&a,&b);
	int M=0;
	for(int i=0;i<a;i++){
		int x,y;scanf("%d%d",&x,&y);
		cnt[x%b][y%b]++;
		M=max(M,cnt[x%b][y%b]);
	}
	int ret=mod;
	for(int i=0;i<b;i++){
		for(int j=0;j<b;j++){
			las[i][j]=las2[i][j]=Las[i][j]=Las2[i][j]=-1;
		}
	}
	for(int i=0;i<b;i++)for(int j=0;j<b;j++){
		if(cnt[i][j]==0)continue;
		int tmp=sqrt(cnt[i][j]-0.5)+1;
		if((int)(sqrt(M-0.5)+1)!=tmp)continue;
		if(cnt[i][j]>tmp*(tmp-1)){
			Las[i][j]=j;
		}else{
			Las2[i][j]=j;
		}
	}
	
	for(int i=0;i<b;i++){
		int cur=-1;
		int pr=-1;
		for(int k=0;k<2;k++){
			for(int j=0;j<b;j++){
				if(Las[i][j]!=-1)cur=Las[i][j];
				if(pr!=-1){
					las[i][j]=pr;
				}
				pr=cur;
			}
		}
	}
	for(int i=0;i<b;i++){
		int cur=-1;
		int pr=-1;
		for(int k=0;k<2;k++){
			for(int j=0;j<b;j++){
				if(Las2[i][j]!=-1)cur=Las2[i][j];
				if(pr!=-1){
					las2[i][j]=pr;
				}
				pr=cur;
			}
		}
	}
/*	for(int i=0;i<b;i++){
		for(int j=0;j<b;j++)printf("%d ",cnt[i][j]);printf("\n");
	}
	for(int i=0;i<b;i++){
		for(int j=0;j<b;j++)printf("%d ",las[i][j]);printf("\n");
	}
	for(int i=0;i<b;i++){
		for(int j=0;j<b;j++)printf("%d ",las2[i][j]);printf("\n");
	}
*/
	int bl=sqrt(M-0.5)+1;
	for(int i=0;i<b;i++){
		int left=-1;
		int right=b;
		while(left+1<right){
			int m=(left+right)/2;

			bool ok=true;
			for(int j=0;j<b;j++)req[j]=0;
			for(int j=0;j<b;j++){
				if(las[j][i]!=-1&&(las[j][i]-i+b)%b>m)ok=false;
				if(las[j][i]!=-1)req[j]=1;
				if(las2[j][i]!=-1&&(las2[j][i]-i+b)%b>m)req[j]=1;
			}
			int mm=0;
			int cur=0;
			for(int k=0;k<2;k++){
				for(int j=0;j<b;j++){
					if(req[j]){
						cur=0;
					}else cur++;
					mm=max(cur,mm);
				}
			}
			if(b-mm-1>m)ok=false;
			if(ok){
				right=m;
			}else left=m;
		}
		ret=min(ret,b*(bl-1)+right);
	}
	printf("%d\n",ret);
}


Measured memory_bytes: 23424
# 

H, W = map(int, input().split())
A = []

for i in range(H):
    A.append(list(map(int, input().split())))
    
ans_loc = []

for i in range(H):
    for j in range(W):
        if i == H-1 and j == W-1:
            break
            
        elif A[i][j]%2 == 1:          
            if j == W-1:
                A[i][j] -= 1
                A[i+1][j] += 1
                ans_loc.append((i+1, j+1, i+2, j+1))
            else:
                A[i][j] -= 1
                A[i][j+1] += 1
                ans_loc.append((i+1, j+1, i+1, j+2))
            
print(len(ans_loc))
for i in ans_loc:
    print(' '.join(map(str, i)))


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

int main(){
    int N;
    cin >> N;
    int a[100000];
    for(int i=0;i<N;i++)
        cin >> a[i];
    //昇順ソートする
    sort(a, a + N);
    //降順ソートなら次のようにする
    //sort(a, a + N, greater<int>());
    int count = 1, X = 0;
    for(int i=1;i<N;i++){
        if(a[i] == a[i-1]){
            count++;    //同じ数字の数をカウント
        }else{
            if((count % 2) != 0){   //奇数回なら紙に書かれている
                X++;                //のでカウントを増やす
            }
            count = 1;  //カウンタリセット
        }
    }
    //最後の数字をカウント
    if((count % 2) != 0)
        X++;
    cout << X << endl;
    return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<cmath>
#include<string>
#include<cstdlib>
#include<stdio.h>
#include<cctype>
#include<algorithm>
#include<string.h>
#include<iomanip>
using namespace std;//ESWN   4?????????,??????????????¢?????°
int A[7];
void exchange(int m,int n)
{
	int temp=A[m];
	A[m]=A[n];
	A[n]=temp;



}
void E()
{
	exchange(1,4);
	exchange(3,6);
	exchange(3,4);




}
void S()//?????????????????????????°±?????´??\???????????¬??????????????´??\??????????????´??????????§????????????????
{
	exchange(1,5);
   exchange(2,6);//????????????????????\?°±?\????
   exchange(2,5);
	





}
void N()
{
	exchange(1,2);
	exchange(5,6);
	exchange(2,5);




}
void W()
{
	exchange(1,4);
	exchange(3,6);
	exchange(1,6);




}



int main()
{
	
	for(int i=1;i<=6;i++)
		cin>>A[i];

	string a;
	cin>>a;
	for(int i=0;i<a.length();i++)
	{
			if(a[i]=='E')
			E();
			if(a[i]=='W')
				W();
				if(a[i]=='S')
					S();
					if(a[i]=='N')//???????????????????°±???string?????????????????°????????¢?????????char*?????¢???char
						N();
	}
	
	

	cout<<A[1]<<endl;

	

}

				
	
	
	

Measured memory_bytes: 3172
import java.util.Scanner;
public class Main{
	static Scanner scan = new Scanner(System.in);
	public static void main(String[] args) {
		System.out.println(answer());
	}
	public static int answer(){
		int n = scan.nextInt();
		int m = scan.nextInt();
		int[] arr= new int[m];
		int sum = 0;
		for(int i = 0 ; i < m ; i++){
			arr[i] = scan.nextInt();
			sum += arr[i];
		}
		return n >= sum ?n-sum:-1;
	}
}

Measured memory_bytes: 46156
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
typedef long long ll;
constexpr auto INFI = 2147483647;
const ll INFL = 9223372036854775807;

int main()
{
    int n, m, q, a, b, c, d;
    int ans = 0;
    vector<vector<int>> query_list;
    cin >> n >> m >> q;
    rep(i, q)
    {
        cin >> a >> b >> c >> d;
        a--; b--;
        vector<int> q = {a, b, c, d};
        query_list.push_back(q);
    }
    vector<vector<int>> comb_list;
    vector<int> start = {1};
    comb_list.push_back(start);
    rep(i,n-1){
        vector<vector<int>> new_comb_list;
        for (auto comb_pre : comb_list) {
            for (int k = comb_pre[comb_pre.size()-1]; k <= m; k++){
                vector<int> comb_tmp = comb_pre;
                comb_tmp.push_back(k);
                new_comb_list.push_back(comb_tmp);
            }
        }
        comb_list = new_comb_list;
    }

    for (auto comb : comb_list){
        int score = 0;
        for (auto q : query_list){
            if (comb[q[1]] -comb[q[0]] == q[2]) score += q[3];
        }
        ans = max(ans, score);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 11748
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

int main() {
	int N;
	cin >> N;
	string s;
	cin >> s;
	int r = 0;
	for (int i = 0; i < N; i++) {
		if (s[i] == 'R') r++;
	}
	if (r > N - r) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits//stdc++.h>
using namespace std;
int main(){
	int d;
	while(cin>>d){
		int e=600/d;
		long long sum=0;
		for(int i=1;i<e;i++){
			sum+=((d*i)*(d*i)*d);
		}
		cout<<sum<<endl;
	}
}

Measured memory_bytes: 3032
import java.util.ArrayDeque;
import java.util.Arrays;
import java.util.Queue;
import java.util.Random;
import java.util.Scanner;
 


public class Main {
	private static Scanner sc = new Scanner(System.in);
	//result = Math.pow(num1, num3)
	//StringBuffer str = new StringBuffer(hoge1);
	//String hoge2 = str.reverse().toString();
	//map.containsKey(A)

	//Map<String, Integer> map = new HashMap<String, Integer>(n);
	/*for ( キーのデータ型 key : マップの名前.keySet() ) {
		データのデータ型 data = マップの名前.get( key );
		
		// keyやdataを使った処理;
	}*/
	//int i = Integer.parseInt(s);
	//Queue<String> qq=new ArrayDeque<>(); //add,poll,peek
	//Deque<String> qq=new ArrayDeque<>();//push,pop,peek
	//ArrayList<String> cc = new ArrayList<>(n);
	//Collections.sort(list);
	//Array.sort(list);   cc.contains(tmp)
	//Arrays.asList(c).contains("a")
	//list.set(1,"walk");//1 1 2 3 5
	static long mod =1000000007;
	//static 	ArrayList<Integer> cc = new ArrayList<>(100);
	
	
	public static void main(String[] args) {
		//int N=sc.nextInt();for(int i=0;i<N;i++) {}
		//int a[]=new int[N];
		//Ae2+Be2=Ce2
	
		//for(int i=0;i<N;i++) {}
		boolean x=false;
		int N=sc.nextInt();
		for(int i=1;i<=N;i++) {
			if(N%i==0) {
				int A=i;
				int B=N/i;
				
				if(A<1||A>9||B<1||B>9) {
					continue;
				}else {
					x=true;
					break;
				}
			}
			
			
		}
		
		if(x)p("Yes");
		else p("No");
		
	}
		
		
		
		static long Nb(long t) {
			long r=1;
			for(long i=t;i>0;i--) {
				r*=i;
				r%=mod;
				
			}
			return (int)r;
			
		}
		
	
	
	
	public static long lcm(long a, long b) {
        return a / gcd(a, b) * b;
	}
	
	public static long gcd(long a, long b) {
        return b == 0 ? a: gcd(b, a % b);
	}

	


	
	static void p(String ans) {System.out.println(ans);};
	static void p(int ans) {System.out.println(ans);};
	static void p() {System.out.println();};
	static void p(long ans) {System.out.println(ans);};
	static void p(double ans) {System.out.println(ans);};
	
}
	


Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
#define SORT(c) sort((c).begin(),(c).end());
#define pb push_back
#define MP make_pair
#define pii pair<int,int>
#define pcc pair<char,char>
#define pic pair<int,char>
#define pci pair<char,int>
#define VS vector<string>
#define VI vector<int>
#define pi 3.141592653589793
#define ll long long
#define ull unsigned long long
#define w(x) int x;cin>>x;while(x--)
#define fast ios_base::sync_with_stdio(0)
#define sz size()
typedef unsigned long long UL;
template<typename T>inline T  S(T a)
{
    return a*a;
}
template<class T>inline string tostring(T a)
{
    ostringstream os("");
    os << a;
    return os.str();
}
template<typename T>inline ll tolong(T a)
{
    ll res;
    istringstream os(a);
    os>>res;
    return res;
}
template<typename T>inline T gcd(T a, T b)
{
    if (b == 0)return a;
    else return gcd(b, a % b);
}
template<typename T>inline T bigmod(T a, T b, T m)
{
    if (b == 0)return 1;
    else if (b % 2 == 0)return S(bigmod(a, b / 2, m)) % m;
    else return (a % m*bigmod(a, b - 1, m)) % m;
}
const int inf = (int)1e9 + 5;
const ll linf = (ll)1e16 + 5;
const ll modd = (ll)1e9 + 7;
const int mod = 10000007;
/*#define N 20000009
bool prime[N];
vector<ll> prm;
void seive ()
{

    memset(prime, true, sizeof(prime));

    for( ll i=2; i*i<=N; i++)
    {
        if (prime[i] == true)
        {
            prm.pb(i);
            for (ll j=i*i; j<=N; j += i)
                pe[j] = false;
        }
    }
}*/
void pr (int f)
{
    if(f==1)
        cout<<"YES\n";
    else
        cout<<"NO\n";
}
map<int , int >mp;
set<int > s;
multiset<string> :: iterator it;

deque <char> q ;
ll vis [5510000];
int  visited[230];
int main()
{
    fast ;

   string s;
   cin>> s ;
   if(s[s.sz-1]=='3')
    cout<<"bon\n";
   else if(s[s.sz-1]=='1'||s[s.sz-1]=='6'||s[s.sz-1]=='8'||s[s.sz-1]=='0')
    cout<<"pon\n";
   else
    cout<<"hon\n";
}






Measured memory_bytes: 3664
K,A,B = map(int,input().split( ))

#お金に変えてからビスケットに変えるメリットがある場合
if B-A>2:
	b = 1
	K-=A-b
	b = A
	b+=(K//2)*(B-A)
	b+=K%2




else:
	b = 1+K

print(b)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n, k;
    cin >> n >> k;
    int flip = 0, ans = 0;
    char cur, prev; cin >> prev;
    for(int i = 1; i < n; i++) {
        char c; cin >> c;
        if(c == prev) ans++;
        else {
            if(flip) {
                flip ^= 1;
                ans++;
            }
            else if(k != 0) {
                flip ^= 1;
                ans++;
                k--;
            }
        }
        prev = c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static Scanner scan = new Scanner(System.in);
	static	int[][] gems;
	static	boolean[][] roboflag = new boolean[21][21];
	static	int gemNum;
	static	int actNum;
	static	int itmp;
	static	String stmp;
	static	int x,y;
	public static void main (String[] args) {
		while(true) {
			gemNum= scan.nextInt();
			if(gemNum == 0) break;
			gems = new int[gemNum][2];
			for(int i = 0; i < gemNum; i++) {
				gems[i][0] = scan.nextInt();
				gems[i][1] = scan.nextInt();
			}
			actNum = scan.nextInt();
			roboflag = new boolean[21][21];
			x = 10;
			y = 10;
			for(int j = 0; j < actNum; j++) {
				stmp = scan.next();
				itmp = scan.nextInt();
				if(stmp.equals("N")) {
					for(int i = 0; i <= itmp; i++) {
						roboflag[x][y+i] = true;
					}
					y += itmp;
				} else if(stmp.equals("E")) {
					for(int i = 0; i <= itmp; i++) {
						roboflag[x+i][y] = true;
					}
					x += itmp;
				} else if(stmp.equals("S")) {
					for(int i = 0; i <= itmp; i++) {
						roboflag[x][y-i] = true;
					}
					y -= itmp;
				} else if(stmp.equals("W")) {
					for(int i = 0; i <= itmp; i++) {
						roboflag[x-i][y] = true;
					}
					x -= itmp;
				}
			}
			//map();
			for(int i = 0; i <= gemNum; i++) {
				if(i == gemNum) {
					System.out.println("Yes");
					break;
				}
				if(!roboflag[gems[i][0]][gems[i][1]]) {
					System.out.println("No");
					break;
				}
			}
		}
	}
	public static void map() {
		boolean flag;
		for(int i = 0; i <= 20; i++) System.out.print(i + " ");
		System.out.println();
		for(int i = 0; i <= 20;i++) {
			System.out.print(i + " ");
			for(int j = 0; j<= 20; j++) {
			flag = false;
				for(int m = 0; m < gemNum; m++) {
					if(gems[m][0] == i && gems[m][1] == j) {
						System.out.print("- ");
						flag = true;
					}
				}
				if(!flag)	System.out.print("+ ");
			}
			System.out.println();
		}
		System.out.println();
		for(int i = 0; i <= 20; i++) System.out.print(i + " ");
		System.out.println();
		for(int i = 0; i <= 20;i++) {
			System.out.print(i + " ");
			for(int j = 0; j<= 20; j++) {
				if(roboflag[i][j]) System.out.print("~ ");
				else System.out.print("+ ");
				
			}
			System.out.println();
		}
	}
}

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

int main()
{
    string s;
    cin >> s;
    int n = s.size();
    for(int i = 0; i < n - 1; i++){
        if(s[i] == 'A' && s[i + 1] == 'C'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>

using namespace std;

bool fcn(int n){
	string s=to_string(n);
	if(s[0]== s[4] && s[1]==s[3]) return true;
	else return false;
}

int main(){
	int a, b;
	cin >> a >> b;
	int ans = 0;
	for(int i=a; i<=b; i++){
		if(fcn(i)) ans++; 
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10000000)
from itertools import accumulate
def main():
    N = int(readline())
    A = [int(i) for i in readline().split()]
    Ae = A[1::2]
    Ao = A[::2]
    x1 = (sum(Ao)-sum(Ae))//2
    table = [0]*(N+1)
    table[0] = x1
    def rec(i):
        if i == N:
            return
        table[i+1] = A[i] - table[i]
        rec(i+1)
    rec(0)
    for i in table[:N]:
        print(i*2, end=' ')
if __name__ == '__main__':
    main()


Measured memory_bytes: 118384
from collections import Counter, defaultdict
import sys
sys.setrecursionlimit(10 ** 5 + 10)
# input = sys.stdin.readline
from math import factorial
import heapq, bisect
import math
import itertools


import queue
from collections import deque



def main():
    node_num, edge_num = map(int, input().split())
    data = [list(map(int, input().split())) for i in range(node_num - 1 + edge_num)]

    parent_node = [0 for i in range(node_num + 1)]
    graph_data = defaultdict(set)
    nyuuji = [0 for i in range(node_num + 1)]

    for i in range(node_num - 1 + edge_num):
        a, b = data[i]
        graph_data[a].add(b)
        nyuuji[b] += 1

    root = -1
    for i in range(1, node_num + 1):
        if nyuuji[i] == 0:
            root = i

    now_set = set()
    next_set = set()
    now_set.add(root)

    while len(now_set):
        for now_node in now_set:
            for next_node in graph_data[now_node]:
                nyuuji[next_node] -= 1
                if nyuuji[next_node] == 0:
                    next_set.add(next_node)
                    parent_node[next_node] = now_node

        now_set = next_set
        next_set = set()

    for i in range(1, node_num + 1):
        print(parent_node[i])


if __name__ == '__main__':
    main()


Measured memory_bytes: 100564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
 
int main() {
  int N,K; cin>>N>>K;
  int d,a; 
  vector<int> vec(0);
  for(int i=0; i<K; i++){
    cin>>d;
    for(int j=0;j<d; j++){
    cin>>a;
    vec.push_back(a);
    }
  }
  sort(vec.begin(), vec.end());
  int ans=0;
  for(int i=0;i<vec.size();i++){
    if(vec[i+1]-vec[i]>1)ans+=vec[i+1]-vec[i]-1;
  }
  ans+= vec[0]- 1 + N - vec[vec.size()-1];
  cout<< ans <<endl;
  return 0;
}

Measured memory_bytes: 3700
#include <iostream>

using namespace std;

typedef long long ll;

ll lcm(ll a, ll b)
{
    ll r = a % b, tmp, x = a * b;
    if (a < b) {
        tmp = a;
        a = b;
        b = tmp;
    }

    r = a % b;
    while (r != 0) {
        a = b;
        b = r;
        r = a % b;
    }

    return x / b;
}

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    ll n_ac = a / c, n_ad = a / d, n_bc = b / c, n_bd = b / d,
            n_acd = a / lcm(c, d), n_bcd = b / lcm(c, d);
    
    cout << (b - a + 1 - (n_bc - n_ac + (a%c == 0)) - (n_bd - n_ad + (a%d == 0)) + (n_bcd - n_acd + (a % (c*d) == 0))) << endl;
}

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

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

template<class T>bool chmax(T &a, const T &b) { return (a<b)?(a=b,1):0;}
template<class T>bool chmin(T &a, const T &b) { return (b<a)?(a=b,1):0;}

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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

const pid_t pid = getpid();
// Problem Specific Parameter:


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

	vector<ll> a(n), f(n);
	rep(i, n) cin >> a[i];
	rep(i, n) cin >> f[i];

	sort(begin(a), end(a));
	sort(rbegin(f), rend(f));

	ll low = -1LL, high = 1LL << 40;
	while(high - low > 1){
		const ll mid = (low + high) / 2LL;
		ll cur = k;
		rep(i, n){
			const ll num = mid / f[i];
			cur -= max(0LL, a[i] - num);
		}
		if(cur >= 0)
			high = mid;
		else
			low = mid;
	}

	cout << high << endl;
	return 0;
}

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

int main(){
  int n,m,k; cin >>n >>m >>k;
  vector<int> a(n);
  rep(i,n) cin >>a[i];
  vector<int> b(m);
  ll total = 0;
  rep(i,m) {
    cin >>b[i];
    total += b[i];
  }
  int ans = 0;
  int j = m;
  rep(i,n+1){
    while(j>0 && total > k){
      j--;
      total -= b[j];
    }
    if(total>k) break;
    ans = max(ans, i+j);
    if(i==n) break;
    total += a[i];
  }
  cout << ans << endl;
  return 0; 
}

Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

int main(){
    string s;
    cin>>s;
    deque<char> d;
    rep(i,s.size()){
        d.push_back(s[i]);
    }
    ll q,t,f;
    char c;
    bool lr=0;
    cin>>q;
    rep(i,q){
        cin>>t;
        if(t==1){
            lr=!lr;
        }else{
            cin>>f>>c;
            f--;
            if(lr==f) d.push_front(c);
            else d.push_back(c);
        }
    }
    if(!lr){
        for(auto di:d) cout<<di;
        cout<<endl;
    }else{
        reverse(all(d));
        for(auto di:d) cout<<di;
        cout<<endl;
    }
    return 0;
}

Measured memory_bytes: 1024
import java.util.*;
public class Main{

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] x = new int[n];
        int cnt = 0;
        int num = 0;

        for(int i = 0;i<n;i++){
            x[i] = sc.nextInt();
        }

        for(int i = 0;i<n;i++){
            num=(Math.min(x[i],Math.abs(k-x[i])));
            cnt +=(num*2);
        }
        System.out.println(cnt);
    }
}




Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define endl "\n" 
using namespace std;
#define debug(x) cout<<"The value of "<<#x<<" is "<<x<<endl;
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    cin.sync_with_stdio(0); cin.tie(0); 
    int k;
    cin>>k;
    string s;
    cin>>s;
    if(s.size()<=k)
    cout<<s<<endl;
    else
    cout<<s.substr(0,k)<<"..."<<endl;
}


Measured memory_bytes: 3656
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=a; i< (int)(b); ++i)
#define ALL(x) (x).begin(),(x).end()
#define rALL(x) (x).rbegin(),(x).rend()
typedef long double ld;
using ll=long long;
using namespace std;
const int mod=1e9+7;
const ld pi = (acos(-1));
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; }




int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(20);
  
  int n; cin >> n;
  ll res=0;
  map<string,int> p;
  rep(i,0,n){
    string s;
    cin >> s;
    sort(ALL(s));
    res+=p[s];
    p[s]++;
  }
   cout << res << endl;
}

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

# m0 + m1 + m2 + m3 + m4 = d0 + d1 + d2 + d3 + d5
# d0 = (m0 + m1)//2
# d1 = (m1 + m2)//2
# d2 = (m2 + m3)//2
# d3 = (m3 + m4)//2
# d4 = (m4 + m0)//2
# m0 =  d0 - d1 + d2 - d3 + d4
# m1 =  d0 + d1 - d2 + d3 - d4
# m2 = -d0 + d1 + d2 - d3 + d4
# m3 =  d0 - d1 + d2 + d3 - d4
# m4 = -d0 + d1 - d2 + d3 + d4   
s = sum(a)
p = [0 for _ in range(n)]
q = [0 for _ in range(n+1)]
for i in range(n) :
    if i>1 :
        p[i] = p[i-2] + a[i-2]
    q[n-i-2] = q[n-i] + a[n-i-1]

print(*[s-2*p[i]-2*q[i] for i in range(n)])

Measured memory_bytes: 22492
n,m=map(int,input().split())
x=list(map(int,input().split()))
x.sort()
a=[]
for i in range(1,m):
    a.append(x[i]-x[i-1])
a.sort()
ans=0
for i in range(m-n):
    ans+=a[i]
print(ans)

Measured memory_bytes: 56872
mod=1000000007
n=int(raw_input())
l=len(raw_input())
dp=[[0 for i in range(n+2)] for j in range(n+1)]
for i in range(n+1):
    for j in range(i+1):
        if i==0:dp[i][j]=1
        elif j==0:dp[i][j]=(dp[i-1][1]*2+dp[i-1][0])%mod
        else:dp[i][j]=(dp[i-1][j-1]+dp[i-1][j+1]*2)%mod
print dp[n][l]

Measured memory_bytes: 213916
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

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

    Int n;
    cin >> n;

    vector<Int> ans(n, 0);

    for (Int x = 1; x <= n; x++) {
        for (Int y = 1; y <= n; y++) {
            for (Int z = 1; z <= n; z++) {
                Int all = x * x + y * y + z * z + x * y + y * z + z * x;
                if (n < all) {
                    break;
                }

                ans[all - 1]++;
            }
        }
    }

    for (Int i = 0; i < n; i++) {
        cout << ans[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 3688
#include <bits/stdc++.h>
                                               
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define file(s) freopen(s".in","r",stdin); freopen(s".out","w",stdout);                                          
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define int ll
#define forn(i, a, b) for(int i = (a); i <= (b); ++i)
#define forev(i, b, a) for(int i = (b); i >= (a); --i)
#define VAR(v, i) __typeof(i) v=(i)
#define forit(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi; 
typedef vector<ll> Vll;
typedef vector<pair<int, int> > vpii;
typedef vector<pair<ll, ll> > vpll;

const int maxn = (int)1e5 + 100;
const int mod = (int) 2e9 + 7;
const int inf = mod;

int n, a[maxn], tot;  
main () {         
  srand(time(0));
  scanf("%d", &n);
  int sum = 0;
  forn(i, 1, n) scanf("%d", &a[i]), sum += a[i];
  if(sum % (n * (n + 1) / 2)){
    cout << "NO";
    return 0;
  }
  int need = sum / (n * (n + 1) / 2);
  a[n + 1] = a[1];
  forn(i, 1, n){
    if(a[i + 1] - a[i] - need > 0){
      cout << "NO";
      return 0;
    }
    if(abs(a[i + 1] - a[i] - need) % n){
      cout << "NO";
      return 0;
    }
    tot += abs(a[i + 1] - a[i] - need);  
  }                                  
  if(tot != need * n) cout << "NO";
  else cout << "YES";
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
constexpr auto INF = 1000000000;
constexpr auto LLINF = 1LL<<60;
constexpr auto mod = 1000000007;

class unionfind {
	VI par, rank;
public:
	void init(int N) {
		par.clear();
		rank.clear();
		for (int i = 0; i < N; i++) par.push_back(i);
		for (int i = 0; i < N; i++) rank.push_back(1);
	}
	int root(int x) {
		if (par[x] == x)return x;
		return par[x] = root(par[x]);
	}
	int size(int x) {
		if (par[x] == x)return rank[x];
		return size(par[x]);
	}
	void unite(int x, int y) {
		int rx = root(x);
		int ry = root(y);
		if (rx == ry)return;
		if (rank[rx] < rank[ry]) {
			par[rx] = ry;
			rank[ry] += rank[rx];
		}
		else {
			par[ry] = rx;
			rank[rx] += rank[ry];
		}
	}
	bool same(int x, int y) {
		return root(x) == root(y);
	}
};

int main() {
	int n;
	cin >> n;
	vector<pair<ll,int>> x(n), y(n);
	FOR(i, n) {
		cin >> x[i].first >> y[i].first;
		x[i].second = i;
		y[i].second = i;
	}

	vector<pair<ll, pair<int, int>>> edge;
	SORT(x); SORT(y);
	FOR(i, n - 1) {
		edge.push_back({ x[i + 1].first - x[i].first,{x[i].second,x[i + 1].second} });
		edge.push_back({ y[i + 1].first - y[i].first,{y[i].second,y[i + 1].second} });
	}

	unionfind uf;
	uf.init(n);
	ll ans = 0;
	SORT(edge);
	for(auto e: edge) {
		if (!uf.same(e.second.first, e.second.second)) {
			uf.unite(e.second.first, e.second.second);
			ans += e.first;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 9584
#include<bits/stdc++.h>
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
     cin.tie(NULL);
     int t;
    //cin>>t;
     t=1;
     while(t--)
     {

        long long int n,k;
        cin>>n>>k;
        long long int R=n+k-1,L=k;
 int eat;
 if(R<=0)eat=R;
 else if(L>=0)eat=L;
 else eat=0;
 
 int answer=(R+L)*(R-L+1)/2-eat; 
 cout<<answer<<endl;
     }
}


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

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

	vector<int> used(n), ans(n, -1);
	for (int i = 1; i <= n; i++) {
		int cnt = 1;
		for (int j = 0; j < n; j++) {
			if (used[j]) {
				cnt++;
				continue;
			}
			if (b[j] == cnt) {
				ans[i - 1] = max(ans[i - 1], j);
			}
		}
		if (ans[i - 1] == -1) {
			cout << -1;
			return;
		}
		used[ans[i - 1]] = 1;
		ans[i - 1] = b[ans[i - 1]];
	}
	for (auto x: ans) {
		cout << x << endl;
	}
}

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


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


using namespace std;

using ll = long long;
using ld = long double;

#define mp make_pair

const int p = 1000000007;


int mul(int a, int b) {
    return (1LL * a * b) % p;
}

int add(int a, int b) {
    int s = (a+b);
    if (s>=p) s-=p;
    return s;
}

int sub(int a, int b) {
    int s = (a+p-b);
    if (s>=p) s-=p;
    return s;
}

int po(int a, int deg)
{
    if (deg==0) return 1;
    if (deg%2==1) return mul(a, po(a, deg-1));
    int t = po(a, deg/2);
    return mul(t, t);
}

int inv(int n)
{
    return po(n, p-2);
}

/*struct DSU {
    vector<int> sz;
    vector<int> parent;

    void make_set(int v) {
        parent[v] = v;
        sz[v] = 1;
    }

    int find_set(int v) {
        if (v == parent[v])
            return v;
        return parent[v] = find_set(parent[v]);
    }

    void union_sets(int a, int b) {
        a = find_set(a);
        b = find_set(b);
        if (a != b) {
            if (sz[a] < sz[b])
                swap(a, b);
            parent[b] = a;
            sz[a] += sz[b];
        }
    }

    DSU(int n) {
        sz.resize(n);
        parent.resize(n);
        for (int i = 0; i < n; i++) make_set(i);
    }
};*/

/*const int N = 1000000;

vector<int> facs(N), invfacs(N);

void init()
{
    facs[0] = 1;
    for (int i = 1; i<N; i++) facs[i] = mul(facs[i-1], i);
    invfacs[N-1] = inv(facs[N-1]);
    for (int i = N-2; i>=0; i--) invfacs[i] = mul(invfacs[i+1], i+1);
}

int C(int n, int k)
{
    return mul(facs[n], mul(invfacs[k], invfacs[n-k]));
}*/




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

    ll h, w;
    cin>>h>>w;
    ll ans = 1e18;
    for (ll i = 1; i<h; i++)
    {
        ll l = w/2; ll r = w - l;
        ans = min(ans, max({l*i, r*i, (h-i)*w}) - min({l*i, r*i, (h-i)*w}));
    }
    swap(h, w);
    for (ll i = 1; i<h; i++)
    {
        ll l = w/2; ll r = w - l;
        ans = min(ans, max({l*i, r*i, (h-i)*w}) - min({l*i, r*i, (h-i)*w}));
    }
    if (h%3==0 || w%3==0) ans = 0;
    ans = min(ans, w);
    ans = min(ans, h);

    cout<<ans;
}


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


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

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int n;
    int apartment_info[4][3][10];

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                apartment_info[i][j][k] = 0;
            }
        }
    }

    cin >> n;

    for(int i = 0; i < n; i++) {
        int b,f,r,v;
        cin >> b >> f >> r >> v;
        apartment_info[b-1][f-1][r-1] += v;
    }

    for (int i = 0; i < 4; i++) {
        for (int j = 0; j < 3; j++) {
            for (int k = 0; k < 10; k++) {
                cout << " " << apartment_info[i][j][k];
            }
            cout << endl;
        }

        if (i < 3)
            cout << "####################" << endl;
    }


    return 0;
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define ft first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define pt(sth) cout << sth << "\n"
#define chmax(a, b) {if(a<b) a=b;}
#define chmin(a, b) {if(a>b) a=b;}
#define moC(a, s, b) (a)=((a)s(b)+MOD)%MOD
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
static const ll INF=1e18;
static const ll MAX=1e5+7;
static const ll MOD=1e9+7;
ll max(ll a, ll b) {return a>b?a:b;}
ll min(ll a, ll b) {return a<b?a:b;}


ll moP(ll x, ll n) {
  ll res=1;
  while(n>0) {
    if(n&1) res=res*x%13;
    x=x*x%13;
    n>>=1;
  }
  return res;
}

ll dp[MAX][13]={};
int main(void) {
  string s;
  cin >> s;
  ll i, j, k;
  ll N=s.size();
  
  for(i=0; i<N/2; i++) {
    swap(s[i], s[N-1-i]);
  }
  
  dp[0][0]=1;
  for(i=1; i<=N; i++) {
    for(j=0; j<13; j++) {
      
      if(s[i-1]=='?') {
        for(k=0; k<10; k++) {
          ll t=k*moP(10, i-1)%13;
          moC(dp[i][(j+t)%13], +, dp[i-1][j]);
        }
      }else {
        ll t=(s[i-1]-'0')*moP(10, i-1)%13;
        moC(dp[i][(j+t)%13], +, dp[i-1][j]);
      }
      
    }
  }
  
  pt(dp[N][5]);
  
}














Measured memory_bytes: 10624
fun main(args: Array<String>) {
    val (n,m) = readLine()!!.split(" ").map { it.toInt() }
    val x = readLine()!!.split(" ").map { it.toInt() }.sorted()
    val dx = (1..m-1).map { x[it]-x[it-1] }

    val ans = ( x[m-1]-x[0] ) - dx.sortedDescending().take(n-1).sum()
    println(ans)
}

Measured memory_bytes: 52176
#include <bits/stdc++.h>
using namespace std;
 
const int N = 100010;
multiset<int> s, t, p, q;
 
struct Node {
    int l, r;
} w[N];
 
inline bool cmp(Node a, Node b)
{
    if (a.l == b.l) return a.r < b.r;
    return a.l < b.l;
}
 
int main()
{
    register int n, lmx = 0, rmn = 1e9;
    scanf("%d", &n);
    for (register int i = 1; i <= n; ++i) {
        scanf("%d %d", &w[i].l, &w[i].r);
        p.insert(w[i].l);
        q.insert(w[i].r);
        lmx = max(lmx, w[i].l);
        rmn = min(rmn, w[i].r);
    }
    sort(w + 1, w + n + 1, cmp);
    register int ans = 0;
    for (register int i = 1; i < n; ++i) {
        s.insert(w[i].l);
        t.insert(w[i].r);
        register multiset<int>::iterator it1, it2;
        it1 = s.end(); it1--;
        it2 = t.begin();
        register int num1 = *it2 - *it1 + 1;
        p.erase(w[i].l);
        q.erase(w[i].r);
        it1 = p.end(); it1--;
        it2 = q.begin();
        register int num2 = *it2 - *it1 + 1;
        ans = max(ans, num1 + num2);
    }
    for (register int i = 1; i <= n; ++i) {
        ans = max(ans, w[i].r - w[i].l + 1 + max(rmn - lmx + 1, 0));
    }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 10368
#include <bits/stdc++.h>
using namespace std;
template<class T> bool chmax(T& a,T b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T& a,T b) { if (a > b) { a = b; return true; } return false; }

int main() {
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    bool res;
    while (true) {
        c -= b;
        if (c <= 0) {
            res = true;
            break;
        }
        a -= d;
        if (a <= 0) {
            res = false;
            break;
        }
    }
    
    if (res) cout << "Yes" << '\n';
    else cout << "No" << '\n';
}

Measured memory_bytes: 3596
import sys

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

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

def Base_10_to_n(X, n):
    if (int(X/n)):
        return Base_10_to_n(int(X/n), n)+str(X%n)
    return str(X%n)

def main():
    converted = Base_10_to_n(N,K)
    print(len(converted))

main()

Measured memory_bytes: 9184
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl "\n"
#define ll long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#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 INF 2147483647
#define LLINF 9223372036854775807LL
#define vi vector<int>
#define vvi vector<vector<int>>
#define pi pair<int, int>
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

signed main() {
    cin >> X >> Y >> A >> B >> C;
    vi p(A), q(B), r(C);
    cin >> p >> q >> r;
    vi v(X + Y + C);
    sort(RALL(p));
    sort(RALL(q));
    REP(i, X)
    v[i] = p[i];
    REP(i, Y)
    v[i + X] = q[i];
    REP(i, C)
    v[i + X + Y] = r[i];
    sort(RALL(v));
    REP(i, X + Y)
    ans += v[i];
    cout << ans << endl;
}

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

// ----------- define --------------
#define int long long
#define vi vector<int>
#define vc vector<char>
#define ii pair<int,int>
#define fi first
#define sc second
#define stoi stoll
#define all(x) (x).begin(),(x).end()
#define get_bit(x, k) ((x >> k) & 1)
// ---------------------------------

void MAIN() {
  int n; cin >> n;
  vector<int> a(n);
  int zero = 1;
  for (auto &i : a) {
    cin >> i;
    if (i) zero = 0;
  }
  if (zero) {
    cout << "Yes" << '\n';
    return;
  }
  sort(all(a));
  if (n % 3) {
    cout << "No" << '\n';
    return;
  }
  int t = n / 3;
  if (a[0] == 0 && a[t] == 0 && a[t * 2]) {
    cout << "No" << '\n';
    return;
  }
  for (int i = 0; i < t; i++) {
    if ((a[i] ^ a[i + t]) != a[i + t * 2]) {
      cout << "No" << '\n';
      return;
    }
    if (i && (a[i] != a[i - 1] || a[i + t] != a[i + t - 1])) {
      cout << "No" << '\n';
      return;
    }
  }
  cout << "Yes" << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


Measured memory_bytes: 3980
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<chrono>
#define MAX_N 100
#define MAX_M 100
#define REP(i,n) for(int i=0;i<n;i++)
using namespace std;
 
 
int main(){
    int a;
    string b;
    cin>>a>>b;
    if(a%2!=0){
        cout<<"No";
        return 0;
    }
    bool e=true;
    REP(i,a/2){
        if(b[i]!=b[i+a/2]){
            e=false;
        }
    }
    if(e){
        cout<<"Yes";
    }else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 888
#include<stdio.h>
#include<string.h>

int main(void){
    int sa = 'a' - 'A';
    char str[1200];
    scanf("%[^\n]", str);
    for(int i=0; i<strlen(str); i++){
        if(str[i] >= 'a' && str[i] <= 'z') printf("%c", str[i]-sa);
        else if(str[i] >= 'A' && str[i] <= 'Z') printf("%c", str[i]+sa);
        else printf("%c", str[i]);
    }
    printf("\n");
    return 0;
}


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

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

    queue<char> QA, QB, QC;
    for (int i = 0; i < A.length(); ++i) QA.push(A[i]);
    for (int i = 0; i < B.length(); ++i) QB.push(B[i]);
    for (int i = 0; i < C.length(); ++i) QC.push(C[i]);

    char winner;
    char next_player = 'a';
    while(true) {

        if (next_player == 'a') {
            if (QA.size() == 0) {
                winner = 'A';
                break;
            } else {
                next_player = QA.front();
                QA.pop();
                continue;
            }
        }

        if (next_player == 'b') {
            if (QB.size() == 0) {
                winner = 'B';
                break;
            } else {
                next_player = QB.front();
                QB.pop();
                continue;
            }
        }

        if (next_player == 'c') {
            if (QC.size() == 0) {
                winner = 'C';
                break;
            } else {
                next_player = QC.front();
                QC.pop();
                continue;
            }
        }

    }

    cout << winner << endl;
    return 0;
}

Measured memory_bytes: 256
#include<complex>
#include<cstdio>
#include<cmath>
using namespace std;
typedef complex<double> P;
#define F(a,b,c) acos((b*b+c*c-a*a)/2/b/c)
int main(){
	int n;
	double d,e,f,g,h,i;
	for(scanf("%d",&n);n--;){
		scanf("%lf%lf%lf%lf%lf%lf",&d,&g,&e,&h,&f,&i);
		P a(d,g),b(e,h),c(f,i);
		double A=abs(b-c),B=abs(c-a),C=abs(a-b),
		s=sin(2*F(A,B,C)),t=sin(2*F(B,C,A)),u=sin(2*F(C,A,B)),v=s+t+u;
		printf("%.3f %.3f %.3f\n",(d*s+e*t+f*u)/v,(g*s+h*t+i*u)/v,A/sin(F(A,B,C))/2);
	}
}

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

signed main(){
  int N,A;
  cin>>N;
  A=N%1000;
  int ans=1000-A;
  if(ans==1000)ans=0;
  cout<<ans<<endl;
}

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

using namespace std;

#define ll             long long int
#define endl           '\n'

static const int maxn = 2e5 + 5;

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);
      cout.tie(nullptr);


      int n;
      cin >> n;
      multiset <int> ms;
      vector <int> vec(n);
      for (int &x : vec)
      {
            cin >> x;
            ms.insert(x);
      }
      for (int x : vec)
      {
            auto it = ms.find(x);
            ms.erase(it);
            int ans = *ms.rbegin();
            cout << ans << endl;
            ms.insert(x);
      }
}


Measured memory_bytes: 11776
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>

using namespace std;

typedef  pair<int,int> P;
typedef long long LL;
typedef vector<LL> VEC;

const LL INF=1<<30;
const LL MOD=1000000007;

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

return gcd(b,a%b);
}

LL lcm(LL a,LL b){
LL g=gcd(a,b);

return a/g*b;
}


int main(){
    int a;
    int b;
    int k;
    cin>>a>>b>>k;
    int kai=0;
    int ans;
    for(int i=gcd(a,b);i>=1;--i){
        if(a%i==0&&b%i==0){
            kai++;
        }
        if(kai==k){
            ans=i;
            break;
        }
    }

    cout<<ans<<endl;
}



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

const int MAXN = 200010;

char S[MAXN];
int dp[MAXN], w[MAXN];

int main() {
	ios::sync_with_stdio(0); cin.tie(0);
	int N, M;

	cin >> N >> M >> S;

	dp[0] = N;
	int p = 0;
	for(int i = N - 1; i >= 0; i--) if(S[i] == '0') {
		if(dp[p] > i + M) {
			p++;
			if(dp[p] > i + M || dp[p] == 0) {
				cout << "-1\n";
				return 0;
			}
		}
		dp[p + 1] = i;
		w[i] = dp[p] - i;
	}
	for(int t = 0; t != N; t += w[t]) cout << w[t] << " ";
	return 0;
}


Measured memory_bytes: 1408
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 10000;
const long long inf = 1ll << 61;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int, PP> PPP;
struct edge { int to; int cost; };
string s[10006];
signed main() {
	int n; cin >> n;
	rep(i, n)cin >> s[i];
	int cnt = 0;
	rep(i, n) {
			rep(j, s[i].size() - 1) {
				if (s[i][j] == 'A'&&s[i][j + 1] == 'B')cnt++;
			}
	}
	int ab = 0, a = 0, b = 0;
	rep(i, n) {
		if (s[i][0] == 'B'&&s[i][s[i].size() - 1] == 'A')ab++;
		else if (s[i][0] == 'B')b++;
		else if (s[i][s[i].size() - 1] == 'A')a++;
		
	}
	if (a&&b) {
		cnt += ab + 1;
		a--; b--;
	}
	else if(a){
		cnt += ab;
		a--;
	}
	else if (b) {
		cnt += ab;
		b--;
	}
	else if(ab){
		cnt += ab - 1;
	}
	cnt += min(a, b);
	cout << cnt << endl;

}

Measured memory_bytes: 768
N, M = map(int, input().split())
From = set()
To = set()
for _ in range(M):
  a, b = map(int, input().split())
  if a == 1:
    From.add(b)
  if b == N:
    To.add(a)
if From.isdisjoint(To):
  print("IMPOSSIBLE")
else:
  print("POSSIBLE")

Measured memory_bytes: 24116
a = list()
while True:
    m,f,r = map(int,input().split())
    if m == f == r == -1:
        break
    else:
        s = m+f
        if m == -1 or f == -1:
            print("F")
        else:
            if s>=80:
                print("A")
            elif s>=65:
                print("B")
            elif s>=50:
                print("C")
            elif s>=30:
                if r >= 50:
                    print("C")
                else:
                    print("D")
            else:
                print("F")
                
        


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
using P = pair<int, int>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int h1, h2, m1, m2, k;
    cin >> h1 >> m1 >> h2 >> m2 >> k;
    cout << (h2 - h1) * 60 + m2 - m1 - k  << endl;
    return 0;
}

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

int main(){
  int N;
  cin >> N;
  double num = 0;
  for(int i = 0; i < N; i++){
    double x;
    cin >> x ;
    string u;
    cin >> u;
    if(u == "JPY"){
      num += x;
    }
    else{
      num += x * 380000.0;
    }
  }
  cout << num << endl;
}
      
    

Measured memory_bytes: 256
import sys, math, itertools, collections, bisect
input = lambda: sys.stdin.buffer.readline().rstrip().decode('utf-8') 
inf = float('inf') ;mod = 10**9+7 
mans = inf ;ans = 0 ;cnt = 0 ;pro = 1

n = int(input())
A = list(map(int, input().split()))
now = 1000
for i in range(n-1):
    if A[i] < A[i+1]:
        stocks = now//A[i]
        now += (A[i+1] - A[i])*stocks
print(now)

Measured memory_bytes: 65500
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rep1(i, n) for (ll i = 1; i <= (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define to_s to_string
#define len(v) (int)v.size()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define print(x) cout << (x) << '\n'
#define debug(x) cout << #x << ": " << (x) << '\n'
using namespace std;
using ll = long long;
typedef pair<ll, ll> P;
ll MOD = 1e9 + 7;
ll devc(ll x, ll y) { return 1 + (x - 1) / y; }

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    ll N;
    cin >> N;
    unordered_map<ll, ll> mp;

    rep(_,N){
        ll a;
        cin >> a;
        mp[a]++;
        mp[a - 1]++;
        mp[a + 1]++;
    }
    ll ans = 0;
    for (auto p : mp) ans = max(ans, p.second);
    print(ans);

    return 0;
}

Measured memory_bytes: 4260