akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <stdio.h>
#include<limits.h>
#include<algorithm>
#include<queue>
#include<set>
#include<math.h>


#define MOD 1000000007

using namespace std;

long long int modpow(long long int a, long long int n) {
	if (n == 0)return 1;
	if (n == 1)return (a % MOD);

	long long int hanbun = n / 2;
	long long int amari = n % 2;

	long long int ans = (a * a) % MOD;
	ans = modpow(ans, hanbun);

	if (amari == 1)ans *= a;

	ans %= MOD;

	return ans;

}

long long int gcd(long long int a, long long int b) {
	if (a < b) {
		long long int tmp = a;
		a = b;
		b = tmp;
	}

	long long int amari = a % b;

	if (amari == 0)return b;

	return gcd(b, amari);
}

long long int lcm(long long int a, long long int b) {
	long long int ans = (a * b) % MOD;
	long long int wari = modpow(gcd(a, b), MOD - 2);
	ans = (ans * wari) % MOD;
	return ans;
}

long long int factElement[10000] = { 0 };

long long int factrial(int n) {

	if (factElement[n] != 0)return factElement[n];

	if (n == 0) {
		factElement[0] = 1;
		return factElement[n];
	}

	long long int ans = n * factrial(n - 1);
	factElement[n] = ans;
	return factElement[n];

}


void solve(string str, int kind, int mojiLen) {

	//writeするバージョン
	if (str.size() == mojiLen - 1) {
		for (int i = 0; i < kind + 1; i++) {
			char c = 'a' + i;
			cout << str << c << endl;
			
		}
		return;
	}

	//文字列長たりないから、後続を呼ぶやつ。
	//既存の文字を加えるループ。
	for (int i = 0; i < kind; i++) {
		string wkstr = str;
		wkstr.push_back('a' + i);
		solve(wkstr, kind, mojiLen);

	}

	//新規の文字を加える箇所
	string wkstr = str;
	wkstr.push_back('a' + kind);
	solve(wkstr, kind + 1, mojiLen);


}



int main()
{

	int n;
	cin >> n;

	string seed = "a";

	if (n == 1) {
		cout << seed << endl;
	}
	else {
		solve(seed, 1, n);
	}


	return 0;


}



Measured memory_bytes: 1536
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <queue>
#include <algorithm>
#include <set>
#include <map>
#include <bitset>
#include <cmath>
#include <functional>
#define vv(a, b, c, d) vector<vector<d> >(a, vector<d>(b, c))
#define vvi vector<vector<int> >
#define vvl vector<vector<ll> >
#define vll vector<ll>
#define rep(c, a, b) for(ll c=a;c<b;c++)
#define re(c, b) for(ll c=0;c<b;c++)
typedef long long int ll;
typedef long double ld;
using namespace std;

int main(int argc, char const *argv[]) {
  ll x;std::cin >> x;
  for(int i=x;;i++){
    bool flag = true;
    for(int j=2;j*j<=i;j++){
      if(i%j==0) {
        flag = false;
        break;
      }
    }
    if(flag){
      std::cout << i << '\n';
      return 0;
    }
  }
  return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define ps(s) cout << #s << endl;
#define pn(n) cout << (n) << endl;

int main() {
	string s;
	cin >> s;
	if (s == "Sunny") {
		ps(Cloudy);
	}
	else if (s == "Cloudy") {
		ps(Rainy);
	}
	else {
		ps(Sunny)
	}
}

Measured memory_bytes: 256
n = gets.chomp.to_i
a = gets.chomp.split(" ").map(&:to_i)

col = Array.new(9,0)
a.each do |v|
    i = v / 400
    if i < 8
        col[i] += 1
    else
        col[8] += 1
    end
end

m = col[0,8].count {|v| v > 0}

if m == 0
    min = 1
    max = col[8]
elsif col[8] == 0
    min = m
    max = m
else
    min = m
    max = m + col[8]
end
print "#{min} #{max}\n"

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

int main(){

  int n;
  cin >> n;
  vector<int> fibDP(n+1);
  rep(i,n+1){
    if(i == 0 || i == 1) fibDP[i] = 1;
    else fibDP[i] = fibDP[i-1] + fibDP[i-2];
  }

  cout << fibDP[n] << endl;
  return 0;
}


Measured memory_bytes: 3108
import sys
H, W = map(int, input().split())

grid = [[0] for h in range(H)]
#print(grid)
for h in range(H):
    line = list(input())
    grid[h] = line

last = 0
for h in range(H):
    if '#' not in grid[h]:
        print('Impossible')
        sys.exit()
    for w in range(last, W - 1):
        if grid[h][w] == '.' and grid[h][w + 1] == '#':
            print('Impossible')
            sys.exit()
    for w in range(W):
        if grid[h][w] == '#' and w < last:
            print('Impossible')
            sys.exit()
        elif grid[h][w] == '#' and w >= last:
            last = w
print('Possible')

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

#define Abs(x)((x) < 0 ? (x) * -1 : (x))

#define rep(x, y) for ((x) = 0; (x) < (y); (x)++)
#define repin(x, y) for ((x) = 0; (x) <= (y); (x)++)
#define nep(x, y) for ((x) = (y) - 1; 0 <= (x); (x)--)
#define nepi(x, y, z) for ((x) = (y) - 1; (z) <= (x); (x)--)
#define repi(x, y, z) for ((x) = (z); (x) < (y); (x)++)
#define repiin(x, y, z) for ((x) = (z); (x) <= (y); (x)++)
#define reps(x, y, z) for ((x) = 0; (x) < (y); (x) += (z))
#define repis(x, y, z, s) for ((x) = (z); (x) < (y); (x) += (s))
#define repit(x) for (__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define nepit(x) for (__typeof((x).rbegin()) it = (x).rbegin(); it != (x).rend(); it++)

#define All(x) (x).begin(),(x).end()

#define Mem0(x) memset(x, 0, sizeof(x))
#define Mem1(x) memset(x, -1, sizeof(x))

#define Unique(v) v.resize(unique(All(v)) - v.begin())

#define peq(p0, p1)(p0.first == p1.first && p0.second == p1.second)

#define End '\n'
#define Out(x) cout<<(x)<<End
#define OutP(p, sep, end) cout<<p.first<<sep<<p.second<<end

template<typename T> inline bool Max(T &x, const T &y) { return x < y ? x = y, 1 : 0; }
template<typename T> inline bool Min(T &x, const T &y) { return x > y ? x = y, 1 : 0; }
template<typename T> using V = vector<T>;
template<typename T> using VV = V<V<T> >;

#define pb push_back
#define mp make_pair
#define X first
#define Y second
#define lb std::lower_bound
#define ub std::upper_bound

#define lbi(v, x) lb(All(v), (x))-v.begin()
#define ubi(v, x) ub(All(v), (x))-v.begin()

static const ll MOD = 1e9 + 7;
static const double PI = 3.141592653589793;

#define LOCAL 0

int main()
{
#if LOCAL
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("debug.txt", "w", stderr);
#endif

    cin.tie(0);
    ios::sync_with_stdio(false);
	//std::cout.precision(18);

    int n, w, h;

	cin >> n;
	cin >> h;
	cin >> w;

	int ans = 0;

	int i, len = n - h;
	int j, lenJ = n - w;

	repin(i, len) repin(j, lenJ) ans++;

	Out(ans);
	
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		int max = 0;
		for (int i = 1; i < n; i++) {
			boolean[][] arr = new boolean[2][26];
			for (int j = 0; j < n; j++) {
				int idx;
				if (j < i) {
					idx = 0;
				} else {
					idx = 1;
				}
				arr[idx][s.charAt(j) - 'a'] = true;
			}
			int count = 0;
			for (int j = 0; j < 26; j++) {
				if (arr[0][j] && arr[1][j]) {
					count++;
				}
			}
			if (count > max) {
				max = count;
			}
		}
		System.out.println(max);
	}
	
}


Measured memory_bytes: 23252
"use strict";

function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0], 10);
  var S = input[1];
  var s = [...S];
  var ans = N;
  var whiteSum = 0;
  var whiteCount = new Array(N + 1).fill(0);
  whiteCount[0] = 0;

  for (var i = 0; i < N; i++) {
    if (s[i] == ".") {
      whiteSum++;
    }

    whiteCount[i + 1] = whiteSum;
  } //console.log(whiteCount);


  for (var _i = 0; _i <= N; _i++) {
    //console.log(i, whiteCount[i], whiteCount[N], whiteCount[i]);
    var sum = _i - whiteCount[_i] + whiteCount[N] - whiteCount[_i];
    ans = Math.min(sum, ans);
  }

  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int main() {
	int a,b;cin>>a;
  vector<int> vec(a);
  for(int i=0;i<a;i++){
  	cin>>b;
    vec.at(b-1) = i+1;
  }
  
  for(int i=0;i<a;i++){
  	cout<<vec.at(i)<<" ";
  }
  cout<<endl;
}

Measured memory_bytes: 1152
n,m,c = list(map(int, input().split()))
Bs = list(map(int, input().split()))
As =[]
for i in range(n):
	As.append(list(map(int, input().split())))

def check(alist,blist, c):
	num = 0
	for jj in range(len(alist)):
		num += alist[jj] * blist[jj]
	num += c
	return num
cnt = 0
for i in range(n):
	ans = check(As[i],Bs, c)
	if ans > 0:
		cnt += 1
print(cnt)

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

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cerr << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
	os<<"("<<p.first<<","<<p.second<<")";
	return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
	os<<"{";
	rep(i, v.size()) {
		if (i) os<<",";
		os<<v[i];
	}
	os<<"}";
	return os;
}

const int INF = TEN(9);
const int maxn = 100010;

V<int> g[maxn];
int x[maxn];
pii dp[maxn];
set<int> st;

void dfs(int v, int p, int d) {
	pii res(-INF, INF);
	if (x[v] != INF) {
		res = mp(x[v], x[v]);
		st.insert((d + x[v]) % 2);
	}
	for (int to : g[v]) {
		if (to != p) {
			dfs(to, v, d ^ 1);
			chmax(res.fi, dp[to].fi - 1);
			chmin(res.se, dp[to].se + 1);
		}
	}
	if (res.fi > res.se) {
		puts("No");
		exit(0);
	}
	dp[v] = res;
}

void put(int v, int p) {
	for (int to : g[v]) if (to != p) {
		if (x[v] - 1 >= dp[to].fi && x[v] - 1 <= dp[to].se) {
			x[to] = x[v] - 1;
		} else if (x[v] + 1 >= dp[to].fi && x[v] + 1 <= dp[to].se) {
			x[to] = x[v] + 1;
		} else {
			puts("No");
			exit(0);			
		}
		put(to, v);
	}
}

int main() {
	int N;
	cin >> N;
	rep(i, N-1) {
		int a, b;
		cin >> a >> b;
		--a; --b;
		g[a].pb(b); g[b].pb(a);
	}
	int K; cin >> K;

	rep(i, N) x[i] = INF;
	int r;
	rep(i, K) {
		int v, p;
		cin >> v >> p;
		--v;
		x[v] = p;
		r = v;
	}

	dfs(r, -1, 0);
	if (st.size() >= 2) {
		puts("No");
		return 0;
	}

	put(r, -1);
	puts("Yes");	
	rep(i, N) {
		cout << x[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 16896
#include<iostream>

using namespace std;

int main(){
  string S;
  cin >> S;
  int count=0, max=0;
  
  for(auto itr = S.begin(); itr != S.end(); itr++){
    if(*itr == 'A' || *itr == 'C' || *itr == 'G' || *itr == 'T'){
      count++;
      if(count>max) max = count;
    }else{
      count=0;
    }
  }
    
    cout << max << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
using namespace std;
int main()
{
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int x[N], y[M];
  int x_max, y_min;
  x_max = -101;
  y_min = 101;
  for(int i=0; i < N; ++i){
    cin >> x[i];
    x_max = max(x[i], x_max);
  }

  for(int i=0; i < M; ++i){
    cin >> y[i];
    y_min = min(y[i], y_min);
  }

  for(int i=-100; i < 101; ++i){
    if(X < i && i <= Y && x_max < i && y_min >= i){
      cout << "No War" << endl;
      return 0;
    }
  }
  cout << "War" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
int main(void)
{
	int n,k,count=1;
	scanf("%d%d",&n,&k);
	while(n>=k)
	{
		if(n/k>0)
		{
			n=n/k;
			count++;
			}	
	}
	
	printf("%d",count);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
typedef long long ll;
typedef long double la;
using namespace std;

int main(){
    int k;
    cin >> k;
    vector<ll> a;
    for(int i=1;i<=9;i++) a.pb(i);
    while(1){
        if(k <= a.size()){
            cout << a[k-1] << endl;
            return 0;
        }
        k -= a.size();
        vector<ll> old;
        swap(old, a);
        for(ll x : old){
            for(int i = -1; i <= 1; ++i){
                int d = x%10 + i;
                if(d < 0 || d > 9) continue;
                ll nx = x*10 + d;
                a.pb(nx);
            }
        }
    }
    return 0;
}

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

    using namespace std;
    typedef long long ll;
    typedef unsigned long long ull;
    # define M_PI  3.14159265358979323846

    int n,m;
    int sz[100005];
    int parent[100005];
    int ranking[100005];
    vector<pair<int,int>>a(100005);

    int find_comp(int x){
        if(x!=parent[x]){
            parent[x]=find_comp(parent[x]);
        }
        return parent[x];
    }

    bool same_comp(int x, int y){
        return find_comp(x)==find_comp(y);
    }

    void join_comp(int X,int Y){
        int x=find_comp(X);
        int y=find_comp(Y);
        if(ranking[x]>ranking[y]){
            parent[y]=x;
            sz[x]+=sz[y];
        }
        else{
            parent[x]=y;
            sz[y]+=sz[x];
            if(ranking[x]==ranking[y])
                ranking[y]++;
        }
    }



    void solve(){
        cin>>n>>m;
        vector<long long>ans(m+1);
        for(int i=0;i<n;i++){
            parent[i]=i;
            sz[i]=1;
            ranking[i]=0;
        }
        for(int i=0;i<m;i++){
            cin>>a[i].first>>a[i].second;
            a[i].first--;
            a[i].second--;
        }
        ans[m]=(ll)n*(n-1)/2;
        for(int i=m-1;i>=0;i--){
            int x=a[i].first;
            int y=a[i].second;
            if(same_comp(x,y)){
                ans[i]=ans[i+1];
                continue;
            }
            ll size_x=sz[find_comp(x)];
            ll size_y=sz[find_comp(y)];
            join_comp(x,y);
            ans[i]=max(ans[i+1]-size_x*size_y,0LL);
        }
        for(int i=1;i<=m;i++)
            cout<<ans[i]<<"\n";
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 6120
#include <iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<set>

using namespace std;

int main()
{
	int A, B;
	cin >> A >> B;

	int a = A + B;
	int b = A - B;
	int c = A * B;

	cout << max({ a, b, c }) << endl;
}


Measured memory_bytes: 3600
//prefix hai prefix sum
// ho kya rha hai ke dekh dp[x][y]
//dp[x][y]= distributing xy candies among x children 
//so now if dp[x][y]=all possibilies ka sum as or hai ye or ye or etc
// dp[x][y]=dp[x-1][y]+dp[x-1][y-1]+.....dp[x-1][y-a[x]]
// agar isko 0 candy di to x-1 tak y candis deni padengi aur aage par time bohot lega yeh to ham prefix sum ka use karenge to agar hamein ye sum nikalna hai to ham prefix[y]-prefix[y-a[x]-1] kar lenge to hamein sum mil jaega
#include<bits/stdc++.h>
using namespace std;
const int m=1e9+7;
int dp[100][100005];
int arr[100];
int main()
{
    int n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    for(int i=0;i<=arr[0];i++)
    {
        dp[0][i]=1;
    }
    for(int i=1;i<n;i++)
    {
        //dp[i]
        vector<int>prefix(k+1);
        prefix[0]=dp[i-1][0];
        for(int j=1;j<=k;j++)
        {
            prefix[j]=(prefix[j-1]+dp[i-1][j])%m;
        }
        for(int j=0;j<=k;j++)
        {
            if(j>arr[i])
            dp[i][j]=(prefix[j]+m-prefix[j-arr[i]-1])%m;
            else
            dp[i][j]=prefix[j];
        }
    }
    cout<<dp[n-1][k];
    return 0;
}

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

int main(int argc, char const *argv[]) {
  string deck;
  int m, h, sum;

  cin >> deck;

  int i;
  while (deck != "-") {
    cin >> m;
    sum = 0;
    for (i = 0; i < m; i++) {
      cin >> h;
      sum += h;
    }
    cout << deck.substr(sum % deck.length())
         << deck.substr(0, sum % deck.length()) << endl;
    cin >> deck;
  }

  return 0;
}



Measured memory_bytes: 3216
import scala.io.StdIn.readInt

object Main {
  def getQ(n:Int,b:List[Int]):String = {
    if(n/4==0) ((n%4)::b).mkString
    else getQ(n/4,(n%4)::b)
  }

  def main(args:Array[String]) = {
    var n = -1
    while({n=readInt;n} != -1) {
      println(getQ(n,Nil))
    }
  }

}

Measured memory_bytes: 44496
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define eb emplace_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
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; }
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}


int const INF = 1001001001;


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

string w;
cin >> w;
map<char, int> mp;

rep(i,w.size()){
    mp[w[i]]++;
}

for(auto x : mp){
    if(x.second % 2 == 1){
        cout << "No" << endl;
        return 0;
    }
}

cout << "Yes" << endl;

return 0;
}

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



int main() {
  char a;

  cin >> a;

  if(isupper(a))
  cout << "A";
  else
  {
    cout << "a";
  }
}

Measured memory_bytes: 3632
n, a, b = gets.chomp.split(" ").map(&:to_i)
v = gets.chomp.split(" ").map(&:to_i).sort.reverse

def comb_table(n)
  ct = Array.new(51){Array.new(51, 0)}
  (0..n).each do |i|
    (0..i).each do |j|
      if j == 0 || j == i then
        ct[i][j] = 1
      else
        ct[i][j] = ct[i-1][j-1] + ct[i-1][j]
      end
    end
  end
  return ct
end
ct = comb_table(n)

ave = v[0..(a-1)].inject(:+) / a.to_f
puts sprintf("%f", ave)

a_th_val_num = 0
a_th_val_pos = 0

n.times do |i|
  if v[i] == v[a-1] then
    a_th_val_num += 1
    if i < a then
      a_th_val_pos += 1
    end
  end
end

cnt = 0
if v[0] == v[a-1] then
  (a..b).each do |i|
    cnt += ct[a_th_val_num][i]
  end
else
  cnt += ct[a_th_val_num][a_th_val_pos]
end

puts cnt


Measured memory_bytes: 1788
// clang-format off
	#include <bits/stdc++.h>
	using namespace std; using ll = long long; using uint = unsigned int;
	#define SFINAE(x, ...)	template <class, class = void> struct x : false_type {}; template <class T> struct x<T, void_t<__VA_ARGS__>> : true_type {};
	SFINAE(DefaultIO, decltype(cout << declval<T &>()))
	SFINAE(IsTuple, typename tuple_size<T>::type)
	SFINAE(Iterable, decltype(begin(declval<T>())))
	template <class T> constexpr char Space(const T &) { return (Iterable<T>::value or IsTuple<T>::value) ? '\n' : ' '; }
	template <auto &os> struct Writer {
		template <class T> void Impl(T const &t) const {
			if constexpr (DefaultIO<T>::value) os << t;
			else if constexpr (Iterable<T>::value) { int i = 0; for (auto &&x : t) ((i++) ? (os << Space(x), Impl(x)) : Impl(x)); }
			else if constexpr (IsTuple<T>::value) apply([this](auto const &... args) { int i = 0; (((i++) ? (os << ' ', Impl(args)) : Impl(args)), ...);}, t);
			else static_assert(IsTuple<T>::value, "No matching type for print");
		}
		template <class F, class... Ts> auto &operator()(F const &f, Ts const &... ts) const { return Impl(f), ((os << ' ', Impl(ts)), ...), os << '\n', *this; }
	};
	template <auto &is> struct Reader {
		template <class T> auto& operator()(T &t) const {
			if constexpr (DefaultIO<T>::value) is >> t;
			else if constexpr (Iterable<T>::value) for (auto &x : t) (*this)(x);
			else if constexpr (IsTuple<T>::value) apply([this](auto &... args) { ((*this)(args), ...); }, t);
			else static_assert(IsTuple<T>::value, "No matching type for read");
			return *this;
		}
		template <class T> auto operator[](T t) const { (*this)(t); return t; }
	};
	#ifdef NARUT_LOCAL
	#define Debug(...) cerr << "\033[0;31m", Writer<cerr>{}(__VA_ARGS__), cerr << "\033[0m\n"
	#else
	#define Debug(...) 0
	#endif
	[[maybe_unused]] constexpr Reader<cin> Cin; [[maybe_unused]] constexpr Writer<cout> Cout;
	#define FOR(i, j, n) for (int i = int(j); i < int(n); ++i)
	#define ROF(i, j, n) for (int i = int(n) - 1; i >= int(j); --i)
// clang-format on




auto Main() {
	const int n = Cin[0];
	const auto A = Cin[vector<int> (n)]	;
	
	vector<pair<int, int> > pairs = {{A.front(), A.front()}};
	FOR(i,1,n) {
		if (A[i] > A[i-1]) {
			pairs.back().second = A[i];
		}
		if (A[i] < A[i-1]) {
			pairs.emplace_back(A[i], A[i]);
		}
	}

	ll cur = 1000;
	for (auto [lo, hi] : pairs) {
		ll buy = cur/lo;
		cur = cur - buy*lo + buy *hi;
	}
	cout << cur;
}

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
#ifdef NARUT_LOCAL
	assert(freopen("io/test.in", "r", stdin));
	cin.exceptions(cin.badbit | cin.failbit);
	cerr << fixed << setprecision(10);
#endif

	Main();
}


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

int main(){
  ll n,i,g;
  cin >> n;
  vector<ll> a(n);
  for(i=0;i<n;i++){
    cin >> a.at(i);
    if(i==0){
      g=a.at(0);
    }else{
      g=__gcd(a.at(i),g);
    }
  }
  
  if(g!=1){
    cout << "not coprime" << endl;
    return 0;
  }
  
  vector<ll> used(1000000,0);
  for(ll k=0;k<n;k++){
    if(a.at(k)!=1){
      ll j,m=a.at(k);
      vector<ll> p(60,1);
      i=2;
      j=0;
      while(m>=i*i){
        if(m%i==0){
          p.at(j)=i;
          m=m/i;
          j++;
        }else{
          i++;
        }
      }
      p.at(j)=m;
      for(ll l=0;l<=j;l++){
        if(l==0||p.at(l-1)!=p.at(l)){
          if(used.at(p.at(l))==0){
            used.at(p.at(l))++;
          }else{
            cout << "setwise coprime" << endl;
            return 0;
          }
        }
      }
    }
  }
  cout << "pairwise coprime" << endl;
}

Measured memory_bytes: 18824
#include<bits/stdc++.h>
using namespace std;
double a[3000+3];
double dp[3003][3003];
int main(){
int n;
cin >> n;
for(int i=1; i<=n; i++) cin >> a[i];
dp[1][0] = 1.0-a[1];
for(int i=2; i<=n; i++) dp[i][0] = dp[i-1][0]*(1-a[i]);
dp[1][1] = a[1];
for(int i=2; i<=n; i++){
    for(int j=1; j<=i; j++){
        dp[i][j] = dp[i-1][j]*(1-a[i]) + dp[i-1][j-1]*a[i];
    }
}

double ans = 0;
for(int j=n/2+1; j<=n; j++){
    ans+=dp[n][j];
}
cout << fixed << setprecision(10) << ans;
return 0;
}


Measured memory_bytes: 49956
n = int(input())
a = [int(i) for i in input().split(' ')]

dp = [0] * n
dp[0] = 0
dp[1] = abs(a[0] - a[1])
for i in range(2, n):
    dp[i] = min(abs(a[i - 2] - a[i]) + dp[i - 2], abs(a[i - 1] - a[i]) + dp[i - 1])
print(dp[-1])


Measured memory_bytes: 13928
#include<algorithm>
#include<bitset>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<iostream>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
using namespace std;
namespace Solve
{
	const int MAXN=200005;
	int N,K,A[MAXN];
	long long sumv[MAXN];
	int B[MAXN];
	map<int,int>mp;
	void work()
	{
		scanf("%d%d",&N,&K);
		for(int i=1;i<=N;i++)
			scanf("%d",&A[i]);
		sumv[0]=0;
		for(int i=1;i<=N;i++)
			sumv[i]=sumv[i-1]+A[i];
		B[0]=0;
		for(int i=1;i<=N;i++)
			B[i]=(sumv[i]-i)%K;
		long long ans=0;
		mp[0]=1;
		int front=0,rear=1;
		for(int i=1;i<=N;i++)
		{
			rear=i;
			if(rear-front>=K)
			{
				mp[B[front]]--;
				front++;
			}
			if(!mp.count(B[i]))
			{
				mp[B[i]]=1;
			}
			else
			{
				ans+=mp[B[i]];
				mp[B[i]]++;
			}
		}
		cout<<ans<<endl;
		return;
	}
}
int main()
{
	#ifdef LOCAL
	freopen("00test.in","r",stdin);
	freopen("00test.out","w",stdout);
	#endif
	Solve::work(); 
	return 0;
}

Measured memory_bytes: 12800
S = list(input())
K = int(input())
N = len(S)
left = 1
while left < N and S[0] == S[left]:
    left += 1
right = 0
while N - 1 - right and S[0] == S[N - 1 - right]:
    right += 1
S += S
cnt = 0
for i in range(len(S) - 1):
    if S[i + 1] == S[i]:
        S[i + 1] = 'A'
        cnt += 1
if left + right < N and left % 2 != 0 and right % 2 != 0:
    print(max(0, (cnt + 1) * (K // 2) + ((cnt + 1) // 2) * int(K % 2 != 0) - 1))
else:
    print(cnt * (K // 2) + (cnt // 2) * int(K % 2 != 0))


Measured memory_bytes: 8996
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int p = sc.nextInt();
		int q = sc.nextInt();
		int r = sc.nextInt();

		int min =0;

		min = p+q;
		min = Math.min(min,q+r);
		min = Math.min(min,p+r);

		System.out.print(min);

	}

}


Measured memory_bytes: 23764
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include<stack>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,m,n) for(int i=m;i<n;i++)
#define endre getchar(); getchar();return 0;
#define pie 3.141592653589793238462643383279
#define INF 1000000007
signed main() {
	string s;
	int n;
	cin >> n >> s;
	int cnt = 0,sum=0;
	rep(i, n) {
		if (s[i] == '(')cnt++;
		else if (s[i] == ')'&&cnt > 0) cnt--; 
		else  sum++;
	}
	rep(i, sum)cout << '(';
	cout << s;
	rep(i, cnt)cout << ')';
	cout << endl;
}

Measured memory_bytes: 256
//shara's here
#include <bits/stdc++.h>
using namespace std;
typedef int q;
typedef double w;
typedef string s;
typedef long long ll;
typedef long double ld;
void yoinks(){
std::ios::sync_with_stdio(false);
cin.tie(0); cout.tie(0);
}
int main(){
    yoinks();
    char x,y;
    cin>>x>>y;
    s ss="",dd="";
    int n=(int)(y-'0');
    int g=(int)(x-'0');
    while(n--){
    	ss+=x;
    }

    while(g--){
    	dd+=y;
    }
    if(ss<dd)cout<<ss<<endl;
    else cout<<dd<<endl;


    
















return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define watch(x) cout << (#x) << "is " << (x) << '\n';
using namespace std;

const int MOD = 1000000007;

int square(int n){
	return n * n;
}

int main(){
	ios_base::sync_with_stdio(false); cin.tie(0);
	int N; cin >> N;
	vector<int> integers(N);
	for (int i = 0; i < N; i++){
		cin >> integers[i];
	}
	int answer = numeric_limits<int>::max();
	for (int i = -100; i <= 100; i++){
		int temp_answer = 0;
		for (int j = 0; j < N; j++){
			temp_answer += square(integers[j] - i);
		}
		answer = min(answer, temp_answer);
	}
	cout << answer << endl;
}

Measured memory_bytes: 256
// 2020-06-26 22:50:29
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  int k;
  cin >> k;
  queue<ll> que;
  REPC(i, 1, 9) que.emplace(i);
  while(1) {
    k--;
    if(k == 0) break;
    ll a = que.front(); que.pop();
    ll b = a % 10;
    if(b >= 1) { que.push(a * 10 + b - 1); }
    que.push(a * 10 + b);
    if(b <= 8) { que.push(a * 10 + b + 1); }
  }
  cout << que.front() << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 4788
/*
* @Author: kabbo
* @Date:   2020-06-04 21:16:41
* @Last Modified by:   kabbo
* @Last Modified time: 2020-06-13 01:04:12
*/
#include<bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define endl '\n'
#define ull unsigned long long
#define ll long long
const int mod = 1e9 + 7;
using u64 = uint64_t;
using u128 = __uint128_t;
ll dp(ll n) {
    if (n == 1)
        return 1;
    return 1 + (2 * dp(n / 2));
}
void solve() {
    ll n;
    cin >> n;
    cout << dp(n) << endl;
}
int main() {

    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    /*int t;
    cin >> t;*/
    /*for (int i(1); i <= t; ++i) {
        //printf("Case %d: ", i);*/
    solve();
    // }
#ifndef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << "s.\n";
#endif
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
char a[10];
int main(){
	cin >> a;

	REP(i,4)
		a[i] -= '0';

	REP(i,(1 << 3)) {
		ll sum = a[0];

		REP(j,3) {
			if(i & (1 << j)) {
				sum += a[j + 1];
			}else {
				sum -= a[j + 1];
			}
		}

		if(sum == 7) {
			cout << (int)a[0];
			REP(j,3) {
				if(i & (1 << j)) {
					cout << '+';
				}else 
					cout << '-';
				cout << (int)a[j + 1];
			}
			cout << '=' << 7 << endl;
			break;
		}
	}
	return 0;
}


Measured memory_bytes: 256
package main

import (
	"fmt"
)

type Row struct {
	sy int
	sx int
	ty int
	tx int
}

func (r Row) String() string {
	return fmt.Sprint(r.sy, r.sx, r.ty, r.tx)
}

func main() {
	var h, w int
	fmt.Scan(&h, &w)
	a := make([][]int, h)
	for y := 0; y < h; y++ {
		a[y] = make([]int, w)
		for x := 0; x < w; x++ {
			fmt.Scan(&a[y][x])
		}
	}
	var result []Row
	sy, sx := 0, 0
	for true {
		ty, tx := sy, sx+1-(sy%2)*2
		if tx < 0 || tx >= w {
			ty, tx = sy+1, sx
		}
		if ty >= h {
			break
		}
		if a[sy][sx]%2 == 1 {
			a[ty][tx]++
			result = append(result, Row{sy + 1, sx + 1, ty + 1, tx + 1})
		}
		sy, sx = ty, tx
	}
	fmt.Println(len(result))
	for _, row := range result {
		fmt.Println(row)
	}
}


Measured memory_bytes: 21248
n, k = map(int, input().split())

snukes_snacks = [[] for i in range(n)]
for i in range(k):
	d = int(input())
	a = list(map(int, input().split()))
	for j in range(d):
		snukes_snacks[a[j]-1].append(i+1)

ans = 0
for item in snukes_snacks:
	if len(item) == 0:
		ans += 1
print(ans)

Measured memory_bytes: 67824
#!ruby -anrmatrix
(v=Vector
a,b,c,d,e,f=$F.map &:to_f
x,y=*Matrix[[a-c,b-d],[a-e,b-f]].inv/2*v[-c*c-d*d+q=a*a+b*b,q-e*e-f*f]
puts"%.3f %.3f %.3f"%[x,y,v[a-x,b-y].r])if$.>1

Measured memory_bytes: 6432
import itertools

N,M=map(int,input().split())
a=[0]*N
b=[0]*N
C=[[0 for _ in range(N+1)] for _ in range(N+1)]

for i in range(M):
  a,b=map(int,input().split())
  C[a][b]=1
  C[b][a]=1
#print(C)
  
L=[i for i in range(1,N+1)]
#print(L)
ans=0
for v in itertools.permutations(L,len(L)):
  sw=1
  #print(v)
  if v[0]!=1:
    continue
  for i in range(len(v)-1):
    if C[v[i]][v[i+1]]==0:
      sw=0
      break
  if sw==1:
    ans+=1
print(ans)

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

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

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> a(n), b(n);
  vector<pair<ll, ll>> p;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;
    p.push_back(make_pair(a, b));
  }
  sort(p.begin(), p.end());
  ll ans = 0;
  rep(i, n) {
    if (p[i].second <= m) {
      ans += p[i].first * p[i].second; 
      m -= p[i].second;
    } else {
      ans += p[i].first * m;
      break;
    }
    //printf("first: %lld, second: %lld\n", p[i].first, p[i].second);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(ll i=a;i<b;++i)
#define REPN(i,a,b) for(ll i=a;i<=b;++i)
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define ll long long
const int M=1e9+7;
const int MAXN=17;


int main()
{/*
#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
#*/
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
  string s,t;
  cin>>s>>t;
  int a,b;
  cin >>a>>b;
  string u;
  cin>>u;
  if(u==s)
  cout<<a-1<<" "<<b<<"\n";
  else cout<<a<<" "<<b-1<<"\n";

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include <algorithm>
#include <vector>
#include <iostream>
#include <map>
using namespace std;
int main(){
  string o,e;
  int a,b;
  cin>>o>>e;
  a=o.size();
  b=e.size();
  if (a==b){
    for (int i=0;i<a;i++){
      cout<<o[i]<<e[i];}
  }
  else{
    for (int i=0;i<b;i++){
      cout<<o[i]<<e[i];}
    cout<<o[a-1];}
    
  
  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = [int(x.strip()) for x in input().split()]
b = [0]
for i in range(n):
  if i == n-1:
    break
  elif a[i]+b[i] > a[i+1]:
    b.append(a[i]+b[i]-a[i+1])
  else:
    b.append(0)
print(sum(b))

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

int main(){

    int n;
    string s;
    cin>>n>>s;

    int cnt=0;
    string tem[50]={""};


    for(int i=0;i<n-2;i++){
        tem[i]=s[i];
        tem[i]+=s[i+1];
        tem[i]+=s[i+2];
        if(tem[i]=="ABC") cnt+=1;
    }

    cout<<cnt<<endl;

return 0;
}

Measured memory_bytes: 256
Q = int(input())
query = [list(map(int, input().split())) for _ in range(Q)]

def is_prime(n):
  if n <= 1:
    return False
  if n == 2:
    return True
  i = 2
  while i * i <= n:
    if n % i == 0:
      return False
    i += 1
  return True

prime = []
ans = [0]*100001
sum_a = [0]*100001
for n in range(1, 100000+1):
  if is_prime(n) and is_prime((n+1)//2):
    if n != 2:
      prime.append(n)
      ans[n] = 1
  sum_a[n] = sum_a[n-1] + ans[n]

for l, r in query:
  print(sum_a[r] - sum_a[l-1])

Measured memory_bytes: 32028
// Created by Nandu Vinodan
#include <bits/stdc++.h>

#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define rep(i,a,n) for(int i=a;i<=(n);++i)
#define repD(i,a,n) for(int i=a;i>=(n);--i)
#define pb(a) push_back(a)
#define eb(a) emplace_back(a)
#define vi vector<int>
#define pi pair<int, int>
#define INF INT_MAX
#define _INF INT_MIN
#define TC 0

using namespace std;
using ll = long long;

void testcase() {
    ll n, a, b;

    cin >> n >> a >> b;

    ll val = (n/(a+b)) * a;

    ll rem = (n % (a+b));
    if (rem > a) rem = a;
    cout << val + rem << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t=1;
    if (TC)
        cin>>t;
    while(t--) {
        testcase();
    }
    return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    const N = readln.chomp.to!long;
    const as = readln.split.to!(long[]);

    long count2(long x) {
        if (x % 2 == 1) return 0;
        else return 1 + count2(x/2);
    }
    writeln(as.map!(a => count2(a)).sum);
}



Measured memory_bytes: 2812
n=int(input())
p=list(map(int,input().split()))
c=0

for i in range(n-2):
    if p[i+1]!=min(p[i:3+i]) and p[i+1]!=max(p[i:3+i]):
        c+=1
    elif p[i+1]==max(p[i:3+i]) and p[i:3+i].count(p[i+1])==2:
        c+=1
print(c)

Measured memory_bytes: 3060
import java.util.*;

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

        int n = sc.nextInt();

        Map<String, String> map = new HashMap<>();

        String s = sc.next();
        map.put(s, s);
        for(int i = 0; i < n - 1; i++){
            String next = sc.next();
            if(map.containsKey(next)){
                System.out.println("No");
                return;
            }
            if(s.charAt(s.length() - 1) != next.charAt(0)){
                System.out.println("No");
                return;
            }
            map.put(next, next);
            s = next;
        }

        System.out.println("Yes");

    }
}


Measured memory_bytes: 23252
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <string>
#include <iostream>
#include <algorithm>
#include <map>
using namespace std;
typedef long long LL;
LL q, a, b, pf;
int main(){
	scanf("%lld", &q);
	while(q--){
		scanf("%lld%lld", &a, &b);
		pf = sqrt(a * b);
		if(a == b) printf("%lld\n",(a - 1) * 2);
		else if(pf * (pf + 1) < a * b) printf("%lld\n", 2 * pf - 1);
		else if(pf * pf < a * b) printf("%lld\n", 2 * pf - 2);
		else if(pf * (pf - 1) < a * b) printf("%lld\n", 2 * pf - 3);
	}
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a, x[1000], i=0;
  
  while( scanf("%d",&a) != EOF ){
    
    if( a != 0 ){
      x[i]=a;
      i++;
    }
    
    else if( a == 0 ){
      printf("%d\n",x[i-1]);
      i--;
    }
    
  }

  return 0;
}

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

int main(void){
	int n;
	cin>>n;
	while(n--){
		string s;
		valarray<int> h(3);
		int o=0;
		int sc=0;
		h=0;
		while(o!=3){
			cin>>s;
			if(s[0]=='O')o++;
			else if(s[1]=='I'){
				sc+=h[2];
				h=h.shift(-1);
				h[0]=1;
			}else{
				sc+=1+h.sum();
				h=0;
			}
		}
		cout<<sc<<endl;
	}
	return 0;
}

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

int main() {
	int N;
	cin >> N;
	long long res = 0;
	for (int i = 1; i < N+1; i++) {
		if (i % 15 == 0 || i % 3 == 0 || i % 5 == 0) {
			continue;
		}
		else {
			res = res + i;
		}
	}
	cout << res << endl;
}

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


int main()
{
    string s;
    cin>>s;
    string t;
    int flag=1;
    for(int i=0;i<s.length();i++)
    {
        if(s[i]!='A')
            t+=s[i];
        if(s[i]=='K'&&s[i+1]!='I')
            flag=0;
        if(s[i]=='I'&&s[i+1]!='H')
            flag=0;
        if(s[i]=='A'&&s[i+1]=='A')
            flag=0;
    }
    if(t=="KIHBR"&&flag)
        cout<<"YES"<<endl;
    else cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <vector>
//#include <string>
//#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 100100
//#define NIL -1
//#define INFTY 1000000000000000000

int main(){
    LL n;
    LL ans=0;
    cin >> n;
    for(LL i=1; i<n; i++){
        LL tmp=n-i;
        LL tmp_ans=1;
        for(LL j=2; j*j<=tmp; j++){
            LL tmp_multi=1;
            while(tmp%j==0){
                tmp_multi++;
                tmp/=j;
            }
            tmp_ans*=tmp_multi;
        }
        if(tmp>1){
            tmp_ans*=2;
        }
        ans+=tmp_ans;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define INF 2e9
#define MOD 1000000007
using namespace std;
typedef long long llong;
typedef long double ldouble;

using Graph = vector<vector<int>>;

// int ctoi(const char c){
//   if('0' <= c && c <= '9') return (c-'0');
//   return -1;
// }

// int gcd(int a, int b){
//   int ma = max(a,b);
//   int mi = min(a,b);
//   if(mi == 0) return ma;

//   return gcd(mi, ma%mi);
// }

int main(){
  int ans = 0;
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  for(int i=0; i<N; ++i){
    cin >> C[i];
    for(int j=0; j<M; ++j){
      cin >> A[i][j];
    }
  }
  for(int bit=0; bit<(1<<N); ++bit){
    vector<int> understand(M);
    int cash = 0;
    for(int i=0; i<N; ++i){
      if(bit & (1<<i)){
        for(int j=0; j<M; ++j){
          understand[j] += A[i][j];
        }
        cash += C[i];
      }
    }
    for(int i=0; i<M; ++i){
      if(understand[i] < X){
        cash = 0;
        break;
      }
    }
    if(cash>0 && ans>0) ans = min(cash, ans);
    else if(cash>0) ans = cash;
  }
  if(ans==0) cout << -1 << endl;
  else cout << ans << endl;
}


Measured memory_bytes: 3628
#include <stdio.h>

int main(void) {
  int a, b;
  scanf("%d %d", &a, &b);
  if(a < b) {
    for(int i = 0; i < b; i++)
      printf("%d", a);
  } else {
    for(int i = 0; i < a; i++)
      printf("%d", b);
  }
  putchar('\n');
  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

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

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

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

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll A, B;
  cin >> A >> B;

  if (A % 3 == 0) {
    COUT("Possible");
    return 0;
  }

  if (B % 3 == 0) {
    COUT("Possible");
    return 0;
  }
  if ((A + B) % 3 == 0) {
    COUT("Possible");
    return 0;
  }
  
  COUT("Impossible");
  return 0;
}

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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define LLINF       LLONG_MAX/3
#define MOD         (1000000007LL)
#define MODA(a, b)  a=((a)+(b))%MOD
#define MODP(a, b)  a=((a)*(b))%MOD
#define inc(i, l, r)   for(int i=(l);i<(r);i++)
#define dec(i, l, r)   for(int i=(r)-1;i>=(l);i--)
#define pb          push_back
#define se          second
#define fi          first
#define mset(a, b)  memset(a, b, sizeof(a))

using LL  = long long;
using G   = vector<vector<int>>;

int di[] = {0, -1, 0, 1};
int dj[] = {1, 0, -1, 0};
// }}}

int main() {
    cin.tie(0);ios::sync_with_stdio(false);
    int q;cin >> q;
    inc(i, 0, q){
        LL a, b;cin >> a >> b;
        LL c = a*b;

        LL ng = min(a, b)-1;
        LL ok = max(a, b)+1;
        while(ok-ng>1){
            LL m = (ng+ok)/2LL;
            if(ng*ng == c){
                break;
            }
            if(ok*ok == c){
                ng = ok;
                break;
            }
            if(m*m == c){
                ng = m;
                break;
            }else if(m*m < c){
                ng = m;
            }else{
                ok = m;
            }
        }
        LL d = ng;

        LL ans = (d-1)*2;
        if(d*(d+1) < c){
            ans++;
        }else if(d*d == c && a != d && b != d){
            ans--;
        }
        //if(a > d+(d-1)){
            //ans--;
        //}
        //if(b > d+(d-1)){
            //ans--;
        //}
        printf("%lld\n", ans);
        //cout << d << "#" << ans << endl;
    }
    return 0;
}


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

#define rep(i,n) for(ll i = 0; i < n; i++)
#define per(i,n) for(ll i = n-1; i >= 0; i--)
#define REP(i,n) for(ll i = 1; i < n; i++)
#define PER(i,n) for(ll i = n; i >= 1; i--)
#define sz(x) int(x.size())
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define YesorNo(a) printf(a ? "Yes\n" : "No\n")
#define endl '\n'
#define fi first
#define se second
using ll = long long;
using P = pair<int,int>;
using Pl = pair<ll,ll>;
using vi = vector<int>;
using vii = vector<vi>;
using vl = vector<ll>;
using vll = vector<vl>;
using vs = vector<string>;
using vb = vector<bool>;
using vc = vector<char>;
using vcc = vector<vc>;
using vP = vector<P>;
using vPP = vector<vP>;
using vPl = vector<Pl>;
const int dx[] = {0,1,0,-1,1,1,-1,-1};
const int dy[] = {1,0,-1,0,1,-1,-1,1};
const int inf = (1<<30)-1;
const ll infll = (1LL<<62)-1;
ll ceil(const ll &a, const ll &b){return ((a)+(b)-1)/b;}
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; }



int main(){
  rep(i,5) {
    int b;
    cin >> b;
    if(b != i+1) {
      cout << i+1 << endl;
      return 0;
    }
  }
}

Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<string>

using namespace std;

int main(){
    int H,W;
    cin >> H >> W;
    int h,w;
    cin >> h >> w;
    int men = H*W;
    men = men - h*W - ((H-h)*w);
    cout << men << endl;
    return 0;
}


Measured memory_bytes: 256