akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <iomanip>
typedef long long ll;
ll MOD = 1e9+7;
using namespace std;
class kukan
{
	public:
	int l,r;
	double v;
	kukan(int a,int b,double c)
	{
		l=a;r=b;v=c;
	}
};
vector<kukan> vec;
double ans[40001];//t/2
int main()
{
	int n;
	int t[102];
	int v[102];
	cin>>n;
	for(int i=0;i<n;i++)
	{
		cin>>t[i+1];
		t[i+1]*=2;
	}
	for(int i=0;i<n;i++)
		cin>>v[i];
	v[n]=0;
	t[0]=0;
	for(int i=1;i<n+1;i++)
		t[i]+=t[i-1];
	vec.push_back(kukan(0,0,0.0));
	for(int i=1;i<n+1;i++)
		vec.push_back(kukan(t[i-1],t[i],v[i-1]));
	vec.push_back(kukan(t[n],t[n],0.0));
	for(int i=0;i<t[n]+1;i++)
	{
		//それぞれについてそれぞれの関数を適用したときの値を調べる
		double tmp=1e8-1;
		for(int j=0;j<vec.size();j++)
		{
			if(vec[j].l<=i && i<=vec[j].r)
				tmp=min(tmp,vec[j].v);
			else if(i<vec[j].l)
				tmp=min(tmp,vec[j].v+(double)(vec[j].l-i)/2.0);
			else
				tmp=min(tmp,vec[j].v+(double)(i-vec[j].r)/2.0);
		}
		ans[i]=tmp;
	}
	double sum=0.0;
	for(int i=1;i<t[n]+1;i++)
	{
		//cerr<<ans[i]<<endl;
		sum+=(ans[i]+ans[i-1])*0.5/2.0;
	}
	cout<<setprecision(12)<<fixed<<sum<<endl;
	return 0;
}

Measured memory_bytes: 512
S = input()

#0101
tmp=0
cntA=0
for i in range(len(S)):
    if tmp!=int(S[i]):
        cntA+=1
    if tmp==0:
        tmp=1
    else:
        tmp=0

#1010
tmp=1
cntB=0
for i in range(len(S)):
    if tmp!=int(S[i]):
        cntB+=1
    if tmp==0:
        tmp=1
    else:
        tmp=0
#print(cntA,cntB)
print(min(cntA,cntB))


Measured memory_bytes: 3188
#[allow(unused_macros)]
macro_rules! input {
        (source = $s:expr, $($r:tt)*) => {
            let mut iter = $s.split_whitespace();
            let mut next = || { iter.next().unwrap() };
            input_inner!{next, $($r)*}
        };
        ($($r:tt)*) => {
            let stdin = std::io::stdin();
            let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
            let mut next = move || -> String{
                bytes
                    .by_ref()
                    .map(|r|r.unwrap() as char)
                    .skip_while(|c|c.is_whitespace())
                    .take_while(|c|!c.is_whitespace())
                    .collect()
            };
            input_inner!{next, $($r)*}
        };
    }

#[allow(unused_macros)]
macro_rules! input_inner {
        ($next:expr) => {};
        ($next:expr, ) => {};

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

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

#[allow(unused_macros)]
macro_rules! read_value {
        ($next:expr, ( $($t:tt),* )) => {
            ( $(read_value!($next, $t)),* )
        };

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

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

        ($next:expr, bytes) => {
            read_value!($next, String).into_bytes()
        };

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

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

fn main() {
    input! {
            n: usize,
            dams: [i32; n]
        }

    let mut ans : Vec<String>;

    let mut memo = 0;

    // solve first mountain's answer
    for i in 0..n {
        memo += dams[i] * (if i % 2 == 0 { 1 } else { -1 });
    }

    ans = vec![memo.to_string()];

    memo = memo / 2;

    // solve rest of mountains
    for i in 1..n {
        memo = dams[i-1] - memo;
        ans.push((memo * 2).to_string());
    }

    let ans_joined = ans.join(" ");

    println!("{}", ans_joined);
}

Measured memory_bytes: 11132
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

// int MOD = 998244353;
int MOD = 1000000007;


//----------------------------------------------------------------
signed main(){

	ll a,b;
	cin >> a >> b;

	ll ans = 0;
	ll t = 1;
	while(t < b){
		t += a-1;
		ans++;
	}
	cout << ans << endl;
	
	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://abc139.contest.atcoder.jp/tasks/abc139_b

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

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

    int sum = 0;

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

    string ans = "Yes";
    if (4 * m * a[m - 1] < sum ) ans = "No";
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
v_li = list(map(int,input().split()))
c_li = list(map(int,input().split()))
ben = []
for i in range(n):
  b = v_li[i]-c_li[i]
  ben.append(b)
ben.sort()
ben.reverse()
ans = 0
for i in range(n):
  if ben[i] >0:
    ans+=ben[i]
  else:
    break
print(ans)

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

int main(){
    int n;
    string s;
    cin>>n>>s;
    vector<int>l(n),r(n);
    for(int i=1; i<n; ++i){
        if(s[i-1]=='W')l[i]=l[i-1]+1;
        else l[i]=l[i-1];
    }
    for(int i=n-1; i>0; --i){
        if(s[i]=='E')r[i-1]=r[i]+1;
        else r[i-1]=r[i];
    }
    int ans=1e9;
    rep(i,n){
        ans=min(ans,l[i]+r[i]);
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 6156
#include<map>
#include<set>
#include<cmath>
#include<regex>
#include<queue>
#include<stack>
#include<bitset>
#include<vector>
#include<cstdio>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<unordered_map>

#pragma warning(disable:4996)
using namespace std;

int a;
int b;
int c;
int var[3][3];

int main() {
	scanf("%d%d%d", &a, &b, &c);
	var[0][0] = a; var[0][1] = b; var[0][2] = 3 * c - a - b;
	var[1][0] = 3 * c - 2 * a - b + c; var[1][1] = c; var[1][2] = 2 * a + b + c - 3 * c;
	var[2][0] = a + b -c; var[2][1] = 2*c - b; var[2][2] = 3*c - a -c;
	for (int i = 0; i < 3; ++i) {
		for (int j = 0; j < 3; ++j) {
			printf("%d ", var[i][j]);
		}
		puts("");
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
//#include <math.h>
#include <algorithm>
#include <vector>

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))

using namespace std;

#define MOD 1000000007


int main(int argc, char* argv[])
{   
    long n, qq;
    scanf("%ld %ld", &n, &qq);

    vector<long> a(n,0);
    vector<ll> s(n+1,0);
    vector<ll> tt(n+1,0);
    long i;
    for(i=0; i<n; i++) {
        scanf("%ld", &(a[n-1-i]));
    }
    for(i=0; i<n; i++) {
        s[i+1] = s[i] + a[i];
    }

    vector<ll> ans(n,0);
    long kmax=(n-1)/2;
    for(i=0; i<=kmax; i++) {
        tt[i+1] = tt[i] + a[2*i];
    }

    vector<long> judge(kmax,0);
    long k;
    for(k=1; k<=kmax; k++) {
        judge[kmax-k] = (a[k] + a[k*2])/2;
        ans[kmax-k] = s[k] + tt[kmax+1] - tt[k];
    }

    vector<long> x(qq);
    for(i=0; i<qq; i++) {
        scanf("%ld", &(x[i]));
    }
    for(i=0; i<qq; i++) {
        if(kmax>0) {
            vector<long>::iterator it = lower_bound( judge.begin(), judge.end(), x[i]);
            if(it==judge.end()) {
                printf("%lld\n", ans[kmax-1]);
            }
            else {
                long tmp = it-judge.begin();
                if(tmp==0) {
                    printf("%lld\n", s[(n+1)/2]);
                }
                else {
                    printf("%lld\n", ans[tmp-1]);
                }
            }
        }
        else {
            printf("%ld\n", a[0]);
        }
    }

    return 0;
}


Measured memory_bytes: 6016
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 

#define MAX 2001
ll n,z,w;
ll a[MAX];
ll dp[MAX][2];
ll f(ll i,bool turn){
	if(dp[i][turn]!=-1) return dp[i][turn];
	ll ans=0;
	if(!turn){
		ll score = 0;
		For(k,i+1,n){
			score = max(score,f(k,!turn));
		}
		ll c = (i==0 ? w : a[i-1]);
		score = max(score,abs(a[n-1]-c));
		ans = score;
	}else{
		ll score = 1e9;
		For(k,i+1,n){
			score = min(score,f(k,!turn));
		}
		ll c = (i==0 ? z : a[i-1]);
		score = min(score,abs(a[n-1]-c));
		ans =  score;
	}
	dp[i][turn]=ans;
	return ans;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	memset(dp,-1,sizeof(dp));
	cin>>n>>z>>w;
	For(i,0,n) cin>>a[i];
	
	cout<<f(0,0)<<endl;









	
}

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

#define For(i, l, r) for(register int i = (l), i##end = (int)(r); i <= i##end; ++i)
#define Fordown(i, r, l) for(register int i = (r), i##end = (int)(l); i >= i##end; --i)
#define Set(a, v) memset(a, v, sizeof(a))
#define Cpy(a, b) memcpy(a, b, sizeof(a))
#define debug(x) cout << #x << ": " << x << endl
#define DEBUG(...) fprintf(stderr, __VA_ARGS__)

using namespace std;

inline bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
inline bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

namespace pb_ds
{
    namespace io
    {
        const int MaxBuff = 1 << 16;
        const int Output = 1 << 22;
        char B[MaxBuff], *S = B, *T = B;
        #define getc() ((S == T) && (T = (S = B) + fread(B, 1, MaxBuff, stdin), S == T) ? 0 : *S++)
        char Out[Output], *iter = Out;
        inline void flush()
        {
            fwrite(Out, 1, iter - Out, stdout);
            iter = Out;
        }
    }

    template<class Type> inline Type read()
    {
        using namespace io;
        register char ch; register Type ans = 0; register bool neg = 0;
        while(ch = getc(), (ch < '0' || ch > '9') && ch != '-')     ;
        ch == '-' ? neg = 1 : ans = ch - '0';
        while(ch = getc(), '0' <= ch && ch <= '9') ans = ans * 10 + ch - '0';
        return neg ? -ans : ans;
    }

    template<class Type> inline void Print(register Type x, register char ch = '\n')
    {
        using namespace io;
        if(!x) *iter++ = '0';
        else
        {
            if(x < 0) *iter++ = '-', x = -x;
            static int s[100]; register int t = 0;
            while(x) s[++t] = x % 10, x /= 10;
            while(t) *iter++ = '0' + s[t--];
        }
        *iter++ = ch;
    }
}

using namespace pb_ds;

void File() {
	freopen ("l.in", "r", stdin);
	freopen ("l.out", "w", stdout);
}

const int N = 1e5 + 1e3, Maxn = 2e8 + 1e3;

int n, m;

typedef long long ll;

ll times[N], sta[N], b[N], f[N]; int top;

int main () {

	n = read<int>(); m = read<int>();

	sta[++ top] = n;
	For (i, 1, m) {
		ll val = read<ll>();
		while (top && val <= sta[top]) -- top;
		sta[++ top] = val;
	}

	m = top; For (i, 1, m) b[i] = sta[i]; 

	times[m] = 1;
	Fordown (i, m - 1, 1) {
		times[i] += (b[i + 1] / b[i]) * times[i + 1];
		register ll rest = b[i + 1] % b[i];
		while (rest) {
			register int pos = upper_bound(b + 1, b + m + 1, rest) - b - 1;
			if (!pos) { f[rest] += times[i + 1]; break; }
			times[pos] += (rest / b[pos]) * times[i + 1];
			rest %= b[pos];
		}
	}
	f[b[1]] += times[1];
	Fordown (i, b[1] - 1, 1) f[i] += f[i + 1];

	For (i, 1, n) Print(f[i]); io :: flush();

	return 0;
}


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

int main(){

    long long int a,b,k;
    

    cin >> a >> b >> k;

    if(k<=a){
        cout << a-k << " " << b << endl;
    }else{
        cout << 0 << " " << max(b-(k-a),(long long int)0);
    }
    
    return 0;
}

Measured memory_bytes: 256
use std::collections::VecDeque;

fn main() {
    let (n, q): (usize, usize) = {
        let mut line = String::new();
        std::io::stdin().read_line(&mut line);
        let u: Vec<usize> = line.split_whitespace().map(|a| a.parse().unwrap()).collect();
        (u[0], u[1])
    };
    let mut graph = vec![vec![0usize; 0]; n];
    let mut score = vec![0i64; n];
    for i in 0..n-1 {
         let (a, b): (usize, usize) = {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line);
            let u: Vec<usize> = line.split_whitespace().map(|a| a.parse().unwrap()).collect();
            (u[0] - 1, u[1] - 1)
        };
        graph[a].push(b);
        graph[b].push(a);
    }
    for i in 0..q {
        let (p, x): (usize, i64) = {
            let mut line = String::new();
            std::io::stdin().read_line(&mut line);
            let mut iter = line.split_whitespace();
            let p: usize = iter.next().unwrap().parse().unwrap();
            let x: i64 = iter.next().unwrap().parse().unwrap();
            (p - 1, x)
        };
        score[p] += x;
    }
    let mut que: VecDeque<usize> = VecDeque::new();
    que.push_back(0);
    let mut visited = vec![false; n];
    visited[0] = true;
    while !que.is_empty() {
        let cur = que.pop_front().unwrap();
        for &next in &graph[cur] {
            if !visited[next] {
                visited[next] = true;
                score[next] += score[cur];
                que.push_back(next);
            }
        }
    }
    for i in 0..n {
        if i > 0 {
            print!(" ");
        }
        print!("{}", score[i]);
    }
    println!("\n");
}

Measured memory_bytes: 24700
#include <iostream>
 
using namespace std;
 
int main(){
   int h1, s1 , h2 , s2;
   cin >> h1 >> s1 >> h2 >> s2;
   while(h2 > 0 && h1 > 0){
   h2 = h2 - s1;
   h1 = h1 - s2;
   if(h2 <= 0){
	   cout << "Yes";
	   }
	 else if(h2 > 0 && h1 <= 0){
		 cout << "No";
		 }
		  
    
}
    return 0;
}

Measured memory_bytes: 3608
//#pragma comment(linker, "/STACK:134217728")

#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <memory>
#include <cctype>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
using namespace std;

typedef long long Int;
typedef pair<int,int> PII;
typedef vector<int> VInt;

#define FOR(i, a, b) for(i = (a); i < (b); ++i)
#define RFOR(i, a, b) for(i = (a) - 1; i >= (b); --i)
#define CLEAR(a, b) memset(a, b, sizeof(a))
#define SIZE(a) int((a).size())
#define ALL(a) (a).begin(),(a).end()
#define PB push_back
#define MP make_pair

void solve(int test)
{
    int n, k;
    cin >> n >> k;
    if(k == 1) n = k;
    cout << n - k << endl;
}

int main()
{
    int t, T;
    T = 1;
    //scanf("%d", &T);
    FOR(t, 0, T) solve(t);
    
    return 0;
};



Measured memory_bytes: 256
import math


def partition(n: int, k: int) -> int:
    return math.factorial(n + k - 1) // math.factorial(n) // math.factorial(k - 1)


def combination(i: int, j: int) -> int:
    return math.factorial(i) // math.factorial(i - j) // math.factorial(j)


if __name__ == "__main__":
    n, k = map(lambda x: int(x), input().split())
    modulo = 10 ** 9 + 7
    ans = 0
    if k <= n:
        for i in range(k):
            if 0 == i % 2:
                ans += partition(n, k - i) * combination(k, i)
            else:
                ans -= partition(n, k - i) * combination(k, i)
        ans = ans % modulo

    print(ans)



Measured memory_bytes: 5668
#include <vector>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <string>
#include <climits>
#include <tuple>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int,int> T;
 
 
 

vector<int> g[1000];
int used[1000];
int fr[1000];
int ans=0;
int visit=0;
int n,m;
bool ma[13][13];

int main(){
    
    string S;
    cin>>S;
    int s=S.size();
    bool flag1=false;
    int a=s-2,b=2;
    int w=-1;
    for(int i=min(a,b);i<=max(a,b);i++){
        if (S[i]=='C')  {flag1=true;w=i;continue;}
        if (S[i]=='C' and flag1 ){flag1=false;break;}
    }
    bool flag2=true;
    for(int i=1;i<s;i++){
        if(i!=w and ('a'>S[i] or 'z'<S[i]))flag2=false;
    }

    if(flag1 and flag2 and S[0]=='A')cout<<"AC"<<endl;
    else cout<<"WA"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using iii = pair<ii, int>;
#define pq priority_queue
#define vt vector
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define __lcm(a, b) a * b / __gcd(a, b)
const int MOD = 1e9 + 7;
const int INF = 1e9;
const int N = 3e3 + 5;

int dp[N][N];
string s, t;
vt<char> v;

int f(int a, int b) {
    if(a == s.size() || b == t.size()) return 0;
    int &sol = dp[a][b];
    if(sol != -1) return sol;
    if(s[a] == t[b]) return sol = 1 + f(a + 1, b + 1);
    return sol = max(f(a + 1, b), f(a, b + 1));
}

void backtrack(int a, int b) {
    if(a == s.size() || b == t.size()) return;
    int temp = -INF, aplus, bplus;
    aplus = f(a + 1, b);
    bplus = f(a, b + 1);
    if(s[a] == t[b])
        temp = f(a + 1, b + 1);
    if(temp != -INF) {
        v.pb(s[a]);
        backtrack(a + 1, b + 1);
    } else if(aplus > bplus) 
        backtrack(a + 1, b);
    else 
        backtrack(a, b + 1);
}

void solve() {
    cin >> s >> t;
    memset(dp, -1, sizeof(dp));
    backtrack(0, 0);
    for(char x : v) 
        cout << x;
    cout << "\n";
}

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

    solve();
    
}

Measured memory_bytes: 39188
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

ll nums[59];
ll tmp[59];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;
    cin>>N;
    
    rep(i,N) cin>>nums[i];
    
    ll total=0;
    bool f=true;
    while(f){
        mem(tmp,0);
        ll cnt=0;
        rep(i,N)if(nums[i]>=N){
            tmp[i]=nums[i]/N;
            cnt+=tmp[i];
            nums[i]%=N;
        }
        f=false;
        rep(i,N){
            nums[i]+=cnt-tmp[i];
            if(nums[i]>=N) f=true;
        }
        total+=cnt;
    }
    cout1(total)
}

Measured memory_bytes: 256
#include<stdio.h>

int main(void){
    long sum,blue,red,count,remain,ans;
    scanf("%ld%ld%ld",&sum,&blue,&red);

    count = sum/(red+blue);
    remain = sum%(red+blue);
    if(blue<remain){
        ans = blue*count+blue;
    }else{
        ans = blue*count+remain;
    }
    
    printf("%ld\n",ans);

    return 0;
}

Measured memory_bytes: 128
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<unordered_map>
#include<unordered_set>
#include<deque>
#include<cstdio>
using namespace std;
typedef long long int ll;
const int INF = 1 << 30;
#define FOR(i,a,n) for(int i=(ll)a;i<(ll)n;++i)
#define TFOR(i,n)FOR(i,0,n)
#define ALL(x) x.begin(),x.end()
int main() {
	int n, y;
	cin >> n >> y;
	y /= 1000;
	int a=-1, b=-1, c=-1;
	for (int i = 0; i <= n; ++i) {
		for (int j = 0; j <= n - i; ++j) {
			int w = n-i-j;
				if (10 * i + 5 * j + w == y) { a = i; b = j; c = w; }
			}
		}
	cout << a << " " << b << " " << c << endl;
	return 0;
}

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

int main() {
  long x,ans=1;
  cin >> x;
  for(long i=2;i*i<=x;i++) {
    long a=i*i;
    while(a<=x) {
      ans=max(ans,a);
      a*=i;
    }
  }
  cout << ans << endl;
}

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

using ll = long long;
using ull = unsigned long long;
using st = string;
using db = double;
using vll = vector<long long>;
using vvll = vector<vll>;
using vchar = vector<char>;
#define rep(i, m, n) for (int i = (int)(m); i < (int)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
ll mod = 1000000007;

int main(){
  ll n;
  cin >> n;
  vll a(n);
  vin(a);
  sort(all(a), greater<ll>());
  ll alice = 0, bob = 0;
  rep(i, 0, n){
    if(i % 2 == 0) alice += a.at(i);
    else bob += a.at(i);
  }
  cout << alice - bob << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        if (a < 1000) {
            System.out.println("ABC");
        } else {
            System.out.println("ABD");
        }
    }
}


Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int maxn=5e2+5;
const ll inf=1e18;
const int mod=1e9+7;
map<int,int>vis;
struct node
{
    int x,y,num;
    node() {}
    node(int a,int b):x(a),y(b) {}
    bool operator < (const node& b) const
    {
        return x < b.x;
    }
} N[maxn];
long double dp[maxn][maxn];
int main()
{
    string a;
    cin>>a;
    cout<<a[0]<<a[1]<<a[2];
}

Measured memory_bytes: 3600
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

string s[200];
int n,a[200];
void dfs(int x){
    rep(j,n){
        if(s[x][j]=='1'){
            if(!a[j]){
                a[j]=-a[x];
                dfs(j);
            }
            else if(a[j]==a[x]){
                cout<<-1<<endl;
                exit(0);
            }
        }
    }
}

int bfs(int x){
    vector<int> b(n);
    b[x]=1;
    queue<int> q;
    q.push(x);
    while(q.size()){
        int t = q.front();
        q.pop();
        rep(j,n){
            if(s[t][j]=='1'&&!b[j]){
                b[j]=b[t]+1;
                q.push(j);
            }
        }
    }
    return *max_element(b.begin(), b.end());

}
int main(){
    cin>>n;
    rep(i,n)cin>>s[i];
    a[0]=1;
    dfs(0);
    int ans = 0;
    rep(i,n){
        ans = max(ans,bfs(i));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N, K = MAP()
l = LIST()

print(sum(sorted(l, reverse=True)[:K]))


Measured memory_bytes: 3884
"""
AtCoder :: Beginner Contest 173 :: H and V
https://atcoder.jp/contests/abc173/tasks/abc173_c
"""
import sys
from itertools import chain, combinations


def powerset(iterable):
    "powerset([1,2,3]) --> () (1,) (2,) (3,) (1,2) (1,3) (2,3) (1,2,3)"
    s = list(iterable)
    return chain.from_iterable(combinations(s, r) for r in range(len(s)+1))


def main():
    """Main program."""
    height, width, target = (int(i) for i in sys.stdin.readline().split())
    grid = [[0 for _ in range(width)] for _ in range(height)]
    total_black = 0
    for row in range(height):
        for col, color in enumerate(sys.stdin.readline().strip()):
            if color == '#':
                grid[row][col] = 1
                total_black += 1

    soln = 0
    for rows_selected in powerset(range(height)):
        for cols_selected in powerset(range(width)):
            if len(cols_selected) == width:
                continue

            selected_black = 0
            for row in rows_selected:
                selected_black += sum(grid[row])

            for col in cols_selected:
                for row in range(height):
                    if row not in rows_selected:
                        selected_black += grid[row][col] 

            if total_black - selected_black == target:
                soln += 1
    print(soln)


if __name__ == '__main__':
    main()


Measured memory_bytes: 9252
/*Kriti Verma */
#include<bits/stdc++.h>
#define     ll          long long
#define     MOD         10e9+7
#define     pb          push_back
#define     vll         vector<long long>
#define     vi          vector<int>
#define     vl          vector<long>
#define     pii         pair<int, int>
#define     pll         pair<ll,ll>
#define     mp          make_pair
#define     all(a)      (a).begin(),(a).end()
#define     rep(i,a,b)  for(int i=a;i<b;i++)
#define     MAX         100002 
#define     ios          ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;

int main() {
    
    ios
    ll n;
    cin >> n;
    if(n%1000LL==0)cout << "0\n";
    else{
        cout << abs(1000LL-n%1000LL);
    }
    return 0;
}



Measured memory_bytes: 3648
#include <stdio.h>

int sum(int val){
    if(val == 0)return 0;
    int ans = val % 10;
    do{
        val /= 10;
        ans += val % 10;
    }while(val > 0);
    return ans;
}

int main(void){
    int i, n, a, b, ans = 0, buf;
    scanf("%d %d %d",&n,&a,&b);
    for(i=1; i<=n; i++){
        buf = sum(i);
        if(a<=buf && buf<=b)ans += i;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main(void)
{
  char s[11];
  int i,c_i,len,count=0;
  scanf("%s",s);
  len=strlen(s);
  if(s[0]!='A'){
    printf("WA\n");
    return 0;
  }
  for(i=2;i<len-1;i++){
    if(s[i]=='C'&&count==0){
      c_i=i;
      count++;
    }else if(s[i]=='C'&&count==1){
      printf("WA\n");
             return 0;
             }
             }
             if(count==0){
               printf("WA\n");
               return 0;
             }
               for(i=1;i<len;i++){
				if(i!=c_i&&s[i]<97){
                  printf("WA\n");
                  return 0;
                }
               }
             printf("AC\n");
             return 0;
             }

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

int main()
{
  ll N; cin>>N;
  map<int, bool> A;

  rep(i, N) {
    ll tmp; cin>>tmp;
    if(A.count(tmp)) {
      A.erase(tmp);
    } else {
      A.insert(make_pair(tmp, true));
    }
  }

  cout << A.size() << endl;
  return 0;
}

Measured memory_bytes: 8244
N, K = map(int, input().split())
R2, S, P = map(int, input().split())
T = input()

R = []

for i in range(K):
    if T[i]=='r':
        R.append('p')
    elif T[i]=='s':
        R.append('r')
    else:
        R.append('s')

for i in range(K, len(T)):
    if T[i]=='r':
        if R[i-K] == 'p':
            R.append('x')
        else:
            R.append('p')
    elif T[i]=='s':
        if R[i-K] == 'r':
            R.append('x')
        else:
            R.append('r')
    else:
        if R[i-K] == 's':
            R.append('x')
        else:
            R.append('s')

ans = 0
for r in R:
    if r=='p': ans += P
    elif r=='r': ans += R2
    elif r=='s': ans += S

print(ans)





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

const int N=200010;
vector<int> adj[N];
bool pos=false;
int n,m,visit[N];

int main(void){
    scanf("%d %d",&n,&m);
    while(m--){
        int a,b;
        scanf("%d %d",&a,&b);
        adj[a].push_back(b);
        adj[b].push_back(a);
    }
    visit[1]=1;
    queue<pair<int,int> > q;
    q.push(make_pair(1,0));
    while(!q.empty()){
        int now=q.front().first;
        int cnt=q.front().second;
        q.pop();
        if(now==n){
            pos=true;
            break;
        }
        int size=adj[now].size();
        for(int i=0;i<size;i++){
            int x=adj[now][i];
            if(!visit[x]){
                visit[x]=1;
                if(cnt+1<=2){
                    q.push(make_pair(x,cnt+1));
                }
            }
        }
    }
    if(pos)printf("POSSIBLE\n");
    else printf("IMPOSSIBLE\n");
    return 0;
}


Measured memory_bytes: 13552
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <numeric>
typedef long long Int;
#define rep(i,a,b) for(Int i=a;i<b;++i)
#define rrep(i,a,b) for(Int i=a;i>=b;--i)
using namespace std;

struct UnionFind {
    vector<int> parent;

    UnionFind(int n) : parent(n, -1) {}
    void Init(int n) { parent.assign(n, -1); }

    int Root(int x) {
        if (parent[x] < 0) return x;
        else return parent[x] = Root(parent[x]);
    }

    bool IsSame(int x, int y) {
        return Root(x) == Root(y);
    }

    bool Merge(int x, int y) {
        x = Root(x); y = Root(y);
        if (x == y) return false;
        if (parent[x] > parent[y]) swap(x, y);
        parent[x] += parent[y];
        parent[y] = x;
        return true;
    }

    int Size(int x) {
        return -parent[Root(x)];
    }
};

void IrreversibleCompress(vector<long long>& x, map<long long, long long>& zip) {
    sort(x.begin(), x.end());
    x.erase(unique(x.begin(), x.end()), x.end());

    for(long long i = 0; i < x.size(); ++i) {
        zip[x[i]] = i;
    }
}

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

    Int N; cin >> N;
    vector<Int> x(N), y(N), orgX(N), orgY(N);
    rep(i, 0, N) cin >> x[i] >> y[i];
    orgX = x; orgY = y;

    map<long long, long long> zipx;
    IrreversibleCompress(x, zipx);
    map<long long, long long> zipy;
    IrreversibleCompress(y, zipy);

    Int nx = x.size(), ny = y.size();
    UnionFind uf(nx+ny);

    rep(i, 0, N) {
        uf.Merge(zipx[orgX[i]], zipy[orgY[i]]+nx);
    }

    map<Int, Int> mx, my;
    rep(i, 0, nx) {
        mx[uf.Root(i)]++;
    }
    rep(i, nx, nx+ny) {
        my[uf.Root(i)]++;
    }

    Int res = 0;
    rep(i, 0, nx+ny) {
        res += mx[i] * my[i];
    }

    cout << res - N << endl;
}

Measured memory_bytes: 22528
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()

using namespace std ;
using ll = long long ;
using ld = long double ;
using pii = pair <int , int> ;

const int mod = 1e9 + 7 , N = 2e5 + 20 ;
int b , w , fac[N] , inv[N] ;
int fb , fw ;

inline void add (int &a , int b) {
	a += b ;
	if (a >= mod) a -= mod ;
}

inline int pw (int a , int b) {
	int res = 1 ;
	while (b) {
		if (b & 1) res = 1ll * res * a % mod ;
		a = 1ll * a * a % mod ;
		b >>= 1 ;
	}
	return res ;
}

inline int C (int n , int k) {
	if (k < 0 || k > n) return 0 ;
	return 1ll * fac[n] * inv[k] % mod * inv[n - k] % mod ;
}

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

	fac[0] = inv[0] = 1 ;
	for (int i = 1 ; i < N ; i ++) {
		fac[i] = 1ll * fac[i - 1] * i % mod ;
		inv[i] = pw(fac[i] , mod - 2) ;
	}

	cin >> b >> w ;

	for (int i = 1 ; i <= b + w ; i ++) {
		cout << ((fw + 1ll * (2 * mod + 1 - fb - fw) * pw(2 , mod - 2)) % mod) << '\n' ;
	
		if (i >= b) add(fb , 1ll * C(i - 1 , b - 1) * pw(pw(2 , i) , mod - 2) % mod) ;
		if (i >= w) add(fw , 1ll * C(i - 1 , w - 1) * pw(pw(2 , i) , mod - 2) % mod) ;
	}
}


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

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

    int answer = 0;
    for (int i = 1; i < int(s.size()); i++)
    {
        if (s.at(i) != s.at(i - 1))
            answer++;
    }
    cout << answer << endl;
}

Measured memory_bytes: 512
///  author:Kissheart  ///
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<string.h>
#include<vector>
#include<stdlib.h>
#include<math.h>
#include<queue>
#include<deque>
#include<ctype.h>
#include<map>
#include<set>
#include<stack>
#include<string>
#define INF 0x3f3f3f3f
#define FAST_IO ios::sync_with_stdio(false)
const double PI = acos(-1.0);
const double eps = 1e-6;
const int MAX=1e5+10;
const int mod=1e9+7;
typedef long long ll;
using namespace std;
#define gcd(a,b) __gcd(a,b)
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll qpow(ll a,ll b){ll r=1,t=a; while(b){if(b&1)r=(r*t)%mod;b>>=1;t=(t*t)%mod;}return r;}
inline ll inv1(ll b){return qpow(b,mod-2);}
inline ll exgcd(ll a,ll b,ll &x,ll &y){if(!b){x=1;y=0;return a;}ll r=exgcd(b,a%b,y,x);y-=(a/b)*x;return r;}
inline ll read(){ll x=0,f=1;char c=getchar();for(;!isdigit(c);c=getchar()) if(c=='-') f=-1;for(;isdigit(c);c=getchar()) x=x*10+c-'0';return x*f;}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
int n,t;
struct node
{
    int c,t;
}e[MAX];
int main()
{
    int ans=INF;
    scanf("%d%d",&n,&t);
    for(int i=1;i<=n;i++)
        scanf("%d%d",&e[i].c,&e[i].t);
    for(int i=1;i<=n;i++)
    {
        if(e[i].t<=t)
            ans=min(ans,e[i].c);
    }
    if(INF==ans) printf("TLE\n");
    else    printf("%d\n",ans);
    return 0;
}


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

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

target = [-1]*n
seen = [False]*n

from collections import deque
que = deque()

que.append(0)
while len(que) > 0:
    current = que.popleft()
    if seen[current]:
        continue
    seen[current] = True
    nodes = graph[current]

    for i in nodes:
        if target[i] == -1:
            target[i] = current + 1
        que.append(i)

target.pop(0)

if -1 in target:
    print('No')
else:
    print('Yes')
    for t in target:
        print(t)

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

using namespace std;

#define debug(x) cout << #x << "::" << x << endl;
#define debug2(x, y) cout << #x << "::" << x << " " << #y << "::" << y << endl;
#define debug3(x, y, z) cout << #x << "::" << x << " " << #y << "::" << y <<" "<< #z << "::" << z << endl;

#define For(i, a, b) for (int i = a; i < b; i++)

typedef long long ll;
const ll mod = 1e9 + 7;
const int MAX = 1e5 + 5;
typedef pair<int, int> pii;

void add(ll &a, ll b)
{
    a = (a + b) % mod;
    if (a < 0) a += mod;
}
vector<int> g[MAX];
vector<int> visit(MAX,-1);

int dfs(int num) {

   if(visit[num]!=-1) return visit[num];

   if(!g[num].size()) return 0;

    int ans = 0;
   for(auto child : g[num]) {
       ans = max(ans,dfs(child)+1);
   }

   visit[num] = ans;
   return ans;

}
int main() {

    int n,c;
    cin>>n>>c;

    For(i,0,c){
        int x,y;
        cin>>x>>y;
        g[x].push_back(y);
    }

    int ans = 0;

    For(i,1,n+1){
        ans = max(ans,dfs(i));
    }

    cout<<ans<<endl;

    return 0;

}

Measured memory_bytes: 8192
#include <iostream>
#include <string> 
#include <vector> 
#include <algorithm> 
#include <utility> 
#include <tuple> 
#include <cstdint> 
#include <cstdio> 
#include <map> 
#include <queue> 
#include <set> 
#include <stack> 
#include <deque> 
#include <unordered_map> 
#include <unordered_set> 
#include <bitset> 
#include <cctype> 
#include<math.h>
using namespace std;

#define int long long
#define endl "\n"
#define fir first
#define sec second
#define fro front
#define m_p make_pair
#define mod 1000000007
#define all(v)  v.begin(),v.end()
#define rep(i,n)  for(int i=0; i<(int) (n); i++)
#define all(v)  v.begin(),v.end()
#define vecin(v) for(int i=0; i<(int)v.size(); i++)cin>>v[i];
using namespace std;

const int MAX = 510000;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];
int jousu(int x00, int y00) {
	int z00 = 1;
	for (int i = 0; i < y00; i++) {
		z00 *= x00;
	}
	return z00;
}
int keta(int x00) {
	int z00 = x00;
	int w00 = 0;
	while (z00 != 0) {
		z00 /= 10;
		w00++;
	}
	return w00;
}

int modinv(int a, int m) {
	int b = m, u = 1, v = 0;
	while (b) {
		int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
int modpow(int a, int n) {
	int res = 1;
	while (n > 0) {
		if (n & 1) res* a% mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int gcd(int xx, int yy) {
	int p = xx;
	int q = yy;
	if (q > p)swap(p, q);
	while (p % q != 0) {
		p %= q;
		swap(p, q);
	}
	return q;
}
int lcm(int xx, int yy) {
	return xx * yy / gcd(xx, yy);
}
bool prime(int xx) {
	int a = xx;
	for (int i = 2; i * i <= xx; i++) {
		if (xx % i == 0) {
			return 0;
		}
	}
	return 1;
}
int com(int xx, int yy) {
	int zz = 1;
	for (int i = xx; i > xx - yy; i--) {
		zz *= i;
		zz %= mod;
	}
	for (int i = 1; i <= yy; i++) {
		zz *= modinv(i, mod);
		zz %= mod;
	}
	return zz;
}



signed main() {
	int n,t=0;
	cin >> n;
	vector<int>vec1(n), vec2(n);
	vecin(vec1);
	vecin(vec2);
	rep(i, n) {
		vec1[i] = vec1[i] - vec2[i];
	}
	sort(all(vec1));
	reverse(all(vec1));
	rep(i, n) {
		if (vec1[i] <= 0) {
			break;
		}
		t += vec1[i];
	}
	cout << t << endl;
}


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

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new ABC109().doIt(); //DFS
	}
	class ABC109{
		int euqulid(int A,int B) {
			if(B > 0)return euqulid(B,A % B);
			else return A;
		}
		void doIt(){
			int n = sc.nextInt();
			int X = sc.nextInt();
			int ans = Integer.MAX_VALUE;
			for(int i = 0;i < n;i++) {
				int x = sc.nextInt();
				int dist = Math.abs(x - X);
				if(i == 0)ans = dist;
				else ans = euqulid(dist,ans);
			}
			System.out.println(ans);
		}
	}
}


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

int calc(int t, int s, int f){
  if(t<=s)return s;
  return f * ((t-s)/f + ((t-s)%f != 0)) + s;
}

int main(){
  int n;cin>>n;
  vector<int> c(n-1);
  vector<int> s(n-1);
  vector<int> f(n-1);
  for(int i=0;i<n-1;i++){
    cin>>c[i]>>s[i]>>f[i];
  }
  for(int i=0;i<n;i++){
    if(i==n-1){cout<<'0'<<endl;return 0;}
    int ans=s[i];
    for(int j=i;j<n-2;j++){
      ans+=c[j];
      ans = calc(ans, s[j+1], f[j+1]);
    }
    ans += c[n-2];
    cout<<ans<<endl;
  }
}


Measured memory_bytes: 256
//============================================================================
//Everyone has a different way of thinking, so God Created us
//   Hope You Respect My Way..,Thank You ):
// Author      : Murad
// Name        : Codeforces.cpp & Atcoder.cpp
// Description : Problem name
//============================================================================
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
#define pi 3.1415926536
#define forn(i,a,b)for(int i=a;i<b;i++)
#define LL long long
#define ULL unsigned long long
#define MP make_pair
#define ff first
#define ss second
#define endl '\n'
#define INF 1e9 + 1
#define _INF INT32_MIN
#define pq priority_queue
#define MM multimap
#define PB push_back
#define vii vector<int>
#define ipair pair<int,int>
#define lpair pair<LL,LL>
#define El3zba ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define modd 1000000007
#define sfll1(v) scanf("%I64d",&v);
#define sfll2(v1,v2) scanf("%I64d %I64d",&v1,&v2)
#define sfll3(v1,v2,v3) scanf("%I64d %I64d %I64d",&v1,&v2,&v3)
//std::transform(s1.begin(), s1.end(), s1.begin(),::tolower);
char alphz[27] = { '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' };
float Euclidean(LL x1, LL x2, LL y1, LL y2) {
	return sqrt(pow(x1 - x2, 2) + pow(y1 - y2, 2));
}
LL gcd(LL a,LL b) {
	return !b ? a : gcd(b, a % b);
}
LL LCM(LL a, LL b) {
	return (a*b) / gcd(a, b);
}
void PrimeFactor(LL n)
{
	while (n % 2 == 0) {
		//printf("%d ", 2);
//		aa.insert(2);
		n /= 2;
	}
	for (int i = 3; i <= sqrt(n); i += 2)
	{
		if (n%i == 0) {
			//printf("%d ", i);
			//aa.insert(i);
			n /= i;
		}
	}
	if (n > 2){
		//printf("%d ", n);
	//	aa.insert(n);
	};
}
bool is_square(LL x) {
	LL l = 0, r = x;
	while (l <= r) {
		LL mid = l + (r - l) / 2;
		if (mid*mid == x)return true;
		if (mid*mid > x)r = mid - 1;
		else l = mid + 1;
	}
	return false;
}
LL power(LL x, LL y)
{
	LL temp;
	if (y == 0)return 1;
	temp = power(x, y / 2);
	if (y % 2 == 0)
		return temp*temp;
	else return x*temp*temp;
}
bool is_Prime(int x) {
	if (x == 2)return 1;
	else if (x % 2 == 0 || x < 2)return 0;
	for (int i = 3; i*i <= x; i += 2)
		if (x%i == 0)return 0;
	return 1;
}
int main()
{
	El3zba;
	/***  بسم الله الرحمن الرحيم   ***/
	LL n;
	cin >> n;
	if (n == 0)return cout << 0 << endl, 0;
	string ans;
	while (n != 0)
	{
		if (n % 2 == 0)
			ans.PB('0');
		else
			ans.PB('1');
		if (n < 0)
			n = (n - 1) / -2;
		else
			n /= -2;
	}
	reverse(ans.begin(), ans.end());
	cout << ans << endl;
	return 0;
}

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

typedef unsigned long long ull;
ull B=5575777;
ull C[(1<<19)];
ull po[(1<<19)];
char s[(1<<19)];
ull t[(1<<19)];


int calc(int a,int b,int l,int r){
  int L=max(a,l);
  int R=min(b,r);
  return max(0,R-L);
}

void delay(int k,int l,int r){
  if(s[k]=='\0')return;
  char ch=s[k];
  s[k]='\0';
  t[k]=C[r-l]*ch;
  if(r-l==1)return;
  s[k*2+1]=ch;
  s[k*2+2]=ch;
}

void Set(int a,int b,char ch,int k=0,int l=0,int r=(1<<18)){
  delay(k,l,r);
  if(b<=l || r<=a)return;
  if(a<=l && r<=b){
    s[k]=ch;
    t[k]=C[r-l]*ch;
    return;
  }
  if(r-l>1){
    int m=(l+r)/2;
    Set(a,b,ch,k*2+1,l,m);
    Set(a,b,ch,k*2+2,m,r);
    t[k]=t[k*2+1]*po[r-m]+t[k*2+2];
  }
}

ull Get(int a,int b,int k=0,int l=0,int r=(1<<18)){
  delay(k,l,r);
  if(b<=l || r<=a)return 0;
  if(a<=l && r<=b)return t[k];
  int m=(l+r)/2;
  ull vl=Get(a,b,k*2+1,l,m);
  ull vr=Get(a,b,k*2+2,m,r);
  return vl*po[calc(a,b,m,r)]+vr;
}

int n;
char str[MAX_N];

int main(){
  po[0]=1;
  for(int i=1;i<(1<<19);i++)po[i]=po[i-1]*B;
  C[1]=1;
  for(int i=1;i<(1<<19);i++)C[i]=C[i-1]*B+1;

  scanf("%d %s",&n,str);
  for(int i=0;i<n;i++){
    Set(i,i+1,str[i]);
  }

  int q,ax,bx,cx,dx;
  scanf("%d",&q);
  char tmp[10];
  while(q--){
    scanf("%s",tmp);
    if(tmp[0]=='s'){
      scanf("%d %d %s",&ax,&bx,tmp);
      ax--;
      Set(ax,bx,tmp[0]);
    }else if(tmp[0]=='c'){
      scanf("%d %d %d %d",&ax,&bx,&cx,&dx);
      ax--,cx--;

      int lenS=bx-ax;
      int lenT=dx-cx;

      int l=0,r=min(lenS,lenT)+1,m;
      while(r-l>1){
        m=(l+r)/2;
        if( Get(ax,ax+m) == Get(cx,cx+m) )l=m;
        else r=m;
      }
      if(l==min(lenS,lenT)){
        if(lenS<lenT)printf("s\n");
        else if(lenS>lenT)printf("t\n");
        else printf("e\n");
      }else{
        ull lastS=Get(ax+l,ax+l+1);
        ull lastT=Get(cx+l,cx+l+1);
        if(lastS<lastT)printf("s\n");
        else if(lastS>lastT)printf("t\n");
        else assert(0);
      }

    }
  }
  return 0;
}

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

#define Q int t; scanf("%d", &t); for(int q=1; q<=t; q++)
typedef long long int lli;
typedef pair<lli, int> pi;

#define N 100010
lli mod = 998244353;


int main()
{
    int n, m;
    cin >> n >> m;
    vector<string>gr;
    for(int i=0; i<n; i++){
        string s;
        cin >> s;
        gr.push_back(s);
    }
    int a[n][m], b[n][m];
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(gr[i][j] == '#'){
                a[i][j] = -1;
            }
            else{
                int cnt = 0;
                int jj = j;
                while(jj<m && gr[i][jj]=='.'){
                    cnt++;
                    jj++;
                }
                for(;j<m; j++){
                    if(gr[i][j] == '#'){
                        a[i][j] = -1;
                        break;
                    }
                    a[i][j] = cnt;
                }
            }
        }
    }
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++){
            if(gr[j][i] == '#'){
                b[j][i] = -1;
            }
            else{
                int cnt = 0;
                int jj = j;
                while(jj<n && gr[jj][i] == '.'){
                    cnt++;
                    jj++;
                }
                for(;j<n; j++){
                    if(gr[j][i] == '#'){
                        b[j][i] = -1;
                        break;
                    }
                    b[j][i] = cnt;
                }
            }
        }
    }
    int mx = 0;
    for(int i=0; i<n; i++){
        for(int j=0; j<m; j++){
            if(a[i][j] != -1 && b[i][j] != -1){
                mx = max(mx, a[i][j]+b[i][j]-1);
            }
        }
    }
    cout << mx << "\n";

    return 0;
}


Measured memory_bytes: 35584
import std.algorithm,
       std.string,
       std.array,
       std.stdio,
       std.range,
       std.conv;

long abs(long x) {
  return x * (x < 0 ? -1 : 1);
}

void main() {
  long   N = readln.chomp.to!long;
  long[] a = readln.chomp.split.to!(long[]);
  long ans = long.max;

  long[] dp1,
         dp2;
  dp1.length = N;
  dp2.length = N;

  for (size_t i = 0; i < N - 1; i++) {
    if (i == 0) {
      dp1[i] = a[i];
      dp2[i] = a[1..$].sum;
    } else {
      dp1[i] = dp1[i-1] + a[i];
      dp2[i] = dp2[i-1] - a[i];
    }

    long x = dp1[i],
         y = dp2[i];
    long z = abs(x - y);
    if (z < ans) {
      ans = z;
    }
  }

  writeln(ans);
}


Measured memory_bytes: 13440