akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<vector>
#include<numeric>
#include<string>
#include<cmath>
#include<set>
#include<queue>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cctype>
#include<map>
#include<cstring>
#include<bitset>
#include<cassert>

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,a,b) for (int (i)=a;(i)<(b);(i)++)
#define all(x) (x).begin(),(x).end()

using namespace std;
using ll = long long int;

const int inf = 1001001000;
const long long int Inf = 1001001001001001000;



void print(vector<vector<int>> a){
	for (int i = 0; i < a.size(); i++)
	{
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<vector<long long int>> a){
	for (int i=0;i<a.size();i++){
		for (int j=0;j<a[i].size();j++){
			cout << a[i][j] << " ";
		}
		cout << endl;
	}
}

void print(vector<int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(vector<long long int> a){
    int n = a.size();
    for (int j=0;j<n;j++) {
        if (j != n-1) cout << a[j] << " ";
        else cout << a[j] << endl;
    }
}

void print(set<int> a){
	for (auto x:a)
		cout << x << " ";
	cout << endl;
}

//素因数分解をする関数.
map<long long int, int> prime_factorization(long long int a)
{
	map<long long int, int>ans;
	for (long long i = 2; i*i <= a; ++i) {
		while (a%i == 0) {
			ans[i]++;
			a /= i;
		}
	}
	if (a != 1)ans[a]++;
	return ans;
}

//最大公約数を返す関数.
long long int gcd(long long int x, long long int y){
    if (x < y) swap(x,y);
    while (y > 0){
        long long int r = x % y;
        x = y;
        y = r;
    }
    return x;
}

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	set<int> s;
	vector<int> g(n + 1);
	rep(i, n) g[i + 1] = gcd(g[i], a[i]);
	if (g[n] != 1) {
		cout << "not coprime" << endl;
		return 0;
	}
	rep(i, n)
	{
		map<ll, int> m = prime_factorization(a[i]);
		for (auto x:m){
			if (s.count(x.first) == 1){
				cout << "setwise coprime" << endl;
				return 0;
			}
			s.insert(x.first);
		}
	}
	cout << "pairwise coprime" << endl;

	return 0;
}




Measured memory_bytes: 11120
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>
#include <tuple>

#define DEBUG(x) cout<<#x<<": "<<x<<endl

using namespace std;

int main(){

	long long N, X;

	cin >> N >> X;

	long long b=1;
	long long p=1;
	for(int i =0; i< N; i++){
		b = 2*b +3;
		p = 2*p +1;
	}

	long long ans =0;
	while(X!=0){
		if(X == b) {
			ans += p;
			break;
		}
		if(X == 1) break;
		if((b+1)/2 == X){
			ans += (p+1)/2;
			break;
		}
		if((b+1)/2 < X){
			ans += (p+1)/2;
			X -= (b+1)/2;
		} else {
			X--;
		}
		b = (b-3)/2;
		p = (p-1)/2;
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define PRECISION(x) cout << fixed << setprecision(x)
#define FAST_IO ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define ALLR(X) (X).rbegin(), (X).rend()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second

using namespace std;
 
template<class T> void max_self(T & a, const T & b) { if(a < b) a = b; }
template<class T> void min_self(T & a, const T & b) { if(a > b) a = b; }
typedef long long LL;
const int INF = 1e9 + 7;
const double PI = acos(-1.0);
const double EPS = (1e-9);



int main(){
	FAST_IO
	
	int H, W, minCost = 0; cin >> H >> W;
	
	int cost[10][10];
	for(int row = 0; row < 10; ++row){
		for(int col = 0; col < 10; ++col){
			cin >> cost[row][col];
		}
	}
	
	for(int via = 0; via < 10; ++via){
		for(int from = 0; from < 10; ++from){
			for(int to = 0; to < 10; ++to){
				min_self(cost[from][to], cost[from][via] + cost[via][to]);
			}
		}
	}
	
	for(int row = 0; row < H; ++row){
		for(int col = 0; col < W; ++col){
			int x; cin >> x;
			if(x == -1) continue;
			minCost += cost[x][1];
		}
	}
	
	cout << minCost << "\n";
	
	return 0;
}


Measured memory_bytes: 256
class Node:
    def __init__(self, k):
        self.parent = None
        self.childs = [None, None]
        self.key = k


class Tree:
    def __init__(self):
        self.root = None

    def insert(self, z):
        y = None
        x = self.root
        while x != None:
            y = x
            if z.key < x.key:
                x = x.childs[0]
            else:
                x = x.childs[1]
        z.p = y
        if y == None:
            self.root = z
        elif z.key < y.key:
            y.childs[0] = z
        else:
            y.childs[1] = z


def preorder(p):
    s = ""
    if p == None:
        return ""
    s += f"{p.key} "
    s += preorder(p.childs[0])
    s += preorder(p.childs[1])
    return s


def inorder(p):
    s = ""
    if p == None:
        return ""
    s += inorder(p.childs[0])
    s += f"{p.key} "
    s += inorder(p.childs[1])
    return s


n = int(input())

t = Tree()
for i in range(n):
    v = input().split()
    if v[0] == "insert":
        t.insert(Node(int(v[1])))
    else:
        print(" "+inorder(t.root).strip())
        print(" "+preorder(t.root).strip())



Measured memory_bytes: 154340
// C - Guess The Number
#include <bits/stdc++.h>
using namespace std;

int main(){
	int N,M; cin>>N>>M;
	string T(N,'-');
	while(M--){
		int s,c; cin>>s>>c; s--, c+='0';
		if(T[s] !='-' && T[s] != c){ puts("-1"); return 0; }
		if(N!=1 && s==0 && c=='0'){ puts("-1"); return 0; }
		T[s] = c;
	}

	while(N--)
		if(T[N]=='-')
			if(T.size()==1) T[N] = '0';
			else T[N] = N==0? '1': '0';
	cout<< stoi(T) <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> Pii;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

struct Range {
    string d;
    int l, r;
    int id;
};

int convTime(string s) {
    int ret = 0;
    stringstream ss(s);
    string t;
    while (getline(ss, t, ':')) {
        ret *= 60;
        ret += stoi(t);
    }
    return ret;
}

int common(const Range &a, const Range &b) {
    if (a.d != b.d) return 0;
    if (b.id == 0) return 0;
    int l = max(a.l, b.l);
    int r = min(a.r, b.r);
    return max(0LL, r - l);
}

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

    int n;
    while (cin >> n, n) {
        vector<stack<int>> v(1000);
        vector<Range> u;
        rep(i, n) {
            string d, hhmm, e;
            int id;
            cin >> d >> hhmm >> e >> id;
            int m = convTime(hhmm);
            if (v[id].empty()) {
                assert(e == "I");
                v[id].push(m);
            } else {
                assert(e == "O");
                int s = v[id].top(); v[id].pop();
                u.emplace_back((Range){d, s, m, id});
            }
        }

        V len(1000, 0);
        for (auto a : u) {
            if (a.id == 0) {
                for (auto b : u) {
                    len[b.id] += common(a, b);
                }
            }
        }

        cout << *max_element(all(len)) << endl;
    }
}

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

int main()
{
	float a,b,m;
	int m_;
	cin>>a>>b;
	m=(a+b)/2;
	m_=(a+b)/2;	
	if (m-m_>=0.5)
		cout<<m_+1;
	else
		cout<<m_;
	return 0;
}

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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
	int n;cin>>n;
	string s;cin>>s;
	int i,j;
	int ans=0;
	rep(i,n+1)
	{
		string x=s.substr(0,i);
		string y=s.substr(i,n-i);
		vector<bool> alpx(26);
		vector<bool> alpy(26);
		rep(j,x.size())
		{
			alpx[x[j]-'a']=true;
		}
		rep(j,y.size())
		{
			alpy[y[j]-'a']=true;
		}
		int kans=0;
		rep(j,26)if(alpx[j]&&alpy[j])kans++;
		ans=(kans>ans)?kans:ans;
	}
	cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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<int,int> P;

int main(){
    int n;
    cin >> n;
    vector<double> v(n);
    rep(i,n)cin>>v[i];
    sort(v.begin(),v.end(),greater<double>());
    rep(i,n-1){
        double a = v.back();
        v.pop_back();
        double b = v.back();
        v.pop_back();
        v.push_back((a+b)/2);
    }
    cout << v[0] << endl;
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	private static Scanner scan;

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

		String firstInput = scan.nextLine();
		int inputCount = Integer.parseInt(firstInput.substring(0, firstInput.indexOf(" ")));
		int minTime = Integer.parseInt(firstInput.substring(firstInput.indexOf(" ")+1));
		int minCost = 1001;
		for(int i = 0; i < inputCount; i++) {
			String input = scan.nextLine();
			int cost = Integer.parseInt(input.substring(0, input.indexOf(" ")));
			int time = Integer.parseInt(input.substring(input.indexOf(" ")+1));

			if(cost < minCost && time <= minTime) {
				minCost = cost;
			}
		}
		if(minCost < 1001) {
			System.out.println(minCost);
		} else {
			System.out.println("TLE");
		}
	}
}

Measured memory_bytes: 23764
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n;
	int a,b;
	cin>>n>>a>>b;
	for(int i=a;i<=b;i++)
	{
	   if(i%n==0)
	   {
	      cout<<"OK";
		  return 0;	
	   }	
	} 
	cout<<"NG";
}

Measured memory_bytes: 3620
#include <stdio.h>
#include <string.h>

int main(void)
{
	char s[100];
	char t[101];
	int len;
	int i;
	int flag = 0;
	
	scanf("%s",&s);
	scanf("%s",&t);
	
	len = strlen(s);
	
	for(i=0; i<len; i++){
		if(s[i] != t[i]){
			flag = 1;
			break;
		}		
	}
	if(flag == 0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	
	
	return 0;
}

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define int  long long int
#define mod_ceil(a, b) (a % b) ? a / b + 1 : a / b
using namespace std;

int32_t main()
{
   

    int x, n;
    cin >> x >> n;
    vector<int> A(n);
    unordered_set<int> U;
    for (auto &it : A)
    {
        cin >> it;
        U.insert(it);
    }
    for (int i = 0;; i++)
    {
        if (U.find(x - i) == U.end())
        {
            cout << x - i << endl;
            return 0;
        }
        else if (U.find(x + i) == U.end())
        {
            cout << x + i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 3584
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
	vector<int> a(3);
	for (int i=0; i<3; i++) cin >> a[i];
	sort(a.begin(), a.end());
	cout << a[0] << " " << a[1] << " " << a[2] << endl;
	return 0;
}

Measured memory_bytes: 3160
# coding: utf-8
from __future__ import unicode_literals
from __future__ import print_function
import sys
import string

card_strength = [2,3,4,5,6,7,8,9,10,11,12,13,1]

def main():
    lines = map(lambda x: [int(i) for i in string.split(x)],
        sys.stdin.readlines())

    alices_card, bobs_card = lines[0]        
    alice_score = card_strength.index(alices_card)
    bob_score = card_strength.index(bobs_card)

    if(alice_score > bob_score):
        print("Alice")
    elif(alice_score < bob_score):
        print("Bob")
    else:
        print("Draw")

    # sys.stdout.write(%s % count)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2692
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
template<class T>
using Table = vector<vector<T>>;
const ld eps=1e-9;

//// < "D:\D_Download\Visual Studio 2015\Projects\programing_contest_c++\Debug\a.txt"
int main() {
	while (1) {

		int N; cin >> N;
		if (!N)break;
		int W, H; cin >> W >> H;
		vector<vector<int>>field(H + 1, vector<int>(W + 1));
		for (int i = 0; i < N; ++i) {
			int x, y; cin >> x >> y;
			field[y][x]++;
		}
		vector<vector<int>>sums(H + 1, vector<int>(W + 1));
		for (int i = 0; i < H; ++i) {
			for (int j = 0; j < W; ++j) {
				sums[i + 1][j + 1] = sums[i + 1][j] + sums[i][j + 1] - sums[i][j] + field[i + 1][j + 1];
			}
		}
		int S, T; cin >> S >> T;
		int ans = 0;
		for (int l = 0; l <= W - S; ++l) {
			for (int u = 0; u <= H-T; ++u) {
				const int num = sums[u + T][l + S] - sums[u][l + S] - sums[u + T][l] + sums[u][l];
				ans = max(ans, num);
			}
		}
		cout << ans << endl;
	}
	
	return 0;
}

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

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

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

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

int main(){
    int N,K; cin >> N >> K;
    vector<int> P(N);
    vector<int> C(N);
    ll outt=-LNF;
    for(int i=0;i<N;i++){
        cin >> P[i]; P[i]--;
    }
    for(int i=0;i<N;i++){
        cin >> C[i];
    }
    for(int i=0;i<N;i++){
        ll tmp=0;
        int x=P[i];
        for(int j=0;j<min(K,N);j++){
            tmp += C[x];
            outt = max(tmp,outt);
            x = P[x];
        }
    }
    if(K<=N){
        cout << outt << endl;
        return 0;
    }
    ll out=-LNF;
    for(int i=0;i<N;i++){
        int x=i;
        vector<int> s;
        ll tot=0;
        while(1){
            x = P[x];
            s.push_back(C[x]);
            tot += C[x];
            if(x==i) break;
        }
        ll t=0;
        int l=s.size();
        for(int j=0;j<l;j++){
            t += s[j];
            if(j+1>K) break;
            ll now=t;
            if(tot>0){
                ll e = (K-(j+1))/l;
                now += tot*e;
            }
            out = max(out,now);
        }
    }

    cout << max(out,outt) << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <iostream>
#include <vector>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)


int main() {
	int h,w,maxans=0,ans;
	cin>>h>>w;
	vector<string>grid(h);
	rep(i,h)cin>>grid[i];
	//input
	vector<vector<int>>u(h,vector<int>(w)),d(h,vector<int>(w)),l(h,vector<int>(w)),r(h,vector<int>(w));
	rep(i,h){//l and r
	    for(int j=0;j<w;j++){
	        if(grid[i][j]=='.'){
	            if(j==0)l[i][j]=1;
	            else l[i][j]=l[i][j-1]+1;
	        }
	    }
	    for(int j=w-1;j>=0;j--){
	        if(grid[i][j]=='.'){
	            if(j==w-1)r[i][j]=1;
	            else r[i][j]=r[i][j+1]+1;
	        }
	    }
	}
	rep(j,w){//u and d
	    for(int i=0;i<h;i++){
	        if(grid[i][j]=='.'){
	            if(i==0)u[i][j]=1;
	            else u[i][j]=u[i-1][j]+1;
	        }
	    }
	    for(int i=h-1;i>=0;i--){
	        if(grid[i][j]=='.'){
	            if(i==h-1)d[i][j]=1;
	            else d[i][j]=d[i+1][j]+1;
	        }
	    }
	}
	rep(i,h)rep(j,w){
	    ans=l[i][j]+r[i][j]+u[i][j]+d[i][j]-3;
	    //cout<<ans<<endl;//
	    maxans=max(maxans,ans);
	}
	cout<<maxans;
	return 0;
}


Measured memory_bytes: 67200
#include<stdio.h>
double min,max,t,P,ans;
int k;
void find(double l,double r,double p,int cur)
{
	double mid;
    if(r<=min||l>=max) 
		return;   
    if(l>=min&&r<=max) 
	{ ans+=p; return; }
    mid=(l+r)/2;
    if(cur==k)
	{
        if(mid<=max&&mid>=min) 
			ans+=p;
        return ;
    }
    if(mid>=t)
	{
        find(l,mid,p*(1-P),cur+1);
        find(mid,r,p*P,cur+1);
    }
    else
	{        
        find(l,mid,p*P,cur+1);
        find(mid,r,p*(1-P),cur+1);
    }
	return ;
}

int main()
{
    double l,r,p,e;
    scanf("%d%lf%lf",&k,&l,&r);
        
        scanf("%lf %lf %lf",&P,&e,&t);
		ans=0;
        min=t-e;
		max=t+e;
        find(l,r,1,0);
        printf("%.6lf\n",ans);
    
    return 0;
}

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

int main() {
  long long n;
  cin >> n;
  long long a=1,b=n;
  long long opta = a;
  long long optb = b;
  for(long long i = 1; i*i < n+1; i++) {
      if(n%i == 0) {
          a = i; b = n/i;
          if(a+b < opta+optb) {
              opta = a; optb = b;
          }
      }
  }

  cout << opta+optb-2 << endl;

  return 0;
}


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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
typedef vector<ld> vld;
typedef vector<string> vstr;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef priority_queue<ll, vector<ll>, greater<ll>> spqll;  // 小さい順に取り出し
typedef priority_queue<ll, vector<ll>, less<ll>> bpqll;     // 大きい順に取り出し

#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define IREP(i, v) for (auto i = (v).begin(); i != (v).end(); ++i)
#define ALL(v) (v).begin(), (v).end()
#define endl "\n"

ll MOD = 1000000007;
ll INF = 1e18;
ld EPS = 1e-9;
ld PI = M_PI;
vll dx = {1, 0, -1, 0, 1, -1, -1, 1};
vll dy = {0, 1, 0, -1, 1, 1, -1, -1};
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a;} //最大公約数
ll lcm(ll a, ll b) { return a / gcd(a, b) * b;}     //最小公倍数

void yes(){ cout << "Yes" << endl;}
void no(){ cout << "No" << endl;}

//-----------------------------------------
//-----------------------------------------

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

  ll n;
  cin >> n;
  vpll vec(n);
  REP(i,n) cin >> vec[i].first >> vec[i].second;
  vll ans1(n);
  vll ans2(n);
  REP(i,n){
    ans1[i] = vec[i].first - vec[i].second;
    ans2[i] = vec[i].first + vec[i].second;
  }
  sort(ALL(ans1));
  sort(ALL(ans2));
  cout << max(ans1[n-1] - ans1[0], ans2[n - 1] - ans2[0]) << endl;
    
  return 0;
}



Measured memory_bytes: 9452
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
#include<iomanip>
#include<functional>

using namespace std;
typedef long long ll;

// a と b の最大公約数を返す関数
long long GCD(long long a, long long b) {
    if (b == 0) return a;
    else return GCD(b, a % b);
}

int main() {
    int n,k;
    cin >> n >> k;
    vector<int> H(n);
    for (int i = 0; i < n; i++) cin >> H[i];
    sort(H.begin(), H.end());
    ll ans = 0;
    if(n-k>0)
    for (int i = n - k - 1; i >= 0; i--) ans += H[i];
    cout << ans << endl;
}


Measured memory_bytes: 4032
package main

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

var N, M, R int
var ans int = 1e9
var cost [][]int
var r []int

func main() {
	reader.Split(bufio.ScanWords)
	N, _ = strconv.Atoi(read())
	M, _ = strconv.Atoi(read())
	R, _ = strconv.Atoi(read())

	r = make([]int, R)
	cost = make([][]int, N)
	for i := 0; i < N; i++ {
		cost[i] = make([]int, N)
		for j := 0; j < N; j++ {
			cost[i][j] = 1e9
		}
	}

	for i := 0; i < R; i++ {
		r[i], _ = strconv.Atoi(read())
		r[i]--
	}

	for i := 0; i < M; i++ {
		a, _ := strconv.Atoi(read())
		b, _ := strconv.Atoi(read())
		c, _ := strconv.Atoi(read())
		cost[a-1][b-1] = c
		cost[b-1][a-1] = c
	}

	for k := 0; k < N; k++ {
		for i := 0; i < N; i++ {
			for j := 0; j < N; j++ {
				cost[i][j] = min(cost[i][j], cost[i][k]+cost[k][j])
			}
		}
	}
	//fmt.Println(cost)
	used := make(map[int]bool)

	// 調査対象はN!
	// 1,2,3,4...
	// 2,1,3,4...
	for i := 0; i < R; i++ {
		used[r[i]] = true
		//fmt.Printf("%d", r[i])
		ans = min(ans, dfs(1, r[i], 0, used))
		//fmt.Println(":", ans)
		used[r[i]] = false
	}
	fmt.Println(ans)
}

func dfs(n int, now int, sum int, used map[int]bool) int {
	if n == R {
		return sum
	} else {
		var ans int = 1e9
		for i := 0; i < R; i++ {
			next := r[i]
			if used[next] {
				continue
			} else {
				used[next] = true
				//fmt.Printf("%d", next)
				ans = min(ans, dfs(n+1, next, sum+cost[now][next], used))
				//fmt.Printf("/")
				used[next] = false
			}
		}
		return ans
	}
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}
func gcd(x, y uint64) uint64 {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

func combination(x, y int) int {
	return permutation(x, y) / permutation(y, y)
}

func permutation(x, y int) int {
	var ans int = 1
	for i := x - y; 0 < i; i-- {
		ans *= i
	}
	return ans
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}

func pow(x, y int) uint64 { return uint64(math.Pow(float64(x), float64(y))) }
func abs(x int) int       { return int(math.Abs(float64(x))) }
func floor(x int) int     { return int(math.Floor(float64(x))) }

type si struct {
	s int
	i int
}

type SortBy []si

func (a SortBy) Len() int           { return len(a) }
func (a SortBy) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool { return a[i].s < a[j].s }


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

using namespace std;

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

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;  cin >> n;
    int cnt = 0;
    map<int, int> mp;
    rep(i, n) {
      int a;  cin >> a;
      mp[a]++;
    }
    for (auto iter = mp.begin(); iter != mp.end(); iter++) {
      if (iter->second % 2 == 1) cnt++;
    }
    cout << cnt << '\n';

    return 0;
}


Measured memory_bytes: 4992
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

void solve()
{
	string S;
	cin >> S;
	int minV = 1e9;
	for (int i = 0; i < S.size() - 2; ++i)
	{
		string num = "";
		num += S[i];
		num += S[i + 1];
		num += S[i + 2];
		int n = stoi(num);
		minV = min(minV, abs(753 - n));
	}
	cout << minV << endl;
}

int main()
{
	solve();
	return(0);
}

Measured memory_bytes: 256
Imports System.Data
Imports System.Collections.Generic
Module Module1

    Sub Main()
        Dim StationInputData As String = Console.ReadLine()
        Dim StationList As New List(Of String)
        For i As Integer = 0 To StationInputData.Length - 1
            StationList.Add(StationInputData.Substring(i, 1))
        Next

        Dim otherCompany As Boolean = False

        Dim preStation As String = String.Empty
        For Each station As String In StationList
            If preStation <> String.Empty AndAlso preStation <> station Then
                otherCompany = True
                Exit For
            End If
            preStation = station
        Next

        'Dim stationList_addIndex = StationList.Select(Function(x, index) New With {.station = x, .index = index})
        'Dim stationlist_delLastItem = stationList_addIndex.Where(Function(x) x.index < stationList_addIndex.Count - 1)
        'otherCompany = stationlist_delLastItem.Any(Function(x) Not x.station.Equals(stationList_addIndex.Where(Function(y) y.index = x.index + 1).First.station))
        If otherCompany Then
            Console.WriteLine("Yes")
        Else
            Console.WriteLine("No")
        End If
        Stop
    End Sub

End Module


Measured memory_bytes: 21840
from sys import stdin
import sys
import math
from functools import reduce
import functools
import itertools
from collections import deque,Counter,defaultdict
from operator import mul
import copy
# ! /usr/bin/env python
# -*- coding: utf-8 -*-
import heapq
sys.setrecursionlimit(10**6)
# INF =  float("inf")
INF = 10**18
import bisect
import statistics
mod = 10**9+7
# mod = 998244353

A, B = map(int, input().split())

# リストのlcm
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)

print(lcm_base(A, B))

Measured memory_bytes: 77620
from collections import Counter
from collections import deque
from functools import reduce
from pprint import pprint
import bisect
import copy
import fractions
import itertools
import math
import queue
import random
import sys
import time
sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def MI(): return map(int, sys.stdin.readline().split())
def II(): return int(sys.stdin.readline())
def IS(): return input()
def C(x): return Counter(x)
def GCD_LIST(numbers): return reduce(fractions.gcd, numbers)
def LCM_LIST(numbers): return reduce(LCM, numbers)
def LCM(m, n): return (m * n // fractions.gcd(m, n))


n = II()
ab = sorted([LI() for _ in range(n)], key=lambda x: x[1])
s = 0
for i in ab:
    s += i[0]
    if s > i[1]:
        print("No")
        exit()
print("Yes")



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

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        var ans = a.Where((e,i) => (i + 1) % 2 == 1 && e % 2 == 1).Count();
        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 28304
#include <iostream>

using namespace std;

int main(void)
{
    string O, E;
    cin >> O >> E;

    int le = E.size();
    for(int i = 0; i < le; ++i)
        cout << O[i] << E[i];

    if(O.size() - le)
        cout << *O.rbegin();

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>

#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>

#include <cmath>
#include <numeric>
#include <random>
#include <cstring>
#include <cassert>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>
#include <stack>

// type
#include <cstdint>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

int N, K, L;
int A[200005];

bool f(int x) {
    // x以下の数がK個以上ある連続区間の数を調べる
    int ret = 0;
    int cnt = 0;
    int r = -1;
    for (int l = 0; l < N; l++) {
        if (l >= 1 && A[l-1] <= x) cnt--;
        bool flag = false;

        while (r < 0 || cnt < K) {
            r++;
            if (A[r] <= x) cnt++;
            if (r >= N) {
                flag = true;
                break;
            }
        }

        if (flag) break;
        ret += N - r;
    }

    return ret >= L;
}

signed main() {
    cin >> N >> K >> L;
    for (int i = 0; i < N; i++) cin >> A[i];

    int lb = 0;
    int ub = INF;
    while (ub - lb > 1) {
        int mid = (ub + lb) / 2;
        if (f(mid)) {
            ub = mid;
        } else {
            lb = mid;
        }
    }

    cout << ub << endl;
}


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

using namespace std;

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	vector <int> a(5);
	for (int i = 0; i < 5; i++) {
		cin >> a[i];	
	}
	for (int i=0; i<5; i++) {
		if (a[i]==0) {
			cout << i+1;
			break;
		}
	}
	return 0;
	
}

Measured memory_bytes: 3616
n = int(input())
s = input()
cs = [1 if c=='#' else 0 for c in s]
ans = 0

bs = [0]
for c in cs:
    bs.append(bs[-1]+c)

us = [0]
for c in reversed(cs):
    us.append(us[-1] + 1 - c)
vs = list(reversed(us))

ans = min(bs[i] + vs[i] for i in range(len(bs)))

print(ans)


Measured memory_bytes: 22504
# encoding:utf-8
def main():
	n = int(input())
	bars = list(map(int, input().split()))

	bars.sort(reverse = True)

	d = {}
	used = []

	for bar in bars:
		if bar in d:
			d[bar] += 1
			if d[bar] == 2:
				used.append(bar)
				d[bar] = 0
		else:
			d[bar] = 1

		if len(used) == 2:
			print(used[0] * used[1])
			break
	else:
		print(0)

if __name__ == '__main__':
	main()

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main{
    public static void main ( String[] args ) throws Exception {
        Scanner in = new Scanner( System.in );
        int a = in.nextInt();
        String op = in.next();
        int b = in.nextInt();
        switch ( op ){
            case "+":
                System.out.println( a + b );
                break;
            case "-":
                System.out.println( a - b );
                break;
        }
    }
}

Measured memory_bytes: 9684
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long int lli;
const lli N=1e18;
bool isOverflow(lli a, lli b) 
{
    lli result = a * b; 
    if ((a == result / b)  && (result<=1000000000000000000))
        return false;
    else
        return true; 
} 

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    lli n;
    cin>>n;
    lli i,a[n],ans=1,flag=0;
    
    for(i=0;i<n;i++) 
    {
        cin>>a[i];
        if(a[i]==0) flag=1;
    }
    
    if(flag) return cout<<0, 0;
    
    for(i=0;i<n;i++) 
    {
        if(ans>(N/a[i])) return cout<<-1, 0;
        
        ans*=a[i];
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 4408
// 見せてやるぜ、奇跡ってやつをよぉ……
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h, w, t;
    cin >> h >> w >> t;
    int maxhw = max(h, w);
    cout << (t + maxhw - 1) / maxhw << '\n';
    return 0;
}


Measured memory_bytes: 256
import std.stdio, std.math, std.algorithm, std.array, std.string, std.conv, std.container, std.range;
T Read(T)() { return readln.chomp.to!(T); }
T[] Reads(T)() { return readln.split.to!(T[]); }
alias read = Read!(int);
alias reads = Reads!(int);

void main() {
    int x, a; readf("%d %d\n", &x,&a);
    writeln([10, 0][x < a]);
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

class Main {
	public static void main(String[] args)
	{
		FastScanner in=new FastScanner();
		char[] arr=in.next().toCharArray();
		int sum=0;
		for(char c:arr)
			sum+=(int)c-48;
		if(sum%9==0)
			System.out.println("Yes");
		else
			System.out.println("No");
	}

static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}
}

Measured memory_bytes: 36600
#include <bits/stdc++.h>
            using namespace std;
            typedef long long ll;
            ll INF =1e9+7;
            typedef pair<ll,ll> ii;
            #define f(i,a,b) for(long long i = a;i < b;i++)
            #define rf(i,a,b) for(long long i=a;i>=b;i--)
            #define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
            #define w(t) while(t--)
            #define c(n); cin>>n;
            #define p(n) cout<<n;
            #define pl(n) cout<<n<<endl;
            #define ps(n); cout<<n<<" ";
            #define F first
            #define S second
            #define pb(a) push_back(a)
            int main(void){
                fastio;
                map<string,ll>mp;
                mp["SAT"] = 1;
                mp["FRI"] = 2;
                mp["THU"] = 3;
                mp["WED"] = 4;
                mp["TUE"] = 5;
                mp["MON"] = 6;
                mp["SUN"] = 7;
                string s;
                c(s);
                pl(mp[s]);
            }


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

#define WHITE 0
#define BLACK 1
#define inf 2000

int main(){
  int n, mincost, sum=0;
  int A[101][101]={}, color[101], d[101], pi[101];
  int i, j, u, v;

  scanf("%d", &n);
  if(n < 0 || 100 < n)
    exit(1);

  for(i = 0; i < n; i++){
    for(j = 0; j < n; j++){
      scanf("%d", &A[i][j]);
      if(A[i][j] != -1 && (A[i][j] < 0 || 2000 < A[i][j]))
	exit(2);
    }
  }

  for(u = 0; u < n; u++){
    d[u] = inf;
    pi[u] = -1;
    color[u] = WHITE;
  }
  d[0] = 0;

  while(1){
    mincost = inf;
    for(i = 0; i < n; i++){
      if((color[i] != BLACK) && (d[i] < mincost)){
	  mincost = d[i];
	  u = i;
      }
    }
    if(mincost == inf)
      break;
    color[u] = BLACK;
    for(v = 0; v < n; v++){
      if((color[v] != BLACK) && (A[u][v] != -1) && (A[u][v] < d[v])){
	pi[v] = u;
	d[v] = A[u][v];
      }
    }
  }

  for(i = 0; i < n; i++)
    sum += d[i];
  
  printf("%d\n", sum);

  return 0;
}

Measured memory_bytes: 648
import sys

def input(): return sys.stdin.readline()[:-1]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def MATINT(h): return [list(map(int, input().split())) for _ in range(h)]
def MATSTR(h): return [input() for _ in range(h)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
inf = float('inf')
mod = 10 ** 9 + 7

def main():
    N = INT()
    V = sorted(LIST())
    tmp = V[0]
    for i in range(1, N):
        tmp = (tmp + V[i])/2
    print(tmp)

if __name__ == '__main__':
    main()


Measured memory_bytes: 38384
//
//  main.cpp
//  B - Maximum Sum
//
//  Created by 张栩浩 on 2018/5/5.
//  Copyright © 2018年 张栩浩. All rights reserved.
//

#include <iostream>
using namespace std;
int main()
{
    int a,b,c;
    int k;
    cin>>a>>b>>c;
    cin>>k;
    int n;
    int sum=a+b+c;
    n=max(a,b);
    n=max(n,c);
    sum=sum-n;
    while(k--)
    {
        n=2*n;
    }
    cout<<sum+n<<endl;
    return 0;
}


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

x=[]
s=[]
for i in range(n):
    p,q=map(int,input().split())
    x.append(p)
    s.append(q)
r=[0]
for i in range(n):
    r.append(r[-1]+s[i])
b=[]
for i in range(n):
    b.append(r[i+1]-x[i])
a=[-10**30]*n
a[-1]=b[-1]
for i in range(n-1):
    a[n-i-2]=max(a[n-i-1],b[n-i-2])

ans=0
for i in range(n):
    ans=max(ans,a[i]-(r[i]-x[i]))
print(ans)

Measured memory_bytes: 37944
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define f first
#define s second
#define pb push_back
#define eb emplace_back
#define mk make_pair
#define mt make_tuple
#define MOD 1000000007
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
#define all(x) x.begin(), x.end()
#define vi vector<int>
#define vl vector <long long int>
#define pii pair <int,int>
#define pll pair <long long int, long long int>
#define vpii vector< pair<int,int> >
#define vpll vector < pair <long long int,long long int> >
#define boost ios::sync_with_stdio(false); cin.tie(0)
using namespace std;
const int inf = 1e9 + 5;
const ll inf64 = 1e18 + 5;

const int MAX = 1e4 + 5;
const int N = 105;
int dp[MAX][N][2], d;
vector <int> v;

int rec(int pos, int sum, bool f)
{
	if(pos == v.size()) return (sum == 0);
	int &res = dp[pos][sum][f];
	if(~res) return res;
	
	int lim = (f ? 9 : v[pos]);
	res = 0;
	
	for(int i = 0; i <= lim; i++) {
		int nsum = (sum + i) % d;
		res += rec(pos + 1, nsum, f || (i < v[pos]));
		res %= MOD;
	}
	return res;
}
int main()
{
	boost;
	string s;
	cin >> s;
	cin >> d;
	
	for(char c : s)
	v.pb(c - '0');
	
	memset(dp, -1, sizeof dp);
	cout << (rec(0, 0, 0) - 1 + MOD) % MOD;
}


Measured memory_bytes: 12716
import * as fs from 'fs';

namespace AtCoder {
    export interface Paramable {
        args: string[][];
    }

    export interface Task {
        main(this: Task): void;
    }
}

namespace AtCoder.abc084 {
    export class TaskB implements AtCoder.Task, AtCoder.Paramable {
        public constructor(readonly args: string[][]) {
        }

        public main(this: TaskB): void {
            const [a, b]: number[] = this.args[0].map(Number);
            const reg = new RegExp(`^\\d{${a}}-\\d{${b}}$`);
            const result = reg.test(this.args[1][0]);
            const ans: string = result ? 'Yes' : 'No';
            console.log(ans);

        }
    }

    const args: string[][] = fs.readFileSync('/dev/stdin', 'utf8').trim().split('\n').map(r => r.split(' '));
    const task: AtCoder.Task = new TaskB(args);
    task.main();
}

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

int main()
{
    int h, w;
    cin >> h >> w;
    int cnt = 0;
    rep(i, h) {
        string a;
        cin >> a;
        rep(j, w) {
            if(a[j] == '#') cnt++;
        }
    }
    if(cnt == h + w - 1) cout << "Possible" << endl;
    else cout << "Impossible" << endl;
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
using namespace std;
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/*************************************/

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  
  int n;
  cin >> n;
  vector<vector<int>> a(3, vector<int>{-1});
  i64 ans = 1;
  for (int i = 0; i < n; ++i) {
    int x; cin >> x;
    int t = 0;
    for (auto &v : a) {
      t += v.back() == x - 1; 
    }
    ans = (ans * t) % MOD;
    for (auto &v : a) {
      if (v.back() == x - 1) {
        v.push_back(x);
        break;
      } 
    }
  }
  kek(ans);
  
  return 0;
}


Measured memory_bytes: 896
import math
N=int(input())
order=math.floor(math.log10(N))+1
ans=0
for od in range(1,order+1,2):
    if N<10**od:
        ans+=(N-10**(od-1)+1)
        break
    else:
        ans+=9*10**(od-1)
        od+=1
print(ans)

Measured memory_bytes: 9060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#include <boost/multiprecision/cpp_int.hpp>
//typedef boost::multiprecision::cpp_int ll;
typedef long double dd;
#define i_7 (ll)(1E9+7)
//#define i_7 998244353
#define i_5 i_7-2
ll mod(ll a){
    ll c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
typedef pair<ll,ll> l_l;
ll inf=(ll)1E16;
#define rep(i,l,r) for(ll i=l;i<=r;i++)
#define pb push_back
ll max(ll a,ll b){if(a<b)return b;else return a;}
ll min(ll a,ll b){if(a>b)return b;else return a;}
void Max(ll &pos,ll val){pos=max(pos,val);}//Max(dp[n],dp[n-1]);
void Min(ll &pos,ll val){pos=min(pos,val);}
void Add(ll &pos,ll val){pos=mod(pos+val);}
dd EPS=1E-9;
#define fastio ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main(){
    ll n,m,Q;cin>>n>>m>>Q;
    ll l[m],r[m];
    ll x[n+1][n+1];
    rep(i,0,n)rep(j,0,n)x[i][j]=0;
    rep(i,0,m-1){
        cin>>l[i]>>r[i];
        x[l[i]][r[i]]++;
    }
    ll sum[n+1][n+1];
    rep(i,0,n)sum[0][i]=0;
    rep(i,0,n){
        rep(j,1,n){
            sum[j][i]=sum[j-1][i]+x[j][i];
        }
    }
    ll p[Q],q[Q];
    rep(i,0,Q-1)cin>>p[i]>>q[i];
    ll ans;
    rep(i,0,Q-1){
        ans=0;
        rep(j,p[i],q[i]){
            ans=ans+sum[q[i]][j]-sum[p[i]-1][j];
        }
        cout<<ans<<endl;
    }
    
    return 0;
}


Measured memory_bytes: 9472
#include <bits/stdc++.h>
#include <cstdint>
#define pi 3.14159
#define ll long long
// #define int ll
#define ull unsigned long long
#define pb push_back
#define PF push_front //deque
#define mp make_pair
#define pq priority_queue
#define mod 1000000007
#define f first
#define s second
#define pii pair< int, int >
#define vi vector<int>
#define vpii vector<pii>
#define debug(v) for(auto i:v) cout<<i<<" ";
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,b,a) for(int i=b;i>=a;i--)
#define fori(a) for(auto i : a )
#define all(a) begin(a), end(a)
#define set(a,b) memset(a,b,sizeof(a))
#define sz(a) a.size()
#define tc int t; cin >> t; while(t--)
 
using namespace std;
string repeat(string s, int n) {
    string s1 = "";
    for (int i=0; i<n;i++)
        s1+=s;
    return s1;
}
string getString(char x) {
    string s(1, x);
    return s;
}
 
void optimizeIO(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
}
int gcd(int a, int b){
    if (a == 0)  return b;
    return gcd(b % a, a);
}
void  solve(){
  int n;
  cin>>n;
  int a[n+1];
  rep(i,1,n+1) cin>>a[i];
  vector<pair<ll,ll>> dp(n+1,{0,0});
  dp[0].f=0;
  dp[0].s= -1e15;
  rep(i,1,n+1){
    dp[i].f = max(dp[i-1].f+a[i], dp[i-1].s-a[i]);
    dp[i].s = max(dp[i-1].f-a[i], dp[i-1].s+a[i]);
    // cout<<dp[i].f<<" "<<dp[i].s<<endl;
  }
  cout<<dp[n].f<<endl;
}
int main(){
    optimizeIO();
    solve();
}

Measured memory_bytes: 5308