akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
typedef long long ll;
typedef pair<ll,ll> pr;
typedef vector<ll> vc;
typedef unordered_map<ll,ll> umap;
#define pb emplace_back
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define reps(i,v) for(ll i=0;i<v.size();i++)
template<typename T> void chmin(T &a, const T &b) { a = min(a, b); }
template<typename T> void chmax(T &a, const T &b) { a = max(a, b); }
const ll mod = 1e9+7;

int main() {
    // your code goes here
    ll n, ans=1;
    string s;
    vector<string> v;
    cin >> n;
    rep(i,0,n-1){
        cin >> s;
        v.pb(s);
    }
    sort(v.begin(), v.end());
    rep(i,1,n-1){
        if(v[i]!=v[i-1]) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 11648
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>
#include <limits>
#include <iomanip>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

	int numLength = n.length();

	ll sum = 0;
	for (int i = 0; i < numLength; i++)
	{
		string numStr = n.substr(i, 1);
		int num = atoi(numStr.c_str());
		sum += num;
	}

	string result = (sum % 9 == 0) ? "Yes" : "No";

	cout << result << endl;
    return 0;
}

Measured memory_bytes: 3756
from numpy import*
a,b=map(int,input().split())
c=["0"]*(b+2)
x=[list("0"+input().replace(".","0").replace("#","1")+"0")for i in range(a)]
x.insert(0,c)
x.append(c)
y=zeros((a+2,b+2))
x=array(x).astype(int)
for s in range(1,1+a):
    tmp=""
    for t in range(1,1+b):
        if x[s][t]==1:
            tmp+="#"
        else:
            tmp+=str(sum(x[s-1:s+2,t-1:t+2]))
    print(tmp)

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 998244353

typedef long long ll;
typedef pair<ll,ll> P;

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

	ll a, b;cin >> a >> b;
	cout << max(0LL, a - 2 * b) << endl;

	return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main 
{
	public static void main(String[] args)
	{
		class Area
		{
			double x, y, z;
		}
		ArrayList<Area> area = new ArrayList<>();
		Scanner scanner = new Scanner(System.in);
		
		double total_angle = 0;
		for(int i=0; i<1000; i++)
		{
			Area a = new Area();
			double v = 1;
			if(i > 0)
			{
				double z = area.get(i-1).z;
				a.z = Math.sqrt(z*z + 1);
				v = a.z;
			}
			else
			{
				a.z = 1;
			}
			total_angle += Math.asin(1/a.z);
			a.x = v * Math.sin(total_angle);
			a.y = -v * Math.cos(total_angle);		
			area.add(a);
		}
		
		for(; ;)
		{
			int n = scanner.nextInt();
			if(n == -1)
			{
				break;
			}
			
			System.out.printf("%1$.2f\n", area.get(n-1).x);
			System.out.printf("%1$.2f\n", area.get(n-1).y);
		}
	}
}

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

int main() {
    using namespace std;
    int N;
    cin >> N;
    int p[N];
    int i, count = 0;
    for(i=0; i<N; ++i) {
        cin >> p[i];
    }

    if(p[0] == 1) {
        swap(p[0], p[1]);
        ++count;
    }
    for(i=1; i<N; ++i) {
        if(p[i] == i+1) {
            if(p[i+1] == i+1) {
                swap(p[i], p[i-1]);
            }
            else {
                swap(p[i], p[i+1]);
            }
            ++count;
        }
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
long long num;
cin>>num;
string s="";
while(num){
    int mod=num%26;
    if(mod==0){
        s+='z';
        num/=26;
        num-=1;
    }
    else{
        s+='a'+mod-1;
        num/=26;
    }
}
reverse(s.begin(),s.end());
cout<<s;

    return 0;
}

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

int main(){
    int n;
    cin >> n;
    string s[n];
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    bool no = false;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i != j){
                if(s[i] == s[j]) no = true;
            }
        }
    }
    if(no == true){
        cout << "No" << endl;
        return 0;
    }
    for(int i = 1; i < n; i++){
        if(s[i-1][s[i-1].size()-1] != s[i][0]) no = true;
    }
    if(no == true){
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>

using namespace std;

int main(void){
    for(;;){
        int m,d;
        int data[]={0,31,29,31,30,31,30,31,31,30,31,30,31};
        cin>>m>>d;
        if(m==0&&d==0)break;
        for(int i=1;i<=m;i++){
            d+=data[i-1];
        }
        switch(d%7){
            case 0: cout << "Wednesday" << endl; break;
            case 1: cout << "Thursday" << endl;break;
            case 2: cout << "Friday" << endl;break;
            case 3: cout << "Saturday" << endl;break;
            case 4: cout << "Sunday" << endl;break;
            case 5: cout << "Monday" << endl;break;
            case 6: cout << "Tuesday" << endl;
        }
    }
	return 0;
}

Measured memory_bytes: 1152
N,M,K = map(int,input().split())

A = list(map(int, input().split()))
B =list(map(int, input().split()))

sumA=[0]
sumB=[0]


for i in range(N):
  sumA.append(sumA[-1]+A[i])
for i in range(M):
  sumB.append(sumB[-1]+B[i])

  
total=0
startB=len(sumB)-1
for a in range(len(sumA)):
  for b in range(startB,-1,-1):
    if sumA[a]+sumB[b]<=K:
      total=max(total,a+b)
      startB=b
      break
  if sumA[a]>K:
    break
    
print(total)
  

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


int main(){
	int a, b;
    cin >> a >> b;

    if(a > 8 || b > 8){
        cout << ":(" << endl;
    }else{
        cout << "Yay!" << endl;
    }
	
	
	return 0;
}


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

sum = 0
for i in a:
    sum += i

cnt = 0
for i in a:
    if 4 * i * m >= sum:
        cnt += 1

if cnt >= m:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
n = int(input())
arr = list(map(int, input().split()))

# print(arr)

dp = [0]*n
dp[0] = 0
dp[1] = abs(arr[0]-arr[1])

for i in range(2, n):
    dp[i] = min((dp[i-1]+abs(arr[i]-arr[i-1])), (dp[i-2]+abs(arr[i]-arr[i-2])))

print(dp[-1])

Measured memory_bytes: 20552
#include<iostream>
#include<sstream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<complex>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cassert>
using namespace std;

#define rep(i,n) for(int i=0;i<(int)n;i++)
#define fr(i,c) for(__typeof(c.begin()) i=c.begin();i!=c.end();i++)
#define pb push_back
#define mp make_pair
#define all(c) c.begin(),c.end()
#define dbg(x) cerr<<#x<<" = "<<(x)<<endl

typedef vector<int> vi;
typedef pair<int,int> pi;
typedef long long ll;
const int inf=(int)1e9;
const double EPS=1e-9, INF=1e12;

ll extgcd(ll a,ll b,ll &x,ll &y){
	ll g=a; x=1; y=0;
	if(b)g=extgcd(b,a%b,y,x), y-=a/b*x;
	return g;
}
ll inv(ll a,ll m){
	ll x,y;
	extgcd(a,m,x,y);
	return (x%m+m)%m;
}

const int m1=999979,m2=999983;

int main(){
	int n,o,y;
	ll a=0,b=0;
	cin>>n;
	rep(i,n){
		cin>>o>>y;
		if(o==1)a=(a+y)%m1, b=(b+y)%m2;
		if(o==2)a=(a-y%m1+m1)%m1, b=(b-y%m2+m2)%m2;
		if(o==3)a=(a*y)%m1, b=(b*y)%m2;
		if(o==4)a=(a*inv(y,m1))%m1, b=(b*inv(y,m2))%m2;
	}
	ll p,q;
	extgcd(m1,m2,p,q);
	ll ans=(b*m1*p+a*m2*q)%((ll)m1*m2);
	if(ans>=1ll<<31)ans-=(ll)m1*m2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello
{
    public static void Main()
    {
        var a = int.Parse(Console.ReadLine());
        var ans = Math.Pow(a, 1) + Math.Pow(a, 2) + Math.Pow(a, 3);
        Console.WriteLine(ans);
    }
}


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

typedef long lint;
typedef long long llint;
typedef pair<int, int> pint;
typedef pair<long long, long long> pllint;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const llint INF = 1<<21;
// static const llint MOD = 1e9 + 7;

bool compPair(const pint& arg1, const pint& arg2) { return arg1.first > arg2.first; }
template<class T> void chmax(T& a, T b) { if (a < b) { a = b; } }
template<class T> void chmin(T& a, T b) { if (a > b) { a = b; } }

int main(void) {
    string a, b;
    cin >> a >> b;

    if(a.size()>b.size()) { 
        cout << "GREATER" << endl;
        return 0;
    }
    else if(a.size()<b.size()) { 
        cout << "LESS" << endl;
        return 0;
    }
    else {
        for(int in=0;in<a.size();in++) {
            if(a.at(in)-b.at(in)>0) {
                cout << "GREATER" << endl;
                return 0;
            }
            else if (a.at(in)-b.at(in)<0) {
                cout << "LESS" << endl;
                return 0;
            }
            else ;
        }
    }
    cout << "EQUAL" << endl;
    return 0;
}


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

#include <bits/stdc++.h>
using namespace std;
const int maxn = 300, MAXN = 300;
struct edge
{
	int u,v;
	ll cap,flow;
};
vector<edge>e;

vector<int>graph[maxn];

int dist[maxn];
int ptr[maxn];


void add_edge(int u , int v, ll cap)
{
	edge e1 = {u,v,cap,0LL};
	edge e2 = {v,u,0LL,0LL};

	graph[u].push_back(e.size());
	e.push_back(e1);
	
	graph[v].push_back(e.size());
	e.push_back(e2);
}


bool bfs(int s, int t)
{
	memset(dist,-1, sizeof(dist));
	queue<int>q;
	q.push(s);
	dist[s] = 0;
	while(q.size() && dist[t] == -1)
	{
		int u = q.front();
		q.pop();

		for(int i = 0; i < graph[u].size(); i++)
		{
			int id = graph[u][i];
			int v = e[id].v;

			if(dist[v] == -1 && e[id].cap > e[id].flow)
			{
				q.push(v);
				dist[v] = dist[u] + 1;
			}
		}
	}

	return dist[t] != -1;
}

ll dfs(int u , ll flow, int t)
{
	if(!flow)
		return 0;
	if(u == t)
		return flow;
	for(; ptr[u] < graph[u].size(); ptr[u]++)
	{
		int id = graph[u][ptr[u]];
		int v = e[id].v;

		if(dist[v] != dist[u] + 1)
			continue;
		
		ll pushed = dfs(v, min(flow, e[id].cap - e[id].flow), t);
		
		if(pushed)
		{
			e[id].flow += pushed;
			e[id^1].flow -= pushed;
			return pushed;
		}

	}
	return 0;
}


ll dinic(int s, int t)
{
	ll ans = 0;
	while(bfs(s,t))
	{
		memset(ptr,0,sizeof(ptr));
		while(ll pushed = dfs(s, (1LL << 50), t) )
			ans += pushed;
	}
	return ans;
}


ll v[MAXN + 5];
int main(){
	ios::sync_with_stdio(0);
	//cin.tie(0); cout.tie();
	int N;
	cin >> N;
	ll sum = 0;
	for(int i = 2; i <= N+1; i++) {
		cin >> v[i];
		if(v[i] > 0) sum += v[i];
	}


	for(int i = 2; i <= N+1; i++){
		if(v[i] > 0) add_edge(i, N+2, v[i]);
		else add_edge(1, i, -v[i]);
	}

	for(int i = 1; i <= N; i++)
		for(int j = i+i; j <= N; j+=i)
			add_edge(i+1, j+1, (1LL << 45));

	ll ans = dinic(1, N+2);

	cout << sum - ans << "\n";
	return 0;
}

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

std::string s;

int n,k,d[100002],res,count,sum;

int main(){

    std::cin>>n>>k>>s;

    for(int i=0;i<n;i++){
        d[i]=1;
    }

    if(s[0]=='0')
    d[0]=0,count++;

    for(int i=1;i<n;i++){
        if(s[i]==s[i-1])
        d[count]++;
        else
        count++;
    }

    if(count%2==1)
    d[count+1]=0,count++;

    if(k*2>count)
    k=count/2;

    for(int i=0;i<=(count-k*2)/2;i++){
        sum=0;
        for(int j=i*2;j<i*2+k*2+1;j++){
            sum+=d[j];
        }
        if(res<sum)
        res=sum;
    }

    std::cout<<res<<std::endl;

    return 0;

}

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

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

  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a.at(i);
  }
  sort(a.begin(), a.end());

  cout << abs(a.at(0) - a.at(n - 1)) << endl;
}

Measured memory_bytes: 256
package main

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

var (
	MAX      = 500000
	SENTINEL = 2000000000
	cnt      = 0
	L, R     = make([]int, MAX+2), make([]int, MAX+2)
)

func main() {
	fmt.Println(answer(os.Stdin))
}

func answer(r io.Reader) string {
	sc := bufio.NewScanner(r)
	sc.Split(bufio.ScanWords)
	sc.Scan()
	n, _ := strconv.Atoi(sc.Text())
	A := make([]int, n)
	for i := 0; i < n; i++ {
		sc.Scan()
		A[i], _ = strconv.Atoi(sc.Text())
	}

	mergeSort(A, n, 0, n)

	result := strings.TrimRight(fmt.Sprintf("%+v", A)[1:], "]") + "\n"
	return result + strconv.Itoa(cnt)
}

func merge(A []int, n, left, mid, right int) {
	n1 := mid - left
	n2 := right - mid
	for i := 0; i < n1; i++ {
		L[i] = A[left+i]
	}
	for i := 0; i < n2; i++ {
		R[i] = A[mid+i]
	}
	L[n1], R[n2] = SENTINEL, SENTINEL

	i, j := 0, 0
	for k := left; k < right; k++ {
		cnt++
		if L[i] <= R[j] {
			A[k] = L[i]
			i++
			continue
		}
		A[k] = R[j]
		j++
	}
}

func mergeSort(A []int, n, left, right int) {
	if left+1 < right {
		mid := (left + right) / 2
		mergeSort(A, n, left, mid)
		mergeSort(A, n, mid, right)
		merge(A, n, left, mid, right)
	}
}



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

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);	
	int n;
	cin >> n;
	long long int sum = 0;
	vector <int> a(n);
	for (int i = 0; i < n; ++i){
		cin >> a[i];
	}
	sort(a.rbegin(),a.rend());
	sum += a[0];
	a.erase(a.begin());
	n-=2;
	while (n>=2){
		sum += *a.begin()*2;
		a.erase(a.begin());
		n -= 2;
	}
	if (n) sum += *a.begin();
	cout << sum << "\n";
	return 0;
}


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

#define debug(s) cout << #s << " = " << s << endl
#define all(v) (v).begin(), (v).end()
#define KeepUnique(v) (v).erase( unique(all(v)), v.end() )
#define MEMSET(a, val) memset(a, val, sizeof (a))
#define PB push_back
#define endl '\n'
typedef long long ll;

inline int myrand(int l, int r) {
	int ret = rand(); ret <<= 15; ret ^= rand();
	if(ret < 0) ret = -ret; ret %= (r-l+1); ret += l;
	return ret;
}

template <typename F, typename S>
ostream& operator << (ostream& os, const pair< F, S>& p) {
    return os<<"(" <<p.first<<", "<<p.second<<")"; }

typedef pair<int, int> ii;

template<typename T> using min_pq =
	std::priority_queue<T, vector<T>, greater<T> >;

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

int32_t main () {
	// freopen("in", "r", stdin);
	int tym = 10000;
	int n, ans = 0;
	cin >> n;
	vector<int> v(n);
	for(int &b : v) cin >> b;
	for(int i = 1; i < v.size(); i++) {
		if(v[i - 1] == v[i]) {
			v[i] = tym--;
			ans++;
		}
	} cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp> // Common file
//#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
 
using namespace std;
//using namespace __gnu_pbds;
//typedef tree< pair<int, int>, null_type, less<pair<int, int>>, rb_tree_tag, tree_order_statistics_node_update>
//ordered_set;
int dx[] = {0, 1, 0, -1};
int dy[] = {-1, 0, 1, 0};
#define X first
#define Y second
#define int long long int 
const int N = (int)1e6 + 10;
const int MOD = (int) 1e9 + 7;
 
 
void solve(){
    int n; cin >> n;
    int ans = 0;
    for(int i= 1; i <= n; ++i){
        for(int j = 1; j <= n; ++j){
            int gd = __gcd(i, j);
            for(int k = 1; k <= n; ++k){
                ans += __gcd(k, gd);
            }
        }
    }
    cout << ans << '\n';
}
 
int32_t main(){
    ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
    //int t; cin >> t;
    //while(t--)
        solve();
    return 0;
}
/*
Sample inp
*/

Measured memory_bytes: 3652
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		if(n % 2 != 0) {
			System.out.println(n / 2 + 1);
		}else {
			System.out.println(n / 2);
		}
		sc.close();
	}
}


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

long long llmin(long long a, long long b)
{
    return a < b ? a : b;
}

int main()
{
    int n;
    cin >> n;
    vector<long long> a(n + 1), maxa(n + 1), suma(n + 1);
    for (int i = 0; i < n + 1; i++)
    {
        cin >> a[i];
    }
    
    suma[n] = a[n];
    for (int i = n - 1; i >= 0; i--)
    {
        suma[i] = a[i] + suma[i + 1];
    }
    maxa[0] = 1;
    for (int i = 0; i < n; i++)
    {
        if(maxa[i] - a[i] <= 9223372036854775807 / 2)maxa[i + 1] = (maxa[i] - a[i]) * 2;
        else maxa[i + 1] = 9223372036854775807;
    }
    
    long long ans = 0;
    for (int i = 0; i < n + 1; i++)
    {
        long long buf = llmin(suma[i], maxa[i]);
        //cout << suma[i] << " " << maxa[i] << " " << buf << endl;
        if(maxa[i] <= 0)
        {
            ans = -1;
            break;
        }
        else if(n == 0 && a[0] == 1){
            ans = 1;
            break;
        }
        else if(a[0] != 0)
        {
            ans = -1;
            break;
        }
        else if(suma[n] > maxa[n])
        {
            ans = -1;
            break;
        }
        
        ans += buf;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 5632
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007

int main() {
  
  int A,B,M;
  cin >> A >> B >> M;

  vector<int> a(A),b(B),ca(A),cb(B);
  for(int i = 0;i < A;i++) {
    cin >> a.at(i);
    ca.at(i) = a.at(i);
  }

  for(int i = 0;i < B;i++) {
    cin >> b.at(i);
    cb.at(i) = b.at(i);
  }

  sort(ca.begin(),ca.end());
  sort(cb.begin(),cb.end());

  int mini = ca.at(0)+cb.at(0);
  for(int i = 0;i < M;i++) {
    int x,y,c;
    cin >> x >> y >> c;
    x--;
    y--;
    int p = max(0,a.at(x)+b.at(y)-c);
    mini = min(p,mini);
  }

  cout << mini << endl;


}


Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <string>
#include <sstream>
#include <cstdlib>
#include <algorithm>

using namespace std;

bool isRunRun(string x)
{
    for(int i = 1; i < x.size(); i++){
        if(abs((x[i-1]-'0') - (x[i]-'0')) > 1){
            return false;
        }
    }
    return true;
}

int main(void)
{
    int k;

    cin >>k;

    vector<string> rrs;
    queue<string> q;

    for(int i = 1; i < 10; i++){
        string x = "";
        x += i+'0';
        q.push(x);
    }

    int ct = 0;
    while(!q.empty()){
        string cr = q.front(); q.pop();
        ct++;
        if(ct == k){
            printf("%s\n", cr.c_str());
            break;
        }
        char lc = cr[cr.size()-1];
        if(lc == '0'){
            q.push(cr+"0");
            q.push(cr+"1");
        }else if(lc == '9'){
            q.push(cr+"8");
            q.push(cr+"9");
        }else{
            for(int i = (lc-'0')-1; i <= (lc-'0')+1; i++){
                string bb = "";
                bb += i+'0';
                q.push(cr+bb);
            }
        }
    }

    return 0;
}

Measured memory_bytes: 13696
#include "bits/stdc++.h"
using namespace std;
#define PIGRECO 3.141592653589793

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c> {i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
	~debug() { cerr << endl; }
	eni( != ) cerr << boolalpha << i; ris;
}
eni( == ) ris << range(begin(i), end(i));
}
sim, class b dor(pair < b, c > d) {
	ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
	*this << "[";
	for (auto it = d.b; it != d.e; ++it)
		*this << ", " + 2 * (it == d.b) << *it;
	ris << "]";
}
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////




int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int n;
	cin >> n;
	string s;
	cin >> s;

	int reddo = 0;

	for (char c : s) {
		if (c == 'R')reddo++;
	}

	int val1 = 0;

	for (int i = 0; i < reddo; i++) {
		if (s[i] != 'R')
			val1++;
	}

	int ans = min(val1, min(n - reddo, reddo));


	cout << ans << endl;







}

Measured memory_bytes: 3796
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
  let stdin = stdin();
  let stdin = stdin.lock();
  let token: String = stdin
    .bytes()
    .map(|c| c.expect("failed to read char") as char)
    .skip_while(|c| c.is_whitespace())
    .take_while(|c| !c.is_whitespace())
    .collect();
  token.parse().ok().expect("failed to parse token")
}

use std::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let a = read::<i64>();
  let b = read::<i64>();
  let c = read::<i64>();
  println!("{}", if b - a == c - b { "YES" } else { "NO" });
}

Measured memory_bytes: 4352
import sys
# input = sys.stdin.buffer.readline
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

H, W = map(int, input().split())
A = [[int(x) for x in input().split()] for _ in range(H)]
B = [[int(x) for x in input().split()] for _ in range(H)]
C = [[0] * W for _ in range(H)]
for i in range(H):
    for j in range(W):
        C[i][j] = abs(A[i][j] - B[i][j])
center = 80 * (H+W) # (80+80)*80=12800

dp = [[0] *W for _ in range(H)]
dp[0][0] = (1 << (center - C[0][0])) | (1 << (center + C[0][0]))
for i in range(H):
    for j in range(W):
        if i:
            dp[i][j] |= dp[i-1][j] << C[i][j]
            dp[i][j] |= dp[i-1][j] >> C[i][j]
        if j:
            dp[i][j] |= dp[i][j-1] << C[i][j]
            dp[i][j] |= dp[i][j-1] >> C[i][j]
ans = center * 2
for i in range(center*2):
    if (dp[H-1][W-1] >> i) & 1:
        ans = min(ans, abs(i-center))
print(ans)

Measured memory_bytes: 60124
#include <iostream>
#include <string.h>
#include <math.h>
using namespace std;

int main() {
  long int n, k;
  cin >> n >> k;
  long int nt = n;
  if(k == 1) nt = 0;
  else{
    nt %= k;
    if(abs(nt-k)<nt) nt = abs(nt-k);
  }
  cout << nt << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fi first
#define se second
using namespace std;

int n, m;
int data[10] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};
bool ch[10] = {0};
// 0:now,1,2:bf
int dp[10010][10010] = {0};

string solve();
int main() {
  cin >> n >> m;
  for(int i = 0; i < m; ++i) {
    int x;
    cin >> x;
    ch[x] = 1;
  }
  cout << solve() << endl;
  return 0;
}

string solve() {
  string ans;
  for(int i = 0; i <= 10000; ++i)
    for(int j = 0; j <= n; ++j)
      if(i + j != 0) dp[i][j] = -1;
  for(int i = 1; i <= 10000; ++i)
    for(int j = 2; j <= n; ++j)
      for(int k = 9; k > 0; --k)
        if(ch[k] && dp[i][j] == -1 && j - data[k] >= 0 &&
           dp[i - 1][j - data[k]] != -1) {
          dp[i][j] = k;
        }
  for(int i = 10000; i >= 0; --i)
    if(dp[i][n] != -1) {
      int now = n;
      for(int j = i; j > 0; --j) {
        ans += '0' + dp[j][now];
        now -= data[dp[j][now]];
      }
      break;
    }
  return ans;
}

Measured memory_bytes: 391424
unittest
{
	assert( [ "3 2", "100 50 200" ].parse.expand.solve == 1 );
	assert( [ "5 8", "50 30 40 10 20" ].parse.expand.solve == 2 );
	assert( [ "10 100", "7 10 4 5 9 3 6 8 2 1" ].parse.expand.solve == 2 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	auto ans = 0L;
	auto d = 0L;
	auto m = long.max;
	foreach( i, a; as )
	{
		if( a < m )
		{
			m = a;
		}
		else
		{
			auto dd = a - m;
			if( d < dd )
			{
				ans = 1;
				d = dd;
			}
			else if( d == dd )
			{
				ans++;
			}
		}
	}
	return ans;
}


Measured memory_bytes: 6836
#include "bits/stdc++.h"
#include "math.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<int> vin;
typedef vector<pair<ll,ll> > vp;
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
const int INF=1e9+7;
int main(){
  int n;
  cin>>n;
  if(n<1000){cout<<"ABC"<<endl;}
  else{cout<<"ABD"<<endl;}
}


Measured memory_bytes: 256
from copy import copy
n=int(input())
a=[0]+list(map(int,input().split()))
ans=[0]*(n+1) 
for i in range(n//2+1,n+1):
    ans[i]=a[i]
for j in reversed(range(1,n//2+1)):
    k=2
    count=0
    j_copy=copy(j)
    a_j=a[j]
    while True:
        count+=ans[k*j_copy]
        k+=1
        if k*j_copy>n:
            break
    if count%2==a_j:
        ans[j]+=0
    else:
        ans[j]+=1
temp=[]
for i in range(1,n+1):
  if ans[i]==1:
    temp.append(str(i))
print(ans.count(1))
print(" ".join(temp))

Measured memory_bytes: 103192
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define MOD (ll)(1e9+7)
#define INF 1e17
#define int ll
#define EPS (1e-6)
using namespace std;
using ll=long long;
using pii=pair<int,int>;

int gcd(int a,int b) { return b==0?a:gcd(b,a%b); }
int lcm(int a,int b) { return a/gcd(a,b)*b; }

int fpow(int b,int p)
{
	if(p==0) return 1;
	int h=fpow(b,p/2);
	if(p%2) return h*b%MOD*h%MOD;
	return h*h%MOD;
}

int32_t main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int in[3];
	cin>>in[0]>>in[1]>>in[2];
	sort(in,in+3);
	if(in[0]-in[1]!=in[1]-in[2]) cout<<"NO\n";
	else cout<<"YES\n";
	return 0;
}





























Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{

        int i,a,b,c,j,g=0,k;

        scanf("%d",&a);

        int s[a];

        for(i=0;i<a;i++){

                scanf("%d",&s[i]);

        }
        //printf("%d\n",s[a-1]);
        b=s[0];

        for(c=1;c<a;c++){

                //printf("%d\n",b);
                if(b<s[c]){

                        b = s[c];
                //      printf("%d\n",b);
        }
        }
        for(j=0;j<a;j++){

                g+=s[j];
                //printf("%d\n",g);
        }

        k=g-b;

        if(b<k){

                printf("Yes\n");

        }
  else if(b>=k){

                printf("No\n");

        }

        return 0;
}
                         

Measured memory_bytes: 128
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        string[] input = Console.ReadLine().Split(' ');
        int n = int.Parse(input[0]);
        int x = int.Parse(input[1]);
        int[] a = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        Array.Sort(a);
        int ans = 0;
        for (int i = 0; i < n - 1; i++)
        {
            if (x >= a[i])
            {
                x -= a[i];
                ans++;
            }
        }
        if (x == a[n - 1])
            ans++;
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <assert.h>
#define ll long long
#define ull unsigned long long
using namespace std;

vector<ll> V;
vector<vector<ll>> DP;
vector<ll> P;

ll getSum(int start, int end){
    return P[end + 1] - P[start];
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    int n;
    cin >> n;
    V = vector<ll>(n);
    DP = vector<vector<ll>>(n, vector<ll>(n, -1));
    P = vector<ll>(n + 1);
    for (auto &v : V) cin >> v;

    for (int i = 1; i <= n; i++){
        P[i] = P[i - 1] + V[i -1];
    }

    for (int i = n - 1; i >= 0; i--){
        for (int j = i; j < n; j++){
            ll &dp = DP[i][j];
            if (i == j){
                dp = 0;
            } else if (j == (i + 1)){
                dp = V[i] + V[j];
            } else {
                dp = INT64_MAX;
                for (int z = i; z < j; z++){
                    dp = min(dp, DP[i][z] + DP[z + 1][j]);
                }
                dp += getSum(i, j);
            }
        }
    }


    cout << DP[0][n - 1];
    return 0;
}

Measured memory_bytes: 1536
#include <algorithm>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <list>

using namespace std;

typedef long long ll;

#define sz size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define all(c) (c).begin(), (c).end()
#define rep(i,a,b) for(ll i=(a);i<(b);++i)
#define clr(a, b) memset((a), (b) ,sizeof(a))
#define ctos(d) string(1,d)
#define print(x) cout<<#x<<" = "<<x<<endl;

#define MOD 1000000007

ll dp[55][3000][55];

int main() {
  ll n,a;
  cin>>n>>a;
  vector<ll> v;
  rep(i,0,n){
    ll b;
    cin>>b;
    v.pb(b);
  }
  clr(dp,0);
  dp[0][0][0] = 1;
  rep(i,1,n+1){
    rep(j,0,2700){
      rep(k,0,52){
        // use
        dp[i][j+v[i-1]][k+1] += dp[i-1][j][k];
        // not use
        dp[i][j][k] += dp[i-1][j][k];
      }
    }
  }
  ll ans = 0;
  rep(i,0,2700){
    rep(j,1,52){
      if(i%j==0&&i/j==a){
        ans += dp[n][i][j];
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 71168
#include "bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define mFOR(i, a, b) for (int i = a; i > b; i--)
#define MP make_pair
#define PB push_back
#define ALL(v) v.begin(), v.end()
#define N 1007
#define INF 1000000007
using namespace std;

typedef long long ll;

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }
ll fceil(ll a, ll b) { return (a % b == 0 ? a / b : a / b + 1); }
double dist(vector<int> y, vector<int> z)
{
   double ret = 0;
   for (int i = 0; i < y.size(); i++)
      ret += (y[i] - z[i]) * (y[i] - z[i]);
   ret = sqrt(ret);
   return ret;
}

int main()
{
   int n, d, ans = 0;
   cin >> n >> d;
   vector<vector<int>> x(n, vector<int>(d, 0));
   for (int i = 0; i < n; i++)
      for (int j = 0; j < d; j++)
         cin >> x[i][j];
   for (int i = 0; i < n; i++)
      for (int j = i + 1; j < n; j++)
      {
         double ds = dist(x[i], x[j]);
         if ((int)ceil(ds) == (int)floor(ds))
            ans++;
      }
   cout << ans << endl;
   return 0;
}


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

public class Main{
	public static void main(String[] args)throws IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split(" ");
		int a = Integer.parseInt(s[0]);
		int b = Integer.parseInt(s[1]);
		if((isGPA(a) && isGPA(b)) || (isGPB(a) && isGPB(b)) || (a == 2 && b == 2)){
			System.out.println("Yes");
		}else{
			System.out.println("No");
		}
	}
	public static boolean isGPA(int num){
		int[] CNT = {1,3,5,7,8,10,12};
		for(int n : CNT){
			if(n == num){
				return true;
			}
		}
		return false;
	}

	public static boolean isGPB(int num){
		int[] CNT = {4,6,9,11};
		for(int n : CNT){
			if(n == num){
				return true;
			}
		}
		return false;
	}
}

Measured memory_bytes: 21460
n, x = map(int, input().split())
Ls = list(map(int, input().split()))

Di = list()
for i in range(n+1):
    if i == 0:
        Di.append(0)
    else:
        Di.append(Di[-1] + Ls[i-1])
    
cnt = 0
for i in range(len(Di)):
    if Di[i] <= x:
        cnt += 1
print(cnt)

Measured memory_bytes: 3064
import itertools as itr

l,r = map(int,input().split())

l_r = l % 2019
r_r = r % 2019
l_q = l // 2019
r_q = r // 2019


if r_q > l_q:
	print(0)
else:

	vals = range(l_r,r_r+1)

	print(min([(a*b)%2019 for a,b in itr.combinations(vals, 2)]))



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

using namespace std;

typedef unsigned long long ull;

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

    unordered_map<string, int> mp;
    vector<string> vec;
    int n;
    cin >> n;
    int maxx = 0;
    for (int i = 0; i < n; i ++) {
        string s;
        cin >> s;
        mp[s] ++;
        if (mp[s] > maxx)
            maxx = mp[s];
        vec.push_back(s);
    }

    set<string> sset;

    for (string s : vec) {
        if (mp[s] == maxx)
            sset.insert(s);
    }
    for (auto s : sset)
        cout << s << endl;


    return 0;
}

Measured memory_bytes: 35512
#[allow(unused_imports)]
use std::{cmp::Reverse, collections::*};

#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Chars, Usize1},
};

#[allow(unused_imports)]
use itertools::Itertools;

#[allow(unused_imports)]
use num::Integer;

#[fastout]
pub fn main() {
    input! {
        n: i32, a: i32, b: i32
    }

    let mut sum = 0;
    for i in 1..=n {
        let mut c = 0;
        let mut tmp = i;
        while tmp > 0 {
            c += tmp % 10;
            tmp /= 10;
        }
        if a <= c && c <= b {
            sum += i;
        }
    }
    println!("{}", sum);
}


Measured memory_bytes: 2176
a = input()
n = len(a)
r = 0
g ,p =0, 0
for i in a:
    if i =="g":
        if g>p:
            r+=1
            p+=1
        else:
            g+=1
    else:
        if g>p:
            p+=1
        else:
            g+=1
            r-=1
print(r)


Measured memory_bytes: 39792
#include<iostream>
using namespace std;
int main(){
    int n,q,S[100000]={},T[100000]={},count=0;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>S[i];
    }
    cin>>q;
    for(int i=0;i<q;i++){
        cin>>T[i];
    }
    for(int i=0;i<q;i++){
        int left=0,right=n;
        while(left<right){
            int mid=(left+right)/2;
            if(S[mid]==T[i]){
                count+=1;
                break;
            }
            else if(T[i]<S[mid]){
                right=mid;
            }
            else{
                left=mid+1;
            }
        }
    }
    cout<<count<<endl;
}



Measured memory_bytes: 3876
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define llower(v,hoge) *lower_bound(v.begin(), v.end(), hoge)
#define lupper(v,hoge) *upper_bound(v.begin(), v.end(), hoge)

const lint MOD = pow(10, 9) + 7;

/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
vector<char>NUM(10);
	NUM = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };
*/


int main() {
	string S;
	cin >> S;
	int cnt = 0;
	rep(i, 4) {
		if (S[i] == '2') {
			cnt++;
		}
	}
	cout << cnt << endl;
}


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

int main(){
  int w, h, x, y, r;

  cin >> w >> h >> x >> y >> r;

  if( (x - r >= 0) &&( x + r <= w) && (y - r >= 0) && (y + r <= h) ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
}



Measured memory_bytes: 3116
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <fstream>
#include <algorithm>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define pb push_back
#define INF 1e11
#define mod 11092019
#define eps 1e-15
#define abs(x) ((x)>=0?(x):-(x))
#define y1 solai
#define fi first
#define se second
typedef long long ll;
typedef long double ldb;
typedef pair<ll,ll> pll;
const ll N=200100;
ll n,m,x,y,a[N],s;
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);

	cin>>n;
	for(ll i=1;i<=n;i++)
		cin>>x,a[x]++,s+=x;
	cin>>m;
	for(ll i=1;i<=m;i++)
	{
		cin>>x>>y;
		s+=(y-x)*a[x];
		a[y]+=a[x];
		a[x]=0;
		cout<<s<<"\n";
	}
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(m);
	rep(i, m) cin >> a[i];

	sort(a.begin(), a.end());
	vector<int> dist(m);
	for (int i = 0; i < m - 1; i++) {
		dist[i] = abs(a[i] - a[i+1]); 
	}
	sort(dist.rbegin(), dist.rend());
	
	int ans = 0;
	for (int i = n - 1; i < m - 1; i++) {

			ans += dist[i];
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define REP(i,b,e) for(int i=(b);i<(e);++i)
#define RREP(i,b,e) for(int i=(b)-1;i>=e;--i)
#define rep(i,e) for(int i=0;i<(e);++i)

constexpr int MOD = 1000000007;
constexpr int INF = 1LL << 30;
constexpr long long LLINF = 1LL << 62;
constexpr double EPS = 1e-9;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15) << boolalpha;
  }
} initializer;

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

template<typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "[";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    if (it != vec.begin()) os << ", ";
    os << *it;
  }
  return os << "]";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &pa) {
  return os << "(" << pa.first << ", " << pa.second << ")";
}

template<typename Tuple, size_t N>
struct TuplePrinter {
  static void print(const Tuple &t) {
    TuplePrinter<Tuple, N-1>::print(t);
    cout << ", " << get<N-1>(t);
  }
};

template<typename Tuple>
struct TuplePrinter<Tuple, 1> {
  static void print(const Tuple &t) {
    cout << get<0>(t);
  }
};

template<typename... T>
ostream &operator<<(ostream &os, const tuple<T...> &tup) {
  os << "(";
  TuplePrinter<decltype(tup), sizeof...(T)>::print(tup);
  return os << ")";
}

template<typename T>
ostream &operator<<(ostream &os, const set<T> &se) {
  os << "{";
  for (auto it = se.begin(); it != se.end(); ++it) {
    if (it != se.begin()) os << ", ";
    os << *it;
  }
  return os << "}";
}

template<typename T, typename U>
ostream &operator<<(ostream &os, const map<T, U> &ma) {
  os << "{";
  for (auto it = ma.begin(); it != ma.end(); ++it) {
    if (it != ma.begin()) os << ", ";
    os << it->first << ": " << it->second;
  }
  return os << "}";
}

inline void print(void) { cout<<'\n'; }
template<class T> inline void print(const T &x) { cout<<x<<'\n'; }
template<class T, class... U> inline void print(const T &x, const U&... y) { cout<<x<<" "; print(y...); }
#define dump(...) cout<<#__VA_ARGS__<<": [L_"<<__LINE__<<"]"<<'\n'; print(__VA_ARGS__);cout<<'\n';

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


int main() {
  long long n; cin>>n;
  vector<long long> a(n);
  rep(i, n) cin>>a[i];
  long long s = 0;
  rep(i, n) s += a[i];
  rep(i, n-1) a[i+1] += a[i];
  long long ans = LLINF;
  rep(i, n-1) {
    long long rem = s - a[i];
    ans = min(ans, abs(a[i]-rem));
  }
  print(ans);

  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;
int main() {
	int n, a[100000], min = 100000001, ans = 0;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if (min > a[i]) {
			min = a[i];
			ans = i + 1;
		}
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

string lcs_backtrack(string a, string b) {
	int l1=a.size();
  	int l2=b.size();

  int dp[l1+1][l2+1];

  for (int i=0;i<=l1;i++)
  {
  	for (int j=0;j<=l2;j++)
  	{
  		if (i==0||j==0) dp[i][j]=0;
	  		else if (a[i-1]==b[j-1]) dp[i][j]=dp[i-1][j-1]+1;
  				else dp[i][j]=max(dp[i][j-1],dp[i-1][j]);
  		}
  	}

  int k=dp[l1][l2];
  string result(k,'\0');

  int i=l1,j=l2;
   while(i>0 && j>0){

		if (a[i-1]==b[j-1])
		{
			k--;
			result[k]=a[i-1];
			i--;
			j--;
		}
		else if (dp[i][j-1]<dp[i-1][j]) i--;
		else j--;
  	}

  return result;
}

int main() {
 
 string a,b;
 cin >> a >> b;
 cout << lcs_backtrack(a, b) ;

} 


Measured memory_bytes: 38800
#include <iostream>
#include <string>
using namespace std;
 
int main(){
  long int A, B, C, K;
  long int result = 0;
  bool finish_flag = false;

  cin >> A >> B >> C >> K;

  if(K <= A){
    result += K;
    K = 0;
    finish_flag = true;
  }
  else{
    result += A;
    K -= A;
  }

  if( ! finish_flag){
    if(K <= B){
      K = 0;
      finish_flag = true;
    }
    else{
      K -= B;
    }
  }  

  if( ! finish_flag){
    result -= K;
    K = 0;
    finish_flag = true;
  }  

  cout << result << endl;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define each(it,v) for(auto it : v)
#define mod 1000000007
#define all(v) (v).begin(),(v).end()
#define vi vector<int>
#define vl vector<long>
#define P pair<int,int>
using namespace std;

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


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

int main() {
    int N;
    cin >> N;
    vector<pair<int, int>> B;
    vector<int> A;

    int prev = -1;
    for (int i = 0; i < N; ++i) {
        int a; cin >> a;
        if (a != prev) {
            B.push_back(make_pair(a, B.size())); // B は index も付け加える
            A.push_back(a);
            prev = a;
        }
    }

    sort(B.begin(), B.end(), greater<pair<int, int>>());
    
    if(A.size() == 1) {
        if(A[0] > 0) cout << 1 << endl;
        else cout << 0 << endl;
    }
    else {
        int res = 1;
        int cur = 0;
        int prev = 0;
        for(int i = 0; i < B.size(); i++) {
            int id = B[i].second;

            if(id == 0) {
                if(A[id] > A[id+1]) cur++;
            }
            else if(id == A.size() -1) {
                if(A[id-1] < A[id]) cur++;
            }
            else {
                if(A[id-1] <= A[id] && A[id] > A[id+1]) cur++;
                else if(A[id-1] > A[id] && A[id] <= A[id+1]) cur--;
            }
            if(i == (int)B.size() - 1 || B[i].first != B[i+1].first) {
                res = max(res, cur);
                prev = B[i].first;
            }
        }
        cout << res << endl;
    }

    
}


Measured memory_bytes: 4564
S = input()

for i in range(len(S)-1):
    a,b = S[i],S[i+1]
    if a == b:
        print(i+1, i+2)
        exit()

for i in range(len(S)-2):
    a,b = S[i],S[i+2]
    if a == b:
        print(i+1, i+3)
        exit()

print(-1, -1)

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

vector<pair<int, int>> ans;

void solve(int N) {
	if (N == 1) {
		cout << "No" << endl;
		return;
	}
	if (N == 2) {
		cout << "No" << endl;
		return;
	}
	if (N >= 3) {
		int P = (N - 3) / 4; P = P * 4 + 3;
		for (int i = 1; i <= P * 2 - 1; i++) {
			int v1 = i, v2 = i + 1;
			if (v1 > P) { v1 -= P; v1 += N; }
			if (v2 > P) { v2 -= P; v2 += N; }
			ans.push_back(make_pair(v1, v2));
		}

		if (N % 4 == 0) {
			bool flag = false;
			for (int i = 0; i < P; i++) {
				int Q = (i^N);
				int v1 = i + 1, v2 = Q;
				if (v1 < v2 && v2 <= P) {
					ans.push_back(make_pair(v1, N)); ans.push_back(make_pair(v2, 2 * N));
					flag = true;
					break;
				}
			}
			if (flag == false) {
				cout << "No" << endl;
				return;
			}
		}
		if (N % 4 == 1) {
			ans.push_back(make_pair(N - 1, N));
			ans.push_back(make_pair(N, N + 1));
			ans.push_back(make_pair(N + 1, 2 * N - 1));
			ans.push_back(make_pair(2 * N - 1, 2 * N));
		}
		if (N % 4 == 2) {
			ans.push_back(make_pair(N - 2, N - 1));
			ans.push_back(make_pair(N - 1, N + 1));
			ans.push_back(make_pair(N + 1, 2 * N - 2));
			ans.push_back(make_pair(2 * N - 2, 2 * N - 1));
			ans.push_back(make_pair(2 * N - 2, 2 * N));
			ans.push_back(make_pair(3, N));
		}
		cout << "Yes" << endl;
		for (int i = 0; i < ans.size(); i++) {
			cout << ans[i].first << " " << ans[i].second << endl;
		}
	}
}

int main() {
	int N;
	cin >> N;
	solve(N);
	return 0;
}

Measured memory_bytes: 4464
//marico el que lo lea
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <stdlib.h>
#include <assert.h>
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;

void fastIO() {
	std::ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
}

#define FOR(i,f,t) for(int i=f; i<(int)t; i++)
#define FORR(i,f,t) for(int i=f; i>(int)t; i--)
#define FORE(i,c) for(auto i = (c).begin(); i != (c).end(); i++)
#define pb push_back
#define all(obj) obj.begin(), obj.end()
#define ms(obj, val) memset(obj, val, sizeof(obj))
#define ms2(obj, val, sz) memset(obj, val, sizeof(obj[0])*sz)

#define fst first
#define snd second

template<typename T, typename U> inline void mnze(T &x, U y) { if(y < x) x = y; }
template<typename T, typename U> inline void mxze(T &x, U y) { if(x < y) x = y; }

void _scan( int &x ) { scanf("%d",&x); }
void _scan( long long &x ) { scanf("%lld",&x); }
void _scan( double &x ) { scanf("%lf",&x); }
void _scan( char &x ) { scanf(" %c",&x); }
void _scan( char *x ) { scanf("%s",x); }
void scan() {}
template<typename T, typename... U>
void scan( T& head, U&... tail ) { _scan(head); scan(tail...);}

template<typename T> void _dbg(const char* sdbg, T h) { cerr<<sdbg<<"="<<h<<"\n"; }
template<typename T, typename... U> void _dbg(const char* sdbg, T h, U... t) {
	while(*sdbg != ',')cerr<<*sdbg++; cerr<<"="<<h<<","; _dbg(sdbg+1, t...);
}

#ifdef LOCAL
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#define debugv(x) {{cerr <<#x <<" = "; FORE(_i, (x)) cerr <<*_i <<", "; cerr <<"\n"; }}
#define debuga(x, sz) {{cerr <<#x <<" = "; FOR(_i, 0, sz) cerr << x[_i] <<", "; cerr <<"\n"; }}
#else
#define debug(...) (__VA_ARGS__)
#define debugv(x)
#define debuga(x, sz)
#define cerr if(0)cout
#endif

///////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////

const int MAXN = 1e5+5;

int N, l[MAXN], r[MAXN], s[MAXN];

priority_queue<ll> L;
priority_queue<ll, vector<ll>, greater<ll>> R;
ll dL, dR, c;

int main(){
	scan(N);
	FOR(i,0,N) scan(l[i], r[i]);
	FOR(i,0,N) s[i] = r[i]-l[i];
	L.push(l[0]); R.push(l[0]);
	FOR(i,1,N){
		dL -= s[i]; dR += s[i-1];
		ll L0 = L.top(), R0 = R.top();
		if(L0+dL < l[i] && l[i] < R0+dR){
			L.push(l[i]-dL); R.push(l[i]-dR);
		}else if(l[i] >= R0+dR){
			R.push(l[i] - dR);
			R.push(l[i] - dR);
			ll nL0 = R0 + dR; R.pop();
			c += l[i] - nL0;
			L.push(nL0-dL);
		}else{
			L.push(l[i] - dL);
			L.push(l[i] - dL);
			ll nR0 = L0 + dL; L.pop();
			c += nR0 - l[i];
			R.push(nR0-dR);
		}
	}
	printf("%lld\n", c);
}

Measured memory_bytes: 3188