akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define all(a) a.begin(), a.end()
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define debug(x) cerr<<#x<<" -> "<<x<<'\n'
#define debug2(x,y) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<'\n'
#define debug3(x,y,z) cerr<<#x<<" -> "<<x<<" "<<#y<<" -> "<<y<<" "<<#z<<" -> "<<z<<'\n'

 
using namespace std;
using namespace __gnu_pbds;
typedef long long ll;

using ordered_set = tree<ll , null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>;

template<typename T>
struct CMP {
	bool operator() (const T& lhs, const T& rhs) const{
		return lhs < rhs;
	}
};

template <typename T>
T power(T a, T n){
	T res = 1;
	while(n > 0){
		if(n & 1) res = (res * a);
		a = (a * a);
		n >>= 1;
	}
	
	return res;
}

template <typename T>
T power(T a, T n, long long mm){
	T res = 1;
	while(n > 0){
		if(n & 1) res = (res * a) % mm;
		a = (a * a) % mm;
		n >>= 1;
	}
	
	return res;
}

const ll N = 2e5+7;
const ll MOD = 1e9+7;
const ll INF = 2e14+7;

int dp[N];

void testcase(){
	int n, k;
	cin>>n>>k;
	int arr[n];
	
	for(int i = 0; i < n; i++) cin>>arr[i];
	
	for(int i = 0; i <= k; i++){
		if(dp[i]) continue;
		for(int j = 0; j < n; j++){
			dp[i + arr[j]] = 1;
		}
	}
	
	cout<<(dp[k] ? "First" : "Second")<<'\n';
	
}

signed main(){
	fast;
	
	int t = 1;
	//cin>>t;
	while(t--){
		testcase();
	}
	
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
using namespace std;
#include<cstdio>
const int N=2005;
const int M=200005;
char mmp[N][N];
int n,m,Q,map[N][N],sum[N][N],f[N][N],sb[N][N],ans[M];
int shang[N][N],ce[N][N];
int panduan1(int x,int y)
{
	if(map[x-1][y]==1&&map[x][y]==1)
	return 1;
	return 0;
}
int panduan2(int x,int y)
{
	if(map[x][y-1]==1&&map[x][y]==1)
	return 1;
	return 0;
}
int main()   
{
	cin>>n>>m>>Q;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		cin>>mmp[i][j];
		map[i][j]=mmp[i][j]-'0';
		if(map[i][j]==1)
		f[i][j]+=map[i-1][j]+map[i][j-1];
	}
	sum[1][1]=map[1][1];	
	sb[1][1]=0;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+map[i][j];
		sb[i][j]=sb[i-1][j]+sb[i][j-1]-sb[i-1][j-1]+f[i][j];	
	}
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		shang[i][j]=shang[i][j-1]+panduan1(i,j);
	    ce[i][j]=ce[i-1][j]+panduan2(i,j);
	}
	int x1,x2,y1,y2,d,b,an;
	for(int i=1;i<=Q;i++)
	{
		cin>>x1>>y1>>x2>>y2;
		d=sum[x2][y2]-sum[x1-1][y2]-sum[x2][y1-1]+sum[x1-1][y1-1];
		b=sb[x2][y2]-sb[x1-1][y2]-sb[x2][y1-1]+sb[x1-1][y1-1];
		an=d-b;
		an=an+shang[x1][y2]-shang[x1][y1-1]+ce[x2][y1]-ce[x1-1][y1];
		ans[++ans[0]]=an;
	}
	for(int i=1;i<=ans[0];i++)
	cout<<ans[i]<<endl;
}

Measured memory_bytes: 100736
N, M, Q = map(int, input().split())
A = list()
[A.append(list(map(int, input().split()))) for _ in range(Q)]
def generate_sequences(current_sequence, recent_value):
    if len(current_sequence) == N:
        viable.append(current_sequence)
        return
    for i in range(recent_value, M+1):
        generate_sequences(current_sequence+[i], i)
viable = list()
generate_sequences([], 1)
def calc_score(in_list):
  return sum(vec[3] for vec in A if in_list[vec[1]-1]-in_list[vec[0]-1] == vec[2])
print(max(calc_score(in_list) for in_list in viable))

Measured memory_bytes: 22856
import sys
input = sys.stdin.readline

def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))

def main():
    mod=10**9+7
    N,K=MI()
    
    N2=(K-1).bit_length()+1
    A=[[0]*N for _ in range(N2)]
    A[0]=LI()
    
    for i in range(N):
        A[0][i]-=1
        
    for i in range(N2-1):
        for j in range(N):
            A[i+1][j]=A[i][A[i][j]]
            
    now=0
    for i in range(N2):
        if (K>>i)&1:
            now=A[i][now]
            
    print(now+1)
        
 
    

main()


Measured memory_bytes: 187452
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> P;
#define int long long
#define override_rep(i, l, r, mes, ...) mes
#define rep1(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = l; i < r; i++)
#define rep(...) override_rep(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
template<typename T, typename U>
istream& operator>>(istream& in, pair<T, U>& p) {
    in >> p.first >> p.second;
    return in;
}
signed main(signed argc, char* argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    const int MOD = 1000000007;
	int n,m;
	cin>>n>>m;
	int cnt=0;
	rep(i,m){
		int in;
		cin>>in;
		cnt+=in;
	}
	if(cnt>n)cout<<-1<<endl;
	else cout<<n-cnt<<endl;
}


Measured memory_bytes: 3616
#include<iostream>
using namespace std;
int main(){
    int R,G,B,N;
    cin>>R>>G>>B>>N;
    int ans=0;
    for(int i=0;i<=N/R;++i){
        for(int j=0;j<=N/G;++j){
            int tmp=R*i+G*j;
            if(N-tmp>=0){
                if((N-tmp)%B==0){
                    ans+=1;
                }
            }
        }
    }
    cout<<ans<<endl;
    return 0;
}

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

using namespace std;

const int W = 10, D = 10, E = 10;
int imos[E][D + 1][W + 1];

int main(){
    int d, w, x, ans, imax, omin;
    int outer[E], inner[E];
    while(cin >> d >> w, d){
        memset(outer, 0, sizeof(outer));
        memset(inner, 0, sizeof(inner));
        memset(imos, 0, sizeof(imos));
        ans = 0;
        for(int i = 1;i <= d;++i){
            for(int j = 1;j <= w;++j){
                cin >> x;
                imos[x][i][j] = 1;
            }
        }
        for(int i = 1;i <= d;++i){
            for(int j = 1;j <= w;++j){
                for(x = 0;x < E;++x){
                    imos[x][i][j] += imos[x][i][j - 1];
                }
            }
        }
        for(int i = 1;i <= d;++i){
            for(int j = 1;j <= w;++j){
                for(x = 0;x < E;++x){
                    imos[x][i][j] += imos[x][i - 1][j];
                }
            }
        }
        for(int i = 1;i <= d;++i){
            for(int j = 1;j <= w;++j){
                for(int ii = i + 2;ii <= d;++ii){
                    for(int jj = j + 2;jj <= w;++jj){
                        // cout << i << "," << j << " " << ii << "," << jj << endl;
                        for(x = 0;x < E;++x){
                            outer[x] = imos[x][i - 1][j - 1] - imos[x][i - 1][jj] - imos[x][ii][j - 1] + imos[x][ii][jj];
                            inner[x] = imos[x][i][j] - imos[x][i][jj - 1] - imos[x][ii - 1][j] + imos[x][ii - 1][jj - 1];
                            outer[x] -= inner[x];
                            // cout << outer[x] << "," << inner[x] << endl;
                        }
                        imax = E;
                        for(x = 0;x < E;++x){
                            if(inner[x] != 0) {
                                imax = x;
                            }
                        }
                        for(x = 0;x < E;++x){
                            if(outer[x] != 0) break;
                        }
                        omin = x;
                        // cout << imax << " " << omin << endl;
                        if(imax < omin){
                            // cout << imax << "," << omin << endl;
                            int a = 0;
                            for(x = 0;x < omin;++x){
                                a += (omin - x) * inner[x];
                            }
                            ans = max(ans, a);
                        }
                    }
                }
            }
        }
        cout << ans << endl;
    }
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<char, ll> pcl;

#define m0(x) memset(x, 0, sizeof(x))
#define all(x) x.begin(), x.end()
#define rep(i, n) for(int i = 0; i < (n); i++)
#define asort(x) sort(all(x));
#define dsort(x, t) sort(x.begin(), x.end(), greater<t>());
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define MINS(m, s) m.insert(mp(s, 1));
#define MFIN(m, s) m.find(s) != m.end()
#define mp make_pair
#define pb push_back
#define INF (1 << 29)
const int mod = 1000000007;

int main() {
    string s;
    cin >> s;
    for(int i = 0; i < 3; i++) {
        cout << s[i];
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>

void QSort(int x[ ],  int y[ ], int left, int right);
void Swap(int x[ ], int y[ ], int i, int j);

int main(void){
    int n, m;
    int *a;
    int *b;
    int count = 0;
    long pay=0;
    int c=0;
    
    int tempa, tempb;
    
    scanf("%d %d", &n, &m);
    

	a = (int *)malloc(sizeof(int) * n);
	b = (int *)malloc(sizeof(int) * n);

	for (int i = 0; i < n; i++) {
		scanf("%d %d", &tempa, &tempb);
		a[i] = tempa;
		b[i] = tempb;
	}
	
	QSort(a, b, 0, n - 1);

	while(count < m){
	    pay += a[c];
	    count++;
	    b[c]--;
	    if(b[c]==0) c++;
	}
    
    printf("%ld", pay);
    
    free(a);
    free(b);

}

void QSort(int x[ ], int y[ ], int left, int right)
{
    int i, j;
    int pivot;

    i = left;                      /* ソートする配列の一番小さい要素の添字 */
    j = right;                     /* ソートする配列の一番大きい要素の添字 */

    pivot = x[(left + right) / 2]; /* 基準値を配列の中央付近にとる */

    while (1) {                    /* 無限ループ */

        while (x[i] < pivot)       /* pivot より大きい値が */
            i++;                   /* 出るまで i を増加させる */

        while (pivot < x[j])       /* pivot より小さい値が */
            j--;                   /*  出るまで j を減少させる */
        if (i >= j)                /* i >= j なら */
            break;                 /* 無限ループから抜ける */

        Swap(x, y, i, j);             /* x[i] と x[j]を交換 */
        i++;                       /* 次のデータ */
        j--;
    }
    //ShowData(x, 10);               /* 途中経過を表示 */

    if (left < i - 1)              /* 基準値の左に 2 以上要素があれば */
        QSort(x, y, left, i - 1);     /* 左の配列を Q ソートする */
    if (j + 1 <  right)            /* 基準値の右に 2 以上要素があれば */
        QSort(x, y, j + 1, right);    /* 右の配列を Q ソートする */
}

  /* 配列の要素を交換する */
void Swap(int x[ ], int y[ ], int i, int j)
{
    int temp;

    temp = x[i];
    x[i] = x[j];
    x[j] = temp;
    
    temp = y[i];
    y[i] = y[j];
    y[j] = temp;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

vector<vector<int>> graph(200200, vector<int>());
vector<long long> ans(200200, 0);
int n, q;

void dfs(int now, int pp) {
    for(int i = 0; i < graph.at(now).size(); ++i) {
        int check = graph.at(now).at(i);
        if(check != pp) {
            ans.at(check) += ans.at(now);
            dfs(check, now);
        }
    }
}

int main() {
    cin >> n >> q;
    for(int i = 0; i < n-1; ++i) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph.at(a).push_back(b);
        graph.at(b).push_back(a);
    }

    int p; long long x;
    for(int i = 0; i < q; ++i) {
        cin >> p >> x;
        p--;
        ans.at(p) += x;
    }
    
    dfs(0, 0);

    for(int i = 0; i < n; ++i) {
        if(i == n-1) cout << ans.at(i) << endl;
        else cout << ans.at(i) << " ";
    }
}

Measured memory_bytes: 30592
def someone_ans():
    n = int(input())
    a = list(map(int, input().split()))
    a.sort()
    x_max = a[n - 1]
    center = a[0]
    for i in range(1, n - 1):
        if abs(center - x_max / 2) > abs(a[i] - x_max / 2):
            center = a[i]
    return "{0} {1}".format(x_max, center)


print(someone_ans())


Measured memory_bytes: 14052
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
 
string s;
int n;
 
int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	int a, b, c, d;
	cin >> n >> a >> b >> c >> d;
	a --; b --; c --; d --;
	cin >> s;
	vector <bool> fp(n), sp(n);
	vector <int> dp(n);
	fp[a] = sp[b] = 1;
	for (int i=1; i<n; i++) {
		if (s[i] == '#') continue;
		if (fp[i-1] || (i > 1 && fp[i-2])) {
			fp[i] = 1;
		}
		if (sp[i-1] || (i > 1 && sp[i-2])) {
			sp[i] = 1;
		}
	}
	if (d > c) {
		if (fp[c] && sp[d]) {
			cout << "Yes";
		} else {
			cout << "No";
		}
		return 0;
	}
	int tec = 0;
	for (int i=b; i<=d+1; i++) {
		if (s[i] ==  '#') {
			tec = 0;
			continue;
		}
		tec ++;
		if (tec >= 3) break;
	}
	if (s[b+1] == '.' && s[b-1] == '.') tec = 3;
	cout << (tec >= 3 && fp[c] && sp[d] ? "Yes" : "No");
	return 0;
}

Measured memory_bytes: 1360
#include <bits/stdc++.h>
using namespace std;
#define rep0(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define ll long long
#define BIT_FLAG_0 (1<<0) // 0000 0000 0000 0001
int gcd(int a, int b){
    if(a%b == 0){
        return b;
    }else{
    return gcd(b, a%b);
    }
}

int main(){
    int n;
    ll sum0=0,sum1=0,sum2=0,temp=0;
    cin >> n;
    vector<int> x(n);
    rep0(i,n){ 
        cin >> x[i];
        temp+=x[i];
    }
    temp=temp/x.size();
    rep0(i,n){
        sum0+=(x[i]-temp-1)*(x[i]-temp-1);
    }
    rep0(i,n){
        sum1+=(x[i]-temp)*(x[i]-temp);
    }
    rep0(i,n){
        sum2+=(x[i]-temp+1)*(x[i]-temp+1);
    }
    cout << min(min(sum0,sum1),sum2) << endl;
    return 0;
}

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

using ll = long long;

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

int main(int argc, char **argv)
{
	int n;
	vector<ll> v(1000000);

	cin >> n;
	for (int i = 0; i < n; ++i) cin >> v[i];

	int ans{0};
	for (int i = 0; i < n; ++i) ans = GCD(ans, v[i]);
	
	std::cout << ans << std::endl;
}

Measured memory_bytes: 8064
#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() {
  char a;
  cin >> a;
  
  if (isupper(a))
   {
       cout << "A" << endl;
   }
   else
   {
       cout << "a" << endl;
   }
}


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

int main() {
    int  N, L;  cin >> N >> L;
    int sum = 0, min_abs = 10000000, ans;
    for (int i = 0; i < N; ++i) sum += i + L;
    for (int i = 0; i < N; ++i) {
        if (min_abs > abs(i + L)) {
            min_abs = min(min_abs, abs(i + L));
            ans = sum - (i + L);
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
def parent(i):
    return i//2
    
def left(i):
    return 2 * i

def right(i):
    return 2 * i + 1
 
if __name__ == '__main__':
    n = int(input().rstrip())
    a = [-1]
    a += [int(i) for i in input().rstrip().split(" ")]
    for i in range(1, n+1):
        print("node {}: ".format(i), end = "")
        print("key = {}, ".format(a[i]),end = "") 
        if parent(i) >= 1:
            print("parent key = {}, ".format(a[parent(i)]), end = "")
        if left(i) <= n:
            print("left key = {}, ".format(a[left(i)]), end = "")
        if right(i) <= n:
            print("right key = {}, ".format(a[right(i)]), end = "")
        print()

Measured memory_bytes: 7768
str = input() 

if str[0] == str[1]:
    if str [2] == str [3] and str[0] != str[2]:
        print('Yes')
    else :
        print('No')
elif str[0] == str[2]:
    if str [1] == str[3]and str[0] != str[1]:
        print('Yes')
    else :
        print('No')
elif str[0] == str[3]:
    if str [1] == str[2]and str[0] != str[1]:
        print('Yes')
    else :
        print('No')
else :
    print('No')

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#include<cctype>
using namespace std;
#define rep(i,n) for (int i=0;i<(n);i++)
#define all(v) (v).begin(),(v).end()
typedef long long int ll;
#define pi 3.1415926535897932384
#define E9 1000000000
#define eps 1e-4
#define pii pair<int,int>

int main(){
  int N; cin >> N;
  int A[N+2];  
  rep(i,N) cin >> A[i+1];
  A[0] = 0, A[N+1] = 0;
  int retval = 0;
  rep(i,N+1) retval += abs(A[i+1]-A[i]);

  for (int i=1;i<=N;i++) {
    cout << retval - abs(A[i+1] - A[i]) - abs(A[i]-A[i-1]) + abs(A[i+1]-A[i-1]) << endl;  
  }
  
  
  // cout << fixed << setprecision(10);
  
  return 0;
}



Measured memory_bytes: 1664
#include<stdio.h>
int main()
{
  int N,C,P;
  scanf("%d",&N);
  if(N%1000==0)
  { P=0;
    printf("%d",P);
  }
  else
  {
  C=N%1000;
  P=1000-C;
  printf("%d",P);
  }
  return 0;
}
  


Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define inf 1001001001001000
#define mod 1000000007
using namespace std;

struct UnionFind {
    vl par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(ll n) : par(n) { //最初は全てが根であるとして初期化
        rep(i,n) par[i] = i;
    }

    ll root(ll x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        ll rx = root(x); //xの根をrx
        ll ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(ll x, ll y) { // 2つのデータx, yが属する木が同じならtrueを返す
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};

int main(void){
    ll n,m;
    cin>>n>>m;
    vl p(n),ip(n);
    rep(i,n){
        cin>>p[i];
        p[i]--;
        ip[p[i]] = i;
    }
    UnionFind uf(n);
    rep(i,m){
        ll x,y;
        cin>>x>>y;
        x--;
        y--;
        uf.unite(x,y);
    }
    ll ans = 0;
    rep(i,n){
        if(uf.same(i,ip[i])) ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

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

  string ans = "Yes";
  if (n != m) {
    ans = "No";
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <stack>
#include <vector>
#include <algorithm>
#include <set>
#include <deque>
#include <utility>
#include <chrono>
#include <sstream>
#include <iomanip>

#define INF 1 << 30
#define MOD 1000000007
#define PI 3.14159265358979
#define rep(i, n) for (int (i) = 0; (i) < (int)(n); (i)++)
#define reu(i, l, r) for (int (i) = (int)(l); (i) < (int)(r); (i)++)
#define D(x) cout << x << endl
#define d(x) cout << x
#define all(x) (x).begin(), (x).end()
#define pub(x) push_back(x)
#define pob() pop_back()
#define puf(x) push_front(x)
#define pof() pop_front()
#define mp(x, y) make_pair((x), (y))
#define fi first
#define se second

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
template<typename T, typename U> inline void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> inline void amax(T &x, U y) { if (x < y) x = y; }

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

int main() { 
        int a, b;
        cin >> a >> b;
        int ans = 0;
        if (a < b) {
                if (0 <= a) {
                        ans = b - a;
                } else if (a < 0 && 0 < b) {
                        if (-a > b) {
                                ans = -b - a + 1;
                        } else {
                                ans = b + a + 1;
                        }
                } else {
                        ans = b - a;
                }
        } else {
                if (0 < b && a != 0) {
                        ans = 1 + -b + a + 1;
                } else if (b <= 0 && 0 <= a) {
                        if (-b > a) {
                                ans = -b - a + 1;
                        } else {
                                ans = 1 + b + a;
                        }
                } else {
                        ans = 1 + -b + a + 1;
                }
        }
        D(ans);
        return 0;
}



Measured memory_bytes: 256
from collections import defaultdict, deque, Counter

N = int(input())

counter = Counter()
nodes = defaultdict(list)
edges = []

for i in range(N - 1):
    u, v = map(int, input().split(' '))
    nodes[u].append((v, i))
    nodes[v].append((u, i))
    edges.append((u, v))

K = 0
for node in nodes.values():
    K = max(K, len(node))

checked = set()
queue = deque([(1, 0)])
edge_colors = [0] * N

while queue:
    u, uc = queue.popleft()
    checked.add(u)
    color = 1
    for v, e in nodes[u]:
        if v in checked:
            continue
        if color == uc:
            color += 1
        edge_colors[e] = color
        queue.append((v, color))
        color += 1

print(K)
for i in range(N - 1):
    print(edge_colors[i])


Measured memory_bytes: 61416
import bisect
n = int(input())
s = input()
rl = []
gl = []
bl = []
for i in range(n):
    if s[i] == "R": rl.append(i+1)
    elif s[i] == "G": gl.append(i+1)
    else: bl.append(i+1)

ans = len(rl)*len(gl)*len(bl)

for i in rl:
    for j in gl:
        lb = len(bl)
        if (i+j)%2==0:
            index = bisect.bisect_left(bl, (i+j)//2)
            if lb>index and bl[index] == ((i+j)//2):
                ans -= 1
        if 2*i-j>0:
            index = bisect.bisect_left(bl, 2*i-j)
            if lb>index and bl[index] == (2*i-j):
                ans -= 1
        if 2*j-i>0:
            index = bisect.bisect_left(bl, 2*j-i)
            if lb>index and bl[index] == (2*j-i):
                ans -= 1
print(ans)

Measured memory_bytes: 74764
import java.util.*

private val WHITESPACE = "\\s+".toRegex()

private fun readLn() = readLine()!!
private fun readList() = readLn().split(WHITESPACE)

// helps split strings into multiple tokens
private var tokenizer = StringTokenizer("")
private fun read(): String {
    while (tokenizer.hasMoreTokens().not()) tokenizer = StringTokenizer(readLn(), " ")
    return tokenizer.nextToken()
}

private fun readInt() = read().toInt()
private fun readLong() = read().toLong()
private fun readDouble() = read().toDouble()

private fun readIntList() = readList().map { it.toInt() }
private fun readLongList() = readList().map { it.toLong() }
private fun readDoubleList() = readList().map { it.toDouble() }

private fun readIntArray(n: Int = 0) =
    if (n == 0) readList().run { IntArray(size) { get(it).toInt() } } else IntArray(n) { readInt() }

fun main() {
    val n = readInt()
    val x = readInt()
    val t = readInt()

    if (n <= x) println(t)
    else {
        val q = n / x
        val r = n % x
        if (r != 0) println((q * t) + t)
        else println(q * t)
    }
}






Measured memory_bytes: 35224
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
 
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
 
using namespace std;
 
 
int inputValue(){
    int a;
    cin >> a;
    return a;
};
 
void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};
 
void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}
 
template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}
 
int main(int argc, const char * argv[]) {
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);


    printf("%d\n",a*b/2);
    return 0;
}

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

namespace ConsoleApplication7
{
    //ONLINE JUDGE (ITP1_6_E)


    class Program
    {
        static char hanntei(int m,int f,int r)
        {
            int goukei = m + f;

            if ((m == -1) || (f == -1))
            {
                return 'F';
            }

            if (80 <= goukei)
            {
                return 'A';
            }

            if (65 <= goukei)
            {
                return 'B';
            }
            if (((30 <= goukei) && (goukei < 50) && (50 <= r)) || (50 <= goukei))
            {
                return 'C';
            }
            if ((30 <= goukei) && (goukei < 50))
            {
                return 'D';
            }
                return 'F';
        }
        

        static void Main(string[] args)
        {
            List<char> list = new List<char>();
            while(true)
            {
                string[] str = Console.ReadLine().Split(' ');
                int m = int.Parse(str[0]);
                int f = int.Parse(str[1]);
                int r = int.Parse(str[2]);

                if ((m == -1) && (f == -1) && (r == -1))
                { 
                    break;
                }
                char g = hanntei(m, f, r);
                list.Add(g);


            }
            for (int i = 0; i < list.Count; ++i)
            {
                Console.WriteLine(list[i]);
            }

        }
    }
}

Measured memory_bytes: 5336
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

int main()
{
	long long A, B,k;
	scanf("%lld%lld", &A, &B);
	k = (A + B) / 2;
	if ((A+B) % 2 == 0)printf("%lld\n", k);
	else printf("IMPOSSIBLE\n");
	return 0;
}

Measured memory_bytes: 128
from collections import deque

X = input()
stack = deque([X[0]])
for i in range(1, len(X)):
    if X[i] == 'S':
        stack.appendleft(X[i])

    if X[i] == 'T':
        if stack:
            check = stack.popleft()
            if check == 'T':
                stack.appendleft(check)
                stack.appendleft(X[i])
        else:
            stack.appendleft(X[i])

print(len(stack))


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

const int MOD = 1000000007;

//long long
using ll = long long;

//出力系
#define print(x) cout << x << endl
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
 
// begin() end()
#define all(x) (x).begin(),(x).end()

//for
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)

//最大公約数 
unsigned gcd(unsigned a, unsigned b) {
  if(a < b) return gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}



  
int main() {

int N;
cin >> N;

vector<int>d(N);
REP(i, N) cin >> d.at(i);

sort(all(d));

int ans = d.at(N / 2) - d.at(N / 2 - 1);

print(ans);

}

Measured memory_bytes: 640
#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<int> x(n), y(n);
  rep(i,n) cin >> x[i] >> y[i];
  // 距離を求める関数(ラムダ式:無名関数)
  auto dist = [&](int i, int j) {
    double dx = x[i]-x[j];
    double dy = y[i]-y[j];
    return sqrt(dx*dx+dy*dy);
  };
  vector<int> p(n);
  rep(i,n)p[i] = i;
  double len=0;
  int cnt = 0;
  do {
    rep(i, n-1) {
      len += dist(p[i], p[i+1]);
    }
    cnt++;
  } while (next_permutation(p.begin(), p.end()));
  double ans = len/cnt;
  printf("%.10f\n", ans);
  return 0;
}

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

using namespace std;

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

	vector<int> v;
	for (int i = 1; i <= min(a, b); i++)
	{
		if(a%i == 0 && b%i == 0) v.push_back(i);
	}

        cout << v[v.size() - k] << endl;
	return 0;
}

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

#define ll long long
#define PI acos(-1)
#define N 1e10+7
#define mp(a,b) make_pair(a,b)
#define inf 1e10

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

int main()
{
//    freopen("input.txt","r",stdin);
//    freopen("output.txt","w",stdout);
    int a,b,c;
    cin>>a>>b>>c;
    if(b+c-a<=0)
    {
        cout<<min(b,c)<<" "<<0<<endl;
    }
    else
    {
        cout<<min(b,c)<<" "<<b+c-a<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
a = gets.split.map(&:to_i)
sum = a.inject(:+)
cs1,cs2 = [0],[0]
(N/2).times do |i|
  cs1[i+1] = cs1[i] + a[i*2]
  cs2[i+1] = cs2[i] + a[i*2+1]
end
cs1[N/2+1] = cs1[N/2]+a[N-1]
#p cs1
#p cs2
ans = []
N.times do |i|
  if i % 2 == 0
    t = cs1[N/2+1] - cs1[i/2] + cs2[i/2]
    ans << t*2-sum
  else
    t = cs2[N/2] - cs2[i/2] + cs1[i/2+1]
    ans << t*2-sum
  end
end

puts ans.join(" ")


Measured memory_bytes: 14876
#include "bits/stdc++.h"

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

class Data{
public:
    int n,p,y;
    bool operator<(const Data& rhs){return y<rhs.y;}
};

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

	int N=in(),M=in();
        vector<Data*> D(M);
        vector<Data*> S[N];
        REP(i,M){
            Data* temp=new Data;
            temp->p=in(),temp->y=in();
            S[temp->p-1].emplace_back(temp);
            D[i]=temp;
        }
        REP(i,N){
            sort(ALL(S[i]),[&](Data* lhs,Data* rhs){return (*lhs)<(*rhs);});
            int j=0;
            for(int j=0,ej=S[i].size();j!=ej;++j){
                S[i][j]->n=j;
            }
        }
        REP(i,M){
            char str[128];
            sprintf(str,"%06d%06d",D[i]->p,D[i]->n+1);
            cout << str << endl;
        }
	return 0;
}


Measured memory_bytes: 10880
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef pair<int, int> PII;
const int MAXM = 200000 + 10, MAXN = 1000 + 10, inf = 1e9;
namespace NF {
  struct Edge {
    int v, c, f, nx;
    Edge() {}
    Edge(int v, int c, int f, int nx):
      v(v), c(c), f(f), nx(nx) {}
  } E[MAXM];
  int G[MAXN], lev[MAXN], cur[MAXN];
  int sz, N;
  void init(int n) {
    N = n; sz = 0;
    memset(G, -1, sizeof(G));
  }
  void link(int u, int v, int c) {
    E[sz] = Edge(v, c, 0, G[u]); G[u] = sz ++;
    E[sz] = Edge(u, 0, 0, G[v]); G[v] = sz ++;
  }
  bool bfs(int S, int T) {
    static int Q[MAXN];
    for (int i = 0; i < N; ++ i) lev[i] = -1;
    Q[0] = S; lev[S] = 0;
    for (int h = 0, t = 1; h < t; ++ h) {
      int u = Q[h], v;
      for (int now = G[u]; ~now; now = E[now].nx) {
        if (lev[v = E[now].v] == -1 && E[now].c > E[now].f) {
          lev[v] = lev[u] + 1; Q[t ++] = v;
        }
      }
    }
    return lev[T] != -1;
  }
  int dfs(int u, int T, int low) {
    if (u == T) return low;
    int ret = 0, tmp, v;
    for (int &now = cur[u]; ~now && ret < low; now = E[now].nx) {
      if (lev[v = E[now].v] == lev[u] + 1 && E[now].c > E[now].f) {
        tmp = dfs(v, T, min(low - ret, E[now].c - E[now].f));
        ret += tmp; E[now].f += tmp; E[now ^ 1].f -= tmp;
      }
    }
    if (!ret) lev[u] = -1; return ret;
  }
  int dinic(int S, int T) {
    int ret = 0;
    while (bfs(S, T)) {
      memcpy(cur, G, sizeof(G[0]) * N);
      ret += dfs(S, T, inf);
    }
    return ret;
  }
  static bool mark[MAXN];
  int solve(int S, int T) {
    bfs(S, T); int ret = 0;
    memset(mark, 0, sizeof(mark));
    queue<int> Q; Q.push(T); mark[T] = true;
    while (!Q.empty()) {
      int u = Q.front(); Q.pop();
      for (int now = G[u]; ~now; now = E[now].nx) {
        int v = E[now].v;
        if (E[now ^ 1].c > E[now ^ 1].f) {
          if (!mark[v]) mark[v] = true, Q.push(v);
        }
        else ret += (lev[v] != -1 && E[now].c > 0);
      }
    }
    return ret;
  }
}

int main() {
  int n, m, s, t; 
  while (scanf("%d%d%d%d", &n, &m, &s, &t) == 4 && n) {
    NF::init(n); -- s; -- t;
    for (int i = 0, u, v; i < m; ++ i) {
      scanf("%d%d", &u, &v); -- u, -- v;
      NF::link(u, v, 1);
    }
    int maxflow = NF::dinic(s, t);
    int ret = NF::solve(s, t);
    if (ret != 0) maxflow ++;
    printf("%d %d\n", maxflow, ret);
  }
  return 0;
}

Measured memory_bytes: 1540
#include <stdio.h>

int main(void) {
	int S = 0;
	

	scanf("%d", &S);

	printf("%d", S / 3600);//?????????

	printf(":%d", S % 3600 / 60); // ???

	printf(":%d\n", S % 3600 % 60); // ?§???°
	
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
#define ll long long
#define pii pair<int,int>
#define PI 2*acos(0)
#define INF 1e18
#define mx 200005
using namespace std;
//const ll int p=1000000007;
//vector<ll > prime;
//bool mark[mx];
ll int mod(ll int a,ll int b)
{
    ll int m=a%b;
    if(m<0) m=(b<0)?(m-b):(m+b);
    return m;
}
ll maxpow(ll n)
{
    return (n & (~(n-1)));
}
bool isPrime(ll n)
{
    if(n<2) return false;
    if(n==2) return true;
    if(n%2==0) return false;
    for(ll i=3;i*i<=n;i+=2){
        if(n%i==0) return false;
    }
    return true;
}
/*void init()
{
    mark[1]=1;
    int i,j,limit=sqrt(mx*1.0)+2;
    prime.push_back(2);
    for(i=4;i<mx;i+=2) mark[i]=1;
    mark[2]=0;
    for(i=3;i<mx;i+=2){
        if(!mark[i]){
            prime.push_back(i);
            if(i<=limit){
                for(j=i*i;j<mx;j+=2*i){
                    mark[j]=1;
                }
            }
        }
    }
}
/*
ll maxdiv(ll n)
{
    ll i,ans=1;
    for(i=0;i<prime.size();i++){
        if(n%prime[i]==0){
            ans=n/prime[i];break;
            //return ans;
        }
    }
    return ans;
}*/
ll lcm(ll a,ll b)
{
    ll ans=a*b;
    return (ans/__gcd(a,b));
}
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll T,N,X,z;
    cin>>N>>X>>T;
    z=N/X;
    if(N%X) z++;
    cout<<T*z;
    return 0;
}
//1028C


Measured memory_bytes: 3636
import java.util.Scanner;

public class Main {

	private static final long x = (long) Math.pow(10, 18);

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String a = sc.next();
		String b = sc.next();

		int ans = 0;
		for (int i = 0; i < a.length(); i++) {
			if (a.charAt(i) != b.charAt(i)) ans++;
		}

		System.out.println(ans);

		sc.close();
	}

}


Measured memory_bytes: 41232
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let p = read_vec::<usize>()
        .iter()
        .map(|x| x - 1)
        .collect::<Vec<_>>();

    let mut grid = vec![vec![0; n]; n];
    for y in 0..n {
        for x in 0..n {
            grid[y][x] = vec![x, y, n - 1 - x, n - 1 - y].into_iter().min().unwrap() as i32;
        }
    }
    let mut occ = vec![vec![1; n]; n];

    let mut ans = 0i32;
    for num in p {
        let x = num % n;
        let y = num / n;
        ans += grid[y][x];
        occ[y][x] = 0;
        dfs(x, y, &mut grid, &mut occ);
    }
    println!("{}", ans);
}

fn dfs(x: usize, y: usize, grid: &mut Vec<Vec<i32>>, occ: &mut Vec<Vec<i32>>) {
    if x > 0 {
        let (adj_x, adj_y) = (x - 1, y);
        if grid[adj_y][adj_x] > grid[y][x] + occ[y][x] {
            grid[adj_y][adj_x] = grid[y][x] + occ[y][x];
            dfs(adj_x, adj_y, grid, occ);
        }
    }
    if y > 0 {
        let (adj_x, adj_y) = (x, y - 1);
        if grid[adj_y][adj_x] > grid[y][x] + occ[y][x] {
            grid[adj_y][adj_x] = grid[y][x] + occ[y][x];
            dfs(adj_x, adj_y, grid, occ);
        }
    }
    if y < grid.len() - 1 {
        let (adj_x, adj_y) = (x, y + 1);
        if grid[adj_y][adj_x] > grid[y][x] + occ[y][x] {
            grid[adj_y][adj_x] = grid[y][x] + occ[y][x];
            dfs(adj_x, adj_y, grid, occ);
        }
    }
    if x < grid.len() - 1 {
        let (adj_x, adj_y) = (x + 1, y);
        if grid[adj_y][adj_x] > grid[y][x] + occ[y][x] {
            grid[adj_y][adj_x] = grid[y][x] + occ[y][x];
            dfs(adj_x, adj_y, grid, occ);
        }
    }
}

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}


Measured memory_bytes: 25364
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main(){
	ios::sync_with_stdio(false);
	int n,k;
	cin>>n>>k;
	int mp[n+1];
	for(int i=0;i<n+1;++i){
		mp[i] = 0;
	}
	for(int i=1;i<=k;++i){
		int d;
		cin>>d;
		for(int j=0;j<d;++j){
			int val;
			cin>>val;
			++mp[val];
		}
	}
	int ans =0;
	for(int i=1;i<=n;++i){
		if(!mp[i])
			++ans;
	}
	cout<<ans<<'\n';
}

Measured memory_bytes: 3652
# -*- coding: utf-8 -*-

import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
A=LIST()

cnt=0
for i in range(N):
    if A[A[i]-1]==i+1:
        cnt+=1
print(cnt//2)


Measured memory_bytes: 13812
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

struct Node {
  LL cnt = 0;
  vector<int> es;
};

int N, Q;
vector<Node> G;

void dfs(int v, int parent, LL cnt) {
  G[v].cnt += cnt;
  for (int u : G[v].es) {
    if (u == parent) continue;
    dfs(u, v, G[v].cnt);
  }
}

int main() {
  cin >> N >> Q;
  G.resize(N);
  for (int i = 0; i < N-1; ++i) {
    int a, b; cin >> a >> b; --a, --b;
    G[a].es.push_back(b);
    G[b].es.push_back(a);
  }

  for (int i = 0; i < Q; ++i) {
    int p, x; cin >> p >> x; --p;
    G[p].cnt += x;
  }

  dfs(0, -1, 0);

  for (int i = 0; i < N; ++i) cout << G[i].cnt << " ";
  cout << endl;
}


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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n;
	cin>>n;
	string ans = "";
	while( n > 0 ){
		ll mod = n % 26;
		if( mod == 0 ){ mod = 26; }
		ans += 'a' + (mod - 1);
		n = (n - mod)/26;
	}
	reverse(ans.begin(),ans.end());
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
using namespace std;
void selection(pair<char,int> p[], int n){
    for(int i = 0; i < n; ++i){
        int minj = i;
        for(int j = i; j < n; ++j){
            if(p[j].second < p[minj].second){
                minj = j;
            }
        }
        if(minj != i){
            swap(p[minj], p[i]);
        }
    }
}
string bubble(pair<char,int> p[],int n){
    bool flag = true;
    while(flag){
        flag = false;
        for(int j = n-1; j != 0; --j){
            if(p[j].second < p[j-1].second){
                swap(p[j], p[j-1]);
                flag = true;
            }
        }
    }
    return "Stable";
}
void show(pair<char, int> p[], int n){
    for(int i = 0; i < n; ++i){
        if(i) cout << " ";
        cout << p[i].first << p[i].second;
    }
    cout << endl;
}
int main(){
    int n, cnt = 0; cin >> n;
    pair<char, int> p[n],q[n];
    for(int i = 0; i < n; ++i){
        char c; cin >> c;
        int x; cin >> x;
        p[i].first = q[i].first = c;
        p[i].second = q[i].second = x;
    }
    string s = bubble(p,n);
    show(p,n);
    cout << s << endl;
    selection(q,n);
    show(q,n);
    bool flag = true;
    for(int i = 0; i < n; ++i){
        if(!(p[i].first == q[i].first && p[i].second == q[i].second)){
            flag = false;
            break;
        }
    }
    if(flag) cout << "Stable" << endl;
    else cout << "Not stable" << endl;
    return 0;
}


Measured memory_bytes: 3220
n,x=map(int,input().split())
*a,=map(int,input().split())
c=0

for i in range(n-1):
    v=a[i]+a[i+1]
    if i and v-x>a[i+1]:
        a[i+1]=x-a[i]
        c+=(v-x)
    else:
        if 0<v-x<=a[i+1]:
            a[i+1]-=(v-x)
            c+=(v-x)
        elif v-x>a[i+1]:
            a[i]-=(v-x-a[i+1])
            a[i+1]=0
            c+=(v-x)

print(c)

Measured memory_bytes: 63984
from collections import defaultdict
N = int(input())
A = list(map(int, input().split()))

d = defaultdict(int)
strong = 0

for a in A:
    if a >= 3200:
        strong += 1
        continue
    d[a // 400] += 1

Cmin = max(len(d), 1)
Cmax = len(d) + strong
print(Cmin, Cmax)

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

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;
}

int main(){
    int n, m; cin >> n >> m;
    vector<int> a(n); rep(i, n) cin >> a[i];
    double sum = accumulate(a.begin(), a.end(), 0.0);
    double thr = sum / (4*m);
    sort(a.begin(), a.end(), greater<int>());
    if(a[m-1] >= thr) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
  
//    Curriculum...
//Letters and Sounds
//English Appendix 1: Spelling
//KS3
//Curriculum word lists
//English literature study books
//Resources...
//Spellzone guides
//Spelling resources
//Dictionary
//Tools
//FAQs
//Help...
//Contact us
//Book FREE
//Help
    
    public static void main(String args[]) {
        Scanner Input = new Scanner(System.in);
        String A = Input.next();
        String B = Input.next();
        if (A.length() == B.length()) {
            int E = 1;
            int G = 0;
            int L = 0;
            for (int I = 0; I < A.length(); I++) {
                if (A.charAt(I) == B.charAt(I)) {
                    E++;
                } else if (A.charAt(I) > B.charAt(I)) {
                    System.out.println("GREATER");
                    G++;
                    break;
                } else if (A.charAt(I) < B.charAt(I)) {
                    System.out.println("LESS");
                    L++;
                    break;
                }
            }
            if (L == 0 && G == 0) {
                System.out.println("EQUAL");
            }
        } else if (A.length() > B.length()) {
            System.out.println("GREATER");
        } else {
            System.out.println("LESS");
        }
    }
}//Keep Copying This Useless Code


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(n); ++i)
#define repr(i, a, b) for (int i=a; i<(b); ++i)
#define reprev(i, n) for (int i=n-1; i>=0; --i)
#define reprrev(i, a, b) for (int i=b-1; i>=(a); --i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main() {
    cout << fixed << setprecision(10);
    
    int N, M; cin >> N >> M;
    if (N > M) {
        rep(i, N) cout << M;
        cout << endl;
    } else if (N < M) {
        rep(i, M) cout << N;
        cout << endl;
    } else {
        rep(i, N) cout << N;
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**9)

H, N = map(int, input().split())
magic = [_ for _ in range(N)]

for k in range(N):
  magic[k] = list(map(int, input().split()))
  magic[k].append(magic[k][0]/magic[k][1])

magic.sort(key = lambda x: x[2], reverse=True)
ans = [0 for _ in range(H+1)]
visited = [0]
anskouho = [float('inf')]

def solve(start, power, point, maryoku):
  if start == H:
    print(min(point, min(anskouho)))
    exit()
  elif start > H:
    anskouho.append(point)
    return 0
  elif ans[start] != 0:
    return 0
  else:
    visited.append(start)
    ans[start] = point
    solve(start+power, power, point+maryoku, maryoku)

for k in range(N):
  for item in visited:
    solve(item+magic[k][0], magic[k][0], ans[item] + magic[k][1], magic[k][1])

print(min(anskouho))

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

public class Main {
	public static void main(String[] a) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		char[] data = str.toCharArray();

		StringBuffer sb = new StringBuffer(str);
		str = sb.reverse().toString();
		System.out.println(str);
	}
}

Measured memory_bytes: 24040
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		output(A, N);
		insertionSort(A, N);
		sc.close();
	}

	public static void insertionSort(int[] A, int N) {
		for (int i = 1; i < N; i++) {
			int v = A[i];
			int j = i - 1;
			while (j >= 0 && A[j] > v) {
				A[j + 1] = A[j];
				j--;
			}
			A[j + 1] = v;
			output(A, N);
		}
	}

	public static void output(int[] A, int N) {
		for (int i = 0; i < N; i++) {
			if (i > 0) {
				System.out.print(" ");
			}
			System.out.print(A[i]);
		}
		System.out.printf("\n");
	}
}



Measured memory_bytes: 34276
#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>;

void solve() {
    char c;
    cin >> c;
    cout << (char)(c + 1) << endl;
}

int main() {
    solve();
    return 0;
}




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


long long p( long long x ){

          long long t, j;

          t = x;

          for( j = 1 ; j < x ; j = j + 1 ){

               t *= x - j;

               t %= 1000000007;

               }

          return t;

          }


int main(){


    long long n, m, k;


    cin >> n >> m;


    if( abs( n - m ) >= 2 ) k = 0;


    else if( abs( n - m ) == 1 ) k = p( max( n, m ) ) * p( min( n, m ) ) % 1000000007;

    else k = 2 * p( max( n, m ) ) * p( min( n, m ) ) % 1000000007;


    cout << k << endl;


    return 0;

    }


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

using namespace std;

const int maxn = 2e5+10;

int n, m;
int l[maxn], r[maxn], a[maxn];
long long int seg[maxn<<2], lazy[maxn<<2];
vector<int> cnt[maxn];

void put(long long int x, int id){
	lazy[id] += x;
	seg[id] += x;
}

void shift(int id, int l, int r){
	if (r - l > 1 && lazy[id] != 0){
		put(lazy[id], id<<1);
		put(lazy[id], id<<1|1);
	}
	lazy[id] = 0;
}

void sett(int pos, long long int x, int id = 1, int l = 0, int r = n+1){
	if (r - l < 2){
		seg[id] = x;
		return ;
	}

	shift(id, l, r);

	int mid = (l+r)>>1;
	if (pos < mid)
		sett(pos, x, id<<1, l, mid);
	else
		sett(pos, x, id<<1|1, mid, r);

	seg[id] = max(seg[id<<1], seg[id<<1|1]);
}

void update(int L, int R, long long int x, int id = 1, int l = 0, int r = n+1){
	if (L <= l and r <= R){
		put(x, id);
		return ;
	}

	if (R <= l or r <= L)
		return ;

	shift(id, l, r);

	int mid = (l+r)>>1;
	update(L, R, x, id<<1, l, mid);
	update(L, R, x, id<<1|1, mid, r);
	seg[id] = max(seg[id<<1], seg[id<<1|1]);
}

long long int query(int L, int R, int id = 1, int l = 0, int r = n+1){
	if (L <= l and r <= R)
		return seg[id];

	if (R <= l or r <= L)
		return 0;

	shift(id, l, r);

	int mid = (l+r)>>1;
	return max(query(L, R, id<<1, l, mid), query(L, R, id<<1|1, mid, r));
}

int main(){
	cin >> n >> m;
	for (int i = 0; i < m; i++){
		scanf("%d%d%d", &l[i], &r[i], &a[i]);
		cnt[r[i]].push_back(i);
	}

	for (int i = 1; i <= n; i++){
		sett(i, query(0, i));

		for (int id: cnt[i]){
			update(l[id], r[id]+1, a[id]);
		}
	}

	cout << seg[1] << endl;
	return 0;
}


Measured memory_bytes: 25984