akhauriyash/Code-Regression huggingface dataset:
using System;

class Program
{
    static void Main(string[] args)
    {
        var n = int.Parse(Console.ReadLine());
        var A = new int[n];
        var temp = Console.ReadLine().Split(' ');
        for (int i = 0; i < n; i++)
        {
            A[i] = int.Parse(temp[i]);
        }

        var ans = gcd(A);
        Console.WriteLine(ans);
    }

    static int gcd(int[] A)
    {
        var ans = A[0];
        for (int i = 1; i < A.Length; i++)
        {
            ans = gcd(ans, A[i]);
        }
        return ans;
    }

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

Measured memory_bytes: 20064
#include "bits/stdc++.h"
using namespace std;

typedef long long ll;
int main() {
	int k;
	cin >> k;
	string s;
	cin >> s;
	//int n = (int)s.size();
	if ((int)s.size() <= k) {
		cout << s << endl;
	}else {
		string ans = "";
		for (int i = 0; i < k; ++i) {
			ans += s[i];
		}
		ans += "...";
		cout << ans;
	}
	return 0;
}




















Measured memory_bytes: 3632
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <list>
#include <stack>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

int fun(string s){
    int sum=0;
    for (int i=0;i<sz(s);i++){
        sum = sum*10+(s[i]-'0');
    } return sum;
}

inline void solve(){
    string s; cin>>s; 
    int n=sz(s),ans=0;
    for (int i=0;i<(1<<(n-1));i++){
        map <int,int> p; 
        for (int j=0;j<n-1;j++){
            if (i&(1<<j)){
                p[j+1] = 1;
            }
        }
        string k;
        for(int j=0;j<n;j++){
            if (p[j]) k += '+';
            k += s[j];
        }
        string h;
        for (int j=0;j<sz(k);j++){
            if (k[j]=='+'){
                ans += fun(h);
                h = "";
            }
            else h += k[j];
        }
        ans += fun(h);
    }
    cout << ans << endl;
}
/*
123
4
00
01
10
11

*/

signed main()
{
    int n=1; // cin>>n;
    while (n--) solve();
    return 0;
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <numeric>
using namespace std;
typedef long long int ll;      
int main()
{   
	ll l,r,m=2019,mini=pow(10,17);
	cin>>l>>r;
	if(l/m!=r/m)
	{
		l=l%m;
	r=r%m;
	l=0;
	r=max(l,r);

	}
	else{
	l=l%m;
	r=r%m;
}
	for (int i = l; i <= r; ++i)
	{
		for (int j=i+1;j<=r; ++j)
		{
			ll z=(i*j)%m;
			if(z<mini)mini=z;
		}
	}
	cout<<mini<<"\n";
}

Measured memory_bytes: 256
//
// Created by yamunaku on 2019/08/17.
//

#include <bits/stdc++.h>

using namespace std;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repl(i, l, r) for(int i = (l); i < (r); i++)
#define per(i, n) for(int i = ((n)-1); i >= 0; i--)
#define perl(i, l, r) for(int i = ((r)-1); i >= (l); i--)
#define all(x) (x).begin(),(x).end()
#define MOD9 998244353
#define MOD1 1000000007
#define IINF 1000000000
#define LINF 1000000000000000000
#define SP <<" "<<
#define CYES cout<<"Yes"<<endl
#define CNO cout<<"No"<<endl
#define CFS cin.tie(0);ios::sync_with_stdio(false)
#define CST(x) cout<<fixed<<setprecision(x)

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> mti;
typedef vector<ll> vl;
typedef vector<vector<ll>> mtl;

int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    char mic = 'z'+1;
    rep(i, n){
        mic = min(mic, s[i]);
    }
    string t = s;
    reverse(all(t));
    s += t;
    if(k == 1){
        string mis(1, 'z' + 1);
        rep(i, n + 1){
            mis = min(mis, s.substr(i, n));
        }
        cout << mis << endl;
        return 0;
    }else if(k >= 14){
        string ans(n, mic);
        cout << ans << endl;
        return 0;
    }
    vector<ll> c(2 * n, 0);
    c[0] = (s[0] == mic ? 1 : 0);
    repl(i, 1, 2 * n){
        if(s[i] == mic) c[i] = c[i - 1] + 1;
        else c[i] = 0;
    }
    ll maxc = c[n - 1];
    repl(i, n, 2 * n){
        maxc = max(maxc, c[i]);
    }
    if((maxc << (k - 1)) >= n){
        string ans(n, mic);
        cout << ans << endl;
        return 0;
    }
    reverse(all(s));
    string ans(1, 'z' + 1);
    int len = n - maxc * ((1 << (k - 1)) - 1);
    rep(i, n+1){
        ans = min(ans, s.substr(i, len));
    }
    string ans2(maxc * ((1 << (k - 1)) - 1), mic);
    ans = ans2 + ans;
    cout << ans << endl;
    return 0;
}


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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

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

template<class S, class T> ostream& operator << (ostream& os, const pair<S, T> v){
  os << "(" << v.first << ", " << v.second << ")"; return os;
}
template<class T> ostream& operator << (ostream& os, const vector<T> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << " ";} os << v[i];} return os;
}
template<class T> ostream& operator << (ostream& os, const vector<vector<T>> v){
  for(int i = 0; i < v.size(); i++){if(i > 0){os << endl;} os << v[i];} return os;
}

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

    ll N;
    cin >> N;
    vector<ll> p(N);
    REP(i, N) cin >> p[i];
    ll cnt = 0;
    REP(i, N) if(p[i] != i+1) cnt++;

    cout << (cnt <=2 ? "YES" : "NO") << endl;
    return 0;
}

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

signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int n,a,b,c,d,l,r,i;
	cin>>n>>a>>b>>c>>d;
	l=r=a;
	for(i=2;i<=n;i++)
	{
		if(b*2<l+r)
		{
			l-=d;
			r-=c;
		}
		else
		{
			r+=d;
			l+=c;
		}
	}
	if(l<=b && b<=r)
		cout<<"YES\n";
	else
		cout<<"NO\n";
	
	return 0;
}


Measured memory_bytes: 256
k = gets.to_i

answer = (1..k).to_a.repeated_combination(3).map { |a, b, c|
  number = [a, b, c].uniq.size
  case number
  when 1 then a.gcd(b).gcd(c) * 1
  when 2 then a.gcd(b).gcd(c) * 3
  when 3 then a.gcd(b).gcd(c) * 6
  end
}.sum

puts answer


Measured memory_bytes: 25248
#include "bits/stdc++.h"
using namespace std;

int main(void) {
	int a, b;
	cin >> a >> b;

	int d[5], count = 0;

	for(int i=a;i<=b;i++) {
		int num = i;
		for(int j=0;j<5;j++) {
			d[j] = num%10;
			num /= 10;
		}
		if(d[0] == d[4] && d[1] == d[3]) count++;
	}

	cout << count << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
namespace Dinic{
	#define N 205
	#define M 80005
	#define INF 0x3f3f3f3f
	struct edge{
		int flow,t,next;
	}e[M];int ecnt,head[N];
	void addedge(int f,int t,int fl){
		e[++ecnt]=(edge){fl,t,head[f]};head[f]=ecnt;
		e[++ecnt]=(edge){0,f,head[t]};head[t]=ecnt;
	}
	//----------------
	int S,T;
	int dis[N],cur[N];
	bool BFS(){
		memset(dis,0x3f,sizeof(dis));
		dis[S]=0;queue<int> que;que.push(S);
		while(!que.empty()){
			int u=que.front();que.pop();
			for(int i=head[u];i;i=e[i].next){
				if(e[i].flow!=0&&dis[e[i].t]==0x3f3f3f3f){
					dis[e[i].t]=dis[u]+1,que.push(e[i].t);
				}
			}
		}
		return dis[T]!=INF;
	}
	
	int DFS(int u,int a){
		if(u==T||a==0) return a;
		int ret=0;
		for(int &i=cur[u];i;i=e[i].next){
			if(e[i].flow==0||dis[e[i].t]!=dis[u]+1) continue;
			int f=DFS(e[i].t,a<e[i].flow? a:e[i].flow);
			if(f){
				e[i].flow-=f;e[i^1].flow+=f;
				ret+=f;a-=f;
				if(a==0) return ret;
			}
		}
		return ret;
	}
	int work(int S1,int T1){
		S=S1,T=T1;
		int ret=0;
		while(BFS()){
			memcpy(cur,head,sizeof(cur));
			ret+=DFS(S1,INF);
		}
		return ret;
	}
	void initialize(){
		ecnt=1;memset(head,0,sizeof(head));
	}
	#undef N
	#undef M
	#undef INF
}

#define N 205
#define M 10000007

int n;
int pos[N],pcnt;
int dp[N][N];
bool p[M];
int main(){
    scanf("%d",&n);
    for(int i=1,t;i<=n;i++){
        scanf("%d",&t);
        if(pcnt>0&&pos[pcnt]==t) pos[pcnt]=t+1;
        else pos[++pcnt]=t,pos[++pcnt]=t+1;
    }
    for(int i=2;i<M;i++){
        p[i]=!p[i];
        if(p[i])
           for(int j=i+i;j<M;j+=i) p[j]=true;
    }
    int nodd=0,neven=0;
    for(int i=1;i<=pcnt;i++)
        pos[i]%2==0? neven++:nodd++;
    
    Dinic::initialize();
    for(int i=1;i<=pcnt;i++)    
        for(int j=1;j<=pcnt;j++)
            if(pos[i]%2==0 && pos[j]%2==1 && p[abs(pos[i]-pos[j])])
                Dinic::addedge(i,j,1);
    int S=pcnt+1,T=S+1;
    for(int i=1;i<=pcnt;i++)
        if(pos[i]%2==0) Dinic::addedge(S,i,1);
        else Dinic::addedge(i,T,1);
    
    int ans=Dinic::work(S,T);
    cout<<ans+(nodd-ans)/2*2+(neven-ans)/2*2+(nodd-ans)%2*3;
    return 0;
}

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

//前処理で西と東の予選をO(n)でやっておいて決勝をO(1)で行うというイメージ
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a.at(i);

    vector<int> lm(n); //iより左にあるものたちの中でのmax
    vector<int> rm(n); //iより右にあるものたちの中でのmax

    for(int i=1;i<n;i++){
        lm[i] = max(lm[i-1],a[i-1]);
    }
    //a、rmのインデックスが最大n-1なので、それより1左にずらしてn-2
    for(int i=n-2; i>=0;i--){
        rm[i] = max(rm[i+1],a[i+1]);
    }
    rep(i,n) cout << max(lm[i],rm[i]) << endl;

}

Measured memory_bytes: 5640
#include<iostream>
#include<algorithm>
#include<string.h>
#include<string>
using namespace std;
const int maxn = 1000005;
int n;
int a[maxn], b[maxn], c[maxn];
int main()
{
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 0; i < n; i++)
		cin >> b[i];
	for (int i = 0; i < n; i++)
		cin >> c[i];
	sort(a, a + n); sort(b, b + n); sort(c, c + n);
	long long sum = 0;
	long long temp1=0, temp2 = 0;
	for (int i = 0; i < n; i++)
	{
		while (a[temp1] < b[i] && temp1 < n)
			temp1++;
		while (c[temp2] <= b[i] && temp2 < n)
			temp2++;
		sum += temp1*(n - temp2);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 8832
import java.lang.reflect.Array;
import java.util.*;
public class Main {
	Runner[] runner = new Runner[8];//????????\????????????
	Runner[] winner = new Runner[6];//????????????1?????¨???????????\??????
	Runner[] loser = new Runner[18];//?????????3?????\????????\????????????
	void doIt(){
		Scanner sc = new Scanner(System.in);
		int l = 0, w = 0;//loser,winner????¨???¶??¨
		int num;
		String time;
		for(int pare = 0; pare < 3; pare++){
			for(int run = 0; run < runner.length; run++){
				num = sc.nextInt();
				time = sc.next();
				runner[run] = new Runner(num,time);
			}
			Arrays.sort(runner);
			for(int win = 0; win < winner.length/3; win++){
				winner[w] = runner[win];
				w++;
			}
			for(int lose = 0; lose < loser.length/3; lose++){
				loser[l] = runner[lose+2];
				l++;
			}
		}
		Arrays.sort(loser);
		for(int i = 0; i < winner.length; i++){
			System.out.println(winner[i].num + " " + winner[i].time);
		}
		System.out.println(loser[0].num + " " + loser[0].time);
		System.out.println(loser[1].num + " " + loser[1].time);
	}
	public static void main(String[] args){
		new Main().doIt();
	}
	class Runner implements Comparable<Runner>{
		int num;
		String time;
		Runner(int num, String time) {
			this.num = num;
			this.time = time;
		}
		@Override
		public int compareTo(Runner r){
			return time.compareTo(r.time);
		}
	}
}

Measured memory_bytes: 26252
/*
靠，真想自己一个大嘴巴，一个比?大小的函数都尼?写?偏了
*/
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<string>
#include<math.h>
#include<algorithm>
#define MAXVAL 999999999;
using namespace std;

int dataSet[46][46];
int resultSet[46];
int N;
int result[46];


void Find_Value (int m)
{
	memset(result,0,sizeof(resultSet));
	for (int k=0;k<=m;k++)
	{
		for (int i=0;i<=m;i++)
		{
			for (int j=0;j<=m;j++)
			{
				dataSet[i][j] =  min(dataSet[i][j],dataSet[i][k] + dataSet[k][j]);
			}
		}
	}
}

int main ()
{
	while (cin>>N && N!=0)
	{
		for (int i=0;i<=15;i++)
		{
			for (int j=0;j<=15;j++)
			{
				if ( i == j)
				{
					dataSet[i][j] = 0;
				}
				else
				{
					dataSet[i][j] = 999999;
				}
			}
		}
		int m = 0;
		for (int i=0;i<N;i++)
		{
			int x,y,value;
			cin>>x>>y>>value;
			dataSet[x][y] = dataSet[y][x] = min(dataSet[x][y],value);
			m = max(max(m,x),y);	
		}
		Find_Value (m);
		int ans =  999999;
		int every_total = 0;
		int Find_pos = 0;
		for (int i=0;i<=m;i++)
		{
			every_total = 0;
			for (int j=0;j<=m;j++)
			{
				if (dataSet[i][j] !=  999999)
				{
					every_total += dataSet[i][j];
				}
			}
			if (ans > every_total)
			{
				Find_pos = i;
				ans = every_total;
			}
		}
		cout<<Find_pos<<" ";
		cout<<ans<<endl;

	}
	return 0;
}

Measured memory_bytes: 3068
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text.RegularExpressions;

public class Solution
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine());
        var S = Console.ReadLine();

        int prevLen = -1;
        do
        {
            prevLen = S.Length;
            S = Regex.Replace(S, @"(.)\1+", @"$1");
        }
        while (S.Length != prevLen);

        Console.WriteLine(S.Length);
    }
}

Measured memory_bytes: 20944
N, M = map(int, input().split())
KS = [list(map(int, input().split())) for i in range(M)]
P = list(map(int, input().split()))

ans = 0
for i in range(2**N):
    bit = str(bin(i))[2:].zfill(N)
    for (_, *s), p in zip(KS, P):
        ons = 0
        for si in s:
            ons += int(bit[si-1])
        if ons % 2 != p:
            break
    else:
        ans += 1

print(ans)

Measured memory_bytes: 41456
n,m = map(int,input().split())
Check1 = [False]*n
Check2 = [False]*n
for i in range(m):
    a,b = map(int,input().split())
    if a ==1:
        Check1[b-1] = True
    elif a == n:
        Check2[b-1] = True
    elif b == 1:
        Check1[a-1] = True
    elif b == n:
        Check2[a-1] = True
for i in range(n):
    if Check1[i] and Check2[i]:
        print('POSSIBLE')
        exit()
print('IMPOSSIBLE')

Measured memory_bytes: 6132
#include<iostream>
#include<algorithm>
using lint=int64_t;
using namespace std;

int main()
{
	int N,K;
	lint a[100010]={};

	cin >> N >> K;
	for(int i=1;i<=N;i++)
		cin >> a[i];

	lint sum[100010]={};
	lint sump[100010]={};
	for(int i=1;i<=N;i++)
	{
		sum[i]=sum[i-1]+a[i];
		sump[i]=sump[i-1];
		if(a[i]>0)
			sump[i]+=a[i];
	}

	lint ans=0;
	for(int l=1;l<=N-K+1;l++)
	{
		int r=l+K-1;
		lint tans=sump[l-1]+max((lint)0,sum[r]-sum[l-1])+(sump[N]-sump[r]);
		ans=max(ans,tans);
	}

	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 2560
#!/usr/bin/env python
"""M-SOLUTIONS プロコンオープン 2020: C - Marks
https://atcoder.jp/contests/m-solutions2020/tasks/m_solutions2020_c
"""


def main():
    N, K = list(map(int, input().split()))
    As = list(map(int, input().split()))

    for i in range(0, N-K):
        prev_score = As[i]
        score = As[K + i]
        if prev_score < score:
            print('Yes')
        else:
            print('No')


if __name__ == '__main__':
    main()


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

using namespace std;
using ll = long long;
const int kMod = 1e09 + 7;

int main(int argc, char const *argv[]) {
  string s;
  cin >> s;
  int n = s.size();
  vector<vector<ll>> table(n + 1, vector<ll>(13, 0));

  table[n][0] = 1;
  int keta = 1;

  for (int i = n - 1; i >= 0; i--) {
    if (s[i] != '?') {
      int tmp = s[i] - '0';

      for (int j = 0; j < 13; j++) {
        table[i][(j + keta * tmp) % 13] += table[i + 1][j];
        table[i][(j + keta * tmp) % 13] %= kMod;
      }

    } else {
      for (int j = 0; j < 13; j++) {
        for (int k = 0; k < 10; k++) {
          table[i][(j + keta * k) % 13] += table[i + 1][j];
          table[i][(j + keta * k) % 13] %= kMod;
        }
      }
    }
    keta = keta * 10 % 13;
  }

  cout << table[0][5] << endl;

  return 0;
}


Measured memory_bytes: 13696
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
bool c[300010];
int N,Q,maxc=-1,ans=0;
int s[300010];
int main()
{
	cin >> N >> Q;
	for(int i=0;i<N;i++)
	{
		int a;
		cin >> a;
		maxc=max(maxc,a);
		c[a]=true;
	}
	for(int i=0;i<=maxc;i++)
	{
		if(c[i])s[i+1]=i;
		else s[i+1]=s[i];
	}
	for(int i=0;i<Q;i++)
	{
		int q;
		cin >> q;
		ans=0;
		for(int d=maxc;maxc;)
		{
			int p=d%q;
			ans=max(ans,p);
			if(d-p<=0)break;
			d=s[d-p];
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 2624
#include <iostream>
#include <vector>
#include <cstdio>
#include <algorithm>
#include <set>
#include <map>
#include <cassert>
#include <numeric>
#include <string>
#include <cstring>
#include <cmath>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

typedef long long int int64;




int main(int,  char **)
{
#ifdef LOCAL
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif

    long long n;
    scanf("%lld", &n);
    vector <int> v;
    int ans = 0;
    while (n > 0)
    {
        ans += n % 10;
        v.push_back(n % 10);
        n /= 10;
    }
    if ((int) v.size() > 1)
        ans = max(ans, v.back() - 1 + ((int) v.size() - 1) * 9);

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



	return 0;
}



Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i = (a); i < (b); ++i)
#define rrep(i,a,b) for(int i = (b); i --> (a);)
#define all(v) (v).begin(),(v).end()
#define trav(x,v) for(auto &x : v)
#define sz(v) int(v.size())
typedef vector<int> vi;
typedef long long ll;
typedef pair<int,int> pii;

int main(){
	int n;
	cin >> n;
	vi ans;
	int pos = 2;
	while(sz(ans) < n-2){
		while(__gcd(210, pos) == 1) ++pos;
		ans.push_back(pos);
		pos++;
	}
	int sum = 0;
	trav(x, ans) sum += x;
	sum %= 210;
	while(__gcd(210,pos)==1 || __gcd(210, sum+pos) == 1) ++pos;
	ans.push_back(pos);
	sum += pos;
	++pos;
	while((pos + sum)%210 != 0) ++pos;
	ans.push_back(pos);
	trav(x, ans) cout << x << ' ';
	cout << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <vector>
#include <string>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <stack>
#include <set>
#include <queue>
#include <algorithm>
#include <deque>
using namespace std;

#define INF 1e18
#define int long long

int n, ans = 0;

void dfs(int x, int a, int b, int c) {
    if(x > n) return;
    if(a && b && c) ans++;
    dfs(10 * x + 3, 1, b, c);
    dfs(10 * x + 5, a, 1, c);
    dfs(10 * x + 7, a, b, 1);
}

signed main() {
    cin >> n;
    dfs(0, 0, 0, 0);
    cout << ans << endl;
}


Measured memory_bytes: 256
import sys
import math
input = sys.stdin.readline

x = int(input())
k = 200

def main():
    for a in range(-k, k):
        for b in range(-k, k):
            if a**5 - b**5 == x:
                print(a, b)
                return
    return 1/0

if __name__ == '__main__':
    main()


Measured memory_bytes: 64612
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String[] s = new String[n];
        for (int i = 0; i < n; i++) {
            s[i] = toSortedString(sc.next());
        }
        Map<String, Counter> map = new HashMap<>();
        long c = 0L;
        for (int i = 0 ; i < n; i++) {
            if (map.containsKey(s[i])) {
                c += map.get(s[i]).increment();
            } else {
                map.put(s[i], new Counter());
            }
        }
        System.out.println(c);
    }
    private static String toSortedString(String s) {
        char[] array = s.toCharArray();
        Arrays.sort(array);
        return new String(array);
    }
    private static class Counter {
        private long c = 1L;
        private long increment() {
            return this.c++;
        }
    }
}


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

int main() {
  int W,a,b;
  cin>>W>>a>>b;
  if (b>a+W) cout << b-a-W<<endl;
  else if (a > b+W) cout << a-b-W<<endl;
  else cout << 0 <<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define pll pair<ll, ll>
#define vint vector<int >
#define vll vector<ll >
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int n;
    cin >> n;
    if(n%10==3){
        cout << "bon" << endl;
    }else if(n%10==0 || n%10==1 || n%10==6 || n%10==8){
        cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }
    return 0;
}

Measured memory_bytes: 3636
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int ans=0;
    for (int i=1; i<=n; i++){
        int t;
        cin>>t;
        if (i%2==1&&t%2==1) ans++;
    }
    cout<<ans;
}

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

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

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

template <class M>
struct SegmentTree{
    using T = typename M::T;
    int sz;
    vector<T> seg;
    explicit SegmentTree(int n) {
        sz = 1;
        while(sz < n) sz <<= 1;
        seg.assign(2*sz, M::e());
    }

    void set(int k, const T &x){ seg[k + sz] = x; }

    void build(){
        for (int i = sz-1; i > 0; --i) seg[i] = M::f(seg[2*i], seg[2*i+1]);
    }

    void update(int k, const T &x){
        k += sz;
        seg[k] = x;
        while (k >>= 1) seg[k] = M::f(seg[2*k], seg[2*k+1]);
    }

    T query(int a, int b){
        T l = M::e(), r = M::e();
        for(a += sz, b += sz; a < b; a >>=1, b>>=1){
            if(a & 1) l = M::f(l, seg[a++]);
            if(b & 1) r = M::f(seg[--b], r);
        }
        return M::f(l, r);
    }

    template<typename C>
    int find(int t, C &c, T &val, int k, int l, int r){
        if(r-l == 1){
            val = f(val, seg[k]);
            return c(val) ? k-sz : -1;
        }
        int m = (l+r) >> 1;
        if(m <= t) return find(t, c, val, (k << 1) | 1, m, r);
        if(t <= l && !c(val = f(val, seg[k]))) return -1;
        int lv = find(t, c, val, (k << 1) | 0 , l, m);
        if(~lv) return lv;
        return find(t, c, val, (k << 1) | 1, m, r);
    }

    template<typename C>
    int find(int t, C &c){
        T val = M::e();
        return find(t, c, val, 1, 0, sz);
    }
    T operator[](const int &k) const { return seg[k + sz]; }
};


struct Monoid{
    using T = pair<int, int>;
    static T f(T a, T b) {
        if(a.first != b.first) return a.first < b.first ? b : a;
        return a.second < b.second ? a : b;
    }
    static T e() { return {0, 0}; }
};

int main() {
    int n, q;
    cin >> n >> q;
    SegmentTree<Monoid> seg(n);
    vector<int> val(n);
    for (int i = 0; i < n; ++i) {
        seg.set(i, {0, i});
    }
    seg.build();
    for (int i = 0; i < q; ++i) {
        int a, b;
        scanf("%d %d", &a, &b); a--;
        val[a] += b;
        seg.update(a, {val[a], a});
        auto res = seg.query(0, n);
        printf("%d %d\n", res.second+1, res.first);
    }
    return 0;
}


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

int solver(int h[], int num){
    int m =100;
    int pivot = 0;
    bool flag = true;
    for(int i=0;i<num;i++){
        //cout << h[i];
        m = min(m, h[i]);
    }
    //cout << endl;
    if(m > 0){
        for(int i=0; i<num; i++){
            h[i] -= m;
        }
    }
    for(int i=0; i<num; i++){
        if(h[i] != 0){
            flag = false;
        }
    }
    if(flag){
        //cout << 'a'<<m << endl;
        return m;
    }
    for(int i=0; i<num; i++){
        if(h[i] == 0){
            pivot = i;
            break;
        }
    }
    if(pivot == 0){
        return solver(&h[1], num-1) + m;
    }else if(pivot == num - 1){
        return solver(h, num-1) + m;
    }else{
        return solver(h, pivot) + solver(&h[pivot+1],num-pivot-1) + m;
    }
}

int main(){
    int N;
    int h[100] = {};
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> h[i];
    }
    cout << solver(h,N) << endl;

}


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 a = n%1000;
    
    int b = 1000-a;
    
    if(b != 1000){
      System.out.println(b);
    }else{
      System.out.println(0);
    }
  
  }
}

Measured memory_bytes: 35584
#include<iostream>
using namespace std;
using ll = long long;
int main(){
	ll a, b;
	cin >> a >> b;
	for(int i = 1; i < 2000; i++){
		if((ll)(i * 8 / 100) == a && (ll)(i / 10) == b){
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var a, b, c, x int
	fmt.Scan(&a, &b, &c, &x)

	ans := 0
	for i := 0; i <= a; i++ {
		for j := 0; j <= b; j++ {
			for k := 0; k <= c; k++ {
				if x == 500*i+100*j+50*k {
					ans++
				}
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include<stdio.h>

int a, b, c;

int main(void)
{
	int ans;
	
	scanf( "%d %d %d", &a, &b, &c );
	
	ans = a + b;
	
	if ( ans > b + c ) ans = b + c;
	if ( ans > c + a ) ans = c + a;
	
	printf( "%d\n", ans );
	
	return 0;
}

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

const int INF = 1<<28;

int N, E, T;
vector<int> W;
vector<int> G;
vector<vector<int> > S;

int main() {
  cin >> N >> E >> T;
  W.resize(N);
  for(int i = 0; i < N; ++i) cin >> W[i];
  for(int i = 0; i < N; ++i) if(W[i] == 0) W[i] = INF;
  S.resize(E);
  G.resize(E);
  for(int i = 0; i < E; ++i) {
    int C;
    cin >> G[i] >> C;
    G[i] -= 1;
    S[i].resize(C);
    for(int j = 0; j < C; ++j) {
      cin >> S[i][j];
      S[i][j] -= 1;
    }
  }

  bool update = true;
  while(update) {
    update = false;
    for(int i = 0; i < E; ++i) {
      int maxi = S[i].size();
      vector<int> v;
      for(int j = 0; j < S[i].size(); ++j) v.push_back(W[S[i][j]]);
      sort(v.begin(), v.end(), greater<int>());
      for(int j = 0; j < v.size(); ++j) {
	maxi = max(maxi, v[j] + j);
      }
      if(W[G[i]] > maxi) {
	update = true;
	W[G[i]] = maxi;
      }
    }
  }
  if(W[T-1] == INF) cout << -1 << endl;
  else cout << W[T-1] << endl;
  return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n-1);
  for(int i = 0; i < (n-1); i++) cin >> a.at(i);
  vector<int> b(n, 0);
  for(int i = 0; i < (n-1); i++) {
    b.at(a.at(i)-1)++;
  }
  for(int i = 0; i < n; i++) cout << b.at(i) << endl;
}

Measured memory_bytes: 4844
//بِسْمِ ٱللَّٰهِ ٱلرَّحْمَٰنِ ٱلرَّحِيمِ
#include <bits/stdc++.h>

using namespace std;

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

#define endl "\n"

const int MOD = 1000000007;


int main()
{
    ios::sync_with_stdio(0);cin.tie(0);
    
       int a,b,c;
       cin>>a>>b>>c;
       if(a+b>=c)cout<<"Yes"<<endl;
       else cout<<"No"<<endl;

    
    return 0;
}


Measured memory_bytes: 3640
import math
n = int(input())
x = list(map(int, input().split()))
y = list(map(int, input().split()))
manhattan = 0
euclid = 0
euclid2 = 0
chebishef = 0

for i, j in zip(x, y):
    tmp = abs(i - j)
    manhattan += tmp
    euclid += tmp * tmp
    euclid2 += tmp * tmp * tmp
    chebishef = max(chebishef, tmp)

print(manhattan)
print(math.sqrt(euclid))
print(math.pow(euclid2, 1 / 3))
print(chebishef)



Measured memory_bytes: 5688
import math


def isPrime(n):
    if n == 2:
        return True
    if n % 2 == 0:
        return False

    m = math.floor(math.sqrt(n)) + 1
    for p in range(3, m, 2):
        if n % p == 0:
            return False
    return True


X = int(input())

while True:
    if isPrime(X):
        print(X)
        break
    X += 1


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

int main(){
    int a, b, c, d, e;
    int out;
    scanf("%d %d %d %d %d", &a, &b, &c, &d, &e);
    if (a == 0){
        out = 1;
    } else if(b == 0){
        out = 2;
    } else if(c == 0){
        out = 3;
    } else if(d == 0){
        out = 4;
    } else {
        out = 5;
    }
    printf("%d", out);
    return 0;
}

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

int main(){
    int N, K;
    std::cin >> N >> K;
    std::vector< int > X(N);
    std::vector< int > Y(N);
    for(int i=0; i<N; i++){
        std::cin >> X[i] >> Y[i];
    }
    
    long long min = 4e18;
    for(int x1=0; x1<N; x1++){
        for(int x2=x1+1; x2<N; x2++){
            for(int y1=0; y1<N; y1++){
                for(int y2=y1+1; y2<N; y2++){
                    int xl = std::min(X[x1], X[x2]);
                    int xr = std::max(X[x1], X[x2]);
                    int yl = std::min(Y[y1], Y[y2]);
                    int yr = std::max(Y[y1], Y[y2]);
                    
                    int incnt = 0;
                    for(int i=0; i<N; i++){
                        if(X[i] >= xl && X[i] <= xr && Y[i] >= yl && Y[i] <= yr){
                            incnt++;
                        }
                    }
                    if(incnt >= K){
                        long long area = ((long long)xl - xr) * ((long long)yl - yr);
                        if(min > area){
                            min = area;
                        }
                    }
                }
            }
        }
    }
    
    std::cout << min << std::endl;
    
    
    return 0;
    
}


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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

const int mod = 1000000007;
struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0)
        : x((x % mod + mod) % mod)
    {
    }
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint& operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint& operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x; }
ostream& operator<<(ostream& os, const mint& a) { return os << a.x; }

map<ll, ll> prime_factorize(ll N)
{
    map<ll, ll> res;
    for (ll a = 2; a * a <= N; ++a) {
        if (N % a != 0)
            continue;
        ll ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res[a] = ex;
    }
    if (N != 1)
        res[N] = 1;
    return res;
}

int main()
{
    int n;
    cin >> n;
    const int M = 1000000;
    map<ll, ll> gmap;
    vector<map<ll, ll>> amap(n);
    vector<ll> A(n);
    for (int i = 0; i < n; i++) {
        ll a;
        cin >> a;
        A[i] = a;
        amap[i] = prime_factorize(a);
        for (auto p : amap[i]) {
            if (!gmap.count(p.first)) {
                gmap[p.first] = p.second;
            } else {
                gmap[p.first] = max(gmap[p.first], p.second);
            }
        }
    }

    mint g = 1;
    for (auto p : gmap) {
        mint q(p.first);
        g *= q.pow(p.second);
    }

    mint ans = 0;
    for (int i = 0; i < n; i++) {
        mint a(A[i]);
        ans += g / a;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3968
#! /usr/bin/env python3

# from math import gcd
from fractions import gcd
from collections import Counter, deque, defaultdict
from heapq import heappush, heappop, heappushpop, heapify, heapreplace, merge
from bisect import bisect_left, bisect_right, bisect, insort_left, insort_right, insort
from itertools import accumulate, product, permutations, combinations, combinations_with_replacement
import copy

N, M = [int(_) for _ in input().split()]
AB = [[int(_) for _ in input().split()] for i in range(M)]

graph = [[] for i in range(N)]

for A, B in AB:
    graph[A-1] += [B]
    graph[B-1] += [A]

D = deque([0])
visited = [0] * N
visited[0] = 1

ret = [0 for i in range(N)]

while D:
    v = D.popleft()
    for i in graph[v]:
        i -= 1
        if visited[i]: continue
        visited[i] = 1
        ret[i] = v + 1
        D.append(i)

if any(ret[1:]):
    print("Yes")
    for i in ret[1:]:
        print(i)
else:
    print("No")

Measured memory_bytes: 60616
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
#include <stack>
using namespace std;

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

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};
int dx9[9]={0,1,0,-1,1,-1,1,0,-1};
int dy9[9]={0,1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;
typedef pair<ll, ll> PLL;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
int n, t;
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> n >> t;

  int ma = 0, sum = 0;

  REP(i, t) {
    int a;
    cin >> a;
    ma = max(ma, a);
    sum += a;
  }

  if(ma - 1 > sum - ma) cout << ((ma - 1) - (sum - ma)) << endl;
  else cout << 0 << endl;
}


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

namespace ConsoleApp6
{
    class Program
    {
        static void Main(string[] args)
        {
            var sum = Console.ReadLine()
                .Split(' ')
                .Select(x => int.Parse(x))
                .Sum();

            Console.WriteLine(sum >= 22 ? "bust" : "win");
        }
    }
}


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

// x^n mod p O(log n)
	int64_t modpow(int64_t x,int64_t n,int64_t p){
		int64_t res=1;
		if(n==0){
			return 1;
		}
		res=modpow(x,n/2,p);
		if(n%2==0){
			
			res=(res*res)%p;
			return res;
		} else {
			res=(((x*res)%p)*res)%p;
			return res;
		}
	}
	
// nCr mod p 0(n log p)
int64_t comb(int64_t n,int64_t r, int64_t p){

	int64_t res=1;
// n!
	for(int64_t i=1; i<=n; i++){
		res=res*i;
		res=res%p;
	}
// r!
	for(int64_t i=1; i<=r; i++){
		res=res*modpow(i,p-2,p);
		res=res%p;
	}
// (n-r)!
	for(int64_t i=1; i<=n-r;i++){
		res=res*modpow(i,p-2,p);
		res=res%p;
	}
	
	return res;
}

int main(){
	int X;
	int Y;
	cin >> X >> Y;
	long long ans=0;
	long long p=1e9+7;
	
	if((2*Y-X)%3!=0 || (2*X-Y)%3!=0 || (2*Y-X)<0 || Y-2*(2*Y-X)/3<0){
		cout << 0 << endl;
		return 0;
	} else {
		long long a=(2*Y-X)/3;
		long long b=Y-2*a;
		ans=comb(a+b,min(a,b),p);
		cout << ans << endl;
		return 0;
	}
}

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 = n - 1; i >= 0; i--)
using namespace std;
using Graph = vector<vector<int>>;
typedef long long ll;
typedef pair<int,int> P;

int main(){
    int n, m;
    cin >> n >> m;
    int s[m];
    int c[m];
    rep(i, m) cin >> s[i] >> c[i];
    
    bool ans = false;
    rep(i, 1000){
        bool flag = true;
        string si = to_string(i);
        int keta = si.size();
        if (keta != n) continue;
        rep(j, m){
            if (si[s[j] - 1] - '0' != c[j]) flag = false;
        }
        if (flag){
            ans = true;
            cout << i << endl;
            break;
        }
    }
    if (!ans) cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vvl> vvvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define REP(i, n) for(ll i = 0; i < n; i++)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}

int main(){
    ll x, y, z, k; cin >> x >> y >> z >> k;
    vl as(x), bs(y), cs(z);
    REP(i, x) cin >> as[i];
    REP(i, y) cin >> bs[i];
    REP(i, z) cin >> cs[i];
    sort(as.begin(), as.end(), greater<ll>());
    sort(bs.begin(), bs.end(), greater<ll>());
    sort(cs.begin(), cs.end(), greater<ll>());
    
    vl ans;
    priority_queue<tuple<ll, ll, ll, ll>> rem;
    rem.push(make_tuple(as[0]+bs[0]+cs[0],0,0,0));
    set<tuple<ll, ll, ll>> used; used.insert(make_tuple(0,0,0));
    while(ans.size() < k){
        auto t = rem.top(); rem.pop();
        ans.pb(get<0>(t));
        ll a = get<1>(t), b = get<2>(t), c = get<3>(t);
        if(a < x - 1 && used.count(make_tuple(a+1,b,c)) == 0){
            rem.push(make_tuple(as[a+1]+bs[b]+cs[c],a+1,b,c)); used.insert(make_tuple(a+1,b,c));
        }
        if(b < y - 1 && used.count(make_tuple(a,b+1,c)) == 0){
            rem.push(make_tuple(as[a]+bs[b+1]+cs[c],a,b+1,c)); used.insert(make_tuple(a,b+1,c));
        }
        if(c < z - 1 && used.count(make_tuple(a,b,c+1)) == 0) {
            rem.push(make_tuple(as[a]+bs[b]+cs[c+1],a,b,c+1)); used.insert(make_tuple(a,b,c+1));
        }
    }

    sort(ans.begin(), ans.end(), greater<ll>());
    REP(i, k) cout << ans[i] << endstr;
    return 0;
}


Measured memory_bytes: 1024
n, k = map(int, input().split())
s = list(input())

if s[k-1] == "A":
  s[k-1] = "a"
elif s[k-1] == "B":
  s[k-1] = "b"
else:
  s[k-1] = "c"
  
print("".join(s))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define lld long double
#define REP(i,s,n) for(lli i=s;i<n;i++)
#define RREP(i,s,n) for(lli i=s;i>=n;i--)
#define MOD 1000000007
#define NUM 2520
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define INF (1LL<<50)

signed main(){

	lli n;
	cin>>n;

	vector<lli> a(n);
	REP(i,0,n)cin>>a[i];

	lli ans = INF;

	REP(i,0,2){
		lli sum = 0;
		lli cnt = 0;
		REP(j,0,n){
			if(DEBUG)cout<<"j="<<j<<" sum="<<sum<<" cnt="<<cnt<<endl;
			if((i+j)%2==0){//next +
				if(sum+a[j]<=0){
					cnt += -1*((sum+a[j]))+1;
					sum = 1;
				}
				else{
					sum += a[j];
				}
			}
			else{//next -
				if(sum+a[j]>=0){
					cnt += (sum+a[j])+1;
					sum=-1;
				}
				else{
					sum+=a[j];
				}
			}
		}
		ans = min(ans,cnt);
	}
	cout<<ans<<endl;

	return 0;
}

Measured memory_bytes: 1024
//ABC136 C - Build Stairs
//20190907

using System;
using System.Linq;

namespace C
{
    class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            double[] INPUT = Console.ReadLine().Split().Select(double.Parse).ToArray();
            double[,] H = new double[N, 2];

            for (int i = 0; i < N; i++)
            {
                H[i, 0] = INPUT[i];
                H[i, 1] = 1;
            }

            int p = 1;
            Boolean check = true;

            if (N == 2)
            {
                if (H[0, 0] - 1 > H[1, 0])
                {
                    check = false;
                }
            }

            while (p <= N - 2)
            {

                if (H[p - 1, 0] <= H[p, 0] && H[p, 0] <= H[p + 1, 0])
                {
                    p++;
                }
                else if (H[p - 1, 1] == 1 && H[p - 1, 0] > H[p, 0])
                {
                    H[p - 1, 0] -= 1;
                    H[p - 1, 1] = 0;
                    p = (p > 3 ? p - 2 : 1);
                }
                else if (H[p, 1] == 1 && H[p + 1, 0] < H[p, 0])
                {
                    H[p, 0] -= 1;
                    H[p, 1] = 0;
                    p = (p > 3 ? p - 2 : 1);
                }
                else
                {
                    check = false;
                    break;
                }
            }

            Console.WriteLine(check ? "Yes" : "No");
        }
    }
}


Measured memory_bytes: 30684
class SegmentTree:
    def __init__(self, base_array,n , default_value = 0, segfunc = lambda a, b: a + b): #元配列、大きさ、デフォルト値
        self._num = 2 ** (n - 1).bit_length()
        self._seg = [default_value] * 2 * self._num
        self._segfunc = segfunc
        self._ide_ele = default_value
        for i in range(n):
            self._seg[i + self._num - 1] = base_array[i]
        for i in range(self._num - 2, -1, -1):
            self._seg[i] = segfunc(self._seg[2 * i + 1], self._seg[2 * i + 2])


    def update(self, k, x):
        k += self._num - 1
        self._seg[k] = x
        while k:
            k = (k - 1) // 2
            self._seg[k] = self._segfunc(self._seg[k * 2 + 1], self._seg[k * 2 + 2])


    def query(self, p, q):
        if q <= p:
            return self._ide_ele
        p += self._num - 1
        q += self._num - 2
        res = self._ide_ele
        while q - p > 1:
            if p & 1 == 0:
                res = self._segfunc(res, self._seg[p])
            if q & 1 == 1:
                res = self._segfunc(res, self._seg[q])
                q -= 1
            p = p // 2
            q = (q - 1) // 2
        if p == q:
            res = self._segfunc(res, self._seg[p])
        else:
            res = self._segfunc(self._segfunc(res, self._seg[p]), self._seg[q])
        return res

def main():
    N = int(input())
    S = [c for c in input()]
    M = int(input())

    A = [0 for i in range(N)]

    for i, c in enumerate(S):
        A[i] = 1 << ord(c) - ord('a')

    st = SegmentTree(A, N, 0, lambda a, b: a | b)

    for i in range(M):
        p, a, b = input().split()
        a  = int(a) - 1
        b = int(b) - 1 if p == '2' else b
        if p == '1':
            st.update(a, 1 << ord(b) - ord('a'))

        if p == '2':
            s = st.query(a, b + 1)
            print(bin(s).count('1'))


if __name__ == '__main__':
    main()

Measured memory_bytes: 51992
'use strict';

const lines = [];
require('readline').createInterface({ input: process.stdin })
.on('line', function(line) { lines.push(line) })
.on('close', function() {
  function numeric(v) { return +v }
  function desc(a, b) { return b - a }
  
  const xyabc = lines.shift().split(' ').map(numeric);
  const x = xyabc[0];
  const y = xyabc[1];
  const p = lines.shift().split(' ').map(numeric);
  const q = lines.shift().split(' ').map(numeric);
  const r = lines.shift().split(' ').map(numeric);
  
  const P = p.sort(desc).slice(0, x);
  const Q = q.sort(desc).slice(0, y);
    
  const sum = P.concat(Q).concat(r).sort(desc).slice(0, x + y).reduce(function(sum, i) {
    return sum + i;
  });

  console.log(sum);
});

Measured memory_bytes: 60512
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;

int main()
{
    int X;
    cin >> X;
    X -= 400;
    cout << 8 - X / 200 << endl;
    return 0;
}

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

int main(){
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	int x=a[2]*2-a[0]-a[1];
	if(x%2) x+=3;
	cout<<x/2;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <map>
#define rep(i,n) for(ll i=0; i<n; i++)
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
const ll mod=1e9+7;

int main(){
	int N,R;
	cin >> N >> R;

	int ans;
	if(N<10){
		ans=R+(100*(10-N));
	}else{
		ans=R;
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256