akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cstdio>
#include<cstring>
#include <cstdlib>  
#include <math.h>
#include <cmath>
#include<complex>
#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 Complex = complex<double>;
using ll = long long;
template<typename T>using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;
const ll inf = 1145141919810364364LL;
double PI = acos(-1.0);
#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)


ll x[101010], sum[101010], fact[101010];
ll mod = 1000000007;
ll modpow(ll a, ll n) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

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

	ll N;
	cin >> N;
	for (int i = 0; i < N; i++)cin >> x[i];
	for (int i = 0; i < N; i++) {
		sum[i + 1] = sum[i] + x[i];
		sum[i + 1] %= mod;
	}
	fact[0] = 1;
	for (ll i = 1; i < 101010; i++) {
		fact[i] = fact[i - 1] * i;
		fact[i] %= mod;
	}


	ll ans = 0;
	for (ll i = 0; i < N-1; i++) {
		ll temp = (modpow(i + 1, mod - 2)*x[i])%mod;
		ans -= temp;
		ans += 5LL * mod;
		ans %= mod;
	}
	for (ll i = 1; i < N; i++) {
		ll temp = (x[N - 1] * modpow(i, mod - 2))%mod;
		ans += temp;
		ans %= mod;
	}
	ans *= fact[N - 1];
	puts(ans % mod);

	return 0;
}

Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n; cin >> n;
  int r = 50;
  while(n--){
    int k = 0, x; cin >> x;
    while(x%2 == 0) x /= 2, k++;
    r = min(r, k);
  }
  cout << r << endl;
  return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        mut h: i64, mut w: i64
    }
    let s = h * w;

    let mut ans = 1i64<<60;

    for _ in 0..2 {
        for x in 1..w {
            let s1 = x * h;
            let x2 = w - x;

            let s21 = (x2/2) * h;
            let s22 = s - s1 - s21;
            let smin = min(s1, min(s21, s22));
            let smax = max(s1, max(s21, s22));
            ans = min(ans, smax - smin);
    
            let s21 = x2 * (h/2);
            let s22 = s - s1 - s21;
            let smin = min(s1, min(s21, s22));
            let smax = max(s1, max(s21, s22));
            ans = min(ans, smax - smin);
        }
        std::mem::swap(&mut h, &mut w);
    }
    println!("{}", ans);
}


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

using namespace std;
typedef long long ll;
typedef vector<ll> vl ;
typedef pair<ll,ll> pl;
 
#define mp make_pair
#define pb push_back
#define fir first
#define sec second
#define rep(i,N) for(int i=0; i < (int)N; i++)
#define all(v) (v).begin(),(v).end()
//#define max(a,b) (a>b ? a : b)
//#define min(a,b) (a<b ? a : b)
 
const int MOD = 998244353;
const int INF = 100000002;
const double PI =4*atan(1);
const double eps = 1e-7;
const long long oo = 1e18;



int main(){
  double L;
  cin >> L;
  cout << fixed;
  cout << setprecision(30) <<  L*L*L/27 << endl;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
N=int(input())
ki=[[] for f in range(N)]
for i in range(N-1):
 u,v,w = map(int,input().split())
 ki[u-1].append([v-1,w%2])
 ki[v-1].append([u-1,w%2])
stack = [[0,0]]
check = [0]*N #チェック済みリスト
ans=[2]*N
ans[0]=0
while stack != [] :
 a=stack.pop()
 ne=a[0]
 if check[ne]==0:
  check[ne]=1
  for i in range(len(ki[ne])):
   if check[ki[ne][i][0]]==0:
    stack.append([ki[ne][i][0],(ki[ne][i][1]+ans[ne])%2])
    ans[ki[ne][i][0]]=(ki[ne][i][1]+ans[ne])%2
for i in ans:
 print(i)

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

vector<unordered_map<char, int>> b;

void insert(int k, char c)
{
    k++;
    while (k <= b.size() - 1)
    {
        b[k][c]++;
        k += k & -k;
    }
}

void update(int k, char d, char c)
{
    k++;
    while (k <= b.size() - 1)
    {
        b[k][d]--;
        b[k][c]++;
        k += k & -k;
    }
}

void merge(unordered_map<char, int> &a, unordered_map<char, int> &b)
{
    for (auto p : b)
    {
        a[p.first] += p.second;
    }
}

unordered_map<char, int> get_m(int k)
{
    k++;
    unordered_map<char, int> ret;
    while (k > 0)
    {
        merge(ret, b[k]);
        k -= k & -k;
    }
    return ret;
}

int main()
{
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    b.resize(n + 1);
    for (int i = 0; i < n; i++)
    {
        insert(i, s[i]);
    }
    for (int i = 0; i < q; i++)
    {
        int code;
        cin >> code;
        if (code == 1)
        {
            int k;
            cin >> k;
            k--;
            char c;
            cin >> c;
            if (c != s[k])
            {
                update(k, s[k], c);
                s[k] = c;
            }
        }
        else
        {
            int l, r;
            cin >> l >> r;
            l--;
            r--;
            auto b = get_m(l - 1);
            auto a = get_m(r);
            for (auto p : b)
            {
                a[p.first] -= p.second;
            }
            int res = 0;
            for (auto p : a)
            {
                if (p.second > 0)
                    res++;
            }
            cout << res << endl;
        }
    }
}

Measured memory_bytes: 102788
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] arr = sc.nextLine().split("/");

        String ans = "";
        if (Integer.parseInt(arr[0]) == 2019 &&  Integer.parseInt(arr[1]) <= 4 || Integer.parseInt(arr[0]) < 2019) ans = "Heisei";
        else ans = "TBD";

        System.out.println(ans);
    }
}

Measured memory_bytes: 23764
n = list(input())

mae = []
usiro = []
for i in range(int((len(n)-1)/2)):
    mae.append(n[i])
for i in range(int((len(n)+3)/2)-1,len(n)):
    usiro.append(n[i])

if mae == usiro:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
  int n,count=0;
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      for(int z=0;z<n;z++){
        count++;
      }
    }
  }
  printf("%d",count);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ps push_back
using namespace std;
const int maxn=1e5+5;
vector<int>edg[maxn];
int siz1[maxn], siz2[maxn];
void dfs1(int x, int fa)
{
    siz1[x]=1;
    for(int i=0; i<(int)edg[x].size(); i++)
    {
        if(edg[x][i]==fa)continue;
        dfs1(edg[x][i], x);
        siz1[x]+=siz1[edg[x][i]];
    }
    return;
}

void dfs2(int x, int fa)
{
    siz2[x]=1;
    for(int i=0; i<(int)edg[x].size(); i++)
    {
        if(edg[x][i]==fa)continue;
        dfs2(edg[x][i], x);
        siz2[x]+=siz2[edg[x][i]];
    }
    return;
}
int pre[maxn], cnt, n;
void dfs(int x, int fa, int y)
{
    if(x==y)return;
    for(int i=0; i<(int)edg[x].size(); i++)
    {
        int xx=edg[x][i];
        if(xx==fa)continue;
        if(siz1[xx]!=siz2[xx])
        {
            if(xx==y)return;
            pre[cnt]=pre[cnt-1]+siz1[xx]+siz2[xx]-n;
//            printf("%d %d %d %d %d %d\n", cnt, pre[cnt], pre[cnt-1], siz1[xx], siz2[xx], n);
            cnt++;
            dfs(xx, x, y);
        }
    }
    return;
}

int main()
{
    cin>>n;
    cnt=1;
    pre[0]=0;
    int x, y, i, j;
    for(i=0; i<n-1; i++)
    {
        scanf("%d%d", &x, &y);
        edg[x].ps(y);
        edg[y].ps(x);
    }
    dfs1(1, 0);
    int b=siz1[n];
    dfs2(n, 0);
    int a=siz2[1];
    int c=n-a-b;
//    cout<<a<<" "<<b<<" "<<c<<endl;
    dfs(1, 0, n);
    cnt--;
    if((a+pre[(cnt+1)/2])>(b+c-pre[(cnt+1)/2]))
    {
        printf("Fennec\n");
    }
    else printf("Snuke\n");
    return 0;
}


Measured memory_bytes: 14720
def main():
    n = int(input())

    m = dict()
    n_max = -1;
    for _ in range(n):
        s = input()
        if s not in m:
            m[s] = 0
        else:
            m[s] += 1

        n_max = max(m[s], n_max)

    for k, v in sorted(m.items(), key=lambda x: x[0]):
        if v == n_max:
            print(k)


if __name__ == "__main__":
    main()


Measured memory_bytes: 102488
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int x,a,c,yen=0;
  cin>>x;
  if(x>=500)
  {
  a= x/500;
  x= x%500;
  yen=yen+(a*1000);
  }
  if(x>=5)
  {
  c= x/5;
  yen=yen+(c*5);
  }
  cout<<yen;
  return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<vector<int>> f(n,vector<int>(10));
  vector<vector<int>> p(n,vector<int>(11));
  rep(i,n){
    rep(j,10) cin >> f[i][j];
  }
  rep(i,n){
    rep(j,11) cin >> p[i][j];
  }
  vector<int> a(10);
  a={1,2,4,8,16,32,64,128,256,512};
  
  int ans=-1000000000;
  for(int m=1;m<1024;m++){
    int an=0;
    rep(i,n){//店i
      int q=0;
      rep(j,10){
        if(f[i][j]&&(int)(m/a[j]%2)) q++;
      }
      an+=p[i][q];
    }
    ans=max(ans,an);
  }
  cout << ans << endl;
}

Measured memory_bytes: 3624
import numpy as np
N, L = map(int, input().split())
aji = np.array(list(range(1,N+1))) + L - 1

def getNearestValue(list, num):
    idx = np.abs(np.asarray(list) - num).argmin()
    return list[idx]

answer = sum(aji) - getNearestValue(aji, 0)
print(answer)

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

struct node
{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};

typedef struct node * Node;

#define NIL NULL

Node root;

/*
  Node treeMinimum(Node x)
  {


  }

  Node treeMaximum(Node x)
  {


  }

  Node treeSearch(Node u, int k)
  {


  }

  Node treeSuccessor(Node x)
  {


  }

  void treeDelete(Node z)
  {
  Node y; // node to be deleted
  Node x; // child of y
  }
*/

void insert(int k)
{
  Node y=NIL;
  Node x=root;
  Node z;
  z=malloc(sizeof(struct node));
  z->key=k;
  z->left=NIL;
  z->right=NIL;

  while (x!=NIL)
    {
      y=x; // 親を設定
      if (z->key<x->key)
	{
	  x=x->left; // 左の子へ移動
	}
      else
	{
	  x=x->right; // 右の子へ移動
	}
    }
  z->parent=y;
  if (y== NIL)
    {
      // T が空の場合
      root=z;
    }
  else if (z->key<y->key)
    {
      y->left=z; // z を y の左の子にする
    }
  else
    {
      y->right=z; // z を y の右の子にする
    }
}

void inorder(Node u)
{
  if(u==NIL)
    {
      return;
    }
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u)
{
  if(u==NIL)
    {
      return;
    }
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main()
{
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ )
    {
      scanf("%s", com);
      if ( com[0] == 'i' )
	{
	  scanf("%d", &x);
	  insert(x);
	}
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
    }
  
  return 0;
}

/*
insert(T, z)
{
  y = NIL; // x の親
  x = 'T の根';
  while (x ≠ NIL)
    {
      y = x; // 親を設定
      if (z.key < x.key)
	{
	  x = x.left; // 左の子へ移動
	  else
	    {
	      x = x.right; // 右の子へ移動
	      z.p = y;
	    }
	}
      if (y == NIL)
	{
	  // T が空の場合
	  'T の根' = z;
	}
      else if (z.key < y.key)
	{
	  y.left = z; // z を y の左の子にする
	}
      else
	{
	  y.right = z; // z を y の右の子にする
	}
    }
}

  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ )
    {
      scanf("%s", com);
      if ( com[0] == 'f' )
	{
	  scanf("%d", &x);
	  Node t = treeSearch(root, x);
	  if ( t != NIL ) printf("yes\n");
	  else printf("no\n");
	}
      else if ( com[0] == 'i' )
	{
	  scanf("%d", &x);
	  insert(x);
	}
      else if ( com[0] == 'p' )
	{
	  inorder(root);
	  printf("\n");
	  preorder(root);
	  printf("\n");
	}
      else if ( com[0] == 'd' )
	{
	  scanf("%d", &x);
	  treeDelete(treeSearch(root, x));
	}
    }
 
*/



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



int main()
{
    int a,b,c,d,e,f,g,h,i,j;
    string s,s1;
    vector<char>v;
    vector<char>v1;
    vector<char>v2;
    cin>>s;
    a=s.size();
    if(a%2==0)
    {
        for(i=0; i<a/2; i++)
        {
            v.push_back(s[i]);
        }
        for(i=a/2; i<a; i++)
        {
            v1.push_back(s[i]);
        }

    }

    else
    {
        for(i=0; i<a/2; i++)
        {
            v.push_back(s[i]);
        }
        for(i=a/2+1; i<a; i++)
        {
            v1.push_back(s[i]);
        }
    }
     reverse(v1.begin(),v1.end());
     c=0;d=0;e=0;
     int ans=0;
     for(i=0;i<v.size();i++)
     {
         if(v[i]!=v1[i])
         {
             c++;
         }

     }
     cout<<c<<endl;
     return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
#define endl '\n'
#define fr(i,a,b) for(ll i=a; i<b; i++)
#define fr1(i,a,b) for(ll i=a; i>=b; i--)
#define ll long long int
#define ld long double
#define vi vector<ll>
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define mp(i,j) make_pair(i,j)
#define fi first
#define se second
#define input(a,n) fr(i,0,n)cin>>a[i]
#define output(a,n) fr(i,0,n)cout<<a[i]<<" "
#define dbg cout<<"hurr"<<endl;
#define dbg2 cout<<"hurr2"<<endl;
#define md 1000000007
#define sp << " " <<
#define pi 3.14159265358979323846
#define fixd(x) cout << fixed << setprecision(x);

int main()
{
    fast;
    ll n;
    cin >> n;
    ll a[n][3],dp[n][3];
    fr(i,0,n)
    {
        cin >> a[i][0] >> a[i][1] >> a[i][2];
        dp[i][0]=a[i][0];
        dp[i][1]=a[i][1];
        dp[i][2]=a[i][2];
    }
    dp[0][0]=a[0][0];
    dp[0][1]=a[0][1];
    dp[0][2]=a[0][2];
    fr(i,1,n)
        fr(j,0,3)
            fr(k,0,3)
                if(j!=k)
                    dp[i][j]=max(a[i][j]+dp[i-1][k],dp[i][j]);
    cout << max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
}

Measured memory_bytes: 4992
#include <stdio.h>
#include <math.h>
#include <assert.h>

int min_of_common(int a0, int a1, int b0, int b1) {
  if (a0 > a1) return -1;
  if (b0 > b1) return -1;
  if (a0 >= b0 && a0 <= b1) return a0;
  if (b0 >= a0 && b0 <= a1) return b0;
  return -1;
}

int modify(int current, int target, double tax) {
  int testee = current * tax;
  if (testee < target) {
    do {
      current++;
      testee = current * tax;
    } while (testee < target);
  }
  else if (testee > target) {
    do {
      current--;
      testee = current * tax;
    } while (testee > target);
  }
  assert(testee == target);
  return current;
}

int main() {
  int A, B;
  const double tax_a = 0.08, tax_b = 0.1;
  scanf("%d %d", &A, &B);
  double A0 = (double)A / tax_a;
  double B0 = (double)B / tax_b;
  double A1 = (double)(A + 1) / tax_a;
  double B1 = (double)(B + 1) / tax_b;

  int iA0 = (int)ceil(A0);
  int iA1 = (int)floor(A1);
  int iB0 = (int)ceil(B0);
  int iB1 = (int)floor(B1);

  iA0 = modify(iA0, A, tax_a);
  iA1 = modify(iA1, A, tax_a);
  iB0 = modify(iB0, B, tax_b);
  iB1 = modify(iB1, B, tax_b);

  // printf("%d %d %d %d\n", iA0, iA1, iB0, iB1);
  printf("%d\n", min_of_common(iA0, iA1, iB0, iB1));
  return 0;
}


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

using namespace std;

#define fcout(d) cout << fixed << setprecision(d)
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define repU(i,s,t) for(int i = (s); i <= (t); ++i)
#define repD(i,t,s) for(int i = (t); i >= (s); --i)
#define all(v)  begin(v),end(v)
#define clr(v) fill(all(v),0)
#define l_bnd lower_bound
#define u_bnd upper_bound
#define puf push_front
#define pub push_back
#define pof pop_front
#define pob pop_back
#define mkp make_pair
#define mkt make_tuple
#define fir first
#define sec second
#define q_ceil(n,d) ((n - 1)/(d) + 1)
#define parity(a,b) (((a)^(b)) & 1 ^ 1)

typedef long long ll;
typedef unsigned long long ull;
typedef double db;

const pair<int,int> DIR[] = { {1,0},{0,1},{-1,0},{0,-1},{1,1},{-1,1},{-1,-1},{1,-1} };
const int INF_32 = -1 + (1 << 30);
const ll INF_64 = -1 + (1LL << 62);
const int MOD = 1e9 + 7;


int n,a[2002];
int dp[2002][2002],rec[2][2002];

inline int cal(int i, int j){
	if(dp[i][j] >= 0) return dp[i][j];
	if(i <= j){
		if(j < n){
			if(rec[0][j] < 0){
				repU(k,j + 1,n) rec[0][j] = max(rec[0][j],cal(k,j));
			}
			return dp[i][j] = rec[0][j];
		}
		else return dp[i][n] = abs(a[n] - a[i]);
	}else{
		if(i < n){
			if(rec[1][i] < 0){
				rec[1][i] = INF_32;
				repU(k,i + 1,n) rec[1][i] = min(rec[1][i],cal(i,k));
			}
			return dp[i][j] = rec[1][i];
		}
		else return dp[n][j] = abs(a[n] - a[j]);
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int z;
	cin>>n>>z>>a[0];
	rep1(i,n) cin>>a[i];
	rep(i,2) fill(all(rec[i]),-1);
	rep(i,n + 1) fill(all(dp[i]),-1);
	cout<<cal(0,0)<<'\n';
}


Measured memory_bytes: 16000
# include<iostream>
# include<string>

using namespace std;

int main(){
  int cnt=0;
  string s, t;
  cin >> s;
  cin >> t;
  for(int i=0; i<3; ++i){
    if(s[i] == t[i])
      cnt++;
  }
  cout << cnt << '\n';
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> a(N+1);
    a.at(0) = 0;
    a.at(1) = 0;
    for(int i = 2; i < N+1; i++){
        cin >> a.at(i);
    }
    vector<int> count(N+1, 0);
    for(int i = 2; i < N+1; i++){
        count.at(a.at(i))++;
    }
    for(int i = 1; i < N+1; i++){
        printf("%d\n",count.at(i));
    }
}

Measured memory_bytes: 4844
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#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=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int N,l;
	cin >> N;
	vector<int> B(N-1);
	for (int i = 0;i<N-1;i++){
		cin >> l;
		B[i] = l;
	}
	int ans = B[0];
	for (int i = 1;i<N-1;i++){
		ans += min(B[i-1],B[i]);
	}
	ans += B[N-2];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = 0;
const int mod = 1000000007;

int cnt[101010];
int sum = 0;
int32_t main()
{
    usecppio
    int N; cin >> N;
    for (int i = 0; i<N; i++)
    {
        int x; cin >> x;
        cnt[x]++;
        sum += x;
    }
    int q; cin >> q;
    for (int i = 0; i<q; i++)
    {
        int b, c; cin >> b >> c;
        int s = cnt[b]*(c-b);
        sum += s;
        cnt[c]+=cnt[b];
        cnt[b]=0;
        cout << sum << '\n';
    }
}

Measured memory_bytes: 4420
process.stdin.resume();
process.stdin.setEncoding('utf8');
process.stdin.on('data',function (chunk)
{
  var x = parseInt(chunk.trim(), 10);
  var h = Math.floor(x / 3600);
  var mod = x % 3600;
  var m = Math.floor(mod / 60);
  s = mod % 60;
  console.log(h + ":" + m + ":" + s);
});

Measured memory_bytes: 15488
using System;
using System.Linq;

namespace AtCoderBeginnerContest157
{
	class Program
	{
		static void Main(string[] args)
		{
			var page = ReadInt();
			var kisu = page % 2 == 1;
			Console.WriteLine(kisu ? page / 2 + 1 : page / 2);
		}

		public static int ReadInt()
			=> int.Parse(Console.ReadLine());

		public static int[] ReadIntArray()
			=> Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();

		public static long ReadLong()
			=> long.Parse(Console.ReadLine());

		public static long[] ReadLongArray()
			=> Console.ReadLine().Split().Select(x => long.Parse(x)).ToArray();

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

		public static string[] ReadStringArray()
			=> Console.ReadLine().Split();
	}
}


Measured memory_bytes: 11092
import numpy as np
import collections

N = int(input())
A = list(map(int, input().split()))

dic = {}
after = {}

l = collections.Counter(A)

for key, val in l.items():
	dic[key] = val * (val - 1) // 2
	after[key] = (val - 1) * (val - 2) // 2

numsum = sum(dic.values())

ans = {}
for key in dic.keys():
	ans[key] = numsum - dic[key] + after[key]

for i in range(N):
	print(ans[A[i]])



Measured memory_bytes: 53384
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <algorithm>
#include <climits>
#include <iterator>
#include <stack>
#include <deque>
#include <list>
#include <array>
#include <unordered_set>
#include <unordered_map>
using namespace std;
const int MOD = 1e9 + 7;
int main()
{
	int n, k;
	cin >> n >> k;
	int a[n];
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}
	int dp[n];
	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);
	for (int i = 2; i < n; i++)
	{
		dp[i] = INT_MAX;
		for (int j = i - k; j < i; j++)
		{
			if (j < 0)
				continue;
			dp[i] = min(dp[i], dp[j] + abs(a[i] - a[j]));
		}
	}
	cout << dp[n - 1];
}

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


inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef vector<vector<long long>> VVL;
typedef vector<string> VS;
typedef pair<ll,ll> P;
typedef tuple<int,int,int> tpl;

#define ALL(a)  (a).begin(),(a).end()
#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(c) reverse((c).begin(),(c).end())
#define LB(a,x) lower_bound((a).begin(), (a).end(), x) - (a).begin()
#define UB(a,x) upper_bound((a).begin(), (a).end(), x) - (a).begin()

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);--i)
#define RREP(i,n) RFOR(i,n,0)

#define en "\n"

constexpr double EPS = 1e-9;
constexpr double PI  = 3.1415926535897932;
constexpr int INF = 2147483647;
constexpr long long LINF = 1LL<<60;
constexpr long long MOD = 1000000007; // 998244353;

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

template<class T>
void remove_duplication(vector<T> &v){
    sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
}

long long modp(long long a, long long p) {
    long long res = a % p;
    if (res < 0) res += p;
    return res;
}

void Main(){
    ll N,D,X; cin >> N >> X >> D;

    if(X == 0 && D == 0){
        cout << 1 << en;
        return;
    }
    else if(D == 0){
        cout << N+1 << en;
        return;
    }

    int flag = D>0 ? 1 : -1;
    D = abs(D);

    VL mod{0};
    REP(i,N){
        ll m = modp(mod.back() + X, D);
        mod.push_back(m);
    }
    remove_duplication(mod);
    map<ll,int> mp;
    REP(i,mod.size()) mp[mod[i]] = i;

    vector<vector<P>> v(mod.size()); v[0].emplace_back(0,0);
    ll m = 0;
    for(ll i=1; i<N+1; i++){
        m = modp(m + X, D);
        int k = mp[m];
        ll mn = i*X / D + flag * i*(i-1)/2;
        ll mx = i*X / D + flag * (N*(N-1)/2 - (N-i)*(N-i-1)/2);
        if(flag < 0) swap(mn, mx);
        v[k].emplace_back(mn,mx);
    }

    ll ans = 0;
    REP(i,mp.size()){
        SORT(v[i]);
        ll e = -LINF;
        REP(j,v[i].size()){
            if(e < v[i][j].first) ans += v[i][j].second - v[i][j].first + 1;
            else if(e < v[i][j].second) ans += v[i][j].second - e;
            chmax(e, v[i][j].second);
        }
    }

    cout << ans << en;
    return;
}

int main(void){
    cin.tie(0);ios_base::sync_with_stdio(0);cout<<fixed<<setprecision(15);
    int t=1; //cin>>t;
    REP(_,t){
        Main();
    }
    return 0;
}

Measured memory_bytes: 25200
#include<bits/stdc++.h>
#define M 256
#define EPS 1e-9
using namespace std;

int n,R[M],I[M],O,x[M];
double ans;
int ansS,ansA,ansC;

void ROcalc(int S,int A,int C){
  R[0]=S;
  for(int i=1;i<=n;i++) R[i]=(A*R[i-1]+C)%M,O=(I[i]+R[i])%M,x[O]++;
}

void Hcalc(int S,int A,int C){
  double H=0;
  for(int i=0;i<M;i++)if(x[i]>0)H-=((double)x[i]/n)*(log((double)x[i]/n));
  if(ans>H+EPS) ans=H,ansS=S,ansA=A,ansC=C;
}

int main(){
  while(1){
    cin>>n;
    ans=M;
    if(n==0) break;
  for(int i=1;i<=n;i++)cin>>I[i];
  for(int i=0;i<=15;i++)
    for(int j=0;j<=15;j++)
      for(int k=0;k<=15;k++)memset(x,0,sizeof(x)),ROcalc(i,j,k),Hcalc(i,j,k);
   cout<<ansS<<" "<<ansA<<" "<<ansC<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
N, M = map(int, input().split())

ans = [-1] * N

for i in range(M):
  s, c = map(int, input().split())
  s -= 1
  if ans[s] != -1 and ans[s] != c:
    print(-1)
    exit()
  ans[s] = c
  
if N != 1:
  if ans[0] == 0:
    print(-1)
    exit()
  
  if ans[0] == -1:
    ans[0] = 1
    
  for i in range(N):
    if ans[i] == -1:
      ans[i] = 0

else:
  if ans[0] == -1:
    ans[0] = 0
    
print(''.join(map(str, ans)))
  

Measured memory_bytes: 9068
loopCnt = int(input())
cards = list(map(int, input().split()))

alice = 0
bob = 0

cards.sort(reverse=True)

for i in range(loopCnt):
  if i == 0 or i%2 == 0:
    alice += cards[i]
  elif i%2 == 1:
    bob += cards[i]

print(alice-bob)

Measured memory_bytes: 9176
#include <stdio.h>
 
int main()
{
  int n, k, i;
  char s[11];

  scanf("%d%s%d", &n, s, &k);

  for (i = 0; i < n; i++) {
    if (s[i] != s[k - 1]) {
      s[i] = '*';
    }
  }

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


Measured memory_bytes: 128
import math
import os
import sys
from collections import defaultdict

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

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 998244353

# 解説AC
N = int(sys.stdin.readline())
X = sys.stdin.readline().rstrip()
if len(X) != N:
    X = '0' * (N - len(X)) + X


def get_divisors(n):
    """
    n の約数をリストで返す
    :param int n:
    :rtype: list of int
    """
    ret = []
    for i in range(1, int(math.sqrt(n)) + 1):
        if n % i == 0:
            ret.append(i)
            if n // i != i:
                ret.append(n // i)
    return ret


# @debug
def test(N, X):
    def roll(k):
        if k & 1:
            k >>= 1
        else:
            k = (k >> 1) + 2 ** (N - 1)
        return k

    X = int(X, 2)
    ret = 0
    for K in range(X + 1):
        r = 1
        k = roll(K)
        while k != K:
            k = roll(k)
            r += 1
        ret += r
        if r != N * 2 or 1:
            import numpy as np
            print(np.binary_repr(k, N), r)
    return ret


def inv_s(x):
    """
    :param str x:
    """
    return ''.join(['0' if c == '1' else '1' for c in x])


# @debug
def count(d):
    sz = N // d

    base = X[:sz] + inv_s(X[:sz])
    s = base * (N // sz)
    return int(X[:sz], 2) + (s <= X + inv_s(X))


# 全部 N * 2 で戻る
counts = defaultdict(int)
counts[N * 2] = int(X, 2) + 1

# k 回でもとに戻る
ks = [N * 2 // d for d in get_divisors(N) if d % 2 and d != 1]
for k in ks:
    d = N * 2 // k
    counts[k] = count(d)

# 数え上げ
# k の約数はカウント済みなので引く
ans_counts = defaultdict(int)
for k in sorted(ks):
    ans_counts[k] = counts[k] - sum([ans_counts[d] for d in get_divisors(k)])
ans_counts[N * 2] = counts[N * 2] - sum([ans_counts[d] for d in get_divisors(N * 2)])

ans = 0
for k, cnt in ans_counts.items():
    ans += k * cnt
    ans %= MOD
print(ans)


Measured memory_bytes: 140488
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        char[] s = Console.ReadLine().ToCharArray();
        Array.Sort(s);
        char[] disS = s.Distinct().ToArray();
        int a = 97,
            count = 0;
        for (; count < disS.Length; count++)
        {
            if ((int)disS[count] != a + count)
            {
                Console.WriteLine(Convert.ToChar(a + count));
                return;
            }
        }
        if (count < 26)
            Console.WriteLine(Convert.ToChar(a + count));
        else
            Console.WriteLine("None");
    }
}

Measured memory_bytes: 13524
#include<iostream>
#include<string>

using namespace std;

int main(void)
{
	string str;
	getline(cin,str);
	for(int i=0;i<str.length();i++)
	{
		if('a'<=str[i]&&str[i]<='z')
		{
			str[i]+='A'-'a';
		}
	}
	cout<<str<<endl;
	cin>>str;
}

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

int main() {
	int k, a, b;
	cin >> k >> a >> b;
	if (a <= b / k * k)cout << "OK" << endl;
	else cout << "NG" << endl;
	return 0;
}






Measured memory_bytes: 3552
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
 
#define sl(x) scanf("%ld", &x)
#define ss(x) scanf("%s", x)
#define pl(x) printf("%ld\n", x)
#define pd(x) printf("%lf\n", x)
#define ps(x) printf("%s\n", x)
 
#define INF 1000000000000000000
#define MOD 1000000007
 
#define MIN(a,b) (((a)<(b))?(a):(b))
#define MAX(a,b) (((a)>(b))?(a):(b))

int compare_long(const void *a, const void *b) {
	return *(long*)a - *(long*)b;
}
 
int main() {
	long H, W;
	long tmp;
	long low, mid, high;
	long min, max;
	long ans = INF;
	long i, j;
	
	sl(H); sl(W);
	for(i=0;i<2;i++) {
		low = 1; high = H; mid = (low + high) / 2;
		while(1) {
			if(mid * W <= H * W / 3 && (mid + 1) * W > H * W / 3) {
				break;
			}
			if(mid * W < H * W / 3) {
				low = mid + 1;
				mid = (low + high) / 2;
			} else {
				high = mid - 1;
				mid = (low + high) / 2;
			}
		}
		for(j=0;j<2;j++) {
			min = max = mid * W;
			if((H - mid) % 2 && W % 2) {
				if(H - mid > W) {
					min = MIN(min, (H - mid) / 2 * W);
					max = MAX(max, ((H - mid) / 2 + 1) * W);
				} else {
					min = MIN(min, (H - mid) * (W / 2));
					max = MAX(max, (H - mid) * (W / 2 + 1));
				}
			} else {
				min = MIN(min, (H - mid) * W / 2);
				max = MAX(max, (H - mid) * W / 2);
			}
			ans = MIN(ans, max - min);
			mid++;
		}
		tmp = H; H = W; W = tmp;
	}
	
	pl(ans);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
    int N, M;
    cin >> N >> M;
    string S;
    cin >> S;
    vector<int> jump;
    int t = N;
    while(t != 0){
        int flag = 0;
        for(int i = M; i >= 1; i--){
            if(t - i >= 0 && S[t - i] != '1'){
                jump.push_back(i);
                t -= i;
                flag = 1;
                break;
            }
        }
        if(flag == 0){
            cout << -1 << endl;
            return 0;
        }
    }
    for(int i = jump.size() - 1; i >= 0; i--){
        if(i != 0) cout << jump[i] << ' ';
        else cout << jump[i] << endl;
    }
}

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

using namespace std;

int main() {
    int n, k;
    while(cin >> n >> k) {

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

        map<int, int> count;

        for (int i = 0; i < n; i++) {
            count[a[i]]++;
        }

        vector<int> cc(count.size());
        int x = 0;
        for (auto& p : count) {
            cc[x] = p.second;
            x++;
        }

        sort(cc.begin(), cc.end());


        int c = count.size() - k;
        int ans = 0;

        for (int i = 0; i < c; i++) {
            ans += cc[i];
        }

        cout << ans << endl;
    }
}

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

int main() {
    //ifstream cin("b.in");

    int n, m; cin >> n >> m;
    
    vector<vector<int>> a(n, vector<int> (m, 0));

    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j) {
            cin >> a[i][j];
            a[i][j] -= 1;
        }
    
    auto getState = [&] (vector<int> mask) {
        vector<int> has(m, 0);
        vector<int> cnt(m, 0);

        for(auto val : mask)
            has[val] = 1;

        for(int i = 0; i < n; ++i)
            for(int j = 0; j < m; ++j)
                if(has[a[i][j]]) {
                    cnt[a[i][j]] += 1;
                    break;
                }
        return cnt;
    };

    vector<int> mask;
    for(int i = 0; i < m; ++i)
        mask.push_back(i);
    vector<int> deleted(m, 0);

    int ans = 1e9;

    while(not mask.empty()) {
        vector<int> state = getState(mask);
        int maxx = 0;
        for(int i = 0; i < m; ++i) {
            maxx = max(state[i], maxx);
        }

        vector<int> new_mask;

        for(int i = 0; i < m; ++i) {
            if(state[i] != maxx and not deleted[i]) {
                new_mask.push_back(i);
            } else {
                deleted[i] = 1;
            }
        }

        ans = min(ans, maxx);
        mask = new_mask;
    }

    cout << ans << "\n";
}

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

using namespace std;

int main(){

    long long x, y;
    cin >> x >> y;

    long long ans = log2( (long double) y / x);
    cout << ans + 1 << endl;
    

}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int i=0,x,m,n=0;
	cin>>x>>m;
	x=x-1;
	int j=m;
	int s=(2*x)-1;
	int h[s];
	for(i=0;i<x;i++){
		j--;
		h[n]=j;
		n++;
		}
	j=m;
	h[n]=j;
	n++;
	for(i=0;i<x;i++){
		j++;
        h[n]=j;
        n++;
	}
	int k=n;
    sort(h,h+k);
	for(i=0;i<n;i++)
        cout<<h[i]<<" " ;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int MOD = 1000000007;
const int MAX_N = 100010;

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

vector<P> data[MAX_N];
P ans[MAX_N];

int main(){
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; i++){
        int p, y;
        cin >> p >> y;
        data[p].push_back(P(y, i));
    }

    for (int i = 1; i <= n; i++){
        sort(data[i].begin(), data[i].end());
        for (int j = 0; j < data[i].size(); j++){
            ans[data[i][j].second] = P(i, j + 1);
        }
    }

    for (int i = 0; i < m; i++){
        cout << setw(6) << setfill('0') << ans[i].first;
        cout << setw(6) << setfill('0') << ans[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 7808
package main

import "fmt"

func main() {
	var x, y int
	fmt.Scan(&x, &y)
	g := []int{0, 1, 3, 1, 2, 1, 2, 1, 1, 2, 1, 2, 1}
	if g[x] == g[y] {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>


int main() {
    int x, y, x0, y0, x1, y1, x2, y2, x3, y3;
    int q;
    double t, num, denom, vx, vy;
    int judge;

    scanf("%d", &q);
    
    while (q--) {
        scanf("%d %d %d %d %d %d %d %d",
              &x0, &y0, &x1, &y1, &x2, &y2, &x3, &y3);
        vx = x1 - x0;
        vy = y1 - y0;
        num = (y3-y2)*(x2-x0)-(x3-x2)*(y2-y0);
        denom = (x1-x0)*(y3-y2) - (y1-y0)*(x3-x2);
        t = num / denom;

        printf("%.10f %.10f\n", vx * t + x0, vy * t + y0);
    }

    return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
const int N = 100 + 5, NW = 1e5 + 5;
int val[N], wts[N];
long long dp[N][NW];
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(NULL);
	int n,w;
	cin>>n>>w;
	for(int i = 1; i <= n; ++i){
		cin>>wts[i]>>val[i];
	}
	for(int i = 0; i <= n; ++i){
		for(int j = 0; j <= w; ++j){
			if(i == 0 || j == 0)
				dp[i][j] = 0;
			else if(j - wts[i] >= 0)
				dp[i][j] = max(val[i] + dp[i-1][j - wts[i]], dp[i-1][j]);
			else
				dp[i][j] = dp[i-1][j];
		}
	}
	cout<<dp[n][w]<<endl;
}

Measured memory_bytes: 80128
import java.util.Scanner;
import java.util.Arrays;

class Main{
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      String A = sc.nextLine();
      String[] max = A.split(" ");
      

      int a = Integer.parseInt(max[0]);
      int b = Integer.parseInt(max[1]);
      int c = Integer.parseInt(max[2]);

      if (a < b && b < c){
        System.out.println("Yes");
      }else 
        System.out.println("No");
  }
}

Measured memory_bytes: 26012
let a,b,n = Scanf.sscanf (read_line()) "%f %f %f" (fun a b n ->a,b,n
)

let x = (if b > n then n else b -. 1.)
let _ = Printf.printf "%d\n" ((int_of_float (a *. x /. b)) - (int_of_float a) * (int_of_float @@ x /. b))


Measured memory_bytes: 3876
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#include <tuple>
#include <cassert>
#include <functional>
#include <set>
#include <deque>
#include <list>
using namespace std;
typedef long long ll;
int dx[4] = {0,0,1,-1};
int dy[4] = {1,-1,0,0};
#define LNF __LONG_LONG_MAX__
const ll MOD = 1000000007;
const int MAX = 200000;

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

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

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
// 法mでのaの逆元を計算
long long modinv(long long a, long long m) {
    long long b = m, u = 1, v = 0;
    while (b) {
        long long t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}
// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
//最大公約数
long long gcd(long long x, long long y){
    if(y==0) return x;
    else return gcd(y,x%y);
}
//最小公倍数
long long lcm(long long x, long long y){
    return x / gcd(x, y) * y;
}
// nが大きく,kが10^7程度の時の二項係数
long long com[200005];
void combination(long long n,long long k){
    com[0] = 1;
    for(int i=1;i<=k;i++){
        com[i] = (com[i-1]*(n-i+1)%MOD)*modinv(i,MOD)%MOD;
    }
}

int main(){
    int H,W; cin >> H >> W;
    vector<string> S(H);
    for(int i=0;i<H;i++){
        cin >> S[i];
    }
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(S[i][j]=='#'){
                cout << "#";
                continue;
            }
            int out=0;
            for(int a=-1;a<=1;a++){
                int y=i+a;
                for(int b=-1;b<=1;b++){
                    int x=j+b;
                    if(y<0 || y>=H || x<0 || x>=W) continue;
                    if(S[y][x]=='#') out++;
                }
            }
            cout << out;
        }
        cout << "\n";
    }
    return 0;
}


Measured memory_bytes: 3628
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))

total = 0
for i in range(N):
    if A[i] != 0:
        if A[i] <= B[i]:
            total += A[i]
            B[i] -= A[i]
            A[i] = 0
        else:
            total += B[i]
            A[i] -= B[i]
            B[i] = 0
    if B[i] != 0:
        if A[i+1] <= B[i]:
            total += A[i+1]
            B[i] -= A[i+1]
            A[i+1] = 0
        else:
            total += B[i]
            A[i+1] -= B[i]
            B[i] = 0

print(total)

Measured memory_bytes: 24336
class UnionFind:
    __slots__ = ["_data_size", "_roots"]
 
    def __init__(self, data_size: int) -> None:
        self._data_size = data_size
        self._roots = [-1] * data_size
 
    def __getitem__(self, x: int) -> int:
        while self._roots[x] >= 0:
            x = self._roots[x]
        return x
 
    def is_connected(self, x: int, y: int) -> bool:
        return self[x] == self[y]
 
    def unite(self, x: int, y: int) -> None:
        x, y = self[x], self[y]
        if x == y:
            return
        if self._roots[x] > self._roots[y]:
            x, y = y, x
        self._roots[x] += self._roots[y]
        self._roots[y] = x
 
 
import sys
 
readline = sys.stdin.readline
 
N, Q = map(int, readline().split())
tree = UnionFind(N)
res = []
ans=0
for _ in range(Q):
  u, v = map(int, readline().split())
  tree.unite(u-1, v-1)
for u in range(1,N):
  if not tree.is_connected(u, 0):
      ans+=1
      tree.unite(u, 0)
print(ans)


Measured memory_bytes: 70392
N = int(input())
ABlist = []
for i in range(N):
    c = list(map(int, input().split(" ")))
    ABlist.append(c)

ABlist = sorted(ABlist, reverse = True)
ABlist = sorted(ABlist, key = lambda x :x[1])

#print(ABlist)
ans = "Yes"
k = 0
for j in range(N):
    k += ABlist[j][0]
    if k > ABlist[j][1]:
        ans = "No"
        break
print(ans)

Measured memory_bytes: 54976
import math

n, m = map(int, input().split(" "))
lrL = [list(map(int, input().split(" "))) for _ in range(m)]

_left, _right = 1, n

for l, r in lrL:
    _left = max(_left, l)
    _right = min(_right, r)

print(max(0, _right - _left + 1))


Measured memory_bytes: 27404
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n; string s;
    cin >> n >> s;
    int ans = 0;
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            for (int k = 0; k < 10; ++k) {
                int ok = 0;
                for (int x = 0; x < n; ++x) {
                    if(ok == 0){
                        if(s[x]-'0' == i) ok++;
                    }else if(ok == 1){
                        if(s[x]-'0' == j) ok++;
                    }else if(ok == 2){
                        if(s[x]-'0' == k) ok++;
                    }else break;
                }
                if(ok == 3) ans++;
            }
        }
    }
    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <fstream>
#include <algorithm>
#include <cmath>
using namespace std;

int main()
{
    int input, a, b, c, d;
    cin >> input;
    a = input / 1000;
    b = input / 100 % 10;
    c = input / 10 % 10;
    d = input % 10;

    for (int bits = 0b000; bits < 0b1000; bits++)
    {
        bool op1 = (bits & 0b001);
        bool op2 = (bits & 0b010);
        bool op3 = (bits & 0b100);
        int ans = a;
        ans += op1 ? b : -b;
        ans += op2 ? c : -c;
        ans += op3 ? d : -d;
        if (ans == 7)
        {
            printf("%d%c%d%c%d%c%d=7\n",
                         a, op1 ? '+' : '-', 
                         b, op2 ? '+' : '-',
                         c, op3 ? '+' : '-', d);
            break;
        }
    }
    return 0;    
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
	int n;
	double arr = 0;
	cin >> n;
	while (n--) {
		double x;
		string mon;
		cin >> x >> mon;
		if (mon == "JPY") {
			arr += x;
		}
		else if (mon == "BTC") {
			arr += 380000 * x;
		}
	}
	cout << arr << endl;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;

public class Main {
	static BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter pw = new PrintWriter(new BufferedWriter(new OutputStreamWriter(System.out)));
	
	public static void main(String[] args) throws Exception {
		int N = Integer.parseInt(br.readLine());
		
		long[] yarra = new long[N];
		String[] split = br.readLine().split(" ");
		
		for(int i = 0; i < yarra.length; i++)
			yarra[i] = Long.parseLong(split[i]) - i - 1;
		
		Arrays.sort(yarra);
		
		long left = yarra[0] - 1, right = yarra[N-1] + 1;
		long mid = -1;
		
		while(right - left >= 2) {
			mid = (left + right)/2;
			long val = 0;
			long val2 = 0;
			for(int i = 0; i < yarra.length; i++) {
				val += (long) Math.abs(yarra[i] - mid);
				val2 += (long) Math.abs(yarra[i] - (mid-1));
			}
			
			if(val2 < val)
				right = mid;
			else
				left = mid;
		}
		
		long val = 0;
		long val2 = 0;
		long val3 = 0;
		
		for(int i = 0; i < yarra.length; i++) {
			val += (long) Math.abs(yarra[i] - left);
			val2 += (long) Math.abs(yarra[i] - mid);
			val3 += (long) Math.abs(yarra[i] - right);
		}
		pw.println(Math.min(val, Math.min(val2, val3)));
		
		pw.close();
	}
}







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

using namespace std;
typedef long long ll;

inline int at(ll x, int k){ return (x >> k) & 1; }
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)


int main() {
	int n,k;
	cin >> n>>k;
	int a[n];
	rep(i,0,n){
		a[i]=0;
	}
	rep(i,0,k){
		int d;
		cin >> d;
		rep(j,0,d){
			int temp;
			cin >> temp;
			a[temp-1]=1;
		}
	}

	int ans =0;
	rep(i,0,n){
		if(a[i]==0){
			ans++;
		}
	}

		cout << ans << endl;




}


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

int main()
{
  ll x,k;
  cin>>x>>k;
  ll q=x/k;
  ll res=x-(q*k);
  res=min(res, k-res);
  cout<<res;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1e9+7;
const int N= 100100;
int n , k , x[N] , ans = 1<<30;


int main(){

scanf("%d %d",&n,&k);
for(int i=1;i<=n;i++)scanf("%d",x+i);

int cnt=0;
for(int i=1;i<=n;i++){
    if( x[i] >= 0 )cnt++;
    if( cnt > k )break;

    if( cnt && i - cnt >= k-cnt ){
        if( cnt == k )ans=min( ans , x[i] );
        else ans=min( ans , x[i]+x[i]-x[i-k+1] );
    }

}

for(int i=1;i<=n;i++)x[i]=-x[i];
reverse(x+1,x+1+n);

cnt=0;
for(int i=1;i<=n;i++){
    if( x[i] >= 0 )cnt++;
    if( cnt > k )break;

    if( cnt && i - cnt >= k-cnt ){
        if( cnt == k )ans=min( ans , x[i] );
        else ans=min( ans , x[i]+x[i]-x[i-k+1] );
    }

}
printf("%d\n",ans);

return 0;
}


Measured memory_bytes: 640
import sys
from bisect import bisect_left


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)


def main():
    A, B, Q = map(int, input().split())
    S = [int(input()) for _ in range(A)]
    T = [int(input()) for _ in range(B)]

    for i in range(Q):
        x = int(input())
        s_index = bisect_left(S, x)
        if s_index == 0:
            S1 = S[s_index]
            S2 = S[s_index]
        elif s_index == A:
            S1 = S[s_index - 1]
            S2 = S[s_index - 1]
        else:
            S1 = S[s_index]
            S2 = S[s_index - 1]

        t_index = bisect_left(T, x)
        if t_index == 0:
            T1 = T[t_index]
            T2 = T[t_index]
        elif t_index == B:
            T1 = T[t_index - 1]
            T2 = T[t_index - 1]
        else:
            T1 = T[t_index]
            T2 = T[t_index - 1]
        answer = float("inf")
        for s in [S1, S2]:
            for t in [T1, T2]:
                r = min(abs(x - s) + abs(t - s), abs(x - t) + abs(t - s))
                if answer > r:
                    answer = r
        print(answer)


if __name__ == "__main__":
    main()


Measured memory_bytes: 12260
r, g, b, n = map(int, input().split())

ans = 0
for i in range(int(n / r) + 1):
    for j in range(int(n / g) + 1):
        k = (n - r * i - g * j) / b
        if (k == int(k)) and (k >= 0):
            ans += 1

print(ans)


Measured memory_bytes: 40940
#include <cstdio>

int main(void)
{
    int a, b;
    bool flag, first = false;
    
    while (1){
        scanf("%d %d", &a, &b);
        if (a == 0 && b == 0) break;
        
        if (first) printf("\n");
        else first = true;
        
        flag = false;
        
        while (a <= b){
            if (a % 4 == 0 && (a % 100 != 0 || a % 400 == 0)){
                printf("%d\n", a);
                flag = true;
            }
            a++;
        }
        if (!flag) printf("NA\n");
    }
    
    return (0);
}

Measured memory_bytes: 0