akhauriyash/Code-Regression huggingface dataset:
# -*- coding: utf-8 -*-
# Sorting Three Numbers
#	Write a program which reads three integers, and prints them in ascending order.

# Input
#	Three integers separated by a single space are given in a line.

# Output
#	 Print the given integers in ascending order in a line. Put a single space between two integers.

# Constraints
#	 1 ≤ the three integers ≤ 10000
# Sample Input 1
#	 3 8 1
# Sample Output 1
#	 1 3 8

l = []
a, b, c = (int(x) for x in input().split())
l.append(a)
l.append(b)
l.append(c)

for i in range(2):
    for j in range(i+1, 3):
        if l[i] > l[j]:
            tmp = l[i]
            l[i] = l[j]
            l[j] = tmp

print(l[0], l[1], l[2])



Measured memory_bytes: 5608
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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;
}

signed main() {
  ll N;
  cin >> N;
  if (N % 2 == 0) {
    COUTF(0.5);
  } else {
    ld kazu = N - N / 2;
    COUTF(kazu / N);
  }
  return 0;
}

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

using namespace std;
using ll = long long;

map<int,int> Map;
template<class T>
void fact(T n){
    for(T i = 2; i * i <= n; i++){
        while(n % i == 0){
            Map[i]++;
            n /= i;
        }
    }
    if(n == 1)return;
    Map[n]++;
}


int main()
{
    int n;
    cin >> n;
    if(n < 10) {
        cout << 0 << endl;
        return 0;
    }
    for(int i = 1; i <= n; i++) fact(i);
    int res = 0;
    vector<int> num;
    for(auto i : Map)num.push_back(i.second);
    int m = num.size();

    for(int i = 0; i < m; i++) {
        for(int j = i + 1; j < m; j++) {
            for(int k = 0; k < m; k++) {
                if(i == k || j == k)continue;
                if(num[i] >= 4 && num[j] >= 4 && num[k] >= 2)res++;
            }
        }
    }

    for(int i = 0; i < m; i++) {
        for(int j = 0; j < m; j++) {
            if(i == j)continue;
            if(num[i] >= 14 && num[j] >= 4)res++;
        }
    }

    for(int i = 0; i < m; i++) {
        for(int j = 0; j < m; j++) {
            if(i == j)continue;
            if(num[i] >= 24 && num[j] >= 2)res++;
        }
    }
    if(num.front() >= 74)res++;
    
    
    cout << res << endl;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    try {
        val sc = Scanner(System.`in`)
        val n = Integer.parseInt(sc.nextLine())
        val s = sc.nextLine().split(" ").map { Integer.parseInt(it) }
                .toIntArray()
        val q = Integer.parseInt(sc.nextLine())
        val t = sc.nextLine().split(" ").map { Integer.parseInt(it) }
                .toIntArray()
        if (n > 10000 || q > 500 || s.size < 0 || s.size > 1_000_000_000 || t.size > 1_000_000_000) {
            throw Exception("Illegal input.")
        }
        var c = 0
        val checked = mutableListOf<Int>()
        for (tt in t) {
            if (checked.contains(tt)) continue
            for (ss in s) {
                if (ss == tt) {
                    c++
                    checked.add(tt)
                    break
                }
            }
        }
        println(c)
    } catch (e: Exception) {
        println(e)
    }
}


Measured memory_bytes: 36508
X = int(input())
if X>=500:
    hap_yen = int(X / 500)
    to_hap_yen = hap_yen * 1000
    remain_X = X - (hap_yen * 500)
    remain_hap_yen = int(remain_X / 5)
    remain_hap_yen1=remain_hap_yen*5
    total_hap_yen = to_hap_yen + remain_hap_yen1
    print(int(total_hap_yen))
else:
    hap_yen=int(X/5)
    total_hap_yen=hap_yen*5
    print(total_hap_yen)

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

//upper_bound, lower_boundを用いた
//のになぜか通らない・・・

int main(){
	int n;
	long long a;
	if(scanf("%d", &n)==EOF){return 0;}
	
	long long top[n];
	long long center[n];
	long long down[n];
	
	for(int i = 0; i<n; i++){if(scanf("%lld", &a)==EOF){return 0;} top[i] = a;}
	for(int i = 0; i<n; i++){if(scanf("%lld", &a)==EOF){return 0;} center[i] = a;}
	for(int i = 0; i<n; i++){if(scanf("%lld", &a)==EOF){return 0;} down[i] = a;}
	
	
	// top, downをソート
	sort(top, top+n);
	sort(down, down+n);
	//for(int i = 0; i<n; i++){cout << top[i] << ", "<<endl;}
	//for(int i = 0; i<n; i++){cout << down[i] << ", "<<endl;}
	
	long long sum = 0;
	//int ok1, ng1, ok2, ng2, mid;
	int ok1, ok2;

	for(int i = 0; i< n; i++){
		//center[i]より小さいtopの数を探す
		ok1 = lower_bound(top, top+n, center[i]) - top;
		ok2 = upper_bound(down, down+n, center[i]) - down;
		
		//cout << "top[ok1-1]" <<  top[ok1-1] << ", center:"<< center[i] <<", top[ok1]:"<< top[ok1] << endl;
		//cout << "down[ok2-1]:" << down[ok2-1] <<", center:"<< center[i] <<", down[ok2]:" << down[ok2] << endl;
		sum += (long long)ok1 * (long long)(n - ok2);
	}
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 6108
#include <bits/stdc++.h>
 
using namespace std;
 
#define lli long long int
#define REP(i,s,l) for(lli i=s;i<l;i++)
#define DEBUG 0
#define INF (1LL<<50)
 
 
signed main(){
 
 	lli k;
 	cin>>k;

 	if(k%2==0){
 		cout<<k*k/4<<endl;
 	}
 	else{
 		cout<<(k/2)*(k/2+1)<<endl;
 	}

	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <functional>
#include <iostream>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdio.h>
#include <string>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0; i != n; ++i)
#define REPR(i, n) for(int i = n - 1; i != -1; --i)
#define FOR(i, a, b) for(int i = a; i != b; ++i)
#define RBF(i, n) for(auto &i : n)
#define ABS(n) (n < 0 ? -n : n)
#define MIN(a, b) (a < b ? a : b)
#define MAX(a, b) (a > b ? a : b)
#define IN(n) (cin >> n)
#define OUT(n) (cout << n << "\n")
#define INF 1e9
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false); //cinの高速化
  
  int N;
  IN(N);
  long double ans=0;
  
  REP(i,N){
    long double X;
    string S;
    cin >> X >> S;
    if(S == "BTC") ans += 380000.0 * X;
    else ans += X;
  }
  OUT(ans);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
typedef long long ll;
using namespace std;
int main(){
  ll n,m;
  cin>>n>>m;
  priority_queue<double> pq;
  rep(i,n){
    double k;
    cin>>k;
    pq.push(k);
  }
  rep(i,m){
    double l=pq.top();
    pq.pop();
    pq.push(l/2);
  }
  ll k=0;
  while(pq.size()){
    int l=pq.top();
    k+=l;
    pq.pop();
  }
  cout<<k<<endl;
}

Measured memory_bytes: 1400
from collections import defaultdict, deque
import sys
import heapq
import bisect
import itertools
import queue
import copy
import time
sys.setrecursionlimit(10**8)
INF = float('inf')
mod = 10**9+7
eps = 10**-7

def inp(): return int(sys.stdin.readline())

def inpl(): return list(map(int, sys.stdin.readline().split()))

def inpl_str(): return list(sys.stdin.readline().split())

n, m = inpl()
A = [input() for i in range(n)]
B = [input() for i in range(m)]
for i in range(n-m+1):
    for j in range(n-m+1):
        A1 = [a[j:j+m] for a in A[i:i+m]]
        if A1 == B:
            print('Yes')
            exit()
print('No')

Measured memory_bytes: 4336
class Queue:
  def __init__(self,c):
    self.values = [None]*(c+1)
    self.s = 0
    self.t = 0

  def push(self,x):
    if self._next(self.s) == self.t:
      raise Exception("Overflow")
    self.values[self.s] = x
    self.s = self._next(self.s)

  def pop(self):
    if self.s == self.t:
      raise Exception("Underflow")
    ret = self.values[self.t]
    self.t = self._next(self.t)
    return ret

  def size(self):
    if self.s >= self.t:
      return self.s-self.t
    else:
      return len(self.values) - (self.t-self.s)


  def _next(self,p):
    p += 1
    if p >= len(self.values):
      p = 0
    return p


def solve(G):
  d = {}
  n = len(G)
  for u in G:
    d[u] = -1
  d[1] = 0
  queue = Queue(n+1)
  queue.push(1)
  while queue.size() > 0:
    u = queue.pop()
    for v in G[u]:
      if d[v] == -1:
        d[v] = d[u] + 1
        queue.push(v)
  return d







n = int(input())
G = {}
for i in range(n):
  entry = list(map(int, input().split(' ')))
  u = entry[0]
  k = entry[1]
  G[u] = set()
  for v in entry[2:]:
    G[u].add(v)


d = solve(G)
for u in G:
  print(u,d[u])

Measured memory_bytes: 7896
#include<bits/stdc++.h>
using namespace std;
 
using ll = long long;
const int INF = 1e9+7;
 
void solve()
{
	ll n;cin >> n;
	if(n<=26)
	{
		cout << char('a'+(n-1))  << '\n';
		return;
	}
	string s="";
	while(n>0)
	{
		n--;
		s += char('a'+(n%26));
		//cout << n%26 << '\n';
		n/=26;
	}
	reverse(s.begin(),s.end());
	cout << s << '\n';
 
}
 
int main()
{
	int t=1;
	while(t--) solve();
}	

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

int main(){
	int gs=0,gt=0,i,j,f=0;
	char s[51],t[51],ans[51];
	scanf("%s%s",s,t);
	while(s[gs]!=0)gs++;
	while(t[gt]!=0)gt++;
	if(gs<gt){
		puts("UNRESTORABLE");
		return 0;
	}
	for(i=0;i<gs;i++){
		for(j=0;j<gt;j++){
			if(s[i+j]!=t[j]&&s[i+j]!='?')break;
		}
		if(j==gt){
			char tmp[51];
			/*for(j=0;j<gs;j++){
				if(j>=i&&j<i+gt)tmp[j]=t[j-i];
				else if(s[j]=='?')tmp[j]='a';
				else tmp[j]=s[j];
			}*/
			strcpy(tmp,s);
			for(j=0;j<gt;j++)tmp[i+j]=t[j];
			for(j=0;j<gs;j++){
				if(tmp[j]=='?')tmp[j]='a';
			}
			if(f==0){
				strcpy(ans,tmp);
				f=1;
			}else if(strcmp(ans,tmp)>0){
				strcpy(ans,tmp);
			}
		}
	}
	if(f==0)puts("UNRESTORABLE");
	else printf("%s\n",ans);
	return 0;
}

Measured memory_bytes: 128
#include<iostream>

using namespace std;
int w, h;
int c[50][50];
int dx[]={0, 0, 1, 1, 1, -1, -1, -1};
int dy[]={1, -1, 0, 1, -1, 0, 1, -1};
int used[50][50];

void rec(int i, int j){
   used[i][j]=1;
   for(int k=0; k<8; k++){
      int ni=i+dy[k];
      int nj=j+dx[k];
      if(!(0<=ni&&ni<h&&0<=nj&&nj<w)) continue;
      if(c[ni][nj]&&!used[ni][nj]) rec(ni, nj);
   }
}

int main(){

   while(1){
      cin>> w>> h;
      if(!(w||h)) break;
      for(int i=0; i<h; i++){
         for(int j=0; j<w; j++){
            cin>> c[i][j];
         }
      }

      fill((int*)used, (int*)used+50*50, 0);
      int cnt=0;
      for(int i=0; i<h; i++){
         for(int j=0; j<w; j++){
            if(c[i][j]&&!used[i][j]){
               cnt++;
               rec(i, j);
            }
         }
      }

      cout<< cnt<< endl;
   }

   return 0;
}

Measured memory_bytes: 3076
/**
*    author:  boutarou
*    created: 28.09.2020 18:06:19
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    rep(i, n) cout <<"ACL";
    cout << endl;
    return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<int,P> PP;
const ll MOD=1000000007;
const ll MAX_N=500010;
const ll INF=9999999999;
ll dp[1001][1001];
int dx[]={-1,0,0,1};
int dy[]={0,1,-1,0};

int main(){
    int h,w;
    cin>>h>>w;
    int sh,sw,gh,gw;
    cin>>sh>>sw>>gh>>gw;
    sh--; sw--; gh--; gw--;
    vector<string> G(h);
    for(int i=0;i<h;i++) cin>>G[i];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            dp[i][j]=INF;
        }
    }
    dp[sh][sw]=0;
    priority_queue<PP,vector<PP>,greater<PP> > q;
    q.push(PP(0,P(sh,sw)));
    while(!q.empty()){
        PP pp=q.top(); q.pop();
        int cost=pp.first;
        int i=pp.second.first;
        int j=pp.second.second;
        if(cost>dp[i][j]) continue;
        for(int d=0;d<4;d++){
            int ni=i+dy[d];
            int nj=j+dx[d];
            if(ni>=0 && ni<h && nj>=0 && nj<w && G[ni][nj]=='.' && dp[ni][nj]>dp[i][j]){
                q.push(PP(cost,P(ni,nj)));
                dp[ni][nj]=dp[i][j];
            }
        }
        for(int y=-2;y<3;y++){
            for(int x=-2;x<3;x++){
                int ni=i+y;
                int nj=j+x;
                if(ni>=0 && ni<h && nj>=0 && nj<w && G[ni][nj]=='.' && dp[ni][nj]>dp[i][j]+1){
                    q.push(PP(cost+1,P(ni,nj)));
                    dp[ni][nj]=dp[i][j]+1;
                }
            }
        }
    }
    if(dp[gh][gw]==INF) dp[gh][gw]=-1;
    cout<<dp[gh][gw]<<endl;

}

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

int main(void){
    int n;
    cin >> n;
    vector<int> s(n);
    rep(i, n) cin >> s[i];
    int q;
    cin >> q;
    vector<int> t(q);
    rep(i, q) cin >> t[i];
    int cnt = 0;
    rep(i, q){
        bool flg = false;
        rep(j, n){
            if(t[i] == s[j]){
                flg = true;
                break;
            }
        }
        if(flg) ++cnt;
    }
    cout << cnt << endl;
    return 0;
}


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


signed main()
{
	#ifdef LOCAL
	    freopen("H_input.txt", "r", stdin);
	    //freopen("B_output.txt", "w", stdout);
	#endif
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
   	int h, w, a, b;
   	cin >> h >> w >> a >> b;
   	for (int i=0; i < 2*b; i += 2){
   		for (int j=0; j < a; ++j) cout << '1';
   		for (int j=0; j < w-a; ++j) cout << '0';
   		cout << "\n";
		for (int j=0; j < a; ++j) cout << '0';
   		for (int j=0; j < w-a; ++j) cout << '1';
   		cout << "\n";
   	}
   	for (int i=0; i < h-2*b;++i){
   		for (int j=0; j < a; ++j) cout << '1';
   		for (int j=0; j < w-a; ++j) cout << '0';
   		cout << "\n";
   	}
    return 0;
}

Measured memory_bytes: 1280
n, m, c = map(int,input().split())
b = list(map(int,input().split()))
ans = 0
for i in range(n):
    a = list(map(int,input().split()))
    num = 0
    for j in range(m ):
        num += a[j] * b[j]
        
    if num + c > 0:
        ans += 1
        
print(ans)

Measured memory_bytes: 9196
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define debug(x) cout<<#x<<"->"<<x<<endl
#define sz(data) sizeof(data)/sizeof(data[0])

int cnt;

void bubbleSort(int a[],int n){

    for(int i=0;i<n-1;i++){
        for(int j=n-1;j>=i+1;j--){
            if(a[j]<a[j-1]){
                int temp=a[j];
                a[j]=a[j-1];
                a[j-1]=temp;
                cnt++;
            }
        }
    }

}


int main(){
   //freopen("input.txt" ,"r", stdin);

    int n; cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];

    bubbleSort(a,n);
    for(int i=0;i<n;i++){
            if(i==n-1) cout<<a[i]<<endl;
    else
            cout<<a[i]<<' ';
    }
    cout<<cnt;
    cout<<endl;



}



Measured memory_bytes: 3108
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.LongStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			long x = scanner.nextLong();
			long[] array = LongStream.range(0, 200).map(i -> i * i * i * i * i).toArray();
			for (int i = 0; i < 200; i++) {
				int a;
				if ((a = Arrays.binarySearch(array, x + array[i])) >= 0) {
					System.out.println(a + " " + i);
					break;
				} else if ((a = Arrays.binarySearch(array, x - array[i])) >= 0) {
					System.out.println(a + " -" + i);
					break;
				}
			}
		}
	}
}


Measured memory_bytes: 38836
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define rep(i,n) for(ll i=0;i<(n);i++)
int main(){
  ll n,m,ans=0;cin>>n>>m;
  priority_queue<ll> p;
  rep(i,n){
    ll a;
    cin>>a;
    p.push(a);
  }
  rep(i,m){
    ll b=p.top();
    p.pop();
    p.push(b/2);
  }
  rep(i,n){
    ans+=p.top();
    p.pop();
  }
  cout<<ans<<endl;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int t = 0;
  for(int i = 0;i < N;i++){
    int x;
    cin >> x;
    if((x-0) <= (K - x)){
      t += (2 * x);
    }else{
      t += (K - x) * 2;
    }
  }
  cout << t << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <fstream>
#include <stdlib.h>
#include <ctime>
typedef long long ll;

using namespace std;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << setprecision(100);
 //   freopen("input.txt","r",stdin);
    int n;
    cin>>n;
    int max1=0, max2=0;
    int j1;
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
     //   cout<<x;
        if(x>max1){
            max2=max1;
            max1=x;
            j1=i;
        }
        else if(x>max2){
            max2=x;
        }
    }
    for(int i=0;i<n;i++){
        if(i != j1)cout<<max1<<'\n';
        else cout<<max2<<'\n';
    }
    return 0;
}


Measured memory_bytes: 1664
def func():
    N = int(input())
    H = list(map(int, input().split()))

    prev = H[0]
    count = 0
    mx = 0
    mxIdx = 0
    startIdx = 0
    for i in range(N-1):
        now = H[i+1]
        if prev >= now:
            count += 1
            if i == N - 2:
                if mx < count:
                    mx = count
                    mxIdx = i

        else:
            if mx < count:
                mx = count
                mxIdx = startIdx
            count = 0
            startIdx = i+1

        prev = now

    print(mx)


if __name__ == '__main__':
    func()


Measured memory_bytes: 14228
let () = Scanf.scanf "%d" (fun n ->
      let number_of_divisor n = 
      let rec number_of_divisor' m number =
      match m with
      | 0   -> number
      | m'  -> 
      (let rec is_m'_divisor n' = 
      begin match n' with
      |  0 -> number_of_divisor' (m-1) number
      | n' when m' * n' = n -> number_of_divisor' (m-1) (number + 1)
      | _ -> is_m'_divisor (n' - 1)
      end
      in is_m'_divisor n)
      in number_of_divisor' n 0
      in
      let rec number_of_eight_divisor_to_n n output =
      if n = 0
      then output 
      else if n mod 2 = 0 
      then number_of_eight_divisor_to_n (n - 1) output
      else if number_of_divisor n = 8 
      then number_of_eight_divisor_to_n (n - 1) (output + 1)
      else number_of_eight_divisor_to_n (n - 1) output
      in
 	  Printf.printf "%d" (number_of_eight_divisor_to_n n 0))

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

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define ALL(a) (a).begin(),(a).end()

template<typename U, typename T>
void chmin(U &x, T y) { x = min(x, y); }

template<typename U, typename T>
void chmax(U &x, T y) { x = max(x, y); }

typedef long long int lli;
typedef long double ld;
typedef pair<int,int> P;

const int INF = INT_MAX/3;
const double EPS = 1e-14;
const int dx[4] = {0, 1, 0, -1}; // {-1,  0,  1, -1, 1, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0}; // {-1, -1, -1,  0, 0,  1, 1, 1};

lli N;

int main() {
  cout << fixed << setprecision(10);
  lli b = 1, i = 0;
  cin >> N;
  while (b < N) {
    i++;
    b *= 3;
  }
  cout << i << endl;
  return 0;
}

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

int main() {
    int N, X;
    cin >> N >> X;
    vector<int> L(N);
    for (int i = 0; i < N; i++)
        cin >> L[i];

    int res = 1;
    int now = 0;
    for (int i = 0; i < N; i++) {
        now += L[i];
        if (now > X) break;
        res++;
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
from collections import Counter


def solve(string):
    n, *a = map(int, string.split())
    a = sorted([_a - i - 1 for i, _a in enumerate(a)])
    median = a[len(a) // 2]
    return str(sum([abs(_a - median) for _a in a]))


if __name__ == '__main__':
    print(solve("\n".join([input(), input()])))


Measured memory_bytes: 106612
#include<cstdio>
#include<iostream>
#include<algorithm>
#define int long long
using namespace std;
int w,h,sx,sy,gx,gy,n,c,d,x,y,sc;
int fld[101][101];
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
void dfs(int fx,int fy){
    if(fld[fy][fx]!=sc||fx<1||fy<1||fx>w||fy>h)return;
    fld[fy][fx]=0;
    for(int i=0;i<4;i++){
        dfs(fx+dx[i],fy+dy[i]);
    }
}
signed main(){
    for(;;){
        cin>>w>>h;
        if(w==0&&h==0)break;
        cin>>sx>>sy>>gx>>gy>>n;
        fill(fld[0],fld[0]+101*101,-1);
        for(int i=0;i<n;i++){
            cin>>c>>d>>x>>y;
            if(d==0){
                for(int j=0;j<2;j++){
                    for(int k=0;k<4;k++){
                        fld[y+j][x+k]=c;
                    }
                }
            }
            if(d==1){
                for(int j=0;j<4;j++){
                    for(int k=0;k<2;k++){
                        fld[y+j][x+k]=c;
                    }
                }
            }
        }
        sc=fld[sy][sx];
        dfs(sx,sy);
        if(fld[gy][gx]==0)cout<<"OK"<<endl;
        else cout<<"NG"<<endl;
    }
    return 0;
}

Measured memory_bytes: 1236
#include <stdio.h>
#include <string.h>
 
int main(int argc, char *argv[])
{
	int i, j, k, M, N;
	char mm[64][64], nn[64][64];
	scanf("%d %d\n", &N, &M);
	for ( i = 0; i < N; i++ ){
		fgets(nn[i], 64, stdin);
	}
	for ( i = 0; i < M; i++ ){
		fgets(mm[i], 64, stdin);
	}
						 
	for ( i = 0; i + M <= N; i++ ){
		for ( j = 0; j + M <= N; j++ ){
			for ( k = 0; k < M; k++ ){
				if ( memcmp(nn[k+i]+j, mm[k], M) != 0 ){
					break;
				}
			}
			if ( k == M ){
				printf("Yes\n");
				return 0;
			}
		}
	}
	printf("No\n");
	return 0;
}


Measured memory_bytes: 128
# -*- coding: utf-8 -*-
"""
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0189

"""
import sys
from sys import stdin
input = stdin.readline


def warshallFloyd(V, dp):
    for k in range(V):
        for i in range(V):
            for j in range(V):
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j])


def main(args):
    while True:
        n_max = 9+1
        n = int(input())
        if n == 0:
            break
        dp = [[float('inf')] * n_max for _ in range(n_max)]
        for i in range(n_max):
            dp[i][i] = 0

        max_town = 0
        for _ in range(n):
            a, b, c = map(int, input().split())
            dp[a][b] = c
            dp[b][a] = c
            max_town = max(max_town, a, b)

        warshallFloyd(max_town + 1, dp)


        min_dist = float('inf')
        town_live = -1
        for i, d in enumerate(dp[:max_town+1]):
            sum_dist = 0
            for ele in d[:max_town+1]:
                sum_dist += ele
            if sum_dist < min_dist:
                min_dist = sum_dist
                town_live = i

        print('{} {}'.format(town_live, min_dist))



if __name__ == '__main__':
    main(sys.argv[1:])
    

Measured memory_bytes: 7756
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = float('inf')
for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)
ans = min(ans, min(a) + min(b))
print(ans)


Measured memory_bytes: 24840
#pragma GCC optimize("O3")
#include<bits/stdc++.h>
#define lld long long int
#define ld long double
#define mpi 3.14159265358979323846
#define mod 1000000007
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	lld a,b,x;
	cin >> a >> b >> x;
	lld y = a%x;
	if(y==0)
	{
		//do nothing;
	}
	else
	{
		a = a-y;
		a+=x;
	}
	y = b%x;
	b = b-y;
	cout << ((b-a)/x)+1 << "\n";
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
// memo  fixed  setprecision(20);
using vvll = vector<vector<ll>>;
ll mod =1000000007;
/*"itob" int to "N"base */           template<typename TypeInt> string itob(const TypeInt v, int base){static const char table[] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ";string ret;static numeric_limits<TypeInt> t;TypeInt n = v;if (t.is_signed) {if (v < 0) n *= -1;}while (n >= base) {ret += table[n%base];n /= base;}ret += table[n];if (t.is_signed) {if (v < 0 && base == 10) ret += '-';}reverse(ret.begin(), ret.end());return ret;}
/*"chmin" a = MAX*/                  template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
/*"chmax" a = MIN*/                  template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
/*"ctoi"  char to int*/              int ctoi(char c) {return c-'0';}
/*"gcd"   MAX*/                      ll gcd(ll a,ll b){if(b==0)return a; return gcd(b,a%b);}
/*"lcm"   MIN*/                      ll lcm(ll a,ll b){ll g = gcd(a,b);return a/g*b;}
/*"primecheck"If prime,return true.*/bool primecheck(ll n){if(n < 2) return false;else{for(int i = 2; i * i <= n; i++){if(n % i == 0) return false;}return true;}}
string  reverserange(string s,ll a,ll b){reverse(s.begin()+a-1,s.begin()+b); return s;}
int main(){
    int n;
    cin >>n;
    vector<int>a(n);
    for(int i=0;i<n;i++){
        cin >> a.at(i);
    }
    ll ans = 10e16;
    for(int i=-1000;i<=1000;i++){
        ll che = 0;
        for(int j=0;j<n;j++){
            che+=pow((i-a.at(j)),2);
        }
        ans = min(ans,che);
    }
    cout << ans << endl;
}



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

using namespace std;

int main(){
    int N;
    string a;
    cin >> N >> a;
    auto isOdd = [&](){
        int res = 0;
        for(int i=0;i<N;i++){
            if(a[i] == '2' && ((N-1)&i) == i) res = 1-res;
        }
        return res;
    };
    if(a.find('2') != string::npos){
        cout << (isOdd() ? 1 : 0) << endl;
    } else {
        for(auto& c : a) if(c == '3') c = '2';
        cout << (isOdd() ? 2 : 0) << endl;
    }
}

Measured memory_bytes: 1412
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    int a,b,c,d,e,k;
    cin >> a >> b >> c >> d >> e >> k;

    if (e-a>k){
        cout << ":(";
    } else if (e-b>k){
        cout << ":(";
    }else if (d-a>k){
        cout << ":(";
    }else if (e-c>k){
        cout << ":(";
    }else if (c-a>k){
        cout << ":(";
    }else if (e-d>k){
        cout << ":(";
    }else if (b-a>k){
        cout << ":(";
    }else{
        cout << "Yay!";
    };
    cout << endl;
    return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
using ll = long long;
using namespace std;

int main(){
	int a, b;
	cin >> a >> b;
	cout << (a+b) % 24 << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class Program
{
    static void Main(string[] args)
    {
        //var n = int.Parse(Console.ReadLine());
        var ab = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        var ans = ab[0] - ab[1] * 2;
        if(ans < 0)
        {
            ans = 0;
        }
        Console.WriteLine(ans);
    }
}

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

constexpr int MAX_N = 50;
int p[MAX_N];

int main() {
  int N;
  cin >> N;
  for (int i{}; i < N; ++i)
    cin >> p[i];

  int i1{N};
  for (int i{0}; i < N - 1; ++i) {
    if (p[i] > p[i + 1]) {
      i1 = i;
      break;
    }
  }
  int i2{N};
  for (int i{N - 1}; i > 0; --i) {
    if (p[i - 1] > p[i]) {
      i2 = i;
      break;
    }
  }
  if (i1 != N && i2 != N) {
    swap(p[i1], p[i2]);
  }

  for (int i{0}; i < N - 1; ++i) {
    if (p[i] > p[i + 1]) {
      cout << "NO" << endl;
      return 0;
    }
  }

  cout << "YES" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
typedef struct{char c;int n;} card;
card B[36],S[36];
int bubble(card A[36],int N)
{
	int i,j,c=0,flag=1;
	card stock;
	while(flag)
	{
		flag=0;
		for(i=N-1;i>0;i--)
		{
			if(A[i].n<A[i-1].n)
			{
				stock=A[i];
				A[i]=A[i-1];
				A[i-1]=stock;
				flag=1;
				c++;
			}		
		}
	}
	return c;
}
int selection(card A[36],int N)
{
	int i,j,d,minj,c=0;
	card stock;
	for(i=0;i<N;i++)
	{
		minj=i;
		for(d=0,j=i;j<N;j++)
		{
			if(A[j].n<A[minj].n){minj=j;d=1;}
		}
		stock=A[i];
		A[i]=A[minj];
		A[minj]=stock;
		if(d)c++;
	}
	return c;
}
int main(void)
{
	int n,i,j;
	scanf("%d",&n);
	for(i=0;i<n;i++){scanf(" %c%d",&B[i].c,&B[i].n);}
	memcpy(S,B,sizeof(B));
	bubble(B,n);
	selection(S,n);
	for(i=0;i<n;i++)
	{
		printf("%c%d",B[i].c,B[i].n);
		if(i<n-1){printf(" ");}
		else{printf("\n");}
	}
	printf("Stable\n");
	for(i=0;i<n;i++)
	{
		printf("%c%d",S[i].c,S[i].n);
		if(i<n-1){printf(" ");}
		else{printf("\n");}
	}
	if(!memcmp(B,S,sizeof(B))){printf("Stable\n");}
	else{printf("Not stable\n");}

	return 0;
}

Measured memory_bytes: 624
N = int(input())
A = [int(input()) for i in range(N)]
A.sort()

arr = []
for i in range(N//2):
    arr.append(A[i])
    arr.append(A[-1-i])
if N%2:
    arr.append(A[N//2])

tmp = 0
for a,b in zip(arr,arr[1:]):
    tmp += abs(a-b)

ans = tmp
for i in range(N):
    arr.append(arr[i])
    gain = abs(arr[-1] - arr[-2]) - abs(arr[i] - arr[i+1])
    tmp += gain
    ans = max(tmp, ans)



arr = []
for i in range(N//2):
    arr.append(A[-1-i])
    arr.append(A[i])
if N%2:
    arr.append(A[N//2])

tmp = 0
for a,b in zip(arr,arr[1:]):
    tmp += abs(a-b)

for i in range(N):
    arr.append(arr[i])
    gain = abs(arr[-1] - arr[-2]) - abs(arr[i] - arr[i+1])
    tmp += gain
    ans = max(tmp, ans)

print(ans)

Measured memory_bytes: 8924
#include <iostream>
#include <algorithm>

using namespace std;

int n, m;
const int MAX_N = 50000, MAX_M = 20, INF = 1000000;
int c[MAX_M + 2];
int dp[MAX_M + 2][MAX_N + 2];


void solve() {
	for (int j = 0; j <= n; j++) {
		dp[0][j] = INF;
	}

	for (int i = 0; i <= m; i++) {
		for (int j = 1; j <= n; j++) {
			if (j < c[i]) {
				dp[i + 1][j] = dp[i][j];
			}
			else {
				dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - c[i]] + 1);
			}
		}
	}
	cout << dp[m][n] << endl;
}

int main()
{
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		cin >> c[i];
	}
	solve();
	return 0;
}

Measured memory_bytes: 7400
n=int(input())
l=list(map(int,input().split()))
s=[]
for i in range(n): 
    for j in range(i+1,n): 
        for k in range(j+1,n): 
            if (l[i]+l[j]>l[k] and l[i]+l[k]>l[j] and l[k]+l[j]>l[i] and l[i]!=l[j] and l[i]!=l[k] and l[j]!=l[k]): 
                s.append((i,j,k))
print(len(s))

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

int main() {
    char c1, c2, c3; cin >> c1 >> c2 >> c3;
    if (c1 != c2 && c2 !=c3 && c3 != c1) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}


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

using namespace std;

const int MAXN = 200005;

int n, m, cnt[MAXN][2], del[MAXN];
vector<int> G[MAXN];
char ch[MAXN];
queue<int> Q;

void erase(int x) {
  int v = (ch[x] == 'A' ? 0 : 1);
  for(int i = 0; i < G[x].size(); i++) {
    int nx = G[x][i];
    --cnt[nx][v];
  }
  del[x] = 1;
  Q.push(x);
}

int main() {
  scanf("%d %d", &n, &m);
  scanf("%s", ch + 1);
  for(int i = 1; i <= m; i++) {
    int x, y;
    scanf("%d %d", &x, &y);
    G[x].push_back(y);
    G[y].push_back(x);
  }
  for(int i = 1; i <= n; i++) {
    for(int j: G[i]) {
      if(ch[j] == 'A') ++cnt[i][0];
      if(ch[j] == 'B') ++cnt[i][1];
    }
  }
  for(int i = 1; i <= n; i++) {
    if(!cnt[i][0] || !cnt[i][1]) {
      erase(i);
    }
  }
  while(!Q.empty()) {
    int cur = Q.front(); Q.pop();
    for(int i = 0; i < G[cur].size(); i++) {
      int nx = G[cur][i];
      if(!del[nx]) {
        if(!cnt[nx][0] || !cnt[nx][1]) {
          erase(nx);
        }
      }
    }
  }
  bool ok = false;
  for(int i = 1; i <= n; i++) {
    if(!del[i]) {
      ok = true;
    }
  }
  puts(ok ? "Yes" : "No");
  return 0;
}


Measured memory_bytes: 13184
#include<bits/stdc++.h>
using namespace std;
bool hw(string s){
	int n=s.size();
	for(int i=0;i<n/2;i++)
	    if(s[i]!=s[n-i-1])
	        return false;
	return true;
}
int main(){
	string s,s1,s2;
	cin>>s;
	s1=s.substr(0,(s.size()-1)/2);
	s2=s.substr(s.size()/2+1,(s.size()-1)/2);
	if(hw(s)&&hw(s1)&&hw(s2))
	    cout<<"Yes";
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) {

    // IO Templates
    val br = BufferedReader(InputStreamReader(System.`in`))
    val out = PrintWriter(System.out)

    val (n, m) = br.readLine()!!.split(' ').map { it.toInt() }

    val g = Array(n) { mutableListOf<Int>() }

    for (i in 1..m) {
        var (a, b) = br.readLine()!!.split(' ').map { it.toInt() }
        a--
        b--
        g[a].add(b)
        g[b].add(a)
    }

    var clusterSize = 0
    val seen = BooleanArray(n) { false }

    for (i in 0 until n) {
        if (seen[i]) continue

        clusterSize++
        val que: Queue<Int> = LinkedList()
        que.add(i)
        seen[i] = true

        while (que.isNotEmpty()) {
            val now = que.poll()
            for (next in g[now]) {
                if (seen[next]) continue
                seen[next] = true
                que.add(next)
            }
        }
    }

    out.println(clusterSize - 1)

    out.flush()
}

Measured memory_bytes: 75244
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
using Graph = vector<vector<pair<int, int> > >;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int N; cin >> N;
	vector<int> d(N, 0);
	for (int i = 0; i < N; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());

	int l = d[N / 2-1];
	int r = d[N / 2];


	cout << r - l << endl;





	return 0;
}


Measured memory_bytes: 768
#include <iostream>
#include <vector>

using namespace std;

void min(int x){
    if(x == 0) cout << 1 << " ";
    else cout << x << " ";
    return;
}

void max(int x,int y){
    while(y>0){
        x++; y--;
    }
    cout << x << endl;
    return;
}

int main(){
    int N;
    cin >> N;
    
    int rate[N];
    vector<int> cl(10);
    for(int i=0; i<N ; i++) {
        cin >> rate[i];
        if(rate[i]<400) cl[0]++;
        if(400 <= rate[i] && rate[i] < 800) cl[1]++;
        if(800 <= rate[i] && rate[i] < 1200) cl[2]++;
        if(1200 <= rate[i] && rate[i] < 1600) cl[3]++;
        if(1600 <= rate[i] && rate[i] < 2000) cl[4]++;
        if(2000 <= rate[i] && rate[i] < 2400) cl[5]++;
        if(2400 <= rate[i] && rate[i] < 2800) cl[6]++;
        if(2800 <= rate[i] && rate[i] < 3200) cl[7]++;
        if(3200 <= rate[i]) cl[8]++;
    }
    
    int res = 0;
    
    for(int i=0 ; i<8 ; i++){
        if(cl[i] > 0) res++;
    }
    
    min(res);
    max(res,cl[8]);
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


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

    ll ans = 0;
    if (p == 2 || p == 5) {
        rep(i, n) {
            if ((s[n-i-1]-'0')%p == 0) ans += n-i;
        }
    }
    else {
        vll num(p, 0);
        ll digit = 1;
        ll cur = 0;
        num[cur]++;
        rep(i, n) {
            cur = (cur+(s[n-i-1]-'0')*digit)%p;
            digit *= 10;
            digit %= p;
            num[cur]++;
        }
        rep(i, p) ans += num[i]*(num[i]-1)/2;
    }

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

Measured memory_bytes: 640
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    String S = sc.next();
    if (S.length() >= 4
        && S.substring(0, 4).equals("YAKI")) {
      System.out.println("Yes");
    } else {
      System.out.println("No");
    }
  }
}

Measured memory_bytes: 21844
N, M = map(int, input().split())
X = list(map(int, input().split()))

X = sorted(X)
diff_dict = {}
for i in range(M-1):
    diff = X[i+1] - X[i]
    diff_dict[i] = diff
sorted_diff = sorted(diff_dict.items(), key=lambda x: x[1])[::-1][:N-1]
keys = {x[0] for x in sorted_diff}
tmp = []
count = 0
for i, x in enumerate(X):
    tmp.append(x)
    if i in keys:
        if len(tmp) > 1:
            count += (max(tmp) - min(tmp))
        tmp.clear()
if len(tmp) > 1:
    count += (max(tmp) - min(tmp))
print(count)


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

int n;
int A[101],B[101];

int card(int pre,int* man){
	for(int i = 0; i < n; i++){
		if(man[i] > pre){
			int tmp = man[i];
			man[i] = -1;
			man[n]--;
			return tmp;
		}
	}
	return -1;
}
bool finish(int* man){
	return man[n] == 0;
}

int main(){
	while(cin >> n,n != 0){
		for(int i = 0; i < n; i++){
			cin >> A[i];
		}
		sort(A,A+n);
		int a_itr = 0;
		int b_itr = 0;
		for(int i = 1; i <= 2*n; i++){
			if(A[a_itr] == i){
				a_itr++;
			}
			else{
				B[b_itr++] = i;
			}
		}
		A[n] = B[n] = n;
		
		int pre = 0;
		while(1){
			int taro = card(pre,A);
			if(taro == -1){
				pre = 0;
			}
			else{
				pre = taro;
				if(finish(A)){
					break;
				}
			}
			int hanako = card(pre,B);
			if(hanako == -1){
				pre = 0;
			}
			else{
				pre = hanako;
				if(finish(B)){
					break;
				}
			}
		}
		cout << B[n] << endl << A[n] << endl;
	}
	return 0;
}



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

int solve(int n, vector<int>h){
	vector<int>cost(n, 0);
    cost[0] = 0;
    cost[1] = abs(h[0] - h[1]);
    for (int i=2; i<n; i++){
        cost[i] = min(
            (cost[i-1] + abs(h[i] - h[i-1])),
            (cost[i-2] + abs(h[i] - h[i-2])));
    }
    return cost[n-1];
}

int main(){
    int n; cin>>n;
	vector<int>h(n); rep(i,n) cin >> h[i];
    cout << solve(n,h);
}

Measured memory_bytes: 4576
#include<bits/stdc++.h>
using namespace std;
#define  ft  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define  ll  long long
#define  pi  pair<int,int>
#define  pb  push_back
#define  F   first
#define  S   second
const int N=2e5+3;
string s,p;
//vector<int>v;
//map<int,int>mp;

int main()
{
    ft
    int t,i,j,n,m,l=INT_MAX,r;
    cin>>s;
    n=s.size();
    for(i=0; i<n; i++)
    {
        r=0;
        for(j=i; j<i+3 && i+3<=n; j++)
        {
            r=(r*10)+(s[j]-48);
        }
        l=min(l,abs(753-r));
    }
    cout<<l<<"\n";
    return 0;
}



Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define itn int
#define mod 1000000007
#define INFi 2147483647
#define INFl 9223372036854775807LL
#define fi first
#define se second
#define be begin()
#define en end()
int abs(int a,int b){
    return max(a,b)-min(a,b);
}
int gcd(int a,int b){//最大公約数
int c=a%b;
while(true){
if(c==0) break;
a=b;
b=c;
c=a%b;
}
return b;
}
bool IsPrime(int num){
if (num < 2) return false;
else if (num == 2) return true;
else if (num % 2 == 0) return false;
double sqrtNum = sqrt(num);
for(int i=3;i<=sqrtNum;i+=2){
if(num%i==0){
return false;
}
}
}
int lcm(int a,int b){//最小公倍数
return (a*b)/gcd(a,b);
}	
signed main(){
// __builtin_ctz(N); Nを２で何回割り切れるかを返す
//(n+1)*n/2; １からNまでの総和を求める式
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    cout<<lcm(a,b)<<"\n";
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){
  string S, T;
  int ans=0;
  cin >> S;
  cin >> T;
  for(int i=0; i<S.size(); i++){
    if(S[i] != T[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3920
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, m, n) for(int i=(m); i<(n); ++i)
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define mp make_pair
#define pb push_back
#define Cout(x) cout << (x) << endl
#define dump(x) cerr << #x << " = " << (x) << endl;
typedef long long LL;
typedef vector<int> VI;
typedef vector<long long> VL;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
const int inf = (int)1e9;
const long long mod = (long long)1e9 + 7;
const double pi = acos(-1.0);

string re(string s, char c,char c1) {
	for (auto& C : s) {
		if (C == c)C = c1;
	}
	return s;
}

int main() {
	int n; cin >> n;
	VS s(n); rep(i, n)cin >> s[i];
	string t; cin >> t;

	VS s1(n + 1);
	rep(i, n + 1) {
		s1[i] = re(i == n ? t : s[i], '?', 'a');
	}
	sort(all(s1));
	int ans1 = -1;
	rep(i, n + 1) {
		if (s1[i] == t)ans1 = i + 1;
	}

	VS s2(n + 1);
	rep(i, n + 1) {
		s2[i] = re(i == n ? t : s[i], '?', 'z');
	}
	sort(all(s2));
	int ans2 = -1;
	rep(i, n + 1) {
		if (s2[i] == t) { ans2 = i + 1; break; }
	}

	FOR(i, ans2, ans1 + 1) {
		cout << i << (i == ans1 ? "\n" : " ");
	}
}

Measured memory_bytes: 2048
#include <bits/stdc++.h>
const int N=1000005;
using std::sort;
int n,a[N],b[N];
long long k;
bool cmp(int x,int y){
	return x>y;
}
bool check(long long x){
	long long sum=0;
	for (int i=1;i<=n;i++){
		long long t=x/b[i];
		sum=sum+std::max(0ll,a[i]-t);
	} 
	return sum<=k;
}
int main(){
	scanf("%d%lld",&n,&k);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	for (int i=1;i<=n;i++) scanf("%d",&b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+n+1,cmp);
	long long l=0,r=1ll*a[n]*b[1],ans=0;
	while (l<=r){
		long long mid=(l+r)>>1;
		if(check(mid)){
			r=mid-1,ans=mid;
		}else l=mid+1;
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 5248
N = int(input())
A = list(map(int, input().split()))

print(" ".join(list(map(str, A))))

for i in range(1, len(A)):
  v = A[i]
  j = i - 1
  while j >= 0 and A[j] > v:
    A[j+1] = A[j]
    j -= 1
  A[j+1] = v

  print(" ".join(list(map(str, A))))


Measured memory_bytes: 5604
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    vector<vector<T>>(h,vector<T>(w))
#define VVI(T,h,w,i) vector<vector<T>>(h,vector<T>(w,i))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
    ll x = in(), a = in();
    cout << (x < a ? 0 : 10) << endl;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
#define INF 2147483647
#define INF_LL 9223372036854775807
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

int main() {
	int N;
	cin >> N;
	if (N % 2 == 0)cout << N << endl;
	else cout << N * 2 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const ll P = 1e9+7;
const ll N = 1e6+7;

vector<ll> p(N);
void spf(){
	iota(p.begin(),p.end(),0);

	for(ll i=2;i*i<=N;++i){
		if(p[i] == i){
			for(ll j=i*i;j<N;j+=i){
				if(p[j] == j) p[j] = i;
			}
		}
	}
}

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

	ll t=1;
	// cin>>t;

	spf();

	while(t--){
		ll n;
		cin>>n;

		ll ans = 0;
		for(ll c=1;c<n;++c){
			ll num = n - c;
			unordered_map<ll,ll>m;
			while(num != 1){
				m[p[num]]++;
				num /= p[num];
			}

			ll cnt = 1;
			for(auto &x : m){
				cnt *= (x.second+1)	;
			}	

			ans += cnt;

		}

		cout<<ans<<"\n";

	}

	return 0;
}	


Measured memory_bytes: 11000
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rrep(i,n) for (int i=(int)(n)-1; i>=0; --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) rep(i, x.size()) cerr << x[i] << (i == x.size() - 1 ? "\n" : " ")
#define int long long
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = ((1LL << 30) + (1LL << 29));
const int MOD = 1000000007;

//=============================
int N,M,K;
string S,T;

//=============================
void input()
{
    cin>>S;

}
//=============================
void func(){}
//=============================
void solve()
{
    int ans = 0;
    rep(i,S.size()){
        if (S[i] == '+'){
            ans ++;
        }
        else ans--;
    }
    cout<<ans<<endl;
   
}
//=============================
signed main()
{
    input();
    solve();
    return 0;
}

Measured memory_bytes: 256