akhauriyash/Code-Regression huggingface dataset:
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};
 
 
int main() {
  char a, b;
  cin >> a >> b;
  if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D')) {
    cout << "H" << endl;
  } else {
    cout << "D" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String args[]) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        System.out.println(Math.min(a, b) + Math.min(c, d));
    }
}


Measured memory_bytes: 23764
#include<iostream>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
#include<functional>
using namespace std;

#define INF 1<<21
#define DIV 1000000007

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

int main() {
  int n,a,c,color[8];
  int cnt = 0, ans1 = 0, ans2 = 0;
  for (int i = 0; i < 8; i++) {
	color[i] = 0;
  }

  cin >> n;

  for (int i = 0; i < n; i++) {
	cin >> a;
	c = a / 400;
	switch (c) {
	case 0: color[0] = 1;
	  break;
	case 1: color[1] = 1;
	  break;
	case 2: color[2] = 1;
	  break;
	case 3: color[3] = 1;
	  break;
	case 4: color[4] = 1;
	  break;
	case 5: color[5] = 1;
	  break;
	case 6: color[6] = 1;
	  break;
	case 7: color[7] = 1;
	  break;
	default:cnt++;
	}
  }

  for (int i = 0; i < 8; i++) {
	if (color[i] == 1) {
	  ans1++;
	}
  }

  ans2 = ans1 + cnt;
  if (ans1 == 0) {
	ans1 = 1;
  }

  cout << ans1 << " " << ans2 << endl;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <bitset>
#include <algorithm>
#include <functional>
#include <assert.h>
#include <iomanip>
using namespace std;
// const int N = 7005;
const int M = 1005;
const int INF = 0x3f3f3f3f;
const int MOD = 1000000007;
typedef long long ll;

int main() {
    int x, y;
    while(~scanf("%d %d", &x, &y)) {
        printf("%d\n", x + y/2);
    }
    return 0;
}


Measured memory_bytes: 256
H,W=map(int,input().split())
s=[input()for _ in range(H)]
M=[[0 for _ in range(W)] for _ in range(H)]

for h in range(H):
    for w in range(W):
        if h==0:
            if w==0: #原点
                if s[h][w]=="#":
                    M[h][w]=1
            elif w>0: #最上行
                if s[h][w]==".":
                    M[h][w]=M[h][w-1]
                else:
                    if s[h][w-1]=="#":
                        M[h][w]=M[h][w-1]
                    else:
                        M[h][w]=M[h][w-1]+1
        elif w==0: #最左列
            if s[h][w]==".":
                M[h][w]=M[h-1][w]
            else:
                if s[h-1][w]=="#":
                    M[h][w]=M[h-1][w]
                else:
                    M[h][w]=M[h-1][w]+1
        else: #一般的な位置
            if s[h][w]==".":
                M[h][w]=min(M[h-1][w],M[h][w-1])
            else:
                if s[h-1][w]=="." and s[h][w-1]==".":
                    M[h][w]=min(M[h-1][w],M[h][w-1])+1
                elif s[h-1][w]=="#" and s[h][w-1]==".":
                    M[h][w]=min(M[h-1][w],M[h][w-1]+1)
                elif s[h-1][w]=="." and s[h][w-1]=="#":
                    M[h][w]=min(M[h-1][w]+1,M[h][w-1])
                else:
                    M[h][w]=min(M[h-1][w],M[h][w-1])

print(M[H-1][W-1])

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

bool isprime(int n){
    double rootn = sqrt(n);
    if (n < 2){
        return false;
    }
    else if (n == 2){
        return true;
    }
    else if (n % 2 == 0){
        return false;
    }
    else{
        for(int i = 3; i <= rootn; i += 2){
            if(n % i == 0){
                return false;
            }
        }
        return true;
    }
}


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

    while(A >= B){
        B *= 2;
        K--;
    }
    while(B >= C){
        C *= 2;
        K--;
    }
    if(K >= 0){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
#include <stdio.h>
 
using namespace std;
 
#define int long long
#define rep(i, a, b) for (int i = (a); i <= (b); ++i)

void solve();

signed main () {
    cout.precision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
    #endif
    int t = 1; 
    // cin >> t;	
    int tt = t;
    while (t--) { 
        solve();
    }
    return 0;
}
const int M = 1e9 + 7;
int n;
void solve() {
	cin >> n;
	int ans = 1;
	for (int i = 2; i <= n; i += 1) 
		ans *= i, ans %= M;
	cout << ans;
}     	

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

int main(){
  int N;
  cin >> N;
  string S;
  cin >> S;

  // 左側に白 右側に黒が並ぶようにする

  // 最初に境界を調べる。
  int left_count[N+1]; // 左から見ていって#がある数
  int right_count[N+1]; // 右から見ていって.が出現した数
  for (int i=0; i<N+1; i++){
    left_count[i] = 0;
    right_count[i];
  }
  int l_cnt = 0;
  int r_cnt = 0;
  for (int i=0; i<N+1; i++){
    if (i == 0){
      left_count[i] = 0;
    } else{
      if (S[i-1] == '#'){
        l_cnt += 1;
      }
      left_count[i] = l_cnt;
    }

    if (i == 0){
      right_count[N-i] = 0;
    } else{
      if (S[N-i] == '.'){
        r_cnt += 1;
      }
      right_count[N-i] = r_cnt;
    }
  }
  // 境界は left_count と right_count の和が最小になるところ？
  int min = N;
  for (int i=0; i<N+1; i++){
    if (min > left_count[i] + right_count[i]){
      min = left_count[i] + right_count[i];
    }
  }
  cout << min << endl;

  // int out = 0;
  // int flag = 1;
  // int left_idx = 0;
  // int right_idx = N-1;
  // while(1){
  //   if (left_idx == right_idx){
  //     break;
  //   }
  //   if (flag){
  //     if (S[left_idx] == '#'){
  //       out += 1;
  //       flag = 0;
  //     }
  //     left_idx += 1;
  //   } else{
  //     if (S[right_idx] == '.'){
  //       out += 1;
  //       flag = 1;
  //     }
  //     right_idx -= 1;
  //   }
  // }
  return 0;
}


Measured memory_bytes: 2180
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define pii pair < int , int >
#define F first
#define S second
#define endl '\n'
#define int long long
#define sync ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#pragma GCC optimize("Ofast,no-stack-protector,unroll-loops,fast-math")
#define kill(x) return cout<<x<<'\n', 0;
using namespace std;
const int N=2e5+100;
multiset <pair <pair <ld,pii>,int > > s[N];
multiset <int> ss;
vector <int> g[N];
ll val[N];
deque <char> d[N];
ll sz[N];
void dfs(ll v){
    for (auto u : g[v]){
        dfs(u);
        sz[v]+=sz[u];
        if (s[u].size()>s[v].size()){
            swap(s[u],s[v]);
            ///
        }
        while(s[u].size()){
            pair <pair <ld,pii>,int > x=*s[u].begin();
            s[v].insert(x);
            s[u].erase(s[u].begin());
        }
    }
    if (val[v]==0){
        s[v].insert({{0,{0,1}},v});
        d[v].pb('0');
        return ;
    }
    ld c1=1,k=1;
    ll nod=v;
    d[nod].pb('1');
    while(s[v].size()){
        pair <pair <ld,pii>,int > x=*s[v].begin();
        ll c2=x.F.S.F,k2=x.F.S.S,nod1=x.S;
        if (c1*k2>=k*c2){
            s[v].erase(s[v].begin());
            if (k>=k2){
                for (int i=0;i<d[nod1].size();i++){
                    d[nod].pb(d[nod1][i]);
                }
                k+=k2;
                c1+=c2;
            }
            else{
                for (int i=d[nod].size()-1;i>-1;i--){
                    d[nod1].push_front(d[nod][i]);
                }
                k+=k2;
                c1+=c2;
                nod=nod1;
            }
        }
        else break;
    }
    ld aa=c1/k;
    s[v].insert({{aa,{c1,k}},nod});
   // cout << v << endl;
}
int32_t main(){
    sync;
    ll n;
    cin >> n;
    for (int i=2;i<=n;i++){
        ll p;
        cin >> p;
        g[p].pb(i);
    }
    for (int i=1;i<=n;i++) cin >> val[i];
    dfs(1);
    vector <int> nod;
    while(s[1].size()){
        pair <pair <ld,pii>,int > x=*s[1].begin();
        s[1].erase(s[1].begin());
        nod.pb(x.S);
     //   cout << x.F.S.F << " " << x.F.S.S << " " << x.F.F << endl;
    }
    ll ans=0,c1=0;
    for (auto u : nod){
        for (int i=0;i<d[u].size();i++){
            if (d[u][i]=='1') c1++;
            else ans+=c1;
           // cout << d[u][i];
        }
      //  cout << endl;
    }
  //  cout << endl;
    cout << ans << endl;
}



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

int  i,j,n,k,h,w,a,b,c,d,x,y,z,ret;
int main(void){
  cin>>n>>a>>b;
  ret=a+b-n;
  cout<<min(a,b)<<" "<<(ret>0?ret:0);
  return 0;
}

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

#nの約数列挙
def divisor(n):
    ass = []
    for i in range(1,int(n**0.5)+1):
        if n%i == 0:
            ass.append(i)
            if i**2 == n:
                continue
            ass.append(n//i)
    ass.sort()
    return ass #sortされていない

#[[素因数,数]]を出力
def fctr1(n): 
    f = []
    c = 0
    for i in range(2,int(n**0.5)+2):
        while n%i == 0:
            c += 1
            n = n//i
        if c !=0:
            f.append([i,c])
            c = 0
    if n != 1:
        f.append([n,1])
    return f

D = divisor(N)
ans = 0
for d in D:
    if d == 1:
        continue
    if N >= d and N%d == 0 and len(fctr1(d)) == 1:
        N //= d
        ans += 1
print(ans)


Measured memory_bytes: 65192
#include<bits/stdc++.h>
using namespace std;
int c[100];
int t[100];
int main() {
    int n,T;
    cin>>n>>T;
    int min[100];
    int k=0;
    for(int i=0;i<n;i++){
        cin>>c[i]>>t[i];
        if(t[i]<=T){
            min[k]=c[i];
            k++;
        }
    }
    if(k==0){
        cout<<"TLE"<<endl;
    }
    else{
        sort(min,min+k);
        cout<<min[0]<<endl;
    }
}


Measured memory_bytes: 256
from sys import stdin

n = int(stdin.readline().strip())
x_lst = [int(x) for x in stdin.readline().strip().split()]

p1 = sum(x_lst) // n
p2 = sum(x_lst) // n + 1

p1_sum = sum([(x-p1) ** 2 for x in x_lst])
p2_sum = sum([(x-p2) ** 2 for x in x_lst])

print(min(p1_sum, p2_sum))

Measured memory_bytes: 3060
#include <stdio.h>

int n, A[50];

// 入力値のMから選んだ要素を引いていく再帰関数
int solve(int i, int m) {
    if(m==0) return 1;
    if(i>=n) return 0;
    int res = solve(i+1,m) || solve(i+1,m-A[i]);
    return res;
}

int main(void) {
    int q, M, i;

    scanf("%d", &n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);
    scanf("%d",&q);
    for(i=0;i<q;i++) {
        scanf("%d", &M);
        if(solve(0,M)) printf("yes\n");
        else printf("no\n");
    }
    return 0;
}


Measured memory_bytes: 2028
unittest
{
	assert( [ "1 10", "3 5" ].parse.expand.solve == 3 );
	assert( [ "2 10", "3 5", "2 6" ].parse.expand.solve == 2 );
	assert( [ "4 1000000000", "1 1", "1 10000000", "1 30000000", "1 99999999" ].parse.expand.solve == 860000004 );
	assert( [ "5 500", "35 44", "28 83", "46 62", "31 79", "40 43" ].parse.expand.solve == 9 );
}



import std.algorithm;
import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nh = input.front.split.to!( long[] );
	auto as = new long[ nh[ 0 ] ];
	auto bs = new long[ nh[ 0 ] ];
	foreach( ref a, ref b; lockstep( as, bs ) )
	{
		input.popFront;
		auto ab = input.front.split.to!( long[] );
		a = ab[ 0 ];
		b = ab[ 1 ];
	}
	return tuple( nh[ 1 ], as, bs );
}

auto solve( long h, long[] as, long[] bs )
{
	// 振る用の刀を判定（一番強いやつだけ使う）
	auto am = as.reduce!( max );
	
	// 投げる用の刀を判定（振る用より強いやつだけ使う）
	auto bms = bs.sort!( ( x, y ) => y < x ).filterBidirectional!( ( b ) => am < b );
	
	// 攻撃回数を計算（強い順に使う）
	auto ans = 0L;
	foreach( bm; bms )
	{
		if( h <= 0 ) break;
		h -= bm;
		ans++;
	}
	if( 0 < h ) ans += ( h + am - 1 ) / am;
	return ans;
}


Measured memory_bytes: 4604
n=int(input())
r=''
if n==0:
	print('0')
else:
	while n!=0:
		if n>=0:
			r+=str(n%2)
			n=-(n//2)
		else:
			r+=str(-(-n%-2))
			n=-(-n//-2)
print(r[::-1])

Measured memory_bytes: 3060
n,a,b = map(int, input().split())

ans = 0

for i in range(1,n+1):
    sum = 0
    target = i
    while(target):
        x = target % 10
        sum = sum + x
        target = (target - x) / 10
    if sum >=  a and sum <= b:
        ans = ans + i

print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep2(i, x, n) for (int i = x; i < (n); ++i)
using namespace std;

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

int main() {
    string s, t;
    cin >> s >> t;

    // 昇順ソート
    sort(s.begin(), s.end());
    // 降順ソート
    sort(t.rbegin(), t.rend());
    // 降順ソート（別解）
    // sort(t.begin(), t.end());
    // reverse(t.begin(), t.end());

    if (s < t) cout << "Yes" << endl;
    else cout << "No" << endl;
        
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i,n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<"\n"
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define mp make_pair
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using vc = vector<char>;
using vvc = vector<vc>;
template<class T> inline bool chmax(T& a, T b) { 
 if (a < b) { a = b; return true; } return false; 
}
template<class T> inline bool chmin(T& a, T b) {
 if (a > b) { a = b; return true; } return false; 
}
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll x,y,z,k;
  cin>>x>>y>>z>>k;
  vll a(x),b(y),c(z);
  rep(i,x) cin>>a[i];
  rep(i,y) cin>>b[i];
  vll d(0);
  rep(i,x)rep(j,y){
    d.pb(a[i]+b[j]);
  }
  sort(rall(d));
  rep(i,z) cin>>c[i];
  vll r(0);
  rep(i,min(k,x*y))rep(j,z){
    r.pb(d[i]+c[j]);
  }
  sort(rall(r));
  rep(i,k){
    COUT(r[i]);
  }
}


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

using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define all(x) (x).begin(), (x).end()
#define INF 1000000007
#define mod 1005
#define ll long long int
const double mx = 2e6 + 5;

void solve() {
    ll n;
    cin>>n;
    vector<ll> vect(n);
    ll tXor = 0;
    REP(i, n)
    {
        cin>>vect[i];
        tXor^=vect[i];
    }
    REP(i,n)
    {
        ll ans = tXor^vect[i];
        cout<<ans<<" ";
    }
    cout<<"\n";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t = 1;
//	cin>>t;
    while (t--) {
        solve();
    }
    return 0;
}


Measured memory_bytes: 4764
#include <iostream>
#include <deque>
#include <string>

void solve() {
  std::string str;
  std::deque<char> d;
  int q;
  bool reverse = false;
  std::cin >> str >> q;
  for (int i = 0; i < str.size(); i++) d.push_back(str[i]);
  
  for (int i = 0; i < q; i++) {
    int t;
    std::cin >> t;
    if (t == 1) reverse = (!reverse);
    else {
      int f;
      char c;
      std::cin >> f >> c;
      if (f == 1 && !reverse || f == 2 && reverse) d.push_front(c);
      else d.push_back(c);
    }
  }
  if (reverse)
    for (std::deque<char>::reverse_iterator i = d.rbegin(); i != d.rend(); i++)
      std::cout << *i;
  else
    for (std::deque<char>::iterator i = d.begin(); i != d.end(); ++i)
      std::cout << *i;
}
int main() {
  solve();
  return 0;
}

Measured memory_bytes: 896
#include<stdio.h>
int main()
{
  int i,sum,a;
  char n[200000];
  
  scanf("%s", &n);
  i=0;
  sum=0;
  while(1) {
  if (n[i] != '\0'){
    a=n[i]-'0';
    sum=sum+a;
    i++;
  } else {
    break;
  }
  }
  if (sum % 9 == 0) {
    printf("Yes");
  } else {
    printf("No");
  }
  return 0;
}

Measured memory_bytes: 1900
#include<bits/stdc++.h>
using namespace std;
#define fast                         ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define int                          long long int
#define double                       long double
#define ff                           first
#define ss                           second
#define pb                           push_back
#define eb                           emplace_back
#define all(x)                       (x).begin(), (x).end()
#define sz(x)                        ((int)(x).size())
#define len(x)                       ((int)(x).length())
#define pii                          pair<int,int>
#define vi                            vector<int>
#define vd                           vector<double>
#define vs                            vector<string>
#define mp                          map<int,int>
#define ms(x,y)                     memset(x,y,sizeof(x))
#define ump                         unordered_map<int,int>

#define lb                            lower_bound
#define ub                            upper_bound
#define nx                            cout<<"\n";
#define inf                           9223372036854775807
#define PI                            3.14159265

const int MOD = 1e9 + 7;

inline int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
inline int lcm(int a, int b) { return a * b / gcd(a, b); }
inline int add(int a, int b) {    return ((a % MOD) + (b % MOD)) % MOD;}

inline int multi(int a, int b) {   return ((a % MOD) * (b % MOD)) % MOD;}

inline int sub(int a, int b) {       a %= MOD; b %= MOD; a -= b; if (a < 0) a += MOD; return a;}

inline int power(int a, int b) {       a %= MOD; int res = 1; while (b > 0) {if (b & 1) {res = multi(res, a);} a = multi(a, a); b >>= 1;}  return res;}

bool isPrime(int  x) {      if (x <= 4 || x % 2 == 0 || x % 3 == 0) {return x == 2 || x == 3;} for (int i = 5; i * i <= x; i += 6) {if (x % i == 0 || x % (i + 2) == 0) { return 0;}} return 1;}

int dp[101][100005];
int32_t main()
{
  fast ;


  int n, k; cin >> n >> k;
// int dp[101][100005];
  int arr[n + 1];
  for (int i = 1; i <= n; i++)cin >> arr[i];
  for (int i = 0; i <= k; i++)dp[0][i] = 0;
  dp[0][0] = 1;
  for (int i = 1; i <= n; i++)
  {
    int sum[k + 1];
    sum[0] = dp[i - 1][0];
    for (int j = 1; j <= k; j++)
    {
      sum[j] = add(dp[i - 1][j], sum[j - 1]);
    }
    for (int j = 0; j <= k; j++)
    {
      if (j - arr[i] - 1 >= 0)
      {
        dp[i][j] = sub(sum[j], sum[j - arr[i] - 1]);
      }
      else dp[i][j] = sum[j];
    }

  }
  cout << dp[n][k];


}



Measured memory_bytes: 80000
#include <bits/stdc++.h>
using namespace std;
int main(){
    long n,x;
    cin>>n>>x;
    vector<long> a(n);
    for(int i =0; i<n; i++)
        cin>>a[i];
    long sum=0;
    for(int i =0; i<n; i++){
        if(i>0){
            if(a[i]+a[i-1]>x){
                sum+=a[i]+a[i-1]-x;
                a[i]-=a[i]+a[i-1]-x;
            }
        }
        else{
            if(a[i]>x){
                sum+=a[i]-x;
                a[i]=x;
            }
        }
    }
    cout<<sum;
}

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

int main() {
 int n;
 cin >> n;
 vector<int> x(100001);
 for(int i=0;i<100001;i++){
   x.at(i)=0;
  // cout << x.at(i)<<endl;
 }
 for(int i=0;i<n;i++){
   int a;
   cin >>a;
   if(a!=0){
    x.at(a-1)++;
   }
   x.at(a)++;
   x.at(a+1)++;
 }
  sort(x.begin(),x.end());
  reverse(x.begin(),x.end());
  cout << x.at(0);
}


Measured memory_bytes: 640
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
using ll = long long;
using P = pair<ll,ll>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> a(n, -1);
ll ind = 0;
for(int i = 2; i <= 55555 && a[n - 1] == -1; i++){
    int k = i;
    ll flag = 0;
    for(int j = 2; j * j <= k; j++){
        if(k % j == 0)
            flag++;
    }
    if(!flag && k % 5 == 1){
        a[ind] = k;
        ind++;
    }
}
for(int i = 0; i < n; i++){
    cout << a[i] << (i == n - 1 ? "\n" : " ");
}
}

Measured memory_bytes: 3592
//
//AtCoder Beginner Contest 165
//D - Floor Function
//

#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define reAll(x) (x).rbegin(),(x).rend()

using ll = long long;
using ld = long double;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

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

int main()
{
    ll a, b, n;

    cin >> a >> b >> n;

    n = min(n, b-1);
    cout << a*n/b << endl;
    return 0;
}


Measured memory_bytes: 3632
A, B, C, D = map(int, input().split())
is_taka = True
while A > 0 and C > 0:
    if is_taka:
        C -= B
    else:
        A -= D
    is_taka = not is_taka

ans = ""
if A <= 0:
    ans = "No"
else:
    ans = "Yes"

print(ans)


Measured memory_bytes: 61632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

int main(){
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<int> l(n);
  rep(i, n) cin >> l[i];

  int mi = 1001001001;
  rep(tmp1, 1<<8){
    rep(tmp2, 1<<8){
      bitset<8> bs1(tmp1);
      bitset<8> bs2(tmp2);
      string s1 = bs1.to_string();
      string s2 = bs2.to_string();
      vector<int> s(8);
      rep(i, 8) s[i] = (s1[i]-'0') + (s2[i]-'0') * 2;
      int suma = 0, ca = -1;
      int sumb = 0, cb = -1;
      int sumc = 0, cc = -1;
      rep(i, n){
        if(s[i] == 1){
          suma += l[i];
          ca++;
        }
        if(s[i] == 2){
          sumb += l[i];
          cb++;
        }
        if(s[i] == 3){
          sumc += l[i];
          cc++;
        }
      }
      if(suma*sumb*sumc == 0) continue;
      int res = 0;
      res += abs(a - suma) + ca * 10;
      res += abs(b - sumb) + cb * 10;
      res += abs(c - sumc) + cc * 10;
      chmin(mi, res);
    }
  }

  cout << mi << endl;

  return 0;
}


Measured memory_bytes: 384
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
ll f(ll n) {
	string str = to_string(n);
	ll sum = 0;
	for (int i = 0; i < str.size(); i++) sum += str[i] - '0';
	for (int i = str.size() - 1; i >= 0; i--) {
		for (int j = str[i] - '0'; j <= 9; j++) {
			string t = str.substr(0, i + 1);
			t[i] = '0' + j;
			t += string(str.size() - i - 1, '9');
			ll m = 0;
			ll s = 0;
			for (int k = 0; k < t.size(); k++) {
				m *= 10;
				m += t[k] - '0';
				s += t[k] - '0';
			}
			if (m*sum < n*s) {
				n = m;
				sum = s;
			}
		}
	}
	return n;
}
 int main() {
	 int K;
	 cin >> K;
	 ll n = 1;
	 for (int i = 0; i < K; i++) {
		 cout << n << endl;
		 n = f(n + 1);
	 }
}

Measured memory_bytes: 256
l = input()
n = len(l)
mod = 1000000007
ans = 0
cnt = 0
for i in range(n):
    if l[i] == "1":
        ans += pow(3, n - i - 1, mod) * pow(2, cnt, mod)
        ans %= mod
        cnt += 1
ans += pow(2, cnt, mod)
ans %= mod
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;

const int MAX_FACT = 200001;
unsigned long long MOD = (unsigned long long)1e9 + 7;
unsigned long long fact[MAX_FACT], invFact[MAX_FACT], inv[MAX_FACT];

void init()
{
	fact[0] = 1;
	fact[1] = 1;
	invFact[0] = 1;
	invFact[1] = 1;
	inv[1] = 1;
	for (auto i = 2; i < MAX_FACT; ++i)
	{
		fact[i] = fact[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		invFact[i] = invFact[i - 1] * inv[i] % MOD;
	}
}

unsigned long long calcCombination(int n, int k)
{
	if (n < k)
	{
		return 0;
	}
	if ((n < 0) || (k < 0))
	{
		return 0;
	}

	return fact[n] * (invFact[k] * invFact[n - k] % MOD) % MOD;
}


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

	init();

	auto sum = 0ull;
	for (auto i = B; i < W; ++i)
	{
		sum = (sum + calcCombination(i + H - A - 1, i) * calcCombination(W - i + A - 2, W - i - 1) % MOD) % MOD;
	}

	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,s,n) for(int i=s;i<n;i++)
#define fi first
#define se second
#define all(c) c.begin(),c.end()
typedef long long int ll;
typedef pair<int, int> P;
typedef long double ld;
void Ans(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}

const ll INF=1001001001;
const ll mod=10000000007;

int main(){
  int n;cin>>n;
  string s;
  set<string> st;
  rep(i,n){
    cin>>s;
    st.insert(s);
  }
  
  cout<<st.size()<<endl;
}

Measured memory_bytes: 19120
#include<bits/stdc++.h>
using namespace std;
void *wmem;
inline void rd(int &x){
  int k, 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 void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  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 T> int Factor_L(T N, T fac[], int fs[]){
  T i;
  int sz=0;
  if(N%2==0){
    fac[sz] = 2;
    fs[sz] = 1;
    N /= 2;
    while(N%2==0){
      N /= 2;
      fs[sz]++;
    }
    sz++;
  }
  for(i=3;i*i<=N;i+=2){
    if(N%i==0){
      fac[sz] = i;
      fs[sz] = 1;
      N /= i;
      while(N%i==0){
        N /= i;
        fs[sz]++;
      }
      sz++;
    }
  }
  if(N > 1){
    fac[sz] = N;
    fs[sz] = 1;
    sz++;
  }
  return sz;
}
template<class T> int Divisor_L(T N, T res[], void *mem = wmem){
  T *fc;
  int *fs, fsz, i, j, k, s, sz=0;
  fc = (T*)wmem;
  fs = (int*)(fc+100);
  fsz =Factor_L(N, fc, fs);
  res[sz++] = 1;
  for(i=0;i<fsz;i++){
    s = sz;
    k = s * fs[i];
    for(j=0;j<k;j++){
      res[sz++] = res[j] * fc[i];
    }
  }
  sort(res, res+sz);
  return sz;
}
char memarr[96000000];
int N;
int ys;
int y[100];
int main(){
  int i, res=0;
  wmem = memarr;
  rd(N);
  for(i=1;i<=N;i+=2){
    ys =Divisor_L(i, y);
    if(ys==8){
      res++;
    }
  }
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190715-1

// --- original code ---
// int N;
// int ys, y[100];
// {
//   int i, res = 0;
//   rd(N);
//   for(i=1;i<=N;i+=2){
//     ys = Divisor(i, y);
//     if(ys==8) res++;
//   }
//   wt(res);
// }


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

using bellman_cost = int;
template<class V, class E>
struct Graph
{
	int sz;
	vector<V> v;
	vector<vector<E>> e;
	Graph(int n) : sz(n), v(n), e(n) {}
	template<class... Args>
	inline void assign_vertex(int pos, Args... args) {
		v[pos] = V(args...);
	}
	template<class... Args>
	inline void add_edge(int pos, Args... args) {
		e[pos].emplace_back(args...);
	}
	inline int size() {
		return sz;
	}
};

template<class T>
struct Vertex_Cost
{
	T cost;
	bool valid = false;
	Vertex_Cost(T v1) : cost(v1) {}
	Vertex_Cost() {}
};
using vertex = Vertex_Cost<bellman_cost>;

template<class T>
struct Edge_Cost
{
	int to;
	T cost;
	Edge_Cost(int t, T c) : to(t), cost(c) {}
	Edge_Cost() {}
};
using edge = Edge_Cost<bellman_cost>;
using graph = Graph<vertex, edge>;

template<class T, class V, class E>
void Bellmanford(Graph<V, E>& G, int s, T INF_COST)
{
	auto &v = G.v;
	auto &e = G.e;
	for (auto& vv : v) vv.cost = INF_COST;
	v[s].cost = 0;
	v[s].valid = true;
	for (int i = 0; i + 1 < (int) v.size(); i++) {
		for (int j = 0; j < (int) v.size(); j++) {
			for (auto& x: e[j]) {
				if (v[j].cost == INF_COST) continue;
				v[x.to].cost = min(v[x.to].cost, v[j].cost + x.cost);
				v[x.to].valid = true;
			}
		}
	}
	auto dfs = [&](auto f, int pos) {
		if (!v[pos].valid) return;
		v[pos].valid = false;
		for (auto& y: e[pos]) {
			f(f, y.to);
		}
	};
	for (int i = 0; i < (int) v.size(); i++) {
		for (auto& x: e[i]) {
			if (v[i].cost == INF_COST) continue;
			if (v[x.to].cost > v[i].cost + x.cost) {
				dfs(dfs, x.to);
			}
		}
	}
}


void solve(long long N, long long M, long long P, std::vector<long long> A, std::vector<long long> B, std::vector<long long> C) {
	graph g(N);
	for (int i = 0; i < M; i++) {
		g.add_edge(A[i]-1, B[i]-1, -(C[i] - P));
	}
	Bellmanford(g, 0, INT_MAX);
	if (!g.v[N-1].valid) cout << -1 << endl;
	else cout << max(-g.v[N-1].cost , 0) << endl;
}

signed main() {
	long long N;
	scanf("%lld",&N);
	long long M;
	scanf("%lld",&M);
	long long P;
	scanf("%lld",&P);
	std::vector<long long> A(M);
	std::vector<long long> B(M);
	std::vector<long long> C(M);
	for(int i = 0 ; i < M ; i++){
		scanf("%lld",&A[i]);
		scanf("%lld",&B[i]);
		scanf("%lld",&C[i]);
	}
	solve(N, M, P, std::move(A), std::move(B), std::move(C));
	return 0;
}


Measured memory_bytes: 512
import sys
from collections import deque
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline


def main():
    N, Q = map(int, input().split())
    con = [[] for i in range(N)]
    ans = [0] * N

    for _ in range(N - 1):
        a, b = map(int, input().split())
        con[a - 1].append(b - 1)
        con[b - 1].append(a - 1)
        
    for _ in range(Q):
        p, v = map(int, input().split())
        ans[p-1] += v

    stacks = deque()
    stacks.append((0, -1))

    while stacks:
        stack = stacks.pop()
        node, parent = stack[0], stack[1]

        children = con[node]
        for child in children:
            if child == parent:
                continue
            ans[child] += ans[node]
            stacks.append((child, node))

    print(*ans)


if __name__ == '__main__':
    main()


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

typedef long long ll;
int n, p[5010];
ll A, B, ans = 1e18, f[5010][5010];

int main() {
    scanf("%d %lld %lld", &n, &A, &B);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &p[i]);
    }
    memset(f, 0x3f, sizeof(f)), f[0][0] = 0;
    for (int i = 1; i <= n; i++) {
        for (int j = 0; j <= n; j++) {
            if (p[i] > j) {
                f[i][j] = min(f[i][j], f[i - 1][j] + A);
                f[i][p[i]] = min(f[i][p[i]], f[i - 1][j]);
            } else {
                f[i][j] = min(f[i][j], f[i - 1][j] + B);
            }
        }
    }
    for (int i = 0; i <= n; i++) {
        ans = min(ans, f[n][i]);
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 196352
n,m,zz = [int(x) for x in input().split()]
li = []
for _ in range(n):
    z = [int(x) for x in input().split()]
    li.append(z)
ans = 10**10
for i in range(2**n):
    y = [0]*m
    num = 0
    for j in range(n):
        if (i&(1<<j)):
            for k in range(m):
                y[k]+=li[j][k+1]
            num+=li[j][0]
    if min(y)>=zz:
        ans = min(ans,num)
if ans==10**10:
    ans = -1
print(ans)

Measured memory_bytes: 68672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll ch[200010];
	for(ll i=0;i<n;i++){
		cin>>ch[i];
		ch[i]--;
	}
	ll now=0;
	ll ans=0;
	for(ll i=0;i<n;i++){
		if(ch[i]!=now){
			ans++;
		}
		else{
			now++;
		}
	}
	if(ans==n){
		cout << -1;
		return 0;
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 5184
S = str(input())

if S == 'SUN':
    print('7')
elif S == 'MON':
    print('6')
elif S == 'TUE':
    print('5')
elif S == 'WED':
    print('4')
elif S == 'THU':
    print('3')
elif S == 'FRI':
    print('2')
elif S == 'SAT':
    print('1')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define VV(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a); i>n; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
int main() {
	cout << setprecision(13) << fixed;
	int a, b; cin >> a >> b;
	cout << a / b << " " << a % b << " " << (double)a / b << endl;
	return 0;
}

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

int gcd(int x, int y);

const int INF = 1001001001;

/*struct mint {
    ll x; // typedef long long ll;
    mint(ll x = 0) :x((x% mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this; }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint& operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream& operator>>(istream & is, const mint & a) { return is >> a.x; }
ostream& operator<<(ostream & os, const mint & a) { return os << a.x; }*/

int main() {
    vector<int> a(5);
    int ans;
    rep(i, 5) {
        cin >> a[i];
        if (a[i] == 0)
            ans = i + 1;
    }

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

/*���C�u�����ő����*/
//���[�O���b�h�̌ݏ��@
int gcd(int x, int y) {
    int num[3];
    num[0] = (x > y) ? x : y;
    num[1] = (x <= y) ? x : y;
    num[2] = num[0] % num[1];

    while (num[2]) {
        num[0] = num[1];
        num[1] = num[2];
        num[2] = num[0] % num[1];
    }

    return num[1];
}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
using vl = vector<ll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//

int main() {
    init();
    ll n, a, b;
    cin >> n >> a >> b;
    string s;
    cin >> s;

    ll an = 0, bn = 0;
    rep(i, n) {
        if (s[i] == 'a') {
            cout << ((an + bn < a + b) ? "Yes" : "No") << endl;
            an++;
        } else if (s[i] == 'b') {
            if (an + bn < a + b && bn < b) {
                cout << "Yes" << endl;
                bn++;
            } else
                cout << "No" << endl;
        } else
            cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 848
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>

using namespace std;
typedef long long LL;
static const double EPS = 1e-9;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)

int main(void){
  int m;
  cin>>m;
  string s;
  while(cin>>s){
    set<string> ans;
    FOR(i,1,s.size()){
      string s1 = s.substr(0,i);
      string s2 = s.substr(i);
      string s1r = s1;
      string s2r = s2;
      reverse(s1r.begin(),s1r.end());
      reverse(s2r.begin(),s2r.end());
      ans.insert(s1+s2);
      ans.insert(s1+s2r);
      ans.insert(s1r+s2);
      ans.insert(s1r+s2r);
      ans.insert(s2+s1);
      ans.insert(s2+s1r);
      ans.insert(s2r+s1);
      ans.insert(s2r+s1r);
    }
    cout<<ans.size()<<endl;
  }
  return 0;
}

Measured memory_bytes: 996
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,m;
	cin>>n>>m;
	priority_queue<int>pq;
	long long sum=0;
	for(int i=0;i<n;i++){int x;cin>>x;pq.push(x);}
	for(int i=0;i<m;i++){
		int p=pq.top();
		pq.pop();
		pq.push(p/2);
	}
	while(!pq.empty()){
		sum+=(long long)(pq.top());
		pq.pop();
	}
	cout<<sum;
}

Measured memory_bytes: 892
#include <iostream>
#include <cmath>
#include <stdio.h>

using namespace std;


int main(void){

    pair<double, double> p0, p1, p2;
    int n;
    cin >> p0.first >> p0.second >> p1.first >> p1.second;
    cin >> n;

    while(n--){
        cin >> p2.first >> p2.second;
        // ??????
        double crossProduct = (p1.first - p0.first)*(p2.second - p0.second)
            - (p1.second - p0.second)*(p2.first - p0.first);

        if(crossProduct > 0){ // counter clockwise
            cout << "COUNTER_CLOCKWISE" << endl;
        }else if(crossProduct < 0){ // clockwise
            cout << "CLOCKWISE" << endl;
        }else{ // on line
            // ??????
            double innerProduct = (p1.first - p0.first)*(p2.first - p0.first)
                + (p1.second - p0.second)*(p2.second - p0.second);
            if(innerProduct >= 0){ // ????????????
                double a, b;
                a = sqrt( pow(p1.first - p0.first, 2) + pow(p1.second - p0.second, 2) );
                b = sqrt( pow(p2.first - p0.first, 2) + pow(p2.second - p0.second, 2) );
                if(a >= b){
                    cout << "ON_SEGMENT" << endl;
                }else{
                    cout << "ONLINE_FRONT" << endl;
                }
            }else if(innerProduct < 0){ // ?????????
                cout << "ONLINE_BACK" << endl;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 1224
import java.util.*;
import java.util.stream.Collectors;
import java.io.*;
import java.nio.charset.StandardCharsets;

public class Main {
	public static void main(String[] args) throws IOException {
		InputStreamReader reader = new InputStreamReader(System.in, StandardCharsets.UTF_8);
		BufferedReader in = new BufferedReader(reader);
		Main ins = new Main(in);
		ins.calc();
		ins.showResult();
	}

	Main(BufferedReader in) throws IOException {
		String[] tokens = in.readLine().split(" ");
		long N = Long.parseLong(tokens[0]);
		long A = Long.parseLong(tokens[1]);
		long B = Long.parseLong(tokens[2]);

		long div = N / (A + B);
		long mod = N % (A + B);
		mod = Math.min(mod, A);
		long result = div * A + mod;
		System.out.println(result);
	}

	void calc() {
	}

	void showResult() {
	}

}


Measured memory_bytes: 22992
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using vvvl = vector<vector<vector<ll>>>;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
template<class T> inline void prn(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << ' ';}
template<class T> inline void printv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << (i == n - 1 ? endl : ' ');}
template<class T> inline void printvv(vector<vector<T>>& v) {for (auto u : v) printv(u);}
template<class T> inline void printlnv(vector<T>& v) {int n = sz(v); REP(i, n) cout << v[i] << endl;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    string s;
    cin >> s;
    int n = sz(s);
    REP(i, n) {
        if (s[i] == '?') s[i] = 'D';
    }
    cout << s << endl;
}


Measured memory_bytes: 3784
import math
import collections
import itertools
import sys
import bisect
from heapq import heappop,heappush,heapify
sys.setrecursionlimit(10**6)
def MAP(): return list(map(int,input().split()))
def INT(): return int(input())
def FLOAT(): return float(input())
MOD = 10**9+7

n = INT()
ll = [[] for _ in range(n)]
l = [0]*n

for i in range(n):
    tmp = INT()
    for j in range(tmp):
        x,y = MAP()
        ll[i].append([x-1,y])

ans = 0
for bit in range(2**n):
    ok = True
    is_honest = [(bit>>i) & 1 for i in range(n)]
    #print(is_honest)
    for i in range(n):
        if not is_honest[i]:
            continue
        for x,y in ll[i]:
            if is_honest[x]!=y:
                ok=False
    if ok:
        ans = max(ans,sum(is_honest))
print(ans)

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    double N, M;
    int D;
    cin >> N >> M >> D;
    if(D == 0) {
        output((M - 1.0) / N, 10);
    }
    else {
        output((M - 1.0) * (N - D) * 2.0 / (N * N), 10);
    }
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;

class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String s = br.readLine();
		String[] str = s.split("\\s+");
		int[] col = new int[str.length];
		for(int i = 0;i < str.length;i++){
			col[i] = Integer.parseInt(str[i]);
		}
		boolean[] penki = new boolean[101];
		int cnt = 0;
		int sum = 0;
		while(cnt < 3){
			if(!(penki[col[cnt]])){
				penki[col[cnt]] = true;
				sum++;
			}
			cnt++;
		}
		System.out.print(sum);
	}
}

Measured memory_bytes: 8148
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define si(X) scanf("%d", &(X))
#define sll(X) scanf("%lld",&(X))
const ll mod = 1e9+7;
#define INFL 0x3f3f3f3f3f3f3f3fLL
 
//-------------------------<MATH>-------------------------------------------------------//
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll expo(ll base,ll pow){ll ans = 1;
   while(pow!=0){if(pow&1==1){ans = ans*base;ans = ans%mod;}
   base *= base;base%=mod;pow/=2;}return ans;}
ll inv(ll x){return expo(x,mod-2);}
ll mult_mod(ll a , ll b){a = a%mod; b = b%mod;
ll c = (a * b)%mod;
//cout << a << " " << b << endl;
return c;}
ll add_mod(ll a , ll b){a = (a + mod)%mod;b = (b + mod)%mod;ll c = (a + b)%mod;return c;}
ll fac[(int)(5e5 + 5)] , inv_fac[(int)(5e5 + 5)];
void precomp_factorial(int M){fac[0] = 1;for(int i = 1 ; i <= M ; i++) fac[i] = mult_mod(i , fac[i - 1]);
    inv_fac[M] = inv(fac[M]);for(int i = M - 1 ; i >= 0 ; i--) inv_fac[i] = mult_mod(i + 1 , inv_fac[i + 1]);}
ll nCk(ll n , ll k){ll ans = fac[n];ans = mult_mod(ans , inv_fac[n - k]);ans = mult_mod(ans , inv_fac[k]);return ans;}
int lo[(int)(1e3 + 6)];
void sieve(int M){for(int i = 2 ; i < M ; i++){ if(lo[i]) continue; for(int j = i ; j < M ; j += i)lo[j] = i;}}
int max_expo_prime_n_fac(ll N , int prime){int ress = 0;while(N){ress += (N/prime);N /= prime;}return ress;}
//-------------------------</MATH>-------------------------------------------------------//
 
//-------------------------<STRING>-------------------------------------------------------//
string get_prefix(string x , int MAX){return x.substr(0 , min((int)x.size() , MAX));}
string get_suffix(string x,int MAX){int dn=1;for(int i=x.size()-1;i>=0;i--){if(dn==MAX)return x.substr(i);dn++;}return x;}
string convert_to_binary(int x,int len) {string ans=""; while(x){if(x&1){ans='1'+ans;}
    else{ans ='0'+ans;}x/=2;}int k = ans.size();while(k < len){ans = '0' + ans;k++;}return ans;}
//-------------------------</STRING>-------------------------------------------------------//
 
ull llrand() {ull r = 0;for(int i = 0; i < 5; ++i){r = (r << 15)|(rand() & 0x7FFF);}return r & 0xFFFFFFFFFFFFFFFFULL;}
int dx[8] = {1 , 0 , -1 , 0 , 1 , -1 , -1 , 1};    // last 4 diagonal
int dy[8] = {0 , 1 , 0 , -1 , 1 , 1 , -1 , -1};
 
 
ll dp[210][210][210];
 
int main(){
    string s;
    cin >> s;
    int cnt = 0;
    int ans = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'S'){
            cnt = 0;
        } else{
            cnt++;
            ans = max(ans, cnt);
        }
    }
    cout << ans;
}

Measured memory_bytes: 3548
#include<iostream>
using namespace std;
int main()
{
    int d1,d2;
    if(!scanf("%2d%2d", &d1, &d2)) exit(0);
    int m1,m2;
    string answer = "NA";

    m1 = d1 > 0 && d1 < 13;
    m2 = d2 > 0 && d2 < 13;
    if (m2 && m1) {
        answer = "AMBIGUOUS";
    } else if (m2) {
        answer = "YYMM";
    } else if (m1) {
        answer = "MMYY";
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 256