akhauriyash/Code-Regression huggingface dataset:
"use strict";

// read lines from stdin
const input = require("fs")
  .readFileSync("/dev/stdin", "utf8")
  .split("\n");

const N = parseInt(input[0], 10);
const V = input[1].split(" ").map((val) => parseInt(val, 10));
const C = input[2].split(" ").map((val) => parseInt(val, 10));

let ans = 0;

for (let i = 0; i < N; i++) {
  if (V[i] > C[i]) {
    ans += V[i] - C[i];
  }
}

console.log(ans);

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin >> N;
    long long ans = 1;
    long long A[N];
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        if (A[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }
    for (int i = 0; i < N; i++)
    {
        long long computed = ans * A[i];
        if (computed != 0 && computed / A[i] == ans)
        {
            ans = computed;
        }
        else
        {
            cout << -1 << endl;
            return 0;
        }
    }
    if (ans > (long long)pow(10, 18))
    {
        cout << -1 << endl;
        return 0;
    }
    cout << ans << endl;
}


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

int main(){
    long long n; cin >> n;
    vector<long long> a(n);
    long long sum = 0;
    long long mx = -1e6;
    long long mn = 1e6;
    for (int i = 0; i < n; i++){
        cin >> a[i];
        sum += a[i];
        mx = max(mx, a[i]);
        mn = min(mn, a[i]);
    }
    cout << mn << " " << mx << " " << sum << endl;
    return 0;

}


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

int main(void) {
	int n;
	int a[101];
	int flag[9] = {};
	int count = 0;
	int maxi, mini;

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

	for (int i = 1; i <= n; i++) {
		if (a[i] / 400 >= 8) {
			flag[8]++;
		}
		else {
			flag[a[i] / 400]++;
		}
	}

	for (int i = 0; i <= 7; i++) {
		if (flag[i]>=1) {
			count++;
		}
	}

	mini = max(1, count);
	maxi = count + flag[8];

	cout << mini << " " << maxi << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <bitset>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 200005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;


int main()
{
	vector <int> v;
	int a, b, k;
	cin >> a >> b >> k;
	for (int i = 1; i <= min(a, b); ++i)
	{
		if(a % i == 0 && b % i == 0)
		{
			v.push_back(i);
		}
	}
	reverse(all(v));
	cout << v[k - 1];
}


Measured memory_bytes: 256
import java.util.*;
 
class Main{
  public static void main(String[] args){
    Scanner scanner=new Scanner(System.in);
    String weather=scanner.next();
    if(weather.equals("Sunny")){
      System.out.println("Cloudy");
    } if(weather.equals("Cloudy")){
      System.out.println("Rainy");
    } if(weather.equals("Rainy")){
      System.out.println("Sunny");
    }
  }
}

Measured memory_bytes: 21204
n = int(input())
a = list(map(int,input().split()))

ttl = 0
li = [0]
for i in range(n):
    ttl += a[i]
    li.append(ttl)

dic = {}
ans = 0
for i in range(n+1):
    memo = str(li[i])
    if memo in dic:
        ans += dic[memo]

    if str(li[i]) in dic:
        dic[str(li[i])] += 1
    else:
        dic[str(li[i])] = 1

print(ans)    


    





Measured memory_bytes: 52212
#include<bits/stdc++.h>
using namespace std;
int main(){
int long long n;
cin>> n;
long long int p=n;
int long long temp = 0;
while(n>0)
{
    int long long c = n%10;
    temp = temp + c;
    n=n/10;
}

if(p%temp==0)
{
    cout<<"Yes"<<endl;
}
else
{
    cout<<"No"<<endl;
}
}


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

int main(){
  string s;
  int i,x=0,mx=0,n;
  cin>>n;
  cin>>s;
  for(i=0; i<n; i++){
    if(s[i]=='I') x++;
    else x--;
    mx=max(mx,x);
  }
  cout<<mx<<endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

#define F first
#define S second
#define pb push_back
#define eb emplace_back
#define PI 3.14159265359
#define sz(c) (int)c.size()
#define len(c) (int)c.length()
#define hcf(a, b) __gcd(a, b)
#define all(c) c.begin(), c.end()
#define vint vector<int>
#define vll vector<ll>
#define vpint vector<pair<int, int>>
#define vpll vector<pair<ll, ll>>
#define fr(it, a, b) \
    for (int it = (a); it < (b); it++)
#define tr(con, it) \
    for (auto it = con.begin(); it != con.end(); it++)
#define present(con, ele) (con.find(ele) != con.end())
#define cpresent(con, ele) (find(all(con), ele) != con.end())
#define maximum(a, b, c) (a > b ? (a > c ? a : c) : (b > c ? b : c))
#define minimum(a, b, c) (a < b ? (a < c ? a : c) : (b < c ? b : c))
typedef long long ll;
typedef long double lf;
typedef pair<int, int> pi;
typedef unsigned long long lu;
const ll mod = 1e9 + 7;
int32_t main()
{
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int l, r, d;
    cin >> l >> r >> d;
    cout << r / d - (l - 1) / d << "\n";
    return 0;
}

Measured memory_bytes: 3688
import sys, os, math, bisect, itertools, collections, heapq, queue
from scipy.sparse.csgraph import csgraph_from_dense, floyd_warshall
from decimal import Decimal
from collections import defaultdict

# import fractions

sys.setrecursionlimit(10000000)

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]

lcm = lambda x, y: (x * y) // math.gcd(x, y)
# lcm = lambda x, y: (x * y) // fractions.gcd(x, y)

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


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    N, Q = il()
    S = iss()
    NUM = [0]*(N+1)
    for i in range(1, N):
        NUM[i+1] += NUM[i]
        if S[i-1] == 'A' and S[i] == 'C':
            NUM[i+1] += 1

    for _ in range(Q):
        l, r = il()
        print(NUM[r]-NUM[l])


if __name__ == '__main__':
    main()


Measured memory_bytes: 19312
case = 1
while True:
    n = int(input())
    if not n:
        break
    jpeg = [[0] * n for _ in range(n)]
    n1 = n - 1
    px, cur = [0, 0], 1
    while px[0] < n:
        i, j = px
        jpeg[i][j] = cur
        odd = (i + j) % 2
        if px[not odd] == n1:
            px[odd] += 1
        elif not px[odd]:
            px[not odd] += 1
        else:
            px[not odd] += 1
            px[odd] -= 1
        cur += 1

    print('Case {}:'.format(case))
    for row in jpeg:
        print(''.join('{:>3}'.format(pixel) for pixel in row))

    case += 1

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

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll A[105];

int main()
{
    ll N;
    cin >> N;
    ll min = INF, max = -INF;
    REP(i, N)
    {
        cin >> A[i];
        max = std::max(max, A[i]);
        min = std::min(min, A[i]);
    }

    ll ans = INF;
    for (ll n = min; n <= max; ++n)
    {
        ll m = 0;
        REP(i, N)
        {
            ll t = A[i] - n;
            m += t * t;
        }
        ans = std::min(ans, m);
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
N = int(input())
candies_1 = [int(i) for i in input().split()]
candies_2 = [int(i) for i in input().split()]
count = [0 for i in range(N)]
count[0] = candies_1[0]

# 1列目で下に行った場合
for i in range(N):
    count[0] += candies_2[i]

# 2列目以降で下に行った場合
for i in range(N-1):
    count[i + 1] = count[i] - candies_2[i] + candies_1[i + 1]

print(max(count))

Measured memory_bytes: 3064
function main()
  readline()
  ans=0
  D=Dict{Int,Int}()
  D[0]=1
  s=0
  for a=map(x->parse(Int,x),split(readline()))
    ans+=get(D,s+=a,0)
    D[s]=get(D,s,0)+1
  end
  println(ans)
end
main()

Measured memory_bytes: 149868
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define PI 3.1415926535

int main() {
    ll r, d, x2000;
    cin >> r >> d >> x2000;
    ll prev = x2000;
    for(ll i = 1; i <= 10; i++){
        ll ans = prev * r - d;
        cout << ans << endl;
        prev = ans; 
    }
}


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

using namespace std;

#define ll long long
#define mod 1000000007

void solve(){
	int n;
	cin>>n;
	int arr[n];
	for(int i = 0;i<n;i++)cin>>arr[i];
	ll sum = 0;
	for(int i = 1;i<n;i++){
		if(arr[i] < arr[i-1]){
			sum += (arr[i-1] - arr[i]);
			arr[i] = arr[i-1];
		}
	}
	cout<<sum;
}

int main(){
	int t = 1;
	while(t--){
		solve();
	}
	return 0;
}

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

int main() {
  string s;
  cin>>s;
  int n=s.size();
  bool ans=true;
  for(int i=0;i<n;i+=2){
    if(s[i]=='L')ans=false;
  }
  for(int i=1;i<n;i+=2){
    if(s[i]=='R')ans=false;
  }
  if(ans)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using PII = pair<int, int>;
using VI = vector<int>;

int main() {
#ifdef LOCAL_EXEC
//	freopen("sample.in", "r", stdin);
//	freopen("sample.out", "w", stdout);
#else
  ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif

  ll n, k; cin >> n >> k;
  n %= k;
  cout << min(n, k - n) << endl;

  return 0;
}



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

typedef long long int ll;
typedef unsigned long long int ull;
#define rep(i,n) for(auto i=0;i<(n);i++)
#define rep1(i,n) for(auto i=1;i<=(n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;


struct init{ init(){ cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20); }; }aaaaaaa;


int toP(int y, int x){
    return y*500 + x;
}
pair<int, int> toYX(int p){
    return {p/500, p%500};
}

int main(){
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(hx, h) cin >> s[hx];
    

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

    set<int> visited;
    ll cnt = 0;
    rep(hx, h){
        rep(wx, w){
            if(s[hx][wx] == '.') continue;
            if(0 < visited.count(toP(hx, wx))) continue;
            set<int> blacks;
            set<int> whites;
            queue<pair<int, int>> que;
            que.push({hx, wx});
            while(!que.empty()){
                auto p = que.front(); que.pop();
                int posy = p.first;
                int posx = p.second;
                
                if(0 < visited.count(toP(posy, posx))) continue;
                visited.insert({toP(posy, posx)});
                blacks.insert(toP(posy, posx));

                rep(dir, 4){
                    int x = posx+dx[dir];
                    int y = posy+dy[dir];
                    if(x < 0)   continue;
                    if(w <= x) continue;
                    if(y < 0)   continue;
                    if(h <= y) continue;
                    if(s[y][x] == '#') continue;
                    whites.insert(toP(y, x));
                    rep(tdir, 4){
                        int xx = x+dx[tdir];
                        int yy = y+dy[tdir];
                        if(xx < 0)   continue;
                        if(w <= xx) continue;
                        if(yy < 0)   continue;
                        if(h <= yy) continue;
                        if(s[yy][xx] == '.') continue;
                        que.push({yy, xx});
                    }
                }
            }
            cnt += blacks.size() * whites.size();
        }
    }

    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 11648
#include <stdio.h>

int main(void){

  int r;
  int g;
  int b;
  int rgb;

  
  char buf1[30];
  fgets(buf1, 30, stdin);
  sscanf(buf1, "%d %d %d", &r, &g, &b);
  
  rgb = r * 100 + g * 10 + b;

 

  
  if(rgb % 4 == 0){
  printf("YES");
  }else{
  printf("NO");
  }
  
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <iomanip>

#define REP(i,n) for(int i=0;i<n;++i)
#define RREP(i,n) for(int i=n-1;i>=0;--i)
#define FOR(i,m,n) for(int i=m;i<n;++i)
#define RFOR(i,m,n) for(int i=m-1;i>=n;--i)
#define ALL(v) v.begin(),v.end()
#define INF 1000000001
#define MOD 1000000007

using namespace std;


int main() {
	int n;
	cin >> n;
	vector<int> a;
	REP(i, n) {
		int b;
		cin >> b;
		a.push_back(b);
	}
	REP(i, n) {
		int key = a[i];
		int j = i - 1;
		while (j >= 0 && a[j] > key) {
			a[j + 1] = a[j];
			j--;
		}
		a[j+1] = key;
		REP(k, n) {
			cout << a[k];
			if (k != n - 1)cout << " ";
		}
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 3100
A, B, C, K = map(int, input().split())
ans = 0

#まずAを処理する。
if A >= K:
    ans += K
    A -= K
else:
    ans += A
    K -= A

if K > 0:
    if B >= K:
        print(ans)
        quit()
    else:
        K -= B

    if C >= K:
        ans -= K
        print(ans)
    else:
        ans -= C
        print(ans)


Measured memory_bytes: 9188
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>
#include <cassert>

using namespace std;
typedef long long ll;
ll mod = 1e9+7;
#define rep(i,n) for(int i = 0; i < (n); ++i)

int main() {
    int n;
    cin >> n;
    vector<int> t(n+1, 0);
    vector<int> x(n+1, 0);
    vector<int> y(n+1, 0);
    for (int i = 1; i <= n; ++i) cin >> t[i] >> x[i] >> y[i];
    rep(i, n) {
        int dt = t[i+1] - t[i];
        int dx = x[i+1] - x[i];
        int dy = y[i+1] - y[i];
        int diff = dt - abs(dx) - abs(dy);
        if (diff < 0 || diff % 2 != 0) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 4568
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class Main{

	public static void main(String[] args)throws Exception {
		try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))){
			 PrintWriter out = new PrintWriter(System.out);

			int n = Integer.parseInt(br.readLine());

			Map<String,Integer> map = new HashMap<>();
			int max = 0,tmp = 0;
			for(int i = 0; i < n; i++) {
				String s =  br.readLine();

				if(map.containsKey(s)) {
					tmp = map.get(s)+1;
					map.put(s,tmp);
					max = Math.max(tmp, max);
				}else {
					map.put(s,1);
					max = Math.max(max, 1);
				}


			}

			List<String> list = new ArrayList<>();
			for(String key: map.keySet()) {
				if(map.get(key)==max) {
					list.add(key);
				}
			}

			Collections.sort(list);

			for(String a: list) {
				out.println(a);
			}
			out.flush();

		}


	}

}


Measured memory_bytes: 57300
#include <bits/stdc++.h>
 
using namespace std;
 
#define M_DEBUG if (0)


/******************************************************************************
	typedef
******************************************************************************/
typedef unsigned long long int ullint;

 
/******************************************************************************
	関数
******************************************************************************/
char getWinChar(char c) {
	char ret;
	if (c == 'r') {
		ret = 'p';
	} else if (c == 's') {
		ret = 'r';
	} else if (c == 'p') {
		ret = 's';
	} else {
		assert(0);
	}
	return ret;
}
 
/******************************************************************************
	Main
******************************************************************************/
int main()
{
    int N = -1, K = -1, R = -1, S = -1, P = -1;
    string T = "";
    
    cin >> N >> K;
    assert(N >= 2 && N <= pow(10, 5));
    assert(K >= 1 && K < N);
 
    cin >> R >> S >> P;
    assert(R >= 1 && R <= pow(10, 4));
    assert(S >= 1 && S <= pow(10, 4));
    assert(P >= 1 && P <= pow(10, 4));
    
    map <char, int> charToScore;
    charToScore.insert(make_pair('r', R));
    charToScore.insert(make_pair('s', S));
    charToScore.insert(make_pair('p', P));
 
	cin >> T;
    assert(T.length() == N);
    
    // r のときは i 回目のじゃんけんで筐体がグーを出すことを、
    // s のときはチョキを出すことを、
    // p のときはパーを出すことを表します。
    string ptn = "";
    // とりあえず勝ち手をつくる
    for (char c : T) {
        ptn += getWinChar(c);
    }
 
    // K手前と同じ手は出せない。出せるのは負け手かあいこ手。
    // スコアが高い手を出したい
    // Kを法として合同な手の中で点数を最大にする
	string ptn_k = ptn;
    for (int i = 0; i < K; i++) {
		// 第i手は判定する必要がないので、i+K手から判定する
        for (int j = i + K; j < N; j += K) {
			M_DEBUG cout << "ptn_k = " << ptn_k << endl;
			/// 最大化するには
			/// (1) 勝ち手を出す
			M_DEBUG cout << ptn_k[j-K] << " " << ptn[j] << " " << (ptn_k[j-K] == ptn[j]) << endl;
			if (ptn_k[j-K] != ptn[j]) {
				ptn_k[j] = ptn[j];
				continue;
			}
 
			/// (2) 第i手が前の手と同じだったら、自分（第i手）が別な手を出すか、前の手を変更する。点数が高い方を選ぶ
			int prev_score = (ptn_k[j-K] == ptn[j-K])? charToScore[ptn_k[j-K]] : 0;
			int cur_score = charToScore[ptn[j]];
			M_DEBUG cout << prev_score << " " <<  cur_score << endl;
			(prev_score < cur_score)? ptn_k[j] = ptn[j] : ptn_k[j] = getWinChar(ptn[j]) ;
		}
		// M_DEBUG cout << "ptn_k = " << ptn_k << endl;
 
    }
	// ptn = ptn_k;
    M_DEBUG cout << "ptn: " << ptn << endl;
 
    int score = 0;
	for (int i = 0; i < N; i++) {
		if (ptn[i] == ptn_k[i]) score += charToScore[ptn[i]];
	}
 
	cout << score << endl;
 
	return 0;
}

Measured memory_bytes: 640
/**********************************************************************
   File hoge.cpp
   Author  harunaya
   Date   2020-04-30(Thu)
   note   
**********************************************************************/

#include <bits/stdc++.h>
using namespace std;

int main() {
    int64_t x;
    cin >> x;
    int64_t tkyen = 100;
    bool isgood = false;
    int count = 1;
    while(1){
        tkyen = tkyen * 1.01;
        if(tkyen >= x){
            break;
        }
        count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>

using namespace std;
using ll = long long;

void _cin(){} template <class Head, class... Tail> void _cin(Head&& head, Tail&&... tail){ cin >> head; _cin(forward<Tail>(tail)...); }
void _cout(){ cout << "\n"; } template <class Head, class... Tail> void _cout(Head&& head, Tail&&... tail){ cout << head; _cout(forward<Tail>(tail)...); }
int gcd(int a, int b){ return (b == 0) ? a : gcd(b, a % b); }

#define Sq(x) (x)*(x)
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Rep(n) For(_, n)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) (find(Range(c), x) != c.end())
#define Search(rb, re, x) distance(rb, find(rb, re, x))
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Reverse(c) reverse(Range(c))
#define Unique(a) a.erase(unique(Range(a)), a.end())
#define Cusum(T, xs, sxs) vector<T> sxs(xs.size()+1); For(i, (int)xs.size()) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, ...) T __VA_ARGS__; _cin(__VA_ARGS__)
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs); For(i, n) For(j, m) cin >> xs[i][j]
#define Cinm(T, n, map) unordered_map<T, int> map; Rep(n){ Cin(T, x); map[x] ++; }
#define Cout(...) _cout(__VA_ARGS__)
#define Couts(xs) { for(const auto &e : xs) cout << e << " "; cout << "\n"; }
#define Coutyn(cond) Cout((cond) ? "yes" : "no")
#define CoutYn(cond) Cout((cond) ? "Yes" : "No")
#define CoutYN(cond) Cout((cond) ? "YES" : "NO")
#define vc vector
#define Mini(a, x) a = min(a, x)
#define Maxi(a, x) a = max(a, x)

// constexpr int MOD = 1e9+7;

int main(void){
    Cin(int, n);
    Cins(int, n, a);
    ll ans = 0;
    For(i, n){
        if(i > 0 && a[i-1] > 0 && a[i] > 0) ans ++, a[i-1] --, a[i] --;
        ans += a[i]/2;
        a[i] %= 2;
    }
    Cout(ans);
}




Measured memory_bytes: 640
fun main(arg: Array<String>) {
    val (N, K) = listOfInt()
    val P = listOfInt()
    val e = P.map { (it + 1).toDouble() / 2.0 }
    val s = DoubleArray(N + 1)
    for (n in 0 until N) s[n + 1] = s[n] + e[n]
    var ans = 0.0
    for (n in 0 .. N - K) {
        ans = Math.max(ans, s[n + K] - s[n])
    }
    println(ans)
}
fun next() = readLine()!!
fun nextInt() = Integer.parseInt(next())
fun listOfString() = next().split(" ")
fun listOfInt() = listOfString().map { Integer.parseInt(it) }
fun listOfDouble() = listOfString().map(String::toDouble)


Measured memory_bytes: 60192
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;


map<int,int> factorize(int N) {
  map<int,int> res;
  for (int k=2; k<=N; ++k) {
    int n = k;
    for (int i=2; i*i<n; ++i) {
      while (n%i==0) {
	res[i]++;
	n /= i;
      }
    }
    if (n != 1) res[n]++;
  }
  return res;
}

int main()
{
  string s;
  cin >> s;
  int num[26];
  memset(num,0,sizeof(num));
  REP(i,s.size()) {
    num[s[i]-'a']++;
  }
  int odd = -1;
  bool dame = 0;
  REP(i, 26) {
    if (num[i] % 2 && odd >= 0) dame = 1;  
    if (num[i] % 2) odd = i;
    //cout << num[i] << " ";
  }
  //cout << endl;
  if (dame) {
    cout << 0 << endl;
    return 0;
  }
  num[odd]--;
  int sum = 0;
  REP(i, 26) {
    num[i] /= 2;
    sum += num[i];
  }
  
  map<int, int> factor1, factor2;
  
  factor1 = factorize(sum);
  REP(i, 26) {
    map<int,int> tmp = factorize(num[i]);
    FOR(it, tmp) {
      factor2[it->first] += it->second;
    }
  }
  //FOR(it, factor1) {
  //  cout << it->first << " " << it->second << endl;
  //}
  //cout << "ok1" << endl;
  // FOR(it, factor2) {
//     cout << it->first << " " << it->second << endl;
//   }
//   cout << "ok2" << endl; 
  FOR(it, factor2) {
    factor1[it->first] -= it->second;
  }
  ll ans = 1;
  FOR(it, factor1) {
    for (int i=0; i<it->second; ++i)
      ans *= it->first;
  }
  cout << ans << endl;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int, int>
#define vi              vector<int>
#define si              set<int>
#define usi             unordered_set<int>
#define mii             map<int, int>
#define umii            unordered_map<int, int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int, vi, greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define endl            '\n'
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(t)            int t; cin>>t; while(t--)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
void jaiswal_sahil()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
// #ifndef ONLINE_JUDGE
//     freopen("input.txt", "r", stdin);
//     freopen("output.txt", "w", stdout);
// #endif
}

const int N = 1e6;
int dp[N];
int n, k;

// top down Approach
int minCost(int i, int *a){

    if(i >= n-1)
        return 0;

    if(dp[i] != -1)
        return dp[i];

    int q1 = inf;
    for(int j=i+1; j<=i+k; j++){
        if(j < n){
            int subProb = abs(a[i] - a[j]) + minCost(j, a);
            q1 = min(q1, subProb);
        }
        
    }
    
    return dp[i] = q1;

}

// bottom up Approach
int minCostBU(int n, int k, int *a){

    memset(dp, 0, sizeof(dp));
    dp[2] = abs(a[0] - a[1]);
    for(int i=2; i<=n; i++){
        dp[i] = inf;
        for(int j=i-1; j>=i-k; j--){
            if(j>=0){
                dp[i] = min(dp[i], abs(a[i-1] - a[j-1]) + dp[j]);
            }
        }
    }
    return dp[n];

}

int32_t main()
{
    jaiswal_sahil();

    cin>>n>>k;
    int a[n];
    for(int i=0; i<n; i++)
        cin>>a[i];
    
    // memset(dp, -1, sizeof(dp));
    // int ans = minCost(0, a);

    int ans = minCostBU(n, k, a);
    cout<<ans<<endl;
    return 0;

}

Measured memory_bytes: 8832
n,k,*v=map(int,open(0).read().split())
m=0
r=range
for i in r(n+1):
 for j in r(min(k,n)-i+1):
  t=sorted(v[:i]+v[:~j:-1])
  while t and(k-i-j)*t[0]<0:t.pop(0);j+=1
  m=max(m,sum(t))
print(m)

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <string>
#include <algorithm>
#include <iomanip>
#include <map>
#include <bitset>
#include <cstdio>
#include <set>
//#include <bits/stdc++.h>
#define rep(i,n) Rep(i,0,n)
#define Rep(i,k,n) for(int i=k ; i<n ; i++)
#define rep1(i,n) for(int i=1 ; i<=n ; i++)
#define vi vector<int>
#define vii vector<int,int>
#define Sort(v) sort(v.begin(),v.end())
#define Reverse(v) reverse(v.begin(),v.end())

//const int MOD = 1000000007;
//const int INF = 1<<30;
using namespace std;

string yn(bool x){
    return x ? "Yes" : "No";
}
int main()
{
    int n; cin >> n;
    cout << n/3 << endl;
        
        
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vb=vector<bool>;
using vvb=vector<vb>;
using vd=vector<double>;
using vvd=vector<vd>;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using tll=tuple<ll,ll>;
using tlll=tuple<ll,ll,ll>;
using vs=vector<string>;

#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define rep(i,n) range(i,0,n)
#define rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define range(i,a,n) for(int i=(a);i<(n);i++)

#define LINF ((ll)1ll<<60)
#define INF ((int)1<<30)
#define EPS (1e-9)
#define MOD (1000000007ll)
#define fcout(a) cout<<setprecision(a)<<fixed
#define fs first
#define sc second
#define PI 3.1415926535897932384

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

template<class T>bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T>bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class S>S acm(vector<S>&a){return accumulate(all(a),S());}
template<class S>S max(vector<S>&a){return *max_element(all(a));}
template<class S>S min(vector<S>&a){return *min_element(all(a));}
void YN(bool b){cout<<(b?"YES":"NO")<<"\n";}
void Yn(bool b){cout<<(b?"Yes":"No")<<"\n";}
void yn(bool b){cout<<(b?"yes":"no")<<"\n";}

ll max(int a,ll b){return max((ll)a,b);} ll max(ll a,int b){return max(a,(ll)b);}
template<class T>void puta(T&&t){cout<<t<<"\n";}
template<class H,class...T>void puta(H&&h,T&&...t){cout<<h<<' ';puta(t...);}
template<class S,class T>ostream&operator<<(ostream&os,pair<S,T>p){os<<"["<<p.first<<", "<<p.second<<"]";return os;};
template<class S>auto&operator<<(ostream&os,vector<S>t){bool a=1; for(auto s:t){os<<(a?"":" ")<<s;a=0;} return os;}
#define _cTime (chrono::system_clock::now())
#define progress (chrono::duration_cast<chrono::milliseconds>(_cTime-_sTime).count())
#define reset _sTime=_cTime
auto reset;

int clz(ll x){return 64 - __builtin_clzll(x);}

ll f(ll a){
	if(a<=0)return 0ll;
	ll ans=0;
	rep(i,50){
		ll t=(1ll<<i);
		ll k=(a+1)%(t*2);
		if(i==0){
			if(((a+1)%4)==2||((a+1)%4)==3)ans+=1;
		}
		else if((k>t&&(k-t)%2==1)){
			ans+=t;
		}
	}
	//cout<<ans<<endl;
	return ans;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a,b,ans=0;
	cin>>a>>b;
	cout<<(f(b)^f(a-1))<<endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#define INF 100000
#define MAT_MAX 100

typedef struct {
  int r;
  int c;
} Matrix;

int min(int x, int y){
  return x > y ? y : x;
}

void matrixChainOrder(int m[MAT_MAX+1][MAT_MAX+1], int *p, int n){
  int i, j, k, l, q;
  for(i = 1; i <= n; i++) m[i][i] = 0;
  for(l = 2; l <= n; l++){
    for(i = 1; i <= n-l+1; i++){
      j = i+l-1;
      m[i][j] = INF;
      for(k = i; k <= j-1; k++){
	q = m[i][k] + m[k+1][j] + p[i-1]*p[k]*p[j];
	m[i][j] = min(m[i][j], q);
      }
    }
  }
  printf("%d\n",m[i-1][j]);
}

int main(){
  int i, j, n, m[MAT_MAX+1][MAT_MAX+1], p[MAT_MAX+1];
  Matrix M[MAT_MAX+1];

  scanf("%d",&n);
  for(i = 1; i <= n; i++){
    scanf("%d %d",&M[i].r, &M[i].c);
    p[i] = M[i].c;
    if( i == 1 ) p[0] = M[i].r;
  }
  matrixChainOrder(m, p, n);
  return 0;
}



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

typedef long long ll;
typedef pair<ll, ll> Pii;

int main() {
    ll N; cin >> N;
    vector<ll> A(N); for (int i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end(), greater<ll>());

    bool hasNeg = false;
    bool hasPos = false;
    ll abssum = 0, sum = 0;
    for (int i = 0; i < N; i++) {
        if (A[i] > 0) hasPos = true;
        if (A[i] < 0) hasNeg = true;
        sum += A[i];
        abssum += abs(A[i]);
    }
    if (hasNeg && !hasPos) {
        cout << A[0] * 2 - sum << endl;
        ll t = A[0];
        for (int i = 1; i < N; i++) {
            cout << t << ' ' << A[i] << endl;
            t -= A[i];
        }
    } else if (!hasNeg && hasPos) {
        cout << sum - A[N-1] * 2 << endl;
        ll t = A[N-1];
        for (int i = 1; i < N-1; i++) {
            cout << t << ' ' << A[i] << endl;
            t -= A[i];
        }
        cout << A[0] << ' ' << t << endl;
    } else if (hasNeg && hasPos) {
        cout << abssum << endl;
        ll t = A[N-1];
        for (int i = 1; i < N; i++) {
            if (A[i] > 0) {
                cout << t << ' ' << A[i] << endl;
                t -= A[i];
            }
        }
        cout << A[0] << ' ' << t << endl;
        t = A[0] - t;
        for (int i = 0; i < N-1; i++) {
            if (A[i] <= 0) {
                cout << t << ' ' << A[i] << endl;
                t -= A[i];
            }
        }
    } else {
        cout << 0 << endl;
        for (int i = 0; i < N-1; i++) cout << "0 0" << endl;
    }
}


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

using ll = long long;

ll N, K;
vector<ll> H(200001);

void solve(){
    sort(H.begin() + 1, H.begin() + N + 1, greater<int>());

    ll ans = 0;
    for(int i = K + 1; i <= N; i++) ans += H[i];
    cout << ans;
}
int main(){
    cin >> N >> K;
    for(int i = 1; i <= N; ++i){
        cin >> H[i];
    }
    solve();
    return 0;
}

Measured memory_bytes: 1792
/*
                                                  __          __
      /\   |   |     /\   |  | |  |     /\   | / |  )   /\   |  )
     /__\  |   |    /__\  |--| |  |    /__\  |<  |-<   /__\  |-<
    /    \ |__ |__ /    \ |  | \__/   /    \ | \ |__) /    \ |  \

*/

#import<bits/stdc++.h>
typedef long long ll;
#define forl(n) for(int i=0; i<n; i++)
#define forll(i,a,b,c) for(int i=a; i<b; i+=c)
#define pb(n) push_back(n)

using namespace std;

int main()
{
    ll a,b,x;
    cin>>a>>b;
    x=a%b;
    cout<<min(x,b-x)<<"\n";
}


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <vector>
#include <iostream>
#include <math.h>

using namespace std;

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

  int a = 0;

  //vector<int64_t> P(M);
  //vector<int64_t> Y(M);

  if(N<=9){
    if(M<=9){
      cout << N * M << endl;
      a = 1;
    }
    
  }

  if(a==0){
    cout << -1 << endl;
  }
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 10000
#define NIL -1


struct Node {int p, l, r;};
struct Node T[MAX];
int n;


void preParse(int u){
    if(u == NIL) return;
    printf(" %d", u);
    preParse(T[u].l);
    preParse(T[u].r);
}


void inParse(int u){
    if(u == NIL) return;
    inParse(T[u].l);
    printf(" %d", u);
    inParse(T[u].r);
}

void postParse(int u){
    if(u == NIL) return;
    postParse(T[u].l);
    postParse(T[u].r);
    printf(" %d", u);
}

int main(void){

    int i, v, l, r, root;

    scanf("%d", &n);
    for(i = 0; i < n; i++) T[i].p = NIL;
    
    for(i = 0; i < n; i++){
        scanf("%d%d%d", &v, &l, &r);
        T[v].l = l;
        T[v].r = r;
        if(l != NIL) T[l].p = v;
        if(r != NIL) T[r].p = v;
    }
    

    for(i = 0; i < n; i++ ) if(T[i].p == NIL) root = i;
    
    printf("Preorder\n");
    preParse(root);
    printf("\n");
    printf("Inorder\n");
    inParse(root);
    printf("\n");
    printf("Postorder\n");
    postParse(root);
    printf("\n");

    return 0;
}



Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <string>
#include <cctype>
#include <map>

using namespace std;

const int mod = 1000000007;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ll long long

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

    int remain = x;
    int count = 0;
    vector<int> vec(n);
    for (int i = 0; i < vec.size(); i++)
    {
        cin >> vec[i];
        remain -= vec[i];
        count++;
    }

    sort(vec.begin(), vec.end());
    while (remain > 0)
    {
        remain -= vec[0];
        if (remain >= 0)
        {
            count++;
        }
    }
    
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vi = vector<int>;
using vc = vector<char>;
using vb = vector<bool>;
using vs = vector<string>;
using vll = vector<long long>;
using vp = vector<pair<int, int>>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using vvll = vector<vector<long long>>;
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 (b<a) {a=b; return 1;} return 0;}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n;
    cin >> n;
    vll a(n+1);
    rep(i, n+1) cin >> a[i];
    vll b(n+1);
    for (int i = n; i >= 0; --i) {
        b[i] = a[i];
        if (i != n) b[i] += b[i+1];
    }
    ll now = 1;
    bool flag = true;
    rep(i, n+1) {
        if (b[i] > now) b[i] = now;
        else break;
        now -= a[i];
        now *= 2;
        if (now < 0) {
            flag = false;
            break;
        }
    } 
    ll ans = accumulate(all(b), 0LL);
    if (flag) cout << ans << endl;
    else cout << -1 << endl;
}

Measured memory_bytes: 4784
import math

a,b,h,m= map(int,input().split())

ji = 360/12
fun = 360/60

hh = (ji * h) + (ji/60 * m)
mm = fun * m

if hh > mm:
    c = hh-mm
else:
    c = mm-hh

d = a ** 2 + b ** 2 - 2 * a * b * math.cos(math.radians(c))
ans = math.sqrt(d)

print(str(ans))

Measured memory_bytes: 9452
#include<stdio.h>
int H,A[500000]; 

void maxHeapify(int i){
  int large,temp;
  if(2*i<=H && A[2*i]>A[i]){
    large=2*i;
  }
  else{
    large=i;
  }
  if(2*i+1<=H && A[2*i+1]>A[large]){
    large=2*i+1;
  }
  if(large!=i){
    temp=A[i];
    A[i]=A[large];
    A[large]=temp;
    maxHeapify(large);
  }
}
    

int main(){
  int i;
  scanf("%d",&H);
  for(i=1;i<=H;i++){
    scanf("%d",&A[i]);
  }
  for(i=H/2;i>=1;i--){
    maxHeapify(i);
  }
  for(i=1;i<=H;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}



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


int main(){
    int N;
    while(scanf("%d",&N),N){
        int A=0,B=0;
        while(N--){
            int a,b;
            scanf("%d%d",&a,&b);
            if(a>b)A+=a+b;
            else if(a<b)B+=a+b;
            else{
                A+=a;
                B+=b;
            }
        }

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

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

string to_string(string s) { return '"' + s + '"'; }

string to_string(const char *s) { return to_string((string)s); }

string to_string(bool b) { return (b ? "true" : "false"); }

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifndef ONLINE_JUDGE
#define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define dbg(...) 42
#endif

#define mst(x, a) memset(x, a, sizeof(x))

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;
constexpr int INF = 0x3f3f3f3f;
constexpr ll LLINF = 0x3f3f3f3f3f3f3f3f;
constexpr ll MOD = 1e9 + 7;

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

int N, K;
vector<int> a;

bool valid(int gcd) {
  priority_queue<int> positive;
  priority_queue<int, vector<int>, greater<int>> negative;
  int sum = 0;
  for (int i = 1; i < N; i++) {
    int tmp = a[i] % gcd;
    if (tmp) {
      sum += tmp;
      positive.push(tmp);
    }
  }
  negative.push(-sum);

  while (!negative.empty() && !positive.empty() &&
         -negative.top() + positive.top() > gcd) {
    int a = positive.top() - gcd;
    int b = negative.top() + gcd;
    positive.pop();
    negative.pop();
    if (a > 0) {
      positive.push(a);
    } else if (a < 0) {
      negative.push(a);
    }
    if (b > 0) {
      positive.push(b);
    } else if (b < 0) {
      negative.push(b);
    }
  }

  sum = 0;
  while (!positive.empty()) {
    sum += positive.top();
    positive.pop();
  }
  return sum <= K;
}

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

  cin >> N >> K;
  a.resize(N);

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

  int ans = 1;
  for (int i = 1; i <= floor(sqrt(sum)); i++) {
    if (sum % i == 0) {
      if (valid(i)) {
        ans = max(ans, i);
      }
      if (valid(sum / i)) {
        ans = max(ans, sum / i);
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
N = gets.to_i
points = (1..N).map{gets.split.map(&:to_i)}

sumDist = 0
cnt = 0
(0...N).to_a.permutation{|tour|
	(1...N).each{|i| 
		sumDist += Math.sqrt((points[tour[i]][0] - points[tour[i-1]][0])**2 + (points[tour[i]][1] - points[tour[i-1]][1])**2)
	}
	cnt += 1
}

p sumDist / cnt.to_f

Measured memory_bytes: 3964
#include<stdio.h>
#include<stdlib.h>
int main(){
	int sj[100005];
	int a,b,c,i=1,d=0;
	scanf("%d",&c);
	for(i=1;i<=c;i++)
	{scanf("%d",&sj[i]);}
	a=1;b=sj[1];
	while(a!=2)
	{
	a=b;
	b=sj[a];
	d++;
	if(d>c)
	{printf("-1");
	return 0;}
	}
	printf("%d",d);
	return 0;
} 

Measured memory_bytes: 512
#include <iostream>

using namespace std;

#define rep(i,x) for(int i=0;i<(x);++i)

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

	int N, M;
	string s;
	while (cin >> N, N) {
		cin >> M;
		cin >> s;

		int ans = 0;

		int cnt = 0;
		bool f = true;

		rep(i, M+1) {
			if (s[i] == 'I') {
				if (cnt >= N * 2 + 1) {
					ans += (cnt - N * 2 - 1) / 2 + 1;
				}
				cnt = 1;
				continue;
			}

			if (s[i] == 'O' && s[i + 1] == 'I') {
				cnt += 2;
				i++;
			} else {
				if (cnt >= N * 2 + 1) {
					ans += (cnt - N * 2 - 1) / 2 + 1;
				}
				cnt = 0;
			}
		}

		if (cnt >= N * 2 + 1) {
			ans += (cnt - N * 2 - 1) / 2 + 1;
		}

		cout << ans << endl;
	}
}

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

#define REP(i, n) for(decltype(n) i = 0; i < n; i++)

#define ALL(c)   c.begin(), c.end()
#define SORT(c)  std::sort(ALL(c))
#define RSORT(c) std::sort(ALL(c), std::greater<decltype(c)::value_type>())

using namespace std;
using ll = long long;

const int MOD  = (int)1e9 + 7;
const int INF  = (int)1e9 + 1;
const ll  LINF = (ll)1e18 + 1;

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

    int N;
    std::cin >> N;

    vector<int> A(N), B(N), C(N - 1);
    REP(i, N) {
        std::cin >> A[i];
        A[i]--;
    }
    REP(i, N) {
        std::cin >> B[i];
    }
    REP(i, N - 1) {
        std::cin >> C[i];
    }

    ll ans = 0;
    REP(i, N) {
        ans += B[A[i]];
        if(i < N - 1 && A[i] + 1 == A[i + 1]) {
            ans += C[A[i]];
        }
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    string s;
    cin >> s;
    int n = (int)s.length();
    vector<int> a(n + 1);
    for (int i = 0; i <= n; ++i) {
        if ((i == 0 || s[i - 1] == '>') && (i == n || s[i] == '<')) {
            int j = i - 1;
            while (j >= 0 && s[j] == '>') {
                a[j] = max(a[j], i - j);
                --j;
            }
            j = i + 1;
            while (j <= n && s[j - 1] == '<') {
                a[j] = max(a[j], j - i);
                ++j;
            }
        }
    }
    cout << accumulate(a.begin(), a.end(), 0LL) << endl;
    return 0;
}

Measured memory_bytes: 2844
import sys
n = int(input())
h = list(map(int,input().split()))
for i in range(n-1,0,-1):
    if h[i]-h[i-1]>=0:
        pass
    elif h[i]-h[i-1]==-1:
        h[i-1] -= 1
    else:
        break
else:
    print("Yes")
    sys.exit()
print("No")

Measured memory_bytes: 20660
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <time.h>
using namespace std;
typedef long long ll;

int search(string S, string T) 
{
	int Tz = T.size();
	//後ろから順に、Tの入る場所を探す。
	for (int s = S.size() - 1; s >= 0; --s) {
		if (s - Tz + 1 < 0) return -1;

		string sub = S.substr(s - Tz + 1, Tz);
		for (int t = 0; t < Tz; ++t) {

			if (sub[t] == '?'
				|| sub[t] == T[t]) {
				if (t == Tz - 1) return s - Tz + 1;
			}
			else {
				break;
			}
		}
	}
	return -1;
}

int main()
{
	string S, T; cin >> S >> T;
	int t = search(S, T);
	if (t == -1) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}
	for (int s = 0; s < S.size(); ++s) {
		if (s >= t 
			&& s < t + T.size()) {
			cout << T[s - t];
		}
		else if (S[s] == '?') {
			cout << 'a';
		}
		else {
			cout << S[s];
		}
	}
	cout << endl;
	return 0;
}


Measured memory_bytes: 3128
#import <stdlib.h>
#import <Foundation/Foundation.h>

long calc(long *A, long N, BOOL positive) {
    long s = 0;
    long count = 0;
    
    for (long i=0;i<N;i++){
        s += A[i];
        if(i%2==(positive ? 0 : 1)) {
            if (s<=0) {
                count += 1-s;
                s=1;
            }
        } else {
            if (s>=0) {
                count += s+1;
                s=-1;
            }
        }
    }
    
    return count;
}

int main() {
    long N;
    scanf("%ld", &N);
    long *A = (long*)malloc(N * sizeof(long));
    
    long n;
    long i = 0;
    while (scanf("%ld", &n) != EOF) {
        A[i] = n;
        i++;
    }
    
    printf("%ld", MIN(calc(A,N,YES),calc(A,N,NO)));
    free(A);
}



Measured memory_bytes: 6600
def main():
    N = input_int()
    A = input_int_list_in_line()
    A = [-1, -1] + A

    num_buka = [0] * (N+1)

    for i in range(2, len(A)):
        num_buka[A[i]] += 1

    for i in range(1, len(A)):
        print(num_buka[i])


def input_int():
    return int(input())


def input_ints():
    return map(int, input().split())


def input_int_list_in_line():
    return list(map(int, input().split()))


def input_int_tuple_list(n: int, q: int):
    return [tuple(map(int, input().split())) for _ in range(n)]


main()


Measured memory_bytes: 32240
import collections

def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a

n = int(input())

c = collections.Counter(prime_factorize(n))

temp_list = c.values()
ans = 0

if n == 1:
    print(0)
else:
    for i in temp_list:
        temp_num = i
        temp = 1
        while temp_num >= temp:
            temp_num = temp_num - temp
            ans += 1
            temp += 1
    print(ans)


Measured memory_bytes: 9468
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;


#define MOD 998244353
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


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

ll inv(ll x){
    // MOD=10e9+7
	ll n=MOD-2,a=1;
	while(n>0){
		if(n%2) a=a*x%MOD;
		x=x*x%MOD;
		n=n/2;
	}
	return a;
}

ll Comb(ll n,ll m){
    ll ans = 1; 
    for(int i=0;i < m; i++){
        ans *= ((n-i)*inv(i+1)) % MOD;
        ans %= MOD;
    }
    while(ans<0)ans+=MOD;
    return ans;
}

int main(){
    ll N,M,K;
    cin>>N>>M>>K;
    ll num=M;
    rep(i,0,N-1-K){
        num *= (M-1);
        num %=MOD;
    }
    ll ans =0;
    ll nck = Comb(N-1,K);
    for(ll i = K;i>=0;i--){
        ans += (nck * num) %MOD;
        //cout<<nck<<" "<<num<<endl;
        ans %=MOD;
        nck *= i;
        nck %=MOD;
        nck *= inv(N-1-i+1);
        //cout<<N-i<<endl;
        nck %=MOD;
        num *=M-1;
        num%=MOD;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 3644
s =str(input())

if s == "SUN":
    print(7)
elif s=="MON":
    print(6)
elif s=="TUE":
    print(5)
elif s=="WED":
    print(4)
elif s=="THU":    
    print(3)
elif s=="FRI":    
    print(2)
else :    #SAT
    print(1)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)
const static long long int MOD = 1000000000 + 7;

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    llong sum = 0, ans = 0;
    rep(i, n) {
        int a;
        cin >> a;
        sum += a;
        if (a == 0) {
            ans += sum / 2;
            sum = 0;
        }
    }

    ans += sum / 2;
    cout << ans << endl;

    return 0;
}

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

int main() {
  int N, M, ans;
  cin >> N;
  
  M = 0;
  ans = 0;
  for (int i = 0; i < N; i++) {
    int S = i + 1;
    int buf = 0;
    for (int j = 0; S % 2 == 0; j++) {
      S /= 2;
      buf++;
    }
    M = max(buf, M);
    if (M == buf) ans = i + 1;
  }
  cout << ans << endl;
}

Measured memory_bytes: 256