akhauriyash/Code-Regression huggingface dataset:
# ABC083c
import sys
import math
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

x, y = map(int, input().split())

#y - x * 2 ** n > 0
#x * 2 ** n < y
# 2**n<y/x

# print(math.floor(math.log2(y/x))+1)
ans = 0
while (x <= y):
    ans += 1
    x *= 2
print(ans)

Measured memory_bytes: 3060
from collections import defaultdict
from itertools import combinations
from functools import reduce
n = int(input())
r = int(n ** (1 / 2)) + 2
dic = defaultdict(int)
temp = n
for i in range(2, r):
  if temp < i:
    break
  while temp % i == 0:
    temp //= i
    dic[i] += 1
if temp != 1:
  dic[temp] += 1

ans = n
keys = list(dic.keys())
length = len(keys)
for i in range(1, length + 1):
  for t in combinations(keys, i):
    ans += n // reduce(lambda x, y:x * y, t) * (-1) ** i
print(ans)


Measured memory_bytes: 6320
#coding:utf-8
import math
import string
import time
import fractions



n = int(raw_input())
t = map(int, raw_input().split())
m = int(raw_input())
p = []
for i in range(m):
	p.append(map(int, raw_input().split()))

ret = 0
su = sum(t)
for i in p:
	print su - (t[i[0] - 1] - i[1])



Measured memory_bytes: 4720
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>

#define pb push_back
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define ll long long
 
 
 
using namespace std;

void file(){
	#ifndef ONLINE_JUDGE
    	freopen("tst.txt", "r", stdin);
	#endif	
}
int tc;
const int N=1e6+5,M=2e6+5,MOD=1e9+7,OO=1e9;

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

	ll n,a,b;

	cin>>n>>a>>b;

	if((b-a)%2==0){
		cout<<(b-a)/2<<endl;
	}
	else{
		ll ans = min(b-1,n-a);

		ll c = a;
		ll d = b;

		ll steps = a-1;

		d-=steps;

		if((d-1)%2 == 0){
			ans = min(ans,steps+(d-1)/2);
		}
		else{
			ans=min(ans,steps+1+(d-2)/2);
		}

		c = a;
		d = b;

		steps = n-b;

		c+=steps;

		if((n-c)%2==0){
			ans = min(ans,steps+(n-c)/2);
		}
		else{
			ans = min(ans,steps+1+(n-c-1)/2);
		}

		cout<<ans<<endl;
	}
	
	
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back
#define pii pair<int, int>
#define pll pair<ll, ll>

using namespace std;

typedef long long ll;

/* --- INFの値が適切か確認する --- */
// const int INF = 1 << 30;
// const ll INF = 1LL << 60;
// const int MOD = 1000000007;

int main() {
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i, n) cin >> p[i];
  rep(i, n) REP(j, i, n) {
    vector<int> pp = p;
    swap(pp[i], pp[j]);
    bool flg = true;
    rep(k, n - 1) if (pp[k] > pp[k + 1]) flg = false;

    if (flg) {
      cout << "YES" << endl;
      return 0;
    }
  }
  cout << "NO" << endl;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define Max 10000000

typedef struct{
  char name[100];
  int time;
}Data;

int n, head = 0, tail = 0;
Data Q[Max];

void enqueue(Data);
Data dequeue(void);

int main(){
  int i, q, t = 0, count = 0;
  Data data;

  scanf("%d %d",&n, &q);
  for(i = 1; i <= n; i++){
    scanf("%s",Q[i].name);
    scanf("%d",&Q[i].time);
    enqueue(Q[i]);
  }
  while(count < n){
    data = dequeue();
    if(data.time <= q){
      t += data.time;
      count++;
      printf("%s %d\n",data.name, t);
    }
    else{
      t += q;
      data.time -= q;
      enqueue(data);
    }
  }
  
  return 0;
}

void enqueue(Data x){
  Q[tail] = x;
  if(tail + 1 == n) tail = 0;
  else tail++;
}

Data dequeue(void){
  Data x;
  x = Q[head];
  if(head + 1 == n) head = 0;
  else head++;
  return x;
}

Measured memory_bytes: 6736
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> mp;
ll inf =  1e9;


int main(){
    int a,b,c;
    string s;
    cin>>a;
    cin>>s;
    if(a<3200){
	cout<<"red"<<endl;
    }else{
	cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
int main() {
	int N, K, A[200000];
  long long sum = 0;
	scanf("%d%d",&N,&K);
	for (int i = 0; i < N; i++) scanf("%d",&A[i]);
  sort(A,A+N);
  for (int i = 0; i < N - K; i++) sum += A[i];
  printf("%lld\n",sum);
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
void DFSUtil(int v, bool visited[],vector<int> adj[]) 
{ 
    visited[v] = true; 
    for (auto i = 0; i<adj[v].size(); ++i) 
        if (!visited[adj[v][i]]) 
            DFSUtil(adj[v][i], visited,adj); 
}
int conComp(vector<int> adj[],int V) 
{ 
    bool* visited = new bool[V+1]; 
    int count = 0; 
    for (int v = 1; v <=V; v++) 
        visited[v] = false; 
  
    for (int v = 1; v <=V; v++) { 
        if (visited[v] == false) { 
            DFSUtil(v, visited,adj); 
            count += 1; 
        } 
    } 
  
    return count; 
}  
int main()
{
	int n,m;
	cin>>n>>m;
	vector<int>adj[n+1];
	for(int i=0;i<m;i++)
	{
		int a,b;
		cin>>a>>b;
		adj[a].push_back(b);
		adj[b].push_back(a);
	}
//	for(int i=0;i<n;i++)
//	   for(int j=0;j<adj[i].size();j++)
//	       cout<<adj[i][j]<<" ";
	cout<<conComp(adj,n)-1<<"\n";
}


Measured memory_bytes: 10088
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int n;
    cin >> n;
    vector<long long> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }

    const long long INF = 1LL << 50;
    vector<long long> dp(n + 1, -INF);
    dp[0] = 0;
    vector<pair<int, pair<int,int>>> pre(n + 1, make_pair(-1, make_pair(-1, -1))); 
    for (int i = 0; i < n; ++i) {
        long long sum = 0;
        long long& ans = dp[i + 1];
        for (int j = i; j >= 0; j -= 2) {
            sum += A[j];
            if (ans < sum) {
                ans = sum;
                pre[i + 1] = make_pair(0, make_pair(j + 1, i + 1));
            }
            if (j - 2 >= 0 && ans < sum + dp[j - 2 + 1]) {
                ans = sum + dp[j - 2 + 1];
                pre[i + 1] = make_pair(pre[j - 2 + 1].second.second, make_pair(j + 1, i + 1));
            }
        }
        if (i - 2 >= 0 && dp[i - 2 + 1] > ans) {
            ans = dp[i - 2 + 1];
            pre[i + 1] = pre[i - 2 + 1];
        }
    }
    long long res = *max_element(dp.begin() + 1, dp.end());
    cout << res << '\n';
    vector<pair<int,int>> segs;
    {
        int cur = 0;
        for (int i = 1; i <= n; ++i) {
            if (dp[i] == res) {
                cur = i;
                break;
            }
        }
        // cout << cur << endl;
        while (cur > 0) {
            int l = pre[cur].second.first;
            int r = pre[cur].second.second;
            segs.emplace_back(l, r);
            cur = pre[cur].first;
        }
    }
    reverse(segs.begin(), segs.end());
    int revs = 0;

    vector<int> ops;
    if (!segs.empty()) {
        for (auto& s : segs) {
            // cout << s.first << " - " << s.second << '\n';
        }
        for (int i = 1; i < segs[0].first; ++i) {
            ops.push_back(1);
        }
        for (int i = n, j = 0; i > segs.back().second; --i, ++j) {
            ops.push_back(n - segs[0].first + 1 - j);
        }
        for (int j = 0; j < segs.size(); ++j) {
            int l = j == 0 ? 1 : 3;
            int r = segs[j].second - segs[j].first + l;
            for (int x = 2; x < r; x += 2) {
                ops.push_back(2);
            }

            if (j < segs.size()) {
                int ll = 2;
                int rr = segs[j + 1].first - 1 - segs[j].second - 1 + ll;
                for (int x = 3; x < rr; x += 2) {
                    ops.push_back(3);
                }
            }

        }
    } else {
        assert(0);
    }
    
    cout << ops.size() << '\n';
    for (auto x : ops) {
        cout << x << '\n';
    }

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8

n = int(input().rstrip())

a_list = list(map(int, input().rstrip().split(" ")))
b_list = list(map(int, input().rstrip().split(" ")))
c_list = list(map(int, input().rstrip().split(" ")))

prev = -2
ans = 0
for i in range(n):
    dish = a_list[i] - 1
    ans += b_list[dish]
    if dish - prev == 1:
        ans += c_list[prev]
    prev = dish

print(ans)

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

using namespace std;

char s[20][20];
int h, w;

class pos{
public:
	int h;
  	int w;
  	int step;
  	pos(int i, int j, int s);
private:
};

pos::pos(int i, int j, int s){
  h = i;
  w = j;
  step = s;
}


int cost(pos src){
	
  int c[20][20];

  for(int i=0; i<h; i++){
  	for(int j=0; j<w; j++){
    	c[i][j] = 100000;
    }
  }
  
  c[src.h][src.w] = 0;
  

  vector<pos> index{src};
  
  int itr = 0;
  while(itr < index.size()){
    int i = index[itr].h;
    int j = index[itr].w;
    if(i != h-1){
      if(c[i+1][j] > index[itr].step + 1 && s[i+1][j] == '.'){
    	c[i+1][j] = index[itr].step + 1;
        pos tmp(i+1, j, index[itr].step+1);
        index.push_back(tmp);
      }
    }
    if(j != w-1){
      if(c[i][j+1] > index[itr].step + 1 && s[i][j+1] == '.'){
      	c[i][j+1] = index[itr].step + 1;
        pos tmp(i, j+1, index[itr].step+1);
        index.push_back(tmp);
      }
    }
    if(i != 0){
      if(c[i-1][j] > index[itr].step + 1 && s[i-1][j] == '.'){
      	c[i-1][j] = index[itr].step + 1;
        pos tmp(i-1, j, index[itr].step+1);
        index.push_back(tmp);
      }
    }
    if(j != 0){
      if(c[i][j-1] > index[itr].step + 1 && s[i][j-1] == '.'){
      	c[i][j-1] = index[itr].step + 1;
        pos tmp(i, j-1, index[itr].step+1);
        index.push_back(tmp);
      }
    }
    itr++;
  }
 	
  int max = 0;
  for(int i = 0; i < h; i++){
  	for(int j=0; j<w; j++){
    	if(c[i][j] > max && c[i][j] != 100000){
        	 max=c[i][j];
        }
    }
  }
  return max;
}

int main(){
	
  cin >> h >> w;
  
  for(int i=0; i<h; i++){
      	string tmp;
    	cin >> tmp;
	  	for(int j=0; j<w; j++){
          s[i][j] = tmp[j];
    	}
  }
  
  int max = 0;
  for(int i = 0; i < h; i++){
    for(int j= 0; j<w; j++){
      if(s[i][j] != '#'){
	  pos src(i, j, 0);
      int tmp = cost(src);
      if(tmp > max){
        max = tmp;
      }
    }}
  }
  cout << max << endl;
  
}

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

int main() {
  string str;
  cin >> str;
  int size = (int)str.size();
  int max = size - 2;
  int save = str[0];

  int distance = 0, hand=0;
  for(int i = 1; i < size; ++i){
      char ch = str[i];
      if (ch == save) {
        hand += distance - 1;
        // cout << hand << endl;
        distance = 0;
      } else if(i == (size-1)) {
        hand += distance;
      } else { 
        distance++;
      }
  }

  int w = hand % 2;
  string winner;
  winner = (w==1) ? "First" : "Second";
  cout << winner << endl;

  return 0;
}

Measured memory_bytes: 760
#include <iostream>
#include <iomanip>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <queue>
#include <algorithm>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <list>
#define debug(x) cout << #x << ": " << (x) << endl
using namespace std;

const double PI  = 3.141592653589793238463;
const int INF = 1000000007;

using ull = unsigned long long;
using ll = long long;

using Int = ull;
using Double = double;

using P = pair<Int, Int>;
using V = vector<Int>;
using M = vector<V>;

bool isValid(int n, V& as){
    sort(as.begin(), as.end());
    V bs;
    if(n % 2 == 0){
        for(int i = 1; i < n; i += 2){
            bs.push_back(i);
            bs.push_back(i);
        }
    }else{
        bs.push_back(0);
        for(int i = 2; i < n; i += 2){
            bs.push_back(i);
            bs.push_back(i);
        }
    }
    return equal(as.begin(), as.end(), bs.begin());
}

/*
  1: 0
  2: 1 1
  3: 2 0 2
  4: 3 1 1 3
*/

Int modPow(int n, int m){
    if(m == 0){
        return 1;
    }
    Int a = modPow(n, m / 2);
    Int b = a * a % INF;
    if(m % 2 == 0){
        return b;
    }else{
        return n * b % INF;
    }
}

Int solve(int n){
    return modPow(2, n / 2);
}

Int solve(int n, V& as){
    return isValid(n, as) ? solve(n) : 0;
}

int main(int argc, char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n;
    cin >> n;
    V as(n);
    for(int i = 0; i < n; i++){
        cin >> as[i];
    }

    cout << solve(n, as) << endl;

    return 0;
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  int t[n];
  int sum;
  for(int i=0; i<n; i++){
    cin >> t[i];
    sum += t[i];
  }
  int m;
  cin >> m;
  int p,x;
  int ans[m];
  for(int i=0; i<m; i++){
    cin >> p >> x;
    ans[i] =  sum-t[p-1]+x;
  }
  for(int i=0; i<m; i++){
    cout << ans[i] << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <unordered_map>
#include <queue>
#define For(i, n) for(int i = 0; i < (n); i ++)
#define Range(c) c.begin(), c.end()
#define RevRange(c) c.rbegin(), c.rend()
#define Contains(c, x) find(Range(c), x) != c.end()
#define Sort(a) sort(Range(a))
#define DeSort(a) sort(RevRange(a))
#define Vec2(T, n, m, xs, x) vector<vector<T>> xs(n, vector<T>(m, x))
#define Sum(a) accumulate(Range(a), 0)
#define Cusum(T, n, xs, sxs) vector<T> sxs(n+1); For(i, n) sxs[i+1] = sxs[i] + xs[i]
#define Cin(T, x) T x; cin >> x
#define Cins(T, n, xs) vector<T> xs(n); For(i, n) cin >> xs[i]
#define Cins2(T, n, xs, ys) vector<T> xs(n), ys(n); For(i, n) cin >> xs[i] >> ys[i]
#define Cins3(T, n, xs, ys, zs) vector<T> xs(n), ys(n), zs(n); For(i, n) cin >> xs[i] >> ys[i] >> zs[i]
#define Cinss(T, n, m, xs) Vec2(T, n, m, xs, 0); For(i, n) For(j, m) cin >> xs[i][j]
#define Cout(x) cout << (x) << "\n"
#define Couts(xs) for(const auto &e : xs) cout << e << " "; cout << "\n"

using namespace std;
using ll = long long;

int main(void){
    Cin(int, a);
    Cin(int, b);
    Cin(int, c);
    Cin(int, x);
    int ans = 0;
    For(i, a+1) For(j, b+1) For(k, c+1){
        if(x == 500*i + 100*j + 50*k) ans ++;
    }
    Cout(ans);
}


Measured memory_bytes: 256
N = gets.to_i
$pre, $in = 2.times.map{gets.split.map(&:to_i)}

$post = []

def rec(l, r)
  return if l >= r
  return if $pos == N

  root = $pre[$pos]
  $pos += 1
  m = $in.index(root)

  rec(l, m)
  rec(m + 1, r)
  $post.push(root)
end

def solve
  $pos = 0
  rec(0, $pre.size)
end

puts solve.join(' ')


Measured memory_bytes: 6876
N = int(input())
S = {}
for i in range(N):
    new_input = input()
    if new_input not in S:
        S[new_input] = 0
    S[new_input] += 1

result = []
max_num = max(S.values())
for item in S:
    if S[item] == max_num:
        result.append(item)

result = set(result)
result = sorted(result)
for r in result:
    print(r)

Measured memory_bytes: 43992
#ifndef COMPETITIVE_HEADER
    #pragma GCC optimize ("Ofast")
    #ifdef ONLINE_JUDGE
        #pragma GCC target ("avx512f")
    #else
        #pragma GCC target ("avx")
    #endif
    //----------------------------
    #include <bits/stdc++.h>
    using namespace std;

    typedef long long ll;
    typedef unsigned long long ull;
    #define int ll

    #define FOR(i,j,n) for (int i=(int)(j);i<(n);i++)
    #define REP(i,n) for (int i=0;i<(int)(n);i++)
    #define REPS(i,n) for (int i=1;i<=(int)(n);i++)
    #define REPN(i,n) for (int i=(int)(n)-1;i>=0;i--)
    #define REPNS(i,n) for (int i=(int)(n);i>0;i--)

    #define I(n) scanf("%lld", &(n))
    #define LL(n) scanf("%lld", &(n))
    #define pb(n) push_back((n))
    #define mp(i,j) make_pair((i),(j))
    #define eb(i,j) emplace_back((i),(j))
    #define y0 y3487465
    #define y1 y8687969
    #define j0 j1347829
    #define j1 j234892
    #define uniq(v) v.erase( unique(v.begin(), v.end()), v.end() )

    #define all(x) (x).begin(),(x).end()
    #define sz(x) ((int)(x).size())

    typedef vector<int> vi;
    typedef pair<int,int> pi;
    typedef vector<pi> vpi;
    typedef vector<vi> vvi;
    typedef vector<vpi> vvpi;
    typedef vector<vvi> vvvi;

    const int mod = 1000000007;
#endif

int h,w,k;
string s;
int x1,y1,x2,y2;




signed main(){
    cin >> h >> w >> k;
    cin >> x1 >> y1 >> x2 >> y2;
    char table[h+2][w+2];
    memset(table, '@', sizeof(table));
    REP(i,h){
        cin >> s;
        REP(j,w){
            table[i+1][j+1] = s[j];
        }
    }
    int ans[h+2][w+2];
    REP(i,h+2) REP(j,w+2) ans[i][j] = INT_MAX/2;
    ans[x1][y1] = 0;
    deque<pi> q;
    q.emplace_back(x1,y1);

    // REP(i,h+2) { REP(j,w+2) cerr << table[i][j]; cerr << endl; }
    while(!q.empty()){
        auto pos = q.front();
        q.pop_front();
        int x = pos.first;
        int y = pos.second;
        int dist = ans[x][y];
        table[x][y] = '@';
        REPS(ki, k){
            int xk = x - ki;
            int yk = y;

            if (table[xk][yk] == '@') break;
            if (ans[xk][yk] > dist + 1) {
                q.emplace_back(xk,yk);
                ans[xk][yk] = dist + 1;
            }
        }
        REPS(ki, k){
            int xk = x + ki;
            int yk = y;

            if (table[xk][yk] == '@') break;
            if (ans[xk][yk] > dist + 1) {
                q.emplace_back(xk,yk);
                ans[xk][yk] = dist + 1;
            }
        }
        REPS(ki, k){
            int xk = x;
            int yk = y - ki;

            if (table[xk][yk] == '@') break;
            if (ans[xk][yk] > dist + 1) {
                q.emplace_back(xk,yk);
                ans[xk][yk] = dist + 1;
            }
        }
        REPS(ki, k){
            int xk = x;
            int yk = y + ki;

            if (table[xk][yk] == '@') break;
            if (ans[xk][yk] > dist + 1) {
                q.emplace_back(xk,yk);
                ans[xk][yk] = dist + 1;
            }
        }
    }
    cout << (ans[x2][y2] < INT_MAX/2 ? ans[x2][y2] : -1) << endl;
}

Measured memory_bytes: 30572
#define __USE_MINGW_ANSI_STDIO 0
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
#define int ll
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a<=x&&x<b)
#define MP make_pair
#define PB push_back
#ifdef int
const ll INF = (1LL<<60);
#else
const int INF = (1LL<<30);
#endif
const double PI = 3.14159265359;
const double EPS = 1e-12;
const int MOD = 1000000007;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')';
  return out;
}

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

typedef string::const_iterator State;

string str(State&);
char letter(State&);
string s;

string cipher(State& begin) {
  // cout << "c:" << *begin << endl;
  string ret = "";
  while(begin != s.end() && *begin != ']') {
    ret += str(begin);
    // cout << ret << endl;
  }
  return ret;
}

string str(State& begin) {
  // cout << "s:" << *begin << endl;
  string ret;
  if(*begin == '[') {
    begin++;
    ret = cipher(begin);
    begin++;
    reverse(ALL(ret));
  } else {
    ret = letter(begin);
  }
  return ret;
}

char letter(State& begin) {
  // cout << "l:" << *begin << endl;
  int tmp = 0;
  while(*begin == '+' || *begin == '-') {
    if(*begin == '+') tmp++;
    else tmp--;
    begin++;
  }
  char ret = *begin;
  begin++;
  if(ret == '?') return 'A';
  while(tmp > 0) ret = ret=='Z'?'A':ret+1, tmp--;
  while(tmp < 0) ret = ret=='A'?'Z':ret-1, tmp++;
  return ret;
}

signed main(void)
{
  while(true) {
    cin >> s;
    if(s == ".") break;
    State begin = s.begin();
    cout << cipher(begin) << endl;
  }

  return 0;
}

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

using ll = long long;

#define mod 1000000007
#define REP(i, n) for (int i = 0; i < n; i++)
#define INF (1 << 29)

using namespace std;

//long C(long n, long r);
//long long gcd(long long a, long long b);
//long long lcm(long long a, long long b);

void solve()
{
    int r, g;
    cin >> r >> g;
    int ans = 2*g - r;
    cout << ans << endl;
}

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


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


int main(){

int n;
cin >> n;
int w[n];
rep(i,n)cin >> w[i];
int ans[n];



rep(i,n){
int sum1=0,sum2=0;
  rep(j,n){
    if(i<j)sum1 += w[j];
    else sum2 +=w[j];
  }
    if(sum1 < sum2)ans[i]=sum2-sum1;
    else if(sum2 < sum1)ans[i]=sum1-sum2;
    else ans[i]=0;
  
}

int minl=100000;
rep(i,n) minl = min(minl,ans[i]);

cout << minl << endl;
return 0;
}

Measured memory_bytes: 764
#include<stdio.h>
int main(){
int W,T=4280;
int d=0,x=0;
while(1){
scanf("%d",&W);if(W==-1)break;
T=T-1150;
if(W<=10){printf("%d\n",T);}
else if(W<=20){d=125*(W-10);T=T-d;printf("%d\n",T);}
else if(W<=30){d=140*(W-20);T=T-d-1250;printf("%d\n",T);}
else if(W>30){d=160*(W-30);T=T-d-1250-1400;printf("%d\n",T);}
T=4280;
}
return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define strall(v) (v).cbegin(),(v).cend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}
//const long long INF = 1LL << 60;
 int INF = 500000;
 int MAX = 1e5+10;
 ll mod = 1e9+7;

vector<bool> b_sta(1e5+10,false);

int main(){
  char c[4];
  map<char,int> m;
  rep(i,4){
    char input;
    cin >> input;
    m[input]++;
  } 
  bool flag = true;
  for(auto ma:m){
    if(ma.second != 2) flag = false;  
  }
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as BS
import Data.Maybe (fromJust)
import qualified Data.IntSet as S
import qualified Data.IntMap as M
import Data.List

fromListWithConcat []         = M.empty
fromListWithConcat ((k,v):xs) = M.insertWith (\[a] b -> a:b) k [v] $ fromListWithConcat xs

solve :: [(Int,String)] -> (Int,Int)
solve ps = let (a,w) = go S.empty ps
            in (a,w - waOnly ps)
  where
    go :: S.IntSet -> [(Int,String)] -> (Int,Int)
    go acs [] = (0,0)
    go acs ((p,s):xs)
      | p `S.notMember` acs && s == "AC" =
          let (a,w) = go (S.insert p acs) xs in (a+1,w)
      | p `S.notMember` acs && s == "WA" =
          let (a,w) = go acs xs in (a,w+1)
      | otherwise   = go acs xs
    waOnly :: [(Int,String)] -> Int
    waOnly ps = let m = fromListWithConcat ps
                 in foldl f 0 m
    f a vs
      | all (=="WA") vs = a + length vs
      | otherwise = a

main :: IO ()
main = do
    [n,m] <- map read . words <$> getLine :: IO [Int]
    ps <- map ((\[a,b] -> (read a,b)) . map BS.unpack . BS.words)
        . BS.lines <$> BS.getContents :: IO [(Int,String)]
    let (a,w) = solve ps
    putStr $ show a
    putStr " "
    print w

Measured memory_bytes: 41340
#include <iostream>
using namespace std;
int main() {
    int n =0;
    int w[101];
    int sum1 = 0;
    int sum2 = 0;
    int min = 999999999;
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> w[i];
    }
    for (int j = 0; j < n; ++j) {
        sum1 = sum2 =0;
        for (int i = 0; i <=j ; ++i) {
            sum1 += w[i];
        }
        for (int k = j+1; k < n; ++k) {
            sum2 += w[k];
        }
        int buff = abs(sum1 - sum2);
        if(buff < min){
            min = buff;
        }

    }

    cout << min;
    return 0;
}

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

int main(){
 ios_base::sync_with_stdio(false);
 cin.tie(NULL); 
 
 int n, k;
  cin>>n>>k;
  int a[n];
  for(int i=0; i<n; i++) cin>>a[i];
  
  int dp[n+1];
  dp[0] = 0;
  dp[1] = 0;
  dp[2] = abs(a[1] - a[0]);
  int ans = INT_MAX;
  for(int i=3; i<n+1; i++){
    if(i<=k){
        for(int j=1; j<i; j++)
            ans = min(ans, abs(a[i-1] - a[i-j-1]) + dp[i-j]);
    }
    else{
        for(int j=1; j<=k; j++)
            ans = min(ans, abs(a[i-1] - a[i-j-1]) + dp[i-j]);
    }
    dp[i] = ans;
    ans = INT_MAX;
        // dp[i] = min((abs(a[i-1]-a[i-2]) + dp[i-1]),(abs(a[i-1]-a[i-3]) + dp[i-2]));
  }
  cout<<dp[n]<<endl;
 
   return 0;
}

Measured memory_bytes: 4360
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <utility>
#define int long long
using namespace std;

signed main(){
	int s, m[10],sum;
	cin >> s;
	int j = 0;
	while (1){
		m[j] = s % 10;
		s = s / 10;
		j++;
		if (s == 0)break;
	}
	//sはj桁の数、m[0]は一の位
	sum = 0;
	for (int i = 0; i < pow(2, j - 1); i++){
		int tmp = m[0];
		if (j > 1){
			int jj = i;
			int mul = 1;
			for (int k = 1; k < j; k++){
				if (jj % 2 == 0)mul = mul * 10;
				else mul = 1;
				tmp += m[k] * mul;
				jj = jj / 2;
			}
		}
		sum += tmp;
	}
	cout << sum << endl;
	return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    priority_queue<int> a;
    rep(i,n){
        int k;cin>>k;
        a.push(k);
    }
    rep(i,m){
        int k=a.top();a.pop();
        k/=2;a.push(k);
    }
    ll tot=0;
    rep(i,n){
        tot+=a.top();a.pop();
    }
    cout<<tot<<endl;
    return 0;
}


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

int main(){
    int A,B,C,X;
    cin>>A>>B>>C>>X;
    X=X/50;
    //10,2,1を足してXにする
    
    int num=0;
    
    for (int a=0; a<=A; a++) {
        for (int b=0; b<=B; b++) {
            for (int c=0; c<=C; c++) {
                if (a*10+b*2+c==X) {
                    num++;
                }
            }
        }
    }
    
    cout<<num;
    
    
}


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

using namespace std;

int main(){
  int i,j,k,l,n,m;
  string s;
  cin >> n;
  if(n == 1){
    cout << "Hello World" << endl;
  }else{
    cin >> i >> j;
    cout << i+j << '\n';
  }
  return 0;
}


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

// #define int long long
#define rep(i, n) for (int i = (int)(0); i < (int)(n); ++i)
#define reps(i, n) for (int i = (int)(1); i <= (int)(n); ++i)
#define rrep(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rreps(i, n) for (int i = ((int)(n)); i > 0; i--)
#define irep(i, m, n) for (int i = (int)(m); i < (int)(n); ++i)
#define ireps(i, m, n) for (int i = (int)(m); i <= (int)(n); ++i)
#define SORT(v, n) sort(v, v + n);
#define REVERSE(v, n) reverse(v, v+n);
#define vsort(v) sort(v.begin(), v.end());
#define all(v) v.begin(), v.end()
#define mp(n, m) make_pair(n, m);
#define cout(d) cout<<d<<endl;
#define coutd(d) cout<<std::setprecision(10)<<d<<endl;
#define cinline(n) getline(cin,n);
#define replace_all(s, b, a) replace(s.begin(),s.end(), b, a);
#define PI (acos(-1))
#define FILL(v, n, x) fill(v, v + n, x);
#define sz(x) int(x.size())

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

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) %= mod;
    n >>= 1;
  }
  return res;
}

const int maxf = 10000000;
long long fact[maxf+5];

void fact_init(int n, long long mod){
  fact[0] = 1;
  for(int i=1; i<=n; i++){
    fact[i] = (fact[i-1] * i) % mod;
  }
}

long long comb(long long a, long long b, long long mod){
  if(a<b || a<0 || b<0) return 0;
  if(fact[0] == 0) fact_init(maxf, mod);
  return (fact[a] * modpow((fact[a-b]*fact[b])%mod, mod-2, mod)) % mod;
}

signed main()
{
  cin.tie( 0 ); ios::sync_with_stdio( false );
  ll n,k; cin>>n>>k;
  vll a(n);
  rep(i,n) cin>>a[i];
  ll cnt=0;
  rep(i,n){
    irep(j,i+1,n){
      if(a[i]>a[j]) cnt++;
    }
  }
  ll cnt2=0;
  rrep(i,n){
    for(int j=i-1; j>=0; j--){
      if(a[j]<a[i]) cnt2++;
    }
  }
  ll ans=0;
  ans=((cnt*((k+1)*k/2%MOD)) + cnt2*((k*(k-1)/2%MOD)))%MOD;
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[100000],a[27]={'a','b','c','d','e','f','g','h','i','j','k','l','n','m','o','p','q','r',
							's','t','u','v','w','x','y','z'};
	int i,k,flg,j;
	scanf("%s",s);
	k=strlen(s);
	flg=0;
	for(i=0;i<k;i++){
		for(j=0;j<26;j++){
			if(s[i]==a[j]) a[j]=0;
		}
	}
	for(i=0;i<26;i++){
		if(a[i]!=0){
			printf("%c\n",a[i]); flg=1; break;
		}
	}
	if(flg==0) printf("None\n");
	return 0;
}

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

typedef long long ll;

const ll MAX_N = 100030;
ll A[MAX_N];
ll diff[MAX_N];

int main() {
  ll N;
  cin >> N;
  A[0] = 0;
  for (ll i = 1; i <= N; i++) {
    cin >> A[i];
  }
  A[N+1] = 0;

  ll sum = 0;
  for (ll i = 1; i <= N+1; i++) {
    sum += abs(A[i] - A[i-1]);
  }

  for (ll i = 1; i <= N; i++) {
    ll a = A[i], p = A[i-1], n = A[i+1];
    ll diff = abs(a - p) + abs(a - n) - abs(p - n);
    cout << sum - diff << endl;
  }
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

#define INF 1000000001
#define LINF 1000000000000000001

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

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

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

string s, t;

int main(){
	cin >> s >> t;
	priority_queue<char> c;
	priority_queue<char, vector<char>, greater<char>> a;
	for(int i = 0; i < s.size(); i++){
		a.push(s[i]);
	}
	for(int i = 0; i < t.size(); i++){
		c.push(t[i]);
	}
	bool b = 0;
	while(c.size()){
		if(a.size() == 0){
			b = 1;
			break;
		}
		if(a.top() < c.top()){
			b = 1;
			break;
		}
		if(a.top() > c.top()){
			b = 0;
			break;
		}
		a.pop();
		c.pop();
	}
	if(b) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	return 0;
}

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

int main(){
  int a,b,c,k;
  cin >>a >>b >>c >>k;
  int xa = min(a,k);
  k -= xa;
  int xb = min(b,k);
  k -= xb;
  int xc = k;
  cout << xa-xc << endl;
}


Measured memory_bytes: 3592
#include<cstdio>
#include<cctype>
#include<set>
using namespace std;
const int N=2e5;
int n,fa[N+1],cnt[N+1][2];
auto cmp=[](const int x,const int y)->bool {
	return 1ll*cnt[x][0]*cnt[y][1]==1ll*cnt[y][0]*cnt[x][1]?x>y:1ll*cnt[x][0]*cnt[y][1]>1ll*cnt[y][0]*cnt[x][1];
};
auto s=set<int,decltype(cmp)>(cmp);
long long res;
int read()
{
	int ret=0;
	char c=getchar();
	while(!isdigit(c)) {
		c=getchar();
	}
	while(isdigit(c)) {
		ret=ret*10+c-'0';
		c=getchar();
	}
	return ret;
}
namespace union_set {
	int fa[N+1];
	int find(int x)
	{
		return fa[x]?fa[x]=find(fa[x]):x;
	}
	inline void merge(int x,int y)
	{
		fa[y]=x;
		return;
	}
}
int main()
{
	n=read();
	for(int i=2;i<=n;++i) {
		fa[i]=read();
	}
	for(int i=1;i<=n;++i) {
		cnt[i][read()]=1;
	}
	for(int i=2;i<=n;++i) {
		s.insert(i);
	}
	while(!s.empty()) {
		int u=union_set::find(*s.begin()),f=union_set::find(fa[u]);
		s.erase(u),s.erase(f);
		res+=1ll*cnt[u][0]*cnt[f][1];
		union_set::merge(f,u);
		cnt[f][0]+=cnt[u][0],cnt[f][1]+=cnt[u][1];
		if(f!=1) {
			s.insert(f);
		}
	}
	printf("%lld\n",res);
	return 0;
}

Measured memory_bytes: 15692
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y first
#define st string
#define ull unsigned long long
#define size(s) s.size()
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
/*inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
const ll power(int n,int k)
{
	ll t=1;
	rep(i,k)
	  t*=n;
	return t;
}
const string turn2(int n)
{
	string s="";
	while(n!=0)
	{
		s+=(char)(n%2+'0');
		n/=2;
	}
	reverse(s.begin(),s.end());
	return s;
}
const string turn16(int n)
{
	string s="";
	while(n!=0)
	{
		if(n%16>9)
		  s+=(char)('A'+n%16-10);
		else
		  s+=(char)('0'+n%16);
		n/=16;
	}
	reverse(s.begin(),s.end());
	return s;
}*/
int main()
{
	int h,w,n;
	cin>>h>>w>>n;
	int x=max(h,w);
	int ans=n/x;
	if(n%x!=0)
		ans++;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
	int w,h,x,y,r;
	scanf("%d %d %d %d %d",&w,&h,&x,&y,&r);
	if(x+r<=w && y+r<=h && x-r>=0 && y-r>=0){
		printf("Yes\n");
	}else{
		printf("No\n");
	}
	return 0;
}

Measured memory_bytes: 1820
#include <iostream>
#include <iomanip>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <cstdio>
#include <utility>
#include <string>
#include <cmath>
#include <cstdlib>
#include <cstring>

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

#define rep(i, N) for(int i = 0; i < N; ++i)

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL


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

    u64 N;
    cin >> N;

    if (N % 2 == 1)
    {
        cout << "0\n";
        return 0;
    }

    u64 ans = 0;
    u64 num2 = 0;
    u64 num5 = 0;
    u64 temp = N;
    while (temp > 0)
    {
        num2 += temp / 2ULL;
        temp /= 2ULL;
    }

    temp = N / 2;
    while (temp > 0)
    {
        num5 += temp / 5ULL;
        temp /= 5ULL;
    }

    cout << MIN(num2, num5) << "\n";
    return 0;
}



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

const int V[10][7] = {
  {0, 1, 1, 1, 1, 1, 1},
  {0, 0, 0, 0, 1, 1, 0},
  {1, 0, 1, 1, 0, 1, 1},
  {1, 0, 0, 1, 1, 1, 1},
  {1, 1, 0, 0, 1, 1, 0},
  {1, 1, 0, 1, 1, 0, 1},
  {1, 1, 1, 1, 1, 0, 1},
  {0, 1, 0, 0, 1, 1, 1},
  {1, 1, 1, 1, 1, 1, 1},
  {1, 1, 0, 1, 1, 1, 1}
};

using namespace std;

typedef long long ll;
typedef long double ld;

string change(int a, int b) {
  string res = "";
  for(int i=0; i<7; i++){
    if(V[a][i] == V[b][i]) {
      res += "0";
    } else {
      res += "1";
    }
  }

  return res;
}
  
int main() {
  int n, f=-1, t;

  while(true) {
    cin >> n;
    if(n == -1) break;
    for(int i=0; i<n; i++) {
      cin >> t;
      if(f == -1) {
        for(int j=0; j<7; j++) {
          cout << V[t][j];
        }
        cout << endl;
        f = t;
      } else {
        cout << change(f, t) << endl;
        f = t;
      }
    }
    f = -1;
  }

  return 0;
}

Measured memory_bytes: 1212
#include <stdio.h>

int day_of_month[]={31,29,31,30,31,30,31,31,30,31,30,31};
char *day_of_week[]={"Monday","Tuesday","Wednesday","Thursday",
		    "Friday","Saturday","Sunday"};
main()
{
  int m,d,i,total;

  while(EOF!=scanf("%d %d",&m,&d) && (m || d))
    {
      total=3;
      for(i=0;i<m-1;i++)
	total += day_of_month[i];
      total += (d-1);

      printf("%s\n",day_of_week[total % 7]);
    }
  return(0);
}

Measured memory_bytes: 0
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int b[55],a[55],n;
bool check(int x,int y)
{
	if (y>n) return 1;
	for (int i=1;i<=2;i++)
	{
		if (i==1) b[y]=a[y]; else b[y]=-a[y];
		int flag=1;
		for (int j=0;j<y;j++)
		{
			int xx=b[y]+12,yy=b[j]+12;
			int t=min(abs(xx-yy),24-abs(xx-yy));
		    if (t<x) flag=0;
		}
	    if (flag==1)
		    if (check(x,y+1)) return 1;
	}
	return 0;
}
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%d",&a[i]);
	int l=0,r=12;
	while (l<r)
	{
		int mid=(l+r+1)/2;
		if (check(mid,1)) l=mid;
		else r=mid-1;
	}
	printf("%d\n",r);
	return 0;
}



Measured memory_bytes: 256
s = gets.to_i
result = 0
ary=[]
ary[1] = s
(2..1000000).each do |i|
  result = (ary[i-1]%2 == 0) ? (ary[i-1]/2) : (3*ary[i-1]+1)
  if ary.include?(result)
    p i
    break
  end
  ary[i]=result
end


Measured memory_bytes: 1788
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
#include <deque>
using namespace std;
using P = pair<int,int>;
typedef long long int ll;
#define rep(i, n) for (int(i) = 0; (i) < (n); (i)++)

int main(){ 
  int n;
  cin >> n;
  vector<int>b(n-1);
  rep(i,n-1)cin >> b[i];
  vector<int>a(n);
  a[0]=b[0];
  for(int i=1; i<=n-2; i++){
    a[i]=min(b[i],b[i-1]);
  }
  a[n-1]=b[n-2];
  int ans =0;
  rep(i,n)ans+=a[i];
  cout << ans << endl;
  return 0;
}



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

// varibable settings
#define int long long
const int INF=1e18;

// define basic macro {{{
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define _rrep(i,n) rrepi(i,0,n)
#define rrepi(i,a,b) for(int i=(int)((b)-1);i>=(int)(a);--i)
#define rrep(...) _overload3(__VA_ARGS__,rrepi,_rrep,)(__VA_ARGS__)
#define each(i,a) for (auto&& i : a)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b)
#define mt(a, b, c) make_tuple(a, b, c)
#define divceil(a,b) ((a)+(b)-1)/(b)
#define is_in(x, a, b) ((a)<=(x) && (x)<(b))
#define uni(x) sort(all(x));x.erase(unique(all(x)),x.end())
#define ub upper_bound
#define lb lower_bound
#define posl(A, x) (lower_bound(all(A), x)-A.begin())
#define posu(A, x) (upper_bound(all(A),x)-A.begin())
template<class T> inline void chmax(T &a, const T &b) { if((a) < (b)) (a) = (b); }
template<class T> inline void chmin(T &a, const T &b) { if((a) > (b)) (a) = (b); }

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef long double ld;
typedef pair<int,int> pii;
typedef tuple<int,int,int> iii;

template<typename T> using PQ = priority_queue<T, vector<T>, greater<T>>;
struct Fast { Fast(){ std::cin.tie(0); ios::sync_with_stdio(false); } } fast;

#if defined(PCM) || defined(LOCAL)
  #include "lib/dump.hpp"
#else
  #define dump(...) 42
  #define dump_1d(...) 42
  #define dump_2d(...) 42
#endif
//}}}

signed main() {
  int n;cin>>n;
  vi a(n), b(n);
  rep(i, n) cin>>a[i]>>b[i];
  int ans = INF;
  int s = 0;
  rep(i, n){
    s += a[i];
    if (a[i]>b[i]) chmin(ans, b[i]);
  }
  if (ans==INF) {
    cout << 0 << endl;
    return 0;
  }
  dump(ans);
  cout << s-ans << endl;
  return 0;
}


Measured memory_bytes: 640
import math
from functools import lru_cache

T = int(input())


class Resolver:
    def __init__(self, a, b, c, d):
        self.a = a
        self.b = b
        self.c = c
        self.d = d

    @lru_cache(maxsize=None)
    def resolve(self, n):
        if n == 0:
            return 0
        elif n == 1:
            return self.d
        else:
            div5f = n // 5
            div5c = (n + 4) // 5
            div3f = n // 3
            div3c = (n + 2) // 3
            div2f = n // 2
            div2c = (n + 1) // 2
            return min(
                self.d * n,
                self.d * abs(n - div5f * 5) + self.c + self.resolve(div5f),
                self.d * abs(n - div5c * 5) + self.c + self.resolve(div5c),
                self.d * abs(n - div3f * 3) + self.b + self.resolve(div3f),
                self.d * abs(n - div3c * 3) + self.b + self.resolve(div3c),
                self.d * abs(n - div2f * 2) + self.a + self.resolve(div2f),
                self.d * abs(n - div2c * 2) + self.a + self.resolve(div2c),
            )


for _ in range(T):
    N, A, B, C, D = map(int, input().split(' '))
    resolver = Resolver(A, B, C, D)
    print(resolver.resolve(N))


Measured memory_bytes: 27600
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define sz(x) int(x.size())
using ll = long long;
using P = pair<int,int>;
const ll LLINF = numeric_limits<long long>::max();
const int mod = 1000000007;
const int INF = 1001001001;

int main()
{
    int a,b;
    cin >> a >>b ;
    cout << a*b;
    return 0;
}

Measured memory_bytes: 3632
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author aryssoncf
 */



// Taken from: https://github.com/bqi343/USACO/blob/master/Implementations/content/contest/templateShort.cpp

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ull> vul;
typedef vector<ll> vl;
typedef vector<pii> vpii;

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto& a: x)

#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define rsz resize

#define mp make_pair
#define pb push_back
#define f first
#define s second

const int MOD = 1e9+7; // 998244353; // = (119<<23)+1
const int MX = 2e5+5;

template<class T> bool ckmin(T& a, const T& b) {
    return a > b ? a = b, 1 : 0; }
template<class T> bool ckmax(T& a, const T& b) {
    return a < b ? a = b, 1 : 0; }

mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());


//
// Created by aryssoncf on 28/10/2019.
//

#include <type_traits>


#include <iterator>
#include <utility>

template <typename T>
constexpr auto hasBegin(int) -> decltype(std::begin(std::declval<T>()), true) {
    return true;
}

constexpr bool hasBegin(...) {
    return false;
}

template <typename T>
using IsContainer = std::integral_constant<bool, hasBegin<T>(0)>;


#ifndef JHELPER_EXAMPLE_PROJECT_IO_HPP
#define JHELPER_EXAMPLE_PROJECT_IO_HPP

#endif //JHELPER_EXAMPLE_PROJECT_IO_HPP

template<typename T>
std::istream &operator>>(std::istream &is, std::vector<T> &vec) {
    for (T &element: vec) {
        is >> element;
    }
    return is;
}

template<typename T, typename U>
std::istream &operator>>(std::istream &is, std::pair<T, U> &p) {
    is >> p.first;
    is >> p.second;
    return is;
}

template <class X, class Y>
std::ostream & operator << (std::ostream & os, std::pair <X, Y> const& p) {
    return os << p.first << " " << p.second;
}

template <class Ch, class Tr, class Container>
std::basic_ostream <Ch, Tr> & operator << (std::basic_ostream <Ch, Tr>& os, Container const& x) {
    bool first = true;
    for(auto& y : x) {
        if (first) {
            first = false;
        } else {
            os << " ";
        }
        os << y;
    }
    return os;
}

using namespace std;

class AMultipleArray {
public:
	void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;
        vi A(n), B(n);
        FOR(i, 0, n) {
            in >> A[i] >> B[i];
        }
        ll res = 0;
        ROF(i, 0, n) {
            int a = A[i], b = B[i], m = (a + res) % b;
            if (m) {
                res += b - m;
            }
        }
        out << res << '\n';
	}

	void setup() {}
};


int main() {
    std::ios_base::sync_with_stdio(false);
	AMultipleArray solver;
    solver.setup();
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	in.tie(nullptr);
    out << std::fixed;
    out.precision(20);
	solver.solve(in, out);
	return 0;
}


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

char S[51];
char T[51];
char restoredS[51];
char tmp[51];
char found =0;
int main(){
        scanf("%s",S);
        scanf("%s",T);

        if(strlen(S) < strlen(T)){ puts("UNRESTORABLE"); return 0;}
        for(int i = 0; i <= strlen(S)-strlen(T); i++){
                char possible = 1;
                for(int j = 0; j < strlen(T); j++){
                        if(S[i+j] != '?' && S[i+j] != T[j]){
                                possible = 0;
                                break;
                        }
                }
                if(possible){
                        for(int a = 0; a < strlen(S); a++){
                                tmp[a] = (S[a]=='?')?'a':S[a];
                        }
                        for(int j = 0; j < strlen(T); j++){
                                tmp[i+j] = T[j];
                        }

                        if(!found) strcpy(restoredS, tmp);
                        else{
                                if(strcmp(restoredS, tmp) > 0){
                                        strcpy(restoredS, tmp);
                                }
                        }
                        found = 1;
                }
        }
        if(found) printf("%s\n",restoredS);
        else puts("UNRESTORABLE");
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j,ans=0;
	cin>>n;
	int a[n];
	for(i=1;i<=n;i++)cin>>a[i];
	for(i=1;i<=n;i+=2)
	{
		if(a[i]%2==1)ans++;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <math.h>
using namespace std;

int main(){
    int N,count=0;
    double D,dis;
    cin>>N>>D;
    double x[N],y[N];
    for(int i=0;i<N;i++){
        cin>>x[i]>>y[i];
    }

    for(int i=0;i<N;i++){
        dis=sqrt(x[i]*x[i]+y[i]*y[i]);
        if(D>=dis) count++;   
    }

    cout<<count<<endl;


}

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



int main()
{
    ll h;
    cin >> h;
    ll ans = 0, num = 1;
    while(h > 0){
        h /= 2;
        ans += num;
        num *= 2;
    }
    cout << ans << endl;



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 1; i <= (int)(n); i++)
vector<int> input(int N) {
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  return vec;
}

int main() {
  int a,b,k,count1=0,count2=0;
  cin >> a >> b >> k;
  rep(i,max({a,b})){
    if(a%i==0&&b%i==0){
      count1++;
    }
  }
  rep(i,max({a,b})){
    if(a%i==0&&b%i==0){
      count2++;
    }
    if(count2==count1-k+1){
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
double xa, xb, A, B;
bool visit[3];
bool ans = false;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

	cin >> A >> B;
	for (double i = 1; i <= 100000000; i++) {
		double aa = floor(i * 0.08);
		double bb = floor(i * 0.1);
		if (aa == A && bb == B) {
			cout << (ll)i << "\n";
			ans = true;
			break;
		}
	}
	if (!ans) cout << "-1";
	return 0;
}

Measured memory_bytes: 384