akhauriyash/Code-Regression huggingface dataset:
// Author: Vamsi Krishna Reddy Satti
// With love for Competitive Programming!
 
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize ("Ofast,unroll-loops,-ffloat-store,no-stack-protector")
// #pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,fma")

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

string to_string(const string& s) { return '"' + s + '"'; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cout << " " << to_string(H);
    debug_out(T...);
}
#ifdef LOCAL
    #define debug(...) cout << "#" << __LINE__ << " [" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
    #define debug(...) 3
#endif
 
#define cin_exception cin.exceptions(cin.failbit);
#define cout_precision cout.setf(ios::fixed); cout.precision(15);
#define fast_io ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
using ld = long double;  using ui = uint_fast32_t;
using ll = int_fast64_t; using ul = uint_fast64_t;

// -----------------------------------------------------------------------------

const int MOD = 2019;
int cn[MOD];

void solve() {
    string s;
    cin >> s;
    int n = s.length();
    int v = 0;
    ll an = 0, p = 1;
    cn[0] = 1;
    for (int i = n - 1; i >= 0; --i) {
        v += p * (s[i] - '0'); v %= MOD;
        p *= 10; p %= MOD;
        an += cn[v];
        ++cn[v];
    }
    cout << an << '\n';
}

// -----------------------------------------------------------------------------

int main() {
    fast_io; // cout_precision;
#ifdef LOCAL
    cin_exception;
#endif
    int t = 1;
    // cin >> t;
    for (int i = 1; i <= t; ++i) {
        solve();
    }
}

Measured memory_bytes: 3752
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;

void solve(int n, int m) {
	set<int> s;
	int l = 1;
	int r = n;
	vector<pair<int, int>> v;
	for (int i = 0; i < m; i++) {
		if (s.count(r - l) || s.count(n - (r - l)) || 2 * (r - l) == n) l++;
		v.push_back({l, r});
		s.insert(r - l);
		s.insert(n - (r - l));
		l++;
		r--;
	}
	for (auto t : v) {
		cout << t.first << ' ' << t.second << endl;
	}
}

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);	

	int n, m;
	cin >> n >> m;
	solve(n, m);
}


Measured memory_bytes: 12372
#include <bits/stdc++.h>
using namespace std;
int main(){
int H,W;
  cin>>H>>W;
  vector<vector<int>>M(H+2,vector<int>(W+2,0));
  for(int i=1;i<=H;i++){
  for(int j=1;j<=W;j++){
  char c; cin>>c;
    if(c=='#')
      M[i][j]=1;
    else
      M[i][j]=0;
  }
  
  } bool ans=true;
  for(int i=1;i<=H;i++){
    for(int j=1;j<=W;j++){
    if(M[i][j]==1){
    if(M[i-1][j]+M[i+1][j]+M[i][j-1]+M[i][j+1]==0){
         ans=false; break;}
    
    }
    
    }
    
  }if(ans)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
   return 0;
}
 



Measured memory_bytes: 256
h,w,m=map(int,input().split())
g=[0]*h
l=[0]*w
b=[]
for i in range(m):
  x,y=map(int,input().split())
  g[x-1]+=1
  l[y-1]+=1
  b.append((x-1,y-1))
mxg=max(g);mxl=max(l)
mg=set([i for i,x in enumerate(g) if x==mxg])
ml=set([i for i,x in enumerate(l) if x==mxl])
c=0
for x,y in b:
  if x in mg and y in ml:
    c+=1
print(mxg+mxl-(c==(len(mg)*len(ml))))

Measured memory_bytes: 200552
#include<stdio.h>

int main(void)
{
  int i=0,x=0,y=0;
  int n=0,m=0;
  int H[100], W[100];

  while(1){
    scanf("%d %d", &H[n], &W[n]);  
    if(H[n]==0 && W[n]==0)
      break;
    n++;
  }
  
  while(i<n-1){
    for(x=0; x<H[i]; x++){
      for(y=0; y<W[i]; y++){
	putchar('#');
      }
      putchar('\n');
    }
    putchar('\n');
    i++;
  }

  
  for(x=0; x<H[i]; x++){
    for(y=0; y<W[i]; y++){
	putchar('#');
      }
      putchar('\n');
    }
  putchar('\n');
 
  return 0;
}

Measured memory_bytes: 1760
#include<stdio.h>
int main(void)
{
int a, b, c;
scanf("%d %d %d", &a, &b, &c);
  if(a == 5 && b == 5 && c == 7){
    printf("YES\n");
  } else if(a == 5 && b == 7 && c == 5){
    printf("YES\n");
  } else if(a == 7 && b == 5 && c == 5){
      printf("YES\n");
  } else {
    printf("NO\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
int main() {
	int n, x, i, d, l,ans = 0;
	scanf("%d %d", &n, &x);
	for (i = 0; i < n; i++) {
		scanf("%d", &l);
		d += l;
		if (d <= x) {
			ans++;
		}
	}
  	ans++;
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
ll gcd(ll a, ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) {return a/gcd(a,b)*b;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    string S;
    cin >>S;
    
    if(S[0]=='9'||S[1]=='9'){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }



    return 0;
    

}

Measured memory_bytes: 3608
N = int(input())

def check(N):
    hon = [2,4,5,7,9]
    
    if N == 3:
        print('bon')

    elif [x for x in hon if x == N]:
        print('hon')

    else:
        print('pon')

    exit()


if N > 9 and N < 100:
    N = N%10
    check(N)
elif N>100:
    N = N%100
    N = N%10
    check(N)
else:
    check(N)


Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define REP(i, e) for(int (i) = 0; (i) < (e); ++(i))
#define FOR(i, b, e) for(int (i) = (b); (i) < (e); ++(i))
#define ALL(c) (c).begin(), (c).end()
#define PRINT(x) cout << (x) << "\n"
using namespace std;
using ll = long long; using pint = pair<int, int>; using pll = pair<ll, ll>;
template<typename T> auto compare = [](T x, T y) -> bool{return (x < y);};
const int MOD = 1000000007;

signed main(){
    string S;
    cin >> S;
    if(S == "ABC") PRINT("ARC");
    else PRINT("ABC");
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
//#define int long long
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,n) for(int i=1;i<n;i++)
#define rev(i,n) for(int i=n-1;i>=0;i--)
#define all(v) v.begin(),v.end()
#define P pair<int,int>
#define len(s) (int)s.size()
#define pb push_back

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;
}
constexpr int mod = 1e9+7;
//constexpr int inf = 3e18;

int D;
int C[26];
int A[365][26];
int con[365];
set<int>st[26];
int score(){
	vector<int>last(26,-1);
	int res=0;
	rep(i,D){
		last[con[i]]=i;
		res+=A[i][con[i]];
		rep(j,26){
			res-=C[j]*(i-last[j]);
		}
	}
	return res;
}
int change(int x,int y){
	int res=A[x][y]-A[x][con[x]];
	auto pre_old=--st[con[x]].lower_bound(x);
	auto next_old=st[con[x]].upper_bound(x);
	res+=(*next_old-x-1)*(*next_old-x)/2*C[con[x]];
	res-=(x-*pre_old+*next_old-*pre_old-1)*(*next_old-x)/2*C[con[x]];
	auto pre_new=--st[y].lower_bound(x);
	auto next_new=st[y].lower_bound(x);
	res+=(x-*pre_new+*next_new-*pre_new-1)*(*next_new-x)/2*C[y];
	res-=(*next_new-x-1)*(*next_new-x)/2*C[y];
	return res;
}
unsigned long xor128() {
  static unsigned long x=123456789, y=362436069, z=521288629, w=88675123;
  unsigned long t=(x^(x<<11));
  x=y; y=z; z=w;
  return ( w=(w^(w>>19))^(t^(t>>8)) );
}
double rand_double(){
	return (long double)xor128()/ULONG_MAX;
}
signed main(){
	cin>>D;
	rep(i,26){
		cin>>C[i];
		st[i].insert(-1);st[i].insert(D);
	}
	vector<int>last(26,-1);
	rep(i,D){
		int mx=-mod,idx;
		rep(j,26){
			cin>>A[i][j];
			if(chmax(mx,A[i][j]+C[j]*(i-last[j])*4))idx=j;
		}
		con[i]=idx;st[idx].insert(i);
       last[idx]=i;
	}
	int score_=score();
	cerr<<score_<<endl;
	double C=1980*100;
	int cnt=0;
	while(1000.*clock()/CLOCKS_PER_SEC<=1980){
		int x=xor128()%D,y;
		do{
			y=xor128()%26;
		}while(con[x]==y);
		int diff=change(x,y);
		double ti=1980-1000.*clock()/CLOCKS_PER_SEC;
		double rem=ti/1980.;
		if(diff>=0||(ti/C>rand_double()&&diff>=-11000.*rem)){
			score_+=diff;
			st[con[x]].erase(x);
			con[x]=y;
			st[y].insert(x);
		}
		cnt++;
		if(cnt%100000==0)cerr<<score_<<endl;
	}
	rep(i,D)cout<<con[i]+1<<"\n";
	cerr<<score_<<" "<<cnt<<endl;
}


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

int const N = 1234567;

int start[N], end[N];

int main() {
  int n, m;
  scanf("%d%d", &n, &m);
  for (int i = 0; i < m; i++) {
    int v, u;
    scanf("%d%d", &v, &u);
    --v;
    --u;
    if (v > u) std::swap(v, u);
    if (v == 0) start[u] = true;
    if (u == n - 1) end[v] = true;
  }
  for (int i = 1; i < n - 1; i++) {
    if (start[i] && end[i]) {
      puts("POSSIBLE");
      return 0;
    }
  }
  puts("IMPOSSIBLE");
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  int a, b, c; cin >> a >> b >> c;
  set<int> st;
  st.insert(a);
  st.insert(b);
  st.insert(c);
  cout << SZ(st) << endl;
}


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

int main() {
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    
    if (A + B > C + D) {
        cout << "Left" << endl;
    }
    else if (A + B == C + D) {
        cout << "Balanced" << endl;
    }
    else {
        cout << "Right" << endl;
    }
}

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

long long n, a = 1, b = 100;
vector<int> ans;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	for (int i = 1; i <= 100; i++)
		ans.push_back(i);
	while (n) {
		if (n & 1) {
			ans.push_back(a++);
			n >>= 1;
		}
		else {
			ans.push_back(b--);
			n--;
		}
	}
	cout << ans.size() << '\n';
	for (int x: ans)
		cout << x << ' ';
}

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

int main(int argc, char *argv[])
{
    int n, m, d, p, res, cnt[11];
    while (cin >> n >> m, n | m) {
        res = 0;
        for (int i = 0; i < 11; ++i)
            cnt[i] = 0;
        for (int i = 0; i < n; ++i) {
            cin >> d >> p;
            cnt[p] += d;
        }
        for (int i = 10; i > 0; --i) {
            if (m > cnt[i]) {
                m -= cnt[i];
            } else {
                res += i * (cnt[i] - m);
                m = 0;
            }
        }
        cout << res << endl;
    }
    return 0;
}

Measured memory_bytes: 1160
import math

def solve(N,M,Xs):
    if N >= M:
        return 0

    Ds = [abs(Xs[i]-Xs[i+1]) for i in range(len(Xs)-1)] # Ds[j] := distance between j and j+1

    Ds.sort()
    #print(Ds)
    #print(math.ceil(N/2))

    #ntake = math.ceil(N/2)
    ntake = N-1

    return sum(Ds[0:len(Ds)-ntake])

def main():
    N, M = map(int, input().split())
    Xs = list(map(int, input().split()))
    Xs.sort()
    print(solve(N,M,Xs))


if __name__ == '__main__':
    main()

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

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

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

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

  sort(a, a+n, greater<int>());

  int d = a[m-1], sum = accumulate(a, a+n, 0);

  if (d * 4 * m < sum) cout << "No\n";
  else cout << "Yes\n";

  return (0);
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ll long long
using namespace std;
#define mk  make_pair
#define pb  push_back
#define pi 3.141592653589793238

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    double n;
    cin>>n;
    double ans=2*pi*n;
    cout<<fixed<<setprecision(20)<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3804
S = input()
m = 0
cur = 0
a = [(-1, 0, 0)]

for n, s in enumerate(S):

    if s == '/':
        area = 0
        cur += 1

        while a and a[-1][2] < cur <= m:
            area += a.pop()[1]

        if a and a[-1][2] == cur:
            area += (n - a[-1][0] - 1)
        a.append((n, area, cur))
        m = max(m, cur)

    else:
        if s == '\\': cur -= 1
        a.append((n, 0, cur))
l = [str(x[1]) for x in a if x[1] != 0]
print(sum([x[1] for x in a]))
if len(l):
    print(
        '{} {}'.format(
            len(l),
            ' '.join(l)
        )
    )
else:
    print(0)



Measured memory_bytes: 8716
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll mod = 1000000007;

using Graph = vector<vector<int>>;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int h,w,n;
    cin >> h >> w >> n;
    for(int i=0; i<=max(h,w); ++i) {
        if (i*max(h,w)>=n) {
            cout << i << "\n";
            break;
        }
    }
}


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

using std::cin;
using std::cout;
using std::endl;

using std::string;
using std::pair;

using std::vector;
using std::sort;

int main(){
    int N,Y;
    cin >> N >> Y;
    for(int x=0;x<=N;x++){
        for(int y=0;x+y<=N;y++){
            int z=N-x-y;
            if(10000*x+5000*y+1000*z==Y){
                cout << x << " " << y << " " << z << endl;
                return 0;
            }
        }
    }
    cout << "-1 -1 -1" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String S = sc.next();
		long K = sc.nextLong();
		char c = '.';
		for(int i = 0; i < S.length(); i++) {
			if(i == K - 1) {
				c = S.charAt(i);
				break;
			}else if(S.charAt(i) != '1') {
				c = S.charAt(i);
				break;
			}
		}
		System.out.println(c);
	}
}

Measured memory_bytes: 23892
#include <iostream>
#include <cstdio>
using namespace std;
//#define MAX 10000

int main()
{
    int n,m,i,j;
    cin >> n >> m;
    int c[n],T[n+1];
    for(i=0;i<m;i++)
        cin >> c[i];
    //T[0] = 0;
    for(i=0;i<=n;i++)
        T[i] = i;
    //for(i=1;i<=n;i++)
    for(i=0;i<m;i++)
        for(j=1;j<=n;j++)
            if(c[i]<=j)
                T[j]=min(T[j],T[j-c[i]]+1);
    cout << T[n] << endl;
    return 0;
}



Measured memory_bytes: 3276
#ABC075C
N, M=map(int, input().split())
ab = []
for i in range(M):
    ab.append(list(map(int, input().split())))
visit_list=[0]*N
ans=0
#i番目の2次元配列を除く配列を使って、島jとその隣の未訪問の島にチェックを入れる
def follow(i, ab, j):
    visit_list[j-1]=1
    for k in range(M):
        if k!=i:
            if ab[k][0]==j:
                if visit_list[ab[k][1]-1]==0:
                    follow(i, ab, ab[k][1])
            if ab[k][1]==j:
                if visit_list[ab[k][0]-1]==0:
                    follow(i, ab, ab[k][0])
for i in range(M):
    visit_list=[0]*N
    follow(i, ab, 1)
    if sum(visit_list)!=N:
        ans+=1
print(ans)


Measured memory_bytes: 3064
# -*- coding: utf-8 -*-
n = int(input())
a = [int(i) for i in input().split()]

ans = 0
for i in a:
    if i % 2 == 0:
        tmp = 0
        while True:
            if i % 2 == 1:
                break
            else:
                i /= 2
                tmp += 1
        ans += tmp
print(ans)


Measured memory_bytes: 4148
N, K = map(int, input().split())

a = []
for i in range(N):
    t, d = map(int, input().split())
    a.append((t, d))
a.sort(key=lambda x:x[1], reverse=True)
#print(a)

vmax = 0
s = set()
q = []
for i in range(K):
    vmax += a[i][1]
    if a[i][0] in s:
        q.append(a[i][1])
    s.add(a[i][0])
vmax += len(s)**2   #add the variety bonus
#print(s)
#print(q)
#print(vmax)

i += 1   # same as i = K
v = vmax
while i < N and q:
    if a[i][0] not in s:
        v -= q.pop() + len(s)**2
        v += a[i][1] + (len(s)+1)**2
        vmax = max(vmax, v)
        s.add(a[i][0])
    i += 1
#print(s)
#print(q)
print(vmax)


Measured memory_bytes: 19216
#include <bits/stdc++.h>
                                        #include<iostream>
                                        #include<cstdio>
                                        #include<vector>
                                        #include<queue>
                                        #include<map>
                                        #include<cstring>
                                        #include<string>
                                        #include <math.h>
                                        #include<algorithm>
                                    //    #include <boost/multiprecision/cpp_int.hpp>
                                        #include<functional>
                                #define int long long
                                        #define inf  1000000007
                                        #define pa pair<int,int>
                                        #define ll long long
                                        #define pal pair<double,pa>
                                        #define ppa pair<int,int>
                                        #define ppap pair<pa,pa>
                                        #define ssa pair<string,int>
                                        #define  mp make_pair
                                        #define  pb push_back
                                        #define EPS (1e-10)
                                        #define equals(a,b) (fabs((a)-(b))<EPS)
                                  #define VI vector<int>
                                        using namespace std;
 
 
int gcd(int a,int b){
    if(a<b) return gcd(b,a);
    if(b==0) return a;
    if(a%b==0) return b;
    return gcd(b,a%b);
}
map<int,int>ma;
           signed main(){
               int n;
  cin>>n;
            for(int i=0;i<n;i++){
                int k;
            cin>>k;
                ma[k]++;
            }
            int u;
            int ans=0;
            cin>>u;
            for(int i=0;i<u;i++){
            int k;
                cin>>k;
                if(ma[k]>0) ans++;
             
            }
             
            cout<<ans<<endl;
           }
             

Measured memory_bytes: 12448
//Wrong answer on test inf.
#include<bits/stdc++.h>
#define rep(i,x,y) for (int i=(x);i<=(y);i++)
#define ll long long
#define inf 1000000001
#define y1 y1___
using namespace std;
char gc(){
	static char buf[100000],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++;
}
#define gc getchar
ll read(){
	char ch=gc();ll x=0;int op=1;
	for (;!isdigit(ch);ch=gc()) if (ch=='-') op=-1;
	for (;isdigit(ch);ch=gc()) x=(x<<1)+(x<<3)+ch-'0';
	return x*op;
}
#define N 3000005
int n,a[N],b[N],num[N];
int Max(int x,int y){return num[x]>num[y]?x:y;}
int main(){
	n=read();
	rep (i,0,(1<<n)-1){
		num[i]=read(),b[i]=0,a[i]=i;
		if (num[b[i]]>num[a[i]]) swap(b[i],a[i]);
	}
	rep (j,0,n-1) rep (i,1,(1<<n)-1)
		if (!(i>>j&1)){
			if (num[a[i]]>num[a[i|1<<j]]){
				b[i|1<<j]=Max(b[i],a[i|1<<j]);
				a[i|1<<j]=a[i];
			} else{
				if (a[i]==a[i|1<<j]) b[i|1<<j]=Max(b[i|1<<j],b[i]);
				else b[i|1<<j]=Max(b[i|1<<j],a[i]);
			}
		}
	int ans=0;
	rep (i,1,(1<<n)-1) printf("%d\n",ans=max(ans,num[a[i]]+num[b[i]]));
	return 0;
}

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

signed main(void){
  string A,B; cin >> A >> B;
  int n = A.size();
  int m = B.size();
  
  for(int i = 0; i+m <= n; i++){
   
    string res = A.substr(i,m);
    
    bool ok = true;
    
    for(int j = 0; j < m; j++){ 
      if( res[j] != B[j] && B[j] != '_' ){ ok = false;}
      
    }
    
    if( ok ){ cout << "Yes" << endl; return 0;}
    
  }
  
  cout << "No" << endl; 
  
  return 0;
}


Measured memory_bytes: 3216
buf[20000];char*p=buf;
i,w;
main(){
	read(0,buf,20000);
	for(;*p>10;p++)w=*p==32?0:w*10+*p-48;
	for(;i++<w+1;)putchar_unlocked('#');
	for(;*p>0;p++){
		if(*p==10)putchar_unlocked('#'),putchar_unlocked(10),putchar_unlocked('#');
		else putchar_unlocked(*p);
	}
	for(i=0;i++<w+1;)putchar_unlocked('#');
}

Measured memory_bytes: 128
#include <stdio.h>
#include <stdlib.h>
int func(const void *a, const void *b){
  return *(int*)a - *(int*)b;
}
int main(void){
  int n, m, x, y, xcity[100] = {0}, ycity[100] = {0};
  scanf("%d %d %d %d", &n, &m, &x, &y);getchar();
  for(int i = 0; i < n; i++){
    scanf("%d", &xcity[i]);getchar();
  }
  for(int i = 0; i < m; i++){
    scanf("%d", &ycity[i]);getchar();
  }
  
  qsort(xcity, n, sizeof(int), func);
  qsort(ycity, m, sizeof(int), func);
  if(x < y && xcity[n - 1] < ycity[0] && xcity[n - 1] < y && x < ycity[0]){
    printf("No War\n");
  }else{
    printf("War\n");
  }
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdlib>
#include <string>
#include <algorithm>
#include <vector>
#include <sstream>
using namespace std;

int main(){
  int n;
  string s;
  int max=0;
  cin >> n >> s;
  string ei[] = {"a","b","c","d","e","f","g","h","i","j","k","l",
            "m","n","o","p","q","r","s","t","u","w","v","x","y","z"};


  for(int i=0;i<n;i++){
    string x,y;
    int sum=0;
    x=s.substr(0,i);
    y=s.substr(i,n);
    for(string j : ei){
      if((x.find(j) != std::string::npos)&&
         (y.find(j) != std::string::npos)){
        sum++;
      }
    }
    if(max<sum){
      max=sum;
    }

  }

  cout << max << endl;
  return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using WGraph = vector<vector<pair<int, ll>>>;

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

constexpr int dx[4] = {-1, 0, 0, 1}, dy[4] = {0, -1, 1, 0};
constexpr int INF = 1e9;
constexpr int MOD = 1e9 + 7;
constexpr long long LINF = 1e18;
constexpr double EPS = 1e-10;
constexpr double PI = M_PI;
#pragma endregion

ll rec(int l, int r, vector<vector<ll>> &dp, const vector<ll> &a) {
    if (dp.at(l).at(r) != LINF) return dp.at(l).at(r);
    if (l == r) return dp.at(l).at(r) = 0;
    ll res = LINF;
    for (int i=l; i<r; i++) {
        chmin(res, rec(l, i, dp, a) + rec(i+1, r, dp, a));
    }
    return dp.at(l).at(r) = res + a.at(r) - a.at(l-1);
}

void solve() {
    int n;
    cin >> n;
    vector<ll> a(n+1);
    for (int i=1; i<n+1; i++) {
        cin >> a.at(i);
    }

    for (int i=1; i<n+1; i++) {
        a.at(i) += a.at(i-1);
    }

    vector<vector<ll>> dp(n+1, vector<ll>(n+1, LINF));

    cout << rec(1, n, dp, a) << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(20);

    solve();

    return 0;
}


Measured memory_bytes: 1536
#UnionFind
import sys
sys.setrecursionlimit(10**9)
class UnionFind:
  def __init__(self, n):
    self.n = [-1]*n
    self.r = [0]*n
    self.siz = n

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

  def unite(self, x, y):
    x = self.find_root(x)
    y = self.find_root(y)
    if x == y:
      return
    elif self.r[x] > self.r[y]:
      self.n[x] += self.n[y]
      self.n[y] = x
    else:
      self.n[y] += self.n[x]
      self.n[x] = y
      if self.r[x] == self.r[y]:
        self.r[y] += 1
    self.siz -= 1

  def root_same(self, x, y):
    return self.find_root(x) == self.find_root(y)

  def count(self, x):
    return -self.n[self.find_root(x)]

  def size(self):
    return self.siz

n,m=map(int,input().split())
u=UnionFind(n)
for _ in range(m):
  a,b=map(int,input().split())
  a-=1
  b-=1
  u.unite(a,b)
ans=0
for i in range(n):
  ans=max(ans,u.count(i))
print(ans)


Measured memory_bytes: 14516
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<tuple>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define Per(i,sta,n) for(int i=n-1;i>=sta;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
const ld eps = 1e-8;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;

string s;

void solve(){
    cin >> s;
    int n=s.length();
    bool flag=true;
    rep(i,n){
        if(s[i]!=s[n-i-1]) flag=false;
        //cout << (char)s[i] << "";
    }
    //cout << "" << endl;
    rep(i,(n-1)/2){
        if(s[i]!=s[(n-1)/2-i-1]) flag=false;
        //cout << (char)s[(n-1)/2-i-1] << "";
    }
    //cout << "" << endl;
    rep(i,(n-1)/2){
        if(s[i+(n+1)/2]!=s[(n+1)/2+(n-1)/2-i-1]) flag=false;
        //cout << (char)s[(n+1)/2+(n-1)/2-i-1] << "";
    }
    //cout << "" << endl;
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(50);
    solve();
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll     = long long;
using pii    = pair<int, int>;
using pll    = pair<ll, ll>;
using vi     = vector<int>;
using vl     = vector<ll>;
using vvi    = vector<vi>;
using vvl    = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    string s, t;
    cin >> s >> t;
    int q;
    cin >> q;
    vi a(q), b(q), c(q), d(q);
    for (int i = 0; i < q; ++i) {
        cin >> a[i] >> b[i] >> c[i] >> d[i];
    }
    vi ssum(s.size(), 0), tsum(t.size(), 0);
    for (int i = 0; i < s.size(); ++i) {
        if (s[i] == 'A')
            ssum[i] = 1;
        else
            ssum[i] = 2;
    }
    for (int i = 0; i < t.size(); ++i) {
        if (t[i] == 'A')
            tsum[i] = 1;
        else
            tsum[i] = 2;
    }
    for (int i = 1; i < s.size(); ++i) {
        ssum[i] += ssum[i - 1];
    }
    for (int i = 1; i < t.size(); ++i) {
        tsum[i] += tsum[i - 1];
    }
    ssum.insert(ssum.begin(), 0);
    tsum.insert(tsum.begin(), 0);
    for (int i = 0; i < q; ++i) {
        int snum = ssum[b[i]] - ssum[a[i] - 1];
        int tnum = tsum[d[i]] - tsum[c[i] - 1];
        if (snum % 3 == tnum % 3)
            cout << "YES" << "\n";
        else
            cout << "NO" << "\n";
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  int A[N];
  int sum = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    sum += A[i];
  }
  
  int x[N];
  x[0] = sum;
  for (int i = 1; i <= (N-1)/2; i++) {
    x[0] = x[0] - 2 * A[2 * i - 1];
  }
  for (int i = 1; i < N; i++) {
    x[i] = 2 * A[i-1] - x[i-1];
  }
  
  for (int i = 0; i < N; i++) {
    cout << x[i] << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <vector>
#include <set>
#include <stack>
int N;
int P = 1000000007;
typedef long long ll;
using namespace std;

ll toPower(ll a, ll power) {
  if(power == 0) {
    return  1;
  }
  if(a == 0) {return 0;}
  ll foo = toPower(a, power/2);
  if(power%2 == 0) {
    return (foo*foo) % P;
  } 
  return (((foo*foo)%P)*a)%P;
}

ll inv(ll a) {
  return toPower(a, P-2);
}
struct Node {
  int parent;
  vector<int> children;
  int numDesc;
};

int main() {
  cin >> N;
  vector<set<int>> edges(N);
  for(int i = 0; i< N-1; i++) {
    //cout << i << endl;
    int a,b;
    cin >> a >> b;
    a--; b--;
    edges[a].insert(b);
    edges[b].insert(a);
  }

  vector<Node> nodes(N);
  stack<pair<int,int>> st;
  st.emplace(0,-1);
  while(!st.empty()) {
    auto node_parent = st.top(); st.pop();
    auto node = node_parent.first; auto parent = node_parent.second;
    nodes[node].parent = parent;

    for(const auto neighbor: edges[node]) {
      if(neighbor != parent) {
        st.emplace(neighbor,node);
        nodes[node].children.push_back(neighbor);
      }
    }
  }

  vector<ll> numDesc(N,0);
  function<ll(int)> fillNumDesc =  [&](int node) {
    if(numDesc[node] != 0) {return numDesc[node];}
    ll ans = 1;
    for(const auto ch : nodes[node].children) {
      ans += fillNumDesc(ch);
    }
    numDesc[node] = ans;
    return ans;
  };

  fillNumDesc(0);

 // std::copy(numDesc.begin(), numDesc.end(), std::ostream_iterator<ll>(std:://cout << "numDesc ", " "));
  //cout << endl;

  ll half = inv(2);
  function<ll(vector<ll>)> chanceThrough = [&](vector<ll> nSizes) {
    vector<ll> chanceBlack(nSizes.size());
    ll ans = 1;
    ll chanceAllWhite = toPower(half,N-1);
    for(int i = 0; i < nSizes.size() ; i++) {
      chanceBlack[i] = ((1-toPower(half, nSizes[i]))+P)%P;
    }
    ans -= chanceAllWhite; 
    for(int i = 0; i < nSizes.size(); i++) {
      ans -= (chanceBlack[i]*toPower(half,(N-nSizes[i]-1))+P)%P;
      ans += P; ans %= P;
    }  
    ans += P; ans %= P;
    //cout << "chance go through " << ans << endl;
    return ans;
  };

  ll ans = 0.0;
  for(int i = 0; i < N; i++) {
//    //cout << "Node " << i << " has parent " << nodes[i].parent << " with children # " << nodes[i].children.size() << " and desc # " << numDesc[i] << endl;
    vector<ll> nSizes;
    for(const auto child: nodes[i].children) {
      nSizes.push_back(numDesc[child]);
    } nSizes.push_back(N-numDesc[i]);
    ans += half*chanceThrough(nSizes);
    ans += P; ans %=P;
  }

  cout << ans << endl;




}




Measured memory_bytes: 49664
#include "bits/stdc++.h"
#include "ext/pb_ds/assoc_container.hpp"
#include "ext/pb_ds/tree_policy.hpp"
#include "ext/rope"

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template <typename T> using order_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template <typename T1, typename T2> using order_map = tree <T1, T2, less <T1>, rb_tree_tag, tree_order_statistics_node_update>;

template <class T> bool MIN(T &a, T b) { return a > b ? (a = b, true) : false; }
template <class T> bool MAX(T &a, T b) { return a < b ? (a = b, true) : false; }

#define ll              long long int
#define endl            '\n'
#define pii             pair <int, int>
#define pll             pair <ll, ll>
#define mk              make_pair
#define ff              first
#define ss              second
#define all(a)          (a).begin(), (a).end()
#define rall(a)         (a).rbegin(), (a).rend()
#define eb              emplace_back
#define pb              push_back
#define LINE            __LINE__

static const int maxn = 1e6 + 5;
static const int logn = 19;

signed main()
{
      ios_base::sync_with_stdio(false);
      cin.tie(nullptr);

     	string s;
	cin >> s;
	int n = s.size();
	int pos = 0;
	int len = 0;
	vector <int> ans(n + 1);
	for (int i = 1; i <= n; i++) {
		char ch = s[i - 1];
		if (ch == 'R') {
			pos = i; 
			len = 0;
		}
		else {
			len++;
			if (len & 1) {
				ans[pos + 1]++;
			}
			else {
				ans[pos]++;
			}
		}
	}
	pos = 0;
	len = 0;
	for (int i = n; i >= 1; i--) {
		char ch = s[i - 1];
		if (ch == 'L') {
			pos = i;
			len = 0;
		}
		else {
			len++;
			if (len & 1) {
				ans[pos - 1]++;
			}
			else {
				ans[pos]++;
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		cout << ans[i] << " \n"[i == n];
	}
      #ifndef ONLINE_JUDGE
            cerr << endl << "Time : " << 1.0 * clock() / CLOCKS_PER_SEC << " s." << endl;
      #endif // ONLINE_JUDGE
}


Measured memory_bytes: 1104
#include <bits/stdc++.h>
#define ll long long
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end))) // rep(i, 1, 5) --> {1,2,3,4} // rep(i, 5, 1) --> {4,3,2,1} // rep(it, end(v), begin(v)) --> *it

using namespace std;

map<ll, ll> trial_division(ll n)
{
    map<ll, ll> factorization;
    while (n % 2 == 0)
    {
        factorization[2]++;
        n /= 2;
    }
    for (ll d = 3; d * d <= n; d += 2)
    {
        while (n % d == 0)
        {
            factorization[d]++;
            n /= d;
        }
    }
    if (n > 1)
        factorization[n]++;
    return factorization;
}

int main()
{
    ll n; cin >> n;
    map<ll, ll> mp = trial_division(n);
    ll res = 0;
    bool y = false;
    for (auto x:mp)
    {
        ll nb = 1;
        ll cnt = 0;
        rep(k, 1, x.second + 1)
        {
            cnt += k;
            if (cnt > x.second)
                break;
            nb *= x.first;
            n = n / nb;
            if (n == 0)
            {
                y = true;
                break;
            }
            res++;
        }
        if (y == true)
            break;
    }
    cout << res;
    return 0;
}

Measured memory_bytes: 3620
#include<iostream>
#include<vector>
using namespace std;
 
int main(){
    int N;
    long long K;
    cin>>N>>K;
    vector<long long>A(N);
    for(int i=0;i<N;i++)cin>>A[i];

    long long res=0;
    for(int d=60;d>=-1;d--){
        if(d!=-1 && !(K&(1LL<<d)))continue;

        long long tmp=0;
        for(int e=60;e>=0;e--){
            long long mask=1LL<<e;
            int num=0;
            for(int i=0;i<N;i++)if(A[i]&mask)++num;

            if(e>d){
                if(K&mask)tmp+=mask*(N-num);
                else tmp+=mask*num;

            }
            else if(e==d){
                tmp+=mask*num;
            }
            else{
                tmp+=mask*max(num,N-num);
            }
            
        }
        res=max(res,tmp);
    }
    cout<<res<<endl;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define M (1000000007)
#define N (100010)
int n;
char a[N][15];
ll ans;
map<string,int>mp;

int main(){
	scanf("%d",&n);
	for (int i=1;i<=n;i++) scanf("%s",a[i]);
	for (int i=1;i<=n;i++){
		sort(a[i],a[i]+10);
		if (mp[a[i]]) ans+=mp[a[i]];
		++mp[a[i]];
	}
	printf("%lld",ans);
}


Measured memory_bytes: 12672
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String weather = s.nextLine();
        int count = 0, max =0;
        for(int i = 0; i < 3; ++i) {
            if(weather.charAt(i) == 'R') {
                count++;
            } else {
                max = Math.max(max, count);
                count = 0;
            }
        }
        max = Math.max(max, count);
        System.out.println(max);
   }
}


Measured memory_bytes: 35644
#include <bits/stdc++.h>
#define pi 3.14159
using namespace std;
typedef long long LL;
const LL MOD = 1e9 + 7;
const int N = 1e5 + 7, M = 1e7, OO = 0x3f3f3f3f;
#define AC ios::sync_with_stdio(0);cin.tie(0);cout.tie(0); cin.sync_with_stdio(0);
int main()
{
    int x,y,sum,z,v,sum2;
    cin>>x>>y>>z>>v;
    sum=x*y;
    sum2=z*v;
    cout<<max(sum,sum2);



    return 0;
}


Measured memory_bytes: 3600
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
int gcd(int a,int b) {return b==0?a:gcd(b,a%b);}
struct ConfusionRatio
{
    int fm,fz;
    ConfusionRatio(int a=1,int b=1)
    {
        int g=gcd(a,b);
        fz=a/g;
        fm=b/g;
    }
    bool operator < (const ConfusionRatio &t) const
    {
        return (fz*1LL*t.fm-fm*1LL*t.fz)<=0;
    }
    bool operator == (const ConfusionRatio &t)
    {
        return (fz*1LL*t.fm-fm*1LL*t.fz)==0;
    }
}t[2000005];
int n,a[25];
bool dp[21][200002];
bool check(int id)
{
    int l[25],r[25];
    for(int i=0;i<n;++i)
    {
        long long delt=t[id].fz*1LL*a[i]/t[id].fm;
        l[i]=(int)max(1LL,a[i]-delt);
        r[i]=(int)min(2*a[i]-1LL,a[i]+delt);
    }
    memset(dp,0,sizeof(dp));
    for(int i=l[0];i<=r[0];++i) dp[0][i]=1;
    for(int i=0;i<n-1;++i)
    {
        for(int j=l[i];j<=r[i];++j)
        {
            if(!dp[i][j]) continue;
            int m1=l[i+1]/j,m2=r[i+1]/j;
            while(m1*j<l[i+1]) m1++;
            for(int t=m1;t<=m2;++t) dp[i+1][t*j]=1;
        }
    }
    for(int i=l[n-1];i<=r[n-1];++i) if(dp[n-1][i]) return true;
    return false;
}
int main()
{
    //freopen("in.txt","r",stdin);
    int m=0;
    scanf("%d",&n);
    t[m++]=ConfusionRatio(0,1);
    for(int i=0;i<n;++i)
    {
        scanf("%d",&a[i]);
        for(int j=1;j<a[i];++j) t[m++]=ConfusionRatio(j,a[i]);
    }
    sort(t,t+m);
    int N=0;
    for(int i=0;i<m;)
    {
        t[N++]=t[i];
        int j=i+1;
        while(j<m&&(t[j]==t[i])) j++;
        i=j;
    }
    int l=0,r=N-1;
    while(l+1<r)
    {
        int mid=(l+r)>>1;
        if(check(mid)) r=mid;
        else l=mid+1;
    }
    if(check(l)) printf("%.12f\n",t[l].fz*1.0/t[l].fm);
    else printf("%.12f\n",t[r].fz*1.0/t[r].fm);
    return 0;
}

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

using namespace std;

#ifdef DGC
#include "debug.h"
#else
#define debug(...) 9715
#endif
typedef long long ll;
typedef long double ld;
typedef complex<double> point;
#define F first
#define S second



int main()
{
	#ifdef DGC
		//freopen("a.in", "r", stdin);
		//freopen("b.out", "w", stdout);
	#endif

	ios_base::sync_with_stdio(0), cin.tie(0);

	int n;
	cin >> n;
	vector<vector<int>> mp(10, vector<int>(10));
	for (int i = 1; i <= n; ++i)
	{
		string s = to_string(i);
		++mp[s[0]-'0'][s.back()-'0'];
	}

	ll ans = 0;
	for (int i = 0; i < 10; ++i)
		for (int j = 0; j < 10; ++j)
			ans += (ll)mp[i][j] * mp[j][i];
	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,a,b,x,y,t,tt;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>tt>>x>>y;
        if((tt-t)<abs(x-a)+abs(y-b)||(tt-t)%2!=((abs(x-a)+abs(y-b))%2)){
            cout<<"No"<<endl;
            return 0;
        }
        a=x,t=tt,b=y;
    }
    cout<<"Yes"<<endl;
}


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

int main()
{
    int n;
    string s;
    cin >> n >> s;

    int ans = 0;
    rep (i, n - 2)
        if (s[i] == 'A' && s[i + 1] == 'B' && s[i + 2] == 'C')
            ans++;

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define put(x) cout << x << endl;
using namespace std;
int main()
{
    ll n, a, b;
    cin >> n >> a >> b;
    
    put(a * (n / (a + b)) + min(a, n % (a + b)))
    return 0;
}

Measured memory_bytes: 3564
a , b , c = map(int,input().split())
k = int(input())
p = 0
for i in range(k):
    if p == 0:
        if b <= a:
            b *= 2
            continue
        elif b > a:
            p = 1
    if p == 1:
        c *= 2
        if c > b:
            p = 2
if p == 2:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 61672
#include<iostream>
#include<cstdio>
#include<cstring>

const int N=52,M=N*N;

bool G[N][N]; 
bool sel[N];

namespace CAO
{
	int begin[N],next[M],to[M],id[M];
	int e;

	void add(int x,int y,int z)
	{
		to[++e]=y;
		next[e]=begin[x];
		begin[x]=e;
		id[e]=z;
	}

	int S;

	void dfs(int p)
	{
		if(G[S][p])return;
		G[S][p]=1;
		for(int i=begin[p];i;i=next[i])
			if(sel[id[i]])dfs(to[i]);
	}

	void work()
	{
		memset(G,0,sizeof(G));
		for(int i=0;i<=50;i++)dfs(S=i);
	}
}

namespace NaoYuMaoHaoQiangAAA_WoHaoCaiA
{
	int a[N],b[N];
	int n;
	bool judge()
	{
		for(int i=1;i<=n;i++)
			if(!G[a[i]][b[i]])return 0;
		return 1;
	}
	void solve()
	{
		scanf("%d",&n);
		for(int i=1;i<=n;i++)scanf("%d",a+i);
		for(int i=1;i<=n;i++)scanf("%d",b+i);

		for(int i=0;i<=50;i++)
			for(int j=1;j<=50;j++)
				CAO::add(i,i%j,j);

		for(int i=1;i<=50;i++)sel[i]=1;
		CAO::work();
		if(!judge()){printf("-1\n");return;}

		for(int i=50;i;i--)
		{
			sel[i]=0;
			CAO::work();
			if(!judge())sel[i]=1;
		}
		
		long long ans=0;
		for(int i=1;i<=50;i++)
			if(sel[i])ans|=1ll<<i;
		printf("%lld\n",ans);
	}
}

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


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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    map<int, int> foo, bar;
    for (int i = 0; i < n; i++) {
        int x;
        cin >> x;
        if (i & 1) {
            bar[x]++;
        } else {
            foo[x]++;
        }
    }
    vector<pair<int, int>> vec;
    for (auto i : foo) {
        vec.emplace_back(i);
    }
    sort(vec.begin(), vec.end(), [&](auto x, auto y) {
        return x.second > y.second;        
    });
    vector<pair<int, int>> idk;
    for (auto i : bar) {
        idk.emplace_back(i);
    }
    sort(idk.begin(), idk.end(), [&](auto x, auto y) {
        return x.second > y.second;        
    });
    if (vec.front().first != idk.front().first) {
        cout << n - vec.front().second - idk.front().second << '\n';
    } else {
        if ((int) vec.size() < 2) {
            cout << n / 2 << '\n';
        } else if (vec[1].second > idk[1].second) {
            cout << n - idk.front().second - vec[1].second << '\n';
        } else {
            cout << n - vec.front().second - idk[1].second << '\n';
        }
    }
    return 0;
}


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

int main(){
	string s;
	cin >> s;
	int K;
	cin >> K;
	set<string> ss;
	for(int i = 1; i <= min((int)s.size(), K); i++)
	{
		for(int j = 0; j+i <= (int)s.size(); j++)
		{
			ss.insert(s.substr(j, i));
		}
		
	}
	
	set<string>::iterator it = ss.begin();
	for(int i = 0; i < K-1; i++)
	{
		it++;
	}
	
	cout << *it << endl;	
	
	return 0;
}

Measured memory_bytes: 1664
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp2
{
    class Program2
    {
        static void Main(string[] args)
        {
            int a, b, c, d;
            /*
            string[] a = Console.ReadLine().Split(' ');
            long b = long.Parse(a[0]);
            long c = long.Parse(a[1]);
            long d;
            */

            a = int.Parse(Console.ReadLine());
            b = int.Parse(Console.ReadLine());
            c = a % 500;
            if (a <= b)
            {
                Console.Write("Yes");
            }
            else if (c == 0)
            {
                Console.Write("Yes");
            }
            else
            {
                if (c < b)
                {
                    Console.Write("Yes");
                }
                else
                    Console.Write("No");
            }

            //Console.Write(d);
        }
    }
}


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

int main(){
  string s, t;
  cin >> s >> t;
  vector<int> sv(26), tv(26);
  for(auto x : s) sv[x-'a']++;
  for(auto x : t) tv[x-'a']++;
  sort(sv.begin(), sv.end());
  sort(tv.begin(), tv.end());
  if(sv == tv) cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

Measured memory_bytes: 776
#pragma region Include
#include <bits/stdc++.h>
// #include <algorithm>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <iostream>
// #include <iterator>
// #include <map>
// #include <queue>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <unordered_map>
// #include <unordered_set>
// #include <vector>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define newl "\n"
#define out(x) cout << (x) << newl
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << newl
template <class T>
using VV = vector<vector<T>>;
#define Uni(v) (v).erase(unique((v).begin(), (v).end()), (v).end());

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

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

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;

string tostring(int i, int digit) {
  auto cur = cout.flags();
  stringstream ss;
  ss << setw(4) << setfill('0') << i;
  string ret = ss.str();
  cout.flags(cur);
  return ret;
}

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

#pragma endregion

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int H,A;
  cin>>H>>A;
  out((H-1)/A+1);
  return 0;
}

Measured memory_bytes: 384