akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
char s[1111];

int top;
char oper[1111];int op1[1111],op2[1111],res[1111];
int _top;
int _op1[1111], _op2[1111], _res[1111];
void calc(){
	if(res[top] == -1)return;
	while(top > 0){
		--top;
		if(op1[top] == -1){
			op1[top] = res[top+1];
			top++;
			oper[top] = '@';
			res[top] = -1;
			break;
		}else{
			op2[top] = res[top+1];
			if(oper[top] == '^')
				res[top] = max(op1[top], op2[top]);
			else
				res[top] = min(op1[top], op2[top]);
			oper[top] = '#';
		}
	}
	if(top==0){
		oper[top] = '#';
	}
}
int calc_min(){
	_top = top;
	memcpy(_op1, op1, sizeof(int)*(_top+1));
	memcpy(_op2, op2, sizeof(int)*(_top+1));
	memcpy(_res, res, sizeof(int)*(_top+1));
	while(_top > 0){
		if(_res[_top] == -1)
			_res[_top] = 0;

		--_top;
		if(_op1[_top] == -1){
			_op1[_top] = _res[_top+1];
			_op2[_top] = 0;
		}else{
			_op2[_top] = _res[_top+1];
		}
		if(oper[_top] == '^')
			_res[_top] = max(_op1[_top], _op2[_top]);
		else
			_res[_top] = min(_op1[_top], _op2[_top]);
	}
	if(oper[0] == '@'){
		if(_res[0] == -1)
			_res[0] = 0;
	}
	return _res[0];
}

int calc_max(){
	_top = top;
	memcpy(_op1, op1, sizeof(int)*(_top+1));
	memcpy(_op2, op2, sizeof(int)*(_top+1));
	memcpy(_res, res, sizeof(int)*(_top+1));
	while(_top > 0){
		if(_res[_top] == -1)
			_res[_top] = 99;
		else
		if(oper[_top] == '@' && _res[_top] >= 1 && _res[_top] <= 9)
			_res[_top] = _res[_top] * 10 + 9;

		--_top;
		if(_op1[_top] == -1){
			_op1[_top] = _res[_top+1];
			_op2[_top] = 99;
		}else{
			_op2[_top] = _res[_top+1];
		}
		if(oper[_top] == '^')
			_res[_top] = max(_op1[_top], _op2[_top]);
		else
			_res[_top] = min(_op1[_top], _op2[_top]);
	}
	if(oper[0] == '@'){
		if(_res[_top] == -1)
			_res[_top] = 99;
		else
		if(_res[_top] >= 1 && _res[_top] <= 9)
			_res[_top] = _res[_top] * 10 + 9;
	}
	return _res[0];
}

void process(){
	top = 0;
	res[0] = -1;
	oper[0] = '@';
	for(int it = 0; s[it]; ){
		if(s[it] == '^' || s[it] == '_'){
			oper[top] = s[it];
			op1[top] = -1;
			op2[top] = -1;
			top++;
			res[top] = -1;
			oper[top] = '@';
			it+=2;
		}else{
			if(s[it] >= '0' && s[it] <= '9'){
				if(res[top] == -1){
					res[top] = s[it] - '0';
					if(res[top] == 0)
						calc();
				}
				else{
					res[top] = res[top] * 10 + (s[it] - '0');
					calc();
				}
			}else
				calc();
			int S = calc_min();
			int E = calc_max();
			if(S==E){
				printf("%d %d\n",S, it+1);
				return;
			}
			it++;
		}
	}
}
int main(){
	int _;
	for(scanf("%d",&_); _--;){
		scanf("%s",s);
		process();
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
int main(){
    int q, sty, a;
    cin >> q;
    vector<int> vec;
    for(int i=0;i<q;i++){
        cin >> sty;
        if(sty == 0){
            cin >> a;
            vec.push_back(a);
        }else if(sty == 1){
            cin >> a;
            cout << vec[a] << endl;
        }else{
            vec.pop_back();   
        }
    }
}


Measured memory_bytes: 3856
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
#include<cstdio>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N,K; cin >> N >> K;
    vector<Pi> dt(N);
    map<int,int> mp;
    priority_queue<int,vector<int>,greater<int>> q;
    set<int> s;
    rep(i,N){
        cin >> dt[i].second >> dt[i].first;
    }
    sort(dt.rbegin(),dt.rend());
    ll now = 0;
    ll ans = 0;
    rep(i,K){
        now += dt[i].first;
        s.insert(dt[i].second);
        mp[dt[i].second]++;
        if(mp[dt[i].second] >= 2) q.push(dt[i].first);
    }
    int m = s.size();
    ans = now+(ll)m*m;
    int cnt = 0;
    repr(i,K,N){
        if(mp[dt[i].second] == 0){
            if(!q.empty()){
                int u = q.top();
                q.pop();
                now -= u;
                now += dt[i].first;
                cnt++;
                mp[dt[i].second]++;
                ans = max(ans,now+(ll)(m+cnt)*(m+cnt));
            }
        }
    }
    cout << ans << endl;

}

Measured memory_bytes: 8064
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <bitset>
#include <set>
using namespace std;


int N, K, Q;
vector<int> A;

int solve(int idx){
    int mn = A[idx];
    vector<vector<int>> v;
    vector<int> cur;
    for(int i=1; i<=N; i++){
        if(A[i] < mn){
            if(!cur.empty()){
                v.push_back(cur);
                cur.clear();
            }
        }else{
            cur.push_back(A[i]);
        }
    }
    if(!cur.empty())
        v.push_back(cur);

    vector<int> vv;
    for(auto x : v){
        if(x.size() < K) continue;
        sort(x.begin(), x.end());
        for(int i=0; i<=x.size()-K; i++){
            vv.push_back(x[i]);
        }
    }
    if(vv.size() < Q)
        return 1<<30;
    sort(vv.begin(), vv.end());
    return vv[Q-1] - vv[0];
}

int main(){
    cin >> N >> K >> Q;
    A.resize(N+2, 0);
    for(int i=1; i<=N; i++)
        cin >> A[i];

    int ans = 1<<30;
    for(int i=1; i<=N; i++)
        ans = min(ans, solve(i));
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
N = gets.to_i
pos = []
N.times do
  pos << gets.split.map(&:to_i)
end
diffs = []

N.times do |i|
  N.times do |j|
    x = pos[i][0]-pos[j][0]
    y = pos[i][1]-pos[j][1]
    diffs << [x,y] if x != 0 || y != 0
  end
end

diffs.sort!
c,mc = 1,1
prev = [0,0]
diffs.each do |a|
  if prev == a
    c += 1
  else
    mc = c if c > mc
    c = 1
  end
  prev = a
end
#p diffs
p N==1 ? 1 : N-mc

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

//Function Macros:
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define all(v) (v).begin(), (v).end()
#define setpre(n) cout << fixed << setprecision(n)

//Type / Class / Struct Definitions:
using ll = long long;
using ull = unsigned long long;

//Constants:
const int INF = (1ll << 30) - 1;  //nearly 1.07e9
const ll INFLL = 1ll << 60;       //nearly 1.15e18
const int MOD = 1e9 + 7;
const long double EPS = 1.0e-14;

//Global Variables:

//Prototype Declarations:
int gcd(int, int);
template <class T>
inline bool chmin(T&, T);
template <class T>
inline bool chmax(T&, T);

//================ Main Loop ================
int main() {
    int n, x, y;
    cin >> n >> x >> y;

    x--;
    y--;
    //cout << n << endl;
    vector<int> ans(n, 0);
    rep(i, n - 1) {
        for(int j = i + 1; j < n; j++) {
            int dist = j - i;
            if(i <= x && j >= y) {
                dist = j - i - (y - x) + 1;
            } else {
                chmin(dist, abs(x - i) + abs(y - j) + 1);
            }
            //dbg
            //cout << i + 1 << ", " << j + 1 << " : " << dist << endl;
            dist--;
            ans[dist]++;
        }
    }

    rep(k, n - 1) {
        cout << ans[k] << endl;
    }
    return 0;
}
//===========================================

//Functions:
int gcd(int a, int b) {
    return b ? gcd(b, a % b) : a;
}

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


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();
		ArrayList<Integer> a = new ArrayList<>(n);
		int i;
		for(i = 0; i < n; i++) {
			a.add(sc.nextInt());
		}
		sc = null;
		int min, amari;
		min = Collections.min(a);
		while(true) {
			ArrayList<Integer> b = new ArrayList<>();
			for(i = 0; i < n; i++) {
				amari = a.get(i) % min;
				if(amari > 0) b.add(amari);
			}
			if(b.size() == 0) break;
			min = Collections.min(b);
			b = null;
		}
		System.out.println(min);
	}

}


Measured memory_bytes: 60356
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
typedef pair<int,int> P;
using vi=vector<long long>;
using vvi=vector<vector<long long>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const int inf=1000000009;
void chmin(auto &a,auto b){if(b<a)a=b;}
void chmax(auto &a,auto b){if(a<b)a=b;}

int main(){
  ll n,m,sum=0;cin>>n>>m;
  priority_queue<ll> a;
  rep(i,n){
    ll c;
    cin>>c;
    a.push(c);
  }
  rep(i,m){
    ll k=a.top();
    k/=2;
    a.pop();
    a.push(k);
  }
  while(!a.empty()){
    sum+=a.top();
    a.pop();
  }
  cout<<sum<<endl;
}


Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b;
    cin>>a>>b;
    if(a==1 && b==2) cout<<3<<endl;
    else if(a==1 && b==3) cout<<2<<endl;
    else if(a==2 && b==3) cout<<1<<endl;
    else if(a==2 && b==1) cout<<3<<endl;
     else if(a==3 && b==1) cout<<2<<endl;
     else if(a==3 && b==2) cout<<1<<endl;
return 0;
}
  


Measured memory_bytes: 256
import queue
while 1:
    l_string = input()
    if l_string == '-':
        break
    list(l_string)
    q = queue.Queue()
    string = ''
    for j in range(len(l_string)):
        q.put(l_string[j])
    m = int(input())
    for i in range(m):
        h = int(input())
        for k in range(h):
            q.put(q.get())
    for k in range(len(l_string)):
        string += q.get()
    print(string)





Measured memory_bytes: 6832
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	int A,B,C,K,R;
	R = 0;
	cin >> A >> B >> C >> K;
	for (int i=0; i<K; i++){
		if (B <= A){
			B = B * 2;
		}
		else if (C <= B){
			C = C * 2;
		}
		else {
			R = 1;
		}
	}
	
	if (A < B && B < C) {
		R = 1;
	}
	
	if (R == 1){
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}
}

Measured memory_bytes: 3632
import sys
import heapq
from collections import defaultdict
input = sys.stdin.buffer.readline
sys.setrecursionlimit(10 ** 7)

N, Q = map(int, input().split())
task = []
for _ in range(N):
    s, t, x = map(int, input().split())
    start = t - x
    end = s - x
    task.append((start, -1, x))
    task.append((end, 1, x))
task.sort(reverse=True)

cand = []
discard = defaultdict(int)
ans = []

for _ in range(Q):
    d = int(input())
    while task and task[-1][0] <= d:
        _, flag, x = task.pop()
        if flag == 1:
            heapq.heappush(cand, x)
        else:
            discard[x] += 1

    while cand:
        x = cand[0]
        if discard[x] > 0:
            heapq.heappop(cand)
            discard[x] -= 1
        else:
            break

    if cand:
        ans.append(cand[0])
    else:
        ans.append(-1)

print(*ans, sep="\n")

Measured memory_bytes: 74364
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
typedef pair<int,int> P;

int main() {
  int n,m;
  cin >> n >> m;
  P a[m];
  for(int i=0; i<m; i++) cin >> a[i].F >> a[i].S;
  sort(a,a+m);
  P dp[n];
  for(int i=0; i<n; i++) dp[i]=P(i,i);
  for(int i=0; i<m; i++) {
    dp[a[i].S-1].F=min(dp[a[i].S-1].F,dp[a[i].S].F);
    dp[a[i].S-1].S=max(dp[a[i].S-1].S,dp[a[i].S].S);
    dp[a[i].S].F=min(dp[a[i].S].F,dp[a[i].S-1].F);
    dp[a[i].S].S=max(dp[a[i].S].S,dp[a[i].S-1].S);
  }
  for(int i=0; i<n; i++) {
    if(i) cout << " ";
    cout << dp[i].S-dp[i].F+1;
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 5428
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while(in.hasNext()){
            int n = in.nextInt();
            int k = in.nextInt();
            if(n % 2 == 0){
                n = n / 2;
            }else{
                n = n / 2 + 1;
            }
            if(n >= k){
                System.out.println("YES");
            }else{
                System.out.println("NO");
            }
        }
    }
}

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

int main() {
  ll n, k;
  cin >> n >> k;
  ll ar[n+1];
  for(ll x = 1; x <= n; x++) {
    cin >> ar[x];
  }

  ll dp[n+1];
  dp[1] = 0;
  dp[2] = abs(ar[2]-ar[1]);
  for(ll x = 3; x <= n; x++) {
    ll r = INT_MAX;
    for(ll y = x-1; y >= max(x-k, (ll)1); y--) {
      r = min(r, dp[y] + abs(ar[x] - ar[y]));
    }
    dp[x] = r;
  }

  cout << dp[n];
}

Measured memory_bytes: 5104
import sys
input=sys.stdin.readline
n,m,k=map(int,input().split())
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x

    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
uf=UnionFind(n)
friends=[[] for _ in range(n)]
blocks=[[] for _ in range(n)]
root=dict()
for i in range(m):
  a,b=map(int,input().split())
  uf.union(a-1,b-1)
  friends[a-1].append(b-1)
  friends[b-1].append(a-1)
lis=uf.roots()
for i in lis:
  size=uf.size(i)
  root[i]=size-1
for i in range(k):
  c,d=map(int,input().split())
  if uf.same(c-1,d-1):
    blocks[c-1].append(d-1)
    blocks[d-1].append(c-1)
ans=[]
for i in range(n):
  ans.append(root[uf.find(i)]-len(blocks[i])-len(friends[i]))
print(*ans)

Measured memory_bytes: 112688
X = int(input())
if X == 2:
  print(2)
  exit()

num = 3
ps = [2]
while 1:
  flag = True
  for p in ps:
    if num%p == 0:
      flag = False
      break
  if flag:
    ps.append(num)
    if num>=X:
      print(num)
      exit()
  num += 2

Measured memory_bytes: 42704
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <utility>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <istream>
#include <ostream>

#include <cstdlib>
#include <cmath>
#include <cstdio>

using namespace std;

#define fi first
#define se second
#define mkp make_pair
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define rep(i,n) for(ll i=0; i < (n); ++i)
#define rrep(i,n) for(ll i=((n)-1); i >= 0; --i)

#define OPLT(T) bool operator<(const T & lop_, const T & rop_)
#define OPEQ(T) bool operator==(const T & lop_, const T & rop_)

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

int main() {
	int N;
	cin >> N;
	vector<int> D(N);
	rep(i,N) cin >> D[i];

	int cnt[20] = {1};
	int res = -1;
	rep(i,N) {
		cnt[D[i]]++;
		if( ((D[i]==0||D[i]==12)&&cnt[D[i]]>=2) || cnt[D[i]] >= 3) {
			res = 0;
		}
	}
	if(res) {
		for(int i = 0; i < (1<<11); i++) {
			vector<int> t;
			if(cnt[0]) t.push_back(0);
			if(cnt[12]) t.push_back(12);

			for(int j = 0; j < 11; j++) {
				if(cnt[j+1] == 2) {
					t.push_back(j+1);
					t.push_back(24-(j+1));
				}
				else if(cnt[j+1] == 1) {
					if(i&(1<<j))
						t.push_back(j+1);
					else
						t.push_back(24-(j+1));
				}
			}
			sort(all(t));
			t.push_back(24);
			int mn = 24;
			for(int j = 1; j < t.size(); j++) {
				mn = min(mn, t[j]-t[j-1]);
			}
			res = max(res, mn);
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <ctime>
#define INF 1000000000
#define LINF 9000000000000000000
#define mod 1000000007
 
#define rep(i,n) for(int i=0;i<int(n);i++)
#define rrep(i,n) for(int i=(n);i>=0;i--)
#define REP(i,a,b) for(int i=(a);i<int(b);i++)
#define all(x) (x).begin(),x.end()
#define rsort(x) sort(all(x));reverse(all(x))
#define pb push_back
#define mp make_pair
#define MOD(x) (x%(mod))
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;
 
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};
 
bool debug=false;
/*---------------------------------------------------*/

int main(){
  double a,b,c,d,e,f;
  pi ans;
  double n=0;
  bool ok=false;
  cin>>a>>b>>c>>d>>e>>f;
  for(int i=1;i<=30;i++){
    for(int j=0;j<=30;j++){
      if((i*a+j*b)*100>=f)continue;
      for(int k=0;k<=3000;k++){
	for(int l=0;l<=3000;l++){
	  if((i+j)*100+k*c+l*d>f)continue;
	  //cout<<"濃度"<<" "<<((100*(k*c+l*d))/((i*a+j*b)*100+k*c+l*d))<<endl;
	  if((i*a+j*b)*100+k*c+l*d<=f&&n<=((100*(k*c+l*d))/((i*a+j*b)*100+k*c+l*d))&&(k*c+l*d)/((i*a+j*b)*100)<=e/100){
	    n=((100*(k*c+l*d))/((i*a+j*b)*100+k*c+l*d));
	    ans.first=(a*i+b*j)*100+(k*c+l*d);
	    ans.second=(k*c+l*d);
	  }
	}
      }
    }
  }
  cout<<ans.first<<" "<<ans.second<<endl;
  return 0;
}


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

#define ll long long
#define mx  200005
#define mod 1000000009
#define lim 10000000
#define N 18
using namespace std;

pair<ll,ll>L[mx],R[mx];

int main(){
	ios_base::sync_with_stdio(false);
	int n;cin>>n;
	int a[n+5];

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

	ll l1=0,l2=0,r1=0,r2=0;int j=0;

	for(int i=0;i<n;i++)
	{
		l1+=1LL*a[i];
		while(j<=i && abs(l1-l2)>=abs(l1-a[j]-l2-a[j]))
			{
				l1-=a[j],l2+=1LL*a[j];j++;
			}
		L[i]={l1,l2};
	}
	j=n-1;
	for(int i=n-1;i>=0;i--)
	{
		r1+=1LL*a[i];
		while(j>=i && abs(r1-r2)>=abs(r1-a[j]-r2-a[j]))
		{
			r1-=a[j],r2+=1LL*a[j];j--;
		}
		R[i]={r1,r2};
	}
	ll ans=1e16;
	for(int i=1;i<n-2;i++)
	{
		ll v[]={L[i].first,L[i].second,R[i+1].first,R[i+1].second};
		sort(v,v+4);
		ans=min(ans,v[3]-v[0]);
	}
	cout<<ans<<"\n";
     return 0;
}


Measured memory_bytes: 7296
import java.io.IOException;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;
import java.util.PriorityQueue;
import java.util.Scanner;

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

		while(true){
			final int N = sc.nextInt();
			
			if(N == 0){
				break;
			}
			
			int[][] costs = new int[N][N + 1];
			
			for(int i = 0; i < N; i++){
				for(int j = 0; j <= N; j++){
					costs[i][j] = sc.nextInt();
				}
			}
			
			int[] bit = new int[1 << N];
			
			bit[0] = 0;
			for(int i = 1; i < bit.length; i++){
				bit[i] = Integer.MAX_VALUE;
			}
			
			
			for(int itr = 0; itr < N; itr++){
				//System.out.println(Arrays.toString(bit));
				
				for(int pos = bit.length - 1; pos >= 0; pos--){
					if(bit[pos] < Integer.MAX_VALUE){
						for(int flag = 0; flag <= N; flag++){
							if(flag == 0){
								
							}else if((pos & (1 << (flag - 1))) == 0){
								continue;
							}
							
							for(int stage = 0; stage < N; stage++){
								bit[pos | (1 << stage)] = Math.min(bit[pos | (1 << stage)], bit[pos] + costs[stage][flag]);
							}
							
						}
					}
				}
			}
			//System.out.println(Arrays.toString(bit));
			
			System.out.println(bit[(1 << N) - 1]);
			
		}
		
		
	}

}

Measured memory_bytes: 12000
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

const int MX = 100;
const int INF = INT_MAX / 2;

vector<vector<vector<int>>> dp;

void solve(const int A, const int B, const int C) {
    // {steps, a, b, c}
    queue<tuple<int, int, int, int>> que;
    dp[A][B][C] = 0;
    que.push(make_tuple(0, A, B, C));

    const vector<tuple<int, int, int>> diffs = {
        make_tuple(2, 0, 0),
        make_tuple(0, 2, 0),
        make_tuple(0, 0, 2),
        make_tuple(1, 1, 0),
        make_tuple(1, 0, 1),
        make_tuple(0, 1, 1),
    };

    while (!que.empty()) {
        auto elem = que.front();
        que.pop();
        int cur_steps, cur_a, cur_b, cur_c;
        tie(cur_steps, cur_a, cur_b, cur_c) = elem;
        // printf("cur_steps: %d, cur_a: %d, cur_b: %d, cur_c: %d\n",
        //         cur_steps, cur_a, cur_b, cur_c);

        for (auto &diff : diffs) {
            int diff_a, diff_b, diff_c;
            tie(diff_a, diff_b, diff_c) = diff;

            int next_steps = cur_steps + 1;
            int next_a = cur_a + diff_a;
            int next_b = cur_b + diff_b;
            int next_c = cur_c + diff_c;

            if (next_a >= MX || next_b >= MX || next_c >= MX) {
                continue;
            }

            if (next_steps < dp[next_a][next_b][next_c]) {
                dp[next_a][next_b][next_c] = next_steps;
                que.push(make_tuple(next_steps, next_a, next_b, next_c));
            }
        }
    }
}

// bfs
int main(void) {
    int A, B, C;
    cin >> A >> B >> C;

    dp.resize(MX);
    for (int i = 0; i < MX; i++) {
        dp[i].resize(MX);
        for (int j = 0; j < MX; j++) {
            dp[i][j].resize(MX, INF);
        }
    }

    solve(A, B, C);

    int ans = INF;
    for (int i = max({A, B, C}); i < MX; i++) {
        chmin(ans, dp[i][i][i]);
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 7932
function main(input){
    var l = input.split('\n')[1].split(' ').map((n)=>Number.parseInt(n,10));
    var sum = l.reduce((a,b) => a + b );
    var max = Math.max(...l);
    console.log( max < sum-max ? 'Yes' : 'No');
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 11468
import math
import itertools
from heapq import heapify, heappop, heappush
from sys import stdin, stdout, setrecursionlimit
from bisect import bisect, bisect_left, bisect_right
from collections import defaultdict, deque


# d = defaultdict(lambda: 0)
# setrecursionlimit(10**7)
# inf = float("inf")


##### stdin ####
def LM(t, r): return list(map(t, r))
def R(): return stdin.readline()
def RS(): return R().split()
def I(): return int(R())
def F(): return float(R())
def LI(): return LM(int,RS())
def LF(): return LM(float,RS())
def ONE_SL(): return list(input())
def ONE_IL(): return LM(int, ONE_SL())
def ALL_IL(): return LM(int,stdin)

##### tools #####
def ap(f): return f.append
def pll(li): print('\n'.join(LM(str,li)))
def pljoin(li, s): print(s.join(li))



##### main #####
def main():

	S = input()
	
	if S == 'zyxwvutsrqponmlkjihgfedcba':
		print(-1)
		exit()

	set_al = set([chr(i) for i in range(97,123)])
	set_s = set(S)

	if len(S) != len(set_s):
		print("-1")

	availables = sorted(list(set_al - set_s), reverse = True)

	if availables:
		print(S+str(availables[-1]))
	else:
		f = False
		for i in range(len(S))[::-1]:
			chr_n = ord(S[i])

			while chr_n <= 122:
				if chr(chr_n) not in S:
					S = S[:-1]
					S += chr(chr_n)
					f = True
					break
				chr_n += 1

			if f:
				break
			S = S[:-1]

		print(S)


if __name__ == '__main__':
  main()

Measured memory_bytes: 3572
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func main() {
	buf := make([]byte, 1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)

	n := nextInt()
	k := nextInt()
	q := nextInt()

	a := make([]int, q)
	for i := 0; i < q; i++ {
		a[i] = nextInt() - 1
	}

	r := solve(n, k, q, a)
	for _, x := range r {
		if x {
			fmt.Println("Yes")
		} else {
			fmt.Println("No")
		}
	}
}

func solve(n, k, q int, a []int) []bool {
	cnt := make([]int, n)

	for _, x := range a {
		cnt[x]++
	}

	r := make([]bool, n)
	for i := 0; i < n; i++ {
		if k-q+cnt[i] > 0 {
			r[i] = true
		} else {
			r[i] = false
		}
	}

	return r
}


Measured memory_bytes: 4740
#include <iostream>
#include <map>
#include <queue>
#include <cmath>
#include <vector>
#include <iostream>
#include <algorithm>
#include <functional>
using namespace std;
#pragma warning (disable: 4996)

int main() {
	int r;
	cin >> r;
	cout << r * r << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main {
	public static void main(String[] args){
		Scanner scanner = new Scanner(System.in);
		String s = scanner.nextLine();
		long length = s.length();
		scanner.close();
		long sum = 0;
		for(int i=0;i<length;i++){
			long left = (long) Math.ceil(Math.pow(2, i-1));
			for(int j=i+1;j<length+1;j++){
				sum += (long) left * Long.valueOf(s.substring(i, j))* Math.ceil(Math.pow(2, length - j - 1));
			}
		}
		System.out.println(sum);
	}
}


Measured memory_bytes: 9680
#include "bits/stdc++.h"
#define rep(i,a,n) for(int i = (a);i < (n);i++)
typedef unsigned long long ull;
typedef long long ll;
using namespace std;

int main(){
    int memo,ans=10000,h,w;
    cin >> h >> w;
    char cells[h][w];
    
    rep(i,0,h){
        rep(j,0,w){
            cin >> cells[i][j];
        }
    }
    
    rep(i,0,h-2){
        rep(j,i+1,h-1){
            memo = 0;
            rep(k,0,h){
                rep(l,0,w){
                    if(k <= i && cells[k][l] != 'W'){
                        memo++;
                    }
                    else if(k > i && k <= j && cells[k][l] != 'B' ){
                        memo++;
                    }
                    else if(k > j && cells[k][l] != 'R'){
                        memo++;
                    }
                }
            }
            ans = min(ans,memo);
        }
        
    }
    
    cout << ans << endl;
    
    
    return 0;   
}


Measured memory_bytes: 3100
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define MAX 2000000
#define INFTY (1<<30)
int h, a[MAX + 1];
void maxHeapify(int i) {
	int l, r, largest;
	l = 2 * i;
	r = 2 * i + 1;
	if (l <= h&&a[l] > a[i])largest = l;
	else largest = i;
	if (r <= h&&a[r] > a[largest])largest = r;
	if (largest != i) {
		swap(a[i], a[largest]);
		maxHeapify(largest);
	}
}
int extract() {
	int maxv;
	if (h < 1)return -INFTY;
	maxv = a[1];
	a[1] = a[h--];
	maxHeapify(1);
	return maxv;
}
void increaseKey(int i, int key) {
	if (key < a[i])return;
	a[i] = key;
	while (i > 1 && a[i / 2] < a[i]) {
		swap(a[i], a[i / 2]);
		i = i / 2;
	}
}
void insert(int key) {
	h++;
	a[h] = -INFTY;
	increaseKey(h, key);
}
int main() {
	int key;
	string com;
	while (1) {
		cin >> com;
		if (com[0] == 'e'&&com[1] == 'n')break;
		if (com[0] == 'i') {
			cin >> key;
			insert(key);
		}
		else {
			cout << extract() << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 7044
/*
ID: thanhvq1
LANG: C++14
PROB: namenum
*/

#pragma GCC optimize ("O2")
#include<bits/stdc++.h>
#include<unistd.h>
using namespace std;
//#define int long long
#define double long double
#define vec vector
#define vi vector<int>
#define vvi vector<vector<int>>
#define FZ(n) memset((n),0,sizeof())
#define FMO(n) memset((n),-1,sizeof(n))
#define unset unordered_set
#define ii pair<int, int>
#define vii vector<ii>
#define F first
#define S second
#define PB push_back
#define ALL(x) begin(x),end(x)
#define SZ(x) ((int)(x).size())
#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define FORE(i, a, b) for(int i = (a); i <= (b); i++)
#define FORD(i, a, b) for(int i = (a); i >= (b); i--)
#define bitcount(n) __builtin_popcountll(n)
template <typename T,typename U>
std::pair<T,U> operator+(const std::pair<T,U> & l,const std::pair<T,U> & r) {
  return {l.first+r.first, l.second+r.second};
}
typedef void (*callback_function)(void); // type for conciseness
const long long ZERO = 0LL;
const long long INF64 = 1e18;
const int INF32 = 1e9;
const int MOD = 1e9 + 7;
const double PI = acos(-1.0L);
const double EPS = static_cast<double>(1e-9);
typedef long long ll;

void FILEIO() {  freopen("in.txt", "r", stdin);  freopen("out.txt", "w", stdout); }
//void FILEIO() {  freopen("namenum.in", "r", stdin);  freopen("namenum.out", "w", stdout); }
void input() {   }

// global parameters here:

void solve() {
	int n, l; cin >> n >> l;
	vi a(n+1); FORE(i, 1, n) a[i] = l+i-1;
	int sum = 0;
	FORE(i, 1, n) sum += a[i];
	int minV = INT_MAX, ans;
	FORE(i, 1, n) {
		int k = (int)abs(a[i]);
		if(k <minV) {minV =k; ans = sum - a[i];}
	}
	cout << ans << endl;
}

//#undef int
signed main() {
//#define int long long
  ios_base::sync_with_stdio(false); cin.tie();
//  FILEIO();
//auto beginProgram = chrono::steady_clock::now();

// int t; cin >> t;
//  while(t--)
//  {
//	  cout << aa << ", " << bb << endl;
		solve();
//  }

  //auto endProgram = chrono::steady_clock::now();

  return 0;
}


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

namespace Algorithm
{
    class Program
    {
        static void Main(string[] args)
        {
            var s = Console.ReadLine();
            s = s.Substring(0, s.Length - 1);
            var orgLen = s.Length;

            var len = 0;
            for (var i = 0; i < orgLen; i++)
            {
                if (s.Length % 2 == 0)
                {
                    var halfLen = s.Length / 2;
                    if (s.Substring(0, halfLen) == s.Substring(halfLen,s.Length-halfLen))
                    {
                        len = s.Length;
                        break;
                    }
                }

                s = s.Substring(0, s.Length - 1);
            }

            Console.WriteLine(len);
        }
    }
}


Measured memory_bytes: 11092
s=input()
n=len(s)
f=0
for i in range(1<<n-1):
    a=s[0]
    for j in range(n-1):

        if i&(1<<j):
            
            a+='+'+s[j+1]
        else:
            a+=s[j+1]
    f+=eval(a)
print(f)


Measured memory_bytes: 2940
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>
#include <tuple>
#include <queue>
#include <bitset>
#include <set>
#include <map>
#include <list>

using ll = long long;
using ld = long double;
using namespace std;
const int INF = 1e9+100;
const ll INF64 = 7e18l;
const int mod = 1000000007;
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define ALL(a) (a).begin(), (a).end()
#define FIN ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


int main(){
    FIN;
    ll a,b;
    cin >> a >> b;
    cout << a * b << endl;


    return 0;
}



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

int main()
{
    int n,m,c;
    cin >> n >> m >> c;
    vector<int> b(m);
    for(int i=0; i<m; i++) cin >> b[i];
    int ans = 0;
    for(int i=0; i<n; i++){
        int tmp = c;
        int a = 0;
        for(int j=0; j<m; j++){
            cin >> a;
            tmp += a * b[j];
        }
        if(tmp > 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


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

#define DEBUG(x) cerr << #x << ": " << x << endl;
#define ll long long

int main() {
    int N; // 行
    int M; // 列
    int K; // 黒の個数
    cin >> N >> M >> K;

    /* 全探索できるループ
    for (int i = 0; i <= N; i++) {
        for (int j = 0; j <= M; j++) {
            cout << "i: " << i << ", j: " << j << endl;
        }
    }
    */

    for (int i = 0; i <= N; i++) {
        //cout << "i * (M - j) + (N - i) * j" << endl;
        for (int j = 0; j <= M; j++) {
            //int ans = i * (M - j) + (N - i) * j;
            //int ans = i * (M - j) + j * (N - i);
            int ans = (M * i) + (N * j) - 2 * (i * j);
            //cout << i << " * (" << M << " - " << j << ") + (" << N << " - " << i << ") * " << j << endl;
            //cout << i << " * (  " << M - j << "  ) + (  " << N - i << "  ) * " << j << endl;
            if ( ans == K ) {
                /*
                cout << "i * (M - j) + (N - i) * j" << endl;
                cout << i << " * (" << M << " - " << j << ") + (" << N << " - " << i << ") * " << j << endl;
                cout << i << " * (  " << M - j << "  ) + (  " << N - i << "  ) * " << j << endl;
                */
                cout << "Yes" << endl;
                return 0;
            }
        }
        //cout << endl;
    }

    cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 384
import math
N = int(input())
H = [list(map(int, input().split())) for i in range(N)]
P = [[0, 2*math.pi] for i in range(N)]
for i in range(N):
    for j in range(N):
        if i==j:
            continue
        rad = math.atan2(H[i][1]-H[j][1], H[i][0]-H[j][0])
        mi = (rad - math.pi/2) % (2*math.pi)
        ma = (rad + math.pi/2) % (2*math.pi)
        if ma > mi:
            if P[i][0] >= P[i][1]:
                if mi < P[i][1]:
                    P[i] = [mi, P[i][1]]
                elif ma > P[i][0]:
                    P[i] = [P[i][0], ma]
                else:
                    P[i] = [0, 0]
                    break
            else:
                P[i] = [max(P[i][0], mi), min(P[i][1], ma)]
                if P[i][0] >= P[i][1]:
                    P[i] = [0, 0]
                    break
        else:
            if P[i][0] >= P[i][1]:
                P[i] = [max(P[i][0], mi), min(P[i][1], ma)]
            elif P[i] == [0, 2*math.pi]:
                P[i] = [mi, ma]
            else:
                if mi < P[i][1]:
                    if mi < P[i][0]:
                        continue
                    else:
                        P[i] = [mi, P[i][1]]
                elif ma > P[i][0]:
                    if ma > P[i][1]:
                        continue
                    else:
                        P[i] = [P[i][0], ma]
                else:
                    P[i] = [0, 0]
                    break
for p in P:
    print((p[1]-p[0]) / (2*math.pi) % 1)


Measured memory_bytes: 3316
#include <iostream>
#include <algorithm>
#include <string>
#include <numeric>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define MAX 1000000007

using namespace std;


int main(void){
	int n;
	cin>>n;
	int a[n+1],b[n];
	rep(i,n+1)cin>>a[i];
	rep(i,n)cin>>b[i];

	ll cnt=0;
	rep(i,n){
		if(a[i]>=b[i]){
			cnt+=b[i];
			b[i]=0;
		}
		else{
			b[i]-=a[i];
			cnt+=a[i];
		}
		if(a[i+1]>=b[i]){
			cnt+=b[i];
			a[i+1]-=b[i];
		}
		else{
			cnt+=a[i+1];
			a[i+1]=0;
		}
	}

	cout<<cnt<<endl;

	return 0;

}


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include<algorithm>
#include <vector>
#include<stack>
#include<queue>
#include<list>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
#define modulo 1000000007 // 10^9 + 7
#define MAX 1000000000 // 10^9


int main() {
	int N, M;
	cin >> N >> M;

	int T = 1900 * M + 100 * (N - M);

	int ans = T;
	for (int i = 0; i < M; i++) ans *= 2;

	cout << ans << endl;

	return 0;
}

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

#define mp make_pair
#define fst first
#define snd second
#define forn(i,n) for (int i = 0; i < int(n); i++)
#define forn1(i,n) for (int i = 1; i <= int(n); i++)
#define popcnt __builtin_popcount

using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

template <typename T> T id(T b) {return b;};
template <class It> bool all(It f,It l){return std::all_of(f,l,id<bool>);}
template <class It> bool any(It f,It l){return std::any_of(f,l,id<bool>);}
template <typename T> void chmax(T &x, T y) {if (x < y) x = y;}
template <typename T> void chmin(T &x, T y) {if (x > y) x = y;}

int main()
{
#ifdef FASTIO
  ios_base::sync_with_stdio(false); cin.tie(nullptr);
#endif

  int n,k;

  cin >> n >> k;

  if (k > 1)
    cout << n - k << endl;
  else
    cout << 0 << endl;

  return 0;
}


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

int main()
{
    string S;
    cin >> S;
    int ans = S.size();
    for (int i = 0; i < 2; i++) {
        int cnt = 0;
        for (int j = 0; j < S.size(); j++) {
            if ((j % 2 == 0) && S[j] != (char)(i + '0'))  cnt++;
            if ((j % 2 == 1) && S[j] == (char)(i + '0'))  cnt++;
        }
        ans = min(ans, cnt);
    }
    cout << ans << endl;
    return (0);
}

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

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


Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=1149&lang=jp
//Problem C: ケーキカット
#include <bits/stdc++.h>
#if LOCAL
#include "dump.hpp"
#else
#define dump(...)
#endif
using namespace std;
using ll=long long;
const ll LINF = 0x1fffffffffffffff;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
template<class T>bool chmax(T &a, const T &b) {if (a<b) { a=b; return 1; } return 0;}
template<class T>bool chmin(T &a, const T &b) {if (b<a) { a=b; return 1; } return 0;}
int solve(){
  ll n,w,d; cin>>n>>w>>d;
  if(n==0&&w==0) return 0;
  struct info{
    info()=default;
    info(ll iw,ll id)
      :w(iw)
      ,d(id)
    {
      s=w*d;
    }
    ll w,d;
    ll s;
  };
  vector<info> infos;
  infos.emplace_back(w,d);
  REP(i,n){
    ll p,s; cin>>p>>s;
    --p;
    auto tmp=infos.at(p);
    infos.erase(infos.begin()+p);
    //わける
    auto cut_tate =[&](ll x){
      ll x0=tmp.w-x;
      assert(x0>0);
      ll x1=x;
      if(x0<x1)swap(x0,x1);
      infos.emplace_back(x1,tmp.d);
      infos.emplace_back(x0,tmp.d);
    };
    auto cut_yoko = [&](ll y){
      ll y0=tmp.d-y;
      assert(y0>0);
      ll y1=y;
      if(y0<y1)swap(y0,y1);
      infos.emplace_back(tmp.w,y1);
      infos.emplace_back(tmp.w,y0);
    };

    do{
      ll sss = s % (tmp.w+tmp.d);
      if(sss<tmp.w){
        cut_tate(sss);
        break;
      }
      sss-=tmp.w;
      if(sss<tmp.d){
        cut_yoko(sss);
        break;
      }
      sss-=tmp.d;
    }while(false);
    assert(infos.size()==i+2);
  }
  sort(infos.begin(),infos.end(),[](auto&a,auto&b){ return a.s < b.s;});
  FOR(i,0,infos.size()){
    if(i!=0)cout<<" ";
    cout<<infos.at(i).s;
  }
  cout<<endl;
  return 1;  
}
int main() {
#if LOCAL&01
  //std::ifstream in("./test/sample-1.in");
  std::ifstream in("./input.txt");
  std::cin.rdbuf(in.rdbuf());
#else
  cin.tie(0);
  ios::sync_with_stdio(false);
#endif
  while(solve()!=0){
  }
  return 0;
}


Measured memory_bytes: 3012
#include <CodeforcesSolutions.h>
#include <ONLINE_JUDGE <solution.cf(contestID = "1359",problemID = "C",method = "GET")>.h>
"""
    Author : thekushalghosh
    Team   : CodeDiggers
 
    I prefer Python language over the C++ language :p :D
        
    Visit my website : thekushalghosh.github.io
"""
import sys,math,cmath,time
start_time = time.time()
##########################################################################
################# ---- THE ACTUAL CODE STARTS BELOW ---- #################
    
def solve():
    a,b = invr()
    print(a * b)
                
################## ---- THE ACTUAL CODE ENDS ABOVE ---- ##################
##########################################################################
 
def main():
    global tt
    if not ONLINE_JUDGE:
        sys.stdin = open("input.txt","r")
        sys.stdout = open("output.txt","w")
    t = 1
    for tt in range(t):
        solve()
    if not ONLINE_JUDGE:
        print("Time Elapsed :",time.time() - start_time,"seconds")
    sys.stdout.close()
    
#---------------------- USER DEFINED INPUT FUNCTIONS ----------------------#
def inp():
    return(int(input()))
def inlt():
    return(list(map(int,input().split())))
def insr():
    return(input().strip())
def invr():
    return(map(int,input().split()))

#------------------ USER DEFINED PROGRAMMING FUNCTIONS ------------------#
def counter(a):
    q = [0] * max(a)
    for i in range(len(a)):
        q[a[i] - 1] = q[a[i] - 1] + 1
    return(q)
 
def string_counter(a):
    q = [0] * 26
    for i in range(len(a)):
        q[ord(a[i]) - 97] = q[ord(a[i]) - 97] + 1
    return(q)

ONLINE_JUDGE = __debug__
if ONLINE_JUDGE:
    input = sys.stdin.readline
    
main()


Measured memory_bytes: 62504
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return i
}

func main() {

	sc.Split(bufio.ScanWords)
	n, a, b := nextInt(), nextInt(), nextInt()

	if a == 0 {
		fmt.Print(0)
		return
	}

	sum := a + b
	blue, mod := (n / sum * a), n%sum

	if mod > a {
		fmt.Print(blue + a)
	} else {
		fmt.Print(blue + mod)
	}
}


Measured memory_bytes: 640
import java.util.*;

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

    String ans = Integer.toString(n,k);
    
    System.out.println(ans.length());
    
  }
}


Measured memory_bytes: 21844
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  vector<int> c(N - 1), s(N - 1), f(N - 1);
  rep(i, N - 1) cin >> c[i] >> s[i] >> f[i];

  for (int i = 0; i < N - 1; ++i){
    int now = s[i] + c[i];
    for (int j = i + 1; j < N - 1; ++j){
      if (now >= s[j]){
        if (now % f[j] != 0) now += (f[j] - now % f[j]);
      }
      else now = s[j];
      now += c[j];
    }
    cout << now << endl;
  }
  cout << 0 << endl;
}


Measured memory_bytes: 3620
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define sort(s) sort(s.begin(),s.end())
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<int>>
constexpr auto mod = 1000000007;


//2のn乗を求めるよ！！！
int ni(int n) {
	if (n == 0)return 1;
	int x = ni(n / 2);
	x *= x;
	if (n % 2 == 1)x *= 2;
	return x;
}

//フィボナッチ数列のx番目を求めるよ！
int f(int x,vector<int> s) {
	if (x == 0)return 0;
	if (x == 1)return 1;
	if (s[x] != 0)return s[x];
	s[x] = f(x - 1,s) + f(x - 2,s);
	return s[x];
}

//aとｂの最大公約数を求めるよ！
llint gcd(llint a, llint b) {
	if (a < b)swap(a, b);
	if (b == 0)return a;
	return gcd(b, a % b);
}



// a^n mod を計算する
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b,ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//m進数のn桁を全列挙やで
void dfs(int m, int n) {

	stack<string> st;
	st.push("");
	while (!st.empty()) {
		string now = st.top();
		st.pop();
		if (now.size() == n) {
			cout << now << endl;
		}
		else {
			for (int i = m-1; i >= 0; i--) {
				string next = now + to_string(i);
				st.push(next);
			}
		}
	}
}

int main(){
	int n;
	cin >> n;
	ll ans = 1;

	rep(i ,0,n) {
		ll t;
		cin >> t;
		ans *= t / gcd(ans, t);
	}

	cout << ans << endl;

	return 0;
}




  


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long ll;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};
using std::string;
vector<int> v;
bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // 偶数はあらかじめ除く
    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            return false;
        }
    }
    return true;
}
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  bool flg=false;
  cin>>n;
  for(int i=31;i<=55555;i+=30){
    if(IsPrime(i)==true){
      if(flg){
        cout << " ";
      }
      cout << i;
      n--;
      flg=true;
    }
    if(n==0) break;
  }
  cout<<endl;
  return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

struct Node{
  int key;
  struct Node *pa,*le,*ri;
};

struct Node *ro,*NIL;

void insert(int);
void pre(struct Node *);
void ino(struct Node *);
struct Node * find(struct Node *,int);

int main(){
  int num,buf;
  int i;
  char word[10];
  struct Node * buff;
  scanf("%d",&num);
  
  for(i=0;i<num;i++){
    scanf("%s",word);
    scanf("%d",&buf);
    if(word[0]=='i'){
      insert(buf);
    }else if(word[0]=='p'){
      ino(ro);
      printf("\n");
      pre(ro);
      printf("\n");
    }else if(word[0]=='f'){
      if((buff=find(ro,buf))!=NIL) printf("yes\n");
      else printf("no\n");
    }
  }
  return 0;
}

void insert(int buf){
  struct Node *x,*y,*z;
  y=NIL;
  x=ro;

  z=(struct Node *)malloc(sizeof(struct Node));
  z->key=buf;
  z->le=NIL;
  z->ri=NIL;
  
  while(x!=NIL){
    y=x;
    if(z->key < x->key) x=x->le;
    else x=x->ri;
  }
  z->pa=y;
  if(y==NIL) ro=z;
  else if(z->key < y->key)y->le=z;
  else y->ri=z;
}

void pre(struct Node *ro){
  if(ro==NIL) return;
  printf(" %d",ro->key);
  pre(ro->le);
  pre(ro->ri);
}

void ino(struct Node *ro){
  if(ro==NIL) return;
  ino(ro->le);
  printf(" %d",ro->key);
  ino(ro->ri);
}

struct Node * find(struct Node *x,int buf){
  while(x!=NIL&&buf!=x->key){
    if(buf < x->key) x=x->le;
    else x=x->ri;
  }
  return x;
}



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

int main () {
    int L,R,d;
    int c=0;
    cin >> L >> R >> d ;
    for (int i=L;i<=R;i++){
        if(i%d==0){
            c++;
        }
    }
    cout << c << endl;
}

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

int main() {
    int N;
    int t[110000], x[110000], y[110000];
    cin >> N;
    t[0] = x[0] = y[0] = 0;  
    for (int i = 0; i < N; ++i) cin >> t[i+1] >> x[i+1] >> y[i+1];  

    bool can = true;
    for (int i = 0; i < N; ++i) {
        int dt = t[i+1] - t[i];
        int dist = abs(x[i+1] - x[i]) + abs(y[i+1] - y[i]);
        if (dt < dist) can = false;
        if (dist % 2 != dt % 2) can = false; 
    }

    if (can) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 1408