akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
const int M = 1e9 + 7,N = 1e5 + 1;
int dp[2][N],s,t,n,m;
long long dis[2][N];
struct edges{
	int x,y,w;
}e[N<<1];
struct node{
	int x,w;
	node(int a = 0,int b = 0){
		x = a;w = b;
	}
};
void add(int &a,int b){
	a+=b;
	a%=M;
	if(a >= M)a-=M;
	if(a < 0)a+=M;
}
vector<node>g[N];
bool vis[N];
void dijk(int s,bool at){
	long long *dis = ::dis[at];
	memset(vis,0,sizeof vis);
	int *dp = ::dp[at];
	dis[s] = 0;
	dp[s] = 1;
	priority_queue<pair<long long,int>>q;
	q.push({0,s});
	while(!q.empty()){
		int x = q.top().second;
		long long w = -q.top().first;
		q.pop();
		if(vis[x])continue;
		vis[x] = 1;
		for(auto i : g[x]){
			int y = i.x;
			long long cur = w + i.w;
			if(cur == dis[y])add(dp[y],dp[x]);
			if(cur >= dis[y])continue;
			dp[y] = dp[x];
			dis[y] = cur;
			q.push({-dis[y],y});
		}
	}
}
int main(){
	scanf("%d%d%d%d",&n,&m,&s,&t);	
	for(int i = 0;i < m;i++){
		scanf("%d%d%d",&e[i].x,&e[i].y,&e[i].w);
		int a = --e[i].x,b = --e[i].y,c = e[i].w;
		g[a].push_back({b,c});
		g[b].push_back({a,c});
	}
	for(int i = 0;i < n;i++)dis[0][i] = dis[1][i] = 1e18;
	dijk(--s,0);
	dijk(--t,1);
	long long mndis = dis[0][t];
	int ans = dp[0][t]*1LL*dp[0][t]%M,sz = 0;
	for(auto i : e){
		if(sz == m)break;
		++sz;
		long long mn = min(dis[0][i.x],dis[0][i.y]);
		long long mx = min(dis[1][i.x],dis[1][i.y]);
		if(mn == dis[0][i.y])swap(i.x,i.y);
		if(mn + mx + i.w == mndis && mn * 2 < mndis && mx * 2 < mndis)add(ans,-(dp[0][i.x]*1LL*dp[0][i.x]%M)*(dp[1][i.y]*1LL*dp[1][i.y]%M)%M);
	}
	for(int i = 0;i < n;i++)
		if(dis[0][i] == dis[1][i] && dis[0][i] + dis[1][i] == mndis)add(ans,-(dp[0][i]*1LL*dp[0][i]%M)*(dp[1][i]*1LL*dp[1][i]%M)%M);
	printf("%d\n",ans);
}

Measured memory_bytes: 16724
-- https://github.com/minoki/my-atcoder-solutions
import Data.Char (isSpace)
import Data.List (unfoldr)
import qualified Data.ByteString.Char8 as BS

main = do
  [a,b] <- unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine
  print $ a - min a (2 * b)


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

#define rep(i,n) for(int i = 0; i < (n); ++i)
#define ll long long
#define P pair<ll,ll>
#define all(v) v.begin(),v.end()
const ll mod = 1e9+7;
const ll INF = 1e18;
const double pi = acos(-1.0);

int main(void)
{
    while(true){ll x,y;
    cin>>x>>y;
    if(x==0&&y==0) return 0;
    cout<<min(x,y)<<" "<<max(x,y)<<endl;
    }
    return 0;
}


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

public class ABC163C {
	private static void Main(string[] args) {
		var n = ReadInt();
		var a = ReadIntsAsArray();
		var answers = new int[n];

		foreach (var i in a)
			answers[i-1]++;

		foreach (var answer in answers)
			Console.WriteLine(answer);
	}

	private static int ReadInt() => int.Parse(Console.ReadLine().Trim());
	private static int[] ReadIntsAsArray() => Console.ReadLine().Trim().Split().Select(x => int.Parse(x)).ToArray();
}

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

int main() {

  string s;
  cin >> s;
  int ans = 0;
  
  if(s.at(0)=='R' && s.at(1)=='R' && s.at(2)=='R') {
    ans = 3;
  }
  else if(s.at(0)=='R' && s.at(1)=='R' && s.at(2)!='R') {
    ans = 2;
  }
  else if(s.at(0)!='R' && s.at(1)=='R' && s.at(2)=='R') {
    ans = 2;
  }
  else if(s.at(0)=='S' && s.at(1)=='S' && s.at(2)=='S') {
    ans = 0;
  }
  else ans = 1;
  
  cout << ans << endl;
}

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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vll = vector<ll>;
using vvi = vector<vector<int>>;
using vvl = vector<vector<ll>>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  string s, t;
  cin >> s >> t;
  sort(s.begin(), s.end());
  sort(t.rbegin(), t.rend());
  if (s < t) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <map>
using namespace std;
 
const int N = 2000010;
char s[N], str[N*2];
int p[N*2],a[N];
long long manacher()
{
    int i;
    for(i = 1; s[i]; i++)
        str[i*2] = s[i], str[i*2+1] = '#';
    str[0] = '?', str[1] = '#', str[i*2] = '\0';
    int res = 0, k = 0, maxk = 0,n=strlen(s+1);
    long long mmh=1LL*n*(n+1)/2;
    for (int i=1;i<=n;i++){
        a[s[i]]++;
        mmh-=a[s[i]];
    }
    return mmh+1;
}
 
int main()
{
    scanf(" %s", s + 1);
    printf("%lld\n", manacher());
    return 0;
}

Measured memory_bytes: 4352
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned ll
#define uint unsigned
#define pii pair<int,int>
#define pll pair<ll,ll>
#define PB push_back
#define fi first
#define se second
#define For(i,j,k) for (int i=(int)(j);i<=(int)(k);i++)
#define Rep(i,j,k) for (int i=(int)(j);i>=(int)(k);i--)
#define CLR(a,v) memset(a,v,sizeof(a));
#define CPY(a,b) memcpy(a,b,sizeof(a));
using namespace std;
int n,nn;
int main(){
	scanf("%d",&n);
	nn=n;
	if ((n&(-n))==n)
		return puts("No"),0;
	puts("Yes");
	printf("1 2\n2 3\n1 %d\n%d %d\n%d %d\n",n+3,n+3,n+2,n+2,n+1);
	if (nn%2==0){
		int d=1;
		for (;d*2<=n;d<<=1);
		printf("%d %d\n%d %d\n",n,d,n+(n-d+1),n+n);
		nn--;
	}
	for (;nn>3;nn-=2)
		printf("%d %d\n%d 1\n1 %d\n%d %d\n",nn,nn-1,nn-1,nn+n,nn+n,nn+n-1);
}

Measured memory_bytes: 2304
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;
typedef pair<int, int> pi;


int main() {
  int k;
  string s;
  cin >> k;
  cin >> s;

  if (s.size() <= k){
    cout << s << endl;
    return 0;
  }
  s = s.substr(0, k);
  s += "...";
  cout << s << endl;
  return 0;
}

Measured memory_bytes: 3632
# AOJ ITP1_8_C

import sys

def main():
    counts = []
    for i in range(26): counts.append(0)

    lines = sys.stdin.readlines()

    for i in range(len(lines)):
        string = lines[i]
        for k in range(len(string)):
            c = string[k]
            if 97 <= ord(c) <= 122:
                counts[ord(c) - 97] += 1
            elif 65 <= ord(c) <= 90:
                counts[ord(c) - 65] += 1

    # 結果を出力。
    for i in range(26):
        print(chr(97 + i) + " : " + str(counts[i]))

if __name__ == "__main__":
    main()

# Accepted.


Measured memory_bytes: 5572
#include<bits/stdc++.h>
using namespace std;
int n,a[200010],mn=0x3f3f3f3f,ans;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;++i) {
		scanf("%d",&a[i]);
		if(mn>=a[i]) ans++;
		mn=min(mn,a[i]);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import io
import os


def main():
    n, m = map(int, input().split())

    w, v = [0] * n, [0] * n
    for i in range(n):
        w[i], v[i] = map(int, input().split())

    dp = [0] * (m + 1)
    for i in range(w[0], m + 1):
        dp[i] = v[0]
    for i in range(n - 1):
        for j in reversed(range(w[i + 1], m + 1)):
            dp[j] = max(v[i + 1] + dp[j - w[i + 1]], dp[j])

    print(dp[-1])


input = io.BytesIO(os.read(0, os.fstat(0).st_size)).readline
main()


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

typedef long long ll;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll a=0,n,k;
    cin>>n>>k;
    while(n)
    {
        n/=k;
        a++;
    }
    cout<<a<<endl;
    return 0;

}

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n),b(n);
    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    b=a;
    sort(a.begin(),a.end());
    int x=a[n/2-1],y=a[n/2];

    for(int i = 0; i < n; i++) {
        if(b[i]<=x){
            cout << y << endl;
        }
        else{
            cout << x << endl;
        }
    }

    return 0;
}

Measured memory_bytes: 4840
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>


int compare_int(const void *a, const void *b)
{
//    return *(int*)a - *(int*)b;
    return *(long long*)a - *(long long*)b;
}
//  qsort(A, b, sizeof(int), compare_int);

//long long  factorial(long long n) {
//    if (n > 0) {
//        return n * factorial(n - 1);
//    } else {
//        return 1;
//    }
//}
long long  factorial(long long n, long long depth) {
    if (n > 1) {
        depth++;
        return factorial(n / 2, depth);
    } else {
        return depth;
    }
}

int min(int a, int b) {
    if (a > b)
        return b;
    else
        return a;
}

int distance(int a, int b) {
  return abs(a-b)*abs(a-b);
}



//int ()
/*
int triangle(int a, int b, int c){
  if(a<b+c){
    if(b<c+a){
      if(c<a+b){
        printf("1\n");
        return 1;
      }
    }
  }
  printf("1\n");
  return 0;
}
*/

int main()
{
  int  a ,b, c, d, e, X, Y ,r;
//  long long  a, b, c, d, e, X, Y;
  //  double  c;
// long long  A[200003]={};
  int  A[100003]={};
  int  B[100003]={};
//  int  C[100003][100001]={};
  int  C[100003]={};

  int  flg=0;

//  char s[101][101]={};
  char s[100001]={};
  char t[100001]={};
//  int N, M;
//  int A[1000000001]={};
//  long long  C[101]={};
  int i,j,k;
  long long p=0,q=0;
//  int flag=0;
//  int tmp=0;
//  char tmp[101]={};
//  long long min=10000000000;
//  long long min=100000001;
  long long min =100000001;
  int len=0;
  int l=0;
//  int r=1000001;
  int cnt=0;
  int num=0;
  int num1=0;
  int num2=0;
  long long  ans=0;
  int ans_ac=0;
  int ans_wa=0;
  int max=0;
  long long sum=0;
  int addr=0;
  int ptn=0;
  int  tmp=0;
  double per=0; 
//  bool on_off[100]={};
  
//  char alp[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};

  //  a=0;
  scanf("%d%d", &a,&b);
  for(i=0;i<b;i++){
    scanf("%d%d", &A[i],&B[i]);
    if(A[i]==1 && B[i] ==0 && a!=1){
      printf("-1\n");
      return 0;
    }
  }
  for(i=0;i<b;i++){
    if(C[A[i]-1]==0)C[A[i]-1]=B[i];
    else if (C[A[i]-1]==B[i]) ;
    else {
      printf("-1\n");
      return 0;
    }
  }

  for(i=0;i<a;i++){
    if(i==0 && C[0]==0 && a!=1) C[0]=1;
    printf("%d",C[i]);
  }
  printf("\n");
  
  
return 0;
}


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

using namespace std;

int main()
{
  	string S, T;
  	cin >> S >> T;
  	for(int i = 0; i < S.length(); ++i){
      	if(S == T){
         	cout << "Yes" << endl;
          	return 0;
        }
      	char ch = S.back();
      	S.pop_back();
      	S = ch + S;
    }
  	cout << "No" << endl;
}


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

typedef long long ll;
const int N = 100054, M = N * 2, mod = 1000000007;

struct edge {
	int u, v, w;
	edge (int u0 = 0, int v0 = 0, int w0 = 0) : u(u0), v(v0), w(w0) {}
	edge * read() {return scanf("%d%d%d", &u, &v, &w), this;}
	bool operator < (const edge &B) const {return w < B.w;}
} e[M];

int V, E;
bool mst[M], mist[M];
int p[N];

inline void up(int &x, const int y) {x < y ? x = y : 0;}
inline int max(const int x, const int y) {return x < y ? y : x;}

ll PowerMod(ll a, int n, ll c = 1) {for (; n; n >>= 1, a = a * a % mod) if (n & 1) c = c * a % mod; return c;}

int ancestor(int x) {return p[x] == x ? x : (p[x] = ancestor(p[x]));}

inline bool test(int x, int y, bool un = false) {
	if ((x = ancestor(x)) == (y = ancestor(y))) return true;
	return un && (p[x] = y), false;
}

namespace Tree {
	const int N = ::N, M = ::M, LN = 18;

	int E;
	edge e[M];
	int first[N], next[M];
	int P[LN][N], *p = *P, m[LN][N], dep[N];

	inline void init() {E = 0, memset(first, 0, sizeof first);}

	inline void addedge(int u, int v, int w) {
		e[++E] = edge(u, v, w), next[E] = first[u], first[u] = E;
		e[++E] = edge(v, u, w), next[E] = first[v], first[v] = E;
	}

	void dfs(int x) {
		int i, y;
		for (i = 0; i < LN - 1 && P[i][x]; ++i)
			P[i + 1][x] = P[i][P[i][x]],
			m[i + 1][x] = max(m[i][P[i][x]], m[i][x]);
		for (i = first[x]; i; i = next[i])
			if ((y = e[i].v) != p[x])
				p[y] = x, dep[y] = dep[x] + 1,
				m[0][y] = e[i].w, dfs(y);
	}

	int query(int x, int y) {
		int i, ret = 0;
		if (dep[x] < dep[y]) std::swap(x, y);
		for (i = LN - 1; i >= 0; --i)
			if (dep[x] - (1 << i) >= dep[y]) up(ret, m[i][x]), x = P[i][x];
		if (x == y) return ret;
		for (i = LN - 1; i >= 0; --i)
			if (P[i][x] != P[i][y])
				up(ret, m[i][x]), x = P[i][x],
				up(ret, m[i][y]), y = P[i][y];
		return max(ret, max(m[0][x], m[0][y]));
	}
}

int main() {
	int i, j, k, u, v, w, w0, z0, lt = 0, eq = 0, gt = 0;
	ll X, MST = 0, ans;
	scanf("%d%d%lld", &V, &E, &X);
	assert(E >= V - 1);
	for (i = 0; i < E; ++i) e[i].read();
	if (V <= 2) return puts("0"), 0;
	std::sort(e, e + E);
	for (i = 1; i <= V; ++i) p[i] = i;
	for (j = i = 0; i < E; i = j) {
		for (; e[i].w == e[j].w; ++j);
		for (k = i; k < j; ++k) mst[k] = ancestor(e[k].u) != ancestor(e[k].v);
		for (k = i; k < j; ++k) if (mist[k] = !test(e[k].u, e[k].v, true)) MST += e[k].w;
	}
	if (X < MST) ans = 0;
	else if (X == MST)
//		fprintf(stderr, "MST = X = %lld\n", X),
		z0 = std::count(mst, mst + E, false),
		ans = PowerMod(2, E) - PowerMod(2, z0 + 1);
	else {
//		fprintf(stderr, "MST = %lld, X = %lld\n", MST, X);
		Tree::init();
		for (i = 0; i < E; ++i) if (mist[i]) Tree::addedge(e[i].u, e[i].v, e[i].w);
		Tree::dfs(1);
		for (i = 0; i < E; ++i) if (!mst[i]) {
			u = e[i].u, v = e[i].v, w = e[i].w, w0 = Tree::query(u, v);
//			fprintf(stderr, "(%d, %d, %d) not in MST, w0 = %d\n", u, v, w, w0);
			assert(w > w0);
			if (w - w0 < X - MST) ++lt;
			else if (w - w0 == X - MST) ++eq;
			else ++gt;
		}
		ans = 2 * (PowerMod(2, eq + gt) - PowerMod(2, gt)) % mod;
	}
	return printf("%lld\n", ans + (ans >> 63 & mod)), 0;
}

Measured memory_bytes: 17280
N=int(input())
M=list(map(int,input().split()))
S=[]
T=[]
for i in range(0,len(M))  :
  if M[i]%2==0:
    T.append(M[i])
    S.append(M[i])
for j in range(0,len(S)):
  if S[j]%3!=0 and S[j]%5!=0:
      T.remove(S[j])
    
if len(S)==len(T):
  print('APPROVED')
else:
  print('DENIED')
    

    
  

  

    

    
  

  



Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int N=0,out=0;
	string ashi1,ashi2;

	while(1)
	{
		cin >> N;
		if(N==0) break;
		for(int i=0;i<N/2;i++)
		{
			cin >> ashi1 >> ashi2;
			if((ashi1=="lu"&&ashi2=="ru")||(ashi1=="ru"&&ashi2=="lu")||(ashi1=="ld"&&ashi2=="rd")||(ashi1=="rd"&&ashi2=="ld")) out++;
		}
		if(N%2==1) cin >> ashi1;
		cout << out << endl;
		out=0;
	}
	return 0;
}

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


long long f(long long a) { return (a+1)/2 % 2; }

long long g(long long a) {
    if (a % 2 == 1) return f(a);
    else return f(a+1) ^ (a+1);
}


long long i(long long x,long long y){
  
  return g(x-1)^g(y);
}
  

int main(){

  long long A,B;
  
  cin >> A >> B;
  
  cout << i(A,B) << endl;
}


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

series = list(map(int, input().split()))

place = {}
counter = 0

for i in series:
    if i not in place:
        place[i] = 0
    place[i] += 1
    
for j in place.keys():
    if place[j] > j:
        counter += place[j] - j
    elif j > place[j]:
        counter += place[j]
        
print(counter)

Measured memory_bytes: 17780
#include <math.h>

#include <algorithm>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
#define PI 3.14159265358979323846264338327950L
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define SIZE_OF_ARRAY(array) (sizeof(array) / sizeof(array[0]))

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

  bool ans = true;
  rep(i, S.size()) {
    if (S[i] == 'L' && i % 2 == 0) ans = false;
    if (S[i] == 'R' && i % 2 == 1) ans = false;
  }

  if (ans == true)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#define NIL 2000000001
using namespace std;
typedef struct{
	int key;
	int lch;//??????id
	int rch;//??????id
}NODE;
NODE node[500001];
int root;
int n,a;
string s;
bool flag;

void insert(int id,int num){
	int node1=root;
	int parent=-1;
	while(node1!=-1){
		parent=node1;
		if(num<node[node1].key){
			node1=node[node1].lch;
		}else{
			node1=node[node1].rch;
		} 
	}
	//parent=node1;
	if(parent==-1){
		root=id;
		node[id].lch=node[id].rch=-1;
		node[id].key=num;
	}else if(num<node[parent].key){
		node[parent].lch=id;
		node[id].key=num;
		node[id].rch=node[id].lch=-1;
	}else{
		node[parent].rch=id;
		node[id].key=num;
		node[id].rch=node[id].lch=-1;
	}
}

void inordertreewalk(int id){
	if(node[id].lch!=-1)inordertreewalk(node[id].lch);
	//if(id==root){
	//	cout << node[id].key;	
	//}else if(node[id].key>node[root].key){
		cout << " "<< node[id].key;
	//}else{
	//	cout << node[id].key<<" ";
	//}
	if(node[id].rch!=-1)inordertreewalk(node[id].rch);
	return;
}

void preordertreewalk(int id){
	//if(id==root){
	//	cout << node[id].key;	
	//}else{
		cout << " "<< node[id].key;
	//}
	if(node[id].lch!=-1)preordertreewalk(node[id].lch);
	if(node[id].rch!=-1)preordertreewalk(node[id].rch);
	return;
}

bool find(int num){
	int id=root;
	while(id!=-1){
		if(node[id].key==num){
			return true;
		}else if(node[id].key>num){
			id=node[id].lch;
		}else{
			id=node[id].rch;
		}
	}
	return false;
}

void delete_a(int num){
	int id=root;
	int parent=-1;
	while(id!=-1){
		if(node[id].key==num){
			if(node[id].lch==-1&&node[id].rch==-1){
				if(id==root){
					root=-1;
					break;
				}
				if(node[parent].key>num){
					node[parent].lch=-1;
				}else{
					node[parent].rch=-1;
				}
				break;
			}else if(node[id].lch==-1&&node[id].rch!=-1){
				if(id==root)root=node[id].rch;
				if(node[parent].key>num){
					node[parent].lch=node[id].rch;
				}else{
					node[parent].rch=node[id].rch;
				}
				break;
			}else if(node[id].lch!=-1&&node[id].rch==-1){
				if(id==root)root=node[id].lch;
				if(node[parent].key>num){
					node[parent].lch=node[id].lch;
				}else{
					node[parent].rch=node[id].lch;
				}
				break;
			}else{
				parent=id;
				id=node[parent].rch;
				while(node[id].lch!=-1)id=node[id].lch;
				delete_a(node[id].key);
				node[parent].key=node[id].key;
				//num=node[id].key;
				break;
			}
		}else if(node[id].key>num){
			parent=id;
			id=node[id].lch;
		}else{
			parent=id;
			id=node[id].rch;
		}
	}
}

int main(){
	root=-1;
	cin >>n;
	for(int i=0;i<n;i++){
		cin >>s;
		if(s=="insert"){
			cin >>a;
			insert(i,a);
		}else if(s=="print"){
			if(root==-1)continue;
			inordertreewalk(root);
			cout <<endl;
			preordertreewalk(root);
			cout <<endl;
		}else if(s=="find"){
			cin >>a;
			flag=find(a);
			if(flag){
				cout << "yes"<<endl;
			}else{
				cout << "no"<<endl;
			}
		}else if(s=="delete"){
			cin >>a;
			delete_a(a);
		}

	}
}

Measured memory_bytes: 7804
s=input()
t=list(s)
l=len(s)

ans=0
for i in range(2**(l-1)):
    ans_sub=0
    subst=s[0]
    for j in range(l-1):
        if (i>>j)&1:
            ans_sub+=int(subst)
            subst=s[j+1]
        else:
            subst+=s[j+1]
        if j==l-2:
            ans_sub+=int(subst)
    ans+=ans_sub
if l==1:
    print(int(s))
else:
    print(ans)

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

using ll = long long;
using ld = double;
using pii = pair<int, int>;

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

	int r, g, b, k;
	cin >> r >> g >> b >> k;

	while (g <= r && k > 0) {
		g <<= 1;
		k--;
	}

	while (b <= g && k > 0) {
		b <<= 1;
		k--;
	}

	if (b > g && g > r) {
		cout << "Yes";
	} else {
		cout << "No";
	}

	return 0;
}

Measured memory_bytes: 3656
import java.util.*;

public class Main{
	private static final Scanner scan = new Scanner(System.in)
							.useDelimiter("[,\\s]+");

	public static void main(String[] args){
		int[] l = new int[10];
		int sum1 = 0, sum2 = 0;
		double time = 0, tX = 0;
		while(scan.hasNext()){
			for(int i = 0; i < 10; i++){
				l[i] = scan.nextInt();
			}
			int v1 = scan.nextInt();
			int v2 = scan.nextInt();
			for(int i = 0; i < 10; i++){
				sum1 += l[i];
			}
			time =(double) sum1 / (double)(v2 + v1);
			tX =(double) v1 * time;
			for(int i = 0; i < 10; i++){
				sum2 += l[i];
				if(tX <= sum2){
					System.out.printf("%d\n", i+1);
					sum1 = 0;
					sum2 = 0;
					break;
				}
			}
		}
	}
}

Measured memory_bytes: 26280
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

lint ksum(lint n){
    return n*(n+1)/2;
}

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

    lint n; cin>>n;
    vl a(n);
    lint lxor = 0;
    for (int i = 0; i<n; ++i){
        cin>>a[i];
        if (i >= 2) lxor ^= a[i];
    }

    lint sum = a[0] + a[1];
    if ((sum - lxor)%2 != 0) {cout<<-1; return 0;}

    lint land = (sum - lxor)/2;
    if (land < 0) {cout<<-1; return 0;}
    lint lor = sum - land;
    if (lor <= 0) {cout<<-1; return 0;}

    if ((lor & land) != land) {cout<<-1; return 0;}

    lint cur = land;
    for (int bit = 60; bit >=0; bit--){
        lint bb = 1LL<<bit;
        if ((lor & (bb)) > 0 && (land & (bb)) == 0)
        {
            if (cur + (bb) <= a[0]){
                cur += (bb);
            }
        }
    }
    if (cur > a[0] || cur == 0) cout<<-1;
    else cout<<a[0] - cur;
}


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

using namespace std;
using LLI = long long int;

int main(void) {
	LLI N, a, tmp;
	string S, tmpS;
	cin >> N;
	vector<pair<string, LLI>>vec(N);
	vector<LLI>num(N);
	for (LLI i = 0; i < N; i++) {
		cin >> S >> a;
		vec[i] = make_pair(S, a);
		num[i] = i + 1;
	}
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < N - 1; j++) {
			if (vec[j].first < vec[j + 1].first) {
				swap(vec[j], vec[j + 1]);
				swap(num[j], num[j + 1]);
			}
		}
	}
	for (int i = 0; i < N - 1; i++) {
		for (int j = 0; j < N - 1; j++) {
			if (vec[j].first == vec[j + 1].first && vec[j].second > vec[j + 1].second) {
				swap(vec[j], vec[j + 1]);
				swap(num[j], num[j + 1]);
			}
		}
	}
	for (int i = N - 1; i >= 0;i--) {
		cout << num[i] << endl;
	}
}

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define reps(i, s, n) for(int i = (int)s; i < (int)n; i++)
#define in(i) std::cin >> i;
#define print(i) std::cout << i;
#define println(i) std::cout << i << std::endl;

int main() {
    std::string S, T;
    std::cin >> S >> T;

    long cnt = 0;
    for(int i = 0; i < S.length(); i++) {
        if(S[i] != T[i])
            cnt++;
    }
    print(cnt);
    return 0;
}

Measured memory_bytes: 3352
#include<iostream>
#include<algorithm>
#include<string>
#include<math.h>
#include<cmath>
#include<vector>
#include<stack>
#include<queue>
#include<functional>
#include<map>
#include<set>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)

map<string, int> mp;

int main() {
    int x=0,n,a=0;
    string s;
    cin >> n >> s;
    rep(i, n) {
      
        if (s[i] == 'I')a++;
        else a--;
        if (a > x)x = a;
    }
    cout << x << endl;
}

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

#define NREP() for(ll i = 0; i < n; i++)
#define MREP() for(ll j = 0; j < m; j++)
#define REP(i, x, y) for(ll i = x; i < y; i++)
#define ALL(x) (x).begin(), (x).end()
#define MSG(x) cout << x << endl;
#define MSGF(x, n) MSG(fixed << setprecision(n) << x)
#define END(x) cout << x << endl; exit(0);
#define IPT(v, n) REP(i, 0, n){ cin >> v[i]; }
#define YN(x) x ? cout << "YES" << endl : cout << "NO" << endl;
#define Yn(x) x ? cout << "Yes" << endl : cout << "No" << endl;
#define yn(x) x ? cout << "yes" << endl : cout << "no" << endl;

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<ull> vul;
typedef vector<vector<ull>> vvul;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;

const static ll MOD = 1e9 + 7;
const static ll INF = 1LL << 30;

ll a, b, c, d, k, l, m, n, h, w, q, x, y;
string s, t;

ll ans = 0;
ll sum = 0;
ll cnt = 0;
ll cur = 0;
ll tmp = 0;
ll mini = INF;
ll maxi = 0;

double ave = 0.0;

ll mod_pow(ll base, ll power) {
    if (power == 0) return 1;
    if (power == 1) return base % MOD;
    if (power % 2 == 0) return ((mod_pow(base % MOD, (power / 2)) % MOD) * (mod_pow(base, (power / 2)) % MOD)) % MOD;
    return (base % MOD * (mod_pow(base % MOD, power - 1) % MOD)) % MOD;
}

ll mod_fact(ll number) {
    ll ret = 1;
    ll count = 1;
    while (count <= number) {
        ret *= (count % MOD);
        ret %= MOD;
        count++;
    }
    return ret % MOD;
}

////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

int main() {
    vc row;
    for(char c = 'A'; c <= 'Z'; c++) {
        row.push_back(c);
    }

    cin >> h >> w;
    REP(i_h, 0, h) {
        REP(i_w, 0, w) {
            cin >> t;
            if (t == "snuke") cout << row[i_w] << to_string(i_h + 1) << endl;
        }
    }
}


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


int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];

    sort(a.begin(), a.end());
    cout << a[n-1] - a[0] << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define int long long
#define inf 1000000007
#define LINF 1000000000000000007LL
#define ll long long
using namespace std;
int dp[114514];
signed main(){
	int n,k; cin>>n>>k;
	vector<int> h;
	h.pb(0);
	for(int i=0;i<n;i++){
		int x; cin>>x; h.pb(x);
	}
	dp[1] = 0;
	for(int i=2;i<=n;i++){
		int tmp = LINF;
		for(int j=1;j<=k;j++){
			if( i - j <= 0 )continue;
			tmp = min( tmp, dp[i-j] + abs( h[i]-h[i-j] ) );
		}
		dp[i] = tmp;
	}
	cout<<dp[n]<<endl;
	return 0;
}

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

int main() {
  long long a,b,c,k;
  cin>>a>>b>>c>>k;
  
  if(k<a)cout<<k<<endl;
  else if(k<=a+b)cout<<a<<endl;
  else if(a+b< k && k<=a+b+c)cout<<2*a+b-k<<endl;
  
}


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

long long mmin(long x, long long y) {
	if (x > y) return y;
	else return x;
}

int main() {
	int n, k;
	cin >> n >> k;
	vector<int> H;
	rep(i, n) {
		int h;
		cin >> h;
		H.push_back(h);
	}
	
	long long dp[100009];
	rep(i, 100009) dp[i] = 1000000000;
	dp[0] = 0;
	rep(i,n-1) {
		rep(j,k) {
			if (i + j + 1 > n - 1) break;
			long long a = dp[i];
			a += abs(H[i + j + 1] - H[i]);
			dp[i + j + 1] = mmin(dp[i + j + 1], a);
			//cout << i + j + 1 << " " << dp[i + j + 1] << endl;
		}
	}
	//rep(i, n) cout << dp[i] << endl;
	cout << dp[n - 1] << endl;
}

Measured memory_bytes: 1528
import Control.Monad
 
toTuples :: [[Int]] -> [(Int, Int, Int)]
toTuples ((t:x:y:[]):[]) = [(t, x, y)]
toTuples ((t:x:y:[]):xs) = (t, x, y) : toTuples xs
 
checkPlans :: (Int, Int, Int) -> [(Int, Int, Int)] -> Bool
checkPlans _ [] = True
checkPlans (t1, x1, y1) ((t2, x2, y2):xs) = (time >= delta) && (even delta == even time) && checkPlans (t2, x2, y2) xs
  where
    delta = abs (x2 - x1) + abs (y2 - y1)
    time = t2 - t1
 
main :: IO ()
main = do
    n <- readLn
    list <- replicateM n $ (map read) . words <$> getLine :: IO [[Int]]
    let plans = toTuples list
    putStr $ if checkPlans (0, 0, 0) plans then "Yes" else "No"

Measured memory_bytes: 81276
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define inf 1001001001001001001
#define mod 1000000007
#define mod2 998244353
#define pi acos(-1)
#define all(v) v.begin(),v.end()

int main(){
    string s,t;cin>>s>>t;
    int a,b;cin>>a>>b;
    string u;cin>>u;
    if(s==u){
        a--;
    }else if(t==u){
        b--;
    }
    cout<<a<<" "<<b<<endl;
}

Measured memory_bytes: 3628
#define _USE_MATH_DEFINES
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  vector<int> a(n), b(n);
  int all = 0;
  for (int i = 0; i < n; ++i) {
    scanf("%d", &a[i]);
    // a[i] = rand() % 1000000 + 1;
    all += a[i];
  }
  vector<int> can;
  for (int k = 1; k * k <= all; ++k) {
    if (all % k == 0) {
      can.push_back(k);
      if (all / k != k) can.push_back(all / k);
    }
  }
  int ret = 1;
  for (auto& k : can) {
    for (int i = 0; i < n; ++i) {
      b[i] = a[i] % k;
    }
    sort(b.begin(), b.end());
    int r = 0;
    for (; r < n && b[r] == 0; ++r);
    int64 R = 0;
    for (int i = r; i < n; ++i) {
      R += k - b[i];
    }
    int64 L = 0;
    for (int i = r; i < n && L < R; ++i) {
      L += b[i];
      R -= k - b[i];
    }
    if (L <= m) ret = max(ret, k);
  }
  printf("%d\n", ret);
  return 0;
}


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

// #define int ll
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using si = set<int>;
using ii = pair<int, int>;
using vii = vector<ii>;

#define rep(i, n) for (int i = 0; i < n; i++)
#define dotc()    int tcs; if (cin >> tcs) rep(tc, tcs)
#define sz(x)     (int)x.size()
#define eb        emplace_back
#define pb        push_back
#define mp        make_pair
#define all(x)    x.begin(), x.end()
#define rall(x)   x.rbegin(), x.rend()
#define fi        first
#define se        second

int inf(0x3fffffff);
int mod(1000000007);
double pi(acos(-1.0));

int32_t main() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#endif

  int k;
  cin >> k;
  
  queue<ll> q;
  rep(i, 9) q.push(i + 1);
  while (!q.empty()) {
    ll cur = q.front();
    q.pop();

    k--;
    if (!k) {
      cout << cur;
      break;
    }

    if (cur % 10 != 0) q.push(cur * 10 + cur % 10 - 1);
     q.push(cur * 10 + cur % 10);
    if (cur % 10 != 9) q.push(cur * 10 + cur % 10 + 1);
  }

  return 0;
}


Measured memory_bytes: 4736
// AOJ ALDS1_3_C Doubly Linked List
// 2018.5.1 bal4u

#include <stdio.h>

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void skip(int k) { while (k--) gc(); }

void out(int n)
{
	int i;
	char ob[20];

	if (!n) { pc('0'); return; }
	i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
	while (i--) pc(ob[i]); 
}

int que[2000005]; int top, end;

int main()
{
	int n, i, t;
	char op;

	n = in(); top = 0, end = 1;
	while (n--) {
		if (gc() == 'i') {
			skip(6);
			que[end++] = in();
		} else {
			skip(5);
			op = gc();
			if (op == 'F') {
				skip(5);
				end--;
			} else if (op == 'L') {
				skip(4);
				top++;
			} else {
				que[top] = t = in();
				for (i = end-1; que[i] != t; i--);
				if (i > top) {
					if (end - i < i - top) {
						while (++i < end) que[i-1] = que[i];
						end--;
					} else {
						while (--i > top) que[i+1] = que[i];
						top++;
					}
				}
			}
		}
	}
	t = 0;
	for (i = end-1; i > top; i--) {
		if (t) pc(' ');
		else t = 1;
		out(que[i]);
	}
	pc('\n');
	return 0;
}


Measured memory_bytes: 5316
N = input()
A = list(map(int,input().split()))
cnt = 1
for i,a in enumerate(A):
	if i == 0:
		flag = 0
	elif flag == 0 and a == A[i - 1]:
		pass
	elif a >= A[i - 1] and flag >= 0:
		flag = 1
	elif a <= A[i - 1] and flag <= 0:
		flag = -1
	else:
		flag = 0
		cnt += 1
print(cnt)

Measured memory_bytes: 14252
void solve();

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

//////////////////////////////////////////////////
//////////////////////////////////////////////////
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <limits.h>
#include <math.h>
#include <iomanip>
using namespace std;
typedef pair<int, int> pii;
typedef long double ld;
typedef long long ll;

vector<int> A,B;
int N;

void solve() {
	cin >> N;
	A.resize(N + 1); B.resize(N);
	for (int n = 0; n <= N; n++)cin >> A[n];
	for (int n = 0; n < N; n++)cin >> B[n];
	long long counter = 0;
	for (int n = 0; n < N; n++) {
		if (A[n] > B[n]) {
			counter += B[n];
			A[n] -= B[n];
			continue;
		}
		else {
			counter += A[n];
			B[n] -= A[n];
			if (A[n + 1] <= B[n]) {
				counter += A[n + 1];
				B[n] -= A[n + 1];
				A[n + 1] = 0;
			}
			else {
				counter += B[n];
				A[n + 1] -= B[n];
				B[n] = 0;
			}
			continue;
		}
	}
	cout << counter << endl;
	return;
}

Measured memory_bytes: 1024
def digits_of(num)
  num.to_s.chars.reverse!.map(&:to_i)
end

def palindrome?(num)
  ds = digits_of(num)
  ds.size.times do |i|
    if ds[i] != ds[-(i + 1)]
      return false
    end
  end

  true
end

a, b = gets.split.map(&:to_i)

puts a.upto(b).count { |n| palindrome?(n) }


Measured memory_bytes: 1916
#include <iostream>
#include <ccomplex>
#include <vector>
#include <cassert>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>
#include <time.h>
#include <stack>
#include <locale>
#include <clocale>
#include <ctype.h>
#include <wchar.h>
#include <random>
#include <vector>
#include <unordered_map>
#include <bitset>

using namespace std;
typedef long long int LL;
typedef long long int ll;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

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

  LL N, M;
  cin >> N >> M;

  vector<LL> v(N, 0);
  vector<vector<LL>> g(N);
  REP(i, M)
  {
    LL a, b;
    cin >> a >> b;
    a--;b--;
    v[a]++;
    v[b]++;

    g[a].push_back(b);
    g[b].push_back(a);
  }

  if(N+2<=M){
    bool flag = true;
    REP(i, v.size())
    {
      if(v[i]%2!=0){
        flag = false;
      }
    }
    if(flag){
      LL cnt = 0;
      REP(i, v.size())
      {
        if(v[i]>=4){
          cnt++;
        }
        if(v[i]>=6){
          cnt += 3;
        }
      }
      if(cnt>=3){
        cout << "Yes" << endl;
      }else
      if(cnt<=1){
        cout << "No" << endl;
      }else{
        LL start = -1;
        LL goal = -1;
        REP(i, v.size())
        {
          if(v[i]==4){
            if(start==-1){
              start = i;
            }else{
              goal = i;
            }
          }
        }
        bool flag = false;
        REP(i, g[start].size())
        {
          LL old = start;
          LL now = g[start][i];
          while(true){
            if(now==start){
              flag=true;
              break;
            }
            if(now==goal){
              break;
            }
            LL next = -1;
            REP(j, g[now].size())
            {
              if(g[now][j]!=old){
                next = g[now][j];
              }
            }
            old = now;
            now = next;
          }
        }
        if(flag){
          cout << "Yes" << endl;
        }else{
          cout << "No" << endl;
        }
      }
    }
    else
    {
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }
}


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

int main(){
	long long n,a,b;
	long long q,r;
	cin >> n >> a >> b;
	q = n / (a+b);
	r = n % (a+b);
	if(r > a)
		cout << a * q + a << endl;
	else
		cout << a * q + r << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f(i,a,b) for(int i=a; i<b; i++)
#define F first
#define S second
using namespace std;

int main() 
{
	int n, flag = 0, j = 0, m = 0;
    cin>>n;
    string s[n];
    f(i, 0, n) cin>>s[i];
    sort(s, s+n);
    pair <int, string> p[n];
    f(i, 0, n)
    {
        p[j].S = s[i];
        while(s[i] == p[j].S)
        {
            p[j].F++;
            i++;
        }
        i--;
        j++;
    }
    f(i, 0, n) m = max(m, p[i].F);
    f(i, 0, n) if(p[i].F == m) cout<<p[i].S<<endl;
	return 0;
}

Measured memory_bytes: 17408
a=int(input())
b=int(input())
if a==3 and b==1 :
  print(2)
elif a==1 and b==2 :
  print(3)
elif a==2 and b==3 :
  print(1)
elif a==3 and b==2 :
  print(1)
elif a==1 and b==3 :
  print(2)
elif a==2 and b==1 :
  print(3)


Measured memory_bytes: 3060
import sys
from math import factorial
from fractions import Fraction
import heapq, bisect, fractions
import math
import itertools
sys.setrecursionlimit(10 ** 5 + 10)
INF = 10**15 +5
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
MOD = 10**9 + 7

n, k = MAP()
S, P, R = MAP()
t = input()

lis = [[] for i in range(k)]
for i in range(n):
    lis[i%k].append(t[i])

res = 0
for i in range(k):
    for j in range(len(lis[i])):
        if j != 0 and lis[i][j] == lis[i][j-1]:
            lis[i][j] = 'n'
        if lis[i][j] == 'r':
            res += R
        if lis[i][j] == 's':
            res += S
        if lis[i][j] == 'p':
            res += P

print(res)

Measured memory_bytes: 80252
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
long long inf=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  vector<int> r(3);
  REP(i,3){
    cin>>r[i];
  }
  sort(r.begin(),r.end());
  REP(i,3){
    if(i==2 && r[i]==7){
      continue;
    }else if(r[i]==5){
      continue;
    }else{
      cout<<"NO"<<endl;
      return 0;
    }
  }
  cout<<"YES"<<endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
#define double long double
using namespace std;
const int maxn=1e6+10;
int ln[maxn],po[maxn],dis[maxn],head[maxn],Q,ans,fa[maxn],col[maxn],len[maxn],z,kl,v1,v2,m,x,y,n,t;
struct line{int fr,to,next;}q[maxn*2];
struct asuka{int x,y,z;}ask[maxn];
void dfs(int x,int dist,int co)
{
    if(dist==0)return;
    dis[x]=max(dis[x],dist);
    if(!col[x])col[x]=co;
    for(int p=head[x];int v=q[p].to;p=q[p].next)
        if(dis[v]<dist-1)dfs(v,dist-1,co);
}
void pushline(int f,int t)
{
    q[++kl].to=t;q[kl].fr=f;
    q[kl].next=head[f];head[f]=kl;
}
int main()
{
    cin>>n>>m;
    for(int i=1;i<=m;i++)cin>>x>>y,pushline(x,y),pushline(y,x);
    cin>>Q;
    for(int i=1;i<=Q;i++)cin>>ask[i].x>>ask[i].y>>ask[i].z;
    for(int i=Q;i>=1;i--)
    {
        if(dis[ask[i].x]<ask[i].y+1)dfs(ask[i].x,ask[i].y+1,ask[i].z);
    }
    for(int i=1;i<=n;i++)cout<<col[i]<<endl;
}
/*
我被爆踩了
这样搞
如果操作x在操作y前并且x的全部范围都在y中 那么它没有任何意义
考虑倒扫，不断维护每个节点d的最远影响范围，这东西很容易做，在bfs的过程中记一下d就好了
如果发现用不着当前操作就直接跳。
这应该还是可以很好地被卡
……
*/

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

int main(int argc, char const *argv[])
{
	int n, m; cin >> n >> m;
	vector<int> a(n); rep(i, n) cin >> a[i];
	priority_queue<int> que;
	rep(i, n) que.push(a[i]);

	rep(i, m) {
		int d = que.top(); que.pop();
		que.push(d / 2);
	}
	ll ans = 0;
	while (not que.empty()) {
		ans += que.top();
		que.pop();
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1276
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define for0(n) for(i=0; i<(n); i++)
#define forn1 for(i=1; i<=n; i++)


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    ll _,i,j,n,a,b,e,k,u,t,x=1,m,y,q,f=1,c=0,d=0,l,p,z,o,r,g;
    string ss,s;
    cin>>n>>k;
    ll aa[n+1];
    memset(aa,0,sizeof(aa));
    for0(k)
    {
        cin>>x;
        for(j=0;j<x;j++)
        {
            cin>>y;
            aa[y]++;
        }
    }
    for0(n+1)
    {
        if(aa[i]==0)c++;
    }
    cout<<--c<<endl;


}


Measured memory_bytes: 3664
#include<string>
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
using namespace std;
typedef long long int llint;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
const llint mod=1000000007;
const llint big=1e9+1e8;
const llint red=0xE869120;
const llint pro=1002001;
//2n C n
int main(void){
	llint n,i,j,q,ans=0;
	llint na=big;
	cin>>n;
	for(i=0;i<n;i++){cin>>q;ans+=q;if(q%10!=0){na=min(na,q);}}
	if(ans%10!=0){cout<<ans<<endl;return 0;}
	if(na>=ans){cout<<0<<endl;return 0;}
	cout<<ans-na<<endl;
	return 0;
}


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

int N;

bool isPrime(int n)
{
    bool flg = true;

    if (n == 2)
        return true;

    if (n % 2 == 0) {
        return false;
    }

    for (int i = 3; i <= n / 2; i += 2) {
        if (n % i == 0) {
            flg = false;
            break;
        }
    }

    return flg && (n != 1 && n != 0);
}

int main()
{
    cin >> N;

    int ans = 0;
    for (int i = N; i < INT_MAX; i++) {
        if (isPrime(i)) {
            ans = i;
            break;
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
// 2020-06-05 17:53
#include <bits/stdc++.h>
using namespace std;

// 深さ2の全探索すればおk

int main() {
    int N, M;
    cin >> N >> M;
    vector<vector<int>> G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        --a, --b;
        G[a].push_back(b);
        G[b].push_back(a);
    }

    // 0 -> M-1まで行く
    stack<pair<int, int>> Task;
    Task.emplace(0, 0);
    while (!Task.empty()) {
        auto P = Task.top();
        Task.pop();
        if (P.first == N - 1 && P.second == 2) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
        if (P.second >= 2) continue;
        for (int to : G[P.first]) {
            Task.emplace(to, P.second + 1);
        }
    }
    cout << "IMPOSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 12784
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define in(n) for(int i=0;i<n;i++)
#define inj(n) for(int j=0;j<n;j++)
#define itn int
#define ll long long 
#define ull unsigned ll
#define int ll int
#define S second 
#define F first 
#define mod 1000000007
#define globalbool 2000000
#define pii pair<int,int>
#define N 100000
using namespace std;
using namespace std::chrono;
int Nodes[N+5]={0};
vector<int>Graph[N+1];
bool visited[N+1]={0};
int dfs(int curr)
{
	if(Nodes[curr]!=0)
	{
		return Nodes[curr];
	}
	int sz=Graph[curr].size();
	in(sz)
	{
		Nodes[curr]=max(Nodes[curr],dfs(Graph[curr][i])+1);
	}
	return Nodes[curr];
}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	auto start = high_resolution_clock::now();
	int n,m;
	cin>>n>>m;
	in(m)
	{
		int a,b;
		cin>>a>>b;
		Graph[a].push_back(b);
	}
	int ans=INT_MIN;
	for(int i=1;i<=n;i++)
		ans=max(ans,dfs(i));
	cout<<ans;
	auto stop = high_resolution_clock::now();
    //auto duration = duration_cast<microseconds>(stop - start); 
  
    //cout << "Time taken by function: "
    //<< duration.count() << " microseconds" << endl;
}

Measured memory_bytes: 8064
/******************************************************************************

Welcome to GDB Online.
GDB online is an online compiler and debugger tool for C, C++, Python, PHP, Ruby, 
C#, VB, Perl, Swift, Prolog, Javascript, Pascal, HTML, CSS, JS
Code, Compile, Run and Debug online from anywhere in world.

*******************************************************************************/
#include <cstdio>

int main(){
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    int x,y,z;
    if(a<c){
        x=c-a;
    }
    else{
        x=a-c;
    }
    
    if(a<b){
        y=b-a;
    }
    else{
        y=a-b;
    }
    
    if(b<c){
        z=c-b;
    }
    else{
        z=b-c;
    }
    if(x<=d || (y<=d && z<=d)){
        printf("Yes");
    }
    else{
        printf("No");
    }
}


Measured memory_bytes: 1688
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rItr(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define Itr(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define setp(n) fixed << setprecision(n)
#define lf double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	vi a(3);
	rep(i,3) cin>>a[i];
	sort(all(a));
	cout<<a[2]*10+a[0]+a[1]<<endl;
	return 0;
}

Measured memory_bytes: 256