akhauriyash/Code-Regression huggingface dataset:
n = int(input())
a = [int(i) for i in input().split()]
b = [int(i) for i in input().split()]
c = 0
for i in range(n):
    left = min(a[i], b[i])
    b[i] -= left
    c += left
    right = min(a[i+1], b[i])
    a[i+1] -= right
    c += right
print(c)

Measured memory_bytes: 18624
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]
a,b,c,k = MI()
if a+b >= k:
    print(min(k,a))
else:
    print(a-(k-a-b))


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

int main() {
  int N, cnt=0;
  string S;
  cin >> N >> S;
  rep(i, 1000){
    vector<int> A{i / 100, (i / 10) % 10, i % 10};
    int B=0;
    rep(j, N){
      if(S.at(j)=='0'+A.at(B)) B++;
      if(B==3) break;
    }
    if(B==3) cnt++;
  }
  cout << cnt << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#define MAX 100000
using namespace std;

int main(){
    int N, K, sequence = 1, unhappy, happy;
    string S;
    cin >> N >> K >> S;
    for(int i=1; i<N; i++){
        if(S[i] != S[i-1]) sequence++;
    }
    if(2*K + 1 >= sequence){
        cout << N-1 << endl;
    }
    else{
        sequence -= 2*K;
        unhappy = 1 + sequence - 1;
        cout << N-unhappy << endl;
    }
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL mod=1e9+7;
const LL LINF=1LL<<62;
const int INF=1<<30;


int main(){
    int N,K;cin >> N >> K;
    vector<LL> a(N),b(N);
    for (int i = 0; i < N; i++) {
        cin >> a[i] >> b[i];
    }
    int t = K,c = 0;
    while(t){
        c++;
        t/=2;
    }
    LL ans = 0;
    vector<bool> used(N,false);
    for (int i = 0; i < N; i++) {
        if(a[i] > K) used[i] = true;
    }
    for (int i = c; i >= 0; i--) {
        LL tmp = 0;
        LL p = 1LL << i;
        if(K&p){
            for (int j = 0; j < N; j++) {
                if(used[j]||a[j]&p) continue;
                tmp += b[j];
            }
        }
        else{
            for (int j = 0; j < N; j++) {
                if(used[j]) continue;
                if(a[j]&p) used[j] = true;
            }
        }
        ans = max(ans,tmp);
    }
    LL tmp = 0;
    for (int i = 0; i < N; i++) {
        if(used[i]) continue;
        tmp += b[i];
    }
    ans = max(ans, tmp);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int a;
	cin >> a;
	string s;
	cin >> s;
	cout << (a < 3200 ? "red" : s);
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int p[5], num[3], wl[3], i, f;
	
	while (1){
		for (i = 0; i < 3; i++){
			num[i] = 0;
		}
		
		for (i = 0; i < 5; i++){
			if (scanf("%d", &p[i]), p[i] == 0){
				return (0);
			}
			p[i]--;
			num[p[i]]++;
		}
		
		f = 0;
		
		if (num[0] != 0 && num[1] != 0 && num[2] != 0){
			for (i = 0; i < 3; i++){
				wl[i] = 3;
			}
		}
		else {
			for (i = 0; i < 3; i++){
				if (num[(i + 1) % 3] == 0 && num[(i + 2) % 3] == 0){
					wl[i] = 3;
					f = 1;
					break;
				}
			}
			
			if (f != 1){
				for (i = 0; i < 3; i++){
					if (num[i] == 0){
						wl[(i + 1) % 3] = 1;
						wl[(i + 2) % 3] = 2;
						break;
					}
				}
			}
		}
		
		for (i = 0; i < 5; i++){
			printf("%d\n", wl[p[i]]);
		}
	}
}

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
bool dp[100005];
signed main()
{
    IOS
    int n,K; cin>>n>>K;
    int arr[n];
    for(int i=0;i<n;i++) cin>>arr[i];
    for(int stone = 0;stone <= K;stone++)
    {
      for(int i=0;i<n;i++)
      {
        if(stone >= arr[i] && !dp[stone - arr[i]])
        {
          dp[stone] = 1;
        }
      }
    }
    if(dp[K])
    {
      cout<<"First";
    }
    else cout<<"Second";
    return 0;
}

Measured memory_bytes: 384
N=int(input())
a=list(map(int,input().split()))
odd=0
four=0
for i in range(N):
  if a[i]%4==0:
    four+=1
  elif a[i]%2!=0:
    odd+=1
if four>=odd:
  print("Yes")
else:
  if odd==four+1 and odd+four==N:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 15020
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod = 1e9L+7;
int n;
vector<vector<int>> inp;
vector<int> dp;
//set<int> taken;

/*ll recursive_matching(int i=0,int mask=0)
{   
    if(i == n) return 1;
    if(dp[i][mask] != -1) return dp[i][mask];

    ll ans = 0;
    for(int j=0;j<n;j++)
    {
        int f = 1 << j;
        if(inp[i][j] == 1 and (f & mask) == 0)
        {
            ans += recursive_matching(i+1,mask+f);
            ans%=mod;
        }
    }
    return dp[i][mask] = ans;
}
*/
void add_self(int &a,int &b)
{
    a+=b;
    if(a>=mod) a-=mod;
}

ll mask_dp()
{
    dp[0] = 1;
    for(int mask = 0;mask<(1<<n)-1;mask++)
    {
        int men = __builtin_popcount(mask);
        for(int women = 0;women<n;women++)
        {
            if(inp[men][women] and !(mask & 1<<women))
            {
                int mask_2 = mask ^ 1<<women;
                add_self(dp[mask_2],dp[mask]);
            }
        }
    }
    return dp[(1<<n) -1];
}

int main()
{
    ios_base::sync_with_stdio(0); 
    cin.tie(0); cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    //int k;
    cin>>n;//>>k;
    inp.resize(n+1,vector<int> (n+1));
    dp.assign(1<<n,0);

    for(int i=0;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            cin>>inp[i][j];
        }
    }

    //cout<<candp(k)<<'\n';
    cout<<mask_dp()<<'\n';
    /*for(int i=0;i<n;i++)
    {
        for(int j=0;j<(1<<n);j++)
        {
            cout<<dp[i][j]<<" ";
        }
        cout<<'\n';
    }*/
}

Measured memory_bytes: 11400
#include<stdio.h>
int main()
{
	int num, alls[200000], i,j, now_min, count = 1;

	scanf("%d",&num);

	for (i = 0; i < num; i++) {
		scanf("%d", &alls[i]);
	}
	now_min = alls[0];

	for (i = 1; i < num; i++) {
		if (now_min >= alls[i]) {
			count++;
			now_min = alls[i];
		}
	}
	printf("%d\n", count);

	return 0;
}

Measured memory_bytes: 896
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        FastScanner in = new FastScanner();
        String s = in.nextLine();
        long[] num = new long[26];
        for (int i = 0; i < s.length(); i++) {
            num[s.charAt(i) - 97]++;
        }
        long l = s.length();
        long result = l * (l - 1) / 2 + 1;
        for (int i = 0; i < 26; i++) {
            result -= num[i] * (num[i] - 1) / 2;
        }
        System.out.println(result);
    }

    public static class FastScanner {
        BufferedReader br;
        StringTokenizer st;

        public FastScanner(String s) {
            try {
                br = new BufferedReader(new FileReader(s));
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

        public FastScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String nextToken() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        String nextLine() {
            st = null;
            try {
                return br.readLine();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
            return null;
        }

        int nextInt() {
            return Integer.parseInt(nextToken());
        }

        long nextLong() {
            return Long.parseLong(nextToken());
        }

        double nextDouble() {
            return Double.parseDouble(nextToken());
        }
    }
}

Measured memory_bytes: 25172
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<cstring>
#include<string>
#include<ctime>

using namespace std;
const int Max = 1e6 + 5;

int main(){
	int n, m, i, j, t, k, flag = 0;
	string a, b;
	cin >> a >> b;
	int A[26] = {0}, B[26] = {0};
	for(i = 0; i < a.size(); i++)
		A[a[i] - 'a']++;
	for(i = 0; i < b.size(); i++)
		B[b[i] - 'a']++;
	sort(A, A + 26);
	sort(B, B + 26);
	for(i = 0; i < 26; i++)
		if(A[i] != B[i]) { flag++; break; }
	if(flag) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 776
object Main extends App {
  val n: Int = readInt
  val l1: Array[Int] = readLine.split(" ").map(_.toInt)
  val (t, a) = (l1(0), l1(1))
  val h: Array[Int] = readLine.split(" ").map(_.toInt)

  var min = Int.MaxValue.toDouble
  var index = 1
  h.zipWithIndex.foreach {
    case (height, i) =>
      val diff = (a.toDouble - (t - height * 0.006)).abs
      if (diff < min)  {
        min   = diff
        index = i + 1
      }
  }
  println(index)
}


Measured memory_bytes: 25664
#include<bits/stdc++.h>
using namespace std;
const long double PI =(acos(-1));

int main(){
    int h=1,w=1;

    while(1){
        cin >> h >> w;
        if(h==0 && w==0) break;
        for(int i=0;i<h;++i){
            for(int j=0;j<w;++j){
                cout << '#';
            }
            cout << endl;
        }cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3112
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	LL n,c=0;
    cin>>n;
    FOR(i,1,n){
        LL j=n/i;
        if(i*j==n){
            c+=j-1;
        }else{
            c+=j;
        }
    }
    cout<<c;
}


Measured memory_bytes: 3488
// https://atcoder.jp/contests/abc159/tasks/abc159_d

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;
template <typename T>
inline bool chmax(T& a, T b);
template <typename T>
inline bool chmin(T& a, T b);
void print_ints(vector<ll> v);
template <typename T>
void drop(T a);

const ll INF = 1e18;

void solve() {
  ll N;
  cin >> N;

  VL as(N);
  rep(i, N) cin >> as[i];

  map<ll, ll> ct_map;

  for (auto a : as) ++ct_map[a];

  ll all_ct = 0;

  for (auto p : ct_map) {
    ll ct = p.se;
    all_ct += ct * (ct - 1) / 2;
  }

  for (auto a : as) {
    ll res = all_ct;
    ll ct = ct_map[a];
    res -= ct * (ct - 1) / 2;
    res += (ct - 1) * (ct - 2) / 2;
    cout << res << endl;
  }
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

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

template <typename T>
inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}

void print_ints(vector<ll> v) {
  rep(i, v.size()) {
    if (i > 0) {
      cout << " ";
    }

    cout << v[i];
  }

  cout << endl;
}

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}


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


int main() {

  ll N, d;
  ll ans = 0;
  cin >> N;
  std::vector<ll> vec(N);
  for (ll i = 0; i < N; ++i) {
    cin	>> d;
    vec[i] = d;
  }
  for (ll x = 0; x < N-1; ++x) {
    ll xx = vec[x];
    for	(ll y = x+1; y < N; ++y) {
      ans+=xx*vec[y];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

#define MAX_N 100000

// 入力
int N, M;

const int MOD = 1e9 + 7;

long long mem[MAX_N + 1];

long long fact(long long i) {
    if (i == 1) {
        return 1;
    } else if (mem[i] != 0) {
        return mem[i];
    } else {
        return mem[i] = (i * fact(i - 1)) % MOD;
    }
}

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

    if (abs(N - M) > 1) {
        cout << "0" << endl;
        return 0;
    } else if (N == M) {
        cout << (fact(N) * fact(M) * 2) % MOD << endl;
    } else {
        cout << (fact(N) * fact(M)) % MOD << endl;
    }

    return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>
 
int main(void)
{
  int h,w;
  for(;;)
  {
    scanf("%d %d", &h, &w);
    if(h==0 && w==0){
      break;
    }
    int i,j;
    for (i=0; i<h; ++i) {
      for (j = 0; j < w;  ++j) {
        if (i==0 || i==h-1 || j==0 || j==w-1) {
          putchar('#');
        }
        else{
          putchar('.');
        }
      }
      puts("");
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 588
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

vector<int> prime;

void make(){
  bool p[10010];
  fill(p, p+10010, true);
  p[0] = p[1] = false;
  for(int i = 0 ; i*i < 10010 ; i++){
    if(p[i]){
      for(int j = 2*i ; j < 10010 ; j += i){
	p[j] = false;
      }
    }
  }  
  for(int i = 0 ; i < 10010 ; i++){
    if(p[i]) prime.push_back(i);
  }  
}

int solve(vector<int> prime, int S){
  int ans = 0;
  int s = 0, t = 0, sum = 0;
  for(; ;){
    while(t < prime.size() && sum < S){
      sum += prime[t++];
    }
    if(prime[s] > S) break;
    if(sum == S) ans++;
    sum -= prime[s++];
  }
  return ans;
}

int main(){
  make();
  int n;
  while(cin >> n, n){
    cout << solve(prime, n) << endl;
  }
  return 0;
}

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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

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

struct UnionFind
{
	vector<long long> par;

	void init(long long n) {par.assign(n, -1);}

	long long root(long long x)
	{
		if (par[x] < 0) return x;
		else return par[x] = root(par[x]);
	}

	bool merge(long long x, long long y)
	{
		x = root(x);
		y = root(y);
		if(x == y) return false;
		if (par[x] > par[y]) swap(x, y);
		par[x] += par[y];
		par[y] = x;
		return true;
	}

	bool issame(long long x, long long y)
	{
		return root(x) == root(y);
	}

	long long size(long long x)
	{
		return -par[root(x)];
	}
};


int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	UnionFind uf;
	uf.init(100000*2 + 10);
	ll N, M; cin >> N >> M;
	REP(i, N)
	{
		ll k; cin >> k;
		REP(j, k)
		{
			ll l; cin >> l;
			uf.merge(i, l+N);
		}
	}

	bool ok{true};
	REP(i, N-1)
	{
		if (!uf.issame(i, i+1)) ok = false;
	}
	std::cout << (ok ? "YES" : "NO") << std::endl;
	
	return 0;
}


Measured memory_bytes: 4684
import java.util.*;
public class Main {
  public static void main(String[] args){

    Scanner sc = new Scanner(System.in);
    int A = sc.nextInt();
    int B = sc.nextInt();
    int C = sc.nextInt();

    if ((A + B + C) == 17) {
      System.out.println("YES");
    } else {
      System.out.println("NO");
    }

  }
}

Measured memory_bytes: 21204
#define _CRT_SECURE_NO_WARNINGS
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>

#define nn 100010
#define ll long long
#define inf 10000000000000
using namespace std;

int a[nn], n, m, A[nn], N, q[nn];

inline void Work(int st) {
	N = 0;
	int dl = 0;
	for (int i = st; i <= n; i += 2) 
		if (a[i] >= 0) q[++N] = i;
	
		
	for (int i = n; i > q[N]; i--) A[++A[0]] = i;
	for (int i = 1; i < q[1]; i++) A[++A[0]] = 1;
	for (int i = 1; i < N; i++) {
		int nm = q[i + 1] - q[i] - 1;
		for (int j = (nm + 1) / 2; j >= 1; j--) A[++A[0]] = j + 1;
	}
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	
	ll nm1 = 0, nm0 = 0;
	for (int i = 1; i <= n; i += 2) nm1 += max(0, a[i]);
	for (int i = 2; i <= n; i += 2) nm0 += max(0, a[i]);

	if (nm0 == 0 && nm1 == 0) {
		int ps = 1;
		for (int i = 1; i <= n; i++) if (a[i] > a[ps]) ps = i;
		printf("%d\n%d\n", a[ps],n-1);
		for (int i = n; i > ps; i--) printf("%d ", i);
		for (int i = 1; i < ps; i++) printf("%d ", 1);
		puts("");
		return(0);
	}

	if (nm0 > nm1) {
		Work(2);
	}else {
		Work(1);
	}
	printf("%lld\n", max(nm0, nm1));
	printf("%d\n", A[0]);
	for (int i = 1; i <= A[0]; i++) printf("%d\n", A[i]);
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main {
    public static void main (String[] args) {
      
      Scanner scanner = new Scanner(System.in);
      String n_in = scanner.nextLine();
      int n = Integer.parseInt(n_in);

      String d_all = scanner.nextLine();
      String[] d_str = d_all.split(" ");
      int[] d = new int[n];

      for (int i = 0;  i < n  ; i ++ ) {
          d[i] = Integer.parseInt(d_str[i]);
      }

      int r_int = 0;

      for (int i = 0;  i < n - 1 ; i ++ ) {
          for (int j = i+1;  j < n ; j ++ ) {
             r_int = r_int + (d[i] * d[j]);
          }
      }
      System.out.println(r_int);

      return;
    }
  }

Measured memory_bytes: 22740
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define REP(i,m,n) for(int i=(int)(m); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define RREP(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define rrep(i,n) RREP(i,n-1,0)
#define REPL(i,m,n) for(ll i=(ll)(m); i<(ll)(n); i++)
#define repl(i,n) REPL(i,0,n)
#define all(v) v.begin(), v.end()
// template<class t, class u>
// ostream& operator<<(ostream& os, const pair<t, u>& p) {
//   return os << "{" << p.first << ", " << p.second << "}";
// }
// template<class t> ostream& operator<<(ostream& os, const vector<t>& v) {
//   os << "{";
//   rep(i, v.size()) { if(i) os << ", "; os << v[i]; }
//   return os << "}";
// }
// template<class t> ostream& operator<<(ostream& os, const set<t>& se) {
//   os << "{";
//   auto itr = se.begin();
//   rep(i, se.size()) { if(i) os << ", "; os << *itr; itr++; }
//   return os << "}";
// }
// template<class t, class u>
// ostream& operator<<(ostream& os, const map<t, u>& mp) {
//   os << "{";
//   auto itr = mp.begin();
//   rep(i, mp.size()) { if(i) os << ", "; os << *itr; itr++; }
//   return os << "}";
// }
const int inf = 1e9+7;
const ll longinf = 1LL<<60;
const ll mod = 1e9+7;

int main() {

  ll N;
  cin >> N;

  ll ans;
  if (N % 2 == 0) {
    ans = N / 2;
  }
  else {
    ans = N / 2 + 1;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
int main()
{
    int a, n[100];
    std::cin >> a;
    for (int i = 0; i < a; i++)
        std::cin >> n[i];

    for (int i = 0; i < a; i++)
    {
        int v = n[i], j = i - 1;
        while (j >= 0 && n[j] > v)
            n[j + 1] = n[j--];
        n[j+1] = v;
        for (int i = 0; i < a; i++)
            std::cout << n[i] << (i<a - 1 ? " " : "\n");
    }
}



Measured memory_bytes: 3048
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
const ll oo = 0x3f3f3f3f3f3f3f3fLL;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define pb push_back
#define xx first
#define yy second
#define FOR(i,a,b) for (ll i=(a); i<(b); i++)
#define FORD(i,a,b) for (ll i=ll(b)-1; i>=(a); i--)

void self_min(ll &a, ll b) {
	a = min (a,b);
}
template <class T>
void self_max(T &a, T b) {
	a = max(a,b);
}
void add(ll &a, ll b) {
	a = (a+b)% 1000000007;
}

int main() {
	ios::sync_with_stdio(false);

	ll H, W; cin >> H >> W;

	vector<vb> inp(H,vb(W,true));
	FOR(i,0,H) {
		FOR(j,0,W) {
			char x; cin >> x;
			if (x == '#') {
				inp[i][j] = false;
			}
		}
	}

	vvl dp(H,vl(W,0));
	dp[0][0] = 1;

	FOR(i,0,H) {
		FOR(j,0,W) {
			if(!inp[i][j]) {
				continue;
			}
			if (i+1 < H)
				add(dp[i+1][j], dp[i][j]);
			if (j+1 < W)
				add(dp[i][j+1], dp[i][j]);
		}
	}
	cout << dp[H-1][W-1] << endl;
}


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


int main() {
	ios_base::sync_with_stdio(false);
	int n;
	string s, t;
	cin >> n >> s >> t;
	for (int i = 0; i < n; ++i) cout << s[i] << t[i];
	cout << endl;

	return 0;
}


Measured memory_bytes: 256
public class Main {
	
		
		public static void main(String[] args) {
			java.util.Scanner scan = new java.util.Scanner(System.in);
		int x = scan.nextInt();
			
		
		if(1<=x  && x<=100){;
		System.out.println(x*x*x);// TODO ?????????????????????????????????????????????
		}
		}	
			
		
	
	}
	

Measured memory_bytes: 26356
#include<iostream>
#include<cmath>
#include<string>
#include<algorithm>
#include<set>
#include<iomanip>
using namespace std;

int main()
{
	string s;
	cin>>s;
	for(int i=s.size()-2;;i-=2)
	{
		for(int j=0;j<i/2;j++)
		{
			if(s[j]!=s[j+i/2])break;
			if(j==i/2-1)
			{
				cout<<i<<endl;
				return 0;
			}
		}
	}
	return 0;
}

Measured memory_bytes: 888
#include <vector>
#include <algorithm>
#include <iostream>
#include <functional>
#include <string>

using namespace std;

vector<string> classes;
vector<string>::iterator classI;

int main() {
        int noon[9] = {0}, after[9] = {0};
        int sum[9] = {0}, syu[9] = {0};
        classes.clear();
        string classtemp;
        
        
        for(int i = 0; i < 9; i++) {
            cin >> classtemp;
        
            cin >> noon[i] >> after[i];
            classes.push_back(classtemp);
        }
        
        for(int i = 0; i < 9; i++) {
            sum[i] = noon[i] + after[i];
            syu[i] = (noon[i] * 200) + (after[i] * 300);
        }
        int i = 0;
        
        for (classI = classes.begin(); classI != classes.end(); classI++) {
            
            cout << *classI << " " << sum[i] << " " << syu[i] << endl;
            i++;
        }
    return 0;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;

vector<int> dv;
vector<int> du;
int U, V;
bool subtree = false;

void dfsv(vector<vector<int>> &G, int v, int p, int d){
    dv[v] = d;
    for (auto nv : G[v]){
        if(nv == p) continue;
        dfsv(G, nv, v, d+1);
    }
}

void dfsu(vector<vector<int>> &G, int v, int p, int d){
    du[v] = d;
    for (auto nv : G[v]){
        if(nv == p) continue;
        dfsu(G, nv, v, d+1);
    }
}

int main(){
    int n;
    cin >> n >> U >> V;
    U--; V--;
    vector<vector<int>> G(n);
    int a, b;
    for (int i = 0; i < n - 1; ++i) {
        cin >> a >> b;
        a--; b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    dv.assign(n, -1);
    du.assign(n, -1);
    dfsv(G, V, -1, 0);
    dfsu(G, U, -1, 0);

    int l = 0;
    for (int i = 0; i < n; ++i) {
        if(du[i] < dv[i]){
            l = max(l, dv[i] - 1);
        }
    }

    cout << l << endl;
}

Measured memory_bytes: 11648
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
using namespace std;
const int MOD = 1e9+7;
using ll = long long;
using vi = vector<int>;
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(x) x.begin(), x.end()
int main() {
   string s,t;
   cin >> s >> t;
   sort(ALL(s));
   sort(ALL(t),greater<int>());
   int a = s.size(),b=t.size();
   int c = min(a,b);
   rep(i,c){
     if(s.at(i)!=t.at(i)){
       if(s.at(i)-t.at(i)>0) cout << "No";
       else cout << "Yes";
       return 0;
     }
   }
   if(a<b) cout << "Yes";
   else cout << "No";
   return 0;
}  

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

using namespace std;

int c[13];
int a[13][13];

int main() {
	int n, m, x;
	cin >> n >> m >> x;
	for (int i = 0; i < n; i++) {
		cin >> c[i];
		for (int j = 0; j < m; j++)
			cin >> a[i][j];
	}
	int min_cost = 10000000;
	for (int mask = 0; mask < (1 << n); mask++) {
		int knowledge[13];
		for (int j = 0; j < m; j++)
			knowledge[j] = 0;
		int cost = 0;
		for (int i = 0; i < n; i++) {
			//cout << mask << " " << i << " " << (mask & (1 << i)) << "\n";
			if ((mask & (1 << i)) != 0) {
				cost += c[i];
				for (int j = 0; j < m; j++) {
					knowledge[j] += a[i][j];
				}
			}
		}
		//cout << cost << "\n";
		bool feasible = true;
		for (int j = 0; j < m; j++) {
		 	if (knowledge[j] < x) {
				feasible = false;
			}
		}
		if (feasible) 
			min_cost = min(min_cost, cost);
	}
	if (min_cost != 10000000)
		cout << min_cost << "\n";
	else 
		cout << -1 << "\n";
	return 0;
}


Measured memory_bytes: 3632
import sys, heapq
input = lambda: sys.stdin.readline().rstrip() 
sys.setrecursionlimit(10**7)
INF = 10**10
def I(): return int(input())
def F(): return float(input())
def SS(): return input()
def LI(): return [int(x) for x in input().split()]
def LI_(): return [int(x)-1 for x in input().split()]
def LF(): return [float(x) for x in input().split()]
def LSS(): return input().split()

def resolve():
    S = []
    while True:
        order = LSS()
        if order[0] == 'insert':
            k = int(order[1])
            heapq.heappush(S, -k)
        elif order[0] == 'extract':
            ans = - heapq.heappop(S)
            print(ans)
        else:
            break

if __name__ == '__main__':
    resolve()



Measured memory_bytes: 45580
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

func NewIo() *Io {
	return &Io{
		reader: bufio.NewReader(os.Stdin),
		writer: bufio.NewWriter(os.Stdout),
	}
}

func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) NextInt64() int64 {
	i, err := strconv.ParseInt(io.Next(), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}


func (io *Io) NextFloat() float64 {
	i, err := strconv.ParseFloat(io.Next(), 64)
	if err != nil {
		panic(err)
	}
	return i
}

func (io *Io) PrintLn(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}

func (io *Io) Printf(format string, a ...interface{}) {
	fmt.Fprintf(io.writer, format, a...)
}

func intMin(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func (io *Io) PrintBool(b bool, trueS, falseS string) {
	if b {
		io.PrintLn(trueS)
	} else {
		io.PrintLn(falseS)
	}
}

func intMax(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func absi(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func b2i(b bool) int {
	if b {
		return 1
	}
	return 0
}

type Int64s []int64
func (f Int64s) Len() int {
	return len(f)
}
func (f Int64s) Less(i, j int) bool {
	return f[i] < f[j]
}

func (f Int64s) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}


func abcInt(a int) int {
	if a > 0 {
		return a
	} else {
		return -a
	}
}

func gcdInt(a, b int) int {
	for a%b != 0 {
		a, b = b, a%b
	}
	return b
}

var (
	io *Io
)

type P struct {
	s string
	p int
	id int
}

type PS []P
func (f PS) Len() int {
	return len(f)
}
func (f PS) Less(i, j int) bool {
	if f[i].s != f[j].s {
		return f[i].s< f[j].s
	}
	return f[i].p > f[j].p
}

func (f PS) Swap(i, j int) {
	f[i], f[j] = f[j], f[i]
}

func solve() {
	n := io.NextInt()
	x := []int{}
	for i := 0; i < n; i++ {
		x = append(x, io.NextInt())
	}

	sm := 0
	for _, v := range x {
		sm += v
	}

	ans := sm
	for i := 1; i < n ; i++ {
		tmp := 0
		for j := 0; j < i; j++ {
			tmp += x[j]
		}

		cans := sm - 2 * tmp
		if cans < 0 {
			cans = -cans
		}
		if ans > cans {
			ans = cans
		}
	}

	io.PrintLn(ans)

}


func main() {
	io = NewIo()
	f, err := os.Open("src/input")
	if err == nil {
		io.reader = bufio.NewReader(f)
	}
	defer io.Flush()

	solve()
}

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

int main() {
    int n;
    cin>> n;
    string s;
    cin >> s;
    
    int W[310000],E[310000];
    for(int i = 1; i <= n; ++i) {
        if(s[i-1] == 'W') W[i] = W[i-1] + 1;
        else W[i] = W[i-1];
    }
    
    for(int i = 1; i <= n; ++i) {
        if(s[i-1] == 'E') E[i] = E[i-1] + 1;
        else E[i] = E[i-1];
    }
    
    int mn = 400000;
    for(int i = 0; i <= n; ++i) {
        mn = min(mn, (W[i-1] - W[0]) + (E[n] - E[i]));
    }
    
    cout << mn << endl;
}


Measured memory_bytes: 3076
program probA
  implicit none
  character(len=3) :: s
  integer :: AC, WA, TLE, RE, i, n
  
  read(*,*) n

  AC = 0
  WA = 0
  TLE = 0
  RE = 0
  
  do i = 1, n
     read(*,*) s
     if ( s == 'AC' ) then
        AC = AC + 1
     else if ( s == 'WA' ) then
        WA = WA + 1
     else if ( s == 'TLE' ) then
        TLE = TLE + 1
     else
        RE = RE + 1
     end if
  end do

  write(*,'("AC x ", i0)') AC
  write(*,'("WA x ", i0)') WA
  write(*,'("TLE x ", i0)') TLE
  write(*,'("RE x ", i0)') RE
  
  stop
end program probA


Measured memory_bytes: 2936
macro_rules! input {
    ($ttype:ty) => {
        {
            let mut input = String::new();
            let _= std::io::stdin().read_line(&mut input);
            input.trim().parse::<$ttype>().unwrap()
        }
    };

    ($($ttype:ty),*) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let mut iter = input.trim().split_whitespace();
            (
                $(iter.next().unwrap().parse::<$ttype>().unwrap(),)*
            )
        }
    };

    ($ttype:ty; $x:expr) => {
        {
            use std::io::BufRead;
            let mut input = String::new();
            let stdin = std::io::stdin();
            let _ = stdin.lock().read_line(&mut input);
            let v: Vec<$ttype> = input
                .trim()
                .split_whitespace()
                .map(|x| x.parse().unwrap())
                .collect();
            v
        }
    };

    ($ttype:ty; $x:expr; $y:expr) => {
        {
            use std::io::BufRead;
            let mut matrix = Vec::with_capacity($y);
            for _ in 0..$y {
                let mut input = String::new();
                let stdin = std::io::stdin();
                let _ = stdin.lock().read_line(&mut input);
                let v: Vec<$ttype> = input
                    .trim()
                    .split_whitespace()
                    .map(|x| x.parse().unwrap())
                    .collect();
                matrix.push(v);
            }
            matrix
        }
    };
}

fn main() {
    let (n, m) = input!(i64, i64);
    println!("{}", ((n - 2) * (m - 2)).abs());
}


Measured memory_bytes: 4352
n=int(input())
a=[input() for i in range(n)]
s=0
for i in range(n-1):
    if a[i][-1]!=a[i+1][0]:
        s+=1
a.sort()
for i in range(n-1):
    if a[i]==a[i+1]:
        s+=1
if s==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
N = int(input())
Sn = [int(input()) for _ in range(N)]

ans = sum(Sn)
if ans % 10 == 0:
    Xs, Ys = [], []
    for i in range(N):
        if Sn[i] % 10 == 0:
            Xs.append(Sn[i])
        else:
            Ys.append(Sn[i])

    if len(Ys) != 0:
        m = min(Ys) if len(Ys) > 1 else 0
        ans = sum(Xs) + sum(Ys) - m
    else:
        ans = 0
print(ans)


Measured memory_bytes: 3064
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
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; }

int main() {
    int N; cin >> N;
    vector<int> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];

    vector<int> dp(N + 2, INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
        chmin(dp[i + 1], dp[i] + abs(h[i] - h[i + 1]));
        chmin(dp[i + 2], dp[i] + abs(h[i] - h[i + 2]));
    }
    cout << dp[N - 1] << endl;
    return 0;
}


Measured memory_bytes: 1024
n = int(input())
difficulty = map(lambda x:int(x) ,input().strip().split())

probrems = []

for d in difficulty:
    probrems.append(d)


probrems.sort()

p_n = probrems[int(n/2)-1]
p_n_1 = probrems[int(n/2)]

print(p_n_1 - p_n)

Measured memory_bytes: 14428
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using static System.Console;


namespace ABC94_3
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            long[] x = new long[n];
            long[] y = new long[n];

            string[] s = ReadLine().Split(' ');
            for (int i = 0; i < n; i++)
            {
                x[i] = long.Parse(s[i]);
                y[i] = long.Parse(s[i]);
            }

            Array.Sort(y);
            long a = y[n / 2 - 1];
            long b = y[n / 2];

            for (int i = 0; i < n; i++)
            {
                WriteLine(x[i] > a ? a : b);
            }

        }
    }
}


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

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll n,d,a=0;
  cin >>n>>d;
  rep(i,n){
    ll x,y;
    cin >>x>>y;
    if(x*x+y*y<=d*d)a++;
  }
  cout <<a;
}

Measured memory_bytes: 3632
N = int(input())
h = list(map(int,input().split()))
ans = 0
while sum(h) > 0:
    for i in range(N):
        if h[i] > 0:
            l = i
            break
    ans += 1
    for i in range(l,N):
        if h[i] > 0:
            h[i] -= 1
        else:
            break

print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define mod 998244353
#define mp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define pi pair<ll,ll>
#define endl "\n"
using namespace std;
const ll N=500010;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);

    ll n;
    cin>>n;
    ll ans=0;
    for(ll a=1;a<=n;++a){
        for(ll b=1;b<=n;++b){
                ll gg=__gcd(a,b);
            for(ll c=1;c<=n;++c){
                ans+=__gcd(gg,c);
            }
        }
    }
    cout<<ans;

    return (0);
}


Measured memory_bytes: 3600
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.next());
		int[] p = new int[n];
		int idx;
		for (idx = 0; idx < n; idx++) {
			p[idx] = Integer.parseInt(sc.next());
		}

		int cnt = 0;
		for (idx = 1; idx < n - 1; idx++) {
			if (p[idx] <= p[idx - 1]) {
				if (p[idx] > p[idx + 1]) {
					++cnt;
				}
			} else { //if (p[idx] > p[idx -1]) {
				if (p[idx] <= p[idx + 1]) {
					++cnt;
				}
			}
		}

		System.out.println(cnt);

	}

}


Measured memory_bytes: 25172
#include<iostream>
#include<cmath>
using namespace std;
int main(){
     int a,b,c;
     cin >> a >> b >> c ;
     if (a==b && b == c )
        cout << 1 << endl ;
     else if (a !=b && b != c && c != a)
        cout << 3 << endl ;
     else
        cout << 2 ;


    return 0;
}








Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> inline bool 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;}


int gcd(int x, int y) {
  if (y == 0) return x;
  return gcd(y, x%y);
}

int main() {
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n) cin>>a[i];
  vector<int> l(n), r(n);
  rep(i,n-1) l[i+1] = gcd(l[i], a[i]);
  for (int i = n-1; i >= 1; --i) r[i-1] = gcd(r[i], a[i]);
  int ans = 1;
  rep(i,n) ans = max(ans, gcd(l[i],r[i]));
  cout<<ans<<endl;
  return 0;
}



Measured memory_bytes: 4552
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int H, W, h, w;

int main() {
    GI(H);
    GI(W);
    GI(h);
    GI(w);

    if (H % h == 0 && W % w == 0) {
        cout << "No\n";
    }
    else {
        cout << "Yes\n";

        FORN(i, H) {
            FORN(j, W) {
                if (i % h == h-1 && j % w == w-1) {
                    printf("%d ", -1000*(h*w-1)-1);
                }
                else {
                    printf("1000 ");
                }
            }
            printf("\n");
        }
    }
    
    return 0;
}

Measured memory_bytes: 1536
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
import java.util.function.Function;

import static java.lang.Math.min;

public class Main {
    static Map<Integer, Integer> map = new HashMap<>();

    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        int[] arr = new int[n];
        for (int i = 0; i < n; i++) {
            arr[i] = scanner.nextInt();
        }
        System.out.println(solution(arr, 0));
    }

    public static int solution(int[] arr, int index) {
        //to avoid TLE - use memoization
        if (map.containsKey(index)) {
            return map.get(index);
        }

        //base case
        if (index == arr.length - 1) {
            return 0;
        } else if (index == arr.length - 2) {
            return Math.abs(arr[index] - arr[index + 1]);
        }

        //recursive case
        int min = 0;
        if (index + 2 <= arr.length - 1) {
            min = min((Math.abs(arr[index] - arr[index + 1]) + solution(arr, index + 1))
                    , (Math.abs(arr[index] - arr[index + 2]) + solution(arr, index + 2)));
        }
        map.putIfAbsent(index, min);
        return min;
    }

}


Measured memory_bytes: 78884
#include <iostream>
#include <vector>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
int main(){
	int seat[17] = {0};
	int X = 0;
	int stop[100] = {0};
	int time = 0;
	queue<int> Q;
	while(X < 100){
		int x;
		if(time%5 == 0 && time < 500){
			Q.push(time/5);
		}
		while(1){
			if(Q.size())x = Q.front();
			else x = -1;
			bool f = false;
			
			if(~x){
				int people = (x%5==1?5:2);
				int use = 19 + 3 * (x%3) + 17 * (x%2);
				rep(i,17-people+1){
					bool flag = true;
					rep(j,people){
						flag &= seat[i+j] == 0;
					}
					if(flag){
						rep(j,people){
							seat[i+j] = use;
						}
						f = true;
						break;
					}
				}
			}
			if(f){	
				stop[x] = time - x * 5;
				Q.pop();
				X++;
			}
			if(!f)break;
		}
		rep(i,17){
			seat[i] = max(0,seat[i]-1);
		}
		time++;
	}
	int n,c=0;
	
	while(cin >> n){
		if(n == 1)c++;
		cout << stop[n] << endl;
	}
	int a = 0;
	while(c>=1){cout << a/a << endl;};
	
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e16+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main(){
    int H,W,N;
    cin >> H >> W >> N;
    map<P,int>Mp;
    for(int i = 0; i < N; i++) {
        int a,b;
        cin >> a >> b;
        for(int j = a-1; j <= a+1; j++) {
            for(int k = b-1; k <= b+1; k++) {
                Mp[{j,k}]++;
            }
        }
    }
    vector<int>ans(10);
    int cnt = 0;
    for(pair<P,int> x:Mp) {
        if(x.first.first >= 2 && x.first.first < H) {
            if(x.first.second >= 2 && x.first.second < W) {
                ans[x.second]++;
                cnt++;
            }
        }
    }
    cout << (H-2)*(W-2)-cnt << endl;
    for(int i = 1; i < 10; i++) {
        cout << ans[i] << endl;
    }
}

Measured memory_bytes: 59748
#include<cstdio>
#include<algorithm>

const int N=2e5,inf=1<<30;

int a,b;
int mini=inf;
long long sum;

int main()
{
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d %d",&a,&b);
		sum+=a;
		if(a>b)
			mini = std::min(mini,b);
	}
	if(mini == inf)
		printf("0\n");
	else
		printf("%lld\n",sum-mini);
	return 0;
}

Measured memory_bytes: 128
let read_int_array n = Array.init n (fun _ -> Scanf.scanf " %d" (fun x -> x))

let ans n k a =
  let rec solve i sum ret =
    if i = n then ret
    else if sum + a.(i) < k then solve (i + 1) (sum + a.(i)) (ret + 1)
    else solve (i + 1) sum 0
  in solve 0 0 0

let () =
  let n, k = Scanf.scanf "%d %d" (fun n k -> n, k) in
  let a = read_int_array n in
  Array.sort (fun x y -> - x + y) a;
  print_int (ans n k a)


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

int main() {
    int A, B, C, D, E, F;
    cin >> A >> B >> C >> D >> E >> F;

    double maxp = 0.0;

    int answ = 0;
    int anss = 0;
    for (int a=0; a<=F; a+=100*A) {
        for (int b=0; a+b<=F; b+=100*B) {
            int w = a + b;
            int maxs = min(F-w, E*(w/100));
            for (int c=0; c<=maxs; c+=C) {
                for (int d=0; c+d<=maxs; d+=D) {
                    int s = c + d;
                    if (w == 0 && s == 0) continue;
                    double p = ((double)s / (double)(w + s))*100;
                    if (maxp < p) {
                        answ = w;
                        anss = s;
                        maxp = p;
                    }
                }
            }
        }
    }

    if (anss == 0) cout << 100 * A << " " << anss << endl;
    else cout << answ+anss << " " << anss << endl;

    return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using llint = long long;
using vint = vector<int>;
using vvint = vector<vector <int>>;
const int INF = 1e9;
const llint llINF = 1e18;

int main () {
    int n, x = 1; cin >> n;
    vint p(n), q(n), a(n), b(n);
    for (int i = 0; i < n; i++) {
        x *= i;
        a[i] = i + 1;
        b[i] = i + 1;
    }
    rep(i, n) cin >> p[i];
    rep(i, n) cin >> q[i];

    int ax = 0, bx = 0;
    do {
        if (p == a) break;
        else ax++;
        //rep(i, n) printf("%d ", a[i]);

    } while (next_permutation(all(a)));

    do {
        if (q == b) break;
        else bx++;
    } while (next_permutation(all(b)));


    //cout << ax << endl;
    //cout << bx << endl;

    cout << abs(ax - bx) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;

int main() {
    string s;
    cin >> s;

    int ans = s.size();
    rep(i, 2) {
        int cnt = 0;
        rep(j, s.size()) {
            if ((j % 2 == 0) ^ (s[j] != (char)(i + '0'))) cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
}

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

int days(int Y, int M, int D) {
	int res = 0;
	for(int i = 1; i < Y; i++) {
		if(i % 3)
			res += 20 * 5 + 19 * 5;
		else
			res += 20 * 10;
	}
	for(int i = 1; i < M; i++) {
		if(Y % 3) {
			if(i % 2)
				res += 20;
			else
				res += 19;
		}
		else
			res += 20;
	}
	res += D;
	return res;
}

int main() {
	int n;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int y, m, d;
		cin >> y >> m >> d;
		cout << (days(1000,1,1) - days(y,m,d)) << endl;
	}
}

Measured memory_bytes: 1160
x, k, d = map(int, input().split())

# print(x,k,d)

x = abs(x)
if x <= d:
    if k%2:
        print(d-x)
    else:
        print(x)
    exit()

c = min(x//d, k)
x -= d*c
k -= c
if k%2:
    print(abs(d-x))
else:
    print(x)



Measured memory_bytes: 9176
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<cctype>
#include<string>
#include<set>
#include<iomanip>
#include <map>
#include<algorithm>
#include <functional>
#include<vector>
#include<climits>
#include<stack>
#include<queue>
#include<bitset>
#include <deque>
#include <climits>
#include <typeinfo>
#include <utility> 
using namespace std;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1LL << 60;
#define all(x) (x).begin(),(x).end()
#define puts(x) cout << x << endl
#define rep(i,m,n) for(ll i = m;i < n;++i)
#define pb push_back
#define fore(i,a) for(auto &i:a)
#define rrep(i,m,n) for(ll i = m;i >= n;--i)
 
int main() {
	int N;
	cin >> N;
	vector<int>p(N);
	vector<int>a(N);
	int cnt = 0;
	for (int i = 0; i < N; i++) {
		cin >> p[i];
		if (p[i] != i + 1)cnt++;
	}
	if (cnt <= 2)puts("YES");
	else puts("NO");
 
 
 
	return 0;
}

Measured memory_bytes: 256