akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
vector<int>vis,ans;
vector<bool>dif;
vector<vector<int> >gr,id;
void dfs(int x) {
	vis[x]=1;
	for(int i=0;i<gr[x].size();i++)
		if(!vis[gr[x][i]]) {
			dfs(gr[x][i]);
			if(dif[gr[x][i]]) {
				dif[x]=(int)dif[x]^1;
				ans.push_back(id[x][i]);
			}
		}
}
int main() {
	int n,m;
	vector<pair<int,bool> >bo;
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin>>n>>m;
	bo.resize(n);
	dif.resize(n+1,0);
	vis.resize(n+1,0);
	gr.resize(n+1);
	id.resize(n+1);
	for(int i=0;i<n;i++) cin>>bo[i].first>>bo[i].second;
	sort(bo.begin(),bo.end());
	if(bo[0].second==1) dif[0]=1;
	for(int i=1;i<n;i++)
		if(bo[i].second!=bo[i-1].second)
			dif[i]=1;
	if(bo[n-1].second==1) dif[n]=1;
	for(int i=0;i<m;i++) {
		int l,r,ll,rr;
		cin>>l>>r;
		ll=lower_bound(bo.begin(),bo.end(),make_pair(l,false))-bo.begin();
		rr=upper_bound(bo.begin(),bo.end(),make_pair(r,true))-bo.begin();
		gr[ll].push_back(rr);
		gr[rr].push_back(ll);
		id[ll].push_back(i);
		id[rr].push_back(i);
	}
	for(int i=0;i<=n;i++)
		if(!vis[i]) {
			dfs(i);
			if(dif[i]) {
				cout<<-1<<endl;
				return 0;
			}
		}
	cout<<ans.size()<<endl;
	sort(ans.begin(),ans.end());
	for(int i=0;i<ans.size();i++) cout<<ans[i]+1<<(i==ans.size()-1?'\n':' ');
	return 0;
}

Measured memory_bytes: 20860
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();
		
		final int cake = 4;
		final int donut = 7;
		
		N = N % (cake * donut);
		if(N % 7 % cake <= N / donut)
			System.out.println("Yes");
		else
			System.out.println("No");
	}
}

Measured memory_bytes: 22996
#include <iostream>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	string w;

	w.reserve(100);
	cin >> w;
	
	sort(w.begin(), w.end());

	char ch{w.at(0)};
	int32_t count{ 1 };
	for (auto i{ 1 }; i < w.size(); ++i) {
		if (ch != w[i]) {
			if (count & 1 == 1) 
				break;
			count = 0;
			ch = w[i];
		}
		++count;
	}

	if (count & 1 == 1)
		cout << "No" << endl;
	else
		cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <iomanip>
#include <algorithm>
#include <cassert>
#include <queue>
#include <set>
#include <vector>
#include <cmath>
#include <bitset>
#include <functional>
#include <limits>
#include <map>
using namespace std;

typedef long long ll;
#define rep1(i, n) for(ll i = 1; i <=(ll)(n); i++)
#define rep0(i, n) for(ll i = 0; i <=(ll)(n); i++)

ll pow(ll a, ll n) { //compute a^n with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a;
        a = a * a;
        n >>= 1;
    }
    return res;
}

ll pow(ll a, ll n, ll mod) { //compute a^n (mod mod) with o(logn)
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

const int MAX = 199;
const int MOD = 1000000007;
ll fac[MAX], finv[MAX], inv[MAX];

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

// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

//順列計算
ll PER(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[n - k] % MOD) % MOD;
}

int main(){
    string s;
    cin >> s;
    if(s == "RRR"){
        cout << 3 << endl;
    }else if(s == "RRS" || s == "SRR"){
        cout << 2 << endl;
    }else if(s == "RSS" || s == "SSR" || s == "SRS" || s == "RSR"){
        cout << 1 << endl;
    }else{
        cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 3232
void main()
{
    int n = readln.chomp.to!int;
    string s = readln.chomp;

    int cnt = s[1..$].count('E').to!int;
    int result = cnt;
    foreach (i; 1 .. n)
    {
        if (s[i-1] == 'W') ++cnt;
        if (s[i] == 'E') --cnt;
        result = min(result, cnt);
    }

    result.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 2812
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;


public class Main {

	/**
	 * @param args
	 * @throws IOException 
	 */
	public static void main(String[] args) throws IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

		while(true){
			String[] tmpArray = br.readLine().split(" ");

			int n = Integer.parseInt(tmpArray[0]);
			int m = Integer.parseInt(tmpArray[1]);
			int a = Integer.parseInt(tmpArray[2]);
			if(n == 0 && m == 0 && a == 0){
				return;
			}

			int changePoint[][] = new int[1001][n+1];

			for(int i = 0; i < m; i++){
				tmpArray = br.readLine().split(" ");
				int h = Integer.parseInt(tmpArray[0]);
				int p = Integer.parseInt(tmpArray[1]);
				int q = Integer.parseInt(tmpArray[2]);

//				if(h == 0 && p == 0 && q == 0){
//					break;
//				}

				changePoint[h][p] = q;
				changePoint[h][q] = p;

			}

			for(int i = 1000; i >= 1; i--){
				//			for(int j = 0; j <= n; j++){
				//				System.out.print(changePoint[i][j]+" ");
				//			}
				//			System.out.println();
				if(changePoint[i][a] != 0){
					a = changePoint[i][a];
					//				System.out.println("i = "+i+" change to "+a);
				}
			}

			System.out.println(a);
		}
	}

}

Measured memory_bytes: 64028
import java.util.Scanner;

class Main {
	public static void main(String args[]) {
		Scanner scan = new Scanner(System.in);
		
		int d;
		int ans ;
		int x;
		
		while(scan.hasNextInt()){
			d = scan.nextInt();
			ans = 0;
			x = 1;
			for(int i = d;i < 600; i+=d){
				ans += x * d * x * d * d;
				x++;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 25848
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	k := intScanner()
	fmt.Println((k + 1) / 2 * (k / 2))
}


Measured memory_bytes: 1772
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

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

#include <iostream>

using namespace std;

int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    for(int i=0;i<100;i++)
    {if((c-b)<=0)
    {cout<<"Yes";
    break;
    }
    else
    {c=c-b;
    }
    if((a-d)<=0)
    {cout<<"No";
    break;
    }
    else
    {a=a-d;
    }
    }

    return 0;
}


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

stack<int> st;

int solve(string str){
    int b = st.top(); st.pop();
    int a = st.top(); st.pop();
    if(str=="+") return a+b;
    else if(str=="-") return a-b;
    else if(str=="*") return a*b;
    else if(str=="/") return a/b;
}

int main(){
    string str;
    while(cin>>str){
        if(str=="+"||str=="-"||str=="*"||str=="/")
            st.push(solve(str));
        else st.push(atoi(str.c_str()));
        if(getchar()=='\n'){
            cout << st.top() << endl;
            return 0;
        }
    }
}



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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define Sort(x) sort(x.begin(), x.end())
#define Sort_rev(x) sort(x.begin(), x.end(), greater<int>())
#define ALL(v) (v).begin(), (v).end()

//π M_PI
//deg = rad*180/M_PI

int main() {
    ll n, k, s;
    cin >> n >> k >> s;
    if ( s > 2 ) {
        rep(i, n) {
            if ( i < k ) {
                cout << s << " ";
            } else {
                cout << s-1 << " ";
            }
        }
    } else {
        if ( s == 1 ) {
            rep(i, n) {
                if ( i < k ) {
                    cout << 1 << " ";
                } else {
                    cout << 2 << " ";
                }
            }
        } else {
            rep(i, n) {
                if ( i < k ) {
                    cout << 2 << " ";
                } else {
                    cout << 3 << " ";
                }
            }
        }
    }

    cout << endl;
    return 0;
}


Measured memory_bytes: 1280
#include<bits/stdc++.h>
#define betheflash ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define endl "\n"
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pii pair<int,int>
#define vi vector<int>
#define vs vector<string>
#define vvi vector<vector<int>>
#define mii map<int,int>
#define msi map<string,int>
#define mis map<int,string>
#define pb push_back
#define mod 1000000007
#define PI 3.141592653589793238
using namespace std;
int main()
{
    betheflash
    long long int n,ans=0,m,temp;
    cin>>n;
    long int a[n];
    map<ll,ll> b;
    for(long int i=0;i<n;i++)
    {
    	cin>>a[i];
    	b[a[i]]+=1;
	}
	map<long long int, long long int>::iterator itr; 
	for(itr=b.begin();itr!=b.end();itr++)
	{
		long int v=itr->second;
		ans+=((v)*(v-1))/2;
	}
	
	for(long int i=0;i<n;i++)
	{
		temp=ans;
		
		m=b[a[i]];
		m=(m*(m-1))/2;
		ans=ans-m;
		
		m=b[a[i]];
		m=((m-1)*(m-2))/2;
		ans=ans+m;
		
		cout<<ans<<endl;
		ans=temp;
	}
    return 0;
}

Measured memory_bytes: 11136
import java.util.ArrayList;
import java.util.Collections;
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++) {}
		//M 77 || //A 65 || //R 82 || //C 67 || //H 72 || 
		int N=sc.nextInt();
		char v[]= {77,65,82,67,72};
		
		long vv[]=new long[5];
		for(int i=0;i<N;i++) {
			String S=sc.next();
			for(int a=0;a<5;a++) {
				if(S.charAt(0)==v[a]) {
					vv[a]++;
				}
			}
		}
		
		long ans=0;
		
		for(int a=0;a<5;a++) {
			for(int b=a+1;b<5;b++) {
				for(int c=b+1;c<5;c++) {
					
					ans+=vv[a]*vv[b]*vv[c];
					
					
				}
			}
			
			
		}
		p(ans);
		
		

		
	
		
		
	}



	
	
	
	

	


	
	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);};
	static String nextPermutation(String s) {
		ArrayList<Character> list=new ArrayList<>();
		for(int i=0;i<s.length();i++) {
			list.add(s.charAt(i));
		}
		int pivotPos=-1;
		char pivot=0;
		for(int i=list.size()-2;i>=0;i--) {
			if(list.get(i)<list.get(i+1)) {
				pivotPos=i;
				pivot=list.get(i);
				break;
			}
		}
		if(pivotPos==-1&&pivot==0) {
			return "Final";
		}
		int L=pivotPos+1,R=list.size()-1;
		
		
		
		int minPos=-1;
		char min =Character.MAX_VALUE;
		
		for(int i=R;i>=L;i--) {
			if(pivot<list.get(i)) {
				if(list.get(i)<min) {
					min=list.get(i);
					minPos=i;
				}
			}
		}
		
		Collections.swap(list, pivotPos, minPos);
		Collections.sort(list.subList(L, R+1));
		
		
		StringBuilder sb=new StringBuilder();
		for(int i=0;i<list.size();i++) {
			sb.append(list.get(i));
		}
		return sb.toString();
	}
}
	


Measured memory_bytes: 44912
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string s;
	cin>>s;
	if(s[0] != 'A') {
		cout<<"WA"<<endl;
		return 0;
	}
	else{
		int count=0;
		int check;
		
		for(int i=2;i<s.size()-1;i++){
		
			if(s[i]=='C'){
				count++;
				check=i;
			}
		
			if(count>1){
				cout<<"WA"<<endl;
				return 0;
			}
		
		}
		
		if(count <= 0){
			cout<<"WA"<<endl;
			return 0;
		}

		count=0;

		for(int i=1;i<s.size();i++){
			if(check != i){
				if((s[i]-'a')<0 || (s[i]-'a')>25){
					cout<<"WA"<<endl;
					return 0;
				} 
			}
		}
	}
	cout<<"AC"<<endl;
}

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

MOD = 10 ** 9 + 7

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a].append(b)
    graph[b].append(a)

root = 1
parent = [0] * (N+1)
order = []
stack = [root]
while stack:
    x = stack.pop()
    order.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

# (1/2)^n
x = (MOD + 1) // 2
power = [1] * (N+100)
power_inv = [1] * (N+100)
for i in range(1,N+100):
    power[i] = power[i-1] * 2 % MOD
    power_inv[i] = power_inv[i-1] * x % MOD

# 部分木の大きさ
answer = 0
size = [1] * (N+1)
for v in order[::-1]:
    p = parent[v]
    size[p] += size[v]
    A = [size[w] for w in graph[v] if w != p] # 部分木のサイズ集合
    if v != root:
        A.append(N - 1 - sum(A))
    if len(A) == 1:
        continue
    prod = 1
    coef = 1
    for x in A:
        prod *= power_inv[x]
        prod %= MOD
        coef += (power[x] - 1)
    E = 1 - prod * coef % MOD
    answer += E

answer *= power_inv[1]
answer %= MOD
print(answer)


Measured memory_bytes: 67464
#include <iostream>
#include <vector>
#include <algorithm>
 
using namespace std;
 
int main(int argc, char** argv)
{
    int a, b, c; cin >> a >> b >> c;
    vector<int> nums{a, b, c};
    sort(nums.begin(), nums.end(), greater<int>());
 
    cout << 10 * nums[0] + nums[1] + nums[2] << endl;
    return 0;
}

Measured memory_bytes: 256
import sys
def S(): return sys.stdin.readline().rstrip()
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
INF = 1000000000000

n = I()
result = [0]*4
for i in range(n):
    s = S()
    if(s == 'AC'):
        result[0] += 1
    elif(s == 'WA'):
        result[1] += 1
    elif(s == 'TLE'):
        result[2] += 1
    elif(s == 'RE'):
        result[3] += 1

print('AC x ', result[0])
print('WA x ', result[1])
print('TLE x ', result[2])
print('RE x ', result[3])


Measured memory_bytes: 73488
//Author ::  ABHINAV3010 ::

#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define endl "\n"
#define all(x) (x).begin(), (x).end()
#define fast ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr)
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp>
typedef long long ll;
typedef pair<ll,ll> p;
#define vv(a) vector< vector<a> >
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    new_data_set;
ll mod=1000000007;
ll gcd(ll a,ll b)
{
    return (b==0)?a:gcd(b,a%b);
}
ll power(ll x, ll y, ll p=mod)
{ll res = 1;x = x % p;while (y > 0){if (y & 1){res = (res*x) % p;}y = y>>1;x = (x*x) % p;}return res;}
int main()
{
fast;
ll k;
cin>>k;
string s;
cin>>s;
string ans=s;
if(s.size()>k)
{
     ans=s.substr(0,k)+"...";
}
cout<<ans<<endl;
return 0;
}


Measured memory_bytes: 3656
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

int main() {
    int n,k;
    cin >> n >> k;
    int d[k];
    for(int i=0;i<k;i++) cin >> d[i];

    for(int i=n;;i++){
        int digit;
        bool ok=true;
        int m=i;
        while(m>0){
            digit = m%10;
            for(int j=0;j<k;j++){
                if(digit == d[j]) ok=false;
            }
            m /= 10;
        }
        if(ok){
            cout << i << endl;
            return 0;
        }
    }

}

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

using namespace std;

bool solve(const string& s, const string& t, const string& target)
{
    int N = target.size();
    int a = 0, b = 0, p = 0;    
    for (int i = 0; i < N; i++, p ^= 1) {
        char c = target[i];
        bool found = 0;
        if (p == 0) {
            while (a < N) {
                if (s[a++] == c) {
                    found = 1;
                    break;
                }
            }
        } else {
            while (b < N) {
                if (t[b++] == c) {
                    found = 1;
                    break;
                }
            }
        }
        if (!found) return 0;           
    }
    return 1;
}

int main()
{
    string s, t;
    cin >> s >> t;
    bool res = solve(s, t, s) | solve(t, s, s);
    cout << (res ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 3220
using System;
using System.Collections.Generic;
using System.Linq;
using BitArray = System.Collections.BitArray;
using BigInteger = System.Numerics.BigInteger;
using TextReader = System.IO.TextReader;
using System.Text;

namespace AtCoderProject
{
    public class Program
    {
        public object Calc()
        {
            var N = consoleReader.Int + consoleReader.Int;
            return N >= 10 ? "error" : N.ToString();
        }


        #region いつもの
#pragma warning disable
        private ConsoleReader consoleReader;
        public Program(ConsoleReader consoleReader) { this.consoleReader = consoleReader; }
        static void Main() => Console.WriteLine(new Program(new ConsoleReader(Console.In)).Calc()); static string AllLines<T>(IEnumerable<T> source) => string.Join("\n", source);
    }
    static class Ext
    {
        public static Dictionary<TKey, int> GroupCount<TSource, TKey>(this IEnumerable<TSource> source, Func<TSource, TKey> keySelector) => source.GroupBy(keySelector).ToDictionary(g => g.Key, g => g.Count());
        public static Dictionary<TKey, int> GroupCount<TKey>(this IEnumerable<TKey> source) => source.GroupCount(i => i);
    }
    public class ConsoleReader { private string[] ReadLineSplit() => textReader.ReadLine().Split(Array.Empty<char>(), StringSplitOptions.RemoveEmptyEntries); private string[] line = Array.Empty<string>(); private int linePosition; private TextReader textReader; public ConsoleReader(TextReader tr) { textReader = tr; } public int Int => int.Parse(String); public long Long => long.Parse(String); public double Double => double.Parse(String); public string String { get { if (linePosition >= line.Length) { linePosition = 0; line = ReadLineSplit(); } return line[linePosition++]; } } public class SplitLine { private string[] splited; public SplitLine(ConsoleReader cr) { splited = cr.ReadLineSplit(); cr.line = Array.Empty<string>(); } public int[] Int => String.Select(x => int.Parse(x)).ToArray(); public int[] Int0 => String.Select(x => int.Parse(x) - 1).ToArray(); public long[] Long => String.Select(x => long.Parse(x)).ToArray(); public double[] Double => String.Select(x => double.Parse(x)).ToArray(); public string[] String => splited; } public SplitLine Split => new SplitLine(this); public class RepeatReader : IEnumerable<ConsoleReader> { ConsoleReader cr; int count; public RepeatReader(ConsoleReader cr, int count) { this.cr = cr; this.count = count; } public IEnumerator<ConsoleReader> GetEnumerator() => Enumerable.Repeat(cr, count).GetEnumerator(); System.Collections.IEnumerator System.Collections.IEnumerable.GetEnumerator() => GetEnumerator(); public IEnumerable<string> String => this.Select(cr => cr.String); public IEnumerable<int> Int => this.Select(cr => cr.Int); public IEnumerable<int> Int0 => this.Select(cr => cr.Int - 1); public IEnumerable<long> Long => this.Select(cr => cr.Long); public IEnumerable<double> Double => this.Select(cr => cr.Double); } public RepeatReader Repeat(int count) => new RepeatReader(this, count); }
    #endregion
}


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

using namespace std;

int const N = 241;

int a[N], ans, n;

int main(){
	scanf("%d",&n);
	for(int i=0;i<2*n;++i){
		scanf("%d",&a[i]);
	}
	sort(a, a+2*n);
	for(int i=0;i<2*n;i+=2){
		ans += a[i];
	}
	printf("%d\n",ans);



	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.ComponentModel.Design;
using System.Globalization;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using System.Threading.Tasks;
using System.Xml.Schema;
using static System.Console;

namespace ConsoleApp2
{
    class Program
    {
        static public long[] Sarray() { return ReadLine().Split().Select(long.Parse).ToArray(); }
        static public List<int> Slist() { return new List<int>(ReadLine().Split().Select(int.Parse)); }
        static void Main(string[] args)
        {
            var N = Sarray()[0];
            var ans = 1000 - (N % 1000);
            WriteLine(ans%1000);
            
        }
    }
}

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

using pii = pair<int,int> ;
using pll = pair<long,long> ;
using umpii = unordered_map<int,int> ;
using mpii = map<int,int> ;

#define f first
#define s second

int32_t main(){
	int n ;
	cin >> n ;
	int a[n] , count = 0 ;
	for(int i = 0 ; i < n ; i++) cin >> a[i] ;
	for(int i = 0 ; i < n - 2 ; i++){
		vector<int> x ;
		for(int j = i ; j < i + 3 ; j++){
			x.push_back(a[j]) ;
		}
		sort(x.begin() , x.end()) ;
				// for(auto j : x ) cout << j <<" ";
		if(x[1] == a[i+1]) {count++ ; }
	}
	cout << count ;
	return 0 ;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Text;

namespace ConsoleApplication2
{
    class Program
    {
        static void Main(string[] args)
        {
            string s =Console.ReadLine();
            int n =int.Parse(s);
            n = n * n * n;
            Console.WriteLine(n);
        }
    }
}

Measured memory_bytes: 5600
#include <cstdio>
const int N=100005;
#define ll long long
ll a[N];
int nxt[N][18];
int main (){
	int n;scanf ("%d",&n);
	for (int i=1;i<=n;i++) scanf ("%d",&a[i]);
	int L,q;scanf ("%d%d",&L,&q);
	int lst=n;
	for (int i=n;i>=1;i--){
		while (a[lst]-a[i]>L) --lst;
		nxt[i][0]=lst;
	}
	for (int j=1;j<=16;j++)
		for (int i=1;i<=n;i++)
			nxt[i][j]=nxt[nxt[i][j-1]][j-1];
	while (q--){
		int x,y,ans=0;scanf ("%d%d",&x,&y);if (x>y) x^=y^=x^=y;
		for (int j=16;j>=0;j--)
			if ((nxt[x][j])&&(nxt[x][j]<y)) x=nxt[x][j],ans+=(1<<j);
		printf ("%d\n",ans+1);
	}
	return 0;
}


Measured memory_bytes: 8576
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <list>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <cstring>
typedef long long ll;
using namespace std;

int weight[100005];
int n, k;

bool FillUp(int p)
{
	ll num = 0, cur = 0;
	for (int j = 0; j < k; ++j)
	{
		cur = 0;
		while (cur + weight[num] <= p)
		{
			cur += weight[num];
			++num;
			if (num == n)
				return true;
		}
	}
	return false;
}


ll solve()
{
	ll left = 0;
	ll right = 100000 * 10000;
	while (right - left > 1)
	{
		ll mid = (right + left) / 2;
		if (FillUp(mid))
			right = mid;
		else
			left = mid;
	}
	return right;
}

int main()
{
	//freopen("in.txt", "r", stdin);
	//freopen("out.txt", "w", stdout);
	cin >> n >> k;
	for (int i = 0; i != n; ++i)
	{
		scanf("%d", &weight[i]);
	}
	cout << solve() << endl;
	return 0;
}

Measured memory_bytes: 3596
import java.util.Scanner;
public class Main {
     
 
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int L = 0;
        int R = 0;
        for(int i = 0; i < n; i++) {
            String s1 = stdIn.next();
            String s2 = stdIn.next();
             
            if(s1.compareTo(s2) == 0) {
                L++;
                R++;
            }
            else if(s1.compareTo(s2) < 0) {
                L += 3;
            }
            else {
                R += 3;
            }
        }
         
        System.out.println(R + " " + L);
    }
}


Measured memory_bytes: 29880
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;


int main()
{
	int D,N,M;
	while(cin>>D,D)
	{
		cin >> N >> M;

		vector<int> v;
		v.push_back(0);
		while(--N)
		{
			int d;
			cin >> d;
			v.push_back(d);
		}
		v.push_back(D);

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

		int a = 0;
		while(M--)
		{
			int k;
			cin >> k;

			vector<int>::iterator it;
			it = upper_bound(v.begin(), v.end(), k);

			a += min(*it-k, k-*(it-1));
		}
	
		cout << a << endl;
	}
}

Measured memory_bytes: 1428
n, k = map(int, raw_input().split())
ary = []
for i in xrange(n):
    a, b = map(int, raw_input().split())
    ary.append([a, b]) 
ary.sort(key=lambda x:x[0])
for i in xrange(n):
    k -= ary[i][1]
    if k <= 0:
        result = ary[i][0]
        break
print result


Measured memory_bytes: 22080
def main():

  n=int(input())
  ab=[] #red
  for i in range(n):
    a,b=map(int,input().split())
    ab.append((a,b))
  ab.sort(reverse=True,key=lambda x:x[1])

  cd=[] #blue
  for i in range(n):
    c,d=map(int,input().split())
    cd.append((c,d))
  cd.sort(reverse=False,key=lambda x:x[0])

  cnt=0
  checked_cd=[]
  checked_ab=[]
  for i,(c,d) in enumerate(cd):
    for j,(a,b) in enumerate(ab):
      if i in checked_cd or j in checked_ab:
        continue

      if a<c and b<d:
        cnt+=1
        checked_cd.append(i)
        checked_ab.append(j)

  print(cnt)
  
main()

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

using namespace std;

typedef vector< vector<int> > Graph;

Graph g;

int dfs(int cur, int par) {
	int res = 0, cnt = 0;
	for (int nex : g[cur]) {
		if (nex == par) continue;
		res ^= dfs(nex, cur) + 1;
	}
	return res;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin >> n;
	g.resize(n);
	for (int i = 1; i < n; i++) {
		int x, y;
		cin >> x >> y;
		x--;
		y--;
		g[x].push_back(y);
		g[y].push_back(x);
	}

	cout << (dfs(0, -1) == 0 ? "Bob" : "Alice") << endl;
	return 0;
}

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

public class Main {
	static int a, b, c;

	public static void main(String[] args) {
		try {
			BufferedReader br = createBufferedReader();
			String line = br.readLine();
			StringTokenizer st = new StringTokenizer(line, " ");
			final int N = Integer.parseInt(st.nextToken());
			final int K = Integer.parseInt(st.nextToken());
			final int Q = Integer.parseInt(st.nextToken());
			int[] a = new int[Q];
			int[] points = new int[N];
			int maxpoint = 0;
			for (int i = 0; i < N; i++) {
				points[i] = 0;
			}
			for (int i = 0; i < Q; i++) {
				a[i] = Integer.parseInt(br.readLine());
				if (points[a[i] - 1] == maxpoint) {
					maxpoint++;
				}
				points[a[i] - 1]++;
			}
			for (int i = 0; i < N; i++) {
				System.out.println((Q - points[i] < K) ? "Yes" : "No");
			}
		} catch (IOException ioe) {
			ioe.printStackTrace();
		}
	}

	// 以下問題問わずに共通部分
	// 標準入力の BufferedReader を返す.
	private static BufferedReader createBufferedReader() {
		InputStreamReader isr = new InputStreamReader(System.in);
		return new BufferedReader(isr);
	}
}


Measured memory_bytes: 47824
#include<bits/stdc++.h>
using namespace std;
#define se second
#define fi first
#define ll long long
#define ld long double
#define pll pair<ll ,ll >
#define pii pair<int, int> 
#define mod 998244353
ll power(ll a,ll b){
    ll res=1;
    while(b>0){
        if(b%2!=0) res=(res*a)%mod;
        a=(a*a)%mod;
        b/=2;
    }
    return res;
}
ll ncr(ll n,ll k){
    if(k==0||k==n) return 1ll;
    if(k>n-k) k=n-k;
    ll pro=1;
    for(ll i=0;i<k;i++){
        pro=(pro*(n-i))%mod;
        pro/=(i+1);
    }
    return (pro%mod);
}
vector<int> prime;
void seive(){
    vector<bool > isprime(2001,true);
    for(int i=2;i*i<=2000;i++){
        if(isprime[i]){
            for(int j=i*i;j<=2000;j+=i){
                isprime[j]=false;
            }
        }
    }
    for(int i=2;i<=2000;i++){
        if(isprime[i]) prime.push_back(i);
    }
}

int main(void){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll n,k,q,a;
    cin>>n>>k>>q;
    vector<ll> arr(n+1,0);
    for(int i=0;i<q;i++){
        cin>>a;
        arr[a]++;
    }
    for(int i=1;i<n+1;i++){
        //cout<<arr[i]<<endl;
        if(arr[i]-q+k>0) cout<<"Yes"<<endl;
        else cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 1408
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {

    void run() {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        int cnt = 0;
        for (int i = 0; i < n; i++) {
            cnt += (s.charAt(i) == 'R' ? 1 : 0);
        }
        System.out.println(cnt > n - cnt ? "Yes": "No");
    }

    void debug(Object...os) {
        System.err.println(Arrays.deepToString(os));
    }

    public static void main(String[] args) {
        new Main().run();
    }
}


Measured memory_bytes: 23764
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

using namespace std;


struct UnionFind {
	UnionFind(int n) :parent(n), rank(n, 0), nums(n, 1), groupnum(n) {
		iota(parent.begin(), parent.end(), 0);
	}
	int find(int a) {
		return parent[a] == a ? a : (parent[a] = find(parent[a]));
	}
	bool same(int a, int b) {
		return find(a) == find(b);
	}
	void unite(int a, int b) {
		a = find(a), b = find(b);
		if (a == b)
			return;
		groupnum--;
		if (rank[a] < rank[b]) {
			parent[a] = b;
			nums[b] += nums[a];
		}
		else {
			parent[b] = a;
			nums[a] += nums[b];
			if (rank[a] == rank[b])
				rank[a]++;
		}
	}
	int group_count() {
		return groupnum;
	}
	int get_group_size(int i) {
		return nums[find(i)];
	}
	vector<int> parent;
	vector<int> rank;
	vector<int> nums;
	int groupnum;
};


int main() {
	int n, m;
	cin >> n >> m;
	UnionFind uf(n);
	for (int i = 0; i < m; i++) {
		int x, y, z;
		cin >> x >> y >> z;
		x--, y--;
		uf.unite(x, y);
	}
	cout << uf.group_count() << endl;
	return 0;
}

Measured memory_bytes: 1408
/*#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
#include<bits/stdc++.h>

using namespace std;
# define ll long long
# define int long long  //comment it out when MLE
//# define endl "\n"
#define gok ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//# define m 163577857
//# define MOD 163577857
# define pi acos(-1)
# define fi first
# define se second
#define REP(i,n) for (int i = 1; i <= n; i++)

const ll mod = 1000000007;
const int K = 2;
//typedef vector<vector<int> > matrix;
int add(int a, int b,int mod) {
    a%=mod;
    b%=mod;
	a += b;
	if (a >= mod) a -= mod;
	if(a<0)
    {
        a += mod;
        a %= mod;
    }
	return a;
}

int mul(ll a, int b,int mod) {
    a%=mod;
    b%=mod;
	a *= b;
	return a % mod;
}
int po(int a,int b,int mod)
{
    if(b==0)
        return 1;
    if(b%2==0)
        return po(mul(a,a,mod),b/2,mod);
    return mul(a,po(mul(a,a,mod),(b-1)/2,mod),mod);
}


ll fact[1000003];
ll inv[1000003];

void fact0()
{
	int i,j;
	fact[0]=1;
	for(i=1;i<=200000;i++)
	{
		fact[i]=i*fact[i-1]%mod;
	}
	inv[0]=1;
	inv[1]=1;
	ll p=mod;
	for (i=2; i<=200000; i++)
		inv[i] = (p - (p/i) * inv[p%i] % p) % p;

	for(i=2;i<=200000;i++)
	{
		inv[i]*=inv[i-1];
		inv[i]%=mod;
	}
}


signed main()
{
    gok
   //fact0();

   int k,a,b;
   cin>>k>>a>>b;
   int tt=k;
   bool ch=false;
   while(k<2000)
   {
       if(k>=a&&k<=b)
       {
           ch=true;
           break;
       }
       k+=tt;
   }
   if(ch)
    cout<<"OK";
   else
    cout<<"NG";
















    return 0;
    }


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define all(x) (x).begin(), (x).end()
const int MOD = 1e9 + 7 ;
int mpow(int a,int b,int p=MOD){a=a%p;int res=1;while(b>0){if(b&1)res=(res*a)%p;a=(a*a)%p;b=b>>1;}return res%p;}
const int N=1e5+3;

int32_t main(){
      ios_base::sync_with_stdio(false);
      cin.tie(NULL);
      int n;
      cin>>n;
      int p[n];
      for(int i=0;i<n;i++) cin>>p[i];
      bool f=true;
      for(int i=1;i<n;i++)
      {
            if(p[i]<p[i-1]) f=false;
      }
      if(f)
      {
            cout<<"YES\n";
            return 0;
      }
      for(int i=0;i<n;i++)
      {
            for(int j=i+1;j<n;j++)
            {
                  int t[n];
                  for(int k=0;k<n;k++) t[k]=p[k];
                  swap(t[i],t[j]);
                  bool f=true;
                  for(int k=1;k<n;k++)
                  {
                        if(t[k]<t[k-1]) f=false;
                  }
                  if(f)
                  {
                        cout<<"YES\n";
                        return 0;
                  }
            }
      }
      cout<<"NO\n";
}
// I never lose. I either win or I learn

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
//const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int N;
    cin >> N;
    vector<int> a(N), b(N), c(N), d(N);
    vector<pair<int, int>> p_r(N), p_b(N);
    rep(i, 0, N){
        cin >> a.at(i) >> b.at(i);
        p_r.at(i) = make_pair(a.at(i), b.at(i));
    }
    rep(i, 0, N){
        cin >> c.at(i) >> d.at(i);
        p_b.at(i) = make_pair(c.at(i), d.at(i));
    }
    sort(all(p_r));
    sort(all(p_b));
    set<int> foot;
    int count = 0;
    rep(i, 0, N){
        int bx = p_b.at(i).first;
        int by = p_b.at(i).second;
        int maxy = -300;
        int numy;
        //cout << "B " << bx << " " << by << endl;
        for (int j = 0; j < N; j++){
            if (!foot.count(j)){
                int rx = p_r.at(j).first;
                int ry = p_r.at(j).second;
                //cout << "R " << rx << " " << ry << endl;
                if (rx < bx){
                    if (ry < by){
                        if (maxy < ry){
                            maxy = ry;
                            numy = j;
                            //cout << " OK " << endl;
                        }
                    }
                }
            }
            if (j == N - 1){
                if (maxy != -300){
                    foot.insert(numy);
                    count++;
                }
            }
        }
        
    }
    cout << count << endl;
}

Measured memory_bytes: 256
n = int(input())
a, b = list(map(int, input().split()))
p = list(map(int, input().split()))
cnta = 0
cntb = 0
cntc = 0
for pi in p:
  if pi <= a:
    cnta += 1
  elif pi <= b:
    cntb += 1
  else:
    cntc += 1
ans = min([cnta, cntb, cntc])
print(ans)


Measured memory_bytes: 3060
S = list(input())
T = list(input())

li = [[0 for _ in range(len(S)+1)] for _ in range(len(T)+1)]

for s in range(1,len(S)+1):
    for t in range(1,len(T)+1):
        if S[s-1] == T[t-1]:
            li[t][s] = max(li[t-1][s], li[t][s-1], li[t-1][s-1]+1)
        else:
            li[t][s] = max(li[t-1][s],li[t][s-1])

s = len(S)
t = len(T)
ans = ""
while(s and t):
    if (S[s-1]==T[t-1]) and (li[t][s]-1==li[t-1][s-1]):
        ans = S[s-1]+ans
        s-=1
        t-=1
    elif li[t-1][s] >= li[t][s-1]:
        t-=1
    elif li[t-1][s] < li[t][s-1]:
        s-=1
print(ans)

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

int main(){
    int n,k,x,y;
    cin>>n>>k>>x>>y;
    cout<<min(k,n)*x+max(0,n-k)*y<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using pq = priority_queue<int>;
template<class T>
using P = pair<T, T>;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define REP(i,k,n) for(int i=(k);i<(n);i++)
#define all(a) (a).begin(),(a).end()
#define output(x,y) cout << fixed << setprecision(y) << x << endl;
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; }
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int under = (1 << 31);
int upper = under - 1;
ll UNDER = (1LL << 63);
ll UPPER = UNDER - 1;
const int MOD = 1e9 + 7;
const long double pi = 3.141592653589793;
int main(){
	int n;
	cin >> n;
	int sum = 0;
	rep1(i, n) rep1(j, n) {
		int tmp = gcd(i, j);
		if (tmp == 1) sum += n;
		else {
			rep1(k, n) {
				sum += gcd(tmp, k);
			}
		}
	}
	cout << sum << endl;
	return 0;
}

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

int main()
{
	string s;cin>>s;
	int n=s.length();
	if(s[n-1]=='s')
	{
		cout<<s+"es";
	}
	if(s[n-1]!='s')
	{
		cout<<s+'s';
	}
	return 0;
}


Measured memory_bytes: 3648
N = int(input())
S = input()
L = [0] * N
for i in range(N):
    if S[i] == "#":
        L[i] = 1
    else:
        L[i] = 0

leftblack = 0
rightwhite = len([x for x in L if x == 0])
ans = leftblack + rightwhite

for i in range(N):
    if S[i] == "#":
        leftblack += 1
    else:
        rightwhite -=1
    ans = min(ans, leftblack + rightwhite)
print(ans)

Measured memory_bytes: 6632
#include "bits/stdc++.h"
using namespace std;
using ll = long long;

template <typename T>
void print_vec(const vector<T>& v, bool is_reverse=false, ll num=0){
  if(num == 0) num = (ll)v.size();
  cout << endl; cout << "i=  ";for(ll i=0; i<num; i++) cout << i << "   ";cout << endl;  
  cout << "    ";
  if(is_reverse) for(ll i=num-1; i>=0; i--){ cout<<v[i]; if(i!=0) cout<<"   ";}
  else for(ll i=0; i<num; i++){ cout<<v[i]; if(i!=num-1) cout<<"   ";}
  cout << endl;
}

// template <typename T>
// void print_pairvec(const vector<T> &v, ll num=0){
//   if(num == 0) num = (ll)v.size();
//   cout << endl; for(ll i=0; i<num; i++){ cout << v[i].first << " " << v[i].second << endl;}
// }
template <typename T>
void print_pairvec(const T &_pair, ll num=0){
  cout << endl; for(pair<ll, int> x: _pair){ cout << x.first << " " << x.second << endl;}
}

template <typename T>
void print_vec2(const vector<vector<T>>& v){
  cout << endl; cout << "       ";
  for(ll i=0; i<v[0].size(); i++) cout << i << "   "; 
  cout << endl;
	for(ll i=0; i<v.size(); i++){
		cout << "i=" << i << ":   ";
		for(ll j=0; j<v[i].size(); j++){
			if(v[i][j] == 0) cout << "\x1B[0m" << v[i][j] << "   ";
      else cout << "\x1B[31m" << v[i][j] << "   ";//https://stackoverrun.com/ja/q/12618775
		}
		cout << "\x1B[0m" << endl;
	}
}

int gcd(int a, int b){
  if(b == 0) return a;
  return gcd(b, a%b);
}
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for(int i=0; i<N; i++) cin >> a[i];

  int g = 0;
  for(int i=0; i<N; i++) g = gcd(g, a[i]);
  cout << g << endl;
  return 0;
}


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

using namespace std;

int main() {
  int ans = 0;
  string str;
  while (cin >> str) {
    int scale = 1;
    for (int i = str.length()-1; 0<= i; --i) {
      int a = str[i] - '0';
      if ((0<=a) && (a<=9)) {
        ans += a * scale;
        scale *= 10;
      }
      else {
        scale = 1;
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll k,q;cin>>k>>q;
    vector<ll> d(k); rep(i,k)cin>>d[i];
    vector<ll> a(k);//本当のa_jはこれにx_iとかいろいろ足す
    a[0]=0;
    for(int i=0; i<k-1; i++){
        a[i+1]=a[i]+d[k];
    }


    for(int i=0; i<q; i++){
        ll n,x,m;cin>>n>>x>>m;
        //繰り上がり回数を数える
        //足してって最後に割ればOK
        //O(n)はだめなので繰り返しはまとめて
        vector<ll> e(k);
        rep(i,k){
            e[i]=d[i]%m;
        }
        ll sumc = 0, sump = 0, sumcc = 0, sumpp = 0;
        ll A = (n-1)/k, B=(n-1)%k;
        for(int j=0; j<k; j++){
            sumc += e[j];
            if(e[j]==0)sumcc++;
            if(j<B){
                sump+=e[j];
                if(e[j]==0)sumpp++;
            }
        }
        ll sum = sumc*A+sump+x;
        cout<<n-1-(sum/m-x/m)-sumcc*A-sumpp<<endl;
    }

    


    
    return 0;
}

Measured memory_bytes: 384
# ABC129B - Balance
from itertools import accumulate as acc


def main():
    N, *W = map(int, open(0).read().split())
    total, cumsum = sum(W), list(acc(W))
    ans = min(abs(total - i * 2) for i in cumsum)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

int main(){
  ll N;
  cin >> N;
  ll sum = 0;
  vl T(N);
  rep(i, N){
    cin >> T[i];
    sum += T[i];
  }

  ll M;
  cin >> M;
  vpll PX(M);
  rep(i, M) cin >> PX[i].first >> PX[i].second;

  rep(i, M){
    cout << sum - T[PX[i].first - 1] + PX[i].second << endl;
  }
    
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()

{
   int i,j,tc,a[100000],cnt=0,z;

   scanf("%d",&tc);

   for(i=0;i<tc;i++)
   {
      scanf("%d",&a[i]);
   }

   for(j=1,z=0;j<=tc;j++,z++)
   {
      if(j!=a[z])
      {
         cnt++;
      }
   }

   if(cnt<=2)
   {
      printf("YES\n");
   }

   else
   {
      printf("NO\n");
   }
}


Measured memory_bytes: 1656
//ProblemE

#ifdef _MYPC
#include "mypc.h"
#endif // _MYPC

#include <iostream>
#include <string>
#include <vector>
#include <bitset>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <algorithm>
#include <numeric>
#include <functional>
#include <memory>
#include <complex>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;

//ProblemE

class Solve {
private:

	void solve() {
		int n;
		cin >> n;
		vector<int> a(n, 0), b(n, 0);

		long long rst = 0;
		int minbi = 1000000009;
		for (int i = 0; i < n; i++) {
			cin >> a[i] >> b[i];
			if (a[i] > b[i]) {
				minbi = min(minbi, b[i]);
			}
			rst += a[i];
		}
		if (minbi == 1000000009) {
			rst = minbi;
		}
		cout << rst - minbi << endl;
	}

public:
	Solve() { solve(); }
};

int main(int argc, char* argv[]) {
	unique_ptr<Solve> solve = make_unique<Solve>();
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef double db; 
typedef string str; 
typedef pair<ll,ll> pl; 
typedef vector<ll> vl; 
typedef vector<vl> vvl; 
#define mp make_pair
#define se second
#define pb push_back
#define pf push_front
#define nn <<"\n"
#define F0R(i,a) for(ll i=0;i<a;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
int INF=0x3f3f3f3f;
ll MOD=1000000007;

ll binpow(ll a,ll b, ll c=1e18){
	ll res=1;
	while(b>0){
		if(b & 1){
			res*=a;
			res%=c;
		}
		a*=a;
		a%=c;
		b>>=1;
	}
	return res;
}
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	//ifstream cin("name.in");
	//ofstream cout("name.out");
	string s, t;
	cin>>s>>t;
	ll ans=0;
	for(int i=0;i<s.size();i++){
		if(s[i]!=t[i]) ans++;
	}
	cout<<ans nn;
}


Measured memory_bytes: 3752
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, 0, n) cin >> p[i];
  sort(p.rbegin(), p.rend());

  int ans = 0;
  rep(i, 0, n) {
    if (i == 0)
      ans += p[i] / 2;
    else
      ans += p[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
     
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define int long long
#define rep(i,a,b)    for( i=a;i<b;i++)
#define rep1(i,a,b)    for(int i=a;i<b;i++)

#define repn(i,a,b)   for(int i=a;i>=b;i--)
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define vii vector<pii>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define mod 1000000007  
#define mod2 998244353 
#define pi 3.14159265358979323846

int solve(){
    int v[10],q,ans=0,s=0,n,m;
    cin>>n>>m>>q;
    int a[q],b[q],c[q],d[q];
    rep1(i,0,q) cin>>a[i]>>b[i]>>c[i]>>d[i];
    rep(v[0],1,m+1){
    rep(v[1],v[0],m+1){
    rep(v[2],v[1],m+1){
    rep(v[3],v[2],m+1){
    rep(v[4],v[3],m+1){
    rep(v[5],v[4],m+1){
    rep(v[6],v[5],m+1){
    rep(v[7],v[6],m+1){
    rep(v[8],v[7],m+1){
    rep(v[9],v[8],m+1){
        s=0;
        rep1(i,0,q){
            if(v[b[i]-1]-v[a[i]-1]==c[i]) s=s+d[i];
        }
        ans=max(ans,s);
    }}}}}}}}}}
    cout<<ans;
    return 0;
}   
     
signed main(){      
    IOS;
    int t=1;
    //cin>>t;   
    while(t--){
        solve();
        //if(solve()) cout<<"YES";
        //else cout<<"NO";
        cout<<"\n";
    }
    return 0;
}   

Measured memory_bytes: 3588