akhauriyash/Code-Regression huggingface dataset:
// copied by Nurstan Duisengaliev
// skatal
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
 
#define ll long long
#define all(x) x.begin(), x.end()
#define in insert
#define mp make_pair
#define F first
#define S second
#define ppf pop_front
#define pb push_back
#define ppb pop_back
#define pf push_front
#define pii pair <int, int>
#define boost() ios_base::sync_with_stdio(0), cin.tie(0)
#define sz(x) (int)x.size()
 
using namespace std;
//using namespace __gnu_pbds;

//template<typename T> using ordered_set = tree <T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;                         

const int N = (int)2e5 + 123;
const int mod = (int)1e9 + 7;
const ll INF = (ll)1e18 + 7;
void solve () {
	int x, y;
	cin >> x >> y;
	if (y % 2 == 0 && y / 2 >= x && x >= y / 2 - x) {
		cout << "Yes";
	}
	else cout << "No";
}   	
 
main () {
//	freopen (".in", "r", stdin);
//	freopen (".out", "w", stdout);
	boost ();
	int TT = 1;
//    cin >> TT;
	while (TT --) {
		solve ();
	}
	return 0;	
}

Measured memory_bytes: 3624
N = int(input())

c = []
for i in range(10):
    c.append([0] * 10)
    
#先頭がh,末尾がrの数字の数を記憶
for i in range(N):
    s = str(i+1)
    h = int(s[0])
    r = int(s[-1])
    c[h][r] += 1
    
    
ans = 0
for i in range(10):
  for j in range(10):
    ans += c[i][j]*c[j][i]
    
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<stdbool.h>
#include<math.h>
#include<limits.h>
#define MAX 7
char table[MAX][MAX];
char table_copy[MAX][MAX];
char table_ori[MAX][MAX];
int H, W, K;
int count(void)
{
    int ret = 0;
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (table[i][j] == '#')
                ret++;
        }
    }
    return ret;
}

int main()
{
    int ans = 0;
    scanf("%d %d %d", &H, &W, &K);
    for (int i = 0; i < H; i++)
        scanf("%s", table[i]);
    memcpy(table_ori, table, sizeof(table));


    for (int bit1 = 0; bit1 < (1 << W); bit1++) {
        memcpy(table, table_ori, sizeof(table));
        for (int i = 0; i < W; i++) {
            if (bit1 & (1 << i)) {
                for (int j = 0; j < H; j++)
                    table[j][i] = '*';
            }
        }

        memcpy(table_copy, table, sizeof(table));

        for (int bit2 = 0; bit2 < (1 << H); bit2++) {
            memcpy(table, table_copy, sizeof(table));
            for (int k = 0; k < H; k++) {
                if (bit2 & 1 << k) {
                    for (int l = 0; l < W; l++)
                        table[k][l] = '*';
                }
            }
            if (count() == K)
                ans++;
        }
    }

    printf("%d", ans);
}


Measured memory_bytes: 1736
n = int(input())
n1 = n
a = 2
x = []
while a*a <= n:
    while n % a == 0:
        n //= a
        x.append(str(a))
    a += 1
if n > 1:
    x.append(str(n))
print(str(n1) + ": " + " ".join(x))




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

using ll = long long;
using ull = unsigned long long;

#define MOD 1000000007

int main(void) {
    string S;
    ll count = 0;
    cin >> S;
    for(ll i = 1;i < S.size();i++) {
        if(S[i] == S[i - 1]) {
            S[i] = !(S[i - 1] - '0') + '0';
            count++;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 512
main :: IO ()
main = do
  s <- getLine
  let s1 = tail s   -- sの最初の文字を落とす。delete 1 s でもOK --
  let s2 = init s   -- sの最後の文字を落とす。take 3 s でもOK -- 
  if judge s1 || judge s2
    then putStrLn  "Yes"
    else putStrLn  "No"

judge s
  -- sの最初の文字(s !! 0)を3回繰り返したものと、sが同じかどうか比較
  | s == (replicate 3 (s !! 0)) = True
  | otherwise                   = False


Measured memory_bytes: 380
#include<iostream>
using namespace std;
int main(){
    int x,y;
    while(true){
        cin >> x >> y;
        if(x==0 && y==0){
            break;
        }
        else if(x<=y){
            cout << x <<" " << y <<endl;
        }
        else if(x>y){
            cout << y << " " << x <<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3080
#include <iostream>
#include <fstream>
#include <typeinfo>
#include <vector>
#include <cmath>
#include <map>
#include <string>
#include <algorithm>
#include <cstdio>
#include <queue>
#include <iomanip>
#include <cctype>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const double pi=acos(-1);
const double eps=1e-8;

int n,ans=inf;
vi num;

int main(){
	cin>>n;
	num=vi(n);
	for(int i=0;i<n;i++) cin>>num[i];
	for(int i=-100;i<=100;i++){
		int cost=0;
		for(int j=0;j<num.size();j++){
			int tmp=i-num[j];
			cost+=tmp*tmp;
		}
		ans=min(ans,cost);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main(int argc, char const *argv[])
{
    int a,b,c;
    bool f=1;
    cin>>a>>b>>c;
    if (a==b&&b!=c)
    {
        f=0;
    }
    else if(a==c&&b!=c)f=0;
    else if(b==c&&a!=b)f=0;
    if(!f)cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
using namespace std; //std::の省略のため
using ll = long long;

#define INF 1000000000000 //10^12:∞
#define MOD 1000000007    //10^9+7:合同式の法
#define MAXR 100000       //10^5:配列の最大のrange
const int MAX = 510000;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit()
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main()
{
    COMinit();

    ll n;
    cin >> n;

    ll ans = 0;

    for (ll i = 0; i < (n / 3); i++)
    {
        if (i == 0)
        {
            ans += COM(n, i);
        }
        else
        {
            ans += COM(n - (i + 1) * 3 + i, i);
        }
        ans %= MOD;
    }

    if (ans < 0)
        ans += MOD;

    cout << ans << endl;
}


Measured memory_bytes: 15576
N = int(input())
src = [list(map(int,input().split())) for i in range(N)]

ans = 0
for k in range(N):
    for i in range(N):
        for j in range(N):
            if src[i][j] > src[i][k] + src[k][j]:
                print(-1)
                exit()

for i in range(N-1):
    for j in range(i+1,N):
        for k in range(N):
            if k==i or k==j: continue
            if src[i][j] == src[i][k] + src[k][j]:
                break
        else:
            ans += src[i][j]
print(ans)

Measured memory_bytes: 44124
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define re register
#define ls rt<<1
#define rs rt<<1|1
#define mid ((l+r)>>1)
#define MAXN 200001
#define ll long long
using namespace std;
ll n,m,cnt,T;
ll A,B,C,D;
ll gcd(ll x,ll y)
{
	return y==0?x:gcd(y,x%y); 
}
int main()
{
	cin>>T;
	while(T--){
		cin>>A>>B>>C>>D;
		if(A<B) {
			cout<<"No"<<endl;
			continue;
		}
		if(D<B) {
			cout<<"No"<<endl;
			continue;
		}
		
		if(C>=B-1) {
			cout<<"Yes"<<endl;
			continue;
		}
		if(A%B>C) {
			cout<<"No"<<endl;
			continue;
		}
		if(C<B){
			ll g=gcd(B,D);
			if(B-C-2>g) {
				cout<<"No"<<endl;
				continue;
			}
			A%=B;
			ll x=(B-1-A)/g;
			ll s=A+g*x+g-B;
			ll j=A+x*g;
			if(j>C){
				cout<<"No"<<endl;
				continue;
			}
			if(s==0) {
				cout<<"Yes"<<endl;
				continue;
			}
			if(A<=C) cout<<"Yes"<<endl;
		 	else cout<<"No"<<endl;
		}
	}
}

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

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

// ====================================================================

int main() {
  string s;
  cin >> s;
  int dp[s.size() + 1][3];  // 読みやすいように3にしてる
  memset(dp, 0, sizeof(dp));

  // DPをする、dp[i][1,2]…i文字目までで、直近の文字の長さが1or2
  dp[1][0] = dp[2][1] = 1;
  for (int i = 0; i <= s.size(); i++) {
    if (i >= 1 && s[i - 1] != s[i])  // 1→1
      chmax(dp[i + 1][1], dp[i][1] + 1);
    if (i >= 2 && s[i - 2] != s[i] || s[i - 1] != s[i + 1])  // 2→2
      chmax(dp[i + 2][2], dp[i][2] + 1);
    chmax(dp[i + 2][2], dp[i][1] + 1);  // 1→2
    chmax(dp[i + 1][1], dp[i][2] + 1);  // 2→1
  }

  cout << max(dp[s.size()][1], dp[s.size()][2]) << endl;

  // for (int i = 0; i <= s.size(); i++)
  //   cout << dp[i][1] << " ";
  // cout << endl;
  // for (int i = 0; i <= s.size(); i++)
  //   cout << dp[i][2] << " ";
  // cout << endl;
}


Measured memory_bytes: 2948
#include <stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r) {
    int x, i, j, t;
    x = A[r];
    i = p - 1;
    for ( j = p; j < r; j++) {
        if (A[j] <= x ) {
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i + 1;
}

int main () {
    int i, q;

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

    q = partition(0, n-1);

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

    return 0;
}



Measured memory_bytes: 2104
#include <stdio.h>

int main()
{
	char S[100];
	char P[100];
	char ch;
	int sn,pn,i,j;
	sn = pn = 0;

	while ((ch = getchar()) != '\n') S[sn++] = ch;

	while ((ch = getchar()) != '\n' && ch != EOF ) P[pn++] = ch;

	for (i = 0; i < sn; i++)
	{
		for (j = 0; j < pn; j++) if (S[(i+j)%sn] != P[j]) break;

		if (j == pn) break;
	}

	if (j == pn) printf("Yes\n");
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 1752
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    char c;
    cin >> c;
    if(c>='A'&&c<='Z'){
        cout << "A" << endl;
    }else{
        cout << "a" << endl;
    }

    return 0;
}

Measured memory_bytes: 3636
////   SHAKALAKA BOOM BOOM ////

#include<bits/stdc++.h>

#define ll           long long
#define vi           vector<ll>
#define pb           push_back
#define all(a)       (a).begin(),(a).end()
#define F            first
#define S            second
#define sz(x)        (int)x.size()
#define hell         1000000007
#define endl         '\n'
#define fl(z,a,b)    for(ll z=a;z<b;z++)
#define ifl(i,a,b)   for(ll i=a;i<=b;i++)
#define dfl(i,a,b)   for(ll i=a;i>=b;i--)
#define speed        ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define debug1(x)    cerr << "at line " << __LINE__ << ": " << #x << " = " << (x) << endl
#define debug2(x)    cerr << #x << " = " << (x) << endl
using namespace std;
//=====================
//const int N=1e6;





void solve()
{
        ll n,k;
        cin>>n>>k;
        vi arr(n+1);
        ifl(i,1,n)
        {
            cin>>arr[i];
        }

        vi dp(n+1);
        dp[1] = 0;
        ifl(i,2,n)
        {
            ll ans  = dp[i-1] + abs(arr[i]-arr[i-1]);

            ifl(j,2,k) {
                if (i - j >= 1) ans = min(ans, dp[i - j] + abs(arr[i] - arr[i - j]));

            }
            dp[i] = ans;
        }

        cout<< dp[n] << endl;

}



int main()
{
    ll TESTS=1;
    speed;
  //  cin>>TESTS;
    while(TESTS--) solve();
    return 0;
}


Measured memory_bytes: 1920
#include <string>
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_set>
#include <utility>
#include <cmath>
#include <stdlib.h> 
#include <stdio.h>
#include <iterator>
#include <chrono>
#include <iomanip>
#include <set>
#include <map>
#include <list>
#include <iterator>
#include <deque>
#include <stack>
#include <queue>
#include <fstream>
#include <limits>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <sstream>
#include <random>
#include <cassert>

using namespace std;
#define ffor(n) for(int i = 0; i < n; i++)
#define fffor(n) for(int j = 0; j < n; j++)
int INF = 1e9 + 7;

int main(void) {
	cin.tie(0); ios::sync_with_stdio(0);
	
	int n, x, t;
	cin >> n >> x >> t;
	if (n % x != 0) n += x;
	cout << ((int)(n / x)) * t << '\n';
}





/*
C:\Users\User\Desktop\comp_programming\final_straw_after_this_im_switching_to_vs_code\final_straw_after_this_im_switching_to_vs_code.cpp
*/

Measured memory_bytes: 3620
// UOIAUAI

#include <iostream>

using namespace std;

int main(){
	char c;
	char vowel[5] = {'a', 'e', 'i', 'o', 'u'};
	cin >> c;

	bool flag = false;
	for (int i = 0; i < 5; ++i)
		if (vowel[i] == c){
			flag = true;
			break;
		}

	if (flag)
		cout << "vowel" << endl;
	else
		cout << "consonant" << endl;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main {
	public static void main(String[] args) throws Exception{
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
        int b = sc.nextInt();
        int m = sc.nextInt();
        TreeSet<Integer> list = new TreeSet<>();
        for(int i = a; i < a + m; i++){
        	if(i <= b){
            	list.add(i);
            }
        }
        for(int i = b; i > b - m; i--){
        	if(i >= a){
            	list.add(i);
            }
        }
        for(Integer x: list){
        	System.out.println(x);
        }
	}
}

Measured memory_bytes: 36128
void main()
{
    long n = rdElem;
    long[] a = rdRow;

    long[] l = new long[n+1];
    foreach (i; 0 .. n)
    {
        l[i+1] = gcd(l[i], a[i]);
    }

    long[] r = new long[n+1];
    foreach_reverse (i; 0 .. n)
    {
        r[i] = gcd(r[i+1], a[i]);
    }

    long result;
    foreach (i; 0 .. n)
    {
        result = max(result, gcd(l[i], r[i+1]));
    }

    result.writeln;
}

enum long mod = 10^^9 + 7;
enum long inf = 1L << 60;

T rdElem(T = long)()
if (!is(T == struct))
{
    return readln.chomp.to!T;
}

alias rdStr = rdElem!string;
alias rdDchar = rdElem!(dchar[]);

T rdElem(T)()
if (is(T == struct))
{
    T result;
    string[] input = rdRow!string;
    assert(T.tupleof.length == input.length);
    foreach (i, ref x; result.tupleof)
    {
        x = input[i].to!(typeof(x));
    }
    return result;
}

T[] rdRow(T = long)()
{
    return readln.split.to!(T[]);
}

T[] rdCol(T = long)(long col)
{
    return iota(col).map!(x => rdElem!T).array;
}

T[][] rdMat(T = long)(long col)
{
    return iota(col).map!(x => rdRow!T).array;
}

void rdVals(T...)(ref T data)
{
    string[] input = rdRow!string;
    assert(data.length == input.length);
    foreach (i, ref x; data)
    {
        x = input[i].to!(typeof(x));
    }
}

void wrMat(T = long)(T[][] mat)
{
    foreach (row; mat)
    {
        foreach (j, compo; row)
        {
            compo.write;
            if (j == row.length - 1) writeln;
            else " ".write;
        }
    }
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.traits;
import std.container;
import std.functional;
import std.typecons;
import std.ascii;
import std.uni;

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

int N;
int p[200100];
int Tree1[600000];
int Left[600000], Right[600000];
int Tree2[600000];
int n;
int L[200010], R[200010], S[200010];
int m;
vector<vector<int> > G(200010);
int degree[200010];
struct data{
	int seq;
	int val;
};
struct cmp {
	bool operator() (const struct data a, const struct data b) const {
		return a.val > b.val;
	}
};
priority_queue<struct data, vector<struct data>, cmp > pq;
int res[200010];
int resL;
int wh[200010];

int find_mn1(int nd, int ll, int rr)
{
	if(Left[nd]>=ll && Right[nd]<=rr){
		return Tree1[nd];	
	}
	if(Left[nd]>rr || Right[nd]<ll)
		return 1000000000;
	int v1 = find_mn1(2*nd, ll, rr);
	int v2 = find_mn1(2*nd+1, ll, rr);
	if(v1 < v2)
		return v1;
	else
		return v2;
}

int find_mn2(int nd, int ll, int rr)
{
	if(Left[nd]>=ll && Right[nd]<=rr){
		return Tree2[nd];	
	}
	if(Left[nd]>rr || Right[nd]<ll)
		return 1000000000;
	int v1 = find_mn2(2*nd, ll, rr);
	int v2 = find_mn2(2*nd+1, ll, rr);
	if(v1 < v2)
		return v1;
	else
		return v2;
}

void calc(int ll, int rr, int seq)
{
	int l, r;
	if(ll+1==rr){
		L[m] = ll;
		R[m] = rr;
		S[m] = seq;
		m ++;
		return ;
	}
	if(ll%2==0){
		l = wh[find_mn1(1, ll, rr)];//
		r = wh[find_mn2(1, l, rr)];
	}
	else{
		l = wh[find_mn2(1, ll, rr)];
		r = wh[find_mn1(1, l, rr)];
	}
	L[m] = l;
	R[m] = r;
	S[m] = seq;
	m ++;
	int tm = m-1;
	if(l>ll){
		//calc(ll, l-1, m-1);
		calc(ll, l-1, tm);
	}
	if(r<rr)
		calc(r+1, rr, tm);
	if(l+1<r-1)
		calc(l+1, r-1, tm);
}

void solve()
{
	int i, j;
	n = 1;
	while(n<N)
		n *= 2;
	for(i=n; i<2*n; i++){
		Left[i] = i-n;
		Right[i] = i-n;
	}
	for(i=n-1; i>=1; i--){
		Left[i] = Left[2*i];
		Right[i] = Right[2*i+1];
	}
	for(i=n; i<n+N; i++){
		if( (i-n)%2 == 0)
			Tree1[i] = p[i-n];
		else
			Tree1[i] = 1000000000;
	}
	for(; i<2*n; i++){
		Tree1[i] = 1000000000;
	}
	for(i=n-1; i>=1; i--){//i--;
		if(Tree1[2*i] < Tree1[2*i+1])
			Tree1[i] = Tree1[2*i];
		else
			Tree1[i] = Tree1[2*i+1];
	}
	for(i=n; i<n+N; i++){
		if( (i-n)%2 == 1)
			Tree2[i] = p[i-n];
		else
			Tree2[i] = 1000000000;
	}
	for(; i<2*n; i++){
		Tree2[i] = 1000000000;
	}
	for(i=n-1; i>=1; i--){
		if(Tree2[2*i] < Tree2[2*i+1])
			Tree2[i] = Tree2[2*i];
		else
			Tree2[i] = Tree2[2*i+1];
	}
	
	for(i=0; i<N; i++){
		wh[p[i]] = i;
	}
	m = 0;
	calc(0, N-1, -1);//N
	for(i=0; i<m; i++){
		if(S[i] != -1)
			G[S[i]].push_back(i);
	}
	int u, v;
	for(i=0; i<m; i++){
		for(j=0; j<G[i].size(); j++){
			v = G[i][j];
			degree[v] ++;
		}
	}
	resL = 0;
	struct data dt, dt2;
	dt.seq = 0;
	dt.val = p[L[0]];
	pq.push(dt);
	while(!pq.empty() ){
		dt = pq.top() ;
		pq.pop() ;
		u = dt.seq ;
		res[resL] = p[L[u]];
		resL ++;
		res[resL] = p[R[u]];
		resL ++;
		for(i=0; i<G[u].size(); i++){
			v = G[u][i];
			degree[v] --;
			if(degree[v] == 0){
				dt2.seq = v;
				dt2.val = p[L[v]];
				pq.push(dt2);
			}
		}
	}
	printf("%d", res[0]);
	for(i=1; i<resL; i++){
		printf(" %d", res[i]);
	}
	printf("\n");
}

int main()
{
	int i;
	scanf("%d", &N);
	for(i=0; i<N; i++)
		scanf("%d", &p[i]);
	solve();
	return 0;
}

Measured memory_bytes: 28800
#include <iostream>
#include <string>
#include <cmath>
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long int ll;


int main(){
	  int N;
		cin>>N;
	  ll A[N+1],B[N];
		for (int i = 0; i < N+1; ++i) {
		  cin>>A[i];
		}
		for (int i = 0; i < N; ++i) {
			cin>>B[i];
		}
    ll ans=0;
		for (int i = 0; i < N; ++i) {
			if(A[i]-B[i]>=0){
				ans+=B[i];
				A[i]=A[i]-B[i];
			}
			else if(B[i]-A[i]>=A[i+1]){
				ans+=(A[i]+A[i+1]);
				A[i]=0;
				A[i+1]=0;
			}
			else {
				ans+=B[i];
				A[i+1]=A[i+1]-(B[i]-A[i]);
				A[i]=0;
			}
		}
		cout<<ans<<endl;

}


Measured memory_bytes: 1792
use std::cmp;

const INF: i64 = 1e17 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let v = sc.read::<usize>() - 1;
        let u = sc.read::<usize>() - 1;
        graph[v].push(u);
        graph[u].push(v);
    }

    let mut dp1 = vec![vec![]; n];
    let mut dp2 = vec![vec![]; n];
    dfs(0, 0, &graph, &a, &mut dp1, &mut dp2);

    for i in 1..(n + 1) {
        if dp1[0][i] < INF {
            println!("{}", i - 1);
            return;
        }
        if dp2[0][i] < 0 {
            println!("{}", i - 1);
            return;
        }
    }
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    a: &Vec<i64>,
    dp1: &mut Vec<Vec<i64>>,
    dp2: &mut Vec<Vec<i64>>,
) {
    dp1[v].push(INF);
    dp1[v].push(if a[v] > 0 { a[v] } else { INF });
    dp2[v].push(INF);
    dp2[v].push(a[v]);
    for &next in graph[v].iter() {
        if next == p { continue; }
        dfs(next, v, graph, a, dp1, dp2);

        dp1[v] = connect(&dp1[v], &dp1[next], &dp2[next], true);
        dp2[v] = connect(&dp2[v], &dp1[next], &dp2[next], false);
    }
}

fn connect(dp: &Vec<i64>, child1: &Vec<i64>, child2: &Vec<i64>, flag: bool) -> Vec<i64> {
    assert_eq!(child1.len(), child2.len());
    let child_cuts = child1.len() - 1;
    let mut ans = vec![INF; dp.len() + child_cuts];
    for i in 0..dp.len() {
        if dp[i] == INF { continue; }
        for j in 0..child1.len() {
            if i + j >= 1 {
                if child1[j] != INF {
//                    ans[i + j - 1] = cmp::min(ans[i + j - 1], dp[i] + child1[j]);
                    ch_min(&mut ans[i + j - 1], dp[i] + child1[j]);
                }
                if child2[j] != INF && !flag {
//                    ans[i + j - 1] = cmp::min(ans[i + j - 1], dp[i] + child2[j]);
                    ch_min(&mut ans[i + j - 1], dp[i] + child2[j]);
                }
            }
            if child1[j] != INF || child2[j] < 0 {
                ans[i + j] = cmp::min(ans[i + j], dp[i]);
            }
        }
    }
    ans
}

fn ch_min<T: PartialOrd>(a: &mut T, b: T) {
    if *a > b {
        *a = b;
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 211836
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <ctime>
#include <cstring>
#include <functional>
#include <iostream>
#include <iomanip>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <regex>
#include <vector>

#define fix(n)          cout<<fixed<<setprecision(n)
#define rep(i,n)        for (int i = 0; i < (n); ++i)
#define all(a)          (a).begin(), (a).end()
#define sort(a)         sort(all(a))
#define uniq(a)         sort(a);(a).erase(unique(all(a)), (a).end())
#define reverse(a)      reverse(all(a))
#define ctos(c)         string(1, (c))
#define out(d)          cout << (d)
#define outl(d)         std::cout<<(d)<<"\n"
#define YES()           cout << "YES" << endl
#define NO()            cout << "NO" << endl
#define Yes()           cout << "Yes" << endl
#define No()            cout << "No" << endl
#define ceil(x, y)      ((x + y - 1) / (y))
#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'
#define dbg(v)          for (size_t _ = 0; _ < v.size(); ++_){ cerr << #v << "[" << _ << "] : " << v[_] << '\n'; }
#define pb              push_back
#define fst             first
#define int             long long
#define INF             __LONG_LONG_MAX__

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

const ll MOD = 1000000007; // 10^9 + 7
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll n;

ll f(ll k) {
  return k * (n/k) * (n/k+1) / 2;
}

void solve() {
  cin >> n;
  outl(f(1) - f(3) - f(5) + f(15));
}

signed main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  srand((unsigned)time(NULL));
  fix(12);

  solve();
}


Measured memory_bytes: 3180
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {
		new Main().run();
	}
	
	public void run() throws IOException {
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
		}
		reader.close();
		
		System.out.println(getMinCost(n, a));
	}
	
	private int getMinCost(int n, int[] a) {
		
		boolean[] flags = new boolean[n];
		int[] b = new int[n];
		int mn = Integer.MAX_VALUE;
		int mx = Integer.MIN_VALUE;
		for (int i = 0; i < n; i++) {
			b[i] = a[i];
			mn = Math.min(mn, a[i]);
			mx = Math.max(mx, a[i]);
		}
		Arrays.sort(b);
		
		int[] p = new int[mx + 1];
		for (int i = 0; i < n; i++) {
			p[b[i]] = i;
		}
		
		int cost = 0;
		for (int i = 0; i < n; i++) {
			if (flags[i]) continue;
			int idx = i;
			int sum = 0;
			int cnt = 0;
			int m = Integer.MAX_VALUE;
			while (true) {
				flags[idx] = true;
				cnt++;
				int val = a[idx];
				sum += val;
				m = Math.min(m, val);
				idx = p[val];
				if (flags[idx]) break;
			}
			int c1 = sum + (cnt - 2) * m;
			int c2 = c1 + 2 * (m + mn);
			c2 -= (cnt - 1) * (m - mn);
			cost += Math.min(c1, c2);
		}
		return cost;
	}
}



Measured memory_bytes: 25088
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
constexpr int inf = 3e18;


int N,A[205];
string S;
void solve(){
	cin>>N;
	rep(i,N)cin>>A[i];
	cin>>S;
	vector<int>v;
	rev(i,N){
		int j=A[i];
		for(int k:v)chmin(j,j^k);
		if(j){
			if(S[i]=='0')v.pb(j);
			else {
				puts("1");return;
			}
		}
	}
	puts("0");
}
signed main(){
	int t;cin>>t;
	while(t--)solve();
}


Measured memory_bytes: 3584
///IN THE NAME OF ALLAH
 #include <bits/stdc++.h>
 using namespace std;
 map<int,int>mp;
 int main() {
  int n;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
   int a;
   scanf("%d",&a);
   mp[a]=1;
  }
  if(mp.size()%2==0)
    cout<<mp.size()-1;
  else cout<<mp.size();
}


Measured memory_bytes: 4992
from collections import deque

def doRoundRobin(nt,q):
    result = []

    countTime = 0

    while len(nt) > 0:
        tmp = nt.popleft()
        if tmp[1] <= q:
            countTime += tmp[1]
            result.append([tmp[0],countTime])
        else:
            tmp[1] -= q
            countTime += q
            nt.append(tmp)
    return result


if __name__ == '__main__':
    n, q = map(int,input().split())
    
    nameTime = deque()
    for _ in range(n):
        a, b =  input().split()
        nameTime.append([a,(int)(b)])

    resultNameTime = doRoundRobin(nameTime,q)

    for x in resultNameTime:
        print(x[0],x[1])

Measured memory_bytes: 18456
A,B,C,D,E,F = map(int,input().split())
ans = []
def my_max(x,y):
    if x[0] < y[0]:
        return y
    else:
        return x
maxi = [0,0,0]
for a in range(F // (A*100) + 1):
    for b in range(F // (B*100) + 1):
        water =  100*a*A + 100*b*B 
        if water <= F:
            for c in range(E*water//100//C+1):
                for d in range(E*water//100//D+1):
                    suger = C*c + D*d
                    if suger+water <= F and E*water//100 >= suger \
                    and water + suger > 0:
                        t = (suger/(suger+water),suger+water,suger)
                        maxi = my_max(t,maxi)
ans.sort()
print(maxi[1],maxi[2])

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

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

//#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 998244353;
using P = pair<ll, ll>;

signed main() {
	int n, k; cin >> n >> k; k--;
	string s; cin >> s;
	int tmp = s[k] - 'A';
	s[k] = (char)('a' + tmp);
	cout << s << endl;
	return 0;
}



Measured memory_bytes: 3600
using System;
using System.Collections.Generic;
using System.Linq;

namespace KthSubstring {
    class ConsoleInput {
        private string[] currentLine = null;
        private int currentCursor = 0;

        public string Get() {
            if (currentLine == null || currentCursor >= currentLine.Length) {
                currentLine = Console.ReadLine().Split(' ');
                currentCursor = 0;
            }
            var res = currentLine[currentCursor];
            currentCursor++;
            return res;
        }

        public int GetInt() {
            return int.Parse(Get());
        }
    }

    class Program {
        static ConsoleInput input = new ConsoleInput();

        static void Main(string[] args) {
            var s = input.Get();
            var k = input.GetInt();

            var counterTable = new Dictionary<char, List<int>>();

            for(int i = 0; i < s.Length; ++i) {
                char c = s[i];
                if (!counterTable.ContainsKey(c)) {
                    counterTable.Add(c, new List<int>());
                }
                counterTable[c].Add(i);
            }

            int substringCount = 0;
            for(char c = 'a'; c <= 'z'; ++c) {
                if (counterTable.ContainsKey(c)) {
                    var substrings = new List<string>();
                    substringCount++;
                    if(substringCount == k) {
                        Console.WriteLine(c);
                        return;
                    }
                    foreach (int index in counterTable[c]) {

                        for(int i = 2; i <= 5; i++) {
                            if (index + i > s.Length) break;
                            substrings.Add(s.Substring(index, i));
                        }
                    }
                    var distincts = substrings.Distinct();
                    if(distincts.Count() + substringCount >= k) {
                        var answer = distincts.OrderBy(x => x).ElementAt(k-substringCount-1);
                        Console.WriteLine(answer);
                        return;
                    }
                    else {
                        substringCount += distincts.Count();
                    }
                }
            }
            
        }
    }
}


Measured memory_bytes: 13792
#include<stdio.h>
#include<queue>
#include<algorithm>
using namespace std;
char str[102][102];
int bfs[102][102];
int v[102][102];
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
int main(){
	int a,b;
	while(scanf("%d%d",&a,&b),a+b){
		for(int i=0;i<102;i++)
			for(int j=0;j<102;j++)
				str[i][j]='.';
		for(int i=0;i<b;i++){
			scanf("%s",str[i+1]+1);
		}
		for(int i=0;i<102;i++)
			for(int j=0;j<102;j++){
				bfs[i][j]=-1;
				v[i][j]=0;
			}
		bfs[0][0]=0;
		deque<pair<int,int> > Q;
		Q.push_back(make_pair(0,0));
		while(Q.size()){
			int row=Q.front().first;
			int col=Q.front().second;
			Q.pop_front();
			if(v[row][col])continue;
			v[row][col]=1;
			for(int i=0;i<4;i++){
				if(0<=row+dx[i]&&row+dx[i]<102&&0<=col+dy[i]&&col+dy[i]<102){
					if((!~bfs[row+dx[i]][col+dy[i]])||(bfs[row+dx[i]][col+dy[i]]>bfs[row][col]+(((str[row][col]=='#')&&(str[row+dx[i]][col+dy[i]]!='#'))?1:0))){
						bfs[row+dx[i]][col+dy[i]]=bfs[row][col]+(((str[row][col]=='#')&&(str[row+dx[i]][col+dy[i]]!='#'))?1:0);
						if((str[row][col]=='#')&&(str[row+dx[i]][col+dy[i]]!='#')){
							Q.push_back(make_pair(row+dx[i],col+dy[i]));
						}else Q.push_front(make_pair(row+dx[i],col+dy[i]));
					}
				}
			}
		}
		for(int i=0;i<102;i++){
			for(int j=0;j<102;j++){
				if(str[i][j]=='&')printf("%d\n",bfs[i][j]);
			}
		}
	}
}

Measured memory_bytes: 1200
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (ll i = 0; i < (ll)n; ++i)
static const int dx[4] = { 0, 1, 0, -1 };
static const int dy[4] = { 1, 0, -1, 0 };
static const char dir[4] = { 'u', 'r', 'd', 'l' };
static const ll INF = 1ll << 60;
static const ll MOD = 1e9 + 7;

ll N, Ma, Mb, dp[51][510][510];

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> N >> Ma >> Mb;
    vector<ll> a(N), b(N), c(N);
    rep(i, N) { cin >> a[i] >> b[i] >> c[i]; }
    rep(i, 51)
    {
        rep(j, 510)
        {
            rep(k, 510)
            {
                dp[i][j][k] = INF;
            }
        }
    }
    dp[0][0][0] = 0;
    rep(i, N)
    {
        rep(wa, 500)
        {
            rep(wb, 500)
            {
                if (dp[i][wa][wb] >= INF) {
                    continue;
                }
                dp[i + 1][wa][wb] = min(dp[i + 1][wa][wb], dp[i][wa][wb]);
                dp[i + 1][wa + a[i]][wb + b[i]] = min(dp[i + 1][wa + a[i]][wb + b[i]], dp[i][wa][wb] + c[i]);
            }
        }
    }
    ll res = INF;
    for (int wa = 1; wa < 500; ++wa) {
        for (int wb = 1; wb < 500; ++wb) {
            if (wa * Mb != wb * Ma) {
                continue;
            }
            res = min(res, dp[N][wa][wb]);
        }
    }
    if (res != INF) {
        cout << res << endl;
    } else {
        cout << -1 << endl;
    }
    return 0;
}

Measured memory_bytes: 103936
import java.util.Scanner;

public class Main {
    public static void main(String args[]){
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        String[] strs = str.split("");
        System.out.println(Integer.parseInt(strs[0])+Integer.parseInt(strs[1])+Integer.parseInt(strs[2]));
    }
}

Measured memory_bytes: 22740
#include<iostream>
#include<stdio.h>
using namespace std;
int main(){
	unsigned int n;
	scanf("%d",&n);
	if(n<15)
	printf("%d",n*800);
	else if(n>=15&&n<=1000)
	printf("%d",n*800-(200*(n/15)));
	return 0;
}

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

typedef long long ll;
typedef long double ld;

#define pb push_back
#define sort(s) sort(s.begin(),s.end())
#define reverse(s) reverse(s.begin(),s.end())
#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++)

const ll mod = 1e9+7;

//最大公約数
ll gcd(ll a, ll b) {
    return b ? gcd(b, a%b) : a;
}

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

//素数判定
bool isPrime(ll x){
    ll 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(ll n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        n /= 10;
    }
    return res;
}

//桁数
int dignum(ll n) {
    int res = 0;
    while(n > 0) {
        res++;
        n /= 10;
    }
    return res;
}

//文字列中の特定の文字カウント
ll stringcount(string s,char c){
    return count(s.cbegin(),s.cend(),c);
}

//階乗
ll ka(ll i){
    ll res=1;
    while(i>0){
        res=res*i;
        i--;
    }
    return res;
}
 
//ncr
ll ncr(ll x,ll y){
    ll a = x;
    ll b = 1;
    if(y>(x/2)){
        y=x-y;
    }
    for(ll i=1;i<y;i++){
        a*=x-i;
        b*=i+1;
    }
    return a/b;
}

//フィボナッチ数列
ll f(ll x){
    ll dp[x+1];
    dp[1]=1;
    dp[2]=1;
    for(ll i=3;i<=x;i++){
        dp[i]=dp[i-1]+dp[i-2];
    }
    return dp[x];
}

//char->int
int ctoi(char c){
    return c-'0';
}



int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
      cin >> s[i];
    }
    int ans = 1;
    sort(s);
  
    for(int i=1;i<n;i++){
      if(s[i-1]!=s[i]){
        ans++;
      }
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 9576
import java.util.*;
public class Main{
  public static void main(String[]args){
      Scanner sc = new Scanner(System.in);

      int a = sc.nextInt();
      int b = sc.nextInt();
      int c = sc.nextInt();
      int sum = a+b+c;

        if (sum==17) {
          System.out.println("YES");
        }else{
          System.out.println("NO");
        }


  }
}


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

int p[55];

int find(int a){
    if(p[a] == a) return a;
    return p[a] = find(p[a]);
}

void unite(int a, int b){
    int ra = find(a);
    int rb = find(b);
    if(ra != rb) p[ra] = rb;
}

int main()
{
    int n, m;
    cin >> n >> m;
    int a[m], b[m];
    for(int i=0; i<m; i++){
        cin >> a[i] >> b[i];
        a[i]--;
        b[i]--;
    }
    
    int ans =0;
    for(int i=0; i<m; i++){
        for(int j=0; j<n; j++) p[j] = j;
        for(int j=0; j<m; j++){
            if(j == i) continue;
            unite(a[j], b[j]);
        }
		bool bridge = false;
		for (int j = 1; j < n; j++) {
			if (find(j-1) != find(j)) bridge = true;
		}
		if (bridge) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
// 選択ソート O(N^2)

#include <iostream>
using namespace std;

int selectionSort(int A[], int N) {
    int ex{ 0 }, min{0};
    for (int i = 0; i < N-1; i++) {
        min = i;

        for (int j = i; j < N; j++) {
            if (A[j] < A[min]) {
                min = j;
            }
        }
        swap(A[i], A[min]);
        if( i != min ) ex++;
    }
    return ex;
}

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

    int A[100];

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

    int ex = selectionSort(A,N);

    for (int i = 0; i < N; i++) {
        if (i != 0) cout << ' ';
        cout << A[i];
    }
    cout << endl;
    cout << ex << endl;

}


Measured memory_bytes: 3088
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v,c) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

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


int main(){

    int n;
    cin >> n;
    ll a[n];
    inrep(n,a);

    ll d[n] = {};
    rrep(i,n,1){
	if(a[i-1] >= a[i])d[i-1] = d[i]+1;
    }
    ll ans = 0;
    rep(i,0,n)ans = max(ans,d[i]);
    P(ans);
    return  0;
}


Measured memory_bytes: 1792
import math

def factrization_prime(number):
    factor = {}
    div = 2
    s = math.sqrt(number)
    while div < s:
        div_cnt = 0
        while number % div == 0:
            div_cnt += 1
            number //= div
        if div_cnt != 0:
            factor[div] = div_cnt
        div += 1
    if number > 1:
        factor[number] = 1
    return factor

number = int(input())
factor = factrization_prime(number)
ans = 0
for i in factor.values():
  n = 0
  while n*(n+1)//2 <= i:
    n +=  1
  ans += n-1
print(ans)

Measured memory_bytes: 9128
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define INF 1LL<<50
#define fst first
#define snd second
#define pb push_back
#define int long long
#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i = (b-1);i>=a;i--)
#define REP(i,n)  FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ITR(itr,mp) for(int itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(int itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define debug(x)  cout << #x << " = " << (x) << endl;
typedef long long ll;
typedef pair<ll,ll> P;

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

  int n;
  cin >> n;
  
  int a[n],b[n];
  REP(i,n) cin >> a[i] >> b[i];
  
  int cnt = 0;
  RREP(i,n){
    cnt += b[i]-((a[i]+b[i]+cnt)%b[i] == 0?b[i]:(a[i]+b[i]+cnt)%b[i]);
    //debug(cnt);
  }
  
  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1792
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.PriorityQueue;
import java.util.Scanner;
import java.util.TreeSet;

import org.omg.Messaging.SyncScopeHelper;

public class Main {
	Scanner sc = new Scanner(System.in);
	public static void main(String[] args){
		new Main();
	}
	public Main(){
		new Test_100().doIt();
	}
	class Test_100{
		void doIt() {
			int X = sc.nextInt();
			int T = sc.nextInt();
			int ans = X - T;
			if(ans < 0)System.out.println(0);
			else System.out.println(ans);
		}
	}
}


Measured memory_bytes: 21844
## 安定なソート

def bubbleSort(array)
  (0..(array.length-1)).each do |i|
    (array.length-1).step(i+1, -1).each do |j|
      if array[j][:value] < array[j-1][:value]
        temp = array[j]
        array[j] = array[j-1]
        array[j-1] = temp
      end
    end
  end
  array
end

def selectSort(array)
  (0..(array.length-1)).each do |i|
    minj = i
    (i..(array.length-1)).each do |j|
      if array[j][:value] < array[minj][:value]
        minj = j
      end
    end
    temp = array[i]
    array[i] = array[minj]
    array[minj] = temp
  end
  array
end

def is_stable?(unsorted, sorted)
  (0..(unsorted.length-1)).each do |i|
    (i+1..(unsorted.length-1)).each do |j|
      (0..(unsorted.length-1)).each do |a|
        (a+1..(unsorted.length-1)).each do |b|
          if unsorted[i][:value] == unsorted[j][:value] \
            && unsorted[i] == sorted[b] \
            && unsorted[j] == sorted[a]
            return false
          end
        end
      end
    end
  end
  return true
end

$debug = false
n = gets.to_i
cards = gets.split.map { |card| {suit: card[0], value: card[1].to_i} }

b = bubbleSort(cards.dup)
puts b.map { |card| card[:suit] + card[:value].to_s }.join(" ")
puts is_stable?(cards, b) ? "Stable" : "Not stable"

s = selectSort(cards.dup)
puts s.map { |card| card[:suit] + card[:value].to_s }.join(" ")
puts is_stable?(cards, s) ? "Stable" : "Not stable"



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

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

int main()
{
  int W, H;
  while (cin >> W >> H) {
    vector<string> map(H);
    pair<int, int> target;
    for (int i = 0; i < H; ++i) {
      cin >> map[i];
      if (map[i].find_first_of("t") != string::npos) {
	target.first = map[i].find_first_of("t");
	target.second = i;
      }
    }

    vector<vector<int> > valid(H, vector<int>(W, 0));
    queue<pair<int, int> > que;
    que.push(make_pair(0, 0));
    while (!que.empty()) {
      const pair<int, int> p = que.front();
      que.pop();

      if (valid[p.second][p.first])
	continue;

      valid[p.second][p.first] = 1;
      for (int d = 0; d < 4; ++d) {
	pair<int, int> pp = make_pair(p.first+dx[d], p.second+dy[d]);
	if (pp.first < 0 || pp.first >= W ||
	    pp.second < 0 || pp.second >= H ||
	    map[pp.second][pp.first] == '#' ||
	    valid[pp.second][pp.first])
	  continue;
	que.push(pp);
      }
    }

    int N, ans = -1;
    if (valid[target.second][target.first])
      ans = 0;

    cin >> N;
    for (int i = 0; i < N; ++i) {
      int x, y;
      cin >> x >> y;
      if (ans != 0 && map[y][x] == '#') {
	map[y][x] = '.';
	for (int d = 0; d < 4; ++d) {
	  pair<int, int> p = make_pair(x+dx[d], y+dy[d]);
	  if (p.first < 0 || p.first >= W ||
	      p.second < 0 || p.second >= H ||
	      map[p.second][p.first] == '#' ||
	      !valid[p.second][p.first])
	    continue;
	  que.push(p);
	  valid[p.second][p.first] = 0;
	}

	while (!que.empty()) {
	  const pair<int, int> p = que.front();
	  que.pop();
	  
	  if (valid[p.second][p.first])
	    continue;
	  
	  valid[p.second][p.first] = 1;
	  for (int d = 0; d < 4; ++d) {
	    pair<int, int> pp = make_pair(p.first+dx[d], p.second+dy[d]);
	    if (pp.first < 0 || pp.first >= W ||
		pp.second < 0 || pp.second >= H ||
		map[pp.second][pp.first] == '#' ||
		valid[pp.second][pp.first])
	      continue;
	    que.push(pp);
	  }
	}
	
	if (ans == -1 && valid[target.second][target.first])
	  ans = i+1;
      }
    }
    
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 5864