akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e5+7;
int num[maxn];
int main()
{
    string stra;
    string strb;
    cin>>stra>>strb;
    int len=stra.size();
    memset(num,-1,sizeof(num));
    for(int i=0;i<len;i++)
    {
        if(num[stra[i]]==-1)
        {
            num[stra[i]]=strb[i];
        }
        else
        {
            if(num[stra[i]]!=strb[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    memset(num,-1,sizeof(num));
    for(int i=0;i<len;i++)
    {
        if(num[strb[i]]==-1)
        {
            num[strb[i]]=stra[i];
        }
        else
        {
            if(num[strb[i]]!=stra[i])
            {
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 1160
x1, y1, x2, y2 = [int(x) for x in input().split()]

x3 = x2 + (y1 - y2)
y3 = y2 + (x2 - x1)

x4 = x1 + (y1 - y2)
y4 = y1 + (x2 - x1)

print("{} {} {} {}".format(x3, y3, x4, y4))


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <string>

using namespace std;
int main(int argc, const char * argv[]) {
    
    int r, g, b, n;

    cin >> r >> g >> b >> n;

    int cnt = 0;

    
    int ma = max(max(r, g), b);
    int mi = min(min(r, g), b);
    int mm = r + g + b - ma - mi;

    int d = n/ma;
    for (int i = 0; i <= d; i++ ) {
        int a1 = i*ma;
        int r1 = n - a1;
        int d2 = r1/mm;
        for (int j=0; j <= d2; ++j) {
            int r2 = r1 - j*mm;
            if ( r2 % mi == 0 ) cnt++;
        }
    }

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
#define de(x) cout << #x << "=" << x << endl;
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) { a = b; return 1;} return 0;}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) { a = b; return 1;} return 0;}
#define dame {cout<< "-1" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------

//--MAIN-----------------------------------
void Main() {
    string S; cin>>S;
    ll N=S.size();
    ll K; cin>>K;
    ll dp[110][5][2]={}; // 桁 nokori ぴったり1 else0
    ll c0=S[0]-'0';
    dp[1][0][0]=1; //0
    dp[1][1][0]=c0-1; //それ以外
    dp[1][1][1]=1; //それ
    reps(i,1,N){
        ll c=S[i]-'0';
        rep(k,4){
            //今までぴったり
            // 0
            if(c==0) dp[i+1][k][1]+=dp[i][k][1];
            else dp[i+1][k][0]+=dp[i][k][1];
            // それ
            if(c!=0) dp[i+1][k+1][1]+=dp[i][k][1];
            //それ以外
            if(c!=0) dp[i+1][k+1][0]+=dp[i][k][1]*(c-1);

            //今までぴったりでない
            //0
            dp[i+1][k][0]+=dp[i][k][0];
            //0以外
            dp[i+1][k+1][0]+=dp[i][k][0]*9;
        }
    }
    cout<< dp[N][K][0]+dp[N][K][1] <<"\n";

}

//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

#define all(a) (a).begin(), (a).end()

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

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

    int n, m; cin>>n>>m;

    cout << n * (n - 1) / 2 + m * (m - 1) / 2 << endl;

    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
int h,w,ans;
int row[2005][2005],col[2005][2005];
char s[2005][2005];
int main()
{
	cin>>h>>w;
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			cin>>s[i][j];
	for(int r=1;r<=h;r++)
	{
		int cnt=1,sum=0;
		vector<int> v;
		for(int i=1;i<=w;i++)
			if(s[r][i]=='#')
			{
				if(sum!=0)
				{
					v.push_back(sum);
					cnt++;
					sum=0;
				}
			}
			else
			{
				sum++;
				row[r][i]=cnt;
			}
		if(sum!=0)
			v.push_back(sum);
		for(int i=1;i<=w;i++)
			if(s[r][i]=='.')
				row[r][i]=v[row[r][i]-1];
	}
	for(int c=1;c<=w;c++)
	{
		int cnt=1,sum=0;
		vector<int> v;
		for(int i=1;i<=h;i++)
			if(s[i][c]=='#')
			{
				if(sum!=0)
				{
					v.push_back(sum);
					cnt++;
					sum=0;
				}
			}
			else
			{
				sum++;
				col[i][c]=cnt;
			}
		if(sum!=0)
			v.push_back(sum);
		for(int i=1;i<=h;i++)
			if(s[i][c]=='.')
				col[i][c]=v[col[i][c]-1];
	}
	for(int i=1;i<=h;i++)
		for(int j=1;j<=w;j++)
			if(s[i][j]=='.')
				ans=max(ans,row[i][j]+col[i][j]-1);
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 35584
import java.io.*;
import java.util.Scanner;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		
		pr.println(Math.min(n * a, b));
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);
			
		solve();
			
		pr.close();
		sc.close();
	}

	static class Printer extends PrintWriter {
		Printer(OutputStream out) {
			super(out);
		}
	}
}


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

using namespace std;

#define YES cout << "YES" << endl;
#define NO  cout << "NO"  << endl;
#define Yes cout << "Yes" << endl;
#define No  cout << "No"  << endl;
 
#define INF INT_MAX
#define MOD 1000000007
#define PI  acos(-1)

using ll  = long long;
using ull = unsigned long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define rrep(i, n) for (ll i = (n)-1; i >= 0; i--)

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

    ll A, B;
    cin >> A >> B;

    if ((A+B)%2 == 0){
        cout << abs(A+B)/2 << endl;
    } else {
        cout << "IMPOSSIBLE" << endl;
    }
    return 0;
}


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

public class Hello
{
    public static void Main()
    {
        var N = int.Parse(Console.ReadLine().Trim());

        int zero = 0;
        var map = new Dictionary<Tuple<long, long>, int[]>();

        for(var i = 0; i < N; i++)
        {
            var A_B = Console.ReadLine().Trim().Split().Select(e=> long.Parse(e)).ToArray();
            var x = A_B[0];
            var y = A_B[1];

            if(x == 0 && y == 0) {
                zero++;
                continue;
            }
            var g = Gcd(x, y);
            x /= g;
            y /= g;
            if (y < 0) { x = -x; y = -y; }
            if (y == 0 && x < 0) { x = -x; y = -y; }
            bool rot90 = (x <= 0); 
            if (rot90) {
                var tmp = x;
                x = y; y = -tmp;
            }

            var t = Tuple.Create(x,y);
            if (rot90) {  
                if(map.ContainsKey(t)) {
                    map[t][0]++;
                } else {
                    map[t] = new []{1,0};
                }
            }
            else {
                if(map.ContainsKey(t)) {
                    map[t][1]++;
                } else {
                    map[t] = new []{0,1};
                }
            }
        }

        ModInt ans = 1;
        foreach(var p in map.Values)
        {
            int s = p[0];
            int t = p[1];
            ModInt now = 1;
            now += ModInt.Pow(2, s) - 1;
            now += ModInt.Pow(2, t) - 1;
            ans *= now;
        }
        ans -= 1;

        ans += zero;
        Console.WriteLine(ans);
   }

    class ModInt
    {
        public const long Mod = 1000000007;

        public long num;

        public ModInt(long n) { num = n; }

        public override string ToString() { return num.ToString(); }
        public static ModInt operator +(ModInt l, ModInt r) { l.num += r.num; if (l.num >= Mod) l.num -= Mod; return l; }
        public static ModInt operator -(ModInt l, ModInt r) { l.num -= r.num; if (l.num < 0) l.num += Mod; return l; }
        public static ModInt operator *(ModInt l, ModInt r) { return new ModInt(l.num * r.num % Mod); }
        public static implicit operator ModInt(long n) { n %= Mod; if (n < 0) n += Mod; return new ModInt(n); }

        public static ModInt Pow(ModInt v, long k) { return Pow(v.num, k); }

        public static ModInt Pow(long v, long k)
        {
            long ret = 1;
            for (k %= Mod - 1; k > 0; k >>= 1, v = v * v % Mod)
                if ((k & 1) == 1) ret = ret * v % Mod;
            return new ModInt(ret);
        }

        public static ModInt Inverse(ModInt v) { return Pow(v, Mod - 2); }
    }

    private static long Gcd(long a, long b)
    {
        if (a < b)
        {
            return Gcd(b, a);
        }
        while (b != 0)
        {
            long r = a % b;
            a = b;
            b = r;
        }
        return a;
    }



}

Measured memory_bytes: 72520
// atcoder/ddcc2020-qual/C/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  int h, w, k;
  while (cin >> h >> w >> k) {
    char g[h][w];
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        cin >> g[i][j];
      }
    }

    int x[h][w];
    fill(&x[0][0], &x[h - 1][w - 1] + 1, 0);
    int y = 0;
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (g[i][j] == '#') x[i][j] = ++y;
      }
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 1; j < w; ++j) {
        if (x[i][j] == 0) {
          x[i][j] =  x[i][j - 1];
        }
      }
      for (int j = w - 2; 0 <= j; --j) {
        if (x[i][j] == 0) {
          x[i][j] = x[i][j + 1];
        }
      }
    }
    for (int i = 1; i < h; ++i) {
      if (x[i][0] == 0) {
        for (int j = 0; j < w; ++j) {
          x[i][j] = x[i - 1][j];
        }
      }
    }
    for (int i = h - 2; 0 <= i; --i) {
      if (x[i][0] == 0) {
        for (int j = 0; j < w; ++j) {
          x[i][j] = x[i + 1][j];
        }
      }
    }
    for (int i = 0; i < h; ++i) {
      for (int j = 0; j < w; ++j) {
        if (j) cout << ' ';
        cout << x[i][j];
      }
      cout << endl;
    }
  }

  return 0;
}


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

#if __has_include("print.hpp")
  #include "print.hpp"
#endif

#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define MOD 1000000007

typedef long long ll;
typedef pair<int, int> p;


long double logn(int base, int tv)
{
  return log(tv) / log(base);
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  long double n, k;
  cin >> n >> k;
  long double res = 0;

  for (int i = 1; i <= n; i++) {
    int tmp = i;
    long double p = 1;
    while(tmp < k){
      tmp *= 2;
      p *= 0.5;
    }
    res += p;
  }
  res /= n;
  printf("%.10Lf\n",res);


}


Measured memory_bytes: 256
n,m,x=map(int,input().split())
a=[list(map(int,input().split())) for _ in range(n)]
ans=[]
for i in range(2**n):
    bag=[0 for _ in range(m)]
    total=0
    res=True
    for j in range(n):
        if ((i>>j)&1):
            total+=a[j][0]
            for k in range(m):
                bag[k]+=a[j][k+1]
    for l in range(m):
        if bag[l]<x:
            res=False
            break
    if res:
        ans.append(total)

if ans!=[]:
    print(min(ans))
else:
    print(-1)


Measured memory_bytes: 9284
#include <cstdio>
#include <stdlib.h>
#include <cstring>


using namespace std;

int main(void){
	int i, n;
	char ans[128];
	while(1){
		scanf("%d",&n);
		if(n == 0){
			break;
		}
		sprintf(ans,"%o",n);
		for(i = 0;i < strlen(ans);i++){
			if(ans[i] >= '5'){
				ans[i] += 2;
			}else if(ans[i] == '4'){
				ans[i]++;
			}
		}
		printf("%s\n",ans);
	}
	return 0;
}

Measured memory_bytes: 1048
#include<stdio.h>

int main(){
  int t_a,t_h,a_a,a_h;
  int win;
  scanf("%d %d %d %d",&t_h,&t_a,&a_h,&a_a);
  while(1){
    a_h=a_h-t_a;
    if(a_h<=0){
      win=1;
      break;
    }
    t_h=t_h-a_a;
    if(t_h<=0){
      win=0;
      break;
    }
  }
  if(win){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}


Measured memory_bytes: 1736
#include <iostream>
using namespace std;
int main(int argc, const char * argv[]) {
    int a,b;
    cin >> a;
    cin >> b;
    if(a>=1 && a<=100 && b>=1 && b<=100)
        cout << a*b << " " << 2*(a+b) << endl;
    return 0;
}


Measured memory_bytes: 3084
#include<bits/stdc++.h>
#define ll long long
#define f first
#define s second
#define pb push_back
#define mp make_pair
using namespace std;

int main(){
    ll n,k;
    cin >> n >> k;
    
    cout << n - k + 1;
    
    
    
    
    
    return 0;
}


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

using ll = long long int;

const int MAX_N = (int)(1e5 + 5);

int n;
ll a[MAX_N];

ll whole;
ll tmp;

int main(void){
  scanf("%d", &n);

  for (int i = 0; i < n; ++i) {
    scanf("%lld", &(a[i]));
  }

  whole = abs(0 - a[0]) + abs(a[n - 1] - 0);

  for (int i = 0; i < n - 1; ++i) {
    whole += abs(a[i] - a[i + 1]);
  }

  tmp = whole - (abs(0 - a[0]) + abs(a[0] - a[1])) + abs(0 - a[1]);
  printf("%lld\n", tmp);

  for (int i = 1; i < n - 1; ++i) {
    tmp = whole - (abs(a[i - 1] - a[i]) + abs(a[i] - a[i + 1])) + abs(a[i - 1] - a[i + 1]);
    printf("%lld\n", tmp);
  }

  tmp = whole - (abs(a[n - 2] - a[n - 1]) + abs(a[n - 1] - 0)) + abs(a[n - 2] - 0);
  printf("%lld\n", tmp);

  return 0;
}

Measured memory_bytes: 2048
# -*- coding: utf-8 -*-
"""
D - Cake 123
https://atcoder.jp/contests/abc123/tasks/abc123_d

"""
import sys


from itertools import product

def solve(X, Y, Z, K, A, B, C):
    # TLE
    res_AB = sorted([sum(p) for p in product(A, B)], reverse=True)[:K]
    return sorted([sum(p) for p in product(res_AB, C)], reverse=True)[:K]


def main(args):
    X, Y, Z, K = map(int, input().split())
    A = [int(a) for a in input().split()]
    B = [int(b) for b in input().split()]
    C = [int(c) for c in input().split()]
    ans = solve(X, Y, Z, K, A, B, C)
    print(*ans, sep='\n')


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


Measured memory_bytes: 143200
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,n) for(int i = 0; i < n; ++i)
#define rep2(i,st,ed) for(int i = st; i < ed; ++i)
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
const ll mod = 1e5+3;
const ll N = 1e2 + 200;
const ll INF = 9999999999999;
const double eps = 1e-7;

int main(){
    int n;
    cin>>n;
    cout<<(n+1)/2<<endl; 
    
    return 0;
}

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

#define rep(i, a, b) for (int i = a; i < (b); ++i)
#define trav(a, x) for (auto& a : x)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int w, h, i, j, grid[25][25];
bool iddfs(int dep) {
	//printf("Dep = %d, Pos = (%d, %d)\n", dep, i, j);
	int i0 = i, j0 = j;

	if (dep == 0) {
		return grid[i][j] == 3;
	}

	bool res = false;

	// up
	i = i0, j = j0;
	if (i && grid[i - 1][j] != 1) {
		while (i && grid[i - 1][j] != 1 && grid[i][j] != 3) i--;
		if (grid[i][j] == 3) return true;
		bool flag = i && grid[i - 1][j] == 1;
		if (flag) {
			int li = i, lj = j;
			grid[li - 1][lj] = 0;
			res |= iddfs(dep - 1);
			grid[li - 1][lj] = 1;
		}
	}

	// down
	i = i0, j = j0;
	if (i < h - 1 && grid[i + 1][j] != 1) {
		while (i < h - 1 && grid[i + 1][j] != 1 && grid[i][j] != 3) i++;
		if (grid[i][j] == 3) return true;
		bool flag = i < h - 1 && grid[i + 1][j] == 1;
		if (flag) {
			int li = i, lj = j;
			grid[li + 1][lj] = 0;
			res |= iddfs(dep - 1);
			grid[li + 1][lj] = 1;
		}
	}

	// left
	i = i0, j = j0;
	if (j && grid[i][j - 1] != 1) {
		while (j && grid[i][j - 1] != 1 && grid[i][j] != 3) j--;
		if (grid[i][j] == 3) return true;
		bool flag = j && grid[i][j - 1] == 1;
		if (flag) {
			int li = i, lj = j;
			grid[li][lj - 1] = 0;
			res |= iddfs(dep - 1);
			grid[li][lj - 1] = 1;
		}
	}

	// right
	i = i0, j = j0;
	if (j < w - 1 && grid[i][j + 1] != 1) {
		while (j < w - 1 && grid[i][j + 1] != 1 && grid[i][j] != 3) j++;
		if (grid[i][j] == 3) return true;
		bool flag = j < w - 1 && grid[i][j + 1] == 1;
		if (flag) {
			int li = i, lj = j;
			grid[li][lj + 1] = 0;
			res |= iddfs(dep - 1);
			grid[li][lj + 1] = 1;
		}
	}

	return res;
}

int main() {
	for (;;) {
		cin >> w >> h;
		if (!w && !h) break;

		int i0, j0;
		rep(i, 0, h) rep(j, 0, w) {
			cin >> grid[i][j];
			if (grid[i][j] == 2) i0 = i, j0 = j;
		}

		for (int d = 1; d <= 10; d++) {
			i = i0, j = j0;
			if (iddfs(d)) {
				cout << d << endl;
				goto nextloop;
			}
		}
		cout << -1 << endl;

nextloop: void(0);
	}
}



Measured memory_bytes: 3104
#include <stdio.h>
int main(){

  int n,muki[500],i,j,k,add,mukihow,bash,maxbash;
  char train[1024],name[500],result[500];
  
  scanf("%d",&n);
  
  for(j = 0; j < n; j++){
    
    for(i = 0; i < 1024; i++) train[i]='0';
    for(i = 0; i < 500; i++) name[i]='0';
    for(i = 0; i < 500; i++) muki[i]=0;
    for(i = 0; i < 500; i++) result[i]='0';
    
    
    scanf("%s",train);
    
    add=0;
    for(i = 0; train[i] != '0'; i += 3){
    
    name[add]=train[i];
    add++;
    
  }

    mukihow=add-1;    
    add=0;
    for(i = 1; train[i] != '0'; i += 3){
    
    if(train[i] == '-') muki[add]=1;
    if(train[i] == '<') muki[add]=-1;
    add++;
    
  }

    /*
    printf("%d\n",mukihow);
    

    for(i = 0; i < mukihow+1; i++) printf("%c",name[i]);
    printf("\n");
    
    for(i = 0; i < mukihow; i++) printf("%d",muki[i]);
    printf("\n");
    */    

    bash=0;
    maxbash=0;
    result[0]=name[0];
    
    for(i = 0; i < mukihow; i++){
    bash += muki[i];
    if(maxbash < bash) maxbash=bash;
    if(bash == -1){
    
    for(k = 0; k < maxbash+1; k++) result[maxbash+1-k]=result[maxbash-k];
    maxbash++;
    bash=0;
    
  }

    result[bash]=name[i+1];

  }

    for(i = 0; i < maxbash+1; i++) printf("%c",result[i]);

    printf("\n");
    
    
  }

    return 0;

  }
    
    
    

Measured memory_bytes: 572
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<pair<ll, ll>>> vvpll;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    cin >> n;

    vector<pair<pair<string, ll>, ll>> book(n);
    rep(i, n) {
        string s;
        ll p;
        cin >> s >> p;
        book[i] = make_pair(make_pair(s, -p), i+1);
    }
    sort(all(book));

    rep(i, n) {
        out(book[i].second);
    }

    re0;
}

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

int main()
{
	int n;
	cin>>n;
	int l;
	cin>>l;
	int a[n+1];
	int mini=0;
	int minn=100000;
	for(int i=1;i<=n;i++)
	{
		a[i]=l+i-1;
		if(fabs(a[i])<minn)
		{
		//	cout<<a[i]<<' '<<i<<endl;
			minn=fabs(a[i]);
			mini=i;
		 } 
	 } 
	 a[mini]=0;
	 int ans=0;
	 for(int i=1;i<=n;i++)
	 {
	 	ans+=a[i];
	 }
	 cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INCANT cin.tie(0), cout.tie(0), ios::sync_with_stdio(false), cout << fixed << setprecision(20);
#define int long long
#define gcd __gcd
#define all(x) (x).begin(), (x).end()
template<class T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<class T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}
#define _overload(_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(...) _overload(__VA_ARGS__, repi, _rep)(__VA_ARGS__)
#define _rev(i, n) revi(i, n, 0)
#define revi(i, a, b) for(int i = (int)(a - 1); i >= (int)(b); i--)
#define rev(...) _overload(__VA_ARGS__, revi, _rev)(__VA_ARGS__)
#define each(i, n) for(auto&& i: n)
const int INF = 1e18, MOD = 1e9 + 7;
vector<int> g[111111];
map<pair<int, int>, int> m;
void dfs(int now, int from, int used) {
    cerr<<now<<' '<<from<<' '<<used<<endl;
    int col = 1;
    each(i, g[now]) {
        if(i != from) {
            if(col == used) {
                col++;
            }
            m[{now, i}] = col;
            dfs(i, now, col);
            col++;
        }
    }
}
signed main() {
    INCANT;
    int n, a, b;
    vector<pair<int, int>> gg;
    cin>>n;
    rep(i, n - 1) {
        cin>>a>>b;
        a--, b--;
        g[a].push_back(b);
        gg.push_back({a, b});
    }
    dfs(0, -1, -1);
    set<int> an;
    each(p, gg) {
        an.insert(m[p]);
    }
    cout<<an.size()<<endl;
    each(p, gg) {
        cout<<m[p]<<endl;
    }
}


Measured memory_bytes: 15732
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
X = []
Y = []
C = []
for i in range(M):
    x, y, c = map(int, input().split())
    X.append(x)
    Y.append(y)
    C.append(c)

mn = min(a) + min(b)

for i in range(M):
    t = a[X[i]-1] + b[Y[i]-1] - C[i]
    mn = min(t, mn)

print(mn)

Measured memory_bytes: 85612
#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 <int, int>;

int main() {
  int N;
  cin >> N;
  vector<int> B(N);
  rep(i, (N-1)){
    int A;
    cin >> A;
    B.at(A-1)++;
  }

  rep(i, N) cout << B.at(i) << endl;

}


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

typedef long double ld;
typedef unsigned long ul;
typedef long long ll;
typedef unsigned long long ull;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long> vl;
typedef vector<double> vd;
typedef map<int,int> mii;
typedef pair<int,int> pii;
typedef pair<long,long> pll;

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,a,n) for(int i=a;i<n;i++)
#define ALL(a) (a).begin(),(a).end()
#define pb(x) push_back(x)
#define mp(x,y) make_pair((x),(y))

#define pi 3.14159265358979
#define eps 1e-9
#define inf 1<<30

string s[51];
int n;
int ret[27], buf[27];

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

	rep(i,27){
		ret[i] = 0;
	}

	rep(i,n){
		rep(j,27) buf[j] = 0;
		rep(j,s[i].size()){
			buf[s[i][j] - 'a']++;
		}
		if(i==0){
			rep(j,27) ret[j] = buf[j];
		}else{
			rep(j,27){
				if(ret[j] > buf[j]) ret[j] = buf[j];
			}
		}
	}

	rep(i,27){
		rep(j,ret[i]) printf("%c", 'a'+i);
	}
	printf("\n");
	
	return 0;
}


Measured memory_bytes: 256
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T> using G = greater<T>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), G<type>())
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) lower_bound(ALL(a), (x)) - a.begin()
#define bisect_right(a, x) upper_bound(ALL(a), (x)) - a.begin()
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define OUTPUT_PERMUTATION(n) do{VI v(n); iota(ALL(v), 1); do{REPx(x, v) cout << x << " "; ENDL} while(next_permutation(ALL(v)));} while(0);
#define MAKE_PERMUTATION(n, PER) do{VVI a(fact(n), VI(n)); int idx = 0; VI v(n); iota(ALL(v), 1); do{REP(roop, n) a[idx][roop] = v[roop]; idx++;} while(next_permutation(ALL(v))); PER = a;} while(0); // int fact(), VVI PERを宣言しておく、n=10が限界(500 ms)
#define ENDL cout << endl;

const int INF = 2e9;
const LL MOD = 1e9 + 7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, G<T> >;
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;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I "; else cout << A[i] << " ";}}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL a, b, n;
  cin >> a >> b >> n;
  cout << a*min(b-1, n)/b << endl;

  return 0;
}


Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>
#define MAX_WH 100
using namespace std;


int w,h;//h:i,w:j


char board[MAX_WH][MAX_WH];
bool check[MAX_WH][MAX_WH];

int vx[4] = {1,-1,0,0};
int vy[4] = {0,0,1,-1};

void back(char c, int i, int j){
	check[i][j] = true;
	for(int k=0;k<4;k++){
		int pi,pj;
		pi = i + vx[k];
		pj = j + vy[k];
		if(-1<pi && pi<h && -1<pj && pj<w){
			if(board[pi][pj] == c && !check[pi][pj]){
				back(c,pi,pj);
			}
		}
	}
}

int solve(){
	int sum=0;
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			check[i][j] = false;
		}
	}
	
	for(int i=0;i<h;i++){
		for(int j=0;j<w;j++){
			if(!check[i][j]){
				check[i][j] = true;
				back(board[i][j], i, j);
				sum++;
			}
		}
	}
	return sum;
}	

int main(){
	while(1){
		scanf(" %d %d",&h,&w);
		if(w==0 && h==0) break;
		
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				scanf(" %c",&board[i][j]);
			}
		}
		printf("%d\n",solve());
		
	}
	return 0;
}

Measured memory_bytes: 1512
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <vector>
#include <array>
#include <map>
#include <set>
#include <stack>
#include <cstdint>
#include <cmath>
#include <algorithm>
#include <utility>
#include <numeric>
#include <functional>
#include <cassert>

using namespace std;
using ll = int64_t;
using ull = uint64_t;

constexpr ll INF = 1000000000;/* 1e+9a */

void solve(istream &cin) {
    ll K;
    if (!(cin >> K)) { return; }
    ll A, B;
    cin >> A >> B;
    ll ans = K + 1;
    if(A < K){
        if(B > A){
            ll pro = (K+1-A)/2;
            pro *= (B-A);
            pro += (K+1-A) % 2;
            pro += A;
            ans = max(pro, ans);
        }
    }
    cout << ans << endl;


}

int main(int argc, char *argv[]) {
    string FileName("C"), Modifier("MEPH_");
    string ExecutionName = Modifier + FileName;
    string sub(argv[0]);
    // /home/USER/.../MEPH_X -> MEPH_X
    if (sub.size() > ExecutionName.size())
        sub = sub.substr(sub.size() - ExecutionName.size(), ExecutionName.size());

    cout << setprecision(16) << scientific;
    if (sub != ExecutionName) {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        while (cin) { solve(cin); }
    } else {
        cerr << sub << " test" << endl;
        string inFile = FileName + ".txt";
        auto fs = fstream(inFile, fstream::in);
        while (fs) { solve(fs); }
    }
}


Measured memory_bytes: 256
<?php
// Your code here!
$input = fgets(STDIN);
$a = array();

for($i = 1; $i <= $input; $i++){
    if($i % 2 == 1) $a[] = $i;
}

$a = count($a);
echo sprintf("%.lf",$a/$input).PHP_EOL;

?>


Measured memory_bytes: 4728
#include<iostream>

using namespace std;

int main() {
    int n = 0;
    cin >> n;
    int v[n];
    int c[n];
    int vsum = 0, csum = 0;
    for(int i = 0; i < n; i++) {
        cin >> v[i];
    }

    for(int i = 0; i < n; i++) {
        cin >> c[i];
    }
    for(int i = 0; i < n; i++) {
        if(v[i] > c[i]) {
            vsum+=v[i];
            csum+=c[i];
        }
    }
    cout << vsum - csum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
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;
}
using ll = long long;
const ll MOD = 1e9 + 7;
const long long INF = 1LL << 60;

int main()
{
    int a, b;
    cin >> a >> b;

    cout << a * b << endl;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

const int MAXN = 100005;

struct Edge
{
	int to;
	int nxt;
}edge[MAXN << 1];

int n,id;
int first[MAXN];
int fa[MAXN];

bool mark[MAXN];

void addE(int u,int v)
{
	edge[++id] = (Edge){v,first[u]};
	first[u] = id;
}

void dfs(int u)
{
	for (int i = first[u];i;i = edge[i].nxt)
		if (edge[i].to != fa[u])
		{
			fa[edge[i].to] = u;
			dfs(edge[i].to);
			if (!mark[edge[i].to])
			{
				if (mark[u])
				{
					puts("First");
					exit(0);
				}
				mark[u] = mark[edge[i].to] = 1;
			}
		}
}

int main()
{
	scanf("%d",&n);
	for (int u,v,i = 1;i < n;i++)
	{
		scanf("%d%d",&u,&v);
		addE(u,v);
		addE(v,u);
	}
	dfs(1);
	if (!mark[1])
		puts("First");
	else
		puts("Second");
	return 0;
}

Measured memory_bytes: 2688
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    string s[N];
    ll t[N];
    REP(i, 0, N) {
        cin >> s[i] >> t[i];
    }
    string X;
    cin >> X;
    ll ans = 0;
    bool ok = false;
    REP(i, 0, N) {
        if (ok) {
            ans += t[i];
        } else {
            if (s[i] == X) {
                ok = true;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
package main

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

var (
	sc = bufio.NewScanner(os.Stdin)
	bw = bufio.NewWriter(os.Stdout)
)

const inf = 1 << 60
const mod int = 1e9 + 7

func init() {
	sc.Split(bufio.ScanWords)
}

func ri() (n int) {
	sc.Scan()
	b := sc.Bytes()
	x := 1
	if b[0] == 45 {
		x *= -1
		b = b[1:]
	}
	for _, v := range b {
		n = n*10 + int(v-48)
	}
	return n * x
}

func println(a ...interface{}) {
	_, _ = fmt.Fprintln(bw, a...)
	return
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func swap(a int, b int) (int, int) { return b, a }

func main() {
	defer bw.Flush()
	sc.Split(bufio.ScanWords)
	n := ri()
	neg := make([]int, 0, n)
	pos := make([]int, 0, n)
	for i := 0; i < n; i++ {
		if a := ri(); a < 0 {
			neg = append(neg, a)
		} else {
			pos = append(pos, a)
		}
	}
	sort.Ints(neg)
	sort.Ints(pos)
	if n == 2 {
		tmp := make([]int, 0, 2)
		tmp = append(tmp, neg...)
		tmp = append(tmp, pos...)
		x, y := tmp[0], tmp[1]
		if y > x {
			x, y = y, x
		}
		fmt.Println(x - y)
		println(x, y)
		return
	}
	if len(neg) == 0 {
		x, y := pos[0], pos[1]
		println(x, y)
		neg = append(neg, x-y)
		pos = pos[2:]
	} else if len(pos) == 0 {
		x, y := neg[len(neg)-1], neg[len(neg)-2]
		println(x, y)
		pos = append(pos, x-y)
		neg = neg[:len(neg)-2]
	}
	m := 0
	for _, v := range neg {
		m -= v
	}
	for _, v := range pos {
		m += v
	}
	fmt.Println(m)
	reduceNeg := func() {
		for len(neg) > 1 {
			x := pos[len(pos)-1]
			y := neg[len(neg)-1]
			println(x, y)
			pos = append(pos[:len(pos)-1], x-y)
			neg = neg[:len(neg)-1]
		}
	}
	reducePos := func() {
		for len(pos) > 1 {
			x := neg[len(neg)-1]
			y := pos[len(pos)-1]
			println(x, y)
			neg = append(neg[:len(neg)-1], x-y)
			pos = pos[:len(pos)-1]
		}
	}
	if len(neg) > 1 && len(pos) > 1 {
		if len(neg) > len(pos) {
			reduceNeg()
			reducePos()
		} else {
			reducePos()
			reduceNeg()
		}
	} else if len(neg) == 1 && len(pos) > 1 {
		reducePos()
	} else if len(neg) > 1 && len(pos) == 1 {
		reduceNeg()
	}
	println(pos[0], neg[0])
}


Measured memory_bytes: 4736
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);
int main()
{
    // input_from_file;
  // int t; cin>>t;
  // while(t--){
  ll n;cin>>n;
  vector<vector<ll>> vec(n,vector<ll> (3,0));
  for(int i=0;i<n;i++){
    for(ll j=0;j<3;j++) cin>>vec[i][j];
  }
  vector<vector<ll>> dp(n,vector<ll> (3,0));
  dp[0][0]=vec[0][0];
  dp[0][1]=vec[0][1];
  dp[0][2]=vec[0][2];
  for(int i=1;i<n;i++){
    dp[i][0]=max(dp[i-1][1],dp[i-1][2])+vec[i][0];
    dp[i][1]=max(dp[i-1][0],dp[i-1][2])+vec[i][1];
    dp[i][2]=max(dp[i-1][1],dp[i-1][0])+vec[i][2];
  }
  cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]}); 
	return 0;
}

Measured memory_bytes: 11136
fn main() {
    let mode = "a";
    if mode == "a" {
        a::solve();
    }
}

mod a {
    use std;
    use std::io::Read;

    pub fn solve() {
        let mut buf = String::new();
        std::io::stdin().read_to_string(&mut buf).unwrap();

        let mut text = buf.split_whitespace();
        let a = text.next().unwrap().parse().unwrap();
        let b = text.next().unwrap().parse().unwrap();
        match calc(a, b) {
            None => println!("IMPOSSIBLE"),
            Some(x) => println!("{}", x),
        }
    }

    fn calc(a: i32, b: i32) -> Option<i32> {
        let total = a + b;
        if total & 0x1 == 0x1 {
            return None;
        }
        Some(total / 2)
    }

    #[cfg(test)]
    mod tests {
        use super::*;

        #[test]
        fn test1() {
            assert_eq!(calc(2, 16), Some(9));
        }
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#define rep(i,n) for(int64_t i=0;i < (int64_t)(n);i++)
using namespace std;
//////全探索したいときに開けよ////////
vector<vector<int>> fspattern;
vector<int> fspattern_draft;
int fspcnt = 0;

void setfspattern_core(int floor,int number,int degree){
  if(floor==degree){
    fspattern.at(fspcnt) = fspattern_draft;
    fspcnt++;
  }else{
    rep(i,number){
      fspattern_draft.at(floor) = i;
      setfspattern_core(floor+1,number,degree);
    }
  }
}

void setfspattern(int number,int degree){
  int64_t array_num = 1;
  rep(i,degree){
    array_num *= number;
  }
  fspattern = vector<vector<int>>(array_num,vector<int>(degree));
  fspattern_draft = vector<int>(degree);
  setfspattern_core(0,number,degree);
}

//////nCrのmodを求めたいときに開けよ/////////
//int64_t univMod = 1000000007;
//int64_t factnum = 100000
//vector<int64_t> modfact(factnum);
//vector<int64_t> modinvfact(factnum);

/*void setmodfact(){
  for(int i=0;i<factnum;i++){
    if(i == 0){
      modfact.at(i) = 1;
    }else{
      modfact.at(i) = (modfact.at(i-1)*i)%univMod;
    }
  }
}

int64_t calcmodpower(int64_t a,int64_t n){
  int64_t res = 1;
  while(n != 0){
    if(n & 1){
      res = (res * a) % univMod;
    }
    a = (a*a) % univMod;
    n = n >> 1;
  }
  return res;
}

int64_t calcinverse(int64_t n){
	return calcmodpower(n,univMod-2);
}

void setmodinvfact(){
  for(int i=0;i<factnum;i++){
    if(i==0){
      modinvfact.at(i) = 1;
    }else{
      modinvfact.at(i) = calcmodpower(modfact.at(i),univMod-2);
    }
  }
}*/


/*
int64_t calcGCD(int64_t a,int64_t b){
	int64_t p = a;
	int64_t q = b;
	int64_t c = a%b;
	while(c != 0){
		p = q;
		q = c;
		c = p%q;
	}
	return q;
}
*/

int main(){
  int d,g;
  cin >> d >> g;
  vector<pair<int,int>> pc(d);
  rep(i,d) cin >> pc.at(i).first >> pc.at(i).second;
  setfspattern(2,d);
  int mincnt = 5000000;
  rep(i,fspcnt){
    int score = 0;
    int cnt = 0;
    rep(j,d){
      if(fspattern.at(i).at(j) == 1){
        score += 100*(j+1)*pc.at(j).first+pc.at(j).second;
        cnt += pc.at(j).first;
      }

    }
    if(score < g){
      rep(j,d){
        if(fspattern.at(i).at(d-1-j) == 0){
          rep(k,pc.at(d-1-j).first-1){
            score += 100*(d-j);
            cnt++;
            //cout << score << "," << cnt << endl;
            if(score >= g){
              break;
            }
          }
        }
        if(score >= g){
          break;
        }
      }
    }
    //cout << cnt << endl;
    if(mincnt > cnt && score >= g){
      mincnt = cnt;
      //cout << i;
    }
  }
  cout << mincnt << endl;
      
}

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

const int N = 1e5 + 5;

#define st first
#define nd second

typedef pair<int,int> pun;
typedef long long ll;

int inf = 1<<30;
int dp[N][32];

int tab[N];

int szukaj(int x) {
	for (int i = 0; i < 30; i ++) if ((1 << i) >= x) return i;
	return 30;
}

int K = 30;

int main() {
	int n;
	scanf("%d", &n);
	for (int i = 0; i < n; i ++) {
		scanf("%d", tab + i);
	}
	int z = szukaj(tab[0]);
	for (int i = 0; i <= K; i ++) {
		dp[0][i] = max(z, i);
// 		printf("0 %d -- %d\n", i, dp[0][i]);
	}
	for (int x = 1; x < n; x ++) {
		int z = szukaj(tab[x]);
		for (int i = 0; i <= K; i ++) {
			dp[x][i] = dp[x-1][0] + max(z, i);
		}
		for (int i = 0; i <= K; i ++) {
			int dod = 0;
			for (int j = 0; j <= K; j ++) {
				if (j == z && j <= i && ((1<<z) != tab[x])) dod ++;
				dp[x][i] = min(dp[x][i], dp[x-1][j] + max(z - j, 0) + dod + max(i - z, 0));
			}
//  			printf("%d %d -- %d\n", x, i, dp[x][i]);
		}
	}
	int res = inf;
	for (int i = 0; i <= K; i ++) res = min(res, dp[n-1][i]);
	printf("%d\n", res);
}


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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pll;
typedef vector<bool> vb;
const ll oo = 0x3f3f3f3f3f3f3f3f;
const double eps = 1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c), end(c)
#define FOR(i,a,b) for (ll i = (a); i < (b); i++)
#define FORD(i,a,b) for (ll i = (b)-1; i >= (a); i--)
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define TR(X) ({ if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	ll a, b;
	cin >> a >> b;

	if (a == 1 || b == 1) cout << 1 << endl;
	else cout << (a*b+1)/2 << endl;
}



Measured memory_bytes: 256
module kkk
sub main()
  
  dim h as long
  h = console.readline()
  dim i as long
  dim k as long
    dim ans as long
    
    do 
      k = h - 2^i
      if k < 0 then
        exit do
        end if
      i = i + 1
    loop
    
    ans = 2^i - 1
      console.writeline(ans)
    end sub
  end module

Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
using namespace std;
using lli = long long int;
int main()
{
    lli n, h, w;
    cin >> h >> w >> n;
    lli a[100005] = {};
    lli f[105][105] = {};
    rep(i, n) cin >> a[i];
    int cnt = 0;
    int hoge = 0;
    rep(i, h)
    {
        if (i % 2 == 0) {
            rep(j, w)
            {

                cnt++;
                f[i][j] = hoge + 1;
                if (cnt == a[hoge]) {
                    hoge++;
                    cnt = 0;
                }
            }
        } else {
            rrep(j, w)
            {
                f[i][j] = hoge + 1;
                cnt++;
                if (cnt == a[hoge]) {
                    cnt = 0;
                    hoge++;
                }
            }
        }
    }
    rep(i, h) rep(j, w)
    {
        cout << f[i][j] << " ";
        if (j == w - 1)
            cout << endl;
    }
}


Measured memory_bytes: 1152
import java.io.*;

import java.util.*;
import java.math.*;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
import static java.math.BigInteger.*;
import static java.lang.Character.*;

class AOJ1019 {
	public void run() {
		Scanner sc = new Scanner(System.in);
		while (true) {
			int N = sc.nextInt();
			int K = sc.nextInt();
			if (N == 0 && K == 0)
				return;
			int[] S = new int[K];
			for (int i = 0; i < K; i++)
				S[i] = sc.nextInt();
			int[][] B = new int[N][K];
			for (int i = 0; i < N; i++)
				for (int j = 0; j < K; j++)
					B[i][j] = sc.nextInt();
			boolean f = true;
			int[] T = new int[K];
			for (int i = 0; i < K; i++) {
				for (int j = 0; j < N; j++)
					T[i] += B[j][i];
				if(T[i] > S[i]) {
					f = false;
					break;
				}
			}
			System.out.println(f ? "Yes" : "No");
		}
	}

}


public class Main {
	public static void main(String... args) {
		new AOJ1019().run();
	}

	public static void debug(Object... os) {
		System.err.println(java.util.Arrays.deepToString(os));
	}
}

class Scanner {
	final java.util.Scanner sc;

	public double nextDouble() {
		return Double.parseDouble(sc.next());
	}

	public Scanner(java.io.InputStream is) {
		this.sc = new java.util.Scanner(is);
	}

	public boolean hasNext() {
		return sc.hasNext();
	}

	public String next() {
		return sc.next();
	}

	public int nextInt() {
		return Integer.parseInt(sc.next());
	}

	public String nextLine() {
		return sc.nextLine();
	}

	public long nextLong() {
		return Long.parseLong(sc.next());
	}
}

Measured memory_bytes: 13000