akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>

using namespace std;

int main() {
	int N;
	string S;
	cin >> N >> S;
	long long r = 0, g = 0, b = 0;
	for (int i = 0; i < N; i++) {
		if (S[i] == 'R') {
			r++;
		}
		else if (S[i] == 'G') {
			g++;
		}
		else if (S[i] == 'B') {
			b++;
		}
	}
	long long ans = r * g * b;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; 2 * j - i < N; j++) {
			int k = 2 * j - i;
			if (k < N) {
				if (S[i] != S[j] && S[j] != S[k] && S[k] != S[i]) {
					ans--;
					//cout << i << " " << j << " " << S[k] << endl;
				}
			}
		}
	}
	cout << ans << endl;
	return 0;
}


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

int main(){
  string S; cin>>S;
  for(int i=0;i<3;i++){
    if(S[i]=='1')
      cout<<'9';
    else if(S[i]=='9')
      cout<<'1';
    else
      cout<<S[i];
  }
  cout<<endl;
}

Measured memory_bytes: 256
from collections import deque

n,q=map(int,input().split())

g=[[] for _ in range(n)]
for i in range(n-1):
    a,b=map(int,input().split())
    g[a-1].append(b-1)
    g[b-1].append(a-1)



c=[0]*n

for j in range(q):
    p,x=map(int,input().split())
    c[p-1]+=x

used=[0]*n
used[0]=1
next=deque([0])

while next:
    v=next.popleft()
    cost=c[v]
    for nv in g[v]:
        if used[nv]:
            continue
        used[nv]=1
        next.append(nv)
        c[nv]+=cost

print(*c)
    

Measured memory_bytes: 105364
#include<stdio.h>
#include <sysexits.h>
#include<stdlib.h>
#include<math.h>
int main(void){
  int a,N,sum,i,L;
  if(scanf("%d %d",&N,&L)>2){
    exit(0);
  }
   sum=0;
   if(L<0 && (L+N-1)>0){
     a=0;
   }
   else if(abs(L)>abs(L+N-1)){
     a=L+N-1;
   }
   else{
     a=L;
   }
  for(i=0;i<N;i++){
      sum = sum +L+i;
  }
  sum=sum-a;
  printf("%d",sum);
  return 0;
}




Measured memory_bytes: 128
/*
 *      ┌─┐       ┌─┐ + +
 *   ┌──┘ ┴───────┘ ┴──┐++
 *   │                 │
 *   │       ───       │++ + + +
 *   ███████───███████ │+
 *   │                 │+
 *   │       ─┴─       │
 *   │                 │
 *   └───┐         ┌───┘
 *       │         │
 *       │         │   + +
 *       │         │       Code is far away from bug with the animal protecting
 *       │         └──────────────┐
 *       │                        │
 *       │                        ├─┐
 *       │                        ┌─┘
 *       │                        │
 *       └─┐  ┐  ┌───────┬──┐  ┌──┘  + + + +
 *         │ ─┤ ─┤       │ ─┤ ─┤
 *         └──┴──┘       └──┴──┘  + + + +
 *                神兽保佑
 *               代码无BUG!
 */

#include<bits/stdc++.h>
using namespace std;
class IN{
public:
    template<typename T>
    IN& operator >>(T &x){read(x);return *this;}
    IN& operator >>(double &x){scanf("%lf",&x);return *this;}
    IN& operator >>(char *s){scanf("%s",s);return *this;}
    IN& operator >>(char &c){c=getchar();return *this;}
private:
    template<typename T>
    void read(T &x){
        T f=1;int c=getchar();x=0;
        while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
        while(c>='0'&&c<='9')x=(x<<3)+(x<<1)+(c^48),c=getchar();
        x*=f;
    }
}in;
class NL{}nl;
class BK{}bk;
class OUT{
public:
    template<typename T>
    OUT& operator <<(T x){write(x);return *this;}
    OUT& operator <<(const char *s){printf("%s",s);return *this;}
    OUT& operator <<(char c){putchar(c);return *this;}
    OUT& operator <<(BK x){putchar(' ');return *this;}
    OUT& operator <<(NL x){putchar('\n');return *this;}
private:
    template<typename T>
    void write(T x){
        if(x<0)putchar('-'),x=-x;
        if(x>=10)write(x/10);
        putchar(x%10+48);
    }
}out;

#define pb(x) push_back(x)
#define fi first
#define se second
#define rep(i,a,n) for(int i=a;i<=n;++i)
#define per(i,n,a) for(int i=n;i>=a;--i)
#define mem(a,x) memset(a,x,sizeof(a))
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;
/*****************************************************************************************************/
ll Pow(ll a,ll b,ll mod){ll res=1;a%=mod;while(b){if(b&1)(res*=a)%=mod;(a*=a)%=mod;b>>=1;}return res%mod;}
ll inv(ll a,ll p){if(a==1)return 1;return (p-p/a)*inv(p%a,p)%p;}//p为素数,a<p
ll C(ll n,ll m,ll p){ll res=1;for(ll i=1,j=n-m+1;i<=m;++i,++j){res=res*inv(i,p)%p*j%p;}return res;}
/*****************************************************************************************************/
/*ll ask(int x){ll res=0;while(x)res+=c[x],x-=x&-x;return res;}
void add(ll v,int x){while(x<=n)c[x]+=v,x+=x&-x;}*/
const ll p=998244353;
const int N=3000+10;
int a[N];
ll dp[N][N];

int main(){
    int n,s;
    in>>n>>s;
    rep(i,1,n)in>>a[i];
    rep(i,1,n)rep(j,1,s){
        dp[i][j]=dp[i-1][j];
        if(j>a[i])
            dp[i][j]=(dp[i][j]+dp[i-1][j-a[i]])%p;
        if(j==a[i])
            dp[i][j]=(dp[i][j]+i)%p;
    }
    ll ans=0;
    rep(i,1,n)
        ans=(ans+dp[i][s])%p;
    out<<ans;
    return 0;
}


Measured memory_bytes: 70784
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        c: [[i32; 3]; 3],
    };
    let b = c[0].clone();
    let a = c.iter().map(|v| v[0] - b[0]).collect::<Vec<_>>();
    for i in 0..3{
        for j in 0..3{
            if a[i] + b[j] != c[i][j]{
                println!("No");
                return;
            }
        }
    }
    println!("Yes");
}


Measured memory_bytes: 4352
#include <stdio.h>

#define  DEBT  100000

int main(void){
	int week,i,debt;
	
	debt = DEBT;
	
	scanf("%d", &week);
	
	for(i = 1; i <= week; i++){
		debt *= 1.05;
		
		if(debt % 1000 != 0){
			debt /= 1000;
			debt += 1;
			debt *= 1000;
		}
	}
	
	printf("%d\n", debt);
	
	return 0;
}

Measured memory_bytes: 592
#include<iostream>
#include<algorithm>
#include<vector>
#define LL long long
LL N;
LL S;
std::vector<LL> A;
std::vector<LL> B;
int main(){
    std::cin>>N;
    for(int i=0;i<N;i++){
        LL tmp;
        std::cin>>tmp;
        A.emplace_back(tmp);
        S+=tmp;
    }
    LL K=N*(N+1)/2;
    if(S%K){
        std::cout<<"NO"<<std::endl;
        return 0;
    }
    S/=K;
    for(int i=0;i<N;i++){
        B.emplace_back(A[(i+1)%N]-A[i]);
    }
    LL r=0;
    for(int i=0;i<N;i++){
        if(std::llabs(B[i]-S)%N){
            std::cout<<"NO"<<std::endl;
            return 0;
        }
        r+=std::llabs(B[i]-S)/N;
    }
    if(r==S)std::cout<<"YES"<<std::endl;
    else std::cout<<"NO"<<std::endl;
    return 0;
}

Measured memory_bytes: 2548
#include <iostream>

int main(){
  int r, g, b;
  std::cin >> r >> g >> b;
  int sum = 100*r+10*g+b;
  if (sum%4==0)
    std::cout << "YES" << std::endl;
  else
    std::cout << "NO" << std::endl;
  
  return 0;
}

Measured memory_bytes: 3576
#include<iostream>
using namespace std;
int main(){
    int n;
    string s;
    cin>>n;
    int a=0,b=0,c=0,d=0;
    for(int i=0;i<n;i++){
        cin>>s;
        if(s=="AC") a++;
        else if(s=="WA") b++;
        else if(s=="TLE") c++;
        else d++;
    }
    cout<<"AC x "<<a<<endl;
    cout<<"WA x "<<b<<endl;
    cout<<"TLE x "<<c<<endl;
    cout<<"RE x "<<d<<endl;
}


Measured memory_bytes: 3596
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

static const int MAX_NUM = 10000;
enum eState {
    NO_VISIT = 0,
    NOW_VISIT,
    END_VISIT
};

void SSSP(vector<pair<int, int> > matrix[], int num)
{
    int i;
    int cost[MAX_NUM];
    eState state[MAX_NUM] = {NO_VISIT};
    priority_queue<pair<int, int>, vector<pair<int, int> >, greater<pair<int, int> > > PQ;

    for (i = 0; i < num; i++) {
        cost[i] = 100000 * MAX_NUM;
    }

    PQ.push(make_pair(0, 0));
    cost[0]  = 0;
    state[0] = NOW_VISIT;

    while (PQ.empty() == false) {
        int tid;
        int nid, ncost;
        pair<int, int> target = PQ.top();
        PQ.pop();

        tid = target.second;
        state[tid] = END_VISIT;

#if 0
        if (cost[tid] < target.second) {
            continue;
        }
#endif

        for (i = 0; i < matrix[tid].size(); i++) {
            nid   = matrix[tid][i].second;
            ncost = matrix[tid][i].first;
            if ((state[nid] != END_VISIT) && (cost[nid] > (ncost + cost[tid]))) {
                cost[nid]  = ncost + cost[tid];
                state[nid] = NOW_VISIT;
                PQ.push(make_pair(cost[nid], nid));
            }
        }
    }

    for (i = 0; i < num; i++) {
        printf("%d %d\n", i, cost[i]);
    }

    return;
}

int main(void)
{
    int i, j;
    int num;
    int target, pathnum;
    int path, cost;
    vector<pair<int, int> > matrix[MAX_NUM];

    scanf("%d", &num);
    for (i = 0; i < num; i++) {
        scanf("%d %d", &target, &pathnum);
        for (j = 0; j < pathnum; j++) {
            scanf("%d %d", &path, &cost);
            matrix[target].push_back(make_pair(cost, path));
        }
    }

    SSSP(matrix, num);

    return 0;
}

Measured memory_bytes: 6320
#include <bits/stdc++.h>
using namespace std;
#define all(V) V.begin(),V.end()
#define ll long long
const ll MOD = 1000000007;

complex<double> P[51], Q[51];
int N;

double F(double X) {
	complex<double> A = { X,0 };
	double mf = 0;
	for (int i = 0;i < N;i++) {
		mf = max(mf, abs(Q[i] - A));
	}
	return mf;
}

int main() {
	cin >> N;
	double x, y;
	for (int i = 0;i < N;i++) {
		cin >> x >> y;
		P[i] = { x,y };
	}
	double big, small, id, jd, l, r, l3, r3;
	complex<double> M, me;

	vector<double> ans;

	for (int i = 0;i < N;i++) {
		for (int j = i + 1;j < N;j++) {
			M = (P[i] + P[j]) / 2.0;
			me = complex<double>(0, 1) * (P[i] - P[j]) / abs(P[i] - P[j]);
			for (int k = 0;k < N;k++) {
				Q[k] = (P[k] - M) / me;
			}
			l = -4000, r = 4000;
			
			for (int a = 0;a < 100;a++) {
				l3 = (l * 2 + r) / 3;
				r3 = (l + r * 2) / 3;
				if (F(l3) > F(r3)) {
					l = l3;
				}
				else {
					r = r3;
				}
			}

			ans.push_back(F(l3));
		}
	}
	sort(all(ans));
	printf("%.10f\n", ans[0]);
}

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

#define INF_LL (int64)1e18
#define INF (int32)1e9
#define REP(i, n) for(int64 i = 0;i < (n);i++)
#define FOR(i, a, b) for(int64 i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
#define fs first
#define sc second

using int32 = int_fast32_t;
using uint32 = uint_fast32_t;
using int64 = int_fast64_t;
using uint64 = uint_fast64_t;
using PII = pair<int32, int32>;
using PLL = pair<int64, int64>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

template<typename T>
vector<T> make_v(size_t a){return vector<T>(a);}

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

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

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

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int64 N;
	while (cin >> N && N) {
		vector<char> v(N);
		map<char, int64> mp;
		bool ok = 0;
		REP(i, N) {
			cin >> v[i];
		}
		mp['.'] = 0;
		REP(i, N) {
			mp[v[i]]++;
			vector<pair<int64, char>> vv;
			for (auto x : mp) {
				vv.emplace_back(x.sc, x.fs);
			}
			sort(all(vv), greater<pair<int64, char>>());
			if (vv[0].fs-vv[1].fs > N-i-1) {
				ok = 1;
				cout << vv[0].sc << " " << i+1 << endl;
				break;
			}
		}
		if (!ok) {
			cout << "TIE" << endl;
		}
	}
}



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

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

    cout << a[n - 1] - a[0] << endl;

    return 0;
}

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

int main(){
	int n ; cin >> n ;
	vector<int> a(n) ;
	for(int i=0;i<n;i++) cin >> a.at(i) ;
	vector<int> sub = a ;
	sort(sub.begin(),sub.end()) ;
	for(int i=0;i<n;i++){
		if(a.at(i)==sub.at(n-1)) cout << sub.at(n-2) << endl ;
		else  cout << sub.at(n-1) << endl ;
	}
}

Measured memory_bytes: 3200
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
ll GetDigit(ll num){ return log10(num)+1; } //numの桁数を求める

int main()
{
    string s;
    cin >> s;
    if(s == "ARC") cout << "ABC" << endl;
    else cout << "ARC" << endl;
    return 0;
}

Measured memory_bytes: 3584
#include <iostream>
#include <string>
#include <vector>
#include <utility>
using ll=long long;
using namespace std;

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

    vector<int> P(N);
    vector<ll> C(N);
    for(int i=0;i<N;i++){
        cin>>P[i];
        P[i]--;
    }
    for(int i=0;i<N;i++){
        cin>>C[i];
    }

    ll ans=C[0];
    int masu;
    for(int i=0;i<N;i++){
        vector<vector<ll>> used(N,vector<ll>(3,0));
        masu=i;
        used[masu][0]=1;
        used[masu][1]=0;
        used[masu][2]=0;
        ll tmp=0;
        int amari=0;
        for(int j=1;j<=K;j++){
            masu=P[masu];
            if(used[masu][0]){
                tmp+=C[masu];
                int nokori=K-j;
                int loop=j-used[masu][1];
                ll loopscore=tmp-used[masu][2];
                amari=nokori%loop;
                if(nokori/loop>=1){
                    nokori-=loop;
                    amari+=loop;
                }
                //cout<<nokori<<" "<<loop<<" "<<loopscore<<" "<<amari<<endl;
                if(loopscore>0 && loop!=0){
                    tmp+=(nokori/loop)*loopscore;
                }
                if(tmp>ans){
                    ans=tmp;
                }
                //cout<<"tmp:"<<tmp<<endl;
                break;
            }else{
                used[masu][0]=1;
                used[masu][1]=j;
                used[masu][2]=tmp;
                tmp+=C[masu];
                if(ans<tmp){
                    ans=tmp;
                }
            }  
        }
        for(int j=0;j<amari;j++){
            masu=P[masu];
            tmp+=C[masu];
            if(ans<tmp){
                ans=tmp;
            }
        }
        //cout<<tmp<<endl;
    }
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 3928
const lines: string[] = [];
const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});
reader.on("line", function (line: string) {
  lines.push(line);
});

reader.on("close", function () {
  const rule = lines.shift().split(" ").map(Number);
  const one = rule[0];
  const zero = rule[1];
  const minus = rule[2];
  let num = rule[3];

  let res = 0;
  num = num - one;

  if (num <= 0) {
    console.log(rule[3]);
    return;
  }

  num -= zero;
  if (num <= 0) {
    console.log(one);
    return;
  }

  console.log(one - num);
});


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

using namespace std;

const long long MOD = 1000000007LL;
long long GCD(long long a, long long b){return b == 0 ? a : GCD(b, a % b);}
long long fast_exp(long long base, long long exp, long long mod = MOD) {
    long long tot = 1;
    for(;exp > 0;exp >>= 1) {
       if((exp & 1) == 1) tot = tot * base % mod;
       base = base * base % mod;
    }
    return tot;
}

int freq[100005], rem[100005];
vector<int> nums[100005];

int main(){

    cin.sync_with_stdio(0); cin.tie(0); cout.tie(0);

    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, m, a; cin >> n >> m;

    // greedy match between the two

    for(int i = 0; i < n; ++i){
        cin >> a;
        if(freq[a] == 0){
            nums[a % m].push_back(a);
        }
        ++freq[a]; ++rem[a % m];
    }

    long long tot = rem[0] / 2;

    if(m % 2 == 0)
        tot += rem[m / 2] / 2;

    for(int i = 1; i + i < m; ++i){
        int a = i, b = m - i;
        if(rem[a] < rem[b]){
            int sw = a;
            a = b; b = sw;
        }
        for(int j : nums[a]){
            if(rem[a] - 2 < rem[b]) break;
            while(rem[a] - 2 >= rem[b] && freq[j] > 1){
                freq[j] -= 2;
                ++tot;
                rem[a] -= 2;
            }
        }
        tot += min(rem[a], rem[b]);
    }

    cout << tot << "\n";

    return 0;

}


Measured memory_bytes: 6528
n = int(input())

initial = 1+2+4+7+8+11+13+14

max_per = int((n+1)//15)

ans = 0

ans+= (max_per*initial + 8*15*(max_per-1)*max_per/2)


left = n - 15*max_per

if left<=0:
    print(int(ans))
else:
    for i in range(left):
        cand = 15*max_per + i+1
        if (cand%3!=0) & (cand%5!=0):
            ans+= cand
    print(int(ans))
    

            

    



Measured memory_bytes: 9188
package main

import "fmt"

func main(){
	var r, g, b int

	fmt.Scanf("%d %d %d", &r, &g, &b)

	amari := (10 * g + b) % 4

	if(amari == 0) {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>

using namespace std;


int main() {
	map<int, int> mp;
	long long int n, a[100007], b[100007], c[100007], dp[100007][5] = {};
	string str, str2[5000];
	cin >> n;

	
	for (int i = 1; i <= n; i++) {
		cin >> a[i]>>b[i]>>c[i];
	}

	for (int i = 1; i <= n; i++) {
		dp[i + 1][0] = max(dp[i][1] + a[i ], dp[i][2] + a[i]);
		dp[i + 1][1] = max(dp[i][0] + b[i ], dp[i][2] + b[i]);
		dp[i + 1][2] = max(dp[i][0] + c[i ], dp[i][1] + c[i]);
	}
	cout << max(max(dp[n + 1][0], dp[n + 1][1]), dp[n + 1][2]);
}

Measured memory_bytes: 6528
//コイン問題/動的計画法
#include <iostream>
#include <algorithm>

using namespace std;

static const int NMAX = 50000;
static const int MMAX = 20;
static const int INF = (1 << 29);

int main(){
	int n,m;//支払額,コイン枚数
	cin >> n >> m;

	int c[MMAX+1];//コイン金額リスト
	for (int i = 1; i <= m; ++i){
		cin >> c[i];
	}
	int t[NMAX+1];//
	for (int i = 0; i <= NMAX; ++i){
		t[i] = INF;
	}
	t[0] = 0;
	for (int i = 1; i <= m; ++i){
		for (int j = 0; j + c[i] <= n; ++j){
			t[j + c[i]] = min(t[j + c[i]], t[j] + 1);
		}
	}

	cout << t[n] << endl;
	
	return 0;
}

Measured memory_bytes: 1356
#include <stdio.h>

int que[1000000],l,r;

void push(int x) {
  que[r]=x;
  r++;
  if(r>=1000000) r=0;
}

int pop() {
  int d=que[l];
  l++;
  if(l>=1000000) l=0;
  return d;
}

int main() {
  l=0,r=0;
  int n,q,i;
  scanf("%d%d",&n,&q);
  char ch[n][10];
  int c[n];
  for(i=0; i<n; i++) {
    scanf("%s %d",ch[i],&c[i]);
    push(i);
  }
  int sum=0;
  while(l!=r) {
    int x=pop();
    if(q<c[x]) {
      sum+=q;
      c[x]-=q;
      push(x);
    } else {
      sum+=c[x];
      printf("%s %d\n",ch[x],sum);
    }
  }
  return 0;
}



Measured memory_bytes: 3176
fun main() {
    val len = Integer.parseInt(readLine())
    val arr:Array<String?> = arrayOfNulls(len)
    for (i in 0 until len){
        arr[i] = readLine()
    }
    var ac = 0
    var wa = 0
    var tle = 0
    var re = 0
    for (i in arr) {
        when {
            i == "AC" -> ac++
            i == "WA" -> wa++
            i == "TLE" -> tle++
            i == "RE" -> re++
        }
    }
    println("AC x ${ac}\nWA x ${wa}\nTLE x ${tle}\nRE x ${re}")
}

Measured memory_bytes: 59248
#include<stdio.h>

#include<iostream>

#include<vector>

#include<math.h>

#include<queue>

#include<map>

#include<algorithm>

#include<string.h>

#include<functional>

#include<limits.h>

#include<stdlib.h>

#include<string>

#include<unordered_map>

#include<set>

using namespace std;



#define intmax INT_MAX

#define lmax LONG_MAX

#define uintmax UINT_MAX

#define ulmax ULONG_MAX

#define llmax LLONG_MAX

#define ll long long

#define rep(i,a,N) for((i)=(a);(i)<(N);(i)++)

#define rrp(i,N,a) for((i)=(N)-1;(i)>=(a);(i)--)

#define llfor ll i,j,k

#define sc(a) cin>>a

#define pr(a) cout<<a<<endl

#define pY puts("YES")

#define pN puts("NO")

#define py puts("Yes")

#define pn puts("No")

#define pnn printf("\n")

#define sort(a) sort(a.begin(),a.end())

#define push(a,b) (a).push_back(b)

#define llvec vector<vector<ll>>

#define charvec vector<vector<char>>

#define sizeoof(a,b) (a,vector<ll>(b))

#define llpvec vector<pair<ll,ll>>

/*繰り上げ除算*/ll cei(ll x,ll y){ll ans=x/y;if(x%y!=0)ans++;return ans;}

/*最大公約数*/ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

/*最小公倍数*/ll lcm(ll x,ll y){return x/gcd(x,y)*y;}

/*n乗*/ll llpow(ll x,ll n){ll i,ans=1;rep(i,0,n)ans*=x;return ans;}

/*階乗*/ll fact(ll x){ll i,ans=1;rep(i,0,x)ans*=(x-i);return ans;}

/*nCr*/ll ncr(ll n,ll r){return fact(n)/fact(r)/fact(n-r);}

/*nPr*/ll npr(ll n,ll r){return fact(n)/fact(n-r);}

/*primejudge*/bool prime(ll a){if(a<=1)return false;ll i;for(i=2;i*i<=a;i++){if(a%i==0)return false;}return true;}

llfor;///////////////////////////////////////////////////////////

int main(){

 ll n,k;

 sc(n);sc(k);

 if(n>=2*k-1)pY;
 else pN;





return 0;}

Measured memory_bytes: 3632
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iostream>
#include <iostream>
#include <fstream>
#include <numeric>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <cmath>
#include <set>
#include <map>
#include <functional>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <cstdint>
#include <chrono>

using namespace std;
#define     loop(n,i,a)     for(ll i=a;i<n;i++)
#define     loopR(n,i,a)    for(ll i=a-1;i>=n;i--)
#define     all(arr,n)      arr,arr+n
#define     allv(v)         (v).begin(),(v).end()
#define     rallv(v)        (v).rbegin(),(v).rend()
#define     m_p             make_pair
#define     ll              long long
#define     pii             pair<ll,ll>
#define     vi              vector<int>
#define     vll             vector<ll>
#define     vii             vector<pii>
#define     sz(x)           (int)x.size()
#define     pb              push_back
#define     endl            "\n"
#define     Endl            "\n"
#define     f               first
#define     s               second
#define     mem(dp,n)       memset(dp,n,sizeof dp)
template<typename T>void max_self(T &a,T b){a=max(a,b);}
template<typename T>void min_self(T &a,T b){a=min(a,b);}
int dx[] = { 1 , 0 ,-1 , 0 ,-1 ,-1 , 1 , 1 };
int dy[] = { 0 , 1 , 0 ,-1 ,-1 , 1 ,-1 , 1 };
int KnightI[] = { 2, 1, -1, -2, -2, -1, 1, 2 };
int KnightJ[] = { 1, 2, 2, 1, -1, -2, -2, -1 };
void fast(){
    std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
vector<string> vec_splitter(string s) {
    s += ',';
    vector<string> res;
    while(!s.empty()) {
        res.push_back(s.substr(0, s.find(',')));
        s = s.substr(s.find(',') + 1);
    }
    return res;
}
void debug_out(
        vector<string> __attribute__ ((unused)) args,
        __attribute__ ((unused)) int idx,
        __attribute__ ((unused)) int LINE_NUM) { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(vector<string> args, int idx, int LINE_NUM, Head H, Tail... T) {
    if(idx > 0) cerr << ", "; else cerr << "Line(" << LINE_NUM << ") ";
    stringstream ss; ss << H;
    cerr << args[idx] << " = " << ss.str();
    debug_out(args, idx + 1, LINE_NUM, T...);
}
#define debug(...) debug_out(vec_splitter(#__VA_ARGS__), 0, __LINE__, __VA_ARGS__)
const ll mxN=4e5+10,oo=0x3f3f3f3f,MOD=1e9+7;
const long double PI = acos(-1),eps=1.0e-14;

void solve(){
    string s;
    cin>>s;
    int ch1=0,ch2=0,col=0;
    loop(sz(s),i,0){
        if(s[i]-'0'!=col)
            ch1++;
        col=1-col;
    }
    col=1;
    loop(sz(s),i,0){
        if(s[i]-'0'!=col)
            ch2++;
        col=1-col;
    }
    cout<<min(ch1,ch2)<<endl;
}
int main() {
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
    fast();
    solve();

}


Measured memory_bytes: 3792
N = int(input())
A = [int(a) for a in input().split()]
B = [int(b) for b in input().split()]
Over = []
Minus = 0
Change = 0
for i in range(N):
    if A[i] >= B[i]: Over.append(A[i]-B[i])
    else:
        Minus += B[i] - A[i]
        Change += 1
if Minus == 0: print(0)
else:
    Over.sort(reverse = True)
    for o in Over:
        if Minus >= o:
            Minus -= o
        else: Minus = 0
        Change += 1
        if Minus == 0: break
    if Minus > 0: print(-1)
    else: print(Change)

Measured memory_bytes: 20084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
#include <bitset>
using namespace std;
typedef long long ll;
int main(){
  ll a,b;
  cin >> a >> b;
  cout << max({a + b,a - b,a * b}) << endl; 
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
maxtall = a[0]
ans = 0
for i in range(1,n):
  if a[i]<maxtall:
    ans += maxtall-a[i]
  else:
    maxtall = max(maxtall,a[i])
    
print(ans)

Measured memory_bytes: 32364
#include<iostream>
#include <stdio.h>
#include <string.h>
#include <string>

using namespace std;
int main()
{
	int a = 0;
        int i = 0;
        int j = 0;

	char A[27];
	cin >> A;

	int  len;
	len = strlen(A);

	for (i = 0; i <= len - 2; i++) {
		for (j = i + 1; j <= len - 1; j++) {
			if (A[i] == A[j]){ 
                                            a = 1;
	       }	
           }
	}

	if (a == 1)
		cout << "no";
	else
		cout << "yes";

	cin >> A;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#include <iomanip>
#define vll vector<ll>
#define vvv vector<vvl>
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvvl(a, b, c, d) vector<vvl>(a, vvl(b, vll (c, d)));
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
#define all(obj) (obj).begin(), (obj).end()
typedef int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll n;std::cin >> n;
  vll a(n), b(n);
  re(i, n) std::cin >> a[i];
  re(i, n) std::cin >> b[i];
  vvl dp = vv((1<<n), n+1, 250, ll);
  dp[0][n] = 0;
  re(s, n+1){
    int comb = (1<<s)-1;
    while(comb < (1 << n)){
      int i = comb;
      bitset<18> B(i);
      ll c = 0;
      re(j, n) if(B[j]) c++;
      re(j, n){
        if(B[j]) continue;
        ll tmp = (abs(c-j)%2?b[j]:a[j]);
        ll cost = 0;
        re(k, n) if(!B[k]&&k<j) cost++;
        if(s==0){
          dp[1<<j][j] = min(dp[1<<j][j], dp[0][n]+cost);
        }else{
          re(k, n){
            if(!B[k]) continue;
            ll num = (abs(c-1-k)%2?b[k]:a[k]);
            //std::cout << c << " " << j << " " << k << " " << tmp << " " << num << '\n';
            if(num>tmp||dp[i][k]==250) continue;
            dp[i|(1<<j)][j] = min(dp[i|(1<<j)][j], (ll)(dp[i][k]+cost));
          }
        }
        //std::cout << B << " " << j << " " << dp[(i|(1<<j))][j] << '\n';
      }
      if(s==0) break;
      int x = comb & -comb, y = comb + x;
      comb = ((comb & ~y) / x >> 1) | y;
    }
  }
  ll ans = 250;
  re(i, n) ans = min(ans, dp[(1<<n)-1][i]);
  std::cout << (ans==250?-1:ans) << '\n';
  return 0;
}


Measured memory_bytes: 30976
a = int(input())
b = int(input())
c = int(input())
x = int(input())
n = 0
for i in range(0,a+1):
    if i*500>x:
        continue
    for j in range(0,b+1):
        if i*500+j*100>x:
            continue
        for k in range(0,c+1):
            if i*500+j*100+k*50>x:
                continue
            if i*500+j*100+k*50==x:
                n+=1
print(n)

Measured memory_bytes: 40432
# include <bits/stdc++.h>
# define rep(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
# define reps(i, n) for(int i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(int i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(int i=((int)(n)); i>0; --i)
# define range_for(i, b, e) for(int i=(b), i##_len=(e); i<=i##_len; ++i)
# define ALL(x) (x).begin(), (x).end()
# define RALL(x) (x).rbegin(), (x).rend()
# define pb push_back
# define len(x) ((int)(x).size())
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define debug(x) std::cerr<<#x<<": "<<(x)<<endl;
# define LINT_MAX (LONG_LONG_MAX)
# define cauto const auto
using namespace std;
using lint = long long;
template <class Type> inline constexpr bool InRange(const Type& x, const Type& i, const Type& a) { return (i <= x) && (x <= a); }
template<class Integer>bool chmax(Integer &a, const Integer &b) { if (a<b) { a=b; return 1; } return 0; }
template<class Integer>bool chmin(Integer &a, const Integer &b) { if (b<a) { a=b; return 1; } return 0; }
template<class Integer>bool IsOdd(Integer &n) { return n & 1; }
template<class Integer>bool IsEven(Integer &n) { return !(n & 1); }
int ctoi(const char c) { return ('0' <= c && c <= '9') ? (c - '0') : -1; }
string YesNo(bool b) { return b ? "Yes" : "No"; }
string YESNO(bool b) { return b ? "YES" : "NO"; }
string yesno(bool b) { return b ? "yes" : "no"; }
int dy[4] = {0, 1, 0, -1};
int dx[4] = {1, 0, -1, 0};

// 整数の桁数を返す ( log(N) )
template <class Integer> Integer GetDigit(Integer n) {
    if (n == 0) return 1;
    Integer d = 0;
    while (n) {
        n /= 10;
        d++;
    }
    return d;
}

// 素数かどうかを返す ( O(sqrt(N)) )
template <class Integer>
constexpr bool IsPrime(const Integer n) noexcept {
    if (n < 4) return n == 2 || n == 3;
    if (n % 2 == 0 || n % 3 == 0 || (n % 6 != 1 && n % 6 != 5)) return false;
    for (Integer i = 5; i * i <= n; i += 6) if (n % i == 0 || n % (i + 2) == 0) return false;
    return true;
}


int main()
{
    int N, M; cin >> N >> M;
    int sum = 0;
    rep (i, M)
    {
        int a; cin >> a;
        sum += a;
    }

    cout << max(-1, N - sum) << endl;

    return 0;
}



Measured memory_bytes: 3636
#include<bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>
// #include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define ld long double
#define mk make_pair
#define fi first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define tihs if(fopen("inp.txt","r"))freopen("inp.txt", "r", stdin),freopen("out.txt", "w", stdout);
using namespace std;
#define TRACE
 
#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif
 
#define M 100010


int main(){
	IOS;
	tihs;
	ll a[3];
	rep(i,0,3)cin>>a[i];
	sort(a,a+3);
	if(a[0]==a[1] and a[2]>a[1])cout<<"Yes";
	else if(a[0]<a[1] and a[1]==a[2])cout<<"Yes";
	else cout<<"No";






	return 0;
}

Measured memory_bytes: 256
//Utkarsh.25dec
#include <bits/stdc++.h>
#include <chrono>
#include <random>
#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define rep(i,n) for(ll i=0;i<n;i++)
#define loop(i,a,b) for(ll i=a;i<=b;i++)
#define vi vector <int>
#define vs vector <string>
#define vc vector <char>
#define vl vector <ll>
#define all(c) (c).begin(),(c).end()
#define max3(a,b,c) max(max(a,b),c)
#define min3(a,b,c) min(min(a,b),c)
#define deb(x) cerr<<#x<<' '<<'='<<' '<<x<<'\n'
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
// ordered_set s ; s.order_of_key(val)  no. of elements strictly less than val
// s.find_by_order(i)  itertor to ith element (0 indexed)
typedef vector<vector<ll>> matrix;
ll power(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll modInverse(ll a){return power(a,mod-2);}
const int N=500023;
bool vis[N];
vector <int> adj[N];
void solve()
{
    ll x;
    cin>>x;
    ll div=x/200;
    cout<<10-div<<'\n';
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int T=1;
    //cin>>T;
    int t=0;
    while(t++<T)
    {
        //cout<<"Case #"<<t<<":"<<' ';
        solve();
        //cout<<'\n';
    }
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 15472
import java.util.*;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String str = "";
    for(int i = 0; i < n; i++){
      str += "00";
    }

    int m = sc.nextInt();
    if (m == 100) m++;
    System.out.println(m + str);
  }
}


Measured memory_bytes: 22612
#include <iostream>
#include <algorithm>
using  namespace std;
int main() {
    int n,k;
    int l[50]={0};
    cin>>n>>k;
    for(int i=0;i<n;i++){
        cin>>l[i];
    }
    sort(l,l+50);
    int ans=0;
    for(int i=0;i<k;i++){
        ans+=l[49-i];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys
stdin = sys.stdin
 
sys.setrecursionlimit(10**5) 
 
def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x)-1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())

from bisect import bisect_left, bisect_right

n = ni()
a = sorted(list(li()))
b = sorted(list(li()))
c = sorted(list(li()))

ans = 0
for bi in b:
    ans += bisect_left(a,bi)*(n-bisect_right(c,bi))
    
print(ans)

Measured memory_bytes: 94180
#include <bits/stdc++.h>
using namespace std;
void dame(){
  cout << 0 << endl;
}
int main(){
  int n,a;
  cin >> n;
  int p[100010];
  for(int i=0; i<n; i++){
    p[i]=0;
  }
  for(int i=0; i<n; i++){
    cin >> a;
    p[a]++;
  }
  if(n%2!=0){
    if(p[0] != 1){
      dame();
      return 0;
    }
    for(int i=2; i<n; i+=2){
      if(p[i] != 2){
        dame();
        return 0;
      }
    }
  }else{
    for(int i=1; i<n; i+=2){
      if(p[i] != 2){
        dame();
        return 0;
      }
    }
  }
  //ans=2^(n/2)
  long long int ans=1;
  if(n%2==0){
    for(int i=0; i<n/2; i++){
      ans=(ans*2)%1000000007;
    }
  }else{
    for(int i=0; i<(n-1)/2; i++){
      ans = (ans*2)%1000000007;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>
#include<vector>
#include<cstdio>
using namespace std;
long long n,q,k,x,y,z,dist[111111];
vector<pair<long long,long long> > g[111111];
void dfs(long long i,long long fa)
{
	for (long long j=0;j<g[i].size();j++)
	{
		long long to=g[i][j].first,val=g[i][j].second;
		if (to==fa) continue;
		dist[to]=dist[i]+val;
		dfs(to,i);
	}
}
int main()
{
	scanf("%lld",&n);
	for (long long i=1;i<n;i++)
	{
		scanf("%lld%lld%lld",&x,&y,&z);
		g[x].push_back(make_pair(y,z));
		g[y].push_back(make_pair(x,z));  
	}
	scanf("%lld%lld",&q,&k);
	dfs(k,0);
	while(q--)
	{
		scanf("%lld%lld",&x,&y);
		printf("%lld\n",dist[x]+dist[y]);
	}
	return 0;
}

Measured memory_bytes: 14592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
  public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}


void solve(long long N, std::vector<long long> A){
    ll ans = 1;

    for (int i = 0; i < N; i++)
    {
        if(A[i] %2==0){
            ans *= 2;
        }
    }
    
    cout << powMod(3,N)-ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> A(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&A[i]);
    }
    solve(N, std::move(A));
    return 0;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

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

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	K, N := sc.nextInt(), sc.nextInt()
	A := sc.nextIntSlice(N)
	maxDiff := 0
	for i := 0; i < N; i++ {
		if i == N-1 {
			if maxDiff < abs(K-A[i]+A[0]) {
				maxDiff = abs(K - A[i] + A[0])
			}
		} else if maxDiff < abs(A[i]-A[i+1]) {
			maxDiff = abs(A[i] - A[i+1])
		}
	}

	fmt.Fprintln(wtr, K-maxDiff)
}


Measured memory_bytes: 3840
from collections import deque

def bfs(field):
    q = deque([(0, 0, 1)])
    visited = [[False] * w for _ in range(h)]
    while q:
        i, j, d = q.popleft()
        if i == h - 1 and j == w - 1:
            return d
        if visited[i][j]:
            continue
        visited[i][j] = True
        if i > 0 and field[i - 1][j] == ".":
            q.append((i - 1, j, d + 1))
        if i < h - 1 and field[i + 1][j] == ".":
            q.append((i + 1, j, d + 1))
        if j > 0 and field[i][j - 1] == ".":
            q.append((i, j - 1, d + 1))
        if j < w - 1 and field[i][j + 1] == ".":
            q.append((i, j + 1, d + 1))
        
    else:
        return -1

h, w = map(int, input().split())
field = [input() for _ in range(h)]
b = sum(r.count("#") for r in field)
res = bfs(field)
if res == -1:
    print(-1)
else:
    print(h * w - res - b)


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

int n,m,k;
int a[maxn],sum[maxn];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		sum[i]=sum[i-1]+a[i];
	}
	ll minn=2e18;
	for(int i=1;i<=n;i++)
		minn=min(minn,abs(1ll*sum[n]-2*sum[i]));
	printf("%lld",minn);
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> as(n);
    for (int i = 0; i < n; i++) {
        cin >> as[i];
    }

    sort(as.begin(), as.end());
    int cnt = 1;
    long long sum = 0;
    for (int i = 0; i < n - 1; i++) {
        sum += as[i];
    }
    for (int i = n - 2; i >= 0; i--) {
        if (as[i + 1] <= sum * 2) {
            cnt++;
        } else {
            break;
        }
        sum -= as[i];
    }
    cout << cnt << endl;
}

Measured memory_bytes: 640
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);
    auto c = iota(n).map!(i => readln.chomp.to!int).array;
    c = c.uniq.array;
    n = c.length.to!int;

    auto k = new long[](2 * 10^^5 + 1);
    auto dp = new long[](n + 1);
    dp[0] = 1;
    k[c[0]] = 1;

    foreach (i ; 1 .. n + 1) {
        dp[i] = k[c[i - 1]];
        if (i < n) {
            k[c[i]] += dp[i];
            k[c[i]] %= mod;
        }
    }

    debug {
        writeln(dp);
    }

    auto ans = dp[n];
    writeln(ans);
}



























int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 8060
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include <math.h> 

using namespace std;

#define ll long long int
#define rep(i, n) for(int i = 0; i < n; i++)
#define repp(i, n) for(int i = 1; i <= n; i++)
#define sort(v) sort((v).begin(), (v).end())
using vi = vector<int>;
const int MOD = 1e9 + 7;

bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2) { if (num % i == 0) return false; }

    return true;
}


int main() {
    int N;
    cin >> N;
    vi A(1005, 1);
    for (int i = 2; i <= N; i++) {
        if (IsPrime(i)) {
            repp(j, 20) {
                if (N < pow(i, j)) break;
                A[i] = A[i] + (N / pow(i, j));
            }
        }
    }
    ll ans = 1;
    for (int x : A) {
        ans = ans * x;
        ans = ans % MOD;
    }
    cout << ans  << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main(){
  int n,a;
  cin>>n;
  ll sum=0;
  for(int i=0;i<n;i++){
    cin>>a;
    sum+=a;
  }
  cout<<sum/n<<endl;
}

Measured memory_bytes: 1156
#include <bits/stdc++.h>
#define int long long
#define S second
#define F first
#define pb push_back
#define sz size()
using namespace std;
const int N=5e6+7;
int a[N],b[N],c[N],dp[N][5] ;
int n,x=1,ans,k ;
vector < int > vec ;
vector < int > pos ;
multiset < int > st ;
main()
{
    cin >> n ;
    for (int i=1; i<=n; i++)
        cin >> a[i] >> b[i] >> c[i] ;
    dp[1][1]=a[1] ;
    dp[1][3]=c[1] ;
    dp[1][2]=b[1] ;
    for (int i=2; i<=n; i++)
    {
        dp[i][1]=max(dp[i-1][2],dp[i-1][3])+a[i] ;
        dp[i][2]=max(dp[i-1][1],dp[i-1][3])+b[i] ;
        dp[i][3]=max(dp[i-1][2],dp[i-1][1])+c[i] ;
    }
    for (int i=1; i<=3; i++)
        ans=max(ans,dp[n][i]) ;
    cout << ans << endl ;
}


Measured memory_bytes: 9692