akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String input = sc.next();
		int len = input.length();
		int num = Integer.parseInt(input);
		int ans = 0;
		switch(len%2){
			case 0:
			for(int i = 0; i < len; i+=2)ans += 9 * Math.pow(10, i);
			break;

			case 1:
			if(len == 1){
				ans = num;
				break;
			}
			for(int i = 0; i < len-1; i+=2)ans += 9 * Math.pow(10, i);
			ans += Integer.parseInt(input.substring(1))+1;
			ans += (Integer.parseInt(input.substring(0, 1)) - 1) * Math.pow(10, len-1);
			break;
		}

		System.out.println(ans);
	}
}




Measured memory_bytes: 21844
#include <stdio.h>

int main(){
	int a[30],b,c=0,d=0,i,j;
	for(i=0;i<28;i++){
		scanf("%d",&a[i]);
	}
	a[28]=31;
	for(j=0;j<28;j++){
	for(i=0;i<28;i++){
		if(a[i]>a[i+1]){
			b=a[i];
			a[i]=a[i+1];
			a[i+1]=b;
		}
	}
	}
	for(i=0;i<27;i++){
		if(a[0]!=1){
			c=1;
		}
		if(a[27]!=30){
			printf("%d\n30\n",c);
			return 0;
		}
		if(a[i]+3==a[i+1]){
			c=a[i]+1;
			d=a[i]+2;
			printf("%d\n%d\n",c,d);
			return 0;
		}
		if(a[i]+2==a[i+1]){
			if(c==0){
				c=a[i]+1;
			}else if(d==0){
				d=a[i]+1;
			}
		}
	}
	printf("%d\n%d\n",c,d);
	return 0;
}

Measured memory_bytes: 596
/*
 * Author:  heyuhhh
 * Created Time:  2020/5/10 21:13:22
 */
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <vector>
#include <cmath>
#include <set>
#include <map>
#include <queue>
#include <iomanip>
#include <assert.h>
#define MP make_pair
#define fi first
#define se second
#define pb push_back
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 1e6 + 5;

inline bool cmp1(pii a,pii b) {return a.fi>b.fi;}

inline bool cmp2(pii A,pii B) {return A.se + B.fi > A.fi + B.se;}

void run() {
    int n; cin >> n;
    vector <pii> z(n), f(n), o(n);
    for (int i = 1; i <= n; i++) {
        string s; cin >> s;
        int k = s.length();
        int x = 0, Min = INF;
        for (int j = 0; j < k; j++) {
            if (s[j] == '(') ++x;
            else --x;
            Min = min(Min, x);
        }
        if (x > 0) z.push_back(MP(Min, x));
        else if (x == 0) o.push_back(MP(Min, x));
        else f.push_back(MP(Min, x));
    }
    sort(z.begin(),z.end(),cmp1);
    sort(f.begin(),f.end(),cmp2);
//    sort(all(z), [&] (pii A, pii B) {return A.fi > B.fi;});
//    sort(all(f), [&] (pii A, pii B) {
//        return A.se + B.fi > A.fi + B.se;
//    });
    int tot = 0;
    for (int i = 0; i < sz(z); i++) {
        pii now = z[i];
        if (tot + now.fi >= 0) {
            tot += now.se;   
        } else {
            cout << "No" << '\n';
            return;
        }
    }
    for (int i = 0; i < sz(o); i++) {
        pii now = o[i];
        if (tot + now.fi < 0) {
            cout << "No" << '\n';
            return;
        }
    }
    for (int i = 0; i < sz(f); i++) {
        pii now = f[i];
        if (tot + now.fi >= 0) {
            tot += now.se;   
        } else {
            cout << "No" << '\n';
            return;
        } 
    }
    if (tot != 0) cout << "No" << '\n';
    else cout << "Yes" << '\n';
}

int main() {
//	freopen("1.in","r",stdin);
//	freopen("sol.out","w",stdout);
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    run();
    return 0;
}


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

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

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include <random>
#include<iostream>
#include<iomanip>
using namespace std;
long long divisorN[100000];

int main() {
	long long N;
	cin >> N;

	int p = 0;
	for (long long i = 1; i*i <= N; i++) {
		if (N%i == 0) {
			divisorN[p] = i;
			if (i*i != N) {
				divisorN[p + 1] = N / i;
			}
			else {
				p--;
			}
			p += 2;
		}
	}
	for (long long i = 1; i*i <= N-1; i++) {
		if ((N-1)%i == 0) {
			divisorN[p] = i;
			if (i*i != N-1) {
				divisorN[p + 1] = (N - 1) / i;
			}
			else {
				p--;
			}
			p += 2;
		}
	}

	sort(divisorN, divisorN + p);
	int ans = 0;


	for (int i = 0; i < p; i++) {
		if (divisorN[i] < 2) { continue; }
		if (i > 0) { if (divisorN[i] == divisorN[i - 1]) { continue; } }

		long long a = divisorN[i];
		long long Nc = N;
		while (Nc >= a) {
			if (Nc%a == 0) {
				Nc = Nc / a;
			}
			else {
				Nc = Nc % a;
			}
		}
		if (Nc == 1) { ans++; }
	}
	cout << ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
        a[i]-=i+1;
    }
    sort(a,a+n);
    long long mid=a[n/2];
    long long sum=0;
    for(int i=0;i<n;i++)
        sum+=abs(a[i]-mid);
    cout<<sum<<endl;
    return 0;
}


Measured memory_bytes: 1024
N, M = map(int, input().split())
AC = [False] * (N + 1)
WA = [0] * (N + 1)
for _ in range(M):
    p, S = input().split()
    p = int(p)
    if S =='AC':
        AC[p] = True
    elif S == 'WA' and AC[p] == False:
        WA[p] += 1
print(sum(AC), sum([WA[i] for i, boo in enumerate(AC) if boo]))


Measured memory_bytes: 11312
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll a,b;
    cin >> a >> b;
    if(a >= b){
        rep(i,0,a){
            cout << b;
        }
        cout << endl;
    }else{
        rep(i,0,b){
            cout << a;
        }
        cout << endl;
    }
    

}

Measured memory_bytes: 256
def n0():return int(input())
def n1():return [int(x) for x in input().split()]
def n2(n):return [int(input()) for _ in range(n)]
def n3(n):return [[int(x) for x in input().split()] for _ in range(n)]

n,m,x=n1()
ca=n3(n)
ca

import itertools
book=list(itertools.product([0,1], repeat=n))
price=[]
for line in book:
    p=0
    for i in range(n):
        if line[i]==1:
            p+=ca[i][0]
            
    price.append(p)
A=[[book[i],price[i]] for i in range(len(book))]
A.sort(key=lambda x:x[1])

for line in A:
    t=line[0]
    s=[0]*m
    for i in range(n):
        if t[i]==1:
            s=[s[j]+ca[i][j+1] for j in range(m)]
    if len([i for i in s if i>=x])==m:
        print(line[1])
        break
else:
    print(-1)

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

int main() {
  int x;
  cin >> x;
  
  if(x >= 1800 && x <= 1999) cout << 1 << endl;
  else if(x >= 1600 && x <= 1799) cout << 2 << endl;
  else if(x >= 1400 && x <= 1599) cout << 3 << endl;
  else if(x >= 1200 && x <= 1399) cout << 4 << endl;
  else if(x >= 1000 && x <= 1199) cout << 5 << endl;
  else if(x >= 800 && x <= 999) cout << 6 << endl;
  else if(x >= 600 && x <= 799) cout << 7 << endl;
  else if(x >= 400 && x <= 599) cout << 8 << endl; 
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF INT_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()

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

  int N,M;
  cin>>N>>M;
  vector<vector<int>>s(M);
  for(int i=0;i<M;i++){
    int k;
    cin>>k;
    for(int j=0;j<k;j++){
      int S;
      cin>>S;
      s[i].push_back(S);
    }
  }
  ll ans=0;
  vector<int>p(M);
  for(int i=0;i<M;i++)cin>>p[i];
  for(ll bit=0;bit<pow(2,N);bit++){
    bool ok=true;
    for(int i=0;i<M;i++){
      int sum=0;
      for(int j=0;j<s[i].size();j++){
        sum+=(bit>>(s[i][j]-1))&1;
      }
      if(sum%2!=p[i])ok=false;
    }
    if(ok)ans++;
  }
  cout<<ans<<endl;
  return 0;
}


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

int main() {
  long long int N;
  cin >> N;
  vector<long long int> A(N), B(N);
  for (long long int i = 0; i < N; i++) cin >> A.at(i) >> B.at(i);
  
  long long int S = 0;
  for (long long int i = N - 1; i >= 0; i--) {
    A.at(i) += S;
    if (A.at(i) % B.at(i) != 0) S += (B.at(i) - (A.at(i) % B.at(i)));
  }
  
  cout << S << endl;
}

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

int main(){
    string str;
    vector<int> arp(26);
    while(getline(cin,str)){
        for(int i=0; i<str.size(); i++){
            if(str[i]<='z' && str[i]>='a') arp[str[i]-'a']++;
            else if(str[i]<='Z' && str[i]>='A') arp[str[i]-'A']++;
        }
    }
    for(int i=0; i<arp.size(); i++)
        cout << (char)('a'+i) << " : " << arp[i] << endl;
    return 0;
}


Measured memory_bytes: 3160
import qualified Data.Text.Lazy as T
import qualified Data.Text.Lazy.IO as T
import qualified Data.Text.Lazy.Read as T
import qualified Data.Vector.Unboxed as VU

main :: IO ()
main = do
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  let
    tallyN :: Int -> [Int] -> VU.Vector Int
    tallyN n = VU.accum (const . succ) (VU.replicate n 0) . map (flip (,) ())
    f :: [Int] -> Maybe Bool
    f as = foldl step (Just True) . map (\i -> sum . map (v VU.!) $ [i, 2 * i .. 1000000]) $ [2 .. 1000000]
      where
        step :: Maybe Bool -> Int -> Maybe Bool
        step c x | x <= 1    = c
                 | x < n     = const False <$> c
                 | otherwise = Nothing
        v = tallyN 1000001 as :: VU.Vector Int
  as <- map unsafeTextToInt . T.words <$> T.getContents :: IO [Int]
  putStrLn $ case f as of
    Just True -> "pairwise coprime"
    Just _    -> "setwise coprime"
    _         -> "not coprime"

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 110248
#include "bits/stdc++.h"
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)
#define ALL(v) v.begin(), v.end()
#define FS first
#define SC second
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x) ((x) * (x))
#define bit(n) (1LL<<(n))
#define pcnt(x) __builtin_popcountll(x)
#define PB push_back
#define MP make_pair
#define endl "\n"
using namespace std;
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
typedef vector<LL> VLL;
typedef vector<bool> VB;
typedef vector<vector<int> > VVI;
typedef vector<vector<bool> > VVB;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef vector<PII> VPII;
const LL MOD=1000000007ll;
const LL INF=2000000000ll;

long power(long a,long b){return b?power(a*a%MOD,b/2)*(b%2?a:1)%MOD:1;}

long perm(int N, int K){
	long x=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
	}
	return x%MOD;
}

long factorial(int N){
	return perm(N,N);
}

long comb(int N,int K){
	long x=1,y=1;
	for(int i=1;i<=K;i++)
	{
		x=x*(N-i+1)%MOD;
		y=y*i%MOD;
	}
	return x*power(y,MOD-2)%MOD;
}

long hcomb(int N, int K){
    return comb(N+K-1, N-1);
}

void dfs(const vector<vector<int> > &G, int v, vector<int> &seen) {
    seen[v] = true; // v を訪問済にする

    // v から行ける各頂点 next_v について
    for (auto next_v : G[v]) { 
        if (seen[next_v]) continue; // next_v が探索済だったらスルー
        dfs(G, next_v, seen); // 再帰的に探索
    }
}

void wfs(const vector<vector<int> > &G, int v, vector<int> &dist){
    REP(i,SZ(dist)) dist[i] = -1; // 全頂点を「未訪問」に初期化
    queue<int> que;

    // 初期条件 (頂点 0 を初期ノードとする)
    dist[v] = 0;
    que.push(v); // 0 を橙色頂点にする

    // BFS 開始 (キューが空になるまで探索を行う)
    while (!que.empty()) {
        v = que.front(); // キューから先頭頂点を取り出す
        que.pop();

        // v から辿れる頂点をすべて調べる
        for (int next_v : G[v]) {
            if (dist[next_v] != -1) continue; // すでに発見済みの頂点は探索しない

            // 新たな白色頂点 nv について距離情報を更新してキューに追加する
            dist[next_v] = dist[v] + 1;
            que.push(next_v);
        }
    }
}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cout << fixed << setprecision(10);

	int n, u, k;
	cin >> n;
	VVI G(n);
	REP(i,n){
		cin >> u >> k;
		if(k){
			G[i].resize(k);
			REP(j,k){
				cin >> G[i][j];
				G[i][j]--;
			}
		}
	}

	VI d(n);
	wfs(G,0,d);
	REP(i,n) cout << i+1 << " " << d[i] << endl;

}


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

int main() {
    int N;

    std::cin >> N;
    std::vector<int> A;

    for ( int i = 0; i < N; i++ ){
        int a;
        std::cin >> a;
        if ( a % 2 == 0 ) A.push_back( a );
    }

    int answer = 0;
    for ( int a : A ) {
        int tmp_a = a;
        while ( 1 ) {
            if ( tmp_a % 2 == 0 ) {
                tmp_a /= 2;
                answer++;
            } else break;
        }
    }

    std::cout << answer << std::endl;
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
using namespace std;
int main() {
    int N;
    cin >> N;
    double s;
    string m;
    double total = 0;
    for(int i = 0; i < N; i++){
        cin >> s >> m;
        //cout << s <<  ": " << m << "\n";
        if (m == "BTC")
            s = s*380000.0;
        total += s;
    }
    cout << total;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <math.h>
#include <algorithm>
#include <cstdlib>
#include <ctime>
#include <vector>

using namespace std;






int main()
{
	int a[10];
	for (int i = 0; i < 10; i++) {
		cin >> a[i];
	}
	sort(a, a + 10);
	cout << a[9] << endl << a[8] << endl << a[7] << endl;
	
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
//using namespace __gnu_pbds;

const int N = 3e5 + 10;
const int MOD = 1e9 + 7;
const int64_t INF = 5e18;
const double PI = 2 * acos(0.0);
//template<typename T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int64_t a, b, c, d;
    cin >> a >> b >> c >> d;
    int64_t ans = a * c;
    ans = max(ans, a * d);
    ans = max(ans, b * c);
    ans = max(ans, b * d);
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 3648
s = input()

n = len(s) - 1
ans = 0

for i in range(2 ** n):
    k = 0
    nm = []
    for j in range(n):
        if ((i >> j) & 1):
            nm.append(int(s[k:j + 1]))
            k = j + 1
        
        if j == n - 1:
            nm.append(int(s[k:n + 1]))
    
    ans += sum(nm)

if n == 0:
    print(int(s))
else:
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <set>
#include <math.h>
#include <queue>
#include <stdio.h>
#include <sstream>
using namespace std;
using i64 = int64_t;
#define rep(i, n) for(int i=0;i<n;++i)
#define rep2(i, x, n) for(int i=x;i<n;++i)

int main()
{   
    int h,w,d;
    cin >> h >> w >> d;
    vector<vector<int>> a(h,vector<int>(w));
    rep(i,h) rep(j,w) cin >> a[i][j];
    int q;
    cin >> q;
    vector<int> l(q);
    vector<int> r(q);
    rep(i,q) cin >> l[i] >> r[i];

    unordered_map<int,pair<int,int>> coor;
    rep(i,h) rep(j,w) coor.insert({a[i][j]-1,{i,j}});

    int e = (h*w)/d+1;
    i64 cost[d][e];
    rep(i,d) rep(j,e) cost[i][j] = 0;

    rep(i,d)
        rep2(j,1,e)
        {
            int from = i + (j-1) * d;
            int to = i + j * d;
            if(to>=h*w) continue;

            int from_x = coor[from].first;
            int from_y = coor[from].second;            
            int to_x = coor[to].first;
            int to_y = coor[to].second;

            i64 tmp_cost = abs(to_x-from_x)+abs(to_y-from_y);
            cost[i][j] = cost[i][j-1] + tmp_cost;
        }

    rep(i,q)
    {
        int m = (r[i]-1)%d;
        i64 cost_i = cost[m][(r[i]-1)/d] - cost[m][(l[i]-1)/d];
        cout << cost_i << endl;
    }
    return 0;
}

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

#define NIL NULL

typedef struct node{
    int key;
    struct node *l;
    struct node *r;
    struct node *p;
} Node;

typedef struct node * NodePointer;

NodePointer root;

NodePointer Minimum(NodePointer x){
    
    while(x->l != NIL) x = x->l;
    
    return x;

}

NodePointer Search(NodePointer u, int k){
    
    if(u == NIL || u->key == k) return u;
    else if(u->key > k) return Search(u->l, k);
    else if(u->key < k) return Search(u->r, k);
    
}

NodePointer Successor(NodePointer x){
    
    NodePointer y;
    
    if(x->r != NIL) return Minimum(x->r);
    
    y = x->p;
    
    while(y != NIL && x == y->r){
        x = y;
        y = y->p;
    }
    
    return y;

}

void Delete(NodePointer z){
    
    NodePointer x, y;
    
    if(z->l == NIL || z->r == NIL) y = z;
    else y = Successor(z);
    if(y->l != NIL) x = y->l;
    else x = y->r;
    if(x != NIL) x->p = y->p;
    if(y->p == NIL) root = x;
    else if(y == y->p->l) y->p->l = x;
    else y->p->r = x;
    if(y != z) z->key = y->key;

}

void Insert(int key){
    
    NodePointer x, y, z;
    
    y = NIL;
    x = root;
    
    z = malloc(sizeof(struct node));
    z->key = key;
    z->l = NIL;
    z->r = NIL;
    
    while(x != NIL){
        y = x;
        if(z->key < x->key) x = x->l;
        else x = x->r;
        z->p = y;
    }
    
    z->p = y;
    
    if(y == NIL) root = z;
    else if(z->key < y->key) y->l = z;
    else y->r = z;
    
}

void Inorder(NodePointer u){
    if(u->l != NIL) Inorder(u->l);
    printf(" %d", u->key);
    if(u->r != NIL) Inorder(u->r);
}

void Preorder(NodePointer u){
    printf(" %d", u->key);
    if(u->l != NIL) Preorder(u->l);
    if(u->r != NIL) Preorder(u->r);
}

int main(){
    int n, i, x;
    char com[10];
    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");
        }
        else if(com[0] == 'f'){
            scanf("%d", &x);
            NodePointer t = Search(root, x);
            if(t != NIL) printf("yes\n");
            else printf("no\n");
        }
        else if(com[0] == 'd'){
            scanf("%d", &x);
            Delete(Search(root, x));
        }
    }
    
    return 0;
}

Measured memory_bytes: 19364
#include<iostream>
#include <bits/stdc++.h>
#include<stdio.h>
#include <stdlib.h>
#include<string>
#include<queue>
#include<algorithm>
#include<math.h>

using namespace std;
int main(){
	int W,H,x,y,r;
	cin>>W>>H>>x>>y>>r;
	if(0<=x-r&&x+r<=W&&0<=y-r&&y+r<=H){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}
}


Measured memory_bytes: 3092
def main():
    n = int(input())
    ans = 0
    arr = list(map(int, input().split()))
    for i in range(n):
        for j in range(i+1, n):
            for k in range(j+1, n):
                if arr[i] < arr[j] + arr[k] and arr[j] < arr[i] + arr[k] and arr[k] < arr[i] + arr[j] and arr[i] != arr[j] and arr[j] != arr[k] and arr[k] != arr[i]:
                    ans += 1
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 9200
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <algorithm>
#include <climits>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <vector>
#include <list>
#define rep(i,m,n) for(i=m;i<=n;i++)
#define rsp(it,s) for(set<int>::iterator it=s.begin();it!=s.end();it++)
#define mod 1000000007
#define inf 0x3f3f3f3f
#define vi vector<int>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define ll long long
#define pi acos(-1.0)
#define pii pair<int,int>
#define Lson L, mid, rt<<1
#define Rson mid+1, R, rt<<1|1
const int maxn=1e5+10;
using namespace std;
ll gcd(ll p,ll q){return q==0?p:gcd(q,p%q);}
ll qpow(ll p,ll q){ll f=1;while(q){if(q&1)f=f*p;p=p*p;q>>=1;}return f;}
int n,m,k,t;
map<pair<int,int>,int >a;
ll ans[10];
struct node
{
    int x,y;
    bool operator<(const node&p)const
    {
        return x==p.x?y<p.y:x<p.x;
    }
}d[maxn];
int main()
{
    int i,j;
    scanf("%d%d%d",&n,&m,&k);
    rep(i,1,k)
    {
        int b,c;
        scanf("%d%d",&b,&c);
        a[mp(b,c)]=1;
        d[i].x=b,d[i].y=c;
    }
    sort(d+1,d+k+1);
    rep(i,1,k)
    {
        int x=d[i].x,y=d[i].y;
        for(int u=1;u<=3;u++)
            for(int v=1;v<=3;v++)
        {
            if(x-u+1<1)continue;
            if(x+3-u>n)continue;
            if(y-v+1<1)continue;
            if(y+3-v>m)continue;
            bool flag=true;
            for(int l=x-u+1;l<=x;l++){
                if(!flag)break;
                for(int r=y-v+1;r<=y+3-v;r++)
            {
                if(l==x&&r==y)break;
                if(a[mp(l,r)]){flag=false;break;}
            }
            }
            if(flag){
            int cnt=0;
            for(int l=x-u+1;l<=x+3-u;l++)
                for(int r=y-v+1;r<=y+3-v;r++)
                    if(a[mp(l,r)])cnt++;
            ans[cnt]++;
            }
        }
    }
    ll q=0;
    for(i=1;i<=9;i++)q+=ans[i];
    ans[0]=(ll)(n-2)*(m-2)-q;
    rep(i,0,9)printf("%lld\n",ans[i]);
    //system("Pause");
    return 0;
}


Measured memory_bytes: 157312
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);

        int maxrow, maxcol;

        maxrow = scanner.nextInt();
        maxcol = scanner.nextInt();

        int[][] a = new int[maxrow][maxcol];

        for(int i = 0; i < maxrow; i++){
            for(int ii = 0; ii < maxcol; ii++){
                a[i][ii] = scanner.nextInt();
            }
        }

        int[] b = new int[maxcol];

        for(int i = 0; i < maxcol; i++){
            b[i] = scanner.nextInt();
        }

        int sum = 0;
        for(int row = 0; row < maxrow; row++){
            sum = 0;
            for(int col = 0; col < maxcol; col++){
                sum += (a[row][col] * b[col]);
            }
            System.out.println(sum);
        }

        scanner.close();
    }
}



Measured memory_bytes: 40560
#include<stdio.h>
int main()
{
  int N,i;
  int A[100] = {};
  int judge = 0;

  scanf("%d", &N);

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

  for(i=0;i<N;i++){
    if(A[i]%2 == 0){
      if((A[i]%3 == 0) || (A[i]%5 == 0)){
        judge = 0;
      }
      else{
        judge = 1;  
        break;
      }
    }
    else{
      judge = 0; 
    }
  }
    
  if(judge == 0){
    printf("APPROVED\n");
  }
  else{
    printf("DENIED\n");
  }

  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main(String[] args) {
			Scanner scan =  new Scanner(System.in);
			int X = scan.nextInt();
			int N = scan.nextInt();
			int[] num = new int[102];
			for(int i=0;i<N;i++){
				int c = scan.nextInt();
				num[c] = 1;
			}

			if(num[X] == 0){
				System.out.println(X);
			}else{
				int i = 1;
				while(true){
					if(X-i>=0){
						if(num[X-i] == 0){
							System.out.println(X-i);
							break;
						}
					}
					if(X+i<102){
						if(num[X+i] == 0){
							System.out.println(X+i);
							break;
						}
					}
					i++;
				}
			}
	}
}


Measured memory_bytes: 27236
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define ALL(a)  (a).begin(),(a).end()
#define SZ(a) int((a).size())
#define SORT(c) sort((c).begin(),(c).end())
#define PB push_back
#define MP make_pair
#define MEMSET(v, h) memset((v), h, sizeof(v))
#define sqr(x)  ((x) * (x)) 
#define cub(x)  ((x) * (x) * (x))
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main() {
  string s,t; cin >> s >> t;
  string ans;
  ans += t;
  ans += s;
  cout << ans << endl;
}



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

long long N;
int main(){
  cin >> N;
  for(long long a = 1; a <= 3500; a++){
    for(long long b = 1; b <= 3500; b++){
      if( 4*a*b - N*(a+b) == 0 ) continue;
      long long t = N*a*b / ( 4*a*b - N*(a+b) ) ;
      for(long long d = -1; d <= 1; d++){
	long long c = t + d;
	if( c >= 1 ){
	  if( 4 * a * b * c == N * ( b * c + a * c + a * b) ){
	    cout << a << " " << b << " " << c << endl;
	    return 0;
	  }
	}
      }
    }
  }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <cmath>
#include <utility>
#include <iostream>
#include <functional>
#include <bitset>
#include <algorithm>
#include <vector>
#include <forward_list>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <tuple>
#include <numeric>
#define rep(i, s, g) for ((i) = (s); (i) < (g); ++(i))
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
const ll MOD = 1e9 + 7;
const ll INF = (1ll << 60);

ll n, A, B, C;
ll ans = INF;
vector<ll> l(10);

void bfs(int a, int b, int c, int i, int m)
{
    if (i == n)
    {
        if (!a || !b || !c)
        {
            return;
        }

        ans = min(ans, abs(A - a) + abs(B - b) + abs(C - c) + m - 30);

        return;
    }

    bfs(a + l[i], b, c, i + 1, m + 10);
    bfs(a, b + l[i], c, i + 1, m + 10);
    bfs(a, b, c + l[i], i + 1, m + 10);
    bfs(a, b, c, i + 1, m);
}

int main(void)
{
    cin >> n >> A >> B >> C;

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

    bfs(0, 0, 0, 0, 0);

    cout << ans << endl;
}


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

using namespace std;

const int MAX = 250;
vector<int> V;

void make(int n){
  for(int i = 1; i <= 2*n; i++)
    V.push_back(i);
}

void shuffle(int n, int k){
  if(k){
    //cut

    vector<int> V1,V2;

    for(int i = 0; i < k; i++)
      V1.push_back(V[i]);
    
    for(int i = k; i < V.size(); i++)
      V2.push_back(V[i]);


    V.clear();

    for(int i = 0; i < V2.size(); i++)
      V.push_back(V2[i]);
    for(int i = 0; i < V1.size(); i++)
      V.push_back(V1[i]);

  }else{
    vector<int> V1,V2;
    
    for(int i = 0; i < n; i++)
      V1.push_back(V[i]);
    
    for(int i = n; i < V.size(); i++)
      V2.push_back(V[i]);

    V.clear();

    for(int i = 0; i < n; i++){
      V.push_back(V1[i]);
      V.push_back(V2[i]);
    }
  }

}

int main(){

  int n,m;
  cin >> n;
  make(n);
  cin >> m;
  while(m--){
    int k;
    cin >> k;
    shuffle(n,k);
  }

  for(int i = 0; i < V.size(); i++)
    cout << V[i] << endl;

  return 0;
}

Measured memory_bytes: 1220
#include <iostream> // cin, cout, cerr, clog
#include <algorithm> // minmax, sort, swap
#include <numeric> // iota, accumulate, inner_product
#include <cstdio> // printf, scanf
#include <climits> // INT_MIN, LLONG_MIN
#include <cmath> // long, trig, pow
#include <string> // string, stoi, to_string
#include <vector> // vector
#include <queue> // queue, priority_queue
#include <deque> // deque
#include <stack> // stack
#include <map> // key-value pairs sorted by keys
#include <set> // set
#include <unordered_map> // hashed by keys
#include <unordered_set> // hashed by keys
#include <iomanip> // cout<<setprecision(n)

#define rep(i,n) for(int i = 0; i < n; i++)
#define ENDL "\n"
#define print(i) std::cout << (i) << "\n"

#define int long long // at least int64 > 9*10^18
#define all(v) v.begin(), v.end()

const int MOD = 1e9+7;

signed main() {
	int n,k;
	std::cin >> n >> k;
	std::set<int> states_s;
	for(int i=1;i*i<=n;i++) {
		states_s.emplace(n/(n/i));
		states_s.emplace(n/i);
	}
	std::vector<int> states;
	states.assign(all(states_s));
	int state_count = states.size();
	std::vector<int> a;
	std::vector<int> b;
	a.reserve(state_count);
	b.reserve(state_count);
	for(int i=0;i<state_count;i++) a[i] = states[i];
	for(int i=1;i<k;i++) {
		int last = 0;
		for(int j=0;j<state_count;j++) {
			b[j] = (states[j]-last)*a[std::lower_bound(all(states),(n/states[j]))-states.begin()]%MOD;
			if(j!=0) b[j] = (b[j]+b[j-1])%MOD;
			last = states[j];
		}
		std::swap(a,b);
	}
	print(a[state_count-1]);
	return 0;
}


Measured memory_bytes: 4736
import java.util.Scanner;

class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		Node[] a = new Node[n];
		for (int i = 0; i < n; i++) {
			int id = sc.nextInt();
			a[id] = new Node();
			a[id].id = id;
			a[id].l = sc.nextInt();
			a[id].r = sc.nextInt();
			a[id].p = -1;
		}

		for (int i = 0; i < n; i++) {
			if (a[i].l != -1) a[a[i].l].p = a[i].id;
			if (a[i].r != -1) a[a[i].r].p = a[i].id;
		}

		int j = 0;
		while(a[j].p != -1) j++;
		int root = a[j].id;
		
		System.out.println("Preorder");
		preorder(a, root);
		System.out.println();

		System.out.println("Inorder");
		inorder(a, root);
		System.out.println();

		System.out.println("Postorder");
		postorder(a, root);
		System.out.println();
	}

	static void preorder(Node a[], int id) {
		System.out.print(" " + id);
		if (a[id].l != -1) preorder(a, a[a[id].l].id);
		if (a[id].r != -1) preorder(a, a[a[id].r].id);
	}

	static void inorder(Node a[], int id) {
		if (a[id].l != -1) inorder(a, a[a[id].l].id);
		System.out.print(" " + id);
		if (a[id].r != -1) inorder(a, a[a[id].r].id);
	}

	static void postorder(Node a[], int id) {
		if (a[id].l != -1) postorder(a, a[a[id].l].id);
		if (a[id].r != -1) postorder(a, a[a[id].r].id);
		System.out.print(" " + id);
	}
}

class Node {
	int id;
	int l;
	int r;
	int p;
}

Measured memory_bytes: 26172
#include<iostream>
#include <cmath>
#include<cstdio>
using namespace std;


int main() {
	int N, ans = 0;
	long long int A[10000];
	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	for (int i = 0; i < N; i++) {
		while (A[i] % 2 == 0) {
			ans++;
			A[i] /= 2;
		}
	}
	cout << ans << endl;

	return 0;
}


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

int main(){

  int z[1000] = {0},n,a,b,c,d,x[1000] = {0},tmp,count = 0;
  cin >> n;

  for(int i=0;i<n*(n-1)/2;i++){
    cin >> a >> b >> c >> d;

    if(c > d) z[a-1] += 3;
    else if(d > c) z[b-1] += 3;
    else if(c == d){

      z[a-1]++;
      z[b-1]++;

    }
  }

  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(z[i] < z[j]) count++;
    }
      x[i] = count;
      count = 0;
    }
 
  for(int i=0;i<n;i++) cout << x[i]+1 << endl;
}

Measured memory_bytes: 1168
def matrics_vector_multiply(l1, l2):
    """
    l1: a list(matrics n*m)
    l2: a list(vector  m*1)
    returns a list(vector n*1)

    >>> matrics_vector_multiply([[2]], [0])
    [0]
    >>> matrics_vector_multiply([[1,2,0,1],[0,3,0,1],[4,1,1,0]], [1,2,3,0])
    [5, 6, 9]
    """
    result = []
    for row in l1:
        c = 0
        for i in range(len(row)):
            c += row[i] * l2[i]
        result.append(c)

    return result

if __name__ == '__main__':

    (row, col) = [int(i) for i in input().split(' ')]
    m = []
    v = []
    for r in range(row):
        elms = [int(i) for i in input().split(' ')]
        m.append(elms)
    
    for c in range(col):
        v.append(int(input()))

    for elm in matrics_vector_multiply(m, v):
        print(str(elm))

Measured memory_bytes: 8024
# 初期入力
N = int(input())
A = list(map(int, input().split()))
A_sorted =sorted(enumerate(A))

#
junbann =[(i+1,v) for i,v in enumerate(A) ]
junbann_sort =sorted(junbann,key = lambda x:x[1])
kotae = [i[0] for i in junbann_sort]
print(*kotae)

Measured memory_bytes: 31932
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
 
const ll INF = 1LL << 62;
const double PI = acos(-1);
const double eps = 1e-10;
 
int main() {
  ll n, k;
  cin >> n >> k;
  vector<int> p(n), c(n);
  rep(i, n) {
    cin >> p[i];
    p[i]--;
  }
  rep(i, n) cin >> c[i];
 
  ll ans = -INF;
  rep(si, n) {
    ll x = si, total = 0;
    vector<ll> s(1, 0);
    while (true) {
      x = p[x];
      s.push_back(s[s.size() - 1] + c[x]);
      total += c[x];
      if (x == si) break;
    }
    int l = s.size() - 1;
    rep(i, l) {
      if (i + 1 > k) break;
      ll now = s[i + 1] + max(0LL, total) * ((k - (i + 1)) / l);
      ans = max(ans, now);
    }
  }
  cout << ans << endl;
  return 0;
}

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

int N;
vector<int> a;

int main() {
    cin>>N;
    a.resize(N);
    for (int i=0; i<N; i++) cin>>a[i];
    sort(a.begin(),a.end());
    for (int i=0; i<N-1; i++) {
        if (a[i]==a[i+1]) {
            cout<<"NO"<<endl;
            return 0;
        }
    }
    cout<<"YES"<<endl;
    return 0;
}


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

int main(){
    std::string s;
    std::cin >> s;
    
    std::string::iterator itr = s.begin();
    while(!s.empty() && s.end() != itr){
        if('B' == *itr){
            if(s.begin() == itr){
                s.erase(itr);
            }else{
                itr = s.erase(itr - 1, itr + 1);
                //--itr;
            }
        }else{
            ++itr;
        }
    } 
    std::cout << s << std::endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define PII pair<int,int>
using namespace std;
const int P=998244353;
const int N=2e5+5;
const int Gi=332748118;

struct Pint{
	int x;
	inline Pint(){x=0;}
	inline Pint(int b){x=(b%P+P)%P;}
	inline void operator=(int b){x=(b%P+P)%P;}
    inline bool operator==(const Pint &b) const {return x==b.x;}
    inline bool operator!=(const Pint &b) const {return x!=b.x;}
    inline Pint operator+(const Pint &b)const {return x+b.x>=P?x+b.x-P:x+b.x;}
	inline Pint operator-(const Pint &b)const {return x-b.x<0?x-b.x+P:x-b.x;}
	inline Pint operator*(const Pint &b)const {return 1LL*x*b.x%P;}
	inline void operator+=(const Pint &b){x=x+b.x>=P?x+b.x-P:x+b.x;}
	inline void operator-=(const Pint &b){x=x-b.x<0?x-b.x+P:x-b.x;}
	inline void operator*=(const Pint &b){x=1LL*x*b.x%P;}
	inline void read(){
		char c;int a, b;
	    for(c=getchar(),a=0,b=1;c<48||57<c;c=getchar()){
	        if(c==EOF){x=0;return;}
	        if(c=='-')b=-1;
	    }
	    for(;48<=c&&c<=57;c=getchar())a=((a+(a<<2))<<1)+(c^'0');
	    *this=a*b;
	}
};
Pint a[N],b[N],o[N],fac[N],inv[N],ans;
int lim,l,n,m,r[N],h[N],p[N];
inline Pint ksm(Pint x,int y=P-2){
	Pint ans=1;
	for(;y;y>>=1,x*=x)
		if(y&1)ans*=x;
	return ans;
}
inline void init(int len){
    lim=1,l=-1;
    while(lim<=len)lim<<=1,++l;
    for(int i=1;i<lim;i++)r[i]=(r[i>>1]>>1)|((i&1)<<l);
}
inline void NTT(Pint *A,int ty){
    for(int i=0;i<lim;i++)
        if(i<r[i])swap(A[i],A[r[i]]);
    for(int p=1;p<lim;p<<=1){
        int D=p<<1;
		Pint wn=ksm(ty==1?3:Gi,(P-1)/D);
        o[0]=1;
        for(int i=1;i<p;i++)o[i]=o[i-1]*wn;
        for(int i=0;i<lim;i+=D){
            for(int j=0;j<p;j++){
                Pint x=A[i+j],y=A[i+j+p]*o[j];
                A[i+j]=x+y,A[i+j+p]=x-y;
            }
        }
    }
    if(ty==-1){
    	Pint INV__=ksm(lim);
        for(int i=0;i<lim;i++)
            A[i]*=INV__;
    }
}
Pint C(int x,int y){
	return fac[y]*inv[x]*inv[y-x];
}
Pint A(int x,int y){
	return fac[y]*inv[y-x];
}
vector<Pint>f[N];
priority_queue<PII,vector<PII>,greater<PII> >Q;

int main(){
	scanf("%d",&n),n*=2;
    for(int i=1;i<=n;i++)scanf("%d",&h[i]);
    sort(h+1,h+1+n);
    for(int i=1;i<=n;i++){
    	if(h[i]!=h[i-1])p[++m]=1;
    	else p[m]++;
	}
	fac[0]=1;
	for(int i=1;i<=n;i++)fac[i]=fac[i-1]*i;
	inv[n]=ksm(fac[n]);
	for(int i=n-1;~i;i--)inv[i]=inv[i+1]*(i+1);
	for(int i=1;i<=m;i++){
    	for(int j=0;j<=(p[i]>>1);j++){
    		f[i].push_back(A(j,p[i])*C(j,p[i]-j)*ksm(ksm(2,j)));
		}
		Q.push(PII(f[i].size(),i));
	}
	while(Q.size()>1){
		int u=Q.top().second;
		Q.pop();
		int v=Q.top().second;
		Q.pop(); 
		int su=f[u].size(),sv=f[v].size();
		init(su+sv-2);
		for(int i=0;i<=lim;++i) a[i]=0,b[i]=0;
		for(int i=0;i<su;++i) a[i]=f[u][i];
		for(int i=0;i<sv;++i) b[i]=f[v][i];
		NTT(a,1),NTT(b,1);
		for(int i=0;i<lim;i++) a[i]=a[i]*b[i];
		NTT(a,-1);
		++m;
		if(!Q.size()){
			for(int i=0;i<=su+sv-2;++i)
				ans+=ksm(-1,i)*a[i]*A((n-2*i)>>1,n-2*i)*ksm(ksm(2,(n-2*i)>>1));
			break;
		}
		for(int i=0;i<=su+sv-2;++i) f[m].push_back(a[i]);
		Q.push(PII(f[m].size(),m));
	}
	printf("%d\n",ans.x);
} 

Measured memory_bytes: 19892
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)

int main(){
  int N;
  cin >> N;
  rep(i, N+1){
    if(floor(i * 1.08) == N){
      cout << i << endl;
      return 0;
    }
  }
  cout << ":(" << endl;
}

Measured memory_bytes: 256
//--------------------------------------//
#include <bits/stdc++.h>
#include <vector>
//-------------------------------------//
#define faster               ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ROF(x, y)            for(int i=int(x)-1; i>=int(y); i--)
#define FOR(x, y)            for(int i=int(x); i<int(y); i++)
#define test                 int t; cin >>t; while(t--)
#define strsort(s)           sort(s.begin(), s.end());
#define eofstr               string s; while(cin >>s)
#define cs(i)                printf("Case %d: ", i);
#define eof                  long long int n; while(cin>>n)
#define Y                    cout <<"YES" <<endl;
#define N                    cout <<"NO" <<endl;
#define noo                  cout <<"-1" <<endl;
#define pi a                 cos(-1)
#define cube(x)              (x*x*x)
#define sqr(x)               (x*x)
#include <algorithm>
//-------------------------------------//
typedef unsigned long long   ull;
typedef long long int        lld;
typedef long double          ld;
using namespace std;

//----<<some short ninja function>>----//
//sort(arr, arr+n, greater<int>());
//get line(c i n, s t r);
//*max_element(x, x+n);
//string_stream any_name(s); (string->int)
//-------------------------------------//

lld i, j, f, fn, k, a, l, m, n, o, p;

int main()
{
    int x;
    cin >>x;
    if(x==0){cout <<++x <<endl;}
    else{cout <<--x <<endl;}
}


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

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

  sort(begin(n), end(n));

  printf("%d %d %d\n", n[0], n[1], n[2]);

  return 0;
}



Measured memory_bytes: 3136
#include <iostream>
#include <climits>

using namespace std;
using ll = long long;

int main() {
  ll l, r;
  cin >> l >> r;

  if (2000 < r - l)
    cout << 0 << endl;
  else {
    ll vmin = INT_MAX;
    for (ll i = l; i < r; ++i)
      for (ll j = i + 1; j <= r; ++j)
        if ((i * j) % 2019 < vmin)
          vmin = (i * j) % 2019;
    cout << vmin << endl;
  }
}

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

using namespace std;
#define ll long long int

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

	ll n;
	cin>>n;
	ll arr[n],sum=1000,st=0;
	for (int i = 0; i < n; ++i)
	{
		cin>>arr[i];
	}
	bool buy=0;
	for (int i = 0; i < n-1; ++i)
	{
		if(arr[i+1]>arr[i]){
			if(!buy){
			buy=1;
			st=sum/arr[i];
			sum%=arr[i];
			}
		}
		else if(arr[i+1]<arr[i]){
			if(buy){
				buy=0;
				sum+=st*arr[i];
				st=0;
			}
		}
	}
	sum+=st*arr[n-1];
	cout<<sum<<endl;

	return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
using namespace std::literals::string_literals;
using i64 = std::int_fast64_t;
using std::cout;
using std::cerr;
using std::endl;
using std::cin;

template<typename T>
std::vector<T> make_v(size_t a){return std::vector<T>(a);}

template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
  return std::vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

int main() {
	int n; scanf("%d", &n);
	
	printf("%d\n", n / 500 * 1000 + n % 500 / 5 * 5);
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int[] h = new int[N];
    for (int i =0; i<N; i++) {
      h[i] = sc.nextInt();
    }
    int count =0;
    for (int i =0; i<N; i++) {
      if (h[i] >= K) count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 51880
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[200005];
ll b[200005];

int main(void){
	scanf("%d",&n);
	ll sum=0;
	for(int i=0;i<n;i++){
		scanf("%lld%lld",&a[i],&b[i]);
		sum+=a[i];
	}
	bool flag=false;
	for(int i=0;i<n;i++){
		if(a[i]!=b[i])flag=true;
	}
	if(!flag){
		printf("0\n");
		return 0;
	}
	for(int i=0;i<n;i++){
		if(a[i]<b[i]){
			b[i]-=a[i];
			a[i]=0;
		}
	}
	for(int i=0;i<n;i++){
		if(a[i]==b[i]){
			b[i]-=a[i];
			a[i]=0;
		}
	}
	ll v=-1;
	for(int i=0;i<n;i++){
		if(a[i]>b[i]){
			if(v==-1)v=b[i];
			else v=min(b[i],v);
		}
	}
	printf("%lld\n",sum-v);
	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
  
int main(){
  int a,b,c,d;
  cin >> a >>b>>c>>d;
  int x=(a+d-1)/d;
  int y=(c+b-1)/b;
  cout << (x>=y?"Yes":"No") << endl;
}

Measured memory_bytes: 3632
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <math.h> // sqrt
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <iomanip> // setprecision
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<long long>;
using pii = pair<int, int>;
using psi = pair<string, int>;

int main() {
    int W, H, N;
    cin >> W >> H >> N;
    vector<vi> data(N, vi(3));
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < 3; j++) {
            cin >> data[i][j];
        }
    }
    int X = 0, Y = 0;
    for (int i = 0; i < N; i++) {
        if (data[i][2] == 1) {
            X = max(X, data[i][0]);
        }
        else if (data[i][2] == 2) {
            W = min(W, data[i][0]);
        }
        else if (data[i][2] == 3) {
            Y = max(Y, data[i][1]);
        }
        else {
            H = min(H, data[i][1]);
        }
    }
    if (W - X <= 0 || H - Y <= 0) {
        cout << 0 << endl;
    }
    else {
        cout << (W - X) * (H - Y) << endl;
    }
}


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

using namespace std;

#define lli long long int
#define REP(i,n) for(int i=0;i<n;i++)
#define DEBUG 1

lli diff(lli a){
	if(a%2) return -1;
	else return 1;
}

int main(){

	lli n;
	cin>>n;
	vector<lli> a;
	a.resize(n+10);

	lli center = (n+5)/2;
	lli tmp1;
	lli minCnt=center;
	lli maxCnt=center;
	cin>>tmp1;
	a[center]=tmp1;
	for(lli i=1;i<n;i++){
		lli tmp;
		cin>>tmp;
		a[center + (i+1)/2*diff(i+1)]=tmp;
		if(diff(i+1)==-1){
			minCnt = center+(i+1)/2*diff(i+1);
		}
		else{
			maxCnt = center+(i+1)/2*diff(i+1);
		}
	}

	if(n%2==1){
		for(lli i=minCnt;i<=maxCnt;i++){
			cout<<a[i]<<" ";
		}
	}
	else{
		for(lli i=maxCnt;i>=minCnt;i--){
			cout<<a[i]<<" ";
		}
	}
	cout<<endl;


	return 0;
}

Measured memory_bytes: 3712
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    int[] a = new int[n];
    int c = 1;
    int b = 0;
    int ans = 0;
    
    for(int i=0; i<n; i++){
      a[i] = Integer.parseInt(sc.next());
    }
    
    for(int i=0; i<n; i++){
      if(a[i] == c){
        c++;
      } else {
        b++;
      }
    }
    
    if(b != 0 && c == 1){
      b = -1; 
    }
    
    System.out.println(b);
    
  }
  
  public static long gcd(long a, long b) {
    if (b == 0) {
      return a;
    } else {
      return gcd(b,a%b);
    }
  }
}


Measured memory_bytes: 52248
#include <bits/stdc++.h>
 
using namespace std;
 
#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define TRAV(a, x) for(const auto& a : x)
#define ALL(x) x.begin(), x.end()
#define NEXT_PERM(x) while(next_permutation(ALL(x))) // 순열 알고리즘(오름)
#define PREV_PERM(x) while(prev_permutation(ALL(x))) // 순열 알고리즘(내림)
#define PRINT(x) cout << x
#define PRINT_LN(x) cout << x << endl;
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")
 
typedef long long int ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<char> vc;
 
void solve() {
  int n;
  cin >> n;
  int result = 0;
  REP(i,n){
    REP(j,n){
      REP(k,n){
        result += gcd(i+1, gcd(j+1, k+1));
      }
    }
  }
  cout << result;
}
 
int main() {
  solve();
  return 0;
}


Measured memory_bytes: 3636
N = int(input())
a = list(map(int, input().split()))

maxa = max(a)
mina = min(a)
add = None
if abs(maxa) > abs(mina):
    add = maxa
else:
    add = mina

index = a.index(add)
ans = [(index, i) for i in range(N) if i != index]
if add > 0:
    ans += [(i, i+1) for i in range(N-1)]
else:
    ans += [(i, i-1) for i in range(N-1, 0, -1)]

ans = list(map(lambda x: (x[0]+1, x[1]+1), ans))
print(len(ans))
print('\n'.join(map(lambda x: '%d %d' % x, ans)))


Measured memory_bytes: 3064
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
using namespace std;
#define int long long



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

    int k,s; cin >> k >> s;

    int ans = 0;
    for(int x = 0;x < k+1;x ++){
        for(int y = 0;y < k+1;y ++){
            int z = s - x - y;
            if(0 <= z && z <= k) ans ++;
        }
    }

    cout << ans << endl;
}

Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

int main()
{
	long long S; cin>>S;
	
	long long t=1e9;
	
	int i;
	
	if (S%t) i=S/t+1; else i=S/t; 
	
	int j=i*1000000000-S;
	
	printf("0 0 1000000000 %d 1 %d",j,i);
	
	return 0;
}

Measured memory_bytes: 256