akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}

int main() {
 int N;
 cin >> N;
 bool flag = false;
 for(int i = 1;i<=9;i++){
	 int c = N/i;
	 if(N%i == 0 && c>=1 && c<=9) flag = true;
 }
 if(flag) cout << "Yes" <<endl;
 else cout << "No" <<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int N, K, A[200001], B[200001], C[200001];
	int i, j, k, l, m;
	
	
	/////////////////////////
	// Scan the imput:
	scanf("%d %d",&N,&K);
	
	for (i=1;i<=N;i++){
		scanf("%d",&A[i]);
	}
	////////////////////////
	
	
	///////////////////////////
	// Sort the numbers:
	// B[j] is the number of appearances of the number j.
	for (j=1;j<=N;j++){
		B[j]=0; // :initaly, everything is zero.
	} 
	
	for (i=1;i<=N;i++){
		B[A[i]]=B[A[i]]+1; // If the i-th number is A[i], we are increasing the counter by 1.
	}
	///////////////////////////
	
	
	//////////////////////////////////////////
	// Now, we sort B[j]'s. We count which values of B[j] appeared how many times.
	for (j=1;j<=N;j++){C[j]=0; }
	
	for (j=1;j<=N;j++){
		C[B[j]]=C[B[j]]+1;
	}
	//for (j=1;j<=N;j++){printf("%d\n",C[j]);}
	/////////////////////////////////////////
	
	//////////////////////////////
	// L is the number of different numbers.
	int L=0;
	for (j=1;j<=N;j++){
		L=L+C[j];
	} 
	if (L<=K){printf("0"); return 0;}
	//////////////////////////////
			
			
			
	////////////////////////////////
	// Now we remove some numbers:
	int answ=0;
	for (j=1;j<=N;j++){ //printf("\n%d",answ);
		if (K+C[j]<L){ L=L-C[j];
			answ=answ+j*C[j];
		}
		else {answ=answ+j*(L-K); j=N+1; }
	}
	////////////////////////////////
	
	printf("%d",answ);
	return 0;
}



Measured memory_bytes: 2560
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin >> n;
    int wynik = 0;
    char* a = new char [n];

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

    }
    for (int i = 0;i<n; i++)
    {
        if (a[i]=='G')
        {
            wynik++;
            break;
        }
    }
    for (int i = 0;i<n; i++)
    {
        if (a[i]=='P')
        {
            wynik++;
            break;
        }
    }
    for (int i = 0;i<n; i++)
    {
        if (a[i]=='W')
        {
            wynik++;
            break;
        }
    }
    for (int i = 0;i<n; i++)
    {
        if (a[i]=='Y')
        {
            wynik++;
            break;
        }
    }
    if (wynik == 3)
        cout << "Three";
    else
        cout << "Four";

    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int64_t> L(N+1);
  L.at(0) = 2;
  L.at(1) = 1;
  for (int i = 2; i < N + 1; i++) {
    L.at(i) = L.at(i-1) + L.at(i-2);
  }
  
  cout << L.at(N) << endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, l: "List[int]", r: "List[int]"):
    print(sum(ri - li + 1 for li, ri in zip(l, r)))


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    l = [int()] * (N)  # type: "List[int]"
    r = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        l[i] = int(next(tokens))
        r[i] = int(next(tokens))
    solve(N, l, r)


if __name__ == '__main__':
    main()


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

namespace Competition
{
    class Program
    {
        static void Main(string[] args)
        {
            var nd = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            var N = nd[0]; var D = nd[1];

            var p = 0;
            var res = N/(2*D+1);
            if (N % (2 * D + 1) == 0) Console.WriteLine(res);
            else Console.WriteLine(res + 1);
        }
    }
}


Measured memory_bytes: 13396
def update_vrs(vrs, idx, s):
    if idx == 0:
        vrs[s[0]] += 1
        vrs[s[1]] -= 1
    elif idx == 1:
        vrs[s[0]] -= 1
        vrs[s[1]] += 1
    else:
        raise ValueError()


def process1(vrs, lst_s):
    selects = []
    for s in lst_s:
        if vrs[s[0]] == 0 and vrs[s[1]] == 0:
            return False, None
        elif vrs[s[0]] == 0:
            selects.append(s[0])
            update_vrs(vrs, 0, s)
        else:  # when vrs[s[1]] == 1:
            selects.append(s[1])
            update_vrs(vrs, 1, s)
    return True, selects


def process2(vrs, lst_s):
    selects = []
    for i, s in enumerate(lst_s):
        if vrs[s[0]] == 0 and vrs[s[1]] == 0:
            return False, None
        elif vrs[s[0]] == 0:
            selects.append(s[0])
            update_vrs(vrs, 0, s)
        elif vrs[s[1]] == 0:
            selects.append(s[1])
            update_vrs(vrs, 1, s)
        else:
            if i == len(lst_s) - 1:
                selects.append(s[0])
            else:
                next_s = lst_s[i + 1]
                if s[0] in next_s:
                    selects.append(s[0])
                    update_vrs(vrs, 0, s)
                else:
                    selects.append(s[1])
                    update_vrs(vrs, 1, s)
    return True, selects


def main():
    vrs = {}
    n, vrs['A'], vrs['B'], vrs['C'] = [int(v) for v in input().split(' ')]
    lst_s = []
    for _ in range(n):
        lst_s.append(input().strip())

    sum_abc = vrs['A'] + vrs['B'] + vrs['C']

    if sum_abc == 0:
        ans = False
    elif sum_abc == 1:
        ans, selects = process1(vrs, lst_s)
    else:
        ans, selects = process2(vrs, lst_s)

    if ans is True:
        print('Yes')
        for s in selects:
            print(s)
    else:
        print('No')


if __name__ == '__main__':
    main()


Measured memory_bytes: 85804
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<map>
#include<cmath>
#include<iomanip>
#include<set>
#include<numeric>
#include<random>
#include<cstdio>
#include<climits>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; ++i)
#define rrep(i, st, n) for (int i = st; i < n; ++i)
using pii = pair<int, int>;
//const int inf = 1e9 + 7;
//int dy[] = {0, 0, -1, 1};
//int dx[] = {1, -1, 0, 0};

int main() {
    int N, W; cin >> N >> W;
    int kn[W + 1]; rep(i, W + 1) kn[i] = 0;
    rep(i, N) {
        int v, w; cin >> v >> w;
        rep(j, W + 1) {
            if (j + w <= W) {
                kn[j + w] = max(kn[j + w], kn[j] + v);
            }
        }
        int jj = 1;
        while (1) {
            if (jj * w >= W + 1) break;
            kn[jj * w] = max(kn[jj * w], jj * v);
            ++jj;
            
        }
        
    }
    int mmax = 0;
    rep(i, W + 1) {
        mmax = max(mmax, kn[i]);
    }
    cout << mmax << endl;
}



Measured memory_bytes: 3116
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef pair<pii,pii> P;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
typedef vector<vector<ll>> mat;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<62;
double pi=3.141592653589793238462643383279L;
double eps=1e-14;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define mrep(itr,mp) for(auto& itr:mp)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define umh unordered_map<ll,ll,custom_hash>
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll lcm(ll a,ll b){
    ll c=gcd(a,b);
    return a*b/c;
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
    now%=md;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
ll n,L;
string s[100000];
vector<ll> v;
void dfs(ll l,ll r,ll d){
    if(r-l==0){
        v.push_back(L-d+1);
        return;
    }
    if(d==s[l].size())return;
    ll div=l;
    while(div<r&&s[div][d]=='0')div++;
    dfs(l,div,d+1);
    dfs(div,r,d+1);
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);
    cin>>n>>L;
    rep(i,0,n)cin>>s[i];
    sort(s,s+n);
    dfs(0,n,0);
    ll ans=0;
    rep(i,0,v.size()){
        ll cnt=1;
        //cout<<v[i]<<" ";
        while(v[i]%2==0){
            v[i]/=2;
            cnt*=2;
        }
        ans^=cnt;
    }
    if(ans==0)cout<<"Bob"<<endl;
    else cout<<"Alice"<<endl;
}



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

using ll = long long;

#define for_(i, a, b) for(int i = (a);i < (b);++i)
#define rfor_(i, a, b) for(int i = (b)-1;i >= (a);--i)
#define rep(i, n) for_(i, 0, n)
#define rrep(i, n) rfor_(i, 0, n)

int N, K;

ll x[100005];

ll m;

ll d(int i) {
	return x[i+K-1] - x[i] + min( abs(x[i]), abs(x[i+K-1]) );
}

int main() {
  cin.tie(0);cout.tie(0);
  ios_base::sync_with_stdio(false);
  
  cin>>N>>K;
  rep(i, N)cin>>x[i];
  
  m = d(0);
  rep(i, N-K+1)m = min(m , d(i));
  
  cout<<m<<endl;

  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ll long long
#define ld long double
#define all(a) a.begin(),a.end()
#define endl '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ull unsigned long long
#define int long long
#define iter vector<int>::iterator
using namespace std;
using namespace __gnu_pbds;

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

template<class T>
using ordered_multiset=tree<T,null_type,less_equal<T>,rb_tree_tag,tree_order_statistics_node_update>;

mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rnd1(chrono::steady_clock::now().time_since_epoch().count());

//find_by_order
//order_of_key

const int N=2e5+7;
const int inf=1e18+5;
const int mod=2520;

main ()
{
    ios;
    int a,b;
    cin>>a>>b;
    int mx=max(a+b,max(a*b,a-b));
    cout<<mx<<endl;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;

int main()
{
    int w, h, n;
    cin >> w >> h >> n;

    vector<vector<bool> > v(h, vector<bool>(w, true));
    for(int i=0; i<n; ++i){
        int x, y, a;
        cin >> x >> y >> a;

        int x1 = 0;
        int x2 = w;
        int y1 = 0;
        int y2 = h;
        if(a == 1)
            x2 = x;
        else if(a == 2)
            x1 = x;
        else if(a == 3)
            y2 = y;
        else
            y1 = y;

        for(int i=y1; i<y2; ++i){
            for(int j=x1; j<x2; ++j){
                v[i][j] = false;
            }
        }
    }

    int ans = 0;
    for(int i=0; i<h; ++i){
        for(int j=0; j<w; ++j){
            if(v[i][j])
                ++ ans;
        }
    }
    cout << ans << endl;

    return 0;
}

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

#define MAX 110000


pair<int,int> ab[MAX], ab2[MAX];
int used[MAX];

int main(){
	int N, M;
	
	cin>>N>>M;
	
	for(int i = 0; i < M; i++){
		cin>>ab[i].first>>ab2[i].first;
		ab[i].second = i;
		ab2[i].second = i;
	}
	
	sort(ab,ab+M);
	sort(ab2,ab2+M);
	
	int l = 0, ans = 0;
	
	for(int i = 0,j = 0; i < M; i++){
		bool flag = false;
		if(used[ab2[i].second]) continue;
		l = ab2[i].first-1;
		// cout<<i<<"+++++"<<l<<endl;
		for(; j < M; j++){
			if(l < ab[j].first){
				break;
			}
			// cout<<i<<" "<<l<<" "<<ab[j].first<<endl;
			flag = true;
			used[ab[j].second] = true;
		}
		if(flag) ans++;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 2304
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

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

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a

# Union Find
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())

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

    divisors.sort()
    return divisors


inf = 10 ** 18
mod = 10 ** 9 + 7

n,a,b = lr()
print(min(a,b), max(0,a+b-n))





Measured memory_bytes: 77380
#pragma GCC optimize("O3")

#include "bits/stdc++.h"

using namespace std;

typedef long long ll;
typedef pair<int, int> pi;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define F0R(i, a) for(int i = 0; i < (a); ++i)
#define pb push_back
#define sz(x) (int)x.size()
#define f first
#define s second

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

    int a,b,c;
    cin >> a >> b >> c;
    if(a+b+c>=22)
        cout << "bust";
    else
        cout << "win";

    return 0;
}


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

using namespace std;

#define repd(i,a,b) for (int i=(a);i<(b);++i)
#define rep(i,n) repd(i,0,n)
typedef long long ll;


int main(){
  int n;
  cin >> n;
  priority_queue<int> que;
  rep(i, n){
    int a;
    cin >> a;
    que.push(a);
  }
  int ans = 0;
  while(!que.empty()){
    int a = que.top(); que.pop();
    if(que.empty()){
      ans+=a;
      break;
    }
    int b = que.top(); que.pop();
    ans += a - b;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod 1000000007
#define INF 10000000000000001
#define F first
//#define S second
#define LB lower_bound
#define UB upper_bound
#define vc vector
#define vll vector<long long>
#define pll pair<long long,long long>
#define pb push_back
#define all(v) v.begin(),v.end()
#define T ll test;cin>>test; while(test--)
#define rep(i,a,n) for(ll i=a;i<(long long)n;++i)
#define repr(i,n,a) for(ll i=n;i>(long long)a;--i)
#define MAX 100005
#define sz(x) (ll)x.size()
#define ins insert
#define mp make_pair
#define int  long long
typedef unsigned long long ll;
typedef long double ld;
using namespace std;
int nCrModp(int n, int r, int p) 
{ 
    if (r > n - r) 
        r = n - r; 
    int C[r + 1]; 
    memset(C, 0, sizeof(C)); 
  
    C[0] = 1;  
    for (int i = 1; i <= n; i++) {  
        for (int j = min(i, r); j > 0; j--) 
            C[j] = (C[j] + C[j - 1]) % p; 
    } 
    return C[r]; 
} 
int power(int x, unsigned int y, int p)  
{  
    int res = 1;     
  
    x = x % p;  
   
    if (x == 0) return 0; 
  
    while (y > 0)  
    {  

        if (y & 1)  
            res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}  

signed  main()
{
	ios_base::sync_with_stdio(false);cin.tie(NULL);
	ll n;
	cin>>n;
	if(n==1) {
		cout<<0<<endl;
		return 0;
	}
	ll res=((power(10,n,mod)-(2*power(9,n,mod))%mod+mod)+power(8,n,mod))%mod;
	cout<<res<<endl;
}

Measured memory_bytes: 3648
//============================================================================
// Name        : AOJ.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
using namespace std;

int main() {
	int c1,c5,c10,c50,c100,c500;
	cin>>c1>>c5>>c10>>c50>>c100>>c500;

	if((c1+c5*5+c10*10+c50*50+c100*100+c500*500)>=1000)cout<<1<<endl;
	else cout<<0<<endl;


	return 0;
}

Measured memory_bytes: 3096
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
#define ll long long int
ll gcd(ll a, ll b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}

ll lcm(ll a, ll b)
{
   return a * b / gcd(a, b);
}
int main(){
  ll A,B,C,D;
  cin>>A>>B>>C>>D;
  ll ans,E,count=0;

  
  E = lcm(C,D);
  ans=(B-A+1)-(((B/C)-((A-1)/C))+((B/D)-((A-1)/D))-((B/E)-((A-1)/E)));
  cout<<ans<<endl;
  /* for(int i=10;i<41;i++){
    if(i%6!=0&&i%8!=0){
      cout<<i<<endl;
    count++;
    }}
    cout<<count;*/

  return 0;
}


Measured memory_bytes: 256
//To debug :  g++ -g file.cpp -o code
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,n) for(i=a;i<n;++i)
#define irep(i,n,a) for(i=n;i>a;--i)
#define mod 1000000007
#define pb push_back
#define big 9223372036854775807;
#define big1 LONG_MAX
#define big2 INT_MAX
#define big3 1000000000
#define sma1 LONG_MIN
#define sma2 INT_MIN
#define sma3 -1000000000;
#define mp make_pair
#define mt make_tuple
#define dub double
#define ivec vector<int>
#define lvec vector<long long>
#define cvec vector<char>
#define svec vector<string>
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);

int main()
{
	FAST

	int n,i,val;

	cin>>n;

	int a[n+1]={0},b[n+1]={0},c[n+1]={0};

	int aa[n+1]={0},ab[n+1]={0},ac[n+1]={0};

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


	for(i=1;i<=n;++i)
	{
		val = max(max(aa[i-1],ab[i-1]),ac[i-1]);
		aa[i] = a[i] + max(ab[i-1],ac[i-1]);
		ab[i] = b[i] + max(aa[i-1],ac[i-1]);
		ac[i] = c[i] + max(aa[i-1],ab[i-1]);
	}


	val = max(max(aa[n],ab[n]),ac[n]);


	cout<<val<<"\n";



	return 0;
}

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

int main(){

  int n;

  while(cin >> n){

    int z = 512,a[100] = {0},count = 0,count2 = 0;

    for(int i=10;i>0;i--){

      if(n - z >= 0){
	n -= z;
	a[i] = z;
	count++;
      }
      z /= 2;
    }

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

      if(a[i] != 0){
	cout << a[i];
	count2++;

	if(count2 == count) break;
	cout << " ";

      }
    }

    cout << endl;

  }
}

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

cnt = 0
cnt_BA = 0
cnt_A = 0
cnt_B = 0

for i in range(N) : 
    tmp = (input())
    cnt += tmp.count("AB")
    tmp = tmp[0] +tmp[-1]
    if tmp == "BA" : 
        cnt_BA += 1
    if tmp[-1] == "A" : 
        cnt_A += 1
    if tmp[0] == "B" : 
        cnt_B += 1
    
m = min(cnt_A, cnt_B)

if cnt_BA == cnt_A and cnt_BA == cnt_B and cnt_BA != 0 : 
    print(m-1+cnt)
else : 
    print(m+cnt)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
using namespace std;
using ll = long long;
const int INF = +100100100;
typedef pair<ll,ll> P;
const ll MO = 1000000007;

struct Item{
    ll w,v;
    // Item(ll x,ll y){
    //     w = x; v = y;
    // }
};

int main(){
    ll n,W;
    cin >> n >> W;
    vector<Item> c(n);
    rep(i,n){
        ll w,v;
        cin >> w >> v;
        c[i].w = w; c[i].v = v;
    }
    vector<vector<ll>> dp(n+5,vector<ll>(W+5));
    rep(i,W+5)dp[0][i] =0;
    rep(i,n+5)dp[i][0] = 0;
    rrep(i,n){
        rrep(j,W){
            if(j-c[i-1].w<0)dp[i][j] = dp[i-1][j];
            else dp[i][j] = max(dp[i-1][j-c[i-1].w]+c[i-1].v,dp[i-1][j]);
        }
    }
    cout << dp[n][W] << endl;
    return 0;
}

Measured memory_bytes: 83328
#include<bits/stdc++.h>
#define LL long long
#define Max 100005
const LL mod=1e9+7;
const LL LL_MAX=9223372036854775807;
using namespace std;
int main()
{
    int a[5]={0,1,2,3,4};
    int b[5];
    for(int i=0;i<5;i++)
    scanf("%d",&b[i]);
    int ans=INT_MAX;
    int sum=0;
    while(next_permutation(a,a+5)){
        sum=0;
        for(int i=0;i<4;i++)
        {
            sum+=((b[a[i]]+9)/10)*10;
           // printf("%d %d\n",a[i],b[a[i]]);
        }
        sum+=(b[a[4]]);

        ans=min(sum,ans);
    }
    printf("%d\n",ans);
    return 0;
}


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

import static java.lang.Math.*;
import static java.util.Arrays.*;

// Popularity Estimation
// 2012/12/04
public class Main{
	Scanner sc=new Scanner(System.in);

	int INF=1<<28;

	void run(){
		for(;;){
			int n=sc.nextInt();
			if(n==0){
				break;
			}
			String[] names=new String[n];
			int[][] g=new int[30][n];
			for(int j=0; j<n; j++){
				names[j]=sc.next();
				int m=sc.nextInt();
				for(int i=0; i<m; i++){
					int d=sc.nextInt();
					g[d][j]=1;
				}
			}
			int[] ps=new int[n];
			for(int j=0; j<30; j++){
				int k=0;
				for(int i=0; i<n; i++){
					k+=g[j][i];
				}
				for(int i=0; i<n; i++){
					ps[i]+=g[j][i]*(n+1-k);
				}
			}
			String name="";
			int min=INF;
			for(int i=0; i<n; i++){
				if(ps[i]<min){
					name=names[i];
					min=ps[i];
				}else if(ps[i]==min){
					if(names[i].compareTo(name)<0){
						name=names[i];
					}
				}
			}
			println(min+" "+name);
		}
	}

	void println(String s){
		System.out.println(s);
	}

	public static void main(String[] args){
		new Main().run();
	}
}

Measured memory_bytes: 12000
x, k, d = gets.split(" ").map(&:to_i)
if x.abs >= k * d
  puts x.abs - (k * d)
  exit
end
xx=0
yy=1
flag=false
before_0 = x / d 
if (k - before_0) % 2 == 0
  puts (x - (before_0 * d)).abs
  flag=true
  yy+=1
else (k - before_0) % 2 != 0
  puts  (x - (before_0 * d) - d).abs
  flag=false
  xx+=1
end 

Measured memory_bytes: 14316
use std::io::Read;

fn run() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).unwrap();
    let mut it = s.trim().split_whitespace();
    let n: usize = it.next().unwrap().parse().unwrap();
    let mut g = vec![vec![]; n];
    for _ in 1..n {
        let a: usize = it.next().unwrap().parse().unwrap();
        let b: usize = it.next().unwrap().parse().unwrap();
        g[a - 1].push(b - 1);
        g[b - 1].push(a - 1);
    }
    let mut q = vec![];
    let mut parent = vec![0; n];
    let mut depth = vec![0; n];
    let mut stack = vec![0];
    while let Some(v) = stack.pop() {
        q.push(v);
        if let Some(k) = g[v].iter().position(|u| *u == parent[v]) {
            g[v].swap_remove(k);
        }
        for &u in g[v].iter() {
            parent[u] = v;
            depth[u] = depth[v] + 1;
            stack.push(u);
        }
    }
    let m: usize = it.next().unwrap().parse().unwrap();
    let mut cond = vec![];
    for _ in 0..m {
        let a: usize = it.next().unwrap().parse().unwrap();
        let b: usize = it.next().unwrap().parse().unwrap();
        let mut x = a - 1;
        let mut y = b - 1;
        while x != y {
            if depth[x] <= depth[y] {
                y = parent[y];
            } else {
                x = parent[x];
            }
        }
        cond.push((a - 1, b - 1, x));
    }
    let mut ans = 0i64;
    for i in 0..(1usize << m) {
        let mut imos = vec![0i32; n];
        let mut sign = 1;
        for (j, &(a, b, c)) in cond.iter().enumerate() {
            if (i >> j) & 1 == 1 {
                sign *= -1;
                imos[a] += 1;
                imos[b] += 1;
                imos[c] -= 2;
            }
        }
        let mut c = 0;
        for &v in q[1..].iter().rev() {
            if imos[v] == 0 {
                c += 1;
            }
            imos[parent[v]] += imos[v];
        }
        ans += sign * (1 << c);
    }
    println!("{}", ans);
}

fn main() {
    run();
}


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

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

using ll = long long;
using P = pair<int,int>;
using graph = vector<vector<int>>;

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const ll INF = 1LL<<60;
const ll mod = 1000000007LL;

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

int main() {
  int H,W;
  cin>>H>>W;
  vector<string> v(H);
  rep(i,H) cin>>v[i];
  int cnta = 0, cntb = 0;
  rep(i,H){
    rep(j,W) {
      if(v[i][j]=='.') cnta++;
      else cntb++;
    }
  }
  queue<P> q;
  q.push(make_pair(0,0));
  vector<vector<bool>> seen(H,vector<bool>(W,false));
  seen[0][0] = true;
  graph g(H,vector<int>(W,-1));
  g[0][0] = 0;
  while(!q.empty()){
    P p = q.front();
    q.pop();
    rep(i,4){
      int nx = p.first+dx[i];
      int ny = p.second+dy[i];
      if(nx<0||nx>=H||ny<0||ny>=W) continue;
      if(seen[nx][ny]) continue;
      if(v[nx][ny]=='#') continue;
      seen[nx][ny] = true;
      g[nx][ny] = g[p.first][p.second]+1;
      q.push(make_pair(nx,ny));
    }
  }
  if(g[H-1][W-1]==-1) cout<<g[H-1][W-1]<<endl;
  else cout<<H*W-g[H-1][W-1]-cntb-1<<endl;
}

Measured memory_bytes: 3628
#include <stdio.h>

int main(void)
{
        int a,b,i,k;

        scanf("%d%d%d",&k,&a,&b);

        for(i=a;i<b+1;i++){
                if(i%k==0){
                        printf("OK");
                        return 0;
                }
        }

        printf("NG");
        return 0;
}


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

int main () {
  int a,b;
  cin >> a >> b;
  
  if (a * b % 2 == 0 ) {
    cout << "Even" << endl;
  }
  if (a * b % 2 != 0) {
    cout << "Odd" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fastIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0)
#define endl '\n'
#define ft first
#define sd second
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<char, char> pcc;
typedef pair<double, double> pdd;
typedef pair<long long, long long> pll;
// scanf("%d %d %d %d", &w, &b, &d, &s); %lld
// printf("%d\n", points);
// const double PI = acos(-1);

int main()
{
    #ifdef LOCAL
    freopen("in.txt", "r", stdin);
    // freopen("out.txt", "w", stdout);
    #else
        fastIO;
    #endif
    int n, m, ans;
    cin >> n >> m;
    n--, m--;
    ans = ((n*n+n)/2)+ ((m*m+m)/2);
    cout << ans << endl;
        return 0;

}

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

class union_find {
public:
    union_find(int n) : par(n, -1) {}
    int root(int x) { return par[x] < 0 ? x : par[x] = root(par[x]); }
    bool same(int x, int y) {
        return root(x) == root(y);
    }
    void unite(int x, int y) {
        x = root(x), y = root(y);
        if(x == y) return;
        if(par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
    }
private:
    vector<int> par;
};

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    union_find uf(n);
    vector<int> club(n, -1); // leader -> club id
    int ans = 0;
    for(int i = 0; i < k; ++i) {
        int type; cin >> type;
        if(type == 1) { // same club
            int a, b;
            cin >> a >> b;
            a--; b--;
            int ra = uf.root(a), rb = uf.root(b);
            if(club[ra] == -1 || club[rb] == -1 || club[ra] == club[rb]) {
                uf.unite(a, b);
                club[uf.root(a)] = max(club[ra], club[rb]);
            } else {
                ans = i + 1;
                break;
            }
        } else {
            int c, x;
            cin >> c >> x;
            c--; x--;
            if(club[uf.root(c)] == -1 || club[uf.root(c)] == x) {
                club[uf.root(c)] = x;
            } else {
                ans = i + 1;
                break;
            }
        }
    }
    cout << ans << endl;
}



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

int main() {

    int N;
    string S;
    cin >> N >> S;
    if (N % 2 == 1) {
        cout << "No" << endl;
        return 0;
    }

    if (S.substr(0, N / 2) == S.substr(N / 2)) cout << "Yes" << endl;
    else cout << "No" << endl;




    return 0;
}

Measured memory_bytes: 3628
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];


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


Measured memory_bytes: 8336
#include<iostream>
#include<vector>
#include<string>

int main(){
    int n, k, q;
    std::cin >> n >> k >> q;
    std::vector<int> a(q);
    std::vector<int> point(n, k - q);
    for(int i = 0; i < q; i++){
        std::cin >> a[i];
        a[i]--;
        point[a[i]]++;
    }

    for(int i = 0; i < n; i++){
        if(point[i] > 0){
            std::cout << "Yes" << std::endl;
        }else{
            std::cout << "No" << std::endl;
        }
    }
    return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const ll MOD2=998244353;
const double PI=acos(-1);
const ll INF=1e18;
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
struct edge{ll to,cost;};

int main() {
  ll n;
  cin >> n;
  ll ans=1;
  rep(i,n){
    ll a;
    cin >> a;
    if(a!=0&&ans>INF/a){
      ans=-1;
    }
    if(ans==-1){
      if(a==0){
        ans=0;
      }
      else{
        continue;
      }
    }
    ans*=a;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3640
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	cin.tie(0); cin.sync_with_stdio(0);
	
	const int m = 2019;
	ll l, r, ans = m; cin >> l >> r;
	for(ll i = l; i < l + m && i < r; i++)
	for(ll j = i + 1; j <= l + 2 * m && j <= r; j++)
	ans = min(ans, i * j % m);
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
// to format a document: ctrl + K -> ctrl + D

#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;
using ll = long long int;

int main() {
    string S;
    ll K;
    cin >> S >> K;

    for (int i = 0; i < S.length(); i++) {
        if (S[i] != '1') {
            cout << S[i] << endl;
            return 0;
        }
        if (i == K - 1) break;
    }

    cout << '1' << endl;

    return 0;
}

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

int main() {
	int n; cin >> n;
	vector<int>p(n),check; for (auto&& x : p)cin >> x;
	check = p; sort(check.begin(), check.end());
	int cnt = 0;
	for (int i = 0; i < n; i++) {
		if (p[i]!=check[i])cnt++;
	}
	cout << (cnt <= 2 ? "YES" : "NO") << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
typedef long long ll;
int a[3],m[3];
ll cnt[3];

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

int main(void){
	while(1){
		for(int i=0;i<3;i++){
			scanf("%d %d",&a[i],&m[i]);
		}
		if(a[0]==0)break;
		for(int i=0;i<3;i++){
			int x=a[i]%m[i];
			cnt[i]=1;
			while(x!=1){
				x=x*a[i]%m[i];
				cnt[i]++;
			}
		}
		ll k=cnt[0]*cnt[1]/gcd(cnt[0],cnt[1]);
		printf("%lld\n",k*cnt[2]/gcd(k,cnt[2]));
	}
	return 0;
}

Measured memory_bytes: 1028
#include<iostream>
#include<cstdio>
using namespace std;
#define ll long long
const int P = 1e9 + 7;
const int N = 1e5 + 5;
ll rev[N],sump[N],a[N];
int n;
ll pw(ll n,ll k)
{
    ll ans = 1;
    while (k)
    {
        if (k&1) ans=(ans*n)%P;
        n = (n*n)%P;
        k>>=1;
    }
    return ans;
}

int main()
{
    cin>>n;
    for (ll i=1; i<=n; ++i)
        cin>>a[i];
    for (ll i=1; i<=n; ++i)
        rev[i]=pw(i,P-2);
    sump[0]=0;
    for (ll i=1; i<=n; ++i)
        sump[i]=(sump[i-1]+rev[i])%P;
    ll ans=0;
    for (ll i=1; i<=n; ++i)
        ans=(ans+(sump[i]+sump[n-i+1]-1)*a[i])%P;
    for (ll i=1; i<=n; ++i)
        ans=(ans*i)%P;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define all(a) a.begin(), a.end()
using namespace std;
using ll = long long;
using vi = vector<int>;
using vv = vector<vi>;
using P  = pair<int,int>;
const int INF = 1001001001;
const int MOD = 1000000007;



int main(){
    int r;
    cin >> r;
    cout << 2*M_PI*r << endl;
    return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string s;
    cin >> s;
    sort(s.begin(), s.end());
    cout << (s == "abc" ? "Yes" : "No") << endl;
    return 0;
}


Measured memory_bytes: 256
def f():
 N=int(input())
 s=[0]*N
 for _ in[0]*(N*~-N//2):
  a,b,c,d=map(int,input().split())
  s[a-1]+=3*(c>d)+(c==d)
  s[b-1]+=3*(d>c)+(d==c)
 b=[[]for _ in[0]*N*3]
 for i in range(N):b[s[i]]+=[i]
 r=1
 for x in b[::-1]:
  for y in x:s[y]=r
  if x:r+=len(x)
 print(*s,sep='\n')
f()


Measured memory_bytes: 5664
#include <stdio.h>

int main(void){
	
	float a, b, c, d, e, f;
	float x, y;
	
	while(scanf("%f %f %f %f %f %f", &a, &b, &c, &d, &e, &f) != EOF){
	
	y = (d * c - a * f) / (d * b - a * e);
	x = (c - b * y) / a;
	
	printf("%.3f %.3f\n", x, y);
	}
	return 0;
}

Measured memory_bytes: 648
#include<iostream>
#include<cmath>
#include<string>
#include<map>
#include<queue>
using namespace std;
#define N 3
#define N2 9

struct Puzzle {
	int f[N2];
	int space;
	string path;

	bool operator<(const Puzzle &p)const {
		for (int i = 0; i < N2; i++) {
			if (f[i] == p.f[i])continue;
			return f[i] > p.f[i];
		}
		return false;
	}
};

static const int dx[4] = { -1,0,1,0 };
static const int dy[4] = { 0,-1,0,1 };
static const char dir[4] = { 'u','l','d','r' };

bool isTarget(Puzzle p) {
	for (int i = 0; i < N2; i++)
		if (p.f[i] != (i + 1))return false;
	return true;
}

string bfs(Puzzle s) {
	queue<Puzzle> Q;
	map<Puzzle, bool> V;
	Puzzle u, v;
	s.path = "";
	Q.push(s);
	V[s] = true;

	while (!Q.empty()) {
		u = Q.front();
		Q.pop();
		if (isTarget(u))return u.path;
		int sx = u.space / N;
		int sy = u.space%N;
		for (int r = 0; r < 4; r++) {
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N)continue;
			v = u;
			swap(v.f[u.space], v.f[tx*N + ty]);
			v.space = tx*N + ty;
			if (!V[v]) {
				V[v] = true;
				v.path += dir[r];
				Q.push(v);
			}
		}
	}
	return "unsolvable";
}

int main() {
	Puzzle in;

	for (int i = 0; i < N2; i++) {
		cin >> in.f[i];
		if (in.f[i] == 0) {
			in.f[i] = N2;
			in.space = i;
		}
	}
	string ans = bfs(in);
	cout << ans.size() << endl;

	return 0;
}


Measured memory_bytes: 30624
from bisect import bisect_left, bisect_right

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

Bs = [0]
xs = [-1]
for i, A in enumerate(As):
    if Bs[-1] < A:
        Bs.append(A)
        xs.append(i)

lenB = len(Bs)
sumAs = [0] * lenB
numFulls = [0] * lenB
for A in As:
    i = bisect_left(Bs, A)
    sumAs[i] += A - Bs[i-1]
    numFulls[i-1] += 1

for i in reversed(range(lenB-1)):
    numFulls[i] += numFulls[i+1]

anss = [0] * N
for i in range(1, lenB):
    ans = sumAs[i]
    ans += (Bs[i]-Bs[i-1]) * numFulls[i]
    anss[xs[i]] = ans

print('\n'.join(map(str, anss)))


Measured memory_bytes: 30076
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
ll mod= 1e9 + 7;

int a[1000001];
int main(){
  rep(i,1000001)a[i]=1;
  int n;
  cin >>n;
  int ans=0;
  int b[n+1];
  rep(i,n)cin >>b[i];
  b[n]=3000000;
  sort(b,b+n);
  rep(i,n){
    if(a[b[i]]){
      if(b[i]!=b[i+1]){ans++;}
      for(int r=b[i];r<1000001;r+=b[i]){
        a[r]=0;
      }
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 8328
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
int main(){
  int a, b;
  cin >> a >> b;
  if (a>=13) cout << b;
  else if (a<=5) cout << 0;
  else cout << b/2;
}

Measured memory_bytes: 256
n=int(input())
m=list(map(int,input().split()))
kouho=list(map(int,input().split()))
answer=1
ansc=abs(m[1]-(m[0]-kouho[0]*0.006))
for i in range(n):
    if abs(m[1]-(m[0]-kouho[i]*0.006))<ansc:
        ansc=abs(m[1]-(m[0]-kouho[i]*0.006))
        answer=i+1
print(answer)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main() {
	long long a, b, c, d = 0, e;
	cin >> a >> b;
	for (int h = 1; h <= a; h++) {
		cin >> c;
		if (c <= b - c) {
			d += c * 2;
		}
		else {
			d += (b - c) * 2;
		}
	}
	cout << d << endl;
	cin >> e;
}

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

total = 0
for i in range(N-1):
    cnt = 0
    for j in range(N-i):
        if (N-i) % (N-i-j) == 0:
            cnt += 1 
    if cnt == 8 and (N-i) % 2 != 0:
        total += 1
print(total)

Measured memory_bytes: 9100
#include <bits/stdc++.h>
using namespace std;
using int64 = long long;
#define int int64
#define rep(i, n) for(int i=0; i<n; i++)
#define FOR(i, a, b) for(int i=a; i<b; i++)
#define SORT(x) sort(x.begin(), x.end())
#define GSORT(x) sort(x.begin(), x.end(), greater<int>())
#define mk make_pair
#define fi first
#define se second
#define pb push_back
#define ALL(x) x.begin(), x.end()
#define V(T) vector<T>
typedef pair<int, int> P;
typedef pair<P, P> PP;
typedef vector<int> vi;
typedef vector<vi> vvi;
int max(int a, int b) {if(b>a) return b; else return a;}
int min(int a, int b) {if(b<a) return b; else return a;}

const int MAX_N = 100050;
V(P) edges[MAX_N];
int visit[MAX_N], cost[MAX_N];

bool dfs(int v) {
    visit[v] = 1;

    //頂点vから直接つながっている全ての頂点を探索する
    for(const auto& e: edges[v]) {
        int u = e.fi, d = e.se;

        //もし辺の先の頂点のコストがすでに計算済みかつ、
        //今回のルートのコストと一致しないなら、条件を満たすことはできない
        if(visit[u]) {
            if(cost[v] + d != cost[u]) return false;
            else continue;
        }

        cost[u] = cost[v] + d;

        //深さ優先なので、先の頂点を次々チェックしていく
        if(!dfs(u)) return false;
    }

   return true;
}


signed main() {
    int N, M;
    cin >> N >> M;
    rep(i, M) {
        int l, r, d;
        cin >> l >> r >> d;
        l--; r--;
        edges[l].pb(P(r, d));
        edges[r].pb(P(l, -d));
    }

    bool res = true;
    for(int i=0; i<N && res; i++) {
        if(!visit[i] && !dfs(i)) res = false;
    }

    if(res) cout << "Yes";
    else cout << "No";
    cout << endl;

    return 0;
}

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

int path[15][15];
int dp[1 << 15][15];
const int INF = 999999;

int main()
{
	for (int i = 0; i < 15; i++)
	{
		for (int j = 0; j < 15; j++)
		{
			path[i][j] = INF;
		}
	}
	for (int i = 0; i < (1 << 15); i++)
	{
		for (int j = 0; j < 15; j++)
		{
			dp[i][j] = INF;
		}
	}

	int V, E;
	cin >> V >> E;

	for (int i = 0; i < E; i++)
	{
		int s, t, d;
		cin >> s >> t >> d;
		path[s][t] = d;
	}

	dp[0][0] = 0;
	for (int i = 0; i < (1 << V); i++)
	{
		for (int j = 0; j < V; j++)
		{
			if (dp[i][j] == INF) continue;
			for (int k = 0; k < V; k++)
			{
				if (i & (1 << k)) continue;
				if (path[j][k] == INF) continue;
				dp[i + (1 << k)][k] = min(dp[i + (1 << k)][k], dp[i][j] + path[j][k]);
			}
		}
	}
	if (dp[(1 << V) - 1][0] == INF) cout << -1 << endl;
	else cout << dp[(1 << V) - 1][0] << endl;

	return 0;
}

Measured memory_bytes: 5004
from functools import lru_cache, reduce
from sys import stdin
from operator import mul

@lru_cache(maxsize=None)
def getMin(args:tuple):
    if len(args) == 2:
        return 0
    elif len(args) == 3:
        return reduce(mul, args)
    l = [(args[0:i+1], args[i:], args[0]*args[i]*args[-1]) for i in range(1, len(args)-1)]
    return min([getMin(v[0]) + getMin(v[1]) + v[2] for v in l])


n = int(input())
M = [tuple(map(int, line.split())) for line in stdin.readlines()]
R = tuple([M[0][0]] + [r[1] for r in M])
print(getMin(R))


Measured memory_bytes: 10572
#include <bits/stdc++.h>
#define pb push_back
using namespace std;
 
inline int read()
{
	int sum=0,ff=1; char ch=getchar();
	while(!isdigit(ch))
	{
		if(ch=='-') ff=-1;
		ch=getchar();
	}
	while(isdigit(ch))
		sum=sum*10+(ch^48),ch=getchar();
	return sum*ff;
}
 
char ch[10];
 
int main()
{
	scanf("%s",ch+1);
	(ch[3]==ch[4]&&ch[5]==ch[6])?printf("Yes\n"):printf("No\n");
}

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

#define ll long long int
#define ld long double
#define pb push_back

ll mod = 1000000007;

using namespace std;

bool comp(pair<pair<int,int>,pair<string,int>> &a , pair<pair<int,int>,pair<string,int>> &b )
{
	if(a.second.first == b.second.first)
		return a.second.second > b.second.second;
	else 
		return a.second.first < b.second.first;
}

int main()
{
	
	 ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	 int n;
	 cin>>n;
	 pair<pair<int,int>,pair<string,int>> pi[n];

	 for (int i = 0; i < n; ++i)
	 {
	 	cin>>pi[i].second.first;
	 	cin>>pi[i].second.second;
	 	pi[i].first.first = i+1;
	 }

	 sort(pi,pi+n,comp);

	 for (int i = 0; i < n; ++i)
	 {
	 	cout<<pi[i].first.first<<"\n";
	 }

	 
	return 0;
}

Measured memory_bytes: 256
/*
* @author:  codancer
* @createTime:  time
*/
#include<bits/stdc++.h>

using namespace std;
typedef long long ll;
const ll mod = 1e9+7;
#define pb push_back
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
typedef vector<int> VI;
typedef vector<ll> VII;
typedef pair<int,int> pii;
int main(){
	int n,m;
	cin>>n>>m;
	vector<int> a(n);
	int tot=0;
	rep(i,1,n){
		cin>>a[i-1];
		tot+=a[i-1];
	}
	// cout<<tot<<endl;
	sort(a.begin(),a.end());
	reverse(a.begin(),a.end());
	int now=0;
	rep(i,0,n-1){
		if(a[i]*4*m<tot){
			break;
		}
		++now;
	}
	if(now>=m){
		puts("Yes");
	}else{
		puts("No");
	}
	return 0;
}

Measured memory_bytes: 256
n, a, b, c, d = map(int, input().split())
s = str(input())
if '##' in s[a:c] or '##' in s[b:d]:
    print('No')
else:
    if c < d:
        print('Yes')
    else:
        if '...' in s[b - 2:d + 1]:
            print('Yes')
        else:
            print('No')


Measured memory_bytes: 3572
n, m = map(int, input().split())
A = [[] for i in range(n)]
b = [0 for j in range(m)]

for i in range(n):
    A[i] = list(map(int, input().split()))
for j in range(m):
    b[j] = int(input())
for k in range(n):
    c = 0
    for l in range(m):
        c += A[k][l]*b[l]
    print(c)


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

int main(){

    int roster[5][5][20] = { };

    int n; 
    std::cin >> n;

    int b, f, r, v;

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

        std::cin >> b >> f >> r >> v;
        roster[b][f][r] += v;
    }

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

        if ( i > 1 ) {
            std::cout << "####################" << std::endl;
        }

        for ( int j = 1; j <= 3; j++ ) {

            for (int k = 1; k <= 10; k++ ) {
                std::cout << " " << roster[i][j][k];
            }

            std::cout << std::endl;
        }
    }

    return 0;
}



Measured memory_bytes: 3060