akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define fore(p,x) for(int p=eh[x];p;p=adj[p])
#define gpf(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
typedef long long ll;
const int N = 110000;
const int MX = 1e9;

int to[N * 2], adj[N * 2], eh[N], tot;
int l[N], r[N], c[N];
int n, fl;

void addedge(int a, int b){
	to[++tot] = b;
	adj[tot] = eh[a];
	eh[a] = tot;
	to[++tot] = a;
	adj[tot] = eh[b];
	eh[b] = tot;
}

void dfs(int now, int pre){
	if (fl) return;
	int tl, tr;
	tl = MX;
	fore(p, now) if (to[p] != pre){
		dfs(to[p], now);
		if (l[to[p]] != MX){
			if (c[now] != -1){
				if ((c[now] % 2) == (l[to[p]] % 2) || c[now] < l[to[p]] - 1 || c[now] > r[to[p]] + 1){
					fl = 1;
					return;
				}
			}
			else{
				if (tl == MX){
					tl = l[to[p]] - 1;
					tr = r[to[p]] + 1;
				}
				else if ((tl % 2) == (l[to[p]] % 2)){
					fl = 1;
					return;
				}
				else{
					tl = max(tl, l[to[p]] - 1);
					tr = min(tr, r[to[p]] + 1);
					if (tr < tl){
						fl = 1;
						return;
					}
				}
			}
		}
	}
	if (c[now] == -1){
		l[now] = tl;
		r[now] = tr;
	}
	else{
		l[now] = r[now] = c[now];
	}
}

void dfs2(int now, int pre){
	if (c[now] == -1){
		if (l[now] == MX) c[now] = c[pre] + 1;
		else{
			if (pre == 0) c[now] = l[now];
			else if (c[pre] + 1 > r[now]) c[now] = c[pre] - 1;
			else c[now] = c[pre] + 1;
		}
		//printf("%d %d\n", now, c[now]);
	}
	fore(p, now) if (to[p] != pre) dfs2(to[p], now);
}

int main(){
	scanf("%d", &n);
	rep(i, 1, n - 1){
		int a, b;
		scanf("%d%d", &a, &b);
		addedge(a, b);
	}
	memset(c, -1, sizeof(c));
	int k;
	scanf("%d", &k);
	rep(i, 1, k){
		int v, p;
		scanf("%d%d", &v, &p);
		c[v] = p;
	}
	fl = 0;
	dfs(1, 0);
	if (fl){
		puts("No");
		return 0;
	}
	//rep(i, 1, n) printf("%d %d\n", l[i], r[i]);
	dfs2(1, 0);
	puts("Yes");
	rep(i, 1, n) printf("%d\n", c[i]);
	return 0;
}

Measured memory_bytes: 10368
n = int(input())
t, a = (int(i) for i in input().split())
h = list(int(i) for i in input().split())
for i in range(n):
    h[i] = abs(t-0.006*h[i]-a)

h_sub = sorted(h)
print(h.index(h_sub[0])+1)

Measured memory_bytes: 3060
#include <iostream>

using namespace std;
int l[200000 + 5],r[200000 + 5],ans[505][505];
int n,m,Q,p,q;
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	cin >> n >> m >> Q;
	for(int i = 1;i <= m;++i){
		cin >> l[i] >> r[i];
		ans[1][r[i]]++;ans[l[i] + 1][r[i]]--;
	}
	for(int i = 1;i <= n;++i)
		for(int j = 1;j <= n;++j)
			ans[i][j] += ans[i - 1][j] + ans[i][j - 1] - ans[i - 1][j - 1];
	while(Q--){
		cin >> p >> q;
		cout << ans[p][q] << endl;
	}
	return 0;
}

Measured memory_bytes: 3456
#include<iostream>
#include<cmath>
using namespace std;
int N_MAX=101;
int main()
{
  int n,i,t,res=10000;
  int w[N_MAX];
  cin >> n;
  w[0]=0;
  for(i=0;i<n;i++){
    cin >> t;
    w[i+1]=w[i]+t;
  }
  for(i=1;i<n;i++){
    t=abs(w[n]-2*w[i]);
    if(t<res) res=t;
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vb = vector<bool>;
using vc = vector<char>;
using vs = vector<string>;
using vvi = vector<vector<int>>;
using vvc = vector<vector<char>>;
using pii = pair<int, int>;
#define rep(i,n) for(int i=0; i<(int)(n);i++)

int main(){
  int a,b,c,d,e,k;
  cin >> a >> b >> c >> d >> e >> k;
  e = e - a;
  if(e <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 256
//g++ -std=c++14 test.cpp -o test.out

#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <iomanip>
#include <vector>
#include <queue>
#include <map> 
#include <utility>
#include <limits.h>
#include <bitset>
#include <set>
using namespace std;
 
#define LL long long int
const LL INF = (LL)(1e18)+1;
const int INF_INT = 2147483647-1e6;
const LL mod = 1000000007ll;
const int mod_int = 1000000007;

int N;
int A[200000];
LL counter[200001];//整数iの書かれたボールが出てきた回数をcounter[i]とおく

vector<LL> ans;

void solve(){
	//整数iの書かれたボールを2つ、取り出す方法の数
	vector<LL> cases(N+1,0);
	for(int i=1;i<=N;i++){
		cases[i] = (counter[i]-1)*counter[i]/2;
	}
	//整数iの書かれたボールを一つを除いた上で2つ、取り出す方法の数
	vector<LL> cases_without_one(N+1,0);
	for(int i=1;i<=N;i++){
		if(counter[i]==0) cases_without_one[i] = 0;
		else cases_without_one[i] = (counter[i]-2)*(counter[i]-1)/2;
	}

	LL sum = 0;//casesの合計
	for(int i=1;i<=N;i++) sum += cases[i];
	for(int i=1;i<=N;i++){
		ans.push_back(sum - cases[A[i-1]] + cases_without_one[A[i-1]]);
	}
}
 
int main(){
    cin >> N;
    for(int i=0;i<=N;i++) counter[i] = 0;
    for(int i=0;i<N;i++){
    	cin >> A[i];
    	counter[A[i]]++;
    }
 
    solve();

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

Measured memory_bytes: 7924
#!/usr/bin/env python3
#ABC131 C

import sys
import math
import bisect
sys.setrecursionlimit(1000000000)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

def gcd(n,m):
    if m == 0:
        return n
    else:
        return gcd(m,n%m)
def lcm(n,m):
    return (n*m)//gcd(n,m)

a,b,c,d = LI()
i,j,k = (a-1)//c,(a-1)//d,(a-1)//lcm(c,d)
s,t,u = b//c,b//d,b//lcm(c,d)
x = b - s - t + u
y = (a-1) - i - j + k
print(x -y)


Measured memory_bytes: 38484
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

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

	for(int n; cin >> n, n;) {
		bool first_white;
		vector<int> stone(1, 1);

		int tmp;
		cin >> tmp;
		first_white = (tmp == 0);

		for(int i = 2; i <= n; ++i) {
			int in;
			cin >> in;

 			const int size = stone.size();
			bool same_color = (((size + first_white) & 1) == in);

			if(i & 1) {
				if(same_color)
					++stone[size - 1];

				else
					stone.push_back(1);
			}
			else {
				if(same_color)
					++stone[size - 1];

				else {
					if(size == 1) {
						first_white = !first_white;
						++stone[size - 1];
					}
					else {
						stone[size - 2] += stone[size - 1] + 1;
						stone.pop_back();
					}
				}
			}
		}

		int cnt = 0;
		for(int i = (first_white ? 0 : 1); i < stone.size(); i += 2)
			cnt += stone[i];
		
		cout << cnt << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 1224
#include<stdio.h>
#pragma GCC optimize("O2")
#define rep(i,N) for(int i=0;i<(int)N;i++)
int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
void Radix32(int A[],const int sz)
{
  int temp[200001];const int bit=8;
  rep(k,4)
  {
    int u[256]={},v[256]={};
    rep(i,sz)u[A[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)u[i+1]+=u[i];
    rep(i,sz){temp[--u[A[sz-1-i]>>bit*k&((1<<bit)-1)]]=A[sz-1-i];}k++;
    rep(i,sz)v[temp[i]>>bit*k&((1<<bit)-1)]++;
    rep(i,(1<<bit)-1)v[i+1]+=v[i];
    rep(i,sz)A[--v[temp[sz-1-i]>>bit*k&((1<<bit)-1)]]=temp[sz-1-i];
  }
}
int main(void)
{
  int N=IN(),x,p=0,m=0,z=0,A[200000];
  long K,count=0,l=-2e18,r=-l,mid;x=scanf("%ld",&K);
  rep(i,N){x=IN();if(x>0)A[m+p++]=x;else if(x<0)A[p+m++]=x;else z++;}
  Radix32(A,m+p);
  if(K>1l*m*p&&K<1l*m*p+1l*z*(N-1)/2)return puts("0"),0;
  if(K<=1l*m*p)r=1l;else l=-1l;
  while(l<=r)
  {
    mid=(l+r)/2;count=0;
    if(mid>=0)
    {
      int plus=p-1,minus=m-1;count+=1l*z*(p+m)+1l*z*(z-1)/2+1l*p*m;
      rep(i,plus){while(1l*A[i]*A[plus]>mid){plus--;}if(i>=plus){break;}count+=1l*plus-i;}
      rep(i,minus){while(1l*A[m+p-1-i]*A[m+p-1-minus]>mid){minus--;}if(i>=minus){break;}count+=1l*minus-i;}
    }
    else{int low=0;rep(i,m){while(1l*A[low]*A[p+i]>mid&&low<p){low++;}count+=1l*p-low;}}
    if(count>=K)r=mid-1l;else l=mid+1l;
  }
  return printf("%ld\n",l),0;
}

Measured memory_bytes: 3076
#include <bits/stdc++.h>
    using namespace std;
     
    int main() {
      string N;
      int a;
      cin >> N;
      
    for (int i = 0; i < N.size(); i++) {
      
      if (N.at(i) == '7') {
        a++;
      }

    }
      if(a>0){
        cout << "Yes" << endl;
      }else{
        cout << "No" << endl;
      }

    }

Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define LL long long
using namespace std;

int a[2003];
int main(){
	int n;scanf("%d",&n);	
	for(int i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+1+n);
	int ans = 0;
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans += max((int)(lower_bound(a+1,a+1+n,a[i]+a[j]) - a - 1 - j) , 0);
	printf("%d\n",ans);
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	if(s[s.size()-1]=='s')
	{
		cout<<s<<"es"<<endl;
	}
	else
	{
		cout<<s<<"s"<<endl;
	}
	return 0;
 } 

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

int main(void) {
    string str;
    char letter;
    int count;
    int depth;
    double sum;
    int amount;
    int water[20000] = {};
    
    getline(cin, str);
    
    count = 0;
    
    int i = 0;
    int checked = 0;
    while(checked < str.length()) {
        sum = 0;
        depth = 0;
        i = checked;
        while(i < str.length()) {
            letter = str[i];
            switch(letter) {
                case '/'  : --depth;   sum += depth + 0.5;   break;
                case '_'  : sum += depth;   break;
                case '\\' : ++depth;   sum += depth - 0.5;   break;
            }
            if(depth <= 0) {
                if(letter == '/' && depth == 0) {
                    water[count] += sum;
                    ++count;
                    checked = i;
                }
                sum = 0;
                depth = 0;
            }
            ++i;
        }
        ++checked;
    }
    
    amount = 0;
    for(int j = 0; j < count; ++j) {
        amount += water[j];
    }
    
    cout << amount << endl;
    cout << count;
    for(int j = 0; j < count; ++j) {
        cout << ' ' << water[j];
    }
    cout << endl;
    
    return 0;
}


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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;
  cin >> s;
  int cnt = 0;
  for (auto& c : s) {
    if (c == 'o') {
      cnt++;
    }
  }
  if (cnt + 15 - (int) s.length() >= 8) {
    cout << "YES\n";
  } else {
    cout << "NO\n";
  }
  return 0;
}

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 a ,b;
    cin >> a>>b;
    int x = 0;
    if(a==3) x += 100000;
    if(a==2) x += 200000;
    if(a==1) x += 300000;
    if(b==3) x += 100000;
    if(b==2) x += 200000;
    if(b==1) x += 300000;
    
    if(a==1 && b==1){
        cout << x+400000 << endl;
    }else{
        cout << x << endl;
    }
    return 0;
}


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

    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();

            S = S.Remove(S.Count() - 2);
            while(0<S.Count())
            {
                if (S.Count() % 2 != 0) continue;
                var half = S.Count() / 2;
                var flg = true;
                for (var i = 0;i<half;i++)
                {
                    if (S[i] != S[half + i])
                    {
                        flg = false;
                        break;
                    }
                }
                if (flg) break;
                S = S.Remove(S.Count() - 2);
            }

            Console.WriteLine(S.Count());
        }
    }

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0;i<(int)(n);++i)
#define rep1(i, n) for(int i=1;i<=(int)(n);++i)
#define irep(i, a, n) for(int i=a;i<(int)(n);++i)
#define rrep(i, n) for(int i=(int)(n)-1;i>=0;--i)
#define rrep1(i, n) for(int i=(int)(n);i>=1;--i)
#define allrep(V, v) for(auto&& V:v)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const int INF=1<<29;
const double EPS=1e-9;
using namespace std;


map<long long, long long> prime_factorization(long long n){
  map<long long, long long> factors;
  for(lint div=2; div*div <= n; ++div){
    if(n % div != 0) continue;
    int count = 0;
    while(n % div == 0){
      ++count;
      n /= div;
    }
    factors[div] = count;
  }
  if(n != 1) factors[n] = 1;
  return factors;
}

int main (void)
{
  lint n,p; cin>>n>>p;
  if(n==1){
    cout << p << endl;
    return 0;
  }
  map<lint,lint> factors = prime_factorization(p);
  lint ans=accumulate(all(factors), (lint)1, [n](lint sum, pair<lint,lint> f){return f.second>=n ? sum*pow(f.first,(f.second/n)) : sum;});
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import math

class Vector:
    def __init__(self,x,y):
        self.x = x
        self.y = y
        
    def __add__(self,other):
        return Vector(self.x+other.x,self.y+other.y)
    
    def __sub__(self,other):
        return Vector(self.x-other.x,self.y-other.y)
    
    def __mul__(self,scalar):
        return Vector(self.x*scalar,self.y*scalar)
    def __rmul__(self, scalar):
        return Vector(self.x*scalar,self.y*scalar)
   
    def __repr__(self):
        return str([self.x,self.y])
        
    def norm_2(self):
        return dot(self,self)
    
    def norm(self):
        return math.sqrt(self.norm_2())
    
def v_sum(v1,v2):
    return Vector(v1.x+v2.x,v1.y+v2.y) 
def scalar_multi(k,v):
    return Vector(k*v.x,k*v.y)
def v_diff(v1,v2):
    return v_sum(v1,scalar_multi(-1,v2))
    
def dot(vector1,vector2):
    return vector1.x*vector2.x+vector1.y*vector2.y

def cross(vector1,vector2):
    return vector1.x*vector2.y-vector1.y*vector2.x
    
    
def in_seg(p,s,t):
    '''
    whether point p is in the area of segment(s,t)
    '''
    x = p-s
    d = t-s
    if 0<=dot(x,d)/d.norm_2()<=1:
        return True
    else:
        return False
    
def is_crossed(p,q,s,t):
    a = q-p
    b = t-s
    v = s-p
    w = t-p
    x = p-s
    y = q-s
    if cross(a,v)*cross(a,w)<=0 and cross(b,x)*cross(b,y)<=0:
        if cross(a,v) == cross(a,w) == cross(b,x) == cross(b,y) == 0: 
            #if segments are on the same line, you must check whether an end point is in the other segment at least
            if 0<=dot(a,v)<=a.norm_2() or 0<=dot(a,w)<=a.norm_2() or 0<=dot(b,x)<=b.norm_2() or 0<=dot(b,y)<=b.norm_2():
                return True
            else:
                return False
        else:    
            return True
    else:
        return False
    
def point_line_dist(p,s,t):
    x = p-s
    d = t-s
    return abs(cross(x,d))/d.norm()

def calc(p1,p2,p3,p4):
    min_dists = []
    if in_seg(p1,p3,p4):
        min_dists.append(point_line_dist(p1,p3,p4))
    if in_seg(p2,p3,p4):
        min_dists.append(point_line_dist(p2,p3,p4))
    if in_seg(p3,p1,p2):
        min_dists.append(point_line_dist(p3,p1,p2))
    if in_seg(p4,p1,p2):
        min_dists.append(point_line_dist(p4,p1,p2))
    
    min_dists.append((p1-p3).norm())
    min_dists.append((p1-p4).norm())
    min_dists.append((p2-p3).norm())
    min_dists.append((p2-p4).norm())
    
    if is_crossed(p1,p2,p3,p4):
        min_dists.append(0)
    
    return min(min_dists)

q = int(input())

for i in range(q):
    x1,y1,x2,y2,x3,y3,x4,y4 = map(float,input().split())
    p1 = Vector(x1,y1)
    p2 = Vector(x2,y2)
    p3 = Vector(x3,y3)
    p4 = Vector(x4,y4)
    print(calc(p1,p2,p3,p4))


Measured memory_bytes: 5724
#include<iostream>
#include<cstring>

using namespace std;

void reverseChar(char* str);

char str[50],rstr[50];
int i;

int main()
{
    cin>>str;
    reverseChar(str);
    cout<<str << endl;
    return 0;
}

void reverseChar(char* str)
{
    for(i=0;i<strlen(str)/2;i++)
    {
        char temp= str[i];
        str[i]=str[strlen(str)-i-1];
        str[strlen(str)-i-1]=temp;
    }
}

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

arr = [0]+list(map(int,input().split()))

max_index = 0
max_ = 0
for i in range(N+1):
    if abs(arr[i]) >= max_:
        max_ = abs(arr[i])
        max_index = i

print(2*N-2)
for i in range(1,N+1):
    if i != max_index:
        print('{0} {1}'.format(max_index, i))

if arr[max_index] > 0:
    for i in range(1,N):
        print('{0} {1}'.format(i, i+1))
else:
    for i in range(N, 1,-1):
        print('{0} {1}'.format(i, i-1))

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


int main() {

    ios_base::sync_with_stdio(false); 
    cin.tie(NULL);  
	string s;
	cin>>s;
	long long ans = 0;
  	vector<long long> a(s.size() + 1), b(s.size() + 1);
 
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '<') a[i + 1] = a[i] + 1;
  }
 
  for (int i = s.size() - 1; i >= 0; i--) {
    if (s[i] == '>') b[i] = b[i + 1] + 1;
  }
 
  for (int i = 0; i <= s.size(); i++) ans += max(a[i], b[i]);
  cout << ans << endl;

	return 0;		
}


Measured memory_bytes: 8732
// inputに入力データ全体が入る
function Main(input) {
	var line = input.split("\n");
	var tmp = line[0].split(" ");
	var a = Number(tmp[0]);
	var b = Number(tmp[1]);
	if(a*b%2 === 0) console.log('Even');
	else console.log('Odd');
	return false;
}

//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 7372
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

class Main {
	public static void main(String args[]) {
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

		String ans = "NO";
		for (int i = a; i <= a * b; i += a) {
			if (i % b == c) {
				ans = "YES";
				break;
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<algorithm>	
#include<cmath>
using namespace std;
int main() {
	long long n, a, sum = 0, num = 1, ans = 1; cin >> n;
	int test[123456], uiop[123456] = { 0 };
	for (int h = 0; h < n; h++) {
		cin >> test[h];
		if (h == 0 && test[h] == 0) {
			sum = 1;
		}
		else if (test[h] == 0) {
			sum = 0;
		}
	}
	sort(test, test + n);
	if (sum == 0) {
		cout << 0 << endl; return 0;
	}
	for (int h = 1; h < n; h++) {
		if (test[h] == num) {
			uiop[num]++;
		}
		else if (test[h] == num + 1) {
			num++; uiop[num]++;
		}
		else {
			cout << 0 << endl; return 0;
		}
	}
	for (int h = 1; h < num; h++) {
		for (int i = 0; i < uiop[h + 1]; i++) {
			ans *= uiop[h];
			ans = ans % 998244353;
		}
		ans = ans % 998244353;
	}
	cout << ans % 998244353 << endl;
	cin >> n;
}

Measured memory_bytes: 1152
//
//  second.cpp
//  CoderTest
//
//  Created by yuya on 2019/05/23.
//  Copyright © 2019 yuya. All rights reserved.
//

#include<bits/stdc++.h>
#define ll long long
using namespace std;

int main()
{
    int i;
    int N,M;
    
    cin >> N >> M;
    
    int L,R;
    int Lmax=1, Rmin=N;
    
    for(i=0;i<M;i++){
        cin >> L >> R;
        Lmax = max(Lmax, L);
        Rmin = min(Rmin, R);
    }
    
    
    
    
    if(Lmax <= Rmin) cout << Rmin - Lmax +1 << endl;
    else cout << 0 << endl;


    return 0;
}


Measured memory_bytes: 256
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<numeric>
#include<cassert>
#include<random>
#include<chrono>
#include<unordered_map>
#include<fstream>
#include<list>
#include<functional>
#include<bitset>
#include<complex>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
typedef pair<double,ll> pdl;
#define F first
#define S second
const ll E=1e18+7;
const ll MOD=1000000007;



int main(){
    priority_queue<ll,vector<ll>,greater<ll>> Q;
    string s;
    cin>>s;
    vector<ll> dp(26,0);
    for(int i=0;i<s.size();i++){dp[s[i]-'a']++;}
    ll count=0;
    for(int i=0;i<26;i++){
        if(dp[i]!=0){Q.push(dp[i]); count++;}
    }
    ll sum=0;
    for(int i=1;i<count;i++){
        ll a=Q.top(); Q.pop();
        ll b=Q.top(); Q.pop();
        sum+=a+b;
        Q.push(a+b);
    }
    cout<<max(sum,(ll)s.size())<<endl;
    
    
    
    
    return 0;
}



Measured memory_bytes: 3324
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep2(i,s,n) for (int i = s; i < n; ++i)
#define all(a) a.begin(),a.end()
#define tmax(a,b,c) max(a,max(b,c))
#define tmin(a,b,c) min(a,min(b,c))
#define pb push_back
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> inline bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;

const int mod = 1000000007;
struct mint {
  ll x;
  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;
  }
  void operator++() {
      x += 1;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  void operator--() {
      x -= 1;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=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 {
    mint res(*this);
    return res/=a;
  }
};
struct combination {
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1) {
    assert(n < mod);
    fact[0] = 1;
    for (int i = 1; i <= n; ++i) fact[i] = fact[i-1]*i;
    ifact[n] = fact[n].inv();
    for (int i = n; i >= 1; --i) ifact[i-1] = ifact[i]*i;
  }
  mint operator()(int n, int k) {
    if (k < 0 || k > n) return 0;
    return fact[n]*ifact[k]*ifact[n-k];
  }
};

int main() {
    int x,y;
    cin >> x >> y;
    combination c(1000000);
    if((x+y)%3 != 0) {
        cout << 0 << endl;
        return 0;
    }
    int n = (x+y)/3;
    int a = -1,b = -1;
    rep(i,n+1) {
        if(i+(n-i)*2 == x && i*2+(n-i) == y) {
            a = i;
            b = n-i;
        }
    }
    if(a == -1) {
        cout << 0 << endl;
        return 0;
    }
    cout << c(n,a).x << endl;
}

Measured memory_bytes: 15872
#include <stdio.h>
#include <vector>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>
#include <bitset>
#include <map>
#include <set>
#include <tuple>
#include <string.h>
#include <math.h>
#define MOD 1000000007ll

using namespace std;

using ii = pair<int, int>;
using i64 = long long int;
using ii64 = pair<long long int, long long int>;

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

	int ans = str.size();
	
	for (int i = 0; i < str.size() - 1; i++)
	{
		if (str[i] != str[i + 1])
		{
			ans = min(ans, max(i + 1, (int)str.size() - i - 1));
		}
	}

	printf("%d", ans);

	return 0;
}



Measured memory_bytes: 512
package main

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

func main() {
	var N, K int
	fmt.Scan(&N, &K)
	A := make([]int, N)
	F := make([]int, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sumA := 0
	for i := range A {
		sc.Scan()
		A[i], _ = strconv.Atoi(sc.Text())
		sumA += A[i]
	}
	for i := range F {
		sc.Scan()
		F[i], _ = strconv.Atoi(sc.Text())
	}
	sort.Ints(A)
	sort.Sort(sort.Reverse(sort.IntSlice(F)))
	// fmt.Println("N", N, "K", K, "A", A, "F", F)
	if K >= sumA { // 全員の消化コストを0にすることが可能
		fmt.Println(0)
	} else {
		// Aを昇順に、Fを降順にソートして、i番目のメンバーにi番目の食べ物を担当させるのが最適
		// 全てのメンバーについて完食にかかる時間をx以下にできるか？という問題を考える
		// 一人当たりで完食にかかる時間の最低値は0、最大値は10^6 x 10^6 = 10^12
		left, right := -1, int(1e12)
		cnt := 1
		for right-left > 1 {
			target := (right + left) / 2
			if isOK(A, F, target, K) {
				right = target
			} else {
				left = target
			}
			cnt++
		}
		fmt.Println(right)
	}
}

func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func isOK(a, f []int, target, training int) bool {
	var sum int
	for i := 0; i < len(a); i++ {
		sum += max(0, a[i]-target/f[i]) // 目標完食時間をXとしたときの、各人に必要なトレーニング回数
	}
	if sum <= training { // sum <= trainingであれば、間食目標 targetを達成できる
		return true
	}
	return false
}


Measured memory_bytes: 6272
N = int(input())
h = [int(val) for val in input().split(' ')]
dp = [0, abs(h[0]-h[1])]

for i in range(len(h)-2):
    step1_cost = dp[i+1] + abs(h[i+1]-h[i+2])
    step2_cost = dp[i] + abs(h[i]-h[i+2])
    dp.append(min(step1_cost, step2_cost))
print(dp[-1])

Measured memory_bytes: 13980
#include<bits/stdc++.h>
using namespace std;
#define lop(i,n) for(ll i=0;i<n;i++)
#define lop1(i,n) for(ll i=1;i<=n;i++)
#define lopr(i,n) for(ll i=n-1;i>=0;i--)
#define ll long long int
#define pb push_back
#define all(v) v.begin(),v.end()
#define IOS  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define endl "\n"
#define F first
#define S second	
#define mem(arr,val) memset(arr,val,sizeof(arr))
#define pii pair<int,int>
#define pll pair<ll,ll>
#define LCM(a,b) (a*b)/__gcd(a,b)
#define mii map<int,int>
#define mll map<ll,ll>
#define ub upper_bound
#define lb lower_bound
#define sz(x) (ll)x.size()
#define ld long double
#define pcnt(x) __builtin_popcountll(x)
const long long I1=1e9;
const long long I2=1e18;
const int32_t M1=1e9+7;
const int32_t M2=998244353;
template<typename T,typename T1>T maxn(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T minn(T &a,T1 b){if(b<a)a=b;return a;}
ll dp[100001][101];
pll w[101];
void solve()
{
  //code begins from here//
  int n,k;
  cin>>n>>k;
  lop1(i,n) cin>>w[i].F>>w[i].S;
  sort(w+1,w+n+1);
  lop(i,101) dp[0][i]=0;
  lop1(i,k)
  {
      lop1(j,n)
      {
        if((i-w[j].F>0 && dp[i-w[j].F][j-1]>0) || i==w[j].F) maxn(dp[i][j],dp[i-w[j].F][j-1]+w[j].S);
        maxn(dp[i][j],dp[i][j-1]);
        //cout<<dp[i][j]<<" ";
      }
      //cout<<endl;
  }
  ll ans=0;
  lop1(i,k) maxn(ans,dp[i][n]);
  cout<<ans<<endl;
}

signed main()
{
    IOS;
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef MODULO
        initialize();
    #endif
    #ifdef SIEVE
        sieve();
    #endif
    int testcase=1;
   // cin>>testcase;
    while(testcase--) solve();
    return 0;
}


Measured memory_bytes: 82192
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include<map>
using namespace std;
int main()
{
    int n,h,w;
    scanf("%d%d%d",&n,&h,&w);
    int ans=0;
    for(int i=0;i+h-1<n;i++){
        for(int j=0;j+w-1<n;j++){
            ans++;
        }
    }
    /*for(int i=0;i+w-1<n;i++){
        for(int j=0;j+h-1<n;j++){
            ans++;
        }
    }*/
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<cstdlib>
#include<algorithm>
#include<queue>
#include<vector>
#include<set>
#include<set>
#include<map>
#include<ctime>
#include<iostream>
using namespace std;
typedef long long LL;
const int maxn = 1e5 + 5;
int A[maxn],D[maxn],U[maxn];
int main()
{
	int N;
	while( scanf(" %d",&N ) != EOF ){
		int fst = 0,sum = 0;
		for( int i = 1 ; i <= N ; i++ ){
			scanf(" %d",&A[i]);
			if( i == 1 )
				D[i] = abs(0 - A[i]); 
			else
				D[i] = abs(A[i-1] - A[i]);
			if( i == 2 )
				U[i-1] = abs(0 - A[i]);
			else
				U[i-1] = abs(A[i-2] - A[i]);
			sum += D[i];
		}
		int X = abs(A[N] - 0);
		sum += X;
		for( int i = 1 ; i <= N-1 ; i++ ){
			printf("%d\n",sum-D[i]-D[i+1]+U[i]);
		}
		printf("%d\n",sum-X-D[N]+abs(A[N-1]-0));
	}
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
const ll mod = 998244353 ;
const double pi = acos(-1);
ll fastpow(ll b, ll e) {
    if (!e)
        return 1;
    ll ret = fastpow(b, e / 2);
    ret = (ret * ret) % mod;
    if (e % 2)
        ret = (ret * b) % mod;
    return ret;
}
ll modinv(ll x) {
    return fastpow(x, mod - 2);
}
double torad(double ang) {
    return ang * pi / 180.0;
}
int prime[N];
void sieve() {
    prime[0] = prime[1] = 1;
    for (int i = 2; i < N; i++) {
        if (!prime[i]) {
            for (int j = i; j < N; j += i)
                prime[j] = i;
        }
    }
}

int main()
{
    ///smallest/largest case
    ///initialize
    int n;
    scanf("%d", &n);
    int a[N];
    for (int i = 0; i < n; i++)
        scanf("%d", &a[i]);
    int dp[N] = {0};
    dp[n - 2] = abs(a[n - 1] - a[n - 2]);
    for (int i = n - 3; i >= 0; i--) {
        dp[i] = min(dp[i + 1] + abs(a[i] - a[i + 1]),
                    dp[i + 2] + abs(a[i] - a[i + 2]));
    }
    printf("%d\n", dp[0]);
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>

using namespace std;

const int MAX = 8;
char m[MAX][MAX];
int dx[] = {0,0,1,-1,1,1,-1,-1};
int dy[] = {1,-1,0,0,1,-1,1,-1};
struct Pos{
  int x,y,n;
  Pos(int a,int b,int c):x(a),y(b),n(c){}
};

void input(){
  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++)
      cin >> m[i][j];
}


bool isInside(int x, int y){return 0<=x&&x<MAX&&0<=y&&y<MAX;}


bool turnable(int x, int y, char c, int dir){
  
  int nx = x+dx[dir];
  int ny = y+dy[dir];
  bool flg = false;
  while(isInside(nx,ny) && m[ny][nx] != '.'){
    if(c != m[ny][nx]) flg = true;
    if(c == m[ny][nx]) return flg;
    nx += dx[dir];
    ny += dy[dir];
  }
  return false;
}

int turn(int y, int x, char c){

  if(m[y][x] != '.') return -1;

  int tmp = -1;
  int sum = 0;
  bool valid = false;
  for(int i = 0; i < 8; i++){
    int nx = x+dx[i];
    int ny = y+dy[i];
    bool flg = false;
    int step = 0;
    while(isInside(nx,ny) && m[ny][nx] != '.'){
      step++;
      if(c != m[ny][nx]) flg = true;
      if(c == m[ny][nx]){
	valid = valid||flg;
	if(flg) sum += step-1;
	break;
      }
      nx += dx[i];
      ny += dy[i];
    }
  }
  if(valid) tmp = max(tmp,sum);
  return tmp;
}

void choose(Pos& p,char c){

  for(int i = 0; i < MAX; i++)
    for(int j = 0; j < MAX; j++){
      int tmp = turn(i,j,c);
      if(c == 'x' && tmp >= p.n) p = Pos(j,i,tmp);
      if(c == 'o' && tmp > p.n) p = Pos(j,i,tmp);
    }
}


void put(int x, int y, char c){

  m[y][x] = c;

  for(int i = 0; i < 8; i++)
    if(turnable(x,y,c,i)){
      int nx = x;
      int ny = y;
      while(m[ny+=dy[i]][nx+=dx[i]] != c) m[ny][nx] = c; 

    }
}

void print(){
  for(int i = 0; i < MAX; i++){
    for(int j = 0; j < MAX; j++) cout << m[i][j];
    cout << endl;
  }
}

void solve(){

  int rev = 0;
  while(1){
    char c[] = {'o','x'};
    bool update = false;
    for(int i = 0; i < 2; i++){
      Pos p(0,0,-1);
      choose(p,c[i]);
      if(p.n != -1){
	update = true;
	put(p.x,p.y,c[i]);
      }
    }
    if(!update) break;
  }
}



int main(){

  input();
  solve();
  print();

  return 0;
}

Measured memory_bytes: 1136
#include <stdio.h>
#include <stdlib.h>
#define INF 100000000

typedef struct{
  int num;
  char c;
}Card;

Card A[100000],B[100000];
  int n;

int partition(int p, int r);

void merge(Card *, int, int, int);
void mergeSort(Card *, int, int);

void quicksort(int p, int r){
  int q,i;
  //  for(i=0;i<n;i++)printf("%d ",A[i].num);printf("\n");
  if(p<r)
    {
      q = partition(p,r);
      quicksort(p, q-1);
      quicksort(q+1, r);

    }
  
}


int table(void){

  int i;

  for(i=0;i<n;i++){
    if(A[i].c!=B[i].c)return 0;

  }

  return 1;
}


int main(){
  int i;

  scanf("%d",&n);
  
  for(i=0;i<n;i++){
    scanf(" %c%d",&A[i].c,&A[i].num);
    B[i].c = A[i].c;
    B[i].num = A[i].num;
  }

  quicksort(0,n-1);
  mergeSort(B, 0, n);

  if(table())printf("Stable\n");
  else printf("Not stable\n");

  for(i=0;i<n;i++){
    printf("%c %d\n",A[i].c,A[i].num);
  }
  
  return 0;
}
int partition(int p, int r){
  int i,j;
  Card x,tmp;

  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j].num <= x.num){
      i++;
      tmp = A[j];
      A[j] = A[i];
      A[i] = tmp;
    }
  }
  tmp = A[r];
  A[r] = A[i+1];
  A[i+1] = tmp;
  return i+1;

}

void mergeSort(Card *A, int left, int right){

  int mid;
  
  if(left+1 < right){
    mid = (left+right)/2;
    mergeSort(A, left, mid);
    mergeSort(A, mid, right);
    merge(A, left, mid, right);


  }


}

void merge(Card *A, int left, int mid, int right){

  int i,j,k,n1,n2;
  Card l[500000],r[500000];
  
  n1 = mid - left;
  n2 = right - mid;
  
  // l = malloc(sizeof(int)*n1);
  // r = malloc(sizeof(int)*n2);

  for(i=0;i<n1;i++)l[i]=A[left+i];
  for(i=0;i<n2;i++)r[i]=A[mid+i];
  l[n1].num=INF;r[n2].num=INF;
  i=0;j=0;

  for(k=left;k<right;k++){
    if(l[i].num<=r[j].num){
      A[k]=l[i];
      i++;
    }
    else{
      A[k]=r[j];
      j++;
    }

  }
  
}



Measured memory_bytes: 4068
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

#define Pig (OO)

using namespace std;

const int dx[]={-1,0,1,0};
const int dy[]={0,-1,0,1};

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

ll n,k;
ll a[200010],f[200010];
ll needconsum[200010];

bool chk(ll mid)
{
	for(int i=0;i<n;i++)needconsum[i]=mid/f[i];
	
	ll needtrain=0ll;
	
	for(int i=0;i<n;i++)needtrain+=max(0ll,a[n-i-1]-needconsum[i]);
	
	return(needtrain>k);
}

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>n>>k;
	for(int i=0;i<n;i++)cin>>a[i];
	for(int i=0;i<n;i++)cin>>f[i];
	
	sort(a,a+n);
	sort(f,f+n);
	
	ll L=0ll,R=1000000000000000000ll;
	
	while(L<R)
	{
		ll mid=(L+R)>>1ll;
		
		if(chk(mid))L=mid+1;
		else R=mid;
	}
	
	cout<<L;
		
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    int N,X,T;
    cin >> N >> X >> T;
    int ans = 0;
    if(N%X!=0) ans+=T;
    ans += N/X * T;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int a,b;
  cin>>a;
  bool ok=false;
  for(int i=1;i<=9;i++){
    if(a%i==0&&a/i<10)
      ok=true;
  }
  if(ok)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  return 0;
}

Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

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

int main() {

  int P, Q, R;
  int m, s;
  s = 0;
  m = 0;
  REP(i, 3){
    cin >> P;
    s += P;
    m = max(m, P);
  }

  cout << (s - m) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cassert>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define rep(i,n) FOR(i,0,n)
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define vint vector<int>
#define vdouble vector<double>
#define vstring vector<string>
using namespace std;

#include<map>
#include<set>
#include<queue>

typedef long long ll;
typedef unsigned long long ull;

const int MAX_N = 1000000;
const int INFTY = (1 << 21); // 2097152
// const ll INFTY = (1LL << 60);
const ll MD = 1000000007LL;
// fprintf(stderr, "%d %lld \n", x, xll);


int N, K;
ll X[50], Y[50];

int main() {
	cin >> N >> K;
	rep(i, N) {cin >> X[i] >> Y[i]; }

    ll ret = -1;

	rep(ix1, N)
	rep(iy1, N)
	rep(ix2, N)
	rep(iy2, N){
        ll x1 = X[ix1];
        ll x2 = X[ix2];
        ll y1 = Y[iy1];
        ll y2 = Y[iy2];
		if(x1 < x2 && y1 < y2){
			int c = 0;
			rep(i, N){
				if(x1 <= X[i] && X[i] <= x2 && y1 <= Y[i] && Y[i] <= y2) c++;
			}
			if(c >= K){
				ll m = (x2 - x1) * (y2 - y1);
				if(ret == -1) {ret = m;}
				else {ret = min(m, ret);}
			}
		}
	}

	cout << ret << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll unsigned long long int
#define mod 1000000007
bool isPrime[1000001];
ll power(ll a,ll b)
{
    ll result = 1;
    while(b>0)
    {
        if(b%2)
        {
            result = (a*result)%mod;
        }
        a = (a*a)%mod;
        b = b/2;
    }
    return result;
}
int gcd(int a,int b)
{
    if(b==0)
    {
        return a;
    }
    return gcd(b,a%b);
}
void sieve()
{
    memset(isPrime,1,sizeof(isPrime));
    isPrime[0] = isPrime[1] = 0;
    for(int i=2;i*i<=1000000;i++)
    {
        if(isPrime[i])
        {
            for(int j=i*i;j<=1000000;j+=i)
            {
                isPrime[j] = 0;
            }
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL),cout.tie(NULL);
    int t,n;
    t = 1;
    for(int i=0;i<t;i++)
    {
        char c;
        cin>>c;
        cout<<char(c+1);
    }
    return 0;
}


Measured memory_bytes: 3648
A, B, K = map(int, input().split())
if A + K > B:
  for a in range(A, B + 1):
    print(a)
else:
  for a in range(A, A + K):
    print(a)
  for b in range(max(A + K, B - K + 1), B + 1):
    print(b)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main(){
  int k,ans=1;
  cin>>k;
  int m=7%k;
  for(int i=0;i<k+5;i++){
    if(m==0){
      cout<<ans;
      return 0;
    }
    m=(m*10+7)%k;
    ans++;
  }
  cout<<"-1";
}

Measured memory_bytes: 3628
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;

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

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

    rep(i, n-1) {
        l[i+1] = gcd(l[i], a[i]);
    }
    for(int i = n-1; i >= 1; i--) {
        r[i-1] = gcd(r[i], a[i]);
    }
    int ans = 1;

    rep(i, n) {
        ans = max(ans, gcd(l[i], r[i]));
    }

    cout << ans;

    cout << endl;
    return 0;
}

Measured memory_bytes: 1536
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a1 = sc.nextInt();
        int a2 = sc.nextInt();
        int a3 = sc.nextInt();
        if (a1 + a2 + a3 >= 22) {
            System.out.println("bust");
        } else {
            System.out.println("win");
        }
    }

}

Measured memory_bytes: 23380
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  cin >> N;
  pair<ll, pair<ll, ll>> p[N];
  for(int i=0;i<N;i++){
    cin >> p[i].second.first;
    cin >> p[i].second.second;
    p[i].first = p[i].second.first + p[i].second.second;
  }

  sort(p, p + N);
  reverse(p, p + N);

  ll takahashi = 0LL;
  ll aoki = 0LL;

  for(int i=0;i<N;i++){
    if(i % 2 == 0){
      takahashi += p[i].second.first;
    }
    else{
      aoki += p[i].second.second;
    }
  }

  cout << takahashi - aoki << endl;
  return 0;


}

Measured memory_bytes: 2560
N,L=map(int,input().split())
tot=0#全部使った場合
for i in range(1,N+1):
    tot+=(L+i-1)
l=[]
for i in range(N):
    l.append(tot-(L+(i+1)-1))#
#print(l)
#print(tot)
#lの要素の中でtotとの差が最も小さいものを出力する
for i in range(len(l)):
    if i==0:
        ans=l[i]
        dif=abs(l[i]-tot)
    else:
        if dif>abs(l[i]-tot):
            dif=abs(l[i]-tot)
            ans=l[i]
print(ans)

Measured memory_bytes: 3064
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));

  $x = factorize($n);

  $ans = 0;
  foreach($x as $key => $p){
    $j = 1;
    while($p >= $j){
      $ans++;
      $p -= $j;
      $j++;
    }
  }

  echo $ans;


  function factorize($n){
  $res = [];
  for($i=2; $i*$i<$n; $i++){
    if($n % $i != 0) continue;
    $res[$i]=0;
    while($n % $i == 0){      
      $res[$i]++;
      $n /= $i;
    }
  }
  if($n != 1){
    $res[$n]=1;
  }
  return $res;
}

Measured memory_bytes: 16196
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef pair<int, int> P;
const int c_INF = 11111111111;
const int c_mINF = -11111111111;
const int c_YET = -1;
const int c_Dx[4] = { 0,0,1,-1 };
const int c_Dy[4] = { 1,-1,0,0 };

int main() {
	char S[10];
	scanf("%s", S);
	int count0 = 0;
	int count1 = 0;
	int count2 = 0;
	int count3 = 0;
	if (S[0] == S[1]) {
		count0++;
		count1++;
	}
	if (S[0] == S[2]) {
		count0++;
		count2++;
	}
	if (S[0] == S[3]) {
		count0++;
		count3++;
	}
	if (S[1] == S[2]) {
		count2++;
		count1++;
	}
	if (S[1] == S[3]) {
		count3++;
		count1++;
	}
	if (S[2] == S[3]) {
		count2++;
		count3++;
	}



	if (count0 == 1 && count1 == 1 && count2 == 1 && count3 == 1)printf("Yes");
	else printf("No");
	


}


/*         提出前の確認事項

・デバッグ用の関数は＜＜コメント化＞＞しているか？
・すべての＜＜入力例＞＞は試したか？
・＜＜限界値分析＞＞はしたか？
・＜＜出力の改行＞＞の有無は確認したか？
　　　　　　　　↓
	 ＜＜提出先＞＞に注意して提出！！
*/

Measured memory_bytes: 128
#include <iostream>
using namespace std;
#include<stdlib.h>
#include<stdio.h>
int main(){
    long long a,b,n,m;
    cin>>a>>b;
    for(int i=0;i<10000;i++){
        n=0.08*i;
        m=0.1*i;
        if(n==a && m==b){
            cout<<i<<"\n";
            return 0;
        }
        
    }
    cout<<"-1\n";
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef long double ld;
const double pi=acos(-1.0);
const ll mod=pow(10,9)+7;
const ll INF=pow(2,31)-1;
using str=string;
typedef pair<int,int> P;
typedef vector<int> vi;

ll gcd(ll a,ll b){
    ll v0=a,v1=b,v2=a%b;
    while(v2!=0){
        v0=v1;
        v1=v2;
        v2=v0%v1;
    }
    return v1;
}

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

int main(){
    int n; cin >> n;
    vector<int> a(n);
    rep(i,n){
        cin >> a[i];
    }
    int ans=0,nxt=1;
    rep(i,n){
        if(nxt==a[i]) nxt++;
        else ans++;
    }
    if(ans==n) ans= -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	int n;
	string s;
	cin >> n >> s;
	int ans = 0;
	for(int i = 0; i < 1000; i++) {//000から999まで全探索
		int c[3] = {i/100,(i/10)%10,i%10};//各桁の数字を分ける
		int counter = 0;
		for(int j= 0; j < n; j++) {
			if(s[j] == (c[counter] + '0')){//当てはまる数字が見つかった時
				counter++;//次の桁へ
			}
			if(counter == 3){//三つ揃った
				break;
			}
		}
		if(counter == 3){
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
using namespace std;
int main(void){
    int n,h[100002],c[100002];
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    c[0]=0;
    c[1]=abs(h[0]-h[1]);
    for(int i=2;i<n;i++){
        c[i]=min(c[i-1]+abs(h[i]-h[i-1]),c[i-2]+abs(h[i]-h[i-2]));
    }
    cout<<c[n-1]<<endl;
}


Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		List<Integer> rows = new ArrayList<>();
		List<Integer> columns = new ArrayList<>();
		boolean flag=true;
		
		while (true) {
			int h = s.nextInt();
			int w = s.nextInt();
			if(h==0 && w==0) {
				break;
			}
			if(h>=3 && w>=1 && h<=300 && w<=300) {
				rows.add(h);
				columns.add(w);
			}else {
				flag = false;
				break;
			}
		}
		
		if(flag == true) {
			for(int i=0;i<rows.size();i++) {
				for(int r=0;r<rows.get(i);r++) {
					for(int c=0;c<columns.get(i);c++) {
						if(r==0 || r==rows.get(i)-1) {
							System.out.print("#");
						}else {
							if(c==0 || c==columns.get(i)-1) {
								System.out.print("#");
							}else {
								System.out.print(".");
							}
						}
						
					}
					System.out.println();
				}
				System.out.println();
			}
			}

	}

}

Measured memory_bytes: 34080
import java.io.*;
import java.util.Arrays;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
    String[] line1 = br.readLine().split(" ");
    int x = Integer.parseInt(line1[0]);
    int y = Integer.parseInt(line1[1]);
    int a = Integer.parseInt(line1[2]);
    int b = Integer.parseInt(line1[3]);
    int c = Integer.parseInt(line1[4]);
    
    int[] p = new int[a];
    int[] q = new int[b];
    int[] r = new int[c];
    
    String[] pStr = br.readLine().split(" ");
    String[] qStr = br.readLine().split(" ");
    String[] rStr = br.readLine().split(" ");
    
    for (int i=0; i<a; i++){
      p[i] = Integer.parseInt(pStr[i]);
    }
    for (int i=0; i<b; i++){
      q[i] = Integer.parseInt(qStr[i]);
    }
    for (int i=0; i<c; i++){
      r[i] = Integer.parseInt(rStr[i]);
    }
  
    Arrays.sort(p);
    Arrays.sort(q);
    Arrays.sort(r);
    
    int[] result = new int[x+y];
    System.arraycopy(p, p.length-x, result, 0, x);
    System.arraycopy(q, q.length-y, result, x, y);
    Arrays.sort(result);
    for (int i=0; i<r.length && result[i]<r[r.length-i-1]; i++){
      result[i] = r[r.length-i-1];
    }
    long sum = 0;
    for (int i : result){
      sum += i;
    }
    System.out.println(sum);
  }
}


Measured memory_bytes: 60876
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
int main(void)
{
  int q;
  cin >> q;
  REP(i,q){
    int n;
    cin >> n;
    int answer=0;
    while(n>=10){
      ++answer;
      int tmp=0;
      for(int d=10;d<n;d*=10)
	tmp=max(tmp,(n/d)*(n%d));
      n=tmp;
    }
    cout << answer << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>

int main()
{
	int k,n,i,min,a[1000000];
	
	scanf("%d%d",&k,&n);
	for(i=0;i<n;i++){
	  scanf("%d",&a[i]);
	}
	
	min=a[0]+k-a[n-1];
	for (i=1;i<n;i++){
	  if (a[i]-a[i-1]>min)
	    min=a[i]-a[i-1];
	}
	
	printf("%d",k-min);
}

Measured memory_bytes: 2944
from math import factorial 
def comb(n, r):
  return factorial(n)//(factorial(n-r)*factorial(r))

n,p = map(int,input().split())
al = list(map(int,input().split()))
even = 0
odd = 0
for a in al:
  if a%2 == 0:
    even += 1
  else:
    odd += 1
if p == 1 and odd == 0:
  print(0)
  exit()
ans1 = 2**even
ans2 = 0
if p == 0:
  t = 0
  while t <= odd:
    ans2 += comb(odd,t)
    t += 2
else:
  k = 1
  while k <= odd:
    ans2 += comb(odd,k)
    k += 2
print(ans1*ans2)

Measured memory_bytes: 3064
H, W = map(int, input().split())

w1, w2 = W // 2, W % 2
h1, h2 = H // 2, H % 2

if H > 1 and W > 1:
	num = 2 * w1 * h1 + w2 * h1 + w1 * h2 + w2 * h2 
else:
  num = 1
print(num)



Measured memory_bytes: 2940