akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
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 (a>b) { a=b; return 1; } return 0; }

using ll = long long;
using namespace std;
constexpr long long MAX = 5100000;
constexpr long long INF = 1LL << 60;
constexpr int MOD = 1000000007;

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
string a,b;
cin>>a>>b;
string ans="EQUAL";

if(a.size()>b.size()){
    ans="GREATER";
}
else if(a.size()<b.size()){
    ans="LESS";
}
else{
    rep(i,a.size()){
        int _a=a[i]-'0';
        int _b=b[i]-'0';
        if(_a==_b)continue;

        if(_a>_b){
            ans="GREATER";
        }
        else{
            ans="LESS";
        }
        break;
        }
    }
cout<<ans<<endl;
return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
using namespace std;
int b[100000];
signed main(){
  int a,b,c,d;
  cin>>a>>b>>c;
  if(a+b>=c && a<=c){
    cout<<"YES\n";
  }
  else{
    cout<<"NO\n";
  }
  return(0);
}

Measured memory_bytes: 256
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline int rd_int(void){
  int x;
  rd(x);
  return x;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
template<class S, class T> inline S chmin(S &a, T b){
  if(a>b){
    a=b;
  }
  return a;
}
int N;
int M;
int A;
int C;
int dp[4096];
int main(){
  int Lj4PdHRW, i;
  int res;
  rd(N);
  for(i=(1);i<(1<<N);i++){
    dp[i] = 1073709056;
  }
  int KL2GvlyY = rd_int();
  for(Lj4PdHRW=(0);Lj4PdHRW<(KL2GvlyY);Lj4PdHRW++){
    int Q5VJL1cS;
    rd(A);
    C = 0;
    int e98WHCEY = rd_int();
    for(Q5VJL1cS=(0);Q5VJL1cS<(e98WHCEY);Q5VJL1cS++){
      C |=(1<<(rd_int()-1));
    }
    for(i=(0);i<(1<<N);i++){
      chmin(dp[i|C], dp[i] + A);
    }
  }
  res = dp[(1<<N)-1];
  if(res==1073709056){
    wt_L(-1);
    wt_L('\n');
  }
  else{
    wt_L(res);
    wt_L('\n');
  }
  return 0;
}
// cLay varsion 20190929-1

// --- original code ---
// int N, M, A, C;
// int dp[4096];
// {
//   int res;
//   rd(N);
//   rep(i,1,1<<N) dp[i] = int_inf;
//   REP(rd_int()){
//     rd(A);
//     C = 0;
//     REP(rd_int()) C |= BIT_ith(rd_int()-1);
//     rep(i,1<<N) dp[i|C] <?= dp[i] + A;
//   }
//   res = dp[(1<<N)-1];
//   wt(if[res==int_inf, -1, res]);
// }


Measured memory_bytes: 256
n = int(input())
b = list(map(int,input().split()))
a = [b[0]]
for i in range(len(b)-1):
    if b[i] > b[i+1]:
        a.append(b[i+1])
    else:
        a.append(b[i])

a.append(b[len(b)-1])
print(sum(a)) 


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <queue>
#include <stack>
#include <cstdlib>
#include <map>
#include <iomanip>
#include <set>
#include <stdio.h>
#include <ctype.h>
#include <random>
#include <string.h>
#include <cmath>
#include <unordered_map>
#include <cstdio>
using namespace std;
#define pie 3.141592653589793238462643383279
#define mod 998244353
#define int long long
#define P pair<int,int>
#define all(vec) vec.begin(),vec.end()

int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int kai(int x, int y) {
	int res = 1;
	for (int i = x - y + 1; i <= x; i++) {
		res *= i; res %= mod;
	}
	return res;
}
int mod_pow(int x, int y, int m) {
	int res = 1;
	while (y > 0) {
		if (y & 1) {
			res = res * x % m;
		}
		x = x * x % m;
		y >>= 1;
	}
	return res;
}

int comb(int x, int y) {
	if (y > x)return 0;
	return kai(x, y) * mod_pow(kai(y, y), mod - 2, mod) % mod;
}

int n, l, t, a[100010], w[100010];
vector<P> vec;

signed main() {
	cin >> n >> l >> t;
	for (int i = 0; i < n; i++) {
		cin >> a[i] >> w[i];
		if (w[i] == 1)vec.push_back(make_pair((a[i] + t) % l, 1));
		else vec.push_back(make_pair((a[i] + l - t % l) % l, 2));
	}
	sort(all(vec));
	int p = 0;
	if (w[0] == 1) {
		int cnt = 0;
		for (int i = 1; i < n; i++)if (w[i] == 2 && a[i] - a[0] < 2*t) cnt += 1 + (2*t - (a[i] - a[0])-1) / l;
		cnt %= n;
		int x = lower_bound(all(vec), make_pair((a[0] + t) % l, (int)1)) - vec.begin();
		p = x - cnt;
	}
	else {
		int cnt = 0;
		for (int i = 1; i < n; i++)if (w[i] == 1 && l - (a[i] - a[0]) < 2*t) cnt -= 1 + (2*t - (l - ((a[i] - a[0])))-1) / l;
		cnt %= n;
		cnt += n;
		cnt %= n;
		int x = lower_bound(all(vec), make_pair((a[0] + l - t % l) % l, (int)2)) - vec.begin();
		p = x - cnt;
	}
	for (int i = 0; i < n; i++) cout << vec[(i + p + n) % n].first << endl;
}

Measured memory_bytes: 4464
import sys
if sys.version[0] == '2':
    range, input = xrange, raw_input


class HeavyLightDecomposition:
    def __init__(self, g, root=0):
        self.g = g
        self.vid, self.head, self.heavy, self.parent = [0] * len(g), [-1] * len(g), [-1] * len(g), [-1] * len(g)
        self.dfs(root)
        self.bfs(root)

    def dfs(self, root):
        stack = [(root, -1, False)]
        sub, max_sub = [1] * len(self.g), [(0, -1)] * len(self.g)
        while stack:
            v, par, flag = stack.pop()
            if not flag:
                self.parent[v] = par
                stack.append((v, par, True))
                stack.extend((c, v, False) for c in self.g[v] if c != par)
            else:
                if par != -1:
                    sub[par] += sub[v]
                    if sub[v] > max_sub[par][0]:
                        max_sub[par] = max(max_sub[par], (sub[v], v))
                self.heavy[v] = max_sub[v][1]

    def bfs(self, root=0):
        from collections import deque
        k, que = 0, deque([root])
        while que:
            r = v = que.popleft()
            while v != -1:
                self.vid[v], self.head[v] = k, r
                for c in self.g[v]:
                    if c != self.parent[v] and c != self.heavy[v]:
                        que.append(c)
                k += 1
                v = self.heavy[v]

    def lca(self, u, v):
        while self.head[u] != self.head[v]:
            if self.vid[u] > self.vid[v]:
                u, v = v, u
            v = self.parent[self.head[v]]
        else:
            if self.vid[u] > self.vid[v]:
                u, v = v, u
        return u

N = int(input())
g = [[] for _ in range(N)]
for i in range(N):
    for c in map(int, input().split()[1:]):
        g[i].append(c)
        g[c].append(i)
hld = HeavyLightDecomposition(g)
Q = int(input())
for _ in range(Q):
    u, v = map(int, input().split())
    print(hld.lca(u, v))

Measured memory_bytes: 38780
j,a=0,[]
def f(l,r):
 if l<r:
  global j,a;c=p[j];j+=1;m=i.index(c)
  f(l,m);f(m+1,r);a+=[c]
n,p,i=int(input()),input().split(),input().split()
f(0,n);print(*a)


Measured memory_bytes: 5600
#include<cmath>
#include<algorithm>
#include<iostream>
#include<vector>

using namespace std;

double EPS = 1e-10;

double add(double a, double b){
  if(abs(a+b) < EPS * (abs(a)+abs(b)))return 0;
  return a+b;
}

struct point{
  double x, y;
  point(){}
  point(double x,double y) : x(x) , y(y){}

  point operator + (point p){
    return point(add(x,p.x), add(y,p.y));
  }

  point operator - (point p){
    return point(add(x,-p.x), add(y,-p.y));
  }

  point operator * (double d){
    return point(x*d,y*d);
  }
};

struct segment{
  point a,b;
};

double dot(point a, point b) {
  return (a.x * b.x + a.y * b.y);
}

double cross(point a, point b) {
  return (a.x * b.y - a.y * b.x);
}

int is_intersected_ls(point a1, point a2, point b1, point b2) {
  return ( cross(a2-a1, b1-a1) * cross(a2-a1, b2-a1) < EPS ) &&
         ( cross(b2-b1, a1-b1) * cross(b2-b1, a2-b1) < EPS );
}

int ccw(point p0, point p1, point p2){
  point a = p1 - p0;
  point b = p2 - p0;
  if(cross(a,b)>EPS)return +1;
  if(cross(a,b)<EPS)return -1;
  if(dot(a,b)<-EPS)return +2;
  if(a.x*a.x+a.y*a.y<b.x*b.x+b.y*b.y)return -2;
  return 0;
}

vector<segment> construct_edge(point* p, int n){
  vector<segment>seg,seg2;
  
  for(int i=0;i<n;i++){
    for(int j=0;j<n;j++){
      if(i!=j){
	segment temp;
	temp.a=p[i];
	temp.b=p[j];
	seg.push_back(temp);
      }
    }
  }

  int t=seg.size();
  for(int i=0;i<t;i++){
    int fg=0;
    for(int j=0;j<t;j++){
      if(i!=j && seg[i].b.x==seg[j].a.x && seg[i].b.y==seg[j].a.y){
	if(ccw(seg[i].a,seg[i].b,seg[j].b)==1){
	  fg=1;
	  break;
	}
      }
    }
    if(!fg)seg2.push_back(seg[i]);
  }
  return seg2;
}

int point_contain(vector<segment> ps, point p, int n){
  int cnt=ccw(ps[0].a,ps[0].b,p);

  for(int i=0;i<n;i++)
    if(cnt!=ccw(ps[i].a,ps[i].b,p))return 0;
  
  return 1;
}

int main(void){
  int n;
  point p[3],k,s;
  vector<segment>seg;

  cin >> n;
  while(n--){
    for(int i=0;i<3;i++)
      cin >> p[i].x >> p[i].y;
    
    cin >> k.x >> k.y >> s.x >> s.y;

    seg=construct_edge(p,3);

    if(point_contain(seg,k,3)!=point_contain(seg,s,3))cout << "OK" << endl;
    else cout << "NG" << endl;
    
  }

  return 0;
}

Measured memory_bytes: 956
#include <string>

using namespace std;

int a, b;
string stra, strb;

int main() {
    scanf("%d %d", &a, &b);
    for (int i = 0; i < b; ++i) stra += char('0' + a);
    for (int i = 0; i < a; ++i) strb += char('0' + b);
    if (stra < strb) puts(stra.c_str());
    else puts(strb.c_str());
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
 
int main(void) {
    int x;
    cin >> x;
    if(x == 7 || x == 5 || x == 3){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}

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

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int h, w;
    cin >> h >> w;
    vector<string> M(h);
    for (int i = 0; i < h; ++i) 
        cin >> M[i];
    for (int i = 0; i < h; ++i) 
    {
        for (int j = 0; j < w; ++j) 
        {
            if (M[i][j] == '.') 
            {
                int cnt = 0;
                for (int a = -1; a < 2; ++a) 
                {
                    for (int b = -1; b < 2; ++b) 
                    {
                        int x = i + a, y = j + b;
                        if (x >= 0 && x < h && y >= 0 && y < w && !(x == i && y == j))
                        {
                            if (M[x][y] == '#') 
                                ++cnt;
                        }
                    }
                }
                M[i][j] = (char)('0' + cnt);
            }
        }
    }
    for (int i = 0; i < h; ++i) 
        cout << M[i] << '\n';
    return 0;
}


Measured memory_bytes: 3624
#include <stdio.h>
#include <cstdio>
#include <algorithm>
#include <set>
using namespace std;
int A, B, C, D, E, F;
int main() {
  scanf("%d%d%d%d%d%d", &A, &B, &C, &D, &E, &F);
  
  int water = 0;
  int sugar = 0;
  int res_water = 0;
  int res_sugar = 0;
  for (int i=0 ; 100*A*i<=F ; i++) {
    for (int j=0 ; 100*B*j<=F-100*A*i ; j++) {
      water = 100*A*i + 100*B*j;
      for (int k=0 ; C*k<=F-water ; k++) {
        for (int l=0 ; D*l<=F-water-C*k ; l++) {
          sugar = C*k + D*l;
          if (water == 0) continue;
          if (sugar*(100+E) > E*(water+sugar)) continue;
          if (sugar*(res_water+res_sugar) >= res_sugar*(water+sugar)) {
            res_water = water;
            res_sugar = sugar;
          }
        }
      }
    }
  }
  printf("%d %d\n", res_sugar+res_water, res_sugar);
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
using namespace std ; 
int main() {
	int A, B, C, D;
	cin >> A >> B >> C >> D;
	if (A * B > C * D)
	{
		cout << A * B << endl;
	}
	else if (A * B < C * D)
	{
		cout << C * D << endl;
	}
	else 
	{
		cout << A*B << endl;
	}
}


Measured memory_bytes: 3164
#include <iostream>

int CCC(int n, int x){
    int cnt = 0;
    for(int a = 1; a <= n; a++){
        for(int b = a + 1; (b <= n); b++){
            int c = x - a - b;
            if(c <= n and b < c) cnt++;
        }
    }
    return cnt;
}

int main(void){
    while(true){
        int n, x; scanf("%d%d", &n, &x);
        if(n == 0 and x == 0) break;
        printf("%d\n", CCC(n, x));
    }
    return 0;
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

int n,q;

string a[15];
string b[15];

int con[15][4];


void check(int &r,int &s,int &c){
	r=-1,s=-1,c=-1;
	for(int i=1;i<=20;++i){
		for(int j=1;j<=20;++j){
			for(int k=1;k<=20;++k){
				bool ok=true;
				rep(l,n+1) if(con[l][0]*i+con[l][1]*j+con[l][2]*k!=con[l][3]) ok=false;
				if(ok){
					r=(r==-1||r==i)?i:-2;
					s=(s==-1||s==j)?j:-2;
					c=(c==-1||c==k)?k:-2;
				}
			}
		}
	}
	return;
}


int main(void){
	while(cin >> n >> q){
		if(n==0) break;
		rep(i,15)rep(j,4) con[i][j]=0;
		rep(i,n) cin >> a[i];
		rep(i,q) cin >> b[i];

		int r,s,c;
		int rn=0,cn=0,sn=0,indent=0;
		rep(i,n){
			indent=0;
			while(indent<a[i].size()&&a[i][indent]=='.') indent++;
			con[i][3]=indent;
			rep(j,a[i].size()){
				switch(a[i][j]){
					case '(': rn++;break;
					case ')': rn--;break;
					case '{': cn++;break;
					case '}': cn--;break;
					case '[': sn++;break;
					case ']': sn--;break;
				}
			}
			con[i+1][0]=rn,con[i+1][1]=sn,con[i+1][2]=cn;
		}
		check(r,s,c);
		rn=0,cn=0,sn=0;
		rep(i,q){
			int res=-1;
			rep(j,n+1){
				if(con[j][0]==rn&&con[j][1]==sn&&con[j][2]==cn)
					res=con[j][3];
			}
			if(res>=0)
				cout << (i?" ":"") <<  res;
			else if((rn>0&&r<=0)||(cn>0&&c<=0)||(sn>0&&s<=0))
				cout << (i?" ":"") <<  -1;
			else
				cout << (i?" ":"") << r*rn+s*sn+c*cn;
			rep(j,b[i].size()){
				switch(b[i][j]){
					case '(': rn++;break;
					case ')': rn--;break;
					case '{': cn++;break;
					case '}': cn--;break;
					case '[': sn++;break;
					case ']': sn--;break;
				}
			}

		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using static System.Console;
using static System.Math;

namespace CP
{
    class Atria
    {
        static void Main(string[] args)
        {
            int n = int.Parse(ReadLine());
            int a = (int)(n / 1.08);
            double b = (n / 1.08);
            if (a == b)
            {
                WriteLine(a);
            }
            else
            {
                for (int i = 1; i < 50001; i++)
                {
                    if ((int)(i * 1.08) == n)
                    {
                        WriteLine(i);
                        return;
                    }
                }
                WriteLine(":(");
            }
        }
    }
}

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

struct Data{int a,b,c;};

int main()
{
  int a,b,c,N,d;
  int i;
  vector<int>device;
  vector<Data>trouble;
  while(cin>>a>>b>>c>>N,a|b|c){
    device.clear();
    trouble.clear();
    for(i=0;i<a+b+c+1;i++)device.push_back(2);
    for(i=0;i<N;i++){
      cin>>a>>b>>c>>d;
      Data t={a,b,c};
      if(d)device[a]=device[b]=device[c]=1;
      else trouble.push_back(t);
    }
    for(i=0;i<trouble.size();i++){
      if((device[trouble[i].a]&1)+(device[trouble[i].b]&1)+(device[trouble[i].c]&1)==2){
	device[trouble[i].a]&=1;
	device[trouble[i].b]&=1;
	device[trouble[i].c]&=1;
      }
    }
    for(i=1;i<device.size();i++)cout<<device[i]<<endl;
  }
}

Measured memory_bytes: 0
#include <stdio.h>

int main(void){
  long long K;
  scanf("%lld", &K);

  int N = 50;
  long long A[N];
  for (int i = 0; i < N; i++) {
    A[i] = i+K/N;
  }

  for (int i = 0; i < K%N; i++) {
    A[i] += N;
    for (int j = 0; j < N; j++) {
      if(i != j) A[j]--;
    }
  }

  printf("50\n");
  for (int i = 0; i < N; i++) {
    printf("%lld%c", A[i], i == N-1?'\n':' ');
  }

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int32_t n, w;
  cin >> n >> w;
  vector<uint64_t> weight(n+1, 0);
  vector<uint64_t> value(n+1, 0);
  for (int32_t i = 1; i <= n; ++i) {
    cin >> weight[i] >> value[i];
  }

  vector<vector<uint64_t>> dp(n+1, vector<uint64_t>(w+1, 0));
  for (int32_t i = 1; i <= n; ++i) {
    uint64_t wi = weight[i];
    uint64_t vi = value[i];
    for (int32_t j = 0; j < wi; ++j) {
      dp[i][j] = dp[i-1][j];
    }
    for (int32_t j = wi; j <= w; ++j) {
      dp[i][j] = max(dp[i-1][j], vi + dp[i-1][j-wi]);
    }
  }

  cout << dp[n][w] << endl;
}


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

using namespace std;

int main()
{
    int N, T, A;

    int ans = -1;
    double ansabs = 1000000000.0;

    cin >> N >> T >> A;

    for (int i = 0; i < N;i++)
    {
        int x;
        cin >> x;
        double t = abs(T - x * 0.006 - A);
        if(t < ansabs || ans == -1)
        {
            ans = i + 1;
            ansabs = t;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < n; i++)
#define repr(i, n) for(ll i = n; i >= 0; i--)
#define inf LLONG_MAX
#define all(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;


int main()
{
    string s; cin >> s;
    reverse(all(s));
    if (s.size () < 5) {
        cout << "NO" << endl;
        return 0;
    }
    while (s.size()) {
        if (s.size() >= 5 && (s.substr(0, 5) == "maerd" || s.substr(0, 5) == "esare")) {
            s.erase(s.begin(), s.begin()+5);
            continue;
        }
        if (s.size() >= 6 && s.substr(0, 6) == "resare") {
            s.erase(s.begin(), s.begin()+6);
            continue;
        }

        if (s.size() >= 7 && s.substr(0, 7) == "remaerd") {
            s.erase(s.begin(), s.begin()+7);
            continue;
        }

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

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

using namespace std;

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

const int MAXN = 2 * 105000;
const int INF = (int) 1e9 + 100;

int n;
int a[MAXN];
vector<int> g[MAXN];
vector<int> dp;
int ans[MAXN];

void go(int v, int par = -1) {
    int pos = upper_bound(all(dp), a[v]) - dp.begin();
    int prev = -1;
    if (pos > 0 && pos <= n && dp[pos - 1] < a[v] && a[v] < dp[pos]) {
        prev = dp[pos];
        dp[pos] = a[v];
    }

    ans[v] = lower_bound(all(dp), INF) - dp.begin() - 1;

    for (int to : g[v]) {
        if (to == par) continue;
        go(to, v);
    }

    if (prev != -1)
        dp[pos] = prev;
}

int main() {

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

    for (int i = 0; i < n - 1; i++) {
        int from, to;
        scanf("%d %d", &from, &to);
        from--; to--;
        g[from].push_back(to);
        g[to].push_back(from);
    }

    dp.assign(n + 1, INF);
    dp[0] = -INF;

    go(0);

    for (int i = 0; i < n; i++) 
        printf("%d\n", ans[i]);

    return 0;
}


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

using namespace std;

using ll = long long;

template <typename T>
struct SparseTable {
    int n;
    vector< vector<T> > table;
    vector<int> log_table;

    SparseTable(const vector<T>& v) {
        n = v.size();

        log_table.resize(n + 1, 0);
        for (int i = 2; i <= n; i++) {
            log_table[i] = log_table[i >> 1] + 1;
        }

        table.resize(log_table[n] + 1, vector<T>(n));
        for (int i = 0; i < n; i++) {
            table[0][i] = v[i];
        }

        size_t sz = table.size();
        for (int i = 1; i < sz; i++) {
            for (int j = 0; j + (1 << i) <= n; j++) {
                table[i][j] = max(table[i - 1][j], table[i - 1][j + (1 << (i - 1))]);
            }
        }
    }

    //区間[l, r)に対するクエリに答える
    T query(int l, int r) {
        if (l == r) return 0;
        int k = log_table[r - l];
        return max(table[k][l], table[k][r - (1 << k)]);
    }
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    SparseTable<int> st(a);
    for (int i = 0; i < n; i++) {
        cout << max(st.query(0, i), st.query(i + 1, n)) << "\n";
    }
    return 0;
}


Measured memory_bytes: 17264
#include <iostream>
#include <cassert>
//#define NDEBUG

int main(void){
	using namespace std;
	static const int INPUT_N_MAX = 100;								/* 前提条件 */
	static const int INPUT_A_MIN = 0;
	static const int INPUT_A_MAX = 1000;
	
	int input_n = 0;												/* 数列の長さ */
	cin >> input_n;													/* 入力の整数n */
	assert (0 < input_n && input_n <= INPUT_N_MAX);					/* 前提条件 */	
	int a[input_n-1];
	
	/* 入力 a[0]から順に格納 */
	for (int i = 0; i < input_n; i++){
		cin >> a[i];
		assert (INPUT_A_MIN <= a[i] && a[i] < INPUT_A_MAX);			/* 前提条件 */
	}
	/* 出力 a[input_n-1]から降順に出力 */
	cout << a[input_n-1];
	for (int i = input_n-2; i >= 0; i--){
		cout << " " << a[i];
	}
	cout << endl;
	return 0;
}



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

int main() {
	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i < (int) s.size(); i++) ans += s[i] != t[i];
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 3916
#include<bits/stdc++.h>
constexpr long long INFL = 1LL << 60;
constexpr int INF = 1e9;

using namespace std;

int main()
{
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    if((abs(a-b) <= d && abs(b-c) <= d) || abs(a-c) <= d)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}



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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vll = vector<ll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	for (auto &u : v) os << u << el;
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

int main() {
	int N; cin >> N;
	vint A(N); cin >> A;
	int val, size;

	bool f = false;
	sort(begin(A), end(A));
	if (A.back() - A.front() > 1) { cout << "No" << endl; return (0); }

	if (A.back() - A.front() == 1) {
		f = true;
		int cnt = count(begin(A), end(A), A.front());
		val = A.back() - cnt;
		size = A.size() - cnt;
	} else { val = A.front(); size = A.size(); }
		
	if (!f && size == val + 1 || val > 0 && size >= val * 2) {
		cout << "Yes" << endl;
	} else {
		cout << "No" << endl;
	}

	return (0);
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.StringTokenizer;

public class Main {
	static int H, W;
	static char arr[][];
	static long dp[][];

	public static long dp(int i, int j) {
		if (i == H - 1 && j == W - 1) {
			return 1;
		}
		if (arr[i][j] == '#') {
			return 0;
		}
		if (dp[i][j] != -1) {
			return dp[i][j];
		}
		long down = 0;
		long right = 0;
		if (i != H - 1) {
			down = dp(i + 1, j);
		}
		if (j != W - 1) {
			right = dp(i, j + 1);
		}
		return dp[i][j] = (down%((int)1e9+7) + right%((int)1e9+7))%((int)1e9+7);
	}

	public static void main(String[] args) throws IOException {

		Scanner sc = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
		H = sc.nextInt();
		W = sc.nextInt();
		dp = new long[H + 1][W + 1];
		for (int f = 0; f < H + 1; f++) {
			Arrays.fill(dp[f], -1);
		}
		arr = new char[H + 1][W + 1];
		for (int i = 0; i < H; i++) {
			String str = sc.nextLine();
			for (int j = 0; j < W; j++) {
				arr[i][j] = str.charAt(j);
			}
		}
		out.println(dp(0, 0) % 1000000007);
		// b7ebak ya Eshiba
		out.flush();
		out.close();
	}

	static class Scanner {
		StringTokenizer st;
		BufferedReader br;

		public Scanner(InputStream s) {
			br = new BufferedReader(new InputStreamReader(s));
		}

		public String next() throws IOException {
			while (st == null || !st.hasMoreTokens())
				st = new StringTokenizer(br.readLine());
			return st.nextToken();
		}

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

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

		public String nextLine() throws IOException {
			return br.readLine();
		}

		public double nextDouble() throws IOException {
			String x = next();
			StringBuilder sb = new StringBuilder("0");
			double res = 0, f = 1;
			boolean dec = false, neg = false;
			int start = 0;
			if (x.charAt(0) == '-') {
				neg = true;
				start++;
			}
			for (int i = start; i < x.length(); i++)
				if (x.charAt(i) == '.') {
					res = Long.parseLong(sb.toString());
					sb = new StringBuilder("0");
					dec = true;
				} else {
					sb.append(x.charAt(i));
					if (dec)
						f *= 10;
				}
			res += Long.parseLong(sb.toString()) / f;
			return res * (neg ? -1 : 1);
		}

		public boolean ready() throws IOException {
			return br.ready();
		}

	}
}

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

#define fio ios_base::sync_with_stdio(false); cin.tie(NULL);
#define REP(i,n) for(long long int i=0;i<(n);i++)
#define FOR(i,a,b) for(long long int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(long long int i=(a);i>=(b);i--)
#define sortv(v) sort(v.begin(),v.end());
#define sorta(a,n) sort(a,a+n);
#define arrayin(a,n) for(long long int i=0;i<n;i++) cin>>a[i];
#define arrayout(a,n) for(long long int i=0;i<n;i++) cout<<" ";cout<<"\n";
#define whatIs(x) cout<<#x<<" is "<<x<<endl;
#define fillA(a,value) memset(a,value,sizeof(a));
#define len(s) s.length()
#define reached cout<<"reached "<<endl;
#define INF INT_MAX //Infinity
#define mp make_pair
#define pb push_back
#define mt make_tuple
#define MOD 1000000007
#define fi first
#define se second
#define ii pair<int,int>
#define vi vector<int>
#define vii vector<ii>
#define vi64 vector<lli>
#define viii vector<tuple<int,int,int>>
#define prq priority_queue<int>
#define mii map<int,int>
#define msi multiset<int>
#define nl "\n"
#define sii set<int,int>
#define sz size

typedef long long int lli;
typedef unsigned long long int ulli;
typedef double ld;

using namespace std;

int main()
{
	fio;
	/*int t;
	cin>>t;
	while(t--)
	{
		int n;
		cin>>n;
	}*/
	lli a,b;
	cin>>a>>b;
	lli ans=0;
	while(a<=b)
	{
		ans++;
		a=a*2;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> //C++の標準ライブラリを一行で一括でインクルードする
#include <math.h> //数学関数と数学定数を利用する
#define rep(i,n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}

int main(){
  string s,t;
  cin >> s >> t;
  
  sort(s.begin(),s.end());
  sort(t.begin(),t.end(),greater<int>());
  
  if (s < t) cout << "Yes";
  else cout << "No";

  return 0;
}

Measured memory_bytes: 256
import fileinput

if __name__ == '__main__':
    # 標準入力からグラフ読み込み
    G = []
    g = []
    for line in fileinput.input():
        tokens = list(map(int, line.strip().split()))
        a, b = tokens[0], tokens[1]
        if a == 0 and b == 0:
            G.append(g)
            g = []
        else:
            g.append((tokens[0], tokens[1]))

    # グラフオブジェクトから経路判定
    for g in G:
        result = True
        counts = [0 for i in range(100)]        
        for a, b in g:
            counts[a-1] += 1
            counts[b-1] += 1
        for c in counts[0:2]:
            if c % 2 == 0:
                result = False
        for c in counts[2:100]:
            if c % 2 == 1:
                result = False
        print("OK" if result else "NG")


Measured memory_bytes: 5720
import collections

dic = collections.defaultdict(int)

N, K = map(int, input().strip().split())
for i in range(K):
  di = map(int, input().strip())
  A = map(int, input().strip().split())
  for j in A:
    dic[j] += 1

ans = 0
for i in range(1, N+1):
  if dic.get(i) is None:
    ans += 1

print(ans)

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

int main()
{
	int i,n,m;
	int ans;
	int count;

	cin >> n >> m;
	ans = n;
	count = 1;
	for (i = 2;ans < m;i++)
	{
		ans = n*i;
		ans = ans-count;
		count++;
	}
	if (m == 1)
		i = 1;
	cout << i-1;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using vs = vector<string>;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repb(i, a, b) for (int i = (a); i < (b); i++)
#define ALL(a) (a).begin(),(a).end()
#define PRINT(V) for(auto v:(V))cout<<v<<" "<<endl
inline int GCD(int a, int b){return b ? GCD(b, a % b) : a;}
const int MOD = 1000000007;

int main()
{
    ll A, B;
    cin >> A >> B;
    ll ans = 0;
    ll x = A/2, y = B/2;
    ll shift = 4;
    int f, fa, fb;
    if (A % 2 == 0 && B % 2 == 0)
    {
        ans += ((B - A) / 2) % 2;
    }
    else
    {
        ans += ((B - A) / 2 + 1) % 2;
    }
    while (x || y)
    {
        if ((A-1) % shift >= shift / 2)
        {
            fa = 1 - ((A-1) % shift) % 2;
        }
        else
        {
            fa = 0;
        }
        
        if (B % shift >= shift / 2)
        {
            fb = 1 - (B % shift) % 2;
        }
        else
        {
            fb = 0;
        }
        f = fa xor fb;
        ans += f * shift / 2;
        shift *= 2;
        x /= 2;
        y /= 2;
    }
    cout << ans << endl;
    /*
    if(A % 2 == 0 && B % 2 == 0)
    {
        ans += ((B-A)/2)%2;
    }
    else
    {
        ans += ((B - A) / 2 + 1) % 2;
    }
    ll x = A, y = B;
    A >>= 1;
    B >>= 1;
    int shift = 1;
    while (A && B)
    {
        int f, fa, fb;
        ll bai = (1LL << (shift + 1));
        if (A % 2 == 1)
        {
            fa = (bai - x % bai) % 2;
        }
        if (B % 2 == 1)
        {
            fb = (bai - y % bai) % 2;
        }
        A >>= 1;
        B >>= 1;
        shift++;
    }
    */
}

Measured memory_bytes: 256
//To include everything you need
#include <bits/stdc++.h>
using namespace std;
typedef std::vector<int> vi;
typedef std::vector<std::pair<int, int> > vpi;
typedef std::vector<string> vs;
typedef std::vector<char> vc;

int main()
{
    int n;
    cin >> n;
    vector<int> damWater;
    int minWater = INT_MAX;
    int minIndex;
    vector<long> mountainWater(n);
    long totalWater = 0;
    for (int i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if (a < minWater)
        {
            minWater = a;
            minIndex = i;
        }
        totalWater += a;
        damWater.push_back(a);
    }
    int startingDam = damWater[0];
    mountainWater[0] = totalWater;
    for (int i = 1; i < n; i +=2)
    {
        mountainWater[0] -= 2 * damWater[i];
    }
    for (int j = 1; j < n; j++)
    {
        mountainWater[j] = 2 * damWater[j - 1] - mountainWater[j - 1];
    }
    // long currentTotal = 0;
    // for (long i = 0; i <= 2 * startingDam; i += 2)
    // {
    //     mountainWater[minIndex] = i;
    //     currentTotal = i;
    //     for (int j = minIndex -1; j >= 0; j--)
    //     {
    //         mountainWater[j] = 2 * damWater[j] - mountainWater[j + 1];
    //         currentTotal += mountainWater[j];
    //     }
    //     for (int j = minIndex + 1; j < n; j++)
    //     {
    //         mountainWater[j] = 2 * damWater[j - 1] - mountainWater[j - 1];
    //         currentTotal += mountainWater[j];
    //     }
    //     if (currentTotal == totalWater)
    //         break;
    // }

    for (int i = 0; i < n; i++)
    {
        cout << mountainWater[i] << " ";
    }
}

Measured memory_bytes: 2680
#include <cstdlib>
#include <cctype>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <fstream>
#include <numeric>
#include <iomanip>
#include <bitset>
#include <list>
#include <stdexcept>
#include <functional>
#include <utility>
#include <ctime>
#include <random>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;;
#define MEM(a,b) memset((a),(b),sizeof(a))
const LL INF = 1e9 + 7;
const int N = 1e6 + 10;
int a[N];
int main()
{
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	int ans = 0;
	int n;
	cin >> n;
	for (int i = 1; i * i <= n; i++)
	{
		ans = max(ans, i*i);
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include<algorithm>
#include<bitset>
#include<cmath>
#include<complex>
#include<deque>
#include<functional>
#include<iomanip>
#include<iostream>
#include<iterator>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<unordered_map>
#include<unordered_set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define D()
#define INF 1000000000000
#define MOD 10000007
#define MAXR 100000
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INITA(a,i,j,v) for(ll k=i;k<=j;k++){a[k]=v;}

int main() {
    int n, k;
    vector<ll> v;
    cin >> n >> k;
    REP(i, n) {
        ll tmp;
        cin >> tmp;
        v.push_back(tmp);
    }
    sort(ALL(v));
    ll mn = INF;
    FOR(i, 0, n - k) {
        ll diff = v[i+k-1] - v[i];
        if (diff < mn) {
            mn = diff;
        }
    }
    cout << mn << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string a,b,c="";
	int n;
	cin>>n;
	cin>>a>>b;
	for(int i=0;i<n;i++)
		c = c + a[i] +b[i];
	cout<<c<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b)-1);i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int, int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))

#define MOD 1000000007

vector<int> p;
int n;

void prime(void){
	p.push_back(2);
	for(int i = 3  ; i <= 1000 ; i += 2){
		bool f = true;
		rep(j, p.size()) if(i%p[j] == 0){
			f = false; break;
		}
		if(f == true) p.push_back(i);
	}
}

int fanc(int a){
	int ret = 0, m = n;
	while(true){
		m /= a;
		ret += m;
		if(m == 0) break;
	}
	return ret + 1;
}

int main(void){
	scanf("%d", &n);
	
	prime();
	
	lli ans = 1;
	
	rep(i, p.size()) ans = (ans * fanc(p[i])) % MOD;
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
def input(): return sys.stdin.readline().rstrip()

def main():
  N = input()
  if N[-1] == '3':
    print('bon')
  elif N[-1] in ('2','4','5','7','9'):
    print('hon')
  elif N[-1] in ('0','1','6','8'):
    print('pon')

if __name__ == '__main__':
  main()

Measured memory_bytes: 9120
#include <bits/stdc++.h>
using namespace std;
int main(){ 
   int n,m;
   cin >> n;
   vector<string> s(n);
   for(int i=0;i<n;i++){
    cin >> s[i];
   }
   cin >> m;
   vector<string> t(m);
   for(int i=0;i<m;i++){
    cin >> t[i];
   }
   sort(s.begin(),s.end());
   vector<int> counter(n,0);
   vector<string> existStr(n,"1");
   string tmp=s[0];
   int a=0;
   existStr[a] = tmp;
   for(int i=0;i<n;i++){
        if(s[i]!=tmp){
            a++;
            tmp=s[i];
            existStr[a] = tmp;
            counter[a]++;
            continue;
        }
        counter[a]++;
   }
   a=0;
   for(int i=0;i<m;i++){
       for(int j=0;j<n;j++){
            if(t[i] == existStr[j]){
                counter[j]--;
            }
       }
   }
   int maxvalue=0;
   for(int i=0;i<n;i++){
    if(maxvalue < counter[i]){
        maxvalue = counter[i];
    }
   }
   cout << maxvalue << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define rep2(i,s,f) for(int i=s;i<f;i++)
#define INF 1000000000000000000
#define MOD 1000000007
typedef pair<int, int> P;

bool prime(int n) {
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0)return false;
	}
	return n != 1;
}
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x % y);
}
int lcm(int x, int y) {
	return x / gcd(x, y) * y;
}
int mod_pow(int n, int p, int m) {
	if (p == 0) return 1;
	if (p % 2 == 0) {
		int t = mod_pow(n, p / 2, m);
		return (t * t) % m;
	}
	return n * mod_pow(n, p - 1, m) % m;
}
int extGCD(int a, int b, int& x, int& y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a % b, y, x);
	y -= a / b * x;
	return d;
}
int modinv(int a, int m) {
	int 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;
}
int digit(int x) {
	int cnt = 0;
	while (x > 0) {
		cnt += x % 10;
		x /= 10;
	}
	return cnt;
}
int read() {
	int tmp;
	cin >> tmp;
	return tmp;
}
int xor128() {
	static int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	int t = (x xor (x << 11));
	x = y; y = z; z = w;
	return (w = (w xor (w >> 19)) xor (t xor (t >> 8)));
}
map<int, int> factaring(int x) {
	map<int, int>ans;
	int now = 2;
	while (now * now <= x) {
		if (x % now == 0) {
			x /= now;
			ans[now]++;
		}
		else now++;
	}
	if (x != 1) ans[x]++;
	return ans;
}
int comb(int n, int k) {
	k = min(k, n - k);
	int x = 1, y = 1;
	rep(i, k) {
		y *= i + 1;
		y %= MOD;
	}
	for (int i = n - k + 1; i <= n; i++) {
		x *= i;
		x %= MOD;
	}
	return x * modinv(y, MOD) % MOD;
}

signed main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	ans += n / (a + b) * a;
	int x = n - n / (a + b) * (a + b);
	ans += min(x, a);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>


using namespace std;

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

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


int c[10][10];
const int inf = 1e+9;




int dykstra(int s) {
	if (s == 1) {
		return 0;
	}
	priority_queue<P, vector<P>, greater<P> > que;
	vector<int > d(10, inf);

	d[s] = 0;
	que.push(make_pair(0, s));

	while(! que.empty()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) {
			continue;
		}
		for(int i = 0; i < 10; i++) {
			if (i == v) continue;
			int cost = c[v][i];
			if (p.first + cost < d[i]) {
				d[i] = p.first + cost;
				que.push(make_pair(p.first + cost, i));
			}
			
		}
	}
	return d[1];
}


int main() {
 	int H , W;
 	cin >> H >> W;


 	rep(y , 10) {
 		rep(x , 10) {
 			cin >> c[y][x];
 		}
 	}

 	vector <int> a(10,0);

 	rep (i, H * W) {
 		int t;
 		cin >> t;
 		if (t == -1) {
 			continue;
 		}
 		a[t] ++;
 	}
 	int total = 0;
 	rep(i, 10) {
 		//cout << "i:" " d:" << dykstra(i) << " a:" << a[i] << endl; 
 		total += dykstra(i) * a[i];
 	}
 	cout << total << endl;


	
	return 0;
}

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

using namespace std;

int main(){
    int n,m;
    cin>>n>>m;
    vector<long long> a(n);
    for (int i = 0; i < n; ++i) {
        cin>>a[i];
    }
    sort(a.begin(),a.end());
    vector<pair<long long ,long long>> b;
    for (int i = 0; i < m; ++i) {
        long long tb,tc;
        cin>>tb>>tc;
        b.emplace_back(tc,tb);
    }
    sort(b.rbegin(),b.rend());
    long long tind=0;
    long long ans=0;
    for (int i = 0; i < m; ++i) {
        if(tind>=n)break;
        if(a[tind]>=b[i].first)break;
        auto itl=lower_bound(a.begin(),a.end(),b[i].first);
        long long ind=itl-a.begin();
        ans+=b[i].first*(min(b[i].second,ind-tind));
        tind+=min(b[i].second,ind-tind);
    }
    for (int i = tind; i < n; ++i) {
        ans+=a[i];
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3188
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;
using ll = long long int;

int main()
{
	int x, y, z, k;
	cin >> x >> y >> z >> k;
	auto a = vector<ll>(x);
	auto b = vector<ll>(y);
	auto c = vector<ll>(z);
	for(auto& s : a) cin >> s;
	for(auto& t : b) cin >> t;
	for(auto& u : c) cin >> u;
	auto ab = vector<ll>(x * y);
	for(auto i = 0; i < x; ++i){
		for(auto j = 0; j < y; ++j){
			ab[i * y + j] = a[i] + b[j];
		}
	}
	sort(ab.begin(), ab.end(), greater<ll>());
	int v = min(k, x * y);
	auto d = vector<ll>(v);
	for(auto i = 0; i < v; ++i){
		d[i] = ab[i];
	}
	auto cd = vector<ll>(z * v);
	for(auto i = 0; i < z; ++i){
		for(auto j = 0; j < v; ++j){
			cd[i * v + j] = c[i] + d[j];
		}
	}
	sort(cd.begin(), cd.end(), greater<ll>());
	for(auto i = 0; i < k; ++i){
		cout << cd[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 31616
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <iomanip>
using namespace std;
#define REP(i,n) for (int i=0;i<(n);++i)
#define rep(i,a,b) for(int i=a;i<(b);++i)
template<class T> inline bool chmin(T &a, T b){ if(a > b) { a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){ if(a < b) { a = b; return true;} return false;}
using ll = long long;
constexpr ll INF = 1LL << 60;
constexpr ll MOD = 1e9 + 7;


int w[100];

int main() {
    cin.tie(0); ios_base::sync_with_stdio(false);
    int N;
    cin >> N;
    REP(i,N) cin >> w[i];
    ll ans = INF;
    REP(T,N){
        ll a=0,b=0;
        REP(j,N){
            if(j<=T) a+=w[j];
            else b += w[j];
        }
        ans = min(ans,abs(a-b));
    }
    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
/**
 *       Author:  kulubat
 *       Written on Thursday, 16 April 2020.
 **/

#include <bits/stdc++.h>


using namespace std;


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    int n, k, x, y;

    cin >> n >> k >> x >> y;

    int b = min(k, n);
    int a = max(n-k, 0);

   

    cout << x*b + a*y << "\n";


    return 0;
}


Measured memory_bytes: 256
get_number(Number) :-
    get_string(String),
    number_string(Number, String).

get_number(A, B) :-
    get_number(A),
    get_number(B).

get_number(A, B, C) :-
    get_number(A, B),
    get_number(C).

get_string(String) :-
    current_input(Input),
    read_string(Input, ' \n', '', _, String).

get_chars(Xs) :-
    get_string(S),
    string_chars(S, Xs).

get_numbers(0, []).
get_numbers(N, [X|Xs]) :- 
    get_number(X), 
    N2 is N - 1, 
    get_numbers(N2, Xs).

put_numbers([]).
put_numbers([X|Xs]) :-
    writeln(X),
    put_numbers(Xs).

/* memo
    code(int)
    string_code(1, S, C), (C: code)
    char_code(X, Y) (X: char, Y: code)
    string_chars(S, S2) (S: string, S2: [char])
    to_lower(C, C2) (C: char? C2: code?)
    length(S, L),
    sub_string

    f(0, [], []).
    f(Z, [X|Xs], [Y|Ys]) :- X = Y, f(Z1, Xs, Ys), Z is Z1 + 1.
    f(Z, [_|Xs], [_|Ys]) :- f(Z, Xs, Ys).

    match: =, \=

    numeric: <,=<, >, >= (eval)
    lexicographically: @<. @=<, @>, @>=
    value?: =:=, =\= (eval)
    identical: ==, \==

    between(L,U,X): L <= X <= U
    nth0(I, Xs, Y), nth1(I, Xs, Y): (Xs,Y) -> I, (I, Xs) -> Y 

    sort(Key, Order, List, Sorted): Keyは通常0?, Orderは=なしが重複削除，=は重複保持
    \+ P(X) : not P(X)

    sum_list(Xs, Sum)
*/

f(N, Z) :- f(N, 0, Z).
f(0, S, S).
f(N, S, Z) :- g(N, S, S2), N2 is N - 1, f(N2, S2, Z).

g(N, S, S2) :- N mod 5 =\= 0, N mod 3 =\= 0, S2 is N + S, !.
g(_, S, S).

main :-
    get_number(N),
    f(N, Z),
    writeln(Z).
    % statistics(inferences, IC), writeln(IC).


Measured memory_bytes: 8120
#include <bits/stdc++.h>
 using namespace std;
 int main() {
long long A, B;
 cin >> A >> B;
 if(A % 2 != B % 2) {
 cout << "IMPOSSIBLE" << endl;
 } else {
 cout << (A + B) / 2 << endl;
 }
return 0;
 }

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (ll i=(ll)from; i<(ll)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string S; cin >> S;
  ll result = 0;
  if (S[0]=='R'&&S[1]=='R'&&S[2]=='R') result = 3;
  else if (S[0]=='R'&&S[1]=='R') result = 2;
  else if (S[1]=='R'&&S[2]=='R') result = 2;
  else if (S[0]=='R'||S[1]=='R'||S[2]=='R') result = 1;
  cout << result << endl;
  return 0;
}

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

int main()
{
	int n, m;
	cin >> n >> m;
	pair<int, int> p[m];
	for (int i = 0; i < m; i++) cin >> p[i].first >> p[i].second;
	sort(p, p+m);
	reverse(p, p+m);
	int ans = 0;
	int t = n;
	for (int i = 0; i < m; i++){
		if (p[i].second <= t){
			ans++;
			t = p[i].first;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 1024