akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main(void)
{
    int H,N;

    scanf("%d %d", &H,&N);

    int attack[N],i;
    int sum = 0;

    for(i = 0; i < N; i++)
    {
        scanf("%d", &attack[i]);
        sum = sum + attack[i];
    }

    if (sum >= H)
        printf("Yes\n");
    else
        printf("No\n");

    return 0;
}


Measured memory_bytes: 512
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;
using Library;
using static Library.Input;

namespace AtCoderTemplate
{
    class ProgramB
    {
        static void Main()
        {
            int n = NextInt;
            int count = 0;

            for (int i = 1; i <= n; i++)
            {
                if (i.ToString().Length % 2 == 1)
                {
                    count++;
                }
            }

            System.Console.WriteLine(count);
        }
    }
}

namespace Library
{
    class Input
    {
        static IEnumerator<string> enumerator = new string[] { }.AsEnumerable().GetEnumerator();

        public static string Line => Console.ReadLine();

        public static string[] StrArr => Line.Split(' ');

        public static int NextInt => int.Parse(NextWord());

        public static long NextLong => long.Parse(NextWord());

        public static List<int> IntList => StrArr.Select(int.Parse).ToList();

        public static List<long> LongList => StrArr.Select(long.Parse).ToList();

        public static IEnumerable<long[]> TakeLine(int N)
        {
            return Enumerable.Repeat(0, N).Select(_ => Console.ReadLine().Split(' ').Select(long.Parse).ToArray());
        }

        public static string NextWord()
        {
            while (!enumerator.MoveNext())
            {
                enumerator = StrArr.AsEnumerable().GetEnumerator();
            }
            return enumerator.Current;
        }
    }
}


Measured memory_bytes: 13268
#include <stdio.h>

int main(){
        int n;
        int cost = 0;
        scanf("%d\n", &n);
        int V[n], C[n];
        for(int i=0;i<n;++i){
                scanf("%d", &V[i]);
        }
        for(int i=0;i<n;++i){
                scanf("%d", &C[i]);
        }
        for(int i=0;i<n;++i){
                if(V[i]>C[i]){
                        cost = cost + V[i] - C[i];
                }
        }
        printf("%d", cost);
        return 0;
}

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

using namespace std;

#define for_(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
#define makep make_pair

int N, M;
int t[20020], s[20020], d[20020];

int v[20020];
vector<piii> pac;

void solve() {
	pac.clear();
	for_(i,0,M) pac.push_back(piii(t[i], pii(s[i], d[i])));
	sort(all(pac));
	
	memset(v, 0, sizeof(v));
	v[1] = 1;
	for_(i,0,M) {
		piii pp = pac[i];
		pii p = pp.second;
		v[p.second] |= v[p.first];
	}
	
	int ans = 0;
	for_(i,1,N + 1) ans += v[i];
	cout << ans << endl;
}

int main() {
	while (cin >> N >> M, N) {
		for_(i,0,M) cin >> t[i] >> s[i] >> d[i];
		solve();		
	}
	
	return 0;
}

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

using ll=long long;
using namespace std;

int main(){
    string a,b;
    cin>>a>>b;
    string n=a+b;
    
    int num=stoi(n);
    
    long double ans=sqrt(num);
    if(ans*ans==num) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
    return 0;
}

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

const int MAX = 510000;
const int MOD = 1000000007;

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() {
    int N, K; cin >> N >> K;
    // 前処理
    COMinit();
    for(int i = 1; i <= K; i++){
        cout << (COM(K - 1, i - 1) * COM(N - K + 1, i)) % MOD << endl;
    }      
}

Measured memory_bytes: 12288
n, a, b, c, d = map(int, input().split())
n -= 1
k = abs(b-a)
if k > n*d:
    print("NO")
elif k >= n*c:
    print("YES")
else:
    i = -(-(n*c-k)//(2*c))
    haba = k - (n-2*i)*c
    if haba <= (d-c)*(n-i):
        print("YES")
    else:
        j = i-1
        haba = (n-2*j)*c - k
        if haba <= (d-c)*j:
            print("YES")
        else:
            print("NO")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define PLI pair<ll, int>
#define PIL pair<int, ll>
#define STR string
#define Fst first
#define Snd second
#define SHN 1e9
#define LSHN 1e18
using namespace std;
ll n,m;
int a[200010];
int d[200010][100];
int main()
{
	cin >>n>>m;
	for (int i=0;i<n;i++) cin >>a[i],a[i]--,d[i][0]=a[i];
	for (int i=1;i<67;i++)
		for (int j=0;j<n;j++) d[j][i]=d[d[j][i-1]][i-1];
	int t=0;
	for (int i=0;i<64;i++)
	{
		if ((1ll<<i)>m) break;
		if (m & (1ll<<i)) t=d[t][i];
	}
	cout <<t+1;
	return 0;
}

Measured memory_bytes: 82540
from collections import defaultdict
N, K = map(int, input().split())
d = defaultdict(int)
for _ in range(N):
  a, b = map(int, input().split())
  d[a] += b
d = sorted(d.items(), key=lambda x:x[0])
s = 0
for i in range(len(d)):
  s += d[i][1]
  if K <= s:
    print(d[i][0])
    exit()


Measured memory_bytes: 15324
n,a,b=map(int,input().split())
mod=10**9+7

def comb(n,r,mod):
    p,q=1,1
    for i in range(r):
        p=p*(n-i)%mod 
        q=q*(i+1)%mod 
    return p*pow(q,mod-2,mod)%mod

nca=comb(n,a,mod)
ncb=comb(n,b,mod)

ans=pow(2,n,mod)
ans=(ans-((nca+ncb)%mod+1))%mod
print(ans)

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

struct test {
    long H;
    int N;
    int A[100000];
    char *ans;
} td[] =
    {
        {
            10, 3,
            {4, 5, 6},
            "Yes",
        },
        {
            20, 3,
            {4, 5, 6},
            "No",
        },
        {  
            210, 5,
            {31, 41, 59, 26, 53},
            "Yes",
        },
        {
            211, 5,
            {31, 41, 59, 26, 53},
            "No",
        },
    };

void
solver(long h, int n, int *a)
{
    int i;
    long sum=0;
    for (i=0; i<n; i++)
        sum += a[i];
    if (h>sum)
        printf("No\n");
    else
    {
        printf("Yes\n");
    }
}

int
main(int argc, char *argv[])
{
    int tt;
#if 0
    for(tt=0;tt<sizeof(td)/sizeof(struct test); tt++) {
        solver(td[tt].H, td[tt].N, td[tt].A);
        printf("%s\n",td[tt].ans);
    }
#else
    long H;
    int N;
    int A[100000];
    scanf("%ld%d", &H, &N);
    for(tt=0; tt<N; tt++) {
        scanf("%d", A+tt);
    }
    solver(H, N, A);
#endif
    return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n = scan.nextInt();
		int[] h = new int[n];
		int i;
		for(i = 0; i < n; i++) {
			h[i] = scan.nextInt();
		}
		for(i = n - 1; i >= 1; i--) {
			if(h[i] >= h[i - 1]) {

			}else if(h[i - 1] - h[i] == 1) {
				h[i - 1]--;
			}else {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}

Measured memory_bytes: 50620
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#define maxn 100010
using namespace std;
int n,a[maxn];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	int ans1=a[n];
	int mid=a[n]/2+a[n]%2;
	int pos=0,val=0x7fffffff;
	for(int i=1;i<n;i++){
		if(abs(a[i]-mid)<=val){
			pos=i;
			val=abs(a[i]-mid);
		}
	}
	printf("%d %d\n",ans1,a[pos]);
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
//#include <set>
//#include <map>
//#include <iomanip>
//#include <algorithm>
//#include <numeric>
//#include <queue>
//#include <stack>
//#include <math.h>
//#include <vector>
//#include <string>
//#include <list>
//#include <deque>
//#include <unordered_map>
//typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    int count;
    int ans=0;

    cin >> n;
    for(int i=1; i<=n; i++){
        if(i%2==0){
            continue;
        }
        count=0;
        for(int j=1; j<=i; j++){
            if(i%j==0){
                count++;
            }
        }
        if(count==8){
            ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
while 1:
    D,W=list(map(int,input().split()))
    if (D,W)==(0,0):
        break
    garden = [list(map(int,input().split())) for _ in range(D)]
    ans=0
    for wi in range(W):
        for wj in range(wi+2,W):
            for di in range(D):
                for dj in range(di+2,D):
                    edge_min = float("inf")
                    water_sum=0
                    count=0
                    in_max=0
                    for w in range(wi,wj+1):
                        for d in range(di,dj+1):
                            if w in (wi,wj) or d in (di,dj) :
                                edge_min= min(garden[d][w] , edge_min)
                                ###print(edge_min,garden[d][w],"eee",min(edge_min,garden[d][w]))
                            else:
                                water_sum+=garden[d][w]
                                in_max=max(in_max,garden[d][w])
                                count+=1
                    if edge_min>in_max:                    
                        ans=max(ans,edge_min*count - water_sum)
    print(ans)



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

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

	long long inf = 1e15;
	int max_val = 100005;
	int n, ww;
	cin >> n >> ww;
	vector<int> w(n + 1), v(n + 1);
	for(int i = 1; i <= n; i++) {
		cin >> w[i] >> v[i];
	}
	vector<vector<long long>> dp(n + 1, vector<long long>(max_val, inf));
	dp[0][0] = 0;
	for(int i = 1; i <= n; i++) {
		for(int j = 0; j < max_val; j++) {
			if(v[i] > j) dp[i][j] = dp[i - 1][j];
			else dp[i][j] = min(dp[i - 1][j], dp[i - 1][j - v[i]] + w[i]);
		}
	}
	for(int i = max_val - 1; i >= 0; i--) {
		if(dp[n][i] <= ww) {
			cout << i << endl;
			return 0;
		}
	}
	return 0;	
}

Measured memory_bytes: 80256
N = int(input())
g = [[-1 for _ in range(N)] for _ in range(N)]
for i in range(N):
    m = int(input())
    for j in range(m):
        x,y = map(int,input().split())
        g[i][x-1] = y

ans = 0
for i in range(1 << N):
    hornest = [0] * N
    for j in range(N):
        if (i >> j)&1:
            hornest[j] = 1
    is_ok = 1
    for j in range(N):
        if hornest[j] and is_ok:
            for k in range(N):
                if g[j][k] == -1:
                    continue
                if g[j][k] != hornest[k]:
                    is_ok = 0
    if is_ok:
        ans = max(ans,hornest.count(1))
        
print(ans)


Measured memory_bytes: 3064
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;


void fall(vector<vector<int>>&stones) {
	for (int t = 0; t < 5; ++t) {
		for (int y = stones.size()-1; y > 0; --y) {
			for (int x = 0; x < 5; ++x) {
				if (stones[y][x] == -1 && stones[y - 1][x]!=-1) {
					stones[y][x] = stones[y - 1][x];
					stones[y - 1][x] = -1;
				}
			}
		}
	}
}

int getans(vector<vector<int>>&stones) {
	vector<vector<bool>>banishes(stones.size(), vector<bool>(5, false));
	int score = 0;
	for (int y = 0; y < stones.size(); ++y) {
		for (int l = 0; l < 3; ++l) {
			if (stones[y][l] == stones[y][l + 1] && stones[y][l + 1] == stones[y][l + 2] && stones[y][l] != -1) {
				for (int x =l; x < l+3; ++x) {
					banishes[y][x] = true;
				}
			}
		}
	}
	for (int y = 0; y < stones.size(); ++y) {
		for (int x = 0; x < 5; ++x) {
			if (banishes[y][x]) {
				score += stones[y][x];
				stones[y][x] = -1;
			}
		}
	}
	if (score) {
		fall(stones);
		return score + getans(stones);
	}
	else {
		return 0;
	}
}
int main() {
	while (1) {
		int N; cin >> N;
		if (N) {
			vector<vector<int>>stones(N, vector<int>(5));
			for (int y = 0; y < N; ++y) {
				for (int x = 0; x < 5; ++x) {
					cin >> stones[y][x];
				}
			}
			int ans = getans(stones);
			cout << ans << endl;
		}
		else {
			break;
		}
	}
	return 0;
}

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

int main()
{
    int n, q;
    cin >> n >> q;
    string str;
    cin >> str;

    vector<int> vec((int)str.size());
    for(int i = 1; i < (int)str.size(); ++i)
    {
        if(str[i-1] == 'A'
        && str[i] == 'C')
        {
            vec[i] = vec[i-1]+1;
        }
        else
        {
            vec[i] = vec[i-1];
        }
        
    }

    for(int i = 0; i < q; ++i)
    {
        int l,r;
        cin >> l >> r;
        --l;
        --r;
        cout << vec[r] - vec[l] << endl;
    }
}

Measured memory_bytes: 1408
N= int(input())
x = 0

for i in range(1, N+1):
    if i%3 == 0:
        print("% d"%i, end="")
    else:
        x = i
        while x:
            if x%10 == 3:
                print("% d" % i, end="")
                break
            x //= 10
print()


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

int main(){
	string s;
	cin >> s;
	int n=(int)s.length()+1;
	vector<int> v(n,0);
	int count = 0;
	for(int i=0;i<n-1; i++){
		if (s[i]=='<'){ 
			count+=1;
			v[i+1] = count;
		}
		else count=0;
	}
	count = 0;
	for(int i=n-2;i>=0; i--){
		if (s[i]=='>'){ 
			count+=1;
			v[i] = max(count,v[i]);
		}
		else count=0;
	}
	long long sum=0;
	for(int x: v) sum+=x;
	cout << sum << endl;
	/*for(int i=0;i<n;i++){
		cout << v[i] << " ";
		if(i!=n-1) cout << s[i] << " ";
	}*/
			
     
}


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

#############
# Libraries #
#############

import sys
input = sys.stdin.readline

import math
#from math import gcd
import bisect
from collections import defaultdict
from collections import deque
from functools import lru_cache


#############
# Constants #
#############

MOD = 10**9+7
INF = float('inf')

#############
# Functions #
#############

######INPUT######
def I(): return int(input().strip())
def S(): return input().strip()
def IL(): return list(map(int,input().split()))
def SL(): return list(map(str,input().split()))
def ILs(n): return list(int(input()) for _ in range(n))
def SLs(n): return list(input().strip() for _ in range(n))
def ILL(n): return [list(map(int, input().split())) for _ in range(n)]
def SLL(n): return [list(map(str, input().split())) for _ in range(n)]

######OUTPUT######
def P(arg): print(arg); return
def Y(): print("Yes"); return
def N(): print("No"); return
def E(): exit()
def PE(arg): print(arg); exit()
def YE(): print("Yes"); exit()
def NE(): print("No"); exit()

#####Shorten#####
def DD(arg): return defaultdict(arg)


#####Inverse#####
def inv(n): return pow(n, MOD-2, MOD)

######Combination######
kaijo_memo = []
def kaijo(n):
  if(len(kaijo_memo) > n):
    return kaijo_memo[n]
  if(len(kaijo_memo) == 0):
    kaijo_memo.append(1)
  while(len(kaijo_memo) <= n):
    kaijo_memo.append(kaijo_memo[-1] * len(kaijo_memo) % MOD)
  return kaijo_memo[n]

gyaku_kaijo_memo = []
def gyaku_kaijo(n):
  if(len(gyaku_kaijo_memo) > n):
    return gyaku_kaijo_memo[n]
  if(len(gyaku_kaijo_memo) == 0):
    gyaku_kaijo_memo.append(1)
  while(len(gyaku_kaijo_memo) <= n):
    gyaku_kaijo_memo.append(gyaku_kaijo_memo[-1] * pow(len(gyaku_kaijo_memo),MOD-2,MOD) % MOD)
  return gyaku_kaijo_memo[n]

def nCr(n,r):
  if(n == r):
    return 1
  if(n < r or r < 0):
    return 0
  ret = 1
  ret = ret * kaijo(n) % MOD
  ret = ret * gyaku_kaijo(r) % MOD
  ret = ret * gyaku_kaijo(n-r) % MOD
  return ret

######Factorization######
def factorization(n):
  arr = []
  temp = n
  for i in range(2, int(-(-n**0.5//1))+1):
    if temp%i==0:
      cnt=0
      while temp%i==0: 
        cnt+=1 
        temp //= i
      arr.append([i, cnt])
  if temp!=1:
    arr.append([temp, 1])
  if arr==[]:
    arr.append([n, 1])
  return arr

#####MakeDivisors######
def make_divisors(n):
  divisors = []
  for i in range(1, int(n**0.5)+1):
    if n % i == 0:
      divisors.append(i)
      if i != n // i: 
        divisors.append(n//i)
  return divisors

#####LCM#####
def lcm(a, b):
    return a * b // gcd (a, b)

#####BitCount#####
def count_bit(n):
  count = 0
  while n:
    n &= n -1
    count += 1
  return count

#####ChangeBase#####
def base_10_to_n(X, n):
  if X//n:
    return base_10_to_n(X//n, n)+[X%n]
  return [X%n]

def base_n_to_10(X, n):
  return sum(int(str(X)[-i])*n**i for i in range(len(str(X))))

#####IntLog#####
def int_log(n, a):
  count = 0
  while n>=a:
    n //= a
    count += 1
  return count

#############
# Main Code #
#############

a,b,x = IL()

P(b//x-(a-1)//x)

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

typedef long long ll;
#define x first
#define y second

const int N = 4e3 + 10;
const ll mod = 1e9 + 7;
#define int long long 
int n;
int dp[N][N];
int posw[N], posb[N], a[N];
char c[N];
vector < int > b_set[N], w_set[N];

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

	#ifdef KEK
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif


	cin >> n;
	for (int i = 1; i <= 2 * n; ++i)
	{
		cin >> c[i] >> a[i];
		if (c[i] == 'B') posb[a[i]] = i;
		else posw[a[i]] = i;
	}

	for (int i = 1; i <= 2 * n; ++i)
	{
		for (int j = i + 1; j <= 2 * n; ++j)
		{
			if (c[i] == 'B') b_set[j].push_back(a[i]);
			else w_set[j].push_back(a[i]);
		}
	}
	for (int i = 1; i <= 2 * n; ++i) sort(b_set[i].begin(), b_set[i].end()), sort(w_set[i].begin(), w_set[i].end());

	for (int i = 0; i <= n; ++i)
	{
		for (int j = 0; j <= n; ++j)
		{
			dp[i][j] = 1e9;
			if (i == 0 && j == 0) 
			{
				dp[i][j] = 0;
				continue;
			}
			if (i > 0)
			{
				int cnt_b = b_set[posb[i]].end() - upper_bound(b_set[posb[i]].begin(), b_set[posb[i]].end(), i - 1);
				int cnt_w = w_set[posb[i]].end() - upper_bound(w_set[posb[i]].begin(), w_set[posb[i]].end(), j);
				dp[i][j] = min(dp[i][j], dp[i - 1][j] + cnt_b + cnt_w);
			} 
			if (j > 0)
			{
				int cnt_w = w_set[posw[j]].end() - upper_bound(w_set[posw[j]].begin(), w_set[posw[j]].end(), j - 1);
				int cnt_b = b_set[posw[j]].end() - upper_bound(b_set[posw[j]].begin(), b_set[posw[j]].end(), i);
				dp[i][j] = min(dp[i][j], dp[i][j - 1] + cnt_b + cnt_w);
			}
		}	
	}
	cout << dp[n][n];
	
	return 0;	
}

Measured memory_bytes: 145664
//Keep Working Hard
  // I__Like__Food
  #include<bits/stdc++.h>
  #include <ext/pb_ds/assoc_container.hpp> 
  #include <ext/pb_ds/tree_policy.hpp>
  #define rep(i,a,b) for(int i = a; i <=b; i++)
  #define rep2(i,a,b) for(int i = a; i>=b; i--)
  #pragma GCC optimize("O3")
  #pragma GCC optimize("Ofast") 
  #pragma GCC optimize("unroll-loops")
  using namespace std;
  using namespace __gnu_pbds;
  #define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
  #define endl "\n"
  #define int long long
  #define all(v) v.begin(),v.end()
  #define PB push_back
  #define MP make_pair
  #define double long double
  #define trace1(x)                cerr<<#x<<": "<<x<<endl
  #define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
  #define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
  #define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
  #define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
  #define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
  #define cases int testcases;cin>>testcases; while(testcases--)
  #define mod 1000000007
  #define N 405
  #define INF 1e16
  const double PI = acos(-1);



int32_t main()
{
       

    IOS

    int n,k;
    cin >> n >> k;

    vector<int> arr(n+1);

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

    int dp[n+1][k+1];

    //  dp[i][j] denotes the number of ways to give j candies to first i students

    for(int i = 0; i <= n; i++)for(int j = 0; j <= k; j++)dp[i][j] = 0;

      for(int j = 0; j <= n; j++)dp[j][0] = 1;



        vector<int> pre(k+1);

    for(int i = 1; i <= n; i++)
    {

      pre[0] = dp[i-1][0]%mod;

      for(int s = 1; s <= k; s++)
      {
        pre[s] = (pre[s-1]%mod + dp[i-1][s]%mod + mod)%mod;
        pre[s] %= mod;
      }

      for(int j = 0; j <= k; j++)
      {
        if(j - arr[i] - 1 < 0)
          {
            dp[i][j] = pre[j]%mod;
          }
        else 
          {
            dp[i][j] = (pre[j]%mod - pre[j-arr[i]-1]+ mod)%mod;
          }
        dp[i][j]%= mod;
      }
    }



    cout << dp[n][k];






  

  return 0;
} 

Measured memory_bytes: 80000
#include <stdio.h>

int main(void)
{
	int a,b,c,d;
	int s1,s2;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	s1=a*b,s2=c*d;
	if(s1 == s2)
		{printf("%d",s1);}
	else
		{
		if(s1 > s2)
			{printf("%d",s1);}
		else
			{printf("%d",s2);}
		}
	return 0;
}




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

using namespace std;
const int N=1e5+5;
vector<int>adj[N];
int dp[N];
bool vis[N];
int dfs(int u){
    vis[u]=true;
    if(adj[u].size()==0){
        return 0;
    }
    for(int i=0;i<adj[u].size();i++){
            int v=adj[u][i];
        if(!vis[v]){
          dp[u]=max(dfs(v)+1,dp[u]);
        }
        else{
          dp[u]=max(dp[v]+1,dp[u]);
        }
    }
    return dp[u];
}
int main(){
    int n,m;
    cin >> n >> m;
    for(int i=1;i<=m;i++){
      int u,v;
      cin >> u >> v;
      adj[u].push_back(v);
    }
    for(int i=1;i<=n;i++){
        if(!vis[i]) dfs(i);
//        cout << dp[i] << endl;
    }
    int res=0;
    for(int i=1;i<=n;i++){
        res=max(res,dp[i]);
    }
    //res+=1;
    cout << res << endl;
    return 0;
}

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

//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")
//#pragma GCC target("avx,avx2,fma")

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef set<int> si;
typedef set<ll> sll;
typedef map<int, int> mii;
typedef map<ll, ll> mll;

const double pi = acos(-1.0);
const long long INF = 2e18;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define sz size()
#define in insert
#define endl "\n"

#define sqr(a) ((a) * (a))
#define jor(a) !(a&1)// jor means EVEN number
#define bjor(a) (a&1)// bjor means ODD number

#define all(a)  a.begin(), a.end()
#define mem(arr, b) memset(arr, b, sizeof(arr)) //memset only for -1 and 0
//fill(a, a+n, 5) //fill for any value

#define for0(i,b) for(int i=0;i<(b);i++)
#define for1(i,b) for(int i=1;i<=(b);i++)
#define forab(i,a,b) for(int i=(a);i<=(b);i++)
#define forba(i,b,a) for(int i=(b);i>=(a);i--)
#define rep(i,a,b,c) for(int i=(a);i!=(b);i+=(c))

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define fileRead freopen("input.txt", "r", stdin);
#define fileWrite freopen("output.txt", "w", stdout);

void print(int a[], int n){ // for testing or debugging
    for(int i=0;i<n;i++)cout<<a[i]<<" "; cout<<endl;
}

//-------------------------------------------------------------------\\


int main()
{
    IOS;
    //fileRead
    int tc = 1;
    //cin>>tc;
    while(tc--)
    {
        int n; cin>>n;
        cout<<n+sqr(n)+sqr(n)*n;
    }
}

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

int main() {
	int n;
	long int l[100];
	int count=0;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%ld", l + i);
	}

	for (int a = 0; a < n; a++) {
		for (int b = 0; b < a; b++) {
			for (int c = 0; c < b; c++) {
				if (l[a] + l[b] > l[c] && l[b] + l[c] > l[a] && l[c] + l[a] > l[b]) {
					if(l[a]!=l[b]&& l[c] != l[b]&& l[a] != l[c])
					count++;
				}
			}
		}
	}

	printf("%d\n", count);
	return 0;
}

Measured memory_bytes: 1736
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative

main = do
    [w,h,x,y,r] :: [Int] <- map read . words <$> getLine
    putStrLn $ if 0 <= x-r && x+r <= w && 0 <= y-r && y+r <= h
                   then "Yes"
                   else "No"

Measured memory_bytes: 3644
# -*- coding: utf-8 -*-
"""
Created on Thu Jul  9 15:39:52 2020

@author: TatsuyaYamamoto
"""

N = int(input())

AC, WA, TLE, RE = 0, 0, 0, 0

for i in range(N):
    temp = input()
    if temp == 'AC':
        AC += 1
    elif temp == 'WA':
        WA += 1
    elif temp == 'TLE':
        TLE += 1
    else:
        RE += 1

print('AC x {}'.format(AC))
print('WA x {}'.format(WA))
print('TLE x {}'.format(TLE))
print('RE x {}'.format(RE))

Measured memory_bytes: 9196
#include <iostream>
#include <algorithm>
#include <cstdio>
using namespace std;
char g[300][300];
int main(){
	int n;
	while(cin>>n && n){
		for(int i=0;i<n;i++)cin>>g[i];
		int dx[]={1,1,1,0};
		int dy[]={-1,0,1,1};
		int ans=0;
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				if(g[i][j]=='1'){
					for(int d=0;d<4;d++){
						int ii, jj;
						for(ii=i,jj=j; 0<=ii&&ii<n&&0<=jj&&jj<n && g[ii][jj]=='1'; ii+=dy[d],jj+=dx[d]);
						ans=max({ans,abs(ii-i),abs(jj-j)});
					}
				}
			}
		}
		cout<<ans<<endl;
	}
}

Measured memory_bytes: 1236
n = gets.to_i
a = gets.chomp.split(' ').map(&:to_i)
number_count = {}
ans = []
a.each do |i|
    if !number_count[i]
        number_count[i] = [1,0]
    else
        number_count[i][0] += 1
        number_count[i][1] = (number_count[i][0]*(number_count[i][0]-1)/2)
    end
end
sum = 0
number_count.keys.each do |key|
    sum += number_count[key][1]
end

ans = a.map do |i|
    sum - number_count[i][0]+1
end
puts ans

Measured memory_bytes: 48204
#include <iostream>
#include <algorithm>
#include <vector>
#include <string.h>
#include <string>
#include <cstring>
#include <stdlib.h>
using namespace std;

int main()
{
    int N,M,C;
    cin >> N >> M >> C;
    int B[M];
    for(int i=0; i<M; i++){
        cin >> B[i];
    }
    int A[N][M];
    for(int i=0; i<N; i++){
        for(int j=0; j<M; j++){
            cin >> A[i][j];
        }
    }
    int ans=0;
    for(int i=0; i<N; i++){
        int sum=0;
        for(int j=0; j<M; j++){
            sum=sum+A[i][j]*B[j];
        }
        sum+=C;
        if(sum>0){
            ans++;
        }
    }
    cout << ans;
    return 0;
}


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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

void Main(){
    int n; cin >> n;
    vector<pair<P, int>> r(n);
    vector<pair<ll, int>> pl(n), mi(n);
    rep(i, n){
        int x, y; cin >> x >> y;
        r[i] = {{x, y}, i};
        pl[i] = {y + x, i};
        mi[i] = {x - y, i};
    }
    sort(all(r));
    sort(rall(pl));
    sort(rall(mi));
    ll ans = 0;
    rep(i, n){
        // 右上にぶたん, 右下にぶたん
        ll a = r[i].fi.fi;
        ll b = r[i].fi.se;
        ans = max(ans, pl[0].fi - (a+b));
        ans = max(ans, mi[0].fi - (a-b));
    }
    cout << ans << endl;
    return;
}

int main(){
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

Measured memory_bytes: 11908
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a = b; return 1; } return 0; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧  
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     
　　　　／　　　＼　 　 |　|     
　　　 /　　 /￣￣￣￣/　　|  
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿  
　 　　　＼/＿＿＿＿/　（u　⊃  
---------------------------------------------------------------------------------------------------*/



string S;
//---------------------------------------------------------------------------------------------------
int check(int i, int j) { // S[i..j]
    if (S[i] == '0') {
        int len = j - i + 1;
        if (len == 1) return 1;
        return 0;
    }

    int sm = 0;
    rep(k, i, j + 1) sm = sm * 10 + S[k] - '0';
    return sm <= 255;
}
//---------------------------------------------------------------------------------------------------
void _main() {
    cin >> S;
    int N = S.length();
    int ans = 0;
    rep(a, 1, N) rep(b, a + 1, N) rep(c, b + 1, N) {
        if (check(0, a - 1) and check(a, b - 1) and check(b, c - 1) and check(c, N - 1)) ans++;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3224
#include <iostream>
#include <vector>
#include <map>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> X(N), Y(N);
  map<pair<int,int>, int> M;
  int x, y, w;
  for(int i = 0; i < N; ++i){
    cin >> x >> y >> w;
    X[i] = x;
    Y[i] = y;
    M[make_pair(x,y)] = w;
  }
  long long int ans = 0;
  for(int i = 0; i < N; ++i){
    x = X[i];
    y = Y[i];
    for(int dx = -1; dx < 2; dx += 2){
      for(int dy = -1; dx < 2; dx += 2){
        long long int t = 0;
        for(int j = 0; j < 2; ++j){
          for(int k = 0; k < 2; ++k){
            int x_ = x + dx*j, y_ = y + dy*k;
            t += M[make_pair(x_,y_)];
          }
        }
        ans = max(ans, t);
      }
    }
  }
  cout << ans << " / " << 1 << endl;
  return 0;
}

Measured memory_bytes: 41072
#include <cstdio>
#include <cctype>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;

#define ll long long
#define reg register
#define rep(i, a, b) for (reg int i = (a), i##end = (b); i <= i##end; ++i)
#define dep(i, a, b) for (reg int i = (a), i##end = (b); i >= i##end; --i)

template <typename _typer> inline _typer read() {
    _typer init = 0;
    char ch = getchar(), k = 0;
    for ( ; !isdigit(ch); ch = getchar()) k = (ch == '-');
    for ( ; isdigit(ch); ch = getchar())
        init = (init << 3) + (init << 1) + (ch ^ 48);
    return k ? -init : init;
}
const ll N = 200005, INF = 1e9;

/*******************************************************************************
 *
 *
 *
 ******************************************************************************/

int mx, mx2, A[N];

int main() {
    int n = read<int>();
    rep (i, 1, n) {
        A[i] = read<int>();
        if (A[i] > mx) mx2 = mx, mx = A[i];
        else if (A[i] > mx2) mx2 = A[i];
    }
    rep (i, 1, n) {
        if (A[i] == mx) printf("%d\n", mx2);
        else printf("%d\n", mx);
    }
    return 0;
}



Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n);i++)
#define rep1(i,n) for(int i=1; i<(n); i++)
#define repe(i,n) for(auto &&i:n)
#define all(v) (v).begin(),(v).end()
#define decimal fixed<<setprecision(20)
#define fastcin() cin.tie(0);ios::sync_with_stdio(false)
using namespace std;
using LL = long long;
const int INF = 1e9;
const LL LLINF = 1e16;

int main(){
    int n;
    cin >> n;
    vector<int> v(n), c(n);
    rep(i, n) cin >> v[i];
    rep(i, n) cin >> c[i];
    int ans = 0;
    rep(i, n){
        if(v[i] - c[i] > 0) ans += v[i] - c[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>

using namespace std;

int main()
{
  int n,m,c;
  
  cin>>n>>m>>c;
  vector<int>B(m);
  int i;
  for(i=0;i!=m;i++)
    cin>>B[i];
  int C = 0;
  for(i=0;i!=n;i++)
  {
    int j;
    int s = 0;
    for(j=0;j!=m;j++)
    {
      int x;
      cin>>x;
      s += x*B[j];
    }
    
    if(s+c>0)
      C++;
  }
  
  cout<<C;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
  
using namespace std;
  
int main(void){
  int t;
  cin >> t;
  int h,m,s;
  int a=t%3600;
  h=(t-a)/3600;
  s=a%60;
  m=(a-s)/60;
 
  cout << h << ":" << m << ":" << s << endl;
  
  return 0;
  
}


Measured memory_bytes: 3096
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    double r = Double.parseDouble(sc.next());
    double s = Math.PI * r * r;
    double l = 2 * Math.PI * r;
    System.out.printf("%.6f %.6f", s, l);
    System.out.println("");
  }
}



Measured memory_bytes: 26332
#include <bits/stdc++.h>
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define pb push_back
#define f first
#define sc second
using namespace std;
ll mod=1e9+7,i,j;
ll n,m;
int main(){
    ll x,y;
    cin>>n;
    cin>>x>>y;
    if(x>y) swap(x,y);
    if((y-x)%2==0){
        cout<<(y-x)/2;
    }
    else {
            ll ans=0;
        if(x-1<n-y){
            ll k=x-1;
            y=y-x+1;
            ans=ans+x-1;
            x=1;
            if((y-1)%2==0) y=y;
            else {
                y--;
                ans++;
            }
            ans=ans+(y-1)/2;
            cout<<ans;
        }
        else{
                ll ans=0;
            ll k=n-y;
            x=x+n-y;
            ans=ans+n-y;
            y=n;
            if((y-x)%2==0) y=y;
            else {
                x++;
                ans++;
            }
            ans=ans+(y-x)/2;
            cout<<ans;
        }
    }
    return 0;
}



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

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

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> x(N);
    for (int i = 0; i < N; i++) {
        cin >> x[i];
    }
    vector<int> dx(N);
    for (int i = 0; i < N; i++) {
        dx[i] = abs(X - x[i]);
    }

    int ans = dx[0];
    for (int i = 0; i < N; i++) {
        ans = gcd(ans, dx[i]);
    }
    cout << ans << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<vector>
using namespace std;
long N,K,mod=1e9+7;
vector<int>G[1<<17];
long ans=1;
long dfs(int u,int p,long c)
{
	if(K-c>0)ans=ans*(K-c)%mod;
	else ans=0;
	int cnt=1+(p>=0);
	for(int v:G[u])
	{
		if(v!=p)dfs(v,u,cnt++);
	}
}
main()
{
	cin>>N>>K;
	for(int i=1;i<N;i++)
	{
		int a,b;cin>>a>>b;
		a--,b--;
		G[a].push_back(b);
		G[b].push_back(a);
	}
	dfs(0,-1,0);
	cout<<ans<<endl;
}


Measured memory_bytes: 9984
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define all(a) a.begin(),a.end()
#define rall(c) (c).rbegin(),(c).rend()
#define mp make_pair
#define endl '\n'
#define vec vector<ll>
#define mat vector<vector<ll> >
#define fi first
#define se second
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef long double ld;
typedef complex<double> comp;
const ll INF=1e9+7;
const ll MOD=998244353;
const int MAX=200010;

template< class T >
struct BIT
{
  vector< T > data;

  BIT(int sz)
  {
    data.assign(++sz, 0);
  }

  T sum(int k)
  {
    T ret = 0;
    for(++k; k > 0; k -= k & -k) ret += data[k];
    return (ret);
  }

  void add(int k, T x)
  {
    for(++k; k < data.size(); k += k & -k) data[k] += x;
  }
};

signed main(){
    ll n;cin>>n;
    BIT<ll> bit(n);
    ll q;cin>>q;
    rep(i,n){
        ll a;cin>>a;
        bit.add(i,a);
    }
    rep(i,q){
        ll a,b,x;cin>>a>>b>>x;
        if(a==0){
            bit.add(b,x);
        }else{
            ll res=bit.sum(x-1);
            if(b)res-=bit.sum(b-1);
            cout<<res<<endl;
        }
    }
}

Measured memory_bytes: 8216
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < n; i++)
#define rep2(i, l, r) for (int i = (l); i < (r); i++)
#define ALL(x) (x).begin(), (x).end()     //昇順
#define RALL(x) (x).rbegin(), (x).rend()  // 降順
#define pri(x) cout << (x) << "\n"
#define pri2(x, y) cout << (x) << " " << (y) << "\n"
#define pri3(x, y, z) cout << (x) << " " << (y) << " " << (z) << "\n"
const long long mod = 1e9 + 7;
typedef long long ll;
typedef priority_queue<int> PQ;
typedef vector<long long> VL; // VL a(n);
typedef vector<bool> VB;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<char> VC;
typedef vector<VS> VSS;
typedef vector<VC> VCC;
typedef vector<VL> VLL; // VII a(n,VI(m)) n * m
typedef pair<ll, ll> PL;
typedef map<ll, ll> MP; // MP a;
typedef vector<pair<ll, ll>> PS; // PS a(n);

template <class T, class U>
bool chmax(T &a, U b) {
  if (a <= b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T, class U>
bool chmin(T &a, U b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
template <typename T>
ostream &operator<<(ostream &os, vector<T> &v) {
  os << "{";
  rep(i, (int)v.size()) { os << v[i] << (i < v.size() - 1 ? ", " : ""); }
  os << "}";
  return os;
}

// g++ -std=c++11 prac.cpp
// operator << (cout,a);
// chmin(min,a)

int main() {
  ll n,k,m,x=0,y=0,z = 0,cnt=0,h=0,w=0,ans=0,sum = 0, Max = 0, Min = 3e9+1;
  string s;
  cin >> n >> k;
  for(int b=k+1; b<=n; b++){
    Max = 0;
    int p = n/b;
    int r = n%b;   // n = pb + r とする。
    chmax(Max,r-k+1);
    ans += p*(b-k) + Max;
    if(k==0)
      ans--;
  }
  pri(ans);
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a + b > c + d) cout << "Left" << "\n";
  else if(a + b == c + d) cout << "Balanced" << "\n";
  else cout << "Right" << "\n";
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>

using namespace std;

int main(void){

  long long n;
  cin>>n;
   
  int tmp=n,ans=0;
  while(tmp>0){
    ans +=tmp%10;
    tmp /=10;
  }
  
  if(n%ans==0){
    cout<<"Yes";
  }
  else{
    cout<<"No";
  }
}
    
    

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static long MOD = 1000000007;
    
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = 26;
        int m = sc.nextInt();
        String str = sc.next();
        char[] c = str.toCharArray();
        
        long[] alphabet = new long[n];
        for (int i = 0; i < c.length; i++) {
            int idx = c[i] - 'a';
            alphabet[idx]++;
        }
        
        long ans = 1;
        for (int i = 0; i < 26; i++) {
            ans *= (alphabet[i] + 1);
            ans %= MOD;
        }
        ans--;
        if (ans < 0) ans += MOD;
        System.out.println(ans);
    }
}

Measured memory_bytes: 25684
using System;
using System.Collections.Generic;
using System.Collections.Specialized;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Int32.Parse(Console.ReadLine());
            var vs = Console.ReadLine().Split(' ').Select(x => Double.Parse(x)).ToList();
            vs.Sort();
            var ans = vs[0];
            for (var i= 1;i< n;i++)
            {
                ans = 0.5 * (ans + vs[i]);
            }
            Console.WriteLine(ans);
        }
    }
}


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

using namespace std;

const int N = 1e5 + 10;

typedef long long ll;

int n, a[N];
ll res;

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n; i++) {
    scanf("%d", &a[i]);
  }
  for (int i = n; i > 1; i--) {
    res += a[i] / 2;
    a[i] &= 1;
    res += min(a[i], a[i - 1]);
    a[i - 1] -= min(a[i], a[i - 1]);
  }
  res += a[1] / 2;
  printf("%lld", res);
  return 0;
}

Measured memory_bytes: 640
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
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; }

const ll INF=1e18;

ll n,C;
ll D[35][35];
ll c[505][505];
ll cost[3][35];

int main(){
    cin>>n>>C;
    for(int i=1;i<=C;i++){
        for(int j=1;j<=C;j++) cin>>D[i][j];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++) cin>>c[i][j];
    }
    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=C;k++){
                cost[(i+j)%3][k]+=D[c[i][j]][k];
            }
        }
    }
    ll ans=INF;
    for(int i=1;i<=C;i++){
        for(int j=1;j<=C;j++){
            for(int k=1;k<=C;k++){
                if(i!=j&&j!=k&&k!=i){
                    chmin(ans,cost[0][i]+cost[1][j]+cost[2][k]);
                }
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int P, Q;
  int r[23], c[23], s[23], indent[23];
  int ans[23];
  
  while(cin >> P >> Q, P) {
    for(int i = 0; i < P + Q; i++) {
      string S;
      cin >> S;
      r[i] = count(S.begin(), S.end(), '(') - count(S.begin(), S.end(), ')');
      c[i] = count(S.begin(), S.end(), '{') - count(S.begin(), S.end(), '}');
      s[i] = count(S.begin(), S.end(), '[') - count(S.begin(), S.end(), ']');
      if(i != 0) r[i] += r[i - 1], c[i] += c[i - 1], s[i] += s[i - 1];
      for(indent[i] = 0; S[indent[i]] == '.'; ++indent[i]);
    }
    fill_n(ans, Q, -810);
    ans[0] = 0;
    for(int i = 1; i <= 20; i++) {
      for(int j = 1; j <= 20; j++) {
        for(int k = 1; k <= 20; k++) {
          bool flag = true;
          for(int l = 1; l < P; l++) {
            flag &= i * r[l - 1] + j * c[l - 1] + k * s[l - 1] == indent[l];
          }
          if(!flag) continue;
          for(int l = P; l < P + Q - 1; l++) {
            if(ans[l - P + 1] == -810) ans[l - P + 1] = i * r[l] + j * c[l] + k * s[l];
            else if(ans[l - P + 1] != i * r[l] + j * c[l] + k * s[l]) ans[l - P + 1] = -1;
          }
        }
      }
    }
    for(int i = 0; i < Q; i++) {
      cout << ans[i] << (i + 1 == Q ? "\n" : " ");
    }
  }
}

Measured memory_bytes: 1212
#include<stdio.h>

void bubbleSort(int n, int a[]);

int main(void){
	
	int n;
	
	scanf("%d", &n);
	
	int a[n], i;
	
	for(i=0; i<n; i++){
		scanf("%d", &a[i]);
	}
	
	bubbleSort(n, a);
	
	return 0;
	
}

void bubbleSort(int n, int a[]){
	
	int i, j, x, count=0;
	
	for(j=0; j<n; j++){
		for(i=n-1; j<i; i--){
			if(a[i]<a[i-1]){
				//printf("a[i-1]%d, a[i]%d ", a[i-1], a[i]);
				x=a[i-1];
				a[i-1]=a[i];
				a[i]=x;
				count++;
				//printf("a[i-1]%d, a[i]%d\n", a[i-1], a[i]);
			}
		}
	}
	
	for(i=0; i<n-1; i++){
		printf("%d ", a[i]);
	}
	
	printf("%d\n", a[i]);
	printf("%d\n", count);
	
}


Measured memory_bytes: 2100
import math 

def isPrime(n): 

    if(n <= 1): 
        return False
    if(n <= 3): 
        return True

    if(n % 2 == 0 or n % 3 == 0): 
        return False
      
    for i in range(5,int(math.sqrt(n) + 1), 6):  
        if(n % i == 0 or n % (i + 2) == 0): 
            return False
      
    return True
  
def nextPrime(N): 

    if (N <= 1): 
        return 2
  
    prime = N 
    found = False

    while(not found): 
        prime = prime + 1
  
        if(isPrime(prime) == True): 
            found = True
  
    return prime 

N = int(input())
print(nextPrime(N-1)) 

Measured memory_bytes: 3064
import sys

def solve(C: str):
    C_asc = ord(C)
    C_next_asc = C_asc + 1
    C_next = chr(C_next_asc)

    print(C_next)
    return
 
if __name__ == "__main__":
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    
    tokens = iterate_tokens()
    C = next(tokens)
    solve(C)

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
typedef long long ll;
const ll MOD=1000000007;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
typedef long double ld;
typedef unsigned long long int ull;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<pair<ll, ll>> vpll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<vc> vvc;
typedef vector<vs> vvs;
typedef vector<vll> vvll;
typedef map<int, int> mii;
typedef set<int> si;
//---------------------------------------------------------------------------------------------------

int main(void){
    // Your code here!
    int n; cin >> n;
    vll z(n);
    vll w(n);
    rep(i,n) {
        ll x,y; cin >> x >> y;
        z[i] = x + y;
        w[i] = x - y;
    }
    Sort(z);
    Sort(w);
    // if (z[n-1] - z[0] >= w[n-1] - w[0] ) {
        
    // }
    cout << max(z[n-1] - z[0],w[n-1] - w[0]) << endl;
}


Measured memory_bytes: 6344