akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

		int N = sc.nextInt();
		long[] A = new long[N+1];
		long[] B = new long[N];
		for( int i=0; i<N+1; i++ ){
			A[i] = sc.nextLong();
		}
		for( int i=0; i<N; i++ ){
			B[i] = sc.nextLong();
		}
		long ans = 0;
		for( int i=0; i<N; i++ ){
			if( B[i]<=A[i] ){
				ans += B[i];
			}else{
				if( B[i]<=A[i]+A[i+1] ){
					ans += B[i]; 
				}else{
					ans += A[i]+A[i+1];
				}
				A[i+1] -= B[i] - A[i];
				if( A[i+1]<0 ){
					A[i+1] = 0;
				}
			}
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 89236
using System;
using System.Collections.Generic;

class MyClass
{
    class Station
    {
        public string Name { get; set; }
        public int Time { get; set; }
    }

    static void Main(string[] args)
    {
        string[] str = Console.ReadLine().Split(' ');
        int n = int.Parse(str[0]);
        int t = int.Parse(str[1]);
        string[] time1 = new string[n];
        string[] sta1 = new string[n];
        string[] time2 = new string[n];
        string[] sta2 = new string[n];
        int count = 0;
        var list = new List<Station>();
        for (int i = 0; i < n; i++)
        {
            string[] str2 = Console.ReadLine().Split(' ');
            time1[i] = str2[0];
            sta1[i] = str2[1];
            time2[i] = str2[2];
            sta2[i] = str2[3];
        }
        for (int i = 0; i < n - 1; i++)
        {
            str = time2[i].Split(':');
            int arrival = int.Parse(str[0]) * 60 + int.Parse(str[1]);
            str = time1[i + 1].Split(':');
            int departure = int.Parse(str[0]) * 60 + int.Parse(str[1]);
            int stay = departure - arrival;
            if (stay >= t)
            {
                count++;
                var station = new Station();
                station.Name = sta2[i];
                station.Time = stay;
                list.Add(station);
            }
        }
        Console.WriteLine(count);
        foreach (var item in list)
        {
            Console.WriteLine("{0} {1}", item.Name, item.Time);
        }
    }
}


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

T RD(T)() { static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }

long mod = pow(10, 9) + 7;
long moda(long x, long y) { return (x + y) % mod; }
long mods(long x, long y) { return ((x + mod) - (y % mod)) % mod; }
long modm(long x, long y) { return (x * y) % mod; }

void main()
{
	auto N = RD!long;
	auto A = 0 ~ RDR.split.to!(long[]);
	A ~= 0;

	auto dp = new long[](N+2);

	foreach (i; 0..N+1)
	{
		dp[i+1] = dp[i] + abs(A[i+1] - A[i]);
	}

	foreach (i; 0..N)
	{
		writeln(dp[N+1] -  abs(A[i+1] - A[i]) - abs(A[i+2] - A[i+1]) + abs(A[i+2] - A[i]));
	}
	stdout.flush();
}

Measured memory_bytes: 5368
N,M,X,Y = map(int,input().split())
listx = list(map(int,input().split()))
listy = list(map(int,input().split()))
x_max = max(listx)
y_min = min(listy)
z_list = [i for i in  range(-100,101,1) if X<i and i<= Y]
z_list1 = [1 for z in z_list if x_max < z and y_min>= z]
if len(z_list1)>0:
  print("No War")
else:
  print("War")

Measured memory_bytes: 38384
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <functional>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

int main() {
    int n, m;
    cin >> n >> m;
    n++;
    string s;
    cin >> s;
    VI d(n, -1), x(n + 1, -1);
    d[0] = x[0] = 0;
    int j = 0;
    REP(i,n){
        if (s[i] == '1') continue;
        if (i > x[j]){
            j++;
            if (x[j] < i){
                cout << -1 << endl;
                return 0;
            }
        }
        d[i] = j;
        x[j + 1] = i + m;
    }

    int p = d[n - 1];
    if (p == -1){
        cout << -1 << endl;
        return 0;
    }

    VI d2(n, -1), x2(p + 1, 1e9);
    j = p;
    x2[p] = n - 1;
    FORR(i,n-1,0){
        if (s[i] == '1') continue;
        if (x2[j] > i){
            j--;
        }
        d2[i] = j;
        if (j > 0) x2[j - 1] = i - m;
    }

    VI b(p + 1, 1e9);
    REP(i,n){
        if (d2[i] != -1) chmin(b[d2[i]], i);
    }

    // REP(i,n) cout << d[i] << " ";
    // cout << endl;
    // REP(i,n) cout << d2[i] << " ";
    // cout << endl;

    REP(i,p) cout << b[i + 1] - b[i] << " ";
    cout << endl;

    return 0;
}


Measured memory_bytes: 2688
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define int long long

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;

template<typename T>T& max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T& min(T&a,T&b){if(a<b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<typename T>T get(){T a;cin>>a;return a;}
template<typename T>T rev(T a){reverse(all(a));return a;}
template<typename T>vector<T>&sort(vector<T>&a){sort(all(a));return a;}

const int inf = 3e18;
const double eps = 1e-9;

struct edge { int to, cost; edge(int to, int cost) : to(to), cost(cost) {} };
typedef vector<edge> edges;

edges G[100010];

int d[100010];
int to_max[100010];

signed main()
{ // #define int long long ?????????????????§scanf???????????¨???????????????????????\?????????????????????
    int N, M; cin >> N >> M;

    fill_n(to_max, 100010, -1);
    fill_n(d, 100010, inf);

    rep(i, M) {
        int a, b, c; cin >> a >> b >> c;
        G[a].PB(edge(b, c));

        if (b == N) {
            chmax(to_max[a], c);
        }
    }

    priority_queue<pii, vpii, greater<pii> > pq;

    pq.push(pii(0, 1));
    d[1] = 0;

    while (pq.size()) {
        pii p = pq.top(); pq.pop();

        int v = p.scd;

        if (d[v] < p.fst) continue;

        for (int i = 0; i < G[v].size(); ++i) {
            edge e = G[v][i];

            if (d[e.to] > e.cost && d[v] <= e.cost) {
                d[e.to] = e.cost;
                pq.push(pii(d[e.to], e.to));
            }
        }
    }

    int ans = -1;

    if (d[N] != inf) {
        for (int i = 1; i <= N; ++i) {
            if (d[i] != inf && d[i] <= to_max[i]) {
                chmax(ans, to_max[i]);
            }
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 12100
#include<stdio.h>

/*  */
int selectionSort(int A[], int N) {
    int i, j, t, sw = 0, minj;
    for ( i = 0; i < N - 1; i++ ) {
        minj = i;
        for ( j = i; j < N; j++ ) {
            if ( A[j] < A[minj] ) minj = j;
        }
        t = A[i]; A[i] = A[minj]; A[minj] = t;
        if ( i != minj ) sw++;
    }
    return sw;
}

int main() {
    int A[100], N, i, sw;

    scanf("%d", &N);
    for ( i = 0; i < N; i++ ) scanf("%d", &A[i]);

    sw = selectionSort(A, N);

    for ( i = 0; i < N; i++ ) {
        if ( i > 0) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n");
    printf("%d\n", sw);

    return 0;
}


Measured memory_bytes: 2056
#include <bits/stdc++.h> 
using namespace std;
using ll = long long;
template<typename T> using v2 = vector<vector<T>>;
template<typename T> inline v2<T> fill(int r, int c, const T& t){ return v2<T>(r, vector<T>(c, t)); }
#define F first
#define S second

const int MOD = 1e9+7;
inline int add(int a, int b){ return (a+b)%MOD; }
inline int sub(int a, int b){ return ((a-b)%MOD + MOD)%MOD; }
inline int mul(int a, int b){ return ((ll)a*b)%MOD; }

void solve(){
    int n, k;
    cin >> n >> k;
    vector<pair<int, int>> range;
    for(int i = 1; i*i <= n; ++i){
        range.push_back({n/i, 1});
    }
    int last = range.back().F;
    for(int i = last-1; i > 0; --i){
        range.push_back({i, n/i-n/(i+1)});
    }

    int l = range.size();

    v2<int> dp = fill(k, l, 0);
    v2<int> pref = fill(k, l, 0);
    for(int j = 0; j < l; ++j){
        dp[0][j] = range[j].S;
    }
    pref[0][0] = dp[0][0];
    for(int j = 1; j < l; ++j){
        pref[0][j] = add(pref[0][j-1], dp[0][j]);
    }

    for(int i = 1; i < k; ++i){
        for(int j = 0; j < l; ++j){
            dp[i][j] = mul(range[j].S, pref[i-1][l-1-j]);
        }

        pref[i][0] = dp[i][0];
        for(int j = 1; j < l; ++j){
            pref[i][j] = add(pref[i][j-1], dp[i][j]);
        }
    }

    cout << pref[k-1][l-1] << "\n";
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

Measured memory_bytes: 53324
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const int INF = 1e9;
typedef pair<int, pair<int, int>> P;

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

int main()
{
    int H, W, CH, CW, DH, DW;
    cin >> H >> W >> CH >> CW >> DH >> DW;
    vector<string> maze(H);
    CH--; CW--; DH--; DW--;
    rep(i, H) cin >> maze[i];

    vector<vector<int>> res(H, vector<int>(W, INF));
    priority_queue<P, vector<P>, greater<P>> que;
    res[CH][CW] = 0;
    que.push({0, {CH, CW}});
    while (!que.empty()) {
        int d = que.top().first;
        int y = que.top().second.first, x = que.top().second.second;
        que.pop();
        if (res[y][x] < d) continue;
        for (int j = -2; j <= 2; j++) {
            for (int k = -2; k <= 2; k++) {
                if (j == 0 && k == 0) continue;
                int cx = 1;
                if (abs(j) + abs(k) == 1) cx = 0;
                int tx = x + j, ty = y + k;
                if (tx < 0 || tx >= W || ty < 0 || ty >= H || maze[ty][tx] == '#') continue;
                if (res[ty][tx] > d + cx) {
                    res[ty][tx] = d + cx;
                    que.push({res[ty][tx], {ty, tx}});
                }
            }
        }
    }
    int ans = res[DH][DW];
    if (ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 9596
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;

int main()
{
    ll n;
    string s;
    cin >> n;
    cin >> s;
    vector<vector<ll>> dp(n + 1, vector<ll>(n + 1, 0));
    ll ans = 0;
    for (ll i = n - 1; i >= 0; i--)
    {
        for (ll j = n - 1; j >= 0; j--)
        {
            if (s[i] == s[j])
            {
                dp[i][j] = min(dp[i + 1][j + 1] + 1, abs(i - j));
            }
            ans = max(ans, dp[i][j]);
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 195840
#define _CRT_SECURE_NO_WARNINGS // #pragma warning(disable:4996)
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <functional>
#include <sstream>
#include <cmath>
#include <set>
#include <map>
#include <stack>
using namespace std; 

#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
#define mp(a,b) make_pair(a,b)
#define all(a) a.begin(),a.end()
#define len(x) ((int)(x).size())
#define tmax(a,b,c) max((a),max((b),(c)))
#define tmin(a,b,c) min((a),min((b),(c)))
#define debug(x) cerr << #x << " is " << x << endl;

typedef pair<int, int> Pii;
typedef map<int, int> Mii;
typedef vector<int> Vi;
typedef long long ll;
const int inf = 2e9;
const ll ll_inf = 1e17;
const int mod = 1e9 + 7;
const long double eps = 1e-10;

int p[1322501];

int main()
{
	rep(i,2,1150) {
		int j = i;
		while (j+i < 1322500) {
			j += i;
			p[j]++;
		}
	}

	while (1) {
		int n; cin>>n;
		if (!n) break;
		if (!p[n]) cout << 0 << endl;
		else {
			int l=n, r=n;
			while (p[l]) l--;
			while (p[r]) r++;
			cout << r-l << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 6324
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define rep1(i,n) for(int i=1;i<=(int)n;i++)
#define sp(n) cout << fixed << setprecision(n)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    ll n,m;cin>>n>>m;
    priority_queue<pair<ll,ll>> que;
    rep(i,n){
        ll a;cin>>a;
        que.push({a,1});
    }
    rep(i,m){
        ll b,c;cin>>b>>c;
        que.push({c,b});
    }
    ll tmp=0,res=0;
    while(tmp<n){
        ll x=que.top().first,y=que.top().second;que.pop();
        ll buf=min(y,n-tmp);
        tmp+=buf;
        res+=x*buf;
    }
    cout<<res<<endl;
}


Measured memory_bytes: 7464
#pragma GCC optimize("O3")
//#pragma GCC target("avx2")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (int i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    string s, t;
    cin >> s >> t;

    reverse(ALL(s));
    if (s == t) print("YES");
    else print("NO");
    
}


Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1001001001;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int dx[4] = {1,0,-1,0};
const int dy[4] = {0,1,0,-1};

int main() {
ll n;
cin >> n;
vector<ll> vec(n);
cin >> vec.at(0);
ll maxi = vec.at(0),ans = 0;

for (int i = 1;i < n;i++) {
  cin >> vec.at(i);
  if (vec.at(i) > maxi) maxi = vec.at(i);
  ans += maxi-vec.at(i);
  
}
cout << ans << endl;

return 0;
}



Measured memory_bytes: 4848
#include "bits/stdc++.h"
using namespace std;
using ll  = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
#define double long double
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    const double pi = 3.141592653589793;
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    double ok = 0;
    double ng = 90;
    if (abs(a * b / 2.0 - x) < 1e-10) {
        cout << 45.00000 << "\n";
        return 0;
    } else if (a * b / 2.0 - x > 0.0) {
        // ok         = 45;
        // auto check = [&](double mid) {
        //     double rad = pi * (90.0 - mid) / 180.0;
        //     double l   = b * sin(rad) * b / cos(rad) / 2.0;
        //     return l > x;
        // };
        // while (ng - ok > 1.0e-10) {
        //     double mid = (ng + ok) / 2.0;
        //     if (check(mid))
        //         ok = mid;
        //     else
        //         ng = mid;
        // }
        ok = 90 - atan(x / b / b * 2.0) / pi * 180;
    } else {
        // ng         = 45;
        // auto check = [&](double mid) {
        //     double rad = pi * (mid) / 180.0;
        //     double l   = a * sin(rad) * a / cos(rad) / 2.0;
        //     return l < (a * b - x);
        // };
        // while (ng - ok > 1.0e-10) {
        //     double mid = (ng + ok) / 2.0;
        //     if (check(mid))
        //         ok = mid;
        //     else
        //         ng = mid;
        // }
        ok = atan((a * b - x) / a / a * 2.0) / pi * 180;
    }
    cout << fixed << setprecision(15) << ok << "\n";
    return 0;
}

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

public class Main{
    public static void main(String[] args){
        int count = 0;
        long[] input = null;
        long[] box = null;
        BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
        try{
            String str = bufferedReader.readLine();
            String str2 = bufferedReader.readLine();
            String[] st = str2.split(" ");
            count = Integer.parseInt(str);
            input = new long[count];
            box = new long[count+1];
            int c = 0;
            for(String s: st){
                int a = Integer.parseInt(s);
                input[c] = a;
                box[a]++;
                c++;
            }
        } catch (IOException e){
            e.printStackTrace();
        }
        if(box[0] != 1L || input[0] != 0L){
            System.out.println(0);
        } else{
            long ans = 1;
            for(int i = 1;i < count;i++){
                ans = (ans % 998244353L) * (pow(box[i],box[i+1]) % 998244353L) % 998244353L;
                if(ans == 0L){
                    break;
                }
            }
            System.out.println("" + ans);
        }

    }
    public static long pow(long a,long b){
        long s = 1L;
        for(long i = 0;i < b; i++){
            s = s * a % 998244353L; 
        }
        return s;
    }
}

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

#define INF 1e9
using namespace std;

int main() {

    int N; cin >> N;
    string s; cin >> s;


    int blue = 0;
    int red = 0;
    for (int i = 0; i < N; ++i) {
        if (s[i] == 'B') {
            ++blue;
        } else {
            ++red;
        }
    }

    if (red > blue) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
c = list(input())

first = int(c[0]+c[1])
last = int(c[2]+c[3])

if first <= 12 and first > 0:
    if last <= 12 and last > 0:
        print("AMBIGUOUS")
    else:
        print("MMYY")
elif last <= 12 and last > 0:
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 3060
import sys
def input(): return sys.stdin.readline().strip()
def mapint(): return map(int, input().split())
sys.setrecursionlimit(10**9)

N = int(input())
from collections import defaultdict
dic = defaultdict(int)
for x in range(1, 101):
    for y in range(1, 101):
        for z in range(1, 101):
            dic[x**2+y**2+z**2+x*y+y*z+z*x] += 1

for i in range(1, N+1):
    print(dic[i])

Measured memory_bytes: 72564
#include <iostream>

using namespace std;

int main()
{
    int n,counta=0,countt=0,countr=0,countw=0;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        if(s[0]=='A') counta++;
        if(s[0]=='W') countw++;
        if(s[0]=='T') countt++;
        if(s[0]=='R') countr++;
    }
    cout<<"AC x "<<counta<<endl;
    cout<<"WA x "<<countw<<endl;
    cout<<"TLE x "<<countt<<endl;
    cout<<"RE x "<<countr<<endl;
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define ll int
#define loop(i,x,n) for(ll i= x;i<n;i++)




int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    string a,b;
    cin>>a>>b;
    b[b.size()-1] = '0';
    a.append("0");
    cout<<(a==b?"Yes":"No");
}

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

int main()
{
    stack<int> S1;
    stack<pair<int, int> > S2;
    char ch;
    int sum =0;
    for(int i=0; cin>>ch; i++)
    {
        if(ch == '\\') S1.push(i);
        else if(ch == '/' && S1.size() > 0)
        {
            int j = S1.top(); S1.pop();
            sum += i - j;
            int a = i-j;
            while(S2.size() > 0 && S2.top().first > j)
            {
                a += S2.top().second; S2.pop();
            }
            S2.push(make_pair(j, a));
        }
    }

    vector<int> ans;
    while(S2.size() > 0)
    {
        ans.push_back(S2.top().second);
        S2.pop();
    }
    reverse(ans.begin(), ans.end());
    cout<<sum<<endl;
    cout<<ans.size();
    for(int i=0; i<ans.size(); i++)
    {
        cout<<" ";
        cout<<ans[i];
    }
    cout<<endl;

    return 0;
}


Measured memory_bytes: 3212
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;
typedef long long ll;

int n;
ll total;

bool findPattern() {
  vector<ll> xy;
  for (int i=0;i<=n;i++) {
    for (int j=0;j+i<=n;j++) {
      ll diff = total - 10000 * i - 5000 * j;
      if (diff / 1000 == (n - i - j)) {
        cout << i << " " << j << " " << (n - i - j) << endl;
        return true;
      }
    }
  }
  return false;
}
void solve() {
  if (!findPattern()) {
    cout << "-1 -1 -1" << endl;
  }
}

int main() {
  cin >> n >> total;
  solve();
}


Measured memory_bytes: 256
n=int(input())
a=input()
b=input()
c=input()
x=0
for i in range(n):
    if a[i]==b[i]==c[i]:pass
    elif a[i]==b[i] or b[i]==c[i] or c[i]==a[i]:x+=1
    else:x+=2
print(x)

Measured memory_bytes: 3060
int n;int a[10005];int main(){__builtin_scanf("%d",&n);long long x=0,y=0,z=0;
for(int i=0;i<n;++i)__builtin_scanf("%d",a+i);for(int i=0;i<n;++i){int x;__builtin_scanf("%d",&x);a[i]-=x;x-=a[i];
if(a[i]<0)z-=a[i]/2;else y+=a[i];}if(x>=0 && y<=z)__builtin_puts("Yes");else __builtin_puts("No");}

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

int main() {
  int n;
  cin >> n;
  vector<char> a(n);
  rep(i,n) cin >> a[i];
  int ans = 0;
  rep(i,n) {
    set<char> b;
    int cnt = 0;
    rep(j,i) b.insert(a[j]);
    for(int k = n-1; k >= i; k--) {
      if(b.count(a[k])) cnt++;
      b.erase(a[k]);
    }
    ans = max(ans,cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

int main(){
	
	while(1){
		int a,b;
		int t[111];
		int h[111];
		cin>>a>>b;
		if(a==0 && b==0)break;
		
		rep(i,a)cin>>t[i];
		rep(i,b)cin>>h[i];
		
		int inf = 1111111111;
		int mini = inf;
		
		int ans1,ans2;
		
		rep(i,a){
			rep(j,b){
				swap(t[i],h[j]);
				
				int sumt=0;
				int sumh=0;
				rep(k,a)sumt+=t[k];
				rep(k,b)sumh+=h[k];
				
				if(sumt==sumh){
					int r = t[i]+h[j];
					if(r<mini){
						ans1 = t[i];
						ans2 = h[j];
						mini=r;;
					}
				}
				
				swap(t[i],h[j]);
			}
		}
		
		if(mini==inf)puts("-1");
		else printf("%d %d\n",ans2,ans1);
	}
}

Measured memory_bytes: 1148
import sys
sys.setrecursionlimit(2147483647)
INF=float("inf")
MOD=10**9+7
# input=lambda :sys.stdin.readline().rstrip()
def resolve():
    class UnionFind(object):
        """
        query: O(Ack^-1(n,n)) (amortize)
        """
        def __init__(self,n):
            """
            param n: number of nodes
            """
            self.__par=list(range(n))
            self.__rank=[0]*n
            self.__size=[1]*n

        def __root(self,k):
            if self.__par[k]==k: return k
            else:
                self.__par[k]=self.__root(self.__par[k])
                return self.__par[k]

        def is_same(self,i,j):
            return self.__root(i)==self.__root(j)

        def unite(self,i,j):
            i=self.__root(i)
            j=self.__root(j)
            if i==j: return
            if self.__rank[i]>self.__rank[j]:
                self.__par[j]=i
            else:
                self.__par[i]=j
                if self.__rank[i]==self.__rank[j]: self.__rank[j]+=1

    # 候補となるedgesは2N-2個しかないため、全列挙
    # Kruskal's algorithmでuniteしていく
    from operator import itemgetter
    n=int(input())
    P=[0]*n
    edges=[0]*(2*n-2)
    for i in range(n):
        x,y=map(int,input().split())
        P[i]=(x,y,i)
    # xでsort
    P.sort(key=itemgetter(0))
    for k in range(n-1):
        x0,y0,i=P[k]
        x1,y1,j=P[k+1]
        edges[k]=(i,j,min(abs(x0-x1),abs(y0-y1)))
    # yでsort
    P.sort(key=itemgetter(1))
    for k in range(n-1):
        x0,y0,i=P[k]
        x1,y1,j=P[k+1]
        edges[k+n-1]=(i,j,min(abs(x0-x1),abs(y0-y1)))
    # edgesをcostでsort
    edges.sort(key=itemgetter(2))
    # union findに突っ込んでいく
    tree=UnionFind(n)
    ans=0
    for i,j,cost in edges:
        if tree.is_same(i,j): continue
        tree.unite(i,j)
        ans+=cost
    print(ans)

resolve()

Measured memory_bytes: 128588
import java.util.*;
public class Main {
    public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
    	int i,j,N;
    	int reg=0;
    	int[] ary = new int[1001];
    	for(i=0;i<1001;i++){
    		ary[i]=0;
    	}
    	
    	for(i=1;i<=1000;i++){
    		for(j=2,reg=i;j<=50;j++){
    			reg=reg+i+j-1;
    			if(reg<=1000){
    			    ary[reg]++;	
    			}else{
    				break;
    			}
    		}
    			
    	}
    	while((N = sc.nextInt())!=0){
    		System.out.println(ary[N]);
    	}
    }
}


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

using namespace std; 

typedef string str;
typedef long double db;

#define nl "\n"
#define sp " "
#define fi first
#define se second
#define pb push_back
#define ins insert

#define int long long
#define toint stoll
#define tostr to_string

#define hashmap unordered_map
#define hashset unordered_set

#define llMin LLONG_MIN
#define llMax LLONG_MAX

const int mod = 1e9 + 7;

signed main(){
    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    //cout << fixed << setprecision(10);
    int n; cin >> n; vector<int> v(n);
    for (int i = 0; i < n; i++){
        cin >> v[i];
    }
    int sum = 0;
    for (int i = 1; i < n; i++){
        if (v[i] < v[i-1]){
            sum += (v[i-1] - v[i]);
            v[i] += (v[i-1] - v[i]);
        }
    }
    cout << sum;
}


Measured memory_bytes: 4748
n = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))
ans = 0
prev = -1
for i in A:
    ans += B[i-1]
    if prev == i-1:
        ans += C[i-2]
    prev=i
print(ans)

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

using namespace std;

const int MX = 100000;

vector<int> G[MX];

pair<int, bool> dfs(int v, int p = -1) {
	int res = 0;
	bool hadZero = false;
	for (int u : G[v]) {
		if (u == p) continue;
		auto x = dfs(u, v);
		if (x.first == 0 && hadZero) {
			x.first = 1;
			x.second = false;
		}
		res += x.first;
		hadZero = hadZero || x.first == 0;
	}
	
	return make_pair(res, hadZero);
}

int main() {
	int n;
	ignore = scanf("%d", &n);
	for (int i = 1, u, v; i < n; i++) {
		ignore = scanf("%d %d", &u, &v);
		G[u].emplace_back(v);
		G[v].emplace_back(u);
	}
	
	int r = 0;
	while (r < n && G[r].size() < 3) r++;
	
	if (r == n) {
		printf("1\n");
		return 0;
	}
	
	auto ans = dfs(r);
	printf("%d\n", ans.first);
	
	return 0;
}


Measured memory_bytes: 9088
#include<cstdio>
#include<math.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<set>
#include<cstring>
 
 
using namespace std;
#define int long long int
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1001001001
#define LLINF 1001001001001001001
#define mp make_pair
#define pb push_back

int A,B;
char S[1000];
signed main(){
    scanf("%s",&S);
    rep(i,strlen(S))printf("x");
    printf("\n");
    return 0;
}


Measured memory_bytes: 128
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, accumulate
from operator import itemgetter, mul
from copy import deepcopy,copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd

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

def main():
    s = input()
    t = input()
    ans = 0

    for i in range(3):
        if s[i] == t[i]:
            ans +=1
    print(ans)

if  __name__=='__main__':
    main()

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


long long a[2005][2005]={0};

int main()
{
  int n,k;
  scanf("%d %d",&n,&k);
  for(int i=0;i<=n+2;i++)
  {
  a[i][0]=1;
    for(int j=1;j<=i;j++)
    a[i][j]=(a[i-1][j-1]+a[i-1][j])%1000000007;
  }

   int t=n-k+1;long long ans,tt=t,kk=1,kt=1;
  for(int i=1;i<=k;i++)
  {
  if(n-k+1>=i&&t>0)
  {
    ans=a[n-k+1][i]*a[k-1][i-1]%1000000007;
  /*  t--;

     tt*=t;
     kt++;
     kk*=kt;*/
  }
   else
   ans=0;
    // printf("A %lld %lld %lld\n",tt,kk,a[k-1][i-1]);


   printf("%lld\n",ans);
  }



}


Measured memory_bytes: 30208
#include<bits/stdc++.h>
using namespace std;
typedef  long long   ll;
ll inf=1000000000000000000,mod=1000000007;
int main(){
    ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        
        ll n,m;cin>>n>>m;
        ll arr[n],vis[n+1]={0};vector<ll> ans[n+1],anss;
        for(ll i=0;i<n;i++){
            cin>>arr[i];
            ans[i+1].push_back(arr[i]);
        }
        ll curr=1,idx;
        while(1){
            if(vis[curr]){idx=curr;break;}
            vis[curr]=1;
            anss.push_back(curr);
            curr=ans[curr][0];
        }
        n=anss.size();ll temp;
        if(m<n)
        cout<<anss[m]<<endl;
        else{
            temp=-1;
            for(ll i=0;i<n;i++){
                if(anss[i]==idx)break;
                m--;temp=i;
            }
            m%=(n-temp-1);
            cout<<anss[1+temp+m];
        }
}


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

using namespace std;

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

    int A[100];
    int sum = 0;

    for (int i = 0; i < N; ++i) {
        cin >> A[i];
        sum += A[i];
    }

    int cnt = 0;
    float thr = float(sum) / (4 * M);
    for (int i = 0; i < N; ++i) {
        if (float(A[i]) >= thr) {
            cnt += 1;
        }
    }

    if (cnt < M) {
        cout << "No";
    } else {
        cout << "Yes";
    }

    return 0;
}


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

int main(){
  int N;
  cin >> N;
  int ans = 1;
  int num_100 = 0;
  int num_10 = 0;
  int num_1 = 0;
  
  num_100 = N /100;
  num_10  = (N / 10) % 10;
  num_1   = N % 10;
  
  if(num_100 < num_10){
    ans = num_100 + 1; 
  }
  else if( (num_100 == num_10) && (num_100 < num_1) ){
    ans = num_100 + 1; 
  }
  else if(num_100 == num_10 && num_100 == num_1){
    ans = num_100;
  }
  else{
    ans = num_100;
  }
 cout << ans * 111 << endl;
}

Measured memory_bytes: 256
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
            佛祖保佑       永无BUG
*/
#include<stdio.h>
#define re register
char s[505][505],a[505][505],b[505][505];
int h,w;
int main()
{
	scanf("%d%d",&h,&w);
	for(re int i=1;i<=h;++i)
		scanf("%s",s[i]+1);
	for(re int i=1;i<=h;++i)
		for(re int j=1;j<=w;++j)
			a[i][j]=b[i][j]=s[i][j];
	for(re int i=1;i<=w;++i)
		a[1][i]='#',b[h][i]='#';
	for(re int j=1;j<=w;++j)
		if(j&1) for(re int i=1;i<h;++i) a[i][j]='#';
		else for(re int i=2;i<=h;++i) b[i][j]='#';
	for(re int i=1;i<=h;++i) 
	{
		for(re int j=1;j<=w;++j)
			putchar(a[i][j]);
		printf("\n"); 
	}
	printf("\n");
	for(re int i=1;i<=h;++i)
	{
		for(re int j=1;j<=w;++j)
			putchar(b[i][j]);
		printf("\n");
	}	
	return 0;		
} 

Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }
 
int main(){
    vector<ll> A(3);
    REP(i, 3) cin >> A[i];
    ASC(A);
    cout << A[1]-A[0] + A[2]-A[1] << "\n";
}


Measured memory_bytes: 256
let () = Scanf.scanf "%d %d %d" @@ fun r d x2000 ->
  let xs = Array.make 11 0 in
  xs.(0) <- x2000;
  for i = 1 to 10 do
    xs.(i) <- r * xs.(i - 1) - d;
    Printf.printf "%d\n" xs.(i)
  done

Measured memory_bytes: 3792
#include<bits/stdc++.h>
#define rep(i,n)  for(ll i=0; i<n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF 1e9
using ll = long long;
using namespace std;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main(){
  char x; cin >> x;
  if('A' <= x && x <= 'Z') cout << "A";
  else cout << "a";
  return 0;
}


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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
vl modinv;
void fillModInv(ll n, ll mod){
  modinv = vl(n+1);
  modinv[1] = 1;
  FOR(i,2,n+1){
    modinv[i] = modinv[mod%i] * (mod - mod/i) % mod;
  }
}
/*}}}*/
int main() {
  ll h,n;
  cin >> h >> n;
  ll sum = 0;
  REP(i,n){
    ll ai;
    cin >> ai;
    sum += ai;
  }
  
  //cout << fixed << setprecision(10);
  if(sum<h) cout << "No" << endl;
  else cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 256
ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n,m = mi()
hlis = li()
A = [[]for _ in range(n)]
for i in range(m):
    a,b = mi()
    A[a-1].append(b-1)
    A[b-1].append(a-1)

ans = 0
for i in range(n):
    ima = hlis[i]
    flag = 1
    for k in A[i]:
        if ima <= hlis[k]:
            flag = 0
            break
    if flag:
        ans += 1



print(ans)

Measured memory_bytes: 93168
#![allow(
  non_snake_case,
  unused_variables,
  unused_assignments,
  unused_mut,
  unused_imports,
  unused_macros,
  dead_code
)]
//use proconio::fastout;
use proconio::{input, marker::*};
use std::cmp::*;
use std::collections::*;
//use std::collections::VecDeque;

macro_rules! debug {
  ($($a:expr),* $(,)*) => {
      #[cfg(debug_assertions)]
      eprintln!(concat!($("| ", stringify!($a), "={:?} "),*, "|"), $(&$a),*);
  };
}

fn main() {
  input! {
     N:usize,A:[usize;N],B:[usize;N]
  }
  let N: usize = N;
  let A: Vec<usize> = A;
  let B: Vec<usize> = B;
  let mut n = vec![0; N + 1];
  for i in 0..N {
    n[A[i]] += 1;
    n[B[i]] += 1;
  }
  for i in 0..N {
    if n[i] > N {
      println!("No");
      return;
    }
  }
  let mut d = 0;
  let mut flag = true;
  while flag {
    flag = false;
    for i in 0..N {
      while A[i % N] == B[(i + d) % N] {
        flag = true;
        d += 1;
        if d >= N {
          println!("No");
          return;
        }
      }
    }
  }
  println!("Yes");
  for i in 0..N {
    print!("{} ", B[(i + d) % N]);
  }
}


Measured memory_bytes: 9376
#include <bits/stdc++.h>
  using namespace std;
  const long mxN =1e5+2 ;
  signed main() {
    int n,m;
    cin >> n>> m ;
    vector<vector<int>>adj(n+1) ;
    for(int i=0,a,b;i<m;i++)
      cin >> a >> b,adj[a].push_back(b);
    // for(auto x:adj){
    //   for(auto y:x)
    //     cout << y  << " " ;
    //   cout << endl ;
    // }
    vector<int>dp(n+1) ;int ans=-1 ;
    function<int(int)> dfs=[&](int v){
      if(!dp[v]){
        dp[v]=0;
        for(int x:adj[v])
          dp[v]=max(dp[v],dfs(x));
        dp[v]++ ;
        ans=max(ans,dp[v]) ;
      } return dp[v] ;
    };
    for(int i=1;i<=n;i++)
      ans=max(ans,dfs(i));
    cout << ans-1 ;
  }

Measured memory_bytes: 11792
n, k, q = [ int(_) for _ in input().split() ]
a = [ int(input()) for _ in range(q) ]

p = [ k for _ in range(n) ]

p = [ y-q for y in p ]

for x in a:
	p[x-1] += 1

ans = []

for z in p:
	if z > 0:
		ans.append('Yes')
	else:
		ans.append('No')

for blah in ans:
	print(blah)

Measured memory_bytes: 12580
#include <stdio.h>
#define N 51
int main(int argc, const char * argv[]) {
    int n,p,wan,candidate[N][2],i;
    //candidate 0 ??£??¢ 1 ????????°
    while (1) {
        
        scanf("%d %d",&n,&p);
        
        if (n == 0 && p == 0) {
            break;
        }
        
       
        for (i = 0; i < n; i++) {
            candidate[i][0] = i;
            candidate[i][1] = 0;
        }
        
        
        wan = p;
        
        i = 0;
        
        while (1) {
            
            if (i > n-1) {
                i = 0;
            }
            
            if (wan > 0) {
                wan--;
                candidate[i][1]++;
                if (candidate[i][1] == p) {
                    printf("%d\n",candidate[i][0]);
                    break;
                }
                
                i++;
                continue;
            }
            
            if (wan <= 0) {
                wan = candidate[i][1];
                candidate[i][1] = 0;
                i++;
            }
            
        }
        
        
    }
    return 0;
}

Measured memory_bytes: 600
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cmath>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define F first
#define S second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
int n,m; 
char c[2010][2010];
int a[2010][2010][4];
int res;
int main()
{
	scanf("%d%d",&n,&m);
	for (int i=0;i<n;i++) scanf("%s",&c[i]);
	for (int i=0;i<n;i++)
	{
		a[i][0][0]=(c[i][0]=='#' ? 0 : -1);
		for (int j=1;j<m;j++)
		    a[i][j][0]=(c[i][j]=='#' ? j : a[i][j-1][0]); 
		a[i][m-1][1]=(c[i][m-1]=='#' ? m-1 : m);
		for (int j=m-2;j>=0;j--)
		    a[i][j][1]=(c[i][j]=='#' ? j : a[i][j+1][1]); 
	}
	for (int j=0;j<m;j++)
	{
		a[0][j][2]=(c[0][j]=='#' ? 0 : -1);
		for (int i=1;i<n;i++)
		    a[i][j][2]=(c[i][j]=='#' ? i : a[i-1][j][2]); 
		a[n-1][j][3]=(c[n-1][j]=='#' ? n-1 : n);
		for (int i=n-2;i>=0;i--)
		    a[i][j][3]=(c[i][j]=='#' ? i : a[i+1][j][3]); 
	}
	/*for (int tr=0;tr<4;tr++)
	{
		for (int i=0;i<n;i++)
		{
			for (int j=0;j<m;j++)
			{
				cout <<a[i][j][tr]<<" "; 
			}
			cout <<"\n";
		}
		cout <<"\n";
	}*/
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<m;j++)
		{
			if (c[i][j]=='#') continue;
			int r=0;
			r+=a[i][j][1]-a[i][j][0]-1;
			r+=a[i][j][3]-a[i][j][2]-1;
			r--;
			res=max(res,r);
		}
	}
	cout <<res;
	return 0;
} 

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

typedef long long int lli;
#define pb push_back
#define gcd __gcd
#define MOD 1000000007
#define mod2 998244353
#define forz(i,n) for(long long int i=0;i<n;i++)
char A[51][51];
set<pair<lli,lli>> s1,s2;
set<pair<lli,lli>>::iterator i1,i2;

lli mod(lli a){
    if(a<0) return -1*a;
    return a;
}

bool comp(pair<lli,lli> a,pair<lli,lli> b){
    return 0;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lli t=1,u,j;
    //cin>>t;
    for(u=1;u<=t;u++){
        lli n,m,i,j,p=0,c,q=0,k,a,b,x,y,ne=0,p1=0,p2=0,p3=0,p4=0,q1=0,k1,k2,a1,a2;
        cin>>n;
        lli A[n];
        for(i=0;i<n;i++) cin>>A[i];
        sort(A,A+n);
        multiset<lli> solve;
        multiset<lli>::iterator itr;
        
        if(n==2) {
            cout<<A[1]<<endl;
            continue;
        }
        if(n==3){
            cout<<A[1]+A[2]<<endl;
            continue;
        }
        solve.insert(A[n-1]);
        for(i=n-2;i>=0;i--){
            itr=solve.end();
            itr--;
            p=*itr;
            solve.erase(itr);
            solve.insert(A[i]);solve.insert(A[i]);
            q+=p;
        }
        cout<<q<<endl;
    }
}

Measured memory_bytes: 14596
#include<bits/stdc++.h>
    using namespace std;
  #define int long long int
    #define endl "\n"
    #define MOD 1000000007
    #define mod 1000000007
    #define M 1000000007
    
    #define pb push_back
    #define take(a,b,c) for(int b=0;b<c;b++) cin>>a[b]
  //  #define mp make_pair
  #define boost ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);  
  #define mx 400005
  #define fiint(a,b) memset(a,b,sizeof(a))  
  #define bitcount __builtin_popcount
  #define fori(i,a,b) for(int i=a;i<b;i++)
  #define ford(i,a,b) for(int i=a;i>=b;i--)
  #define debug(x) cout<<x<<endl;
  #define cases(t) int t; cin>>t; while(t--)
  #define inf1 INT_MAX
  #define all(a) a.begin(),a.end()
  #define vec vector<int>
  #define pii pair<int,int>
  #define plii pair<int,int>
  #define pint pair<int,int>
  #define ff first
  #define ss second
  #define lb lower_bound
  #define ub upper_bound
  #define bs binary_search
  #define sz(x) (int)x.size()
#define PI                    3.14159265359

bool prime[10000001];

void sieveFunction(int maxLimit){
    memset(prime, true, sizeof(prime));
    prime[0] = prime[1]=false;
    for(int i=2; maxLimit >= i ; i++){
        if(prime[i]){
            for(int j=2*i ; maxLimit >= j ; j+=i)
                prime[j]=false;
        }
    }
}



	double ex[305][305][305];
	double p[305][305][305];
signed  main() 
{ 
	int n;cin>>n;
	vector<int> a(n + 1 ),cnt(4);
	fori(i,1,n+1){cin>>a[i];     cnt[a[i]]++; }
	//cout<<"Sds"<<endl;
	p[cnt[1]][cnt[2]][cnt[3]]=1;
	for(int c = n ; c>=0 ; c--)
			for(int  b= n ; b >= 0 ; b-- )
				for(int a = n ; a >= 0 ;a--  )
					{	

						if(a+c+b > n) continue;
						if(a==0 && b==0 && c==0)
							continue;
						double pw = (double)(n - (a+b+c) )/n;
						double ew = pw / (1 - pw)  + 1;
						ex [a][b][c] += ew *  p[a][b][c]; 

						if(c!=0)
							{ 
								double temp = (double) c/(a+b+c); 
								p[a][b+1][c-1]  += p[a][b][c] * temp; 
								ex[a][b+1][c-1] += ex [a][b][c] * temp;
							
							}
						if(b!=0)
							{ 
								double temp = (double) b/(a+b+c); 
								p[a+1][b-1][c]  += p[a][b][c] * temp;  
							    ex[a+1][b-1][c] += ex [a][b][c] * temp;            
			                }
						if(a!=0)
							{ 
								double temp = (double) a/(a+b+c); 
								p[a-1][b][c]  += p[a][b][c] * temp;         
								ex[a-1][b][c] += ex [a][b][c] * temp;

							}
						
					}

		printf("%.10lf\n", ex[0][0][0]); 	
}




 


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

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


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

int main(void) {
	const string dd("TLURD");
	string boin("aiueo");
	string siin("kstnhmyrw");

	string str;

	cin >> str;
	int N = str.size();

	for (int i = 0; i < N; i+=2) {
		int num = str[i] - '0';
		char d = str[i + 1];

		// テ」ツつ?
		if (num == 0 && d == 'U') {
			cout << "nn";
			continue;
		}
		
		// テ」ツつ? テ」ツつ?
		if (num == 0 && d == 'D') {
			cout << "wo";
			continue;
		}
		if (num == 0 && d == 'T') {
			cout << "wa";
			continue;
		}

		char b = boin[dd.find(d)];

		// テヲツッツ催ゥツ淞ウテ」ツ?ョテ」ツ?ソ
		if (num == 1) {
			cout << b;
			continue;
		}

		// テ」ツ?敕」ツ?ョテ、ツサツ?
		char s = siin[num - 2];
		cout << s << b;
	}

	cout << endl;
	

	return 0;
}

Measured memory_bytes: 1188