akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#define N_MAX 20


int solve(int n ,int a[]){
  int ans=2000001;
  int pon,gon;
  int i,j;
  for(i=0;i<(1<<n)-1;i++){
    pon=0;
    gon=0;
    for(j=0;j<n;j++){
      if(1<<j&i){
        pon+=a[j];
      }else{
        gon+=a[j];
      }
    }
    if(abs(pon-gon)<ans){
      ans=abs(pon-gon);
    }
  }
  return ans;
}
int main(){
  int n;
  int a[N_MAX];
  int i;
  while(1){
    scanf("%d",&n);
    if(n==0){
      break;
    }
    for(i=0;i<n;i++){
      scanf("%d",a+i);
    }
    printf("%d\n",solve(n,a));

  }

  return 0;
}

Measured memory_bytes: 600
def main120():
    import sys
    S_org = input()
    S = []

    for s in range(len(S_org)):
        S.append(S_org[s])
    S = list(map(int, S))

    cont = True
    index = 0
    count = 0

    if len(S) == 1:
        print(0)
        sys.exit()

    else:
        while(cont):
            if S[index] == S[index+1]:
                index += 1
            else:
                count += 2
                S.pop(index)
                S.pop(index)
                if index > 0:
                    index -= 1

            if index == len(S) - 2:
                if S[index] != S[index+1]:
                    count += 2
                print(count)
                sys.exit()


main120()

Measured memory_bytes: 4860
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		int M = scan.nextInt();
		int Q = scan.nextInt();
		int [][]A = new int[N + 1][N + 1];
		for(int i = 0; i < M; i++) {
			int L = scan.nextInt();
			int R = scan.nextInt();
			A[L][R] ++;
		}
		int [][]B = new int[N + 1][N + 1];
		for(int i = 1; i <= N; i++) {
			for(int j = 1; j <= N; j++) {
				B[i][j] += A[i][j] + B[i][j - 1];
			}
		}
		int [][]C = new int[N + 1][N + 1];
		for(int i = 1; i <= N; i++) {
			for(int j = 1; j <= N; j++) {
				C[j][i] += B[j][i] + C[j-1][i];
			}
		}
		StringBuilder sb = new StringBuilder();
		for(int i = 0; i < Q; i++) {
			int p = scan.nextInt();
			int q = scan.nextInt();
			int cnt = C[q][q] - C[q][p - 1] - C[p - 1][q] + C[p - 1][p - 1];
			sb.append(cnt).append("\n");
		}
		scan.close();
		System.out.println(sb.toString());

//		for(int i = 1; i <= N; i++) {
//			for(int j = 1; j <= N; j++) {
//				System.out.print(B[i][j] + " ");
//			}
//			System.out.println();
//		}
//
//
//		for(int i = 1; i <= N; i++) {
//			for(int j = 1; j <= N; j++) {
//				System.out.print(C[i][j] + " ");
//			}
//			System.out.println();
//		}

	}
}

Measured memory_bytes: 152068
using System.Collections.Generic;
using System.Linq;

public class Hello
{
    public static void Main()
    {
        hoge();
        System.Console.ReadLine();
    }

    public static void hoge()
    {
        var line = System.Console.ReadLine().Split(' ').Select(x=>int.Parse(x)).ToArray();
        var n = line[0];
        var r = line[1];

        if(n < 10)
        {
            r += 100 * (10 - n);
        }

        System.Console.WriteLine(r);
    }

}


Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
long long f[333][333][333];

long long solution(int n,int x,int y){
  f[0][1][0]=1;
  for(int i=0;i<=n;i++)
    for(int j=1;j<=x;j++)
      for(int p=i;p>=0;p--){
          if(p) (f[i][j][p-1]+=f[i][j][p]) %= y;
          else (f[i][j+1][i]+=f[i][j][p]) %= y;
          (f[i+1][j][p]+=f[i][j][p]*(p+1)) %= y;
      }
  return f[n][x + 1][n];
}

int main()
{
  int n, x ,y;
  n = 2;
  x = 3;
  y = 100;
  cin>>n>>x>>y;
  long long res = solution(n, x, y);
  cout<<res<<endl;
  return 0;
}


Measured memory_bytes: 262272
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define sqr(x) ((x)*(x))
#define ull unsigned long long
#define mp make_pair
#define ld long double
#define fi first
#define se second
#define PI pair<int,int>
inline char gc(){
    static char buf[100000],*p1=buf,*p2=buf;
    return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
inline ll read(){
	ll x = 0; char ch = gc(); bool positive = 1;
	for (; !isdigit(ch); ch = gc())	if (ch == '-')	positive = 0;
	for (; isdigit(ch); ch = gc())	x = x * 10 + ch - '0';
	return positive ? x : -x;
}
inline void write(ll a){
    if(a<0){
    	a=-a; putchar('-');
	}
    if(a>=10)write(a/10);
    putchar('0'+a%10);
}
inline void writeln(ll a){write(a); puts("");}
inline void wri(ll a){write(a); putchar(' ');}
const int N=100005;
void GG(){
	puts("No"); exit(0);
}
bool vis[N];
int q[N],flag,n;
set<int> v[N];
void era(int s,int t){//cout<<s<<" fj "<<t<<endl;
	v[s].erase(t); v[t].erase(s);
}
void dfs(int p){
	q[++*q]=p; vis[p]=1;
	for(auto i:v[p])if(q[*q-1]!=i){
		if(vis[i]){
			//for(int i=1;i<=*q;i++)cout<<q[i]<<" "; puts("");
			for(int j=*q-1;j;j--){era(q[j],q[j+1]); if(q[j]==i)break;  } era(q[*q],i); flag=1; return;
		}else{
			dfs(i); if(flag)return;
		}
	}
	--*q;
}
bool find(){//puts("zhu");
	memset(vis,0,sizeof(vis)); flag=*q=0;
	for(int i=1;i<=n;i++)if(v[i].size()){ dfs(i); assert(flag); return 1;}
	return 0;
}
int main(){
	n=read(); int m=read();
	for(int i=1;i<=m;i++){
		int s=read(),t=read();
		assert(v[s].count(t)==0); assert(s!=t);
		v[s].insert(t); v[t].insert(s);
	}
	for(int i=1;i<=n;i++)if(v[i].size()&1)GG();
	int sum=0;
	for(int i=1;i<=n;i++){if(v[i].size()>=6){
		puts("Yes"); return 0;
	}sum+=v[i].size()>2;}
	if(sum>2){
		puts("Yes"); return 0;
	}
	for(int i=1;i<=3;i++)if(!find())GG();
	puts("Yes");
}

Measured memory_bytes: 20992
n, m = map(int, input().split())
h =  list(map(int, input().split()))

dic = {}

for _ in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if a not in dic:
        dic[a] = 0
    dic[a] = max(dic[a], h[b])
    if b not in dic:
        dic[b] = 0
    dic[b] = max(dic[b], h[a])

# print(dic)

answer = 0

for idx, hh in enumerate(h):
    if idx not in dic or hh > dic[idx]:
        answer += 1

print(answer)


Measured memory_bytes: 20124
#include<bits/stdc++.h>
using namespace std;
constexpr int mod = 1e9 + 7;
int main()
{
    int n;
    cin >> n;
    int ara[n+5];
    ara[0] = 0;
    for(int i=1; i<=n; i++) cin >> ara[i];
    long long c_sum[n+5], sum = 0;
    for(int i=1; i<=n; i++){
        sum += ara[i];
        sum %= mod;
        c_sum[i] = sum;
    }
    long long ans = 0;
    c_sum[0] = 0;
    for(int i=n; i>=1; i--){
        ans += (ara[i]*c_sum[i-1])%mod;
    }
    cout << ans%mod << endl;
    return 0;

}


Measured memory_bytes: 5932
#include <iostream>

using namespace std;

bool check(string s) {
	if (s[0] != 'A') {
		return false;
	}

	int c = 0;
	for (int i = 2; i < s.length() - 1; i++) {
		if (s[i] == 'C') {
			c++;
		}
	}
	if (c != 1) {
		return false;
	}

	int cap = 0;
	for (int j = 0; j < s.length(); j++) {
		if(s[j] >= 'A' && s[j] <= 'Z') {
			cap++;
		}
	}
	if (cap != 2) {
		return false;
	}
	return true;
}

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

	if (check(s)) {
		cout << "AC" << '\n';
	} else {
		cout << "WA" << '\n';
	}
	return 0;
}

Measured memory_bytes: 256
def s():
 def b(M,x,y,n=1):
  M[x][y]=0;a=n
  if M[x-1][y]:
   t=b(M,x-1,y,n+1)
   if a<t:a=t
  if M[x][y-1]:
   t=b(M,x,y-1,n+1)
   if a<t:a=t
  if M[x+1][y]:
   t=b(M,x+1,y,n+1)
   if a<t:a=t
  if M[x][y+1]:
   t=b(M,x,y+1,n+1)
   if a<t:a=t
  M[x][y]=1
  return a
 for e in iter(input,'0'):
  n,m=int(e),int(input())
  P=[[0]*(n+2)for _ in[0]*(m+2)]
  for i in range(m):P[i+1][1:-1]=map(int,input().split())
  print(max(b(P,i,j)for i in range(1,m+1)for j in range(1,n+1)if P[i][j]))
if'__main__'==__name__:s()


Measured memory_bytes: 5724
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<string>
#include<cmath>
#include<numeric>
#include<vector>
#include<tuple>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define vint vector<int> 
#define vvint vector<vint>
#define ct(a) cout<<a<<endl
typedef long long ll;
const int MOD = 1e9 + 7;

int H, W;

int main(void)
{
	cin >> H >> W;
	if (H%W == 0)cout << -1 << endl;
	else {
		int i = 1;
		while (1) {
			if (H*i%W != 0)cout << H * i << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int i, score;
  int sumA = 0, sumB = 0;

  //Aツつウツづアツづ個債?計ツづーツ計ツ算
  for(i = 0; i < 4; i++){
    scanf("%d", &score);
    sumA += score;
  }

  //Bツつウツづアツづ個債?計ツづーツ計ツ算
  for(i = 0; i < 4; i++){
    scanf("%d", &score);
    sumB += score;
  }

  //Aツづ?ツづ?つソツづァツつェツ妥・ツつォツつ「ツつゥツ板サツ津ィ
  if(sumA > sumB){
    printf("%d\n", sumA);
  }
  else{
    printf("%d\n", sumB);
  }

  return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdio>
#include <vector>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <algorithm>
#include <utility>
#include <cstring>
#include <cmath>
using namespace std;

int cm(int k){
    return 1<=k&&k<=12;
}
int main() {
    int n;
    cin>>n;
    int x=n/100;
    int y=n%100;
    int a[2]={0};
    if(cm(x))a[0]=1;
    if(cm(y))a[1]=1;
    if(a[0]+a[1]==0){
        cout<<"NA"<<endl;
    }else if(a[0]+a[1]==2){
        cout<<"AMBIGUOUS"<<endl;
    }else if(a[0]){
        cout<<"MMYY"<<endl;
    }else{
        cout<<"YYMM"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  int a[n][3];
  for(int j=0;j<n;j++){
    for(int i=0;i<3;i++){
      cin>>a[j][i];
      if(a[j][i]>a[j][0]){
	int b=a[j][0];
	a[j][0]=a[j][i];
      a[j][i]=b;
      }
    }
  }
  for(int i=0;i<n;i++){
    if(a[i][0]*a[i][0]==a[i][1]*a[i][1]+a[i][2]*a[i][2]){
      cout<<"YES"<<endl;
    }else{
      cout<<"NO"<<endl;
    }
  }
  return(0);
}

Measured memory_bytes: 3080
# Minimum cost sort

n = int(input())
*w, = map(int, input().split())
s = list(sorted(w))

si = [0] * 10001
for i, v in enumerate(s):
    si[v] = i

ans = 0
b = [False] * n
for i in range(n):
    if b[i]:
        continue
    j = i
    mw = w[i]
    z = 0
    nn = 0
    while b[j] == False:
        b[j] = True
        nn += 1
        mw = min(w[j], mw)
        z += w[j]
        j = si[w[j]]
    c = min((nn - 2) * mw + z, mw + z + (nn + 1) * s[0])
    ans += c

print(ans)


Measured memory_bytes: 5764
def solve():
  n, k = map(int,input().split())
  group_num = 10
  
  book_map = [[] for i in range(group_num)]
  acc_map = [[0] for i in range(group_num)]

  for i in range(n):
    c,g = map(int,input().split())
    book_map[g - 1].append(c)

  for i in range(group_num):
    book_map[i].sort(reverse=True)
    acc = 0
    for j in range(len(book_map[i])):
      book_map[i][j] += j * 2
      acc += book_map[i][j]
      acc_map[i].append(acc)
#  print(acc_map)  
  dp = [[0] * (k + 1) for i in range(group_num + 1)]
  for y in range(1,k + 1):
    for x in range(1,group_num + 1):
      for z in range(min(y + 1, len(acc_map[x - 1]))):
        dp[x][y] = max(dp[x][y], dp[x - 1][y - z] + acc_map[x - 1][z])
  
  print(dp[group_num][k])
solve()



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

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

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

int main() {
  	int K;
  	cin >> K;
  	int ab, abc;
  	int count = 0;
  
  	for (int a = 1; a <= K; a++){
      	for (int b = 1; b <= K; b++){
          	ab = gcd(a, b);
          	for (int c = 1; c <= K; c++){
              	abc = gcd(ab, c);
              	count += abc;
            }  
        }
    }
  
  	cout << count << endl;
}

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

int main(){

  int N, M;
  cin >> N >> M;
  
  vector<vector<long long>> p(N,vector<long long>(2));
  for(int i=0; i<N; i++)
    cin >> p.at(i).at(0) >> p.at(i).at(1);
  
  sort(p.begin(), p.end());
  
  long long count = 0;
  
  for(int i=0; i<N; i++){
    if( p.at(i).at(1) >= M ){
      count += M*p.at(i).at(0);
      break;
    }else{
      count += p.at(i).at(0) * p.at(i).at(1);
      M -= p.at(i).at(1);    
    }
  }
  
  cout << count << endl;
  
}

Measured memory_bytes: 5760
h,w,k=map(int,input().split())
li=[]
for i in range(h):
  li.append(list(input()))
ans=0
for i in range(1<<h):
  for j in range(1<<w):
    cnt=0
    for p in range(h):
      for q in range(w):
        if i>>p&1:
          continue
        if j>>q&1:
          continue
        if li[p][q]=="#":
          cnt+=1
    if cnt==k:
      ans+=1
print(ans)


Measured memory_bytes: 9192
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#define int long long
#define gmax(x,y) x=max(x,y)
#define gmin(x,y) x=min(x,y)
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define rep(i,a,b) for(int i=a;i<b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB emplace_back
#define PF emplace_front
#define FILL(a,b) memset(a,b,sizeof(a))
#define lwb lower_bound
#define upb upper_bound
using namespace std;
signed main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	int s,k,d;
	cin>>s>>k>>d;
	s=abs(s);
	int t=s/d;
	if(k<t){
		cout<<s-d*k;RE 0;
	}
	int now=s-d*t;
	k-=t;
	if(k&1){
		cout<<d-now;
	}else cout<<now;
	RE 0;
}


Measured memory_bytes: 3648
//
// Created by jal on 2018/10/6 0006.
//

#include <bits/stdc++.h>
using namespace std;
int main() {
  vector<int> v;
  int n;
  cin >> n;
  while (n--) {
    int op;
    cin >> op;
    if (op == 0) {
      int x;
      cin >> x;
      v.push_back(x);
    } else if (op == 1) {
      int x;
      cin >> x;
      cout << v.at(x) << endl;
    } else {
      v.pop_back();
    }
  }
}


Measured memory_bytes: 3888
#include<bits/stdc++.h>
using namespace std;
#define M 1000000007
#define F first
#define S second
#define mp make_pair
#define pb push_back
#define gcd __gcd
#define in(a) scanf("%d",&a)
#define in2(a,b) scanf("%d%d",&a,&b)
#define in3(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define read(v,i,n) for(i=0;i<n;i++)in(v[i])
#define sc(ch) scanf("%c",&ch)
#define sstr(str) scanf("%s",str)
#define pr(n) printf("%d ",n)
#define out(n) printf("%d\n",n)
#define inl(a) cin >> a
#define prl(a) cout << a << " "
#define outl(a) cout << a << endl
#define yes printf("YES\n")
#define no printf("NO\n")
#define lin printf("\n")
#define dbg(v,i,n) for(i=0;i<n;i++)pr(v[i]); lin
#define ck printf("continue\n")
#define all(vec) vec.begin(),vec.end()
#define asc(vec) sort(vec.begin(),vec.end())
#define lower(v,k) lower_bound(v.begin(),v.end(),k)-v.begin()
#define upper(v,k) upper_bound(v.begin(),v.end(),k)-v.begin()
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<pair<int,int> >
#define vvi vector<vector<int> >
#define viii vector<pair<int,pair<int,int> > >
#define vvii vector<vector<pair<int,int> > >
#define lp(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define N 3005
typedef long long int ll;
double dp[N][2*N];
int main()
{
    int n,i,j;
    in(n);
    vector<double> v(n+1);
    dp[0][N]=1;
    cout << setprecision(15) << fixed;
    lp(i,1,n+1)
        inl(v[i]);
    lp(i,1,n+1)
    {
        lp(j,1,2*N-1)
            dp[i][j]=v[i]*dp[i-1][j-1]+(1-v[i])*dp[i-1][j+1];
    }
    double ans=0;
    lp(j,N+1,2*N)
        ans+=dp[n][j];
    outl(ans);
}


Measured memory_bytes: 141056
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}
//******************************************************************************
template<typename T>vector<T>
make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts){
	return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

template<typename T,typename V>
typename enable_if<is_class<T>::value==0>::type
fill_v(T &t,const V &v){t=v;}

template<typename T,typename V>
typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t,const V &v){
	for(auto &e:t) fill_v(e,v);
}

int A,B,C,D,E,F,X,Y,Z,N,M,W,R,Q;
string s,t;

signed main()
{
	int N,K;
	cin>>N>>K;
	cout<<N-K+1<<endl;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import bisect
import heapq
import itertools
import math
import numpy as np
from collections import Counter, defaultdict, deque
from copy import deepcopy
from decimal import Decimal
from math import gcd
from operator import add, itemgetter, mul, xor
def cmb(n,r,mod):
  bunshi=1
  bunbo=1
  for i in range(r):
    bunbo = bunbo*(i+1)%mod
    bunshi = bunshi*(n-i)%mod
  return (bunshi*pow(bunbo,mod-2,mod))%mod
mod = 10**9+7
def I(): return int(input())
def LI(): return list(map(int,input().split()))
def MI(): return map(int,input().split())
def LLI(n): return [list(map(int, input().split())) for _ in range(n)]



#いまいるところ,
#listとnが与えられたときn回テレポートしたところを出力する
def now_place(li,n):
    now = 1
    for i in range(n):
        now = li[now-1]
    return now

#p回のテレポートでたどってきた道筋のルートを返す

def root(li,p):
    ans = []
    now = 1
    for j in range(p):
        ans.append(now_place(li,j+1))
    return ans



n,k = MI()
a = LI()
#訪れたところのメモがtown
town = []
#訪れたかどうかを0と1で管理
visit=[0]*n
p = 1
while visit[p-1] == 0:
    town.append(p)
    visit[p-1] = 1
    p = a[p-1]
#香りだかい町がいつでてきたか→周期に入るまでのテレポート回数
#len(town[l:])は周期を表す
l = town.index(p)
if k <len(town):
    print(town[k])
else:
    print(town[l + (k-l)%(len(town[l:]))])


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

int main(){ 
  Int H;
  cin >> H;
  Int now = 1, ans = 0;
  
  while (H > 0) {
    ans += now;
    H = H/2;
    now = now * 2;
  }
  
  //ans += now;
  
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
int m, nmin, nmax;

int main() {
    int n;
    while(cin >> n, n){
        int W, H; cin >> W >> H;
        int field[101][101]={0};
        for(int i=0; i<n; ++i){
            int a, b; cin >> a >> b;
            field[b-1][a-1]++;
        }
        int ans=0;
        int S, T; cin >> S >> T;
        for(int i=0; i<H-T+1; ++i){
            for(int j=0; j<W-S+1; ++j){
                int cnt=0;
                for(int k=0; k<T; ++k){
                    for(int l=0; l<S; ++l){
                        if(field[k+i][j+l]==1) cnt++;
                    }
                }
                ans = max(ans, cnt);
            }
        }
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3076
# -*- coding: utf-8 -*-


def main():
    n, k = map(int, input().split())
    v = list(map(int, input().split()))
    reverse_v = v[::-1]
    ans = 0

    for left in range(k + 1):
        for right in range(k - left + 1):
            if left + right > n:
                continue

            remain = k - (left + right)
            merged_v = sorted(v[:left] + reverse_v[:right])
            merged_v_len = len(merged_v)
            minus = 0

            for i in range(min(remain, merged_v_len)):
                if merged_v[i] < 0:
                    minus += merged_v[i]

            ans = max(ans, sum(merged_v) - minus)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 41820
a, b, c = map(int, input().split())

# 自転車のベルを2つ買う。
# ベルは3種類で、それぞれ a円、b円、c円。
# この 3つのうち、異なる 2つのベルを選んで買うときの、値段の合計の最小値を求めて下さい。b

print(min(a+b, b+c, a+c))

Measured memory_bytes: 9156
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var split = Console.ReadLine().Split(' ');
            int n = int.Parse(split[0]);
            int k = int.Parse(split[1]);
            Hashtable h = new Hashtable();
            List<int> hashkeys = new List<int>();
            for (int i = 0; i < n; i++)
            {
                int temp = int.Parse(Console.ReadLine());
                if (h.ContainsKey(temp))
                {
                    h[temp] = int.Parse(h[temp].ToString()) + 1;
                }
                else
                {
                    h[temp] = "1";
                    hashkeys.Add(temp);
                }

            }

            //
            hashkeys.Sort();
            int score = int.MaxValue - 1;
            int lower_index = 0;
            int higher_index = 0;
            int sum_trees = int.Parse(h[hashkeys[lower_index]].ToString());
            int sum_score = 0;


            while (higher_index < hashkeys.Count)
            {
                //scoreを更新する
                if (lower_index >= hashkeys.Count) break;
                sum_score = hashkeys[higher_index] - hashkeys[lower_index];

                //もし、sum_treesがk以上なら、成功パターンなので、後ろを短くする。
                if (sum_trees >= k)
                {
                    


                    if (score > sum_score) score = sum_score;

                    lower_index++;
                    sum_trees -= int.Parse(h[hashkeys[lower_index-1]].ToString());

                }

                //もし、sum_treesがk未満なら、まだ足りないので、前を長くする。
                else
                {
                    higher_index++;
                    if (higher_index >= hashkeys.Count) break;
                    sum_trees += int.Parse(h[hashkeys[higher_index]].ToString());
                    
                }

                //higher_indexがhashkeys.countを超えたらbreak ここでやる


                




            }

            Console.WriteLine(score);
        }
    }
}


Measured memory_bytes: 29528
#!/usr/bin/env python3
import sys
try: from typing import Any, Union, List, Tuple, Dict
except ImportError: pass
sys.setrecursionlimit(10**6)
def debug(*args): print(*args, file=sys.stderr)
def exit(): sys.exit(0)

N, K = map(int, input().split())

if K % 2 == 1:
    NK = N // K
    NK2 = 0
else:
    NK = N // K
    NK2 = N // (K//2) - NK
debug(NK, NK2)
print(NK**3 + NK2**3)


Measured memory_bytes: 38256
import sys
read = sys.stdin.buffer.read
input = sys.stdin.readline
input = sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode('utf-8')

#import numpy as np

def main():
	n=II()
	C=[]
	pre=0
	for i in range(n):
		a=II()
		if a!=pre:
			C.append(a)
		pre=a
	#print(C)

	n=len(C)
	dp=[0]*(n+1)
	dp[1]=1
	li=[0]*(max(C)+10)
	li[C[0]]=1

	for i in range(1,n):
		#print(dp)
		#print(li)
		dp[i+1]=(dp[i]+dp[li[C[i]]])%(10**9+7)
		li[C[i]]=i+1
	print(dp[-1])


if __name__ == "__main__":
	main()


Measured memory_bytes: 24404
#include <stdio.h>

int main()
{
    unsigned int a, b, c, d;
    scanf("%u %u %u %u", &a, &b, &c, &d);

    unsigned int area_ab = a * b, area_cd = c * d;

    if (area_ab > area_cd) printf("%u", area_ab);
    else                   printf("%u", area_cd);

    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
#define rep(i,n) for(int i=0;i<(int)n;i++)
const ll INF=(1LL<<61)-1;


int main(){
    int N; cin >> N;
    vector<int> L(N);
    rep(i,N) cin >> L[i];
    sort(L.begin(),L.end());
    //rep(i,N) cout << L[i] << endl;
    ll res = 0;
    rep(i,N-2){
        for(int j=i+1;j<N-1;j++){
            int l = L[i]+L[j];
            if(L[i]==L[j]) continue;
            if(upper_bound(L.begin(),L.end(),L[j]) == L.end()) continue;
            int x = upper_bound(L.begin(),L.end(),L[j]) - L.begin();
            for(int k=x;k<N;k++){
                //cout << L[i] << L[j] << L[k] << endl;
                if(L[k]<l) res++;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 3624
#include <iostream>
#include <cmath>
#define pi 3.14159265358979323846
using namespace std;
 
int main(){
  double A, B, H, M;
  cin >> A >>B >>H >>M;
  double theta = abs(30.0*H- 5.5*M);
  theta = sqrt(A*A + B*B - 2*A*B*cos(theta/180 * pi));
  cout.precision(20);
  cout <<theta <<endl;
  return 0;
}

Measured memory_bytes: 4176
#include <bits/stdc++.h>
#define MAX (ll)(2e2 + 7)
#define INF (ll)(5e5 + 7)
#define MOD (ll)(1e9 + 7)

using namespace std;
using ll = long long;
using cd = complex<double>;

int main () {
	ll n, k;
	cin >> n >> k;
	ll c[n], p[n];
	bool ch[n] = {};
	for (ll i = 0; i < n; i++)  {
		cin >> p[i];
	}
	for (ll i = 0; i < n; i++)  {
		cin >> c[i];
	}
	ll ans = -MOD;
	for (ll i = 0; i < n; i++) {
		if (ch[i]) {
			continue;
		}
		vector<ll> ve;
		ll cur = i;
		ll ts = 0;
		while (ch[cur] == 0) {
			ve.push_back (c[cur]);
			ts += c[cur];
			ch[cur] = 1;
			cur = p[cur] - 1;
		}
		ll nv = ve.size (), lim = min (k, (ll)ve.size ());
		for (ll i = 0; i < ve.size (); i++) {
			ll co = 0;
			for (ll j = 0; j < lim; j++) {
				co += ve[(i + j) % nv];
				ans = max (co + max (0LL, ts * ((k - j - 1) / nv)), ans);
			}
		}
	}
	cout << ans << "\n";
}


Measured memory_bytes: 3720
import math 
def primeFactors(n): 
    a=[]  
    while n % 2 == 0: 
        a.append(2) 
        n = n // 2
    for i in range(3,int(math.sqrt(n))+1,2):  
        while n % i== 0: 
            a.append(i) 
            n = n // i  
    if n > 2: 
        a.append(n) 
    return a    
import math as m
n=int(input())
x=0
i=0
a=list(set(primeFactors(n)))
ans=0
p=1
flag=False
while(i<len(a)):
    j=a[i]
    x=a[i]
    while(True):
        if n%j==0:  
            ans+=1 
            n//=j
            j*=x
        else:
            break
        if p==n:
            flag=True
            break
    if(flag):break    
    i+=1         
print(ans)        
        
    

Measured memory_bytes: 63236
#include <stdio.h>
#include <vector>
#include <iostream>
#include <string>
#include <algorithm> 
#include <iterator> 
#include <map> 

using namespace std;

string po;
string p="CODEFESTIVAL2016";
int co=0;

int main(){
	cin>>po;
	for(int i=0;i<16;i++){
		if(po[i]!=p[i])co++;
	}
	printf("%d\n",co);
	
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int D;//日数
	uint32_t c[26+1];// 満足度低下係数
	uint32_t s[365+1][26+1]; //d日目にコンテストタイプiを実施したときの満足度増加幅
	
	// 入力
	cin >> D;
	for(int i = 1; i <= 26; ++i) {
		cin >> c[i];
	}
	for(int i = 1; i <= D; ++i) {
		for(int j = 1; j <= 26; ++j) {
			cin >> s[i][j];
		}
	}
	
	//計算
	int last[26+1];
	
	
	for(int d = 1; d <= D; ++d) {
		
		int32_t max_v = 0; //最大満足度
		int type = 1;
		for(int tmpType = 1; tmpType <=26; ++tmpType) {
			int32_t v = 0; //満足度
			
			//増加
			v += s[d][ tmpType ];
			//減少
			for(int i = 1; i <= 26; ++i) {
				v -= c[i] * (d - last[i]);
			}
			v += c[tmpType] * (d - last[tmpType]);
			if ( v > max_v) {
				max_v = v;
				type = tmpType;
			}
		}
		
		last[type] = d;
		cout << type << endl;
	}
	

	return 0;
}



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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))
#define ALL(x) (x).begin(),(x).end()
#define Ceil(x, n) (((((x))+((n)-1))/n))
#define CeilN(x, n) (((((x))+((n)-1))/n)*n)

#define INF 2e7
#define INF_LL 1LL<<60
#define ll long long
#define MAX_V   100005
struct edge {
    int to;
    int cost;
};

typedef pair<int, int> P;  // first: 最短距離, second: 頂点番号

int V, d[MAX_V];
vector<edge> G[MAX_V]; // 隣接リスト表現

void dijkstra(int s) {
    fill(d, d + V, INF);
    d[s] = 0;  // 始点sへの最短距離は0

    priority_queue<P, vector<P>, greater<P>> que;  // 距離が小さい順に取り出せるようgreater<P>を指定
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        int v = p.second;  // 更新した頂点の中で距離が最小の頂点v
        if (d[v] < p.first) {
            continue;
        }
        for (auto e : G[v]) {  // 頂点vから出る辺eを走査
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}
int main(){
    int h, w;
    cin >> h >> w;
    V = h * w;
    vector<string> s(h);
    REP(i, h) cin >> s[i];

    REP(i, h) REP(j, w){
        if(i < h-1) {
            /* 下 */
            if(s[i][j] == '#' && s[i+1][j] == '#') {
                G[w*i + j].push_back({w*(i+1) + j, 0});
            } else if(s[i][j] == '.' && s[i+1][j] == '.') {
                G[w*i + j].push_back({w*(i+1) + j, 0});
            } else if(s[i][j] == '.' && s[i+1][j] == '#') {
                G[w*i + j].push_back({w*(i+1) + j, 1});
            } else {
                G[w*i + j].push_back({w*(i+1) + j, 0});
            }
        }
        if(j < w-1) {
            if(s[i][j] == '#' && s[i][j+1] == '#') {
                G[w*i + j].push_back({w*i + j + 1, 0});
            } else if(s[i][j] == '.' && s[i][j+1] == '.') {
                G[w*i + j].push_back({w*i + j + 1, 0});
            } else if(s[i][j] == '.' && s[i][j+1] == '#') {
                G[w*i + j].push_back({w*i + j + 1, 1});
            } else {
                G[w*i + j].push_back({w*i + j + 1, 0});
            }
        }
    }

    dijkstra(0);
    ll ans = 0;
    if(s[0][0] == '#') ans++;
    ans += d[h*w-1];

    cout << ans << endl;

    return 0;
}


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

int main(){
  long long l,r,mod=2019,ans=123456;
  cin >> l >> r;
  if(r/mod>l/mod){
    cout << "0\n";
    return 0;
  }
  for(ll i=l;i<r;i++){
    for(ll j=i+1;j<=r;j++){
      ans=min(ans, (i*j)%mod);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <complex>
#include <cmath>
#include <ccomplex>
using namespace std;

void solve() {
	string x, y;
	cin >> x >> y;
	int xlen = x.length();
	int ylen = y.length();
	int dp[1010][1010];
	dp[0][0] = 0;

	for (int i = 0; i <= xlen; i++) {
		for (int j = 0; j <= ylen; j++) {
			if (i == 0 || j == 0) {
				dp[i + 1][j + 1] = 0;
			}
			else if (x[i - 1] == y[j - 1]) {
				dp[i + 1][j + 1] = dp[i][j] + 1;
			}
			else {
				dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
			}
		}
	}
	cout << dp[xlen + 1][ylen + 1] << endl;
}
int main() {
	int q;
	cin >> q;
	for (int i = 0; i < q; i++)solve();
}

Measured memory_bytes: 6960
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<n; ++i)
#define all(x) begin(perm),end(perm)
#define showall(obj) for(auto x:obj)cout<<x<<endl;
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
typedef vector<int> vint;
typedef vector<ll> vll;
const int inf = 100100100;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
    int a,b,c,d,e,f,x,y,n,m;
    string s,t;

    cin>>s;
    if(s[0]==s[1]&&s[1]==s[2])cout<<"No"<<endl;
    else cout<<"Yes"<<endl;

    return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 	int a,b,k;
  	cin >> a >> b >> k;
  	for(int i = a; i<=b;i++) {
      	if(i <= a+k-1 || i >= b - k+1)
          	cout << i << endl;
     	 
      
    }
}

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

#define N 2000000
#define INF 2147483647

int A[N],n=0;

int parent(int i){
  return i/2;
}

int left(int i){
  return 2*i;
}

int right(int i){
  return 2*i+1;
}

void increase(int i,int k){
  int temp;
  
  if(k<A[i]) return;

  A[i]=k;

  while(i>1 && A[i/2]<A[i]){
    temp=A[i];
    A[i]=A[i/2];
    A[i/2]=temp;

    i=i/2;
  }

  return;
}

void insert(int k){
  n++;
  A[n]=-INF;
  increase(n,k);
}

void maxHeapify(int i){
  int l,r,largest,temp;

  l=2*i;
  r=2*i+1;

  if(l<=n && A[l]>A[i]) largest=l;
  else largest=i;

  if(r<=n && A[r]>A[largest]) largest=r;

  if(largest!=i){
    temp=A[i];
    A[i]=A[largest];
    A[largest]=temp;

    maxHeapify(largest);
  }

  return;
}

int extract(){
  int max;
  
  if(n<1) return -INF;

  max=A[1];

  A[1]=A[n--];


  maxHeapify(1);

  return max;
}


int main(){
  int i,j=0,k;
  char com[20];

  while(1){
    scanf("%s",com);
    
    if(com[0]=='e' && com[1]=='n') break;
    
    if(com[0]=='i'){
      scanf("%d",&k);

      insert(k);
    }

    else{
      printf("%d\n",extract());
    }

  }

  return 0;
}
  
  
  



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

int main() {
  string str;
  cin >> str;
  
  if(str.at(2) == str.at(3) && str.at(4) == str.at(5)) {
    cout << "Yes" << endl;
  }
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import Control.Monad
main=do
 n<-readLn
 f<-replicateM n (map read.words<$>getLine)
 p<-replicateM n (map read.words<$>getLine)
 print(g (n-1) f p (-10000000000) 1023)
  where g _ _ _ m 0 = m
        g n f p m i = g n f p (max m (h n p (j f (k i)))) (i-1)
        k i = [quot(mod i (2^x))(2^(x-1))|x<-[1..10]]
        j f i =[sum((map (\l->(fst l)*(snd l)))(zip x i))|x<-f]
        h n p f = sum[(p!!x)!!(f!!x)|x<-[0..n]]

Measured memory_bytes: 1660
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0;i<N;i++)

long long  INF=1000000000000000000;
long long mod=1000000007;
using namespace std;

int main(){
long long N,K;
cin>>N>>K;
vector<long long >A(N);

vector<long long >F(N);
rep(i,N)cin>>A[i];
sort(A.begin(),A.end());

rep(i,N)cin>>F[i];

sort(F.begin(), F.end());
reverse(F.begin(),F.end());

long long right=1e12,left=-1;

while(left+1<right){
    long long mid=(right+left)/2;
    long long sum=0;
    rep(i,N){
        if(A[i]*F[i]>mid){
            sum+=A[i]-(int)((double)mid/F[i]);
        }
        if(sum>K)break;
    }

    if(sum>K){
        left=mid;
    }
    else{
        right=mid;
    }
}
cout<<right<<endl;
return 0;
}
/*
3 5
4 2 1
2 3 1

2

3 8
4 2 1
2 3 1

0

11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2

12
*/

Measured memory_bytes: 3328
#include<iostream>
#include<iomanip>
#include<limits>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define big ((ll)(1e9)+7)

int main(){
  ll n,k;
  cin >> n >> k;
  int ans = 0;
  while(n != 0)
  {
    ans++;
    n /= k;
  }
  cout << ans << endl;
}


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

S = [list(map(lambda x: x == "#", list(input()))) for _ in range(H)]

dx = [0, 1, 0, -1]
dy = [-1, 0, 1, 0]

ans = True
for j in range(H):
    for i in range(W):
        if S[j][i]:
            ok = False
            for x, y in zip(dx, dy):
                if i+x < 0 or i+x >= W or j+y < 0 or j+y >= H:
                    continue
                ok = ok or S[j+y][i+x]
            if not ok:
                ans = False
                break
        if not ans:
            break
    if not ans:
        break
print("Yes" if ans else "No")


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;

int main () {
    int h1, m1, h2, m2, k;

    cin >> h1 >> m1 >> h2 >> m2 >> k;

    if (h2 < h1 || (h2 == h1 && m2 < m1)) {
        h2 += 24;
    }

    int hour_dif = h2 - h1;
    int min_dif = m2 - m1;

    if (min_dif < 0) min_dif += 60, hour_dif --;

    int tot = hour_dif * 60 + min_dif;

    cout << tot - k;
}
/*
    Good Luck
        -Lucina
*/


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repp(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define repm(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define INF (1ll<<60)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
const lint MOD =1000000007;
const lint MAX = 10000000;
using Graph =vector<vector<lint>>;
typedef pair<lint,lint> P;

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

void COMinit() // 二項係数を求める時は前処理としてCOMinit()をする
{
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (lint i = 2; i < MAX; i++)
    {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
long long COM(lint n, lint k)
{
    if (n < k)
        return 0;
    if (n < 0 || k < 0)
        return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

lint primary(lint num)
{
    if (num < 2) return 0;
    else if (num == 2) return 1;
    else if (num % 2 == 0) return 0; // 偶数はあらかじめ除く

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // 素数ではない
            return 0;
        }
    }

    // 素数である
    return 1;
}
   long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
   struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
    void init(lint N){
         for(int i = 0; i < N; i++) par[i] = i;
    }
};
  int main(){
     lint N,M;
     cin>>N>>M;
     UnionFind tree(N);
     P p[M];
     rep(i,M){
        lint a,b;
        cin>>a>>b;
        --a;--b;
        p[i]=make_pair(a,b);
     }
     lint ans=0;
     rep(i,M){
         lint s,v;
         tie(s,v)=p[i];
         rep(j,M){
                if(j==i)continue;
                else tree.unite(p[j].first,p[j].second);
         }
         if(!tree.same(s,v))ans++;
            tree.init(N);
     }
     cout<<ans;
   
    }
     
  


Measured memory_bytes: 256
int main(void)
{
  long x;
  scanf("%ld",&x);
  long long i, j;
  for (i = -120; i < 121; i++)
  {
    for (long long j = -120;j < 121;j++)
    {
      if(i * i * i * i * i - j * j * j * j * j == x)
      {
        printf("%lld %lld",i,j);
        return 0;
      }
    }
  }
}


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

#define MAX 1000

void initialize();
int isEmpty();
int isFull();
void push(int x);
int pop();

int top;
int S[100];

int main(){
  int x,n1,n2;
  char s[100];

  initialize();

  while( scanf("%s", s) != EOF ){

    if ( s[0] == '+' ){
      n1 = pop();
      n2 = pop();
      push(n1 + n2);
    } else if ( s[0] == '-' ){
      n1 = pop();
      n2 = pop();
      push(n2 - n1);
    } else if ( s[0] == '*' ){
      n1 = pop();
      n2 = pop();
      push(n1 * n2);
    } else {
      x = atoi(s);
      push(x);
    }
  }
  printf("%d\n",pop());
  return 0;
}

void initialize(){
  top = 0;
}

int isEmpty(){
  return top == 0;
}

int isFull(){
  return top >= MAX - 1;
}

void  push(int x){
  if (isFull()) fprintf(stderr,"overflow\n");
  top++;
  S[top] = x;
}

int pop(){
  if (isEmpty()) fprintf(stderr,"underflow\n");
  top--;
  return S[top+1];
}

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

int main()
{
  int N;
  int p[30]={0};
  cin >>N;
  int ans=0;
  for(int i=0;i<N;i++) cin>>p[i];
  int box;
  for(int i=0;i<N-2;i++){
    box=(p[i]-p[i+1])*(p[i+1]-p[i+2]);
    if(box>0) ans+=1;
    else if(box==0){
      if(p[i]==p[i+1]&&p[i]==p[i+2]) box=0;
      else if(p[i+1]>=p[i]&&p[i+1]>=p[i+2]) ans+=1;
    }
  }
  cout <<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ALL(v) std::begin(v),std::end(v)
using lint=long long;
using ld=long double;
template<class T>using numr=std::numeric_limits<T>;
lint power(lint x,lint y){
    lint ans=1;
    while(y--)ans*=x;
    return ans;
}
int main(){
    std::cin.tie(nullptr);std::ios_base::sync_with_stdio(false);
    std::cout.setf(std::ios_base::fixed);std::cout.precision(15);
    lint n=3;
    lint k;std::cin>>k;
    std::vector<lint>dp(k+1);
    for(lint i=1;i<=k;i++){
        dp.at(i)=power(lint{k/i},n);
    }
    lint ans=0;
    for(lint i=k;i>=1;i--){
        for(lint j=2*i;j<=k;j+=i){
            dp.at(i)-=dp.at(j);
        }
        ans+=dp.at(i)*i;
    }
    std::cout<<ans<<'\n';
}


Measured memory_bytes: 3660
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int cou=0;
        String w = sc.next(),arr;

        while(true){
            arr=sc.next();
            //System.out.print(arr+" ");
            if(arr.equals("END_OF_TEXT")){
                break;
            }
            if(arr.equalsIgnoreCase(w)){
                cou++;
            }
        }
        System.out.println(cou);
        sc.close();
    }
}



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

using namespace std;

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

    for(int i = 0; i < s.size(); i++)
    {
        if (s[i] != s[k - 1])
        {
            s[i] = '*';
        }
    }

    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define Would
#define you
#define please

const int cm = 1 << 17;
char cn[cm], * ci = cn + cm, ct;
inline char getcha() {
	if (ci - cn == cm) { fread(cn, 1, cm, stdin); ci = cn; }
	return *ci++;
}
inline int getint() {
	int A = 0;
	if (ci - cn + 16 > cm) while ((ct = getcha()) >= '0') A = A * 10 + ct - '0';
	else while ((ct = *ci++) >= '0') A = A * 10 + ct - '0';
	return A;
}

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


	int N = getint(), X = getint();

	int kotae = abs(getint() - X);
	rep(i, N - 1) {
		kotae = __gcd(kotae, abs(getint() - X));
	}
	printf("%d", kotae);


	Would you please return 0;
}

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

#define ntest 0

using namespace std;
string s;
void solve() {
    cin >> s;
    s += (s.back() == 's'?"es":"s");
    cout << s;
}
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    if(ntest){
        int t;
        cin >> t;
        while(t--) solve();
    } else {
        solve();
    }

}




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

int main() {
  int a,b;
  cin >> a >> b;
  if(a < 0 && b < 0) {
     if((b-a+1)%2) {
        cout << "Negative" << endl;
     } else {
        cout << "Positive" << endl;
     }
  }
  else if (a> 0 && b > 0) {
     cout << "Positive" << endl;
  }
  else {
    cout << "Zero" <<endl;
  }
  return 0;
}

Measured memory_bytes: 256
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()  # ignore trailing spaces

s = ns()
n = len(s)

ret = [0] * n
for i in range(n-1):
    if s[i:i+2] == "RL":
        for j in range(i, -1, -1):
            if s[j] == "R":
                ret[i + (i-j) % 2] += 1
            else:
                break
        for j in range(i+1, n):
            if s[j] == "L":
                ret[i + (j-i) % 2] += 1
            else:
                break

print(" ".join(map(str, ret)))


Measured memory_bytes: 10484
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	ll h, a, x;
	cin >> h >> a;
	ll sum = 0;
	for (int i = 0; i < a; ++i)
		{
			cin >> x;
			sum += x;
		}
	if (sum >= h) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.nextLine());
		int k = Integer.parseInt(sc.nextLine());

		int ans = 1;
		for (int i = 0; i < n; i++) {
			if (ans < k) {
				ans *= 2;
			} else {
				ans += k;
			}
		}

		System.out.println(ans);

		sc.close();
	}
}

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

using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define MIN(a, b) ((a) > (b) ? (b) : (a))
#define MAX(a, b) ((a) < (b) ? (b) : (a))

const long long INF = 1LL << 60;
typedef unsigned long long ll;
const long long MOD = 1000000000 + 7;

int main()
{
    int n, m;
    cin >> n >> m;
    cout << (1900 * m + 100 * (n - m)) * (1 << m) << endl;
    return 0;
}

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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

const int nmax=100010;
const int qmax=100010;

vi trees[nmax];
int p[nmax];
int last[nmax];

void add_edge(int a,int b){
	trees[a].pb(b);
	trees[b].pb(a);
}

int uf[nmax];
int find(int i){
	if(uf[i]==i)
		return i;
	return uf[i]=find(uf[i]);
}

void unite(int p,int c){
	uf[c]=p;
	return;
}


void dfs(int v,int p){
	if(last[v]==-1)
		unite(p,v);
	for(auto &e:trees[v]){
		if(e!=p)
			dfs(e,v);
	}
}


char type[qmax];
int num[qmax];

int main(void){
	int n,q;
	while(cin >> n >> q){
		if(n==0)
			break;
		for(int i=1;i<=n;++i){
			trees[i].clear();
			uf[i]=i;
			last[i]=-1;
		}
		for(int i=2;i<=n;++i){
			cin >> p[i];
			add_edge(p[i],i);
		}
		last[1]=-2;
		rep(i,q){
			cin >> type[i] >> num[i];
			if(type[i]=='M'&&last[num[i]]==-1)
				last[num[i]]=i;
		}
		dfs(1,-1);
		ll ans=0;
		for(int i=q-1;i>=0;--i){
			if(type[i]=='Q')
				ans+=find(num[i]);
			else{
				if(last[num[i]]==i)
					unite(p[num[i]],num[i]);
			}
		}
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 13648
import java.util.*;
 
public class Main{
	public static void main(String[] args){
    	Scanner scan = new Scanner(System.in);
      	int K = scan.nextInt();
      	int S = scan.nextInt();
      	int counter = 0;
      	for(int X = 0 ; X <= K; X++){
        	for(int Y = 0; Y <= K; Y++){
            	int Z = S - X - Y;
              	if(Z >= 0 && Z <= K){
                	counter++;
                }
            }	
        }
      	System.out.print(counter);
    }
}

Measured memory_bytes: 22996
n, k = map(int, input().split())
a = list(map(int, input().split()))

s = []
ord = [-1] * (n+1)

v = 1
while ord[v] == -1:
    ord[v] = len(s)
    s.append(v)
    v = a[v-1]

c = len(s) - ord[v]
l = ord[v]

ans = 0
if k < l:
    ans = s[k]
else:
    k -= l
    k %= c
    ans = s[l+k]
print(ans)





Measured memory_bytes: 32376