akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
    
    int N;
    
    cin >> N;
    
    long a[N];
    
    for(int i=0; i<N; i++) {
        cin >> a[i];
    }
    
    int num = 0;
    while(true) {
        bool end = true;
        for(int i=0; i<N; i++) {
            if(a[i] % 2 == 0) {
                end = false;
                a[i] = a[i] / 2;
                break;
            }
        }
        
        if(end) {
            break;
        }
        else {
            num++;
        }
    }
    
    cout << num << "\n";
    
    return 0;
}


Measured memory_bytes: 384
#include<iomanip>
#include<limits>
#include<thread>
#include<utility>
#include<iostream>
#include<string>
#include<algorithm>
#include<set>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#include<cmath>
#include<math.h>
#include<numeric>
#include<cassert>
#include<random>
#include<deque>
#include<chrono>
#include<unordered_map>
#include<list>
#include<fstream>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pi;
typedef pair<double,double> pd;
const ll E=1e18+7;
#define F first
#define S second
#define MK make_pair
const ll MOD=1000000007;




int main(){
    ll n;
    cin>>n;
    ll count=0;
    for(int i=0;i<n;i++){
        ll b;
        cin>>b;
        if(b%2==1){count++;}
    }
    if(count%2==0){cout<<"YES"<<endl;}
    else{cout<<"NO"<<endl;}
    
    
    return 0;
}


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

#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define mem(x,val) memset((x),(val),sizeof(x))
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define PI acos(-1.0) 
#define N 111111

const int INF = 1 << 30 ;
typedef long long ll ;
typedef pair < int , int > pii ;

int a[N] ;

int main() {
  int n, m, u, v ;
  scanf("%d %d", &n, &m) ;

  for(int i = 1 ;i<=m ;i++){
    scanf("%d %d", &u, &v) ;
    a[u]++, a[v]++ ;
  }

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

	
  return 0 ;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint     = long long;
const lint inf = 1LL << 60;
const lint mod = 1000000007;

struct UnionFind {
    vector<int> rank, parent, size;

    // +1 for 1-indexed nodes
    UnionFind(int n) : rank(n + 1, 0), parent(n + 1), size(n + 1, 1) {
        iota(parent.begin(), parent.end(), 0); // parent is itself
    }
    int root(int x) {
        if (x != parent[x]) {
            parent[x] = root(parent[x]);
        }
        return parent[x];
    }
    bool isSame(int x, int y) { return root(x) == root(y); }
    bool unite(int x, int y) { return link(root(x), root(y)); }
    bool link(int x, int y) {
        if (x == y)
            return false;
        if (rank[x] > rank[y]) {
            parent[y] = x;
            size[x] += size[y];
        } else {
            parent[x] = y;
            size[y] += size[x];
            if (rank[x] == rank[y]) {
                rank[y]++;
            }
        }
        return true;
    }
    int getSize(int x) { return size[root(x)]; }
};

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

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    lint n, m;
    cin >> n >> m;
    vector<lint> h(n);
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
    }
    vector<vector<int>> edges(n);
    for (int i = 0; i < m; ++i) {
        int u, v;
        cin >> u >> v;
        u--, v--;
        edges[u].emplace_back(v);
        edges[v].emplace_back(u);
    }
    int ret = 0;
    for (int i = 0; i < n; ++i) {
        bool ok = true;
        for (auto &v : edges[i]) {
            if (h[v] >= h[i]) {
                ok = false;
                break;
            }
        }
        if (ok)
            ret++;
    }
    cout << ret << "\n";
    return 0;
}

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

#define N 500005

int no_parent[N], visited[N], depth[N];
vector<int> edge[N];

void dfs(int v){
    if(visited[v])
        return ;
    
    visited[v] = 1;
    depth[v] = 0;
    for(int i=0; i<edge[v].size(); i++) {
        int x = edge[v][i];
        if(!visited[x])
            dfs(x);
        depth[v] = max(depth[v], depth[x] + 1);
    }
    
}

int main() {
    string S;
    cin>>S;
    
    memset(no_parent, 0, sizeof(no_parent));
    for(int i=0; i<S.length(); i++) {
        if(S[i] == '<') {
            edge[i+1].push_back(i);
            no_parent[i]++;
        }
        else {
            edge[i].push_back(i+1);
        }
    }
    
    int n = S.length() + 1;
    memset(depth, 0, sizeof(depth));
    memset(visited, 0, sizeof(visited));
    for(int i=0; i<n; i++) {
        if(no_parent[i] == 0) {
            dfs(i);
        }
    }
    
    long long int ans = 0 ;
    for(int i=0; i<n; i++) {
        ans += depth[i];
    }
    
    cout<<ans;
    
    return 0;
}


Measured memory_bytes: 57348
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return true; } return false; }

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

int solve(int a, int b, int c){
    double d = sqrt(b*b - 4*a*c);
    if (d < 0) return 0;
    if (floor(d != d)) return 0;
    double x = (-b + d) / 2 * a;
    double y = (-b - d) / 2 * a;
    int ans = 0;
    if (floor(x) == x && x > 0) ans++;
    if (floor(y) == y && y > 0) ans++;
    return ans;
}

int f(int n){
    int ans = 0;
    for(int i = 1; i*i <= n; i++){
        for(int j = 1; j*j <= n; j++){
            ans += solve(1, i + j, (i*i + j*j + i*j - n));
        }
    }
    return ans;
}

int main(){
    int n;
    cin >> n;
    for(int i = 1; i <= n; i++){
        cout << f(i) << endl;
    }
    return 0;
}

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

int main() {
  ll n;
  cin >> n; 
  string s;
	map<string,ll> m;
  rep(i,n){
    cin >> s;
    sort(s.begin(),s.end());
    m[s]++;
  }
  ll ans =0;
  auto begin = m.begin(), end = m.end();
  for(auto iter = begin;iter != end; iter++){
    //cout << iter->first << " " << iter->second << endl;;
    ll t = iter->second;
    ans += t * (t - 1) / 2;
  }
  cout << ans << endl;
  return 0;
}

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

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

  int count = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == 'x') {
      count++;  
    }
  }
    
    if (count > 7) {
      cout << "NO";
    }
    else if (count < 8) {
      cout << "YES" << endl;
    }
}


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

#define MAX_N 111111

int par[MAX_N]; //親
int ran[MAX_N]; //木の深さ

//初期化
void init(int n){
  for(int i=0;i<=n;i++){
    par[i]=i;
    ran[i]=0;
  }
}

//根を求める
int find(int x){
  if(par[x]==x)return x;
  else return par[x]=find(par[x]);
}

//集合を合併
void unite(int x,int y){
  x=find(x);
  y=find(y);
  if(ran[x]<ran[y])par[x]=y;
  else {
    par[y]=x;
    if(ran[x]==ran[y])ran[x]++;

  }
}

//xとyが同じ集合に属するのか?
bool same(int x,int y){
  return find(x)==find(y);
}

int main(){
  int n,m,p[111111];
  cin>>n>>m;
  init(n);
  for(int i=1;i<=n;i++)cin>>p[i];
  int x[111111],y[111111];
  for(int i=0;i<m;i++){
    cin>>x[i]>>y[i];
    unite(x[i],y[i]);
  }
  int ans=0;
  for(int i=1;i<=n;i++){
    if(same(i,p[i]))ans++;
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 2176
#include <stdio.h>

#define mod 1000000007
#define ll long long


ll n,k;
ll ans[100010];


ll quickpow(ll a,ll b){ 
        ll ans = 1;
        while(b != 0){ 
                if(b%2 == 1){ 
                        ans = (ans%mod*a%mod)%mod;
                }   
                b = b/2;
                a = (a%mod*a%mod)%mod;
        }   
        return ans;
}


int main(void){

        scanf("%lld %lld",&n,&k);
        for(ll i=k;i>=1;i--){
                ans[i] = quickpow(k/i,n);

                for(ll j=(ll)2*i;j<=k;j=j+i){
                        ans[i] = (ans[i]-ans[j]+mod)%mod;
                }   
        }   

        ll res = 0;
        for(ll i=1;i<=k;i++){
                res = (res+i*ans[i])%mod;
        }   
        printf("%lld\n",res);
return 0;
}



Measured memory_bytes: 2508
#include <iostream>

using namespace std;

int main() {
    int N;
    int A[10000];

    cin >> N;
    for (int i = 0; i < N; i++) cin >> A[i];

    int count = 0;
    bool exist_odd = false;

    while (true) {
        for (int i = 0; i < N; i++) {
            if (A[i] % 2 != 0) exist_odd = true;
        }

        if (exist_odd) break;

        for (int i = 0; i < N; i++) A[i] /= 2;
        count++;
    }

    cout << count << endl;
}

Measured memory_bytes: 256
from collections import Counter

n = int(input())
c = Counter(map(int, input().split()))
c = sorted((e for e in c.items() if e[1] > 1), key=lambda e: -e[0])
if len(c) < 2:
  print(0)
elif c[0][1] >= 4:
  print(c[0][0] ** 2)
else:
  print(c[0][0] * c[1][0])

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

int main(){
  int p, q, r;
  
  cin >> p >> q >> r;
  
  int min = p+q;
  
  if(min > p+r){
    min = p+r;
  }
  if(min > q+r){
    min = q+r;
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

int a[1000], b[1000];

int main(void) {
	int n, m, pos, res;
	int i, j;
	while (1) {
		pos = 0, res=0;
		scanf("%d %d", &n, &m);
		if (n == 0 && m == 0)break;

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

			for (i = 0; i < m; i++) {
				pos = pos + b[i];
				pos += a[pos];
				res++;
				if (pos>= n)break;
			}
		printf("%d\n",res);
	}
	return 0;
}

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

int main(){
    int a, b; cin >> a >> b;
    
    if(a < b) cout << "a < b" << endl;
    else if(a > b) cout << "a > b" << endl;
    else cout << "a == b" << endl;
    
    return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
int main(){

	int E, Y;
	cin>>E>>Y;
	if(E == 1) cout<<Y + 1867;
	if(E == 2) cout<<Y + 1911;
	if(E == 3) cout<<Y + 1925;
	if(E == 4) cout<<Y + 1988;
	if(E == 0 && 1868 <= Y && Y <= 1911) cout<<"M"<< Y - 1867;
	if(E == 0 && 1912 <= Y && Y <= 1925) cout<<"T"<< Y - 1911;
	if(E == 0 && 1926 <= Y && Y <= 1988) cout<<"S"<< Y - 1925;
	if(E == 0 && 1989 <= Y) cout<<"H"<< Y - 1988;
	cout<<endl;

	return 0;
}



Measured memory_bytes: 3100
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

vector<vector<int>> g;

int dfs(vector<bool> v,const int par, const int cur) {
    int ret = 0;
    v[cur] = true;
    bool all = true;
    REP(i,v.size()) if (!v[i]) all = false;
    if (all) return 1;

    for (auto x:g[cur]) {
        if (x == par) continue;
        if (v[x]) continue;
        ret += dfs(v,cur,x);
    }
    
    return ret;
}

int main(void)
{
    IOS
    int n, m;
    cin >> n >> m;
    g.resize(n);
    REP(i,m) {
        int a, b;
        cin >> a >> b;
        a--; b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }

    int ans = 0;
    vector<bool> v(n);
    ans = dfs(v,-1,0);

    cout << ans << '\n';

    return 0;
}

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

int main(){
	long long int n,m;
	cin>>n>>m;
	long long int ans=0;
	for (int i = m/n; i >=1; i--) {
		if (m%i==0) {
			ans=i;
			break;
		}
	}
	cout<<ans<<endl;
}

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

typedef long long LL;

const int N=300000,mod=1000000007;

int add(int a,int b,int p=mod){return a+b>=p?a+b-p:a+b;}
int sub(int a,int b,int p=mod){return a-b<0?a-b+p:a-b;}
int mul(int a,int b,int p=mod){return (LL)a*b%p;}
void sadd(int &a,int b,int p=mod){a=add(a,b,p);}
void ssub(int &a,int b,int p=mod){a=sub(a,b,p);}
void smul(int &a,int b,int p=mod){a=mul(a,b,p);}

int n,m,l,r;

void into(){
  scanf("%d%d%d%d",&n,&m,&l,&r);
}

int inv[N*2+9],fac[N*2+9],ifac[N*2+9];

void Get_inv(){
  inv[1]=1;
  fac[0]=fac[1]=1;
  ifac[0]=ifac[1]=1;
  for (int i=2;i<=n+r;++i){
	inv[i]=mul(mod-mod/i,inv[mod%i]);
	fac[i]=mul(fac[i-1],i);
	ifac[i]=mul(ifac[i-1],inv[i]);
  }
}

int Get_c(int n,int m){return n<m||m<0?0:mul(fac[n],mul(ifac[m],ifac[n-m]));}

int Get_ans(int x,int mx){
  int res=0;
  mx-=m*x;
  for (int i=0;i<=n-m&&i*x<=mx;++i){
	int t=mul(Get_c(n-m,i),Get_c(mx-i*x+n,n));
	i&1?ssub(res,t):sadd(res,t);
  }
  if (--x<=0) return mul(Get_c(n,m),res);
  for (int i=0;i<=n-m&&i*x<=mx;++i){
	int t=mul(Get_c(n-m,i),Get_c(mx-i*x+n,n));
	i&1?sadd(res,t):ssub(res,t);
  }
  return mul(Get_c(n,m),res);
}

int ans;

void Get_ans(){
  for (int i=l;i<=r;++i) sadd(ans,Get_c(i+n-1,n-1));
  for (int i=1;i<=r&&m*i<=r;++i) ssub(ans,Get_ans(i,r));
  for (int i=1;i<l&&m*i<l;++i) sadd(ans,Get_ans(i,l-1));
}

void work(){
  Get_inv();
  Get_ans();
}

void outo(){
  printf("%d\n",ans);
}

int main(){
  into();
  work();
  outo();
  return 0;
}

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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<pair<int, int> > A;
    for(int i = 0; i < N; i++)
    {
        int a, b;
        cin >> a >> b;
        A.push_back(make_pair(a, b));
    }
    sort(A.begin(), A.end());
    priority_queue<int> pq;
    int idx = 0;
    long long ans = 0;
    for(int i = M; i >= 0; --i)
    {
        while((idx < N) && (A[idx].first + i <= M))
        {
            pq.push(A[idx].second);
            ++idx;
        }
        if(!pq.empty()) 
        {    
            ans = ans + pq.top();
            pq.pop();
        }
    }
    cout << ans;
}

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

using namespace std;

bool data[1440];
int n, m, a, b, s, t, p;

int conv(int x){
  if(x == 0) return 0;
  return (x / 100) * 60 + x % 100;
}

main(){
  while(cin >> n >> s >> t && (n|s|t)){
    s = conv(s);
    t = conv(t);
    fill(data, data+1440, false);
    for(int i=0;i<n;i++){
      cin >> m;
      p = s;
      for(int j=0;j<m;j++){
        cin >> a >> b;
        a = conv(a);
        b = conv(b);
        for(int k=p;k<a;k++) data[k] = true;
        p = b;
      }
      for(int j=p;j<t;j++) data[j] = true;
    }
    int ans = 0, cnt = 0;
    for(int i=s;i<t;i++){
      if(data[i]) ++cnt;
      else{
        ans = max(ans, cnt);
        cnt = 0;
      }
    }
    cout << max(ans, cnt) << endl;
  }
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint n,m;cin >> n>>m;
    vector<lint> aced(n),waed(n);
    lint ac = 0, wa = 0;
    REP(i, m) {
        lint p;
        string s;
        cin >>p>>s;
        if(aced[p-1]==1){
            continue;
        }
        if(s=="AC"){
            aced[p - 1] = 1;
            ac++;
        }
        if (s == "WA")
        {
            waed[p-1]++;
        }
    }
    REP(i,n){
        wa += waed[i] * aced[i];
    }
    cout << ac<<" "<<wa <<"\n";

    return 0;
}

Measured memory_bytes: 1792
#include <queue>
#include <cstdio>
#include <vector>
using namespace std;
int V, s, t, p, q, d[100000]; vector<pair<int, int> > G[100000];
int main() {
	scanf("%d", &V);
	for(int i = 0; i < V; i++) {
		scanf("%d%d", &s, &t);
		for(int j = 0; j < t; j++) {
			scanf("%d%d", &p, &q);
			G[i].push_back(make_pair(p, q));
		}
	}
	for(int i = 1; i < V; i++) d[i] = 999999999;
	priority_queue<pair<int, int> > que; que.push(make_pair(0, 0));
	while(!que.empty()) {
		int v = que.top().second; que.pop();
		for(int i = 0; i < G[v].size(); i++) {
			int u = G[v][i].first, w = G[v][i].second;
			if(d[u] > d[v] + w) {
				d[u] = d[v] + w;
				que.push(make_pair(-d[u], u));
			}
		}
	}
	for(int i = 0; i < V; i++) printf("%d %d\n", i, d[i]);
	return 0;
}

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

int main(void){
    int N;
    int num[3][3]={};
    int ans[3][3]={};
    int *heap;
    int ansans=0;
    int math=0;

    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            scanf("%d",&num[i][j]);
        }
    }

    scanf("%d",&N);
    heap = (int *)malloc(N*sizeof(int));

    for(int i=0;i<N;i++){
        scanf("%d",&heap[i]);
    }
    
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            for(int k=0;k<N;k++){
                if(num[i][j]==heap[k]){
                    ans[i][j]=1;
                }
            }
        }
    }
    
    for(int i=0;i<3;i++){
        ansans = 0;
       for(int j=0;j<3;j++){
           ansans+=ans[i][j];
       }
      if(ansans == 3){
          math=1;
      }
    }

    for(int j=0;j<3;j++){
        ansans = 0;
       for(int i=0;i<3;i++){
           ansans+=ans[i][j];
       }
      if(ansans == 3){
          math=1;
      }
    }
    
    
    if(ans[0][0]+ans[1][1]+ans[2][2] == 3){
        math = 1;
    }
    if(ans[0][2]+ans[1][1]+ans[2][0] == 3){
        math = 1;
    }
    
    if(math==1){
        printf("Yes\n");
    }else{
        printf("No\n");
    }

    /*    
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            printf("%d",ans[i][j]);
        }
        printf("\n");
    }
   */ 
    /*
    for(int i=0;i<3;i++){
        for(int j=0;j<3;j++){
            printf("%d",num[i][j]);
        }
    }
    */ 
    free(heap);
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_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(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
const long long INFLL = 1LL << 60;
const int INFINT = 1 << 30;
const long long MOD = 1e9 + 7;

template <class T> void vecout(T V) {
    auto t = V.begin();
    while(t != V.end()) {
        cout << *t++;
        if(t != V.end()) cout << " ";
    }
    cout << endl;
};

int main() {
    int n, m, t;
    cin >> n;
    vector<int> M(2020, 0);
    vector<int> P(n + 1, 0);
    rep(i, 1, n + 1) {
        cin >> t;
        M[t] = i;
        P[i] = t;
    }
    cin >> m;
    rep(i, m) {
        cin >> t;
        if(P[t] != 2019 && M[P[t] + 1] == 0) {
            M[P[t]] = 0;
            M[P[t] + 1] = t;
            P[t]++;
        }
    }

    rep(i, 1, n + 1) { cout << P[i] << "\n"; }
}


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

double PI = 3.141592653589793;

int64_t mypow(int64_t x, int64_t y, int64_t MOD) //x ^ y
{
    if (y == 0)
        return 1;
    if (y == 1)
        return x;
    else if (y % 2 == 1)
        return mypow(x, y - 1, MOD) * x % MOD;
    else
    {
        int64_t tmp = mypow(x, y / 2, MOD);
        return tmp * tmp % MOD;
    }
}

int popcount(int64_t N)
{
    int x = 0;
    while (N > 0)
    {
        if (N % 2 == 1)
            x++;
        N /= 2;
    }
    return x;
}

int main()
{
    int N, one = 0;
    string X;
    cin >> N >> X;
    
    for (int i = 0; i < N; i++)
        if (X[i] == '1')
            one++;

    
    int plus = one + 1, minus = one - 1;

    bool  minus_ = false;
    if (minus == 0)
        minus_ = true, minus = 1;

    int p = 0, p_keta = 1, m = 0, m_keta = 1; //0→1,1→0
    reverse(X.begin(), X.end());
    for (int i = 0; i < N; i++)
    {
        if (X[i] == '1')
            p += p_keta, m += m_keta;
        p %= plus, m %= minus;
        p_keta = (p_keta * 2) % plus, m_keta = (m_keta * 2) % minus;
    }
    int tmp;
    reverse(X.begin(), X.end());
    for (int i = 0; i < N; i++)
    {
        int count = 0;
        if (X[i] == '0')
        {
            tmp = p;
            tmp = (tmp + mypow(2, N - 1 - i, plus)) % plus;
            while (tmp != 0)
            {
                tmp %= popcount(tmp);
                count++;
            }
            cout << count + 1 << endl;
        }
        if (X[i] == '1')
        {
            if(minus_)
                cout << 0 << endl;
            else
            {
                tmp = m;
                tmp = (tmp - mypow(2, N - 1 - i, minus) + minus) % minus;
                while (tmp != 0)
                {
                    tmp %= popcount(tmp);
                    count++;
                }
                cout << count + 1 << endl;
            } 
        }
    }
}

Measured memory_bytes: 3732
#include <bits/stdc++.h> 
#define rep(i,n) for (ll i = 0; i < (n); ++i)
#define size_of_array(array) (sizeof(array)/sizeof(array[0]))
#define MAX 100005
#define NIL -1
using ll =long long;
using namespace std;
using Graph=vector<vector<int>>;
using Field=vector<vector<int>>;
using P =pair<int,int>;

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

P f(int x){
    int a=x%10;
    int b=0;
    while(x){
        b=x;
        x/=10;
    }
    return P(a,b);
}

int main(){
    int n;
    cin>>n;
    map<P,int> freq;
    for(int i=1;i<=n;++i){
        P p=f(i);
        freq[p]++;
    }
    ll ans=0;
    for(int i=1;i<=n;++i){
        P p=f(i);
        P q(p.second,p.first);
        ans+=freq[q];
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <stack>
#include <map>
#define FOR(i,b,e) for(int i=b;i<e;i++)
#define REP(i,n) FOR(i,0,n)
using namespace std;

const int N = 100;
int n;
int d[N+1];
vector< vector<int> > ns;
queue<int> q;

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

  vector<int> v;
  ns.push_back(v);
  cin >> n;
  FOR(i, 1, n+1) {
    int id, k, x; cin >> id;
    vector<int> v;
    cin >> k;
    REP(j, k) {
      cin >> x;
      v.push_back(x);
    }
    ns.push_back(v);
  }

  FOR(i, 1, n+1) d[i] = -1;

  int u = 1;
  q.push(u);
  d[u] = 0;
  while (!q.empty()) {
    u = q.front();
    q.pop();
    REP(i, ns[u].size()) {
      int v = ns[u][i];
      if (d[v] == -1) {
        q.push(v);
        d[v] = d[u] + 1;
      }
    }
  }

  FOR(i, 1, n+1) {
    cout << i << " " << d[i] << endl;
  }
}


Measured memory_bytes: 3200
#include<stdio.h>
int num[200001];
long long ZZ(long long a, long long b)
{
    return a > b ? a - b : b - a;
}
int main()
{
    long long sum = 0;
    int n, i;
    scanf("%d", &n);
    for (i = 0; i < n; i++)
    {
        scanf("%d", &num[i]);
        sum += num[i];
    }
    if(n == 2)printf("%lld", ZZ(num[0], num[1]));
    else
    {
        long long ans = 1e+16;

        long long summ = 0;
        for (i = 0; i < n - 1; i++)
        {
            summ += num[i];
            ans = ans < ZZ(sum - summ, summ) ? ans : ZZ(sum - summ, summ);
        }
        printf("%lld",ans);
    }
    return 0;
}


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

const signed int t[2][6] = {{1, -1, 1, 4, 5, 2},
                         {2, 3, -1, 5, 2, 1},
                         };

int main(void){
  string str;
  while(cin >> str, str != "#"){
    bool flg = true;
    int now_pos = 0;
    for(int p=0; p < str.size(); p++){
      if(t[str[p] - '0'][now_pos] == -1){
        cout << "No" << endl;
        flg = false;
        break;
      }else{
        now_pos = t[str[p] - '0'][now_pos];
      }
    }
    if(now_pos == 5){
      cout << "Yes" << endl;
    }else if(flg){
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 1180
/**
 *      ABC 89 C
 *      author  : kyomukyomupurin
 *      created : 2018-09-01 02:38:24
**/
typedef long long ll;
#include <bits/stdc++.h>
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int N; cin >> N;
    vector<string> S;
    for (int i = 0; i < N; ++i) {
        string x; cin >> x;
        S.push_back(x);
    }

    ll m = 0; ll a = 0; ll r = 0; ll c = 0; ll h = 0;
    for (int i = 0; i < N; ++i) {
        if (S[i].at(0) == 'M'){
            ++m;
        }
        else if (S[i].at(0) == 'A'){
            ++a;
        }
        else if (S[i].at(0) == 'R'){
            ++r;
        }
        else if (S[i].at(0) == 'C'){
            ++c;
        }
        else if (S[i].at(0) == 'H'){
            ++h;
        }
    }

    cout << m*a*r+m*a*c+m*a*h+m*r*c+m*r*h+m*c*h+a*r*c+a*r*h+a*c*h+r*c*h << endl;

    return 0;
}


Measured memory_bytes: 5748
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define MOD 1000000007
using Graph=vector<vector<int>>;

int main(){
  int N;
  cin>>N;
  vector<vector<int>> A(N,vector<int>(N-1));
  for(int i=0;i<N;i++){
    for(int j=0;j<N-1;j++){
      cin>>A.at(i).at(j);
      A.at(i).at(j)--;
    }
  }

  bool flag=true;
  vector<int> finish(N,0),day(N,0);
  while(1){
    bool sub=false;
    int sum=0;
    for(int i=0;i<N;i++){
      sum+=finish.at(i);
      if(finish.at(i)==N-1){
        continue;
      }
      int x=A.at(i).at(finish.at(i));
      if(A.at(x).at(finish.at(x))==i){
        sub=true;
        finish.at(i)++;
        finish.at(x)++;
        day.at(x)=max(day.at(i)+1,day.at(x)+1);
        day.at(i)=day.at(x);
        break;
      }
    }
    if(sum==N*(N-1)){
      break;
    }
    if(sub){
      continue;
    }
    flag=false;
    break;
  }
  if(flag){
    int ans=0;
    for(int i=0;i<N;i++){
      ans=max(ans,day.at(i));
    }
    cout<<ans<<endl;
  }else{
    cout<<-1<<endl;
  }

}


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

using namespace std;
#define all(a)a.begin(),a.end()
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll=long long;
const int INF = 1<<30;
const ll INFll =1LL<<62;
const int mod = int(1e9)+7;
using V = vector<int >;
using P = pair<int,int>;

int main()
{
   ll l,r;cin >>l>>r;
   ll ans=INF;
   int m=2019;
   if(r-l+1>=m)ans=0;
   else {
    for(ll i=l;i<r;i++){
        for(ll j=i+1;j<=r;j++){
        ans=min(ans,((i%m)*(j%m)%m));
        }
    }
   }

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
 
const int MAXN = 1e5+1;
const int MOD = 1e9+7;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second 
#define debug(x)  do{cerr<<#x<<": "<<x<<"\n";}while(0)
#define debugv(x) do{cerr<<#x<<": ";for(auto&e: (x))cerr<<e<<" ";cerr<<"\n";}while(0)
#define FAIL0 {cout << "0\n"; return 0;}
#define FAIL1 {cout << "-1\n"; return 0;}
#define FAILNO {cout << "No\n"; return 0;}
#define YES {cout << "Yes\n"; return 0;}

int N;
multiset<int> S;

int main() {
#ifdef OJ
    freopen("input.txt", "rt", stdin);
    //freopen("output.txt", "wt", stdout);
#endif
    ios::sync_with_stdio(false);
    cin.tie(0);
 
    cin >> N;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        if (S.size()) {
            auto it = S.lower_bound(a);
            if (it != S.begin()) {
                --it;
                S.erase(it);
            }
        }
        S.insert(a);
    }

    cout << S.size() << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
#include <fstream>
#include <utility>
#include <functional>
#include <time.h>
#include <stack>
#include <array>
#include <list>
#define popcount __builtin_popcount
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll MOD=1e9+7;
ll powmod(ll a, ll k){
    ll ap=a, ans=1;
    while(k){
        if(k&1){
            ans*=ap;
            ans%=MOD;
        }
        ap=ap*ap;
        ap%=MOD;
        k>>=1;
    }
    return ans;
}
ll inv(ll a){
    return powmod(a, MOD-2);
}
ll f[1000010], invf[1000010];
void fac(int n){
    f[0]=1;
    for(ll i=1; i<=n; i++) f[i]=f[i-1]*i%MOD;
    invf[n]=inv(f[n]);
    for(ll i=n-1; i>=0; i--) invf[i]=invf[i+1]*(i+1)%MOD;
}
ll comb(int x, int y){
    if(!(0<=y && y<=x)) return 0;
    return f[x]*invf[y]%MOD*invf[x-y]%MOD;
}

int main()
{
    int n, m; cin>>n>>m;
    fac(m);
    ll ans=0;
    for(int i=0; i<=n; i++){
        ll x=comb(m-i, n-i)*f[n-i]%MOD*comb(n, i)%MOD;
        if(i&1) (ans+=MOD-x)%=MOD;
        else (ans+=x)%=MOD;
    }
    ans=ans*comb(m, n)%MOD*f[n]%MOD;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 11440
#include<stdio.h>
#define N 20
#define Q 200
#define true 1
#define false 0

int A[N];
int n;

int solve(int i, int m){

  int res;

  if(m==0) return true;
  if(i>n) return false;

  res = solve(i+1,m) || solve(i+1,m-A[i]);

  return res;

}

int main(){

  int i,j,q,b,check=0;
  int M[Q];

  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[i]);
  }

  for(j=0;j<q;j++){
    i=0;
    if(solve(i,M[j])==true) {
      check++;
    }
    if(check!=0){
      printf("yes\n");
      check=0;
    }
    else printf("no\n");
  }

  return 0;
  
}




Measured memory_bytes: 2108
w = int(input())
n = int(input())

nums = [i for i in range(1,w+1)]

for i in range(n):
    try:
        a, b = list(map(lambda x:int(x)-1, input().split(",")))
    except EOFError:
        break
    nums[a], nums[b] = nums[b], nums[a]

for i in nums:
    print(i)

Measured memory_bytes: 7632
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
int main(void){

	int a[100000];
	int c, d;
	int k;
	int n, m;
	int s, t;
	int x, y, z;
	int ans;
	int max;
	int min;
	for (int i = 0; i < 100000; i++)a[i] = 0;
	scanf("%d", &n);
	max = -1;
	min = 1000001;
	for (int i = 0; i < n; i++){
		scanf("%d", &m);
		if (m > max)max = m;
		if (m < min)min = m;
		a[m]++;
	}

	if (max == min){
		if (max <= n / 2||max==n-1)printf("Yes\n");
		else printf("No\n");
	}
	else if (max == min + 1){
		if (a[min] <= min&&max - a[min] <= a[max] / 2)printf("Yes\n");
		else printf("No\n");
	}
	else printf("No\n");

	return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int x1, x2, x3, x4, x5;
  cin>>x1>>x2>>x3>>x4>>x5;
  if(x1==0){
    cout<<1<<endl;
  }
  if(x2==0){
    cout<<2<<endl;
  }
  if(x3==0){
    cout<<3<<endl;
  }
  if(x4==0){
    cout<<4<<endl;
  }
  if(x5==0){
    cout<<5<<endl;
  }
}



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

#define int long long
//struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (LL i = (a); i < (LL)(n); ++i)
#define REP(i, n) REPS(i, 0, n)
#define DEPS(i, a, n) for (LL i = (a); i >= (LL)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i = (n).begin(); i != (n).end(); ++i)
#define REACH(i, n) for (auto&& i = (n).rbegin(); i != (n).rend(); ++i)
#define FILL(arr,val) fill((arr), (arr)+sizeof(arr)/sizeof((arr)[0]), (val))

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using LL = long long;
using ULL = unsigned long long;
using DBL = double;
using CPX = complex<DBL>;
using VI = vector<int>;
using VVI = vector<VI>;
using VVVI = vector<VVI>;
using VS = vector<string>;
using PII = pair<int, int>;
using PIS = pair<int, string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const LL LINF = 1001001001001001001LL;
const int MOD = 1e9 + 7;
const DBL EPS = 1e-12;
const DBL PI=3.1415926535897932384626;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1};
const int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W)
  {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in()
  {int x; cin >> x; return x;}
inline LL IN()
  {LL x; cin >> x; return x;}
inline VS split(const string& t, char c)
  {VS v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b)
  {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b)
  {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p)
  {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x)
  {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v)
  {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ")
  {REP(i, v.size()) cout << v[i] << (i != (LL)v.size() - 1 ? s : "\n");}

int dist(int pos, int t) {
  if (pos <= t) {
    return (t-pos)*(t-pos);
  } else {
    return (pos-t)*(pos-t);
  }
}

signed main() {
  int N = in();
  VI vi;
  REP(i,N) { vi.pb(in()); }

  int min = INF;
  REP(pos,100) {
    int sum = 0;
    REP(i,N) {
      sum += dist(vi[i], pos);
    }
    chmin(min, sum);
  }
  print(min);
  return 0;
}

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

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

    int  first = 10 * (S[0] - '0') + S[1] - '0';
    int  last = 10 * (S[2] - '0') + S[3] - '0';

    if(0 < first && first < 13)
    {
        if(0 < last && last < 13)
            cout << "AMBIGUOUS" << endl;
        else 
            cout << "MMYY" << endl;
    }
    else
    {
        if(0 < last && last < 13)
            cout << "YYMM" << endl;
        else 
            cout << "NA" << endl;
    }
    
    return 0;  

}

Measured memory_bytes: 256
#include <iostream>
#include <tuple>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
using namespace std;
#define REP(var, num) for(sll var = 0; var < num; var++)
typedef signed long long sll;
typedef unsigned long long ull;

/*
numeric_limits<sll>::max()
*/

int main() {
    sll n, k;
    cin >> n >> k;
    vector<sll> hs(n);
    vector<sll> dp(n);

    REP(i, n) {
        cin >> hs[i];
    }

    REP(i, n) {
        if (i == 0) {
            dp[i] = 0;
        } else if (i == 1) {
            dp[i] = abs(hs[1] - hs[0]);
        } else {
            dp[i] = numeric_limits<sll>::max();
            for (sll j = 1; j <= i && j <= k; j++) {
                dp[i] = min(dp[i], abs(hs[i] - hs[i - j]) + dp[i - j]);
            }
        }
    }

    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
#include <iomanip>
using namespace std;
// type alias
typedef long long LL;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))

// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');

// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpf(args...) if(TRACE) { fprintf(stderr, ##args); putchar('\n'); }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
template<class Iter> void dumpc(Iter begin, Iter end) { if (TRACE) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } }

// $ cp-batch OnestrokePath | diff OnestrokePath.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address OnestrokePath.cpp && ./a.out

/*
 
 1/16/2019
 
 20:12-
 
 */

const int MAX_N=1e2;
VI G[MAX_N];
int N,M;

bool dfs(int i, VI &P) {
  if(i==N-1) return 1;
  int u=P[i],v=P[i+1];
  FORR(w,G[u]) if(w==v) return dfs(i+1,P);
  return 0;
}
void solve() {
  LL res=0;
  VI P(N); REP(i,N)P[i]=i;
  do {
    if(P[0]!=0) continue;
    res+=dfs(0,P);
  } while(next_permutation(ALL(P)));
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>N>>M;
  REP(i,M) {
    int u,v; cin>>u>>v;
    --u,--v;
    G[u].push_back(v);
    G[v].push_back(u);
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cstring>
#include <iostream>

using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define TRACE(x) cout << #x << " = " << x << endl
#define _ << " _ " <<

typedef long long llint;

int main(void) {
  char s[111];
  scanf("%s", s);

  REP(i, strlen(s)) REP(j, i)
    if (s[j] == 'C' && s[i] == 'F') {
      puts("Yes");
      return 0;
    }
  puts("No");
  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
      long N = sc.nextLong();
      long A = sc.nextLong();
      long B = sc.nextLong();
      long AB = A+B;
      long AA = (N/AB)*A;
      if((N%AB)>=A){
        AA +=A;
      }else{
        AA +=N%AB;
      }

      System.out.println(AA);


    }
  
  private static long lcm(long m, long n) {
    return m * n / gcd(m, n);
}
  
  private static long gcd(long m, long n) {
    if(m < n) return gcd(n, m);
    if(n == 0) return m;
    return gcd(n, m % n);
}
}


Measured memory_bytes: 21844
n,m = map(int, input().split())
 
arS = [False] * (n+1)
arP = [False] * (n+1)
 
score = 0
penalty = 0

for i in range(m):
	id, res = input().split()
	id = int(id)
	if (res == "AC") and (arS[id]==False):
		arS[id] = True
		score = score+1
		penalty = penalty + arP[id]
	if (res == "WA"): 
		arP[id] = arP[id] + 1
        
print(score, penalty)

Measured memory_bytes: 4596
import sys

input = sys.stdin.readline


class AtCoder:
    def main(self):
        N = int(input())

        divisors = self.make_divisors(N)
        a, b = 1, N
        for d in divisors:
            if a + b > d + N // d:
                a = d
                b = N // d

        print(a + b - 2)

    def make_divisors(self, n: int):
        divisors = []
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                divisors.append(i)
                if i != n // i:
                    divisors.append(n // i)

        return divisors


# Run main
if __name__ == '__main__':
    AtCoder().main()


Measured memory_bytes: 3272
#include <iostream>

using namespace std;

int main(int argc, const char * argv[]) {
    int N = 0;
    int A = 0; // train fee per person
    int B = 0; // taxi fee for N people
    cin >> N >> A >> B;

    int trainFee = N * A;
    if(trainFee < B) {
        cout << trainFee << endl;
    } else {
        cout << B << endl;
    }
    return 0;
}


Measured memory_bytes: 256
n = gets.chomp.to_i
b_arr = [10**5+1] + gets.chomp.split(" ").map(&:to_i) + [10**5+1]

a_arr = []
b_arr.each_cons(2).with_index do |(b1, b2)|
  if b1 > b2 then
    a_arr << b2
  else
    a_arr << b1
  end
end

puts a_arr.inject(&:+)


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using ULL = unsigned long long;
using VI = vector<int>;
using VL = vector<LL>;
using PII = pair<int, int>;
using PLL = pair<LL, LL>;

#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define MP make_pair
#define PB push_back
#define EB emplace_back
#define F first
#define S second
#define FOR(i, a, b) for (int i = (a); i<(b); ++i)
#define RFOR(i, b, a) for (int i = (b)-1; i>=(a); --i)
#define FILL(a, b) memset(a, b, sizeof(a))

void dout() { cerr << endl; }

template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

const int mod = 998244353;

int add(int a, int b)
{
    a += b;
    if (a >= mod)
        a -= mod;
    return a;
}

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

int mul(int a, int b)
{
    return (LL)a * b % mod;
}

const int maxN = 2e5 + 47;
int bit[maxN];

void inc(int pos, int val)
{
    for (int i = pos + 1; i < maxN; i += i & -i)
        bit[i] = add(bit[i], val);
}

int sum(int pos)
{
    int res = 0;
    for (int i = pos + 1; i > 0; i -= i & -i)
        res = add(res, bit[i]);
    return res;
}

int sum(int l, int r)
{
    return sub(sum(r), sum(l - 1));
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n, k;
    cin >> n >> k;
    VI l(k);
    VI r(k);
    FOR(i, 0, k)
    {
        cin >> l[i] >> r[i];
    }
    VI dp(n);
    dp[0] = 1;
    inc(0, 1);
    FOR(i, 1, n)
    {
        for (int j = 0; j < k; j++)
        {
            if (i - l[j] >= 0)
            {            
                int x = max(0, i - r[j]);
                int y = max(0, i - l[j]);
                dp[i] = add(dp[i], sum(x, y));
            }
        }
        inc(i, dp[i]);
    }
    cout << dp.back();
    return 0;
}

Measured memory_bytes: 4860
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    int n;
    cin >> n;
    vector<pair<int, int>> v(n);
    vector<int> ans(n);
    for (int i = 0; i < n; ++i) {
        int x;
        cin >> x;
        v[i] = {x, i};
    }
    sort(v.begin(),v.end());
    for (int i = 0; i < n-1; ++i) {
        ans[v[i].second] = v.back().first;
    }
    ans[v.back().second] = v[n-2].first;
    for (int i = 0; i < n; ++i) {
        cout << ans[i] << "\n";
    }
    return 0;
}

Measured memory_bytes: 3968
#include <iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    if(a==b)
    {
        cout<<"Draw"<<endl;
    }
    else
    {
        if(a==1)
            cout<<"Alice"<<endl;
        else if(b==1)
            cout<<"Bob"<<endl;
        else
        {
            if(a>b)
                cout<<"Alice"<<endl;
            else
                cout<<"Bob"<<endl;
        }
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define all(x) x.begin(), x.end()
#define MOD 1000000007
#define vi vector < int >
#define pii pair < int, int >
#define INF (int)1e9
#define pb push_back
#define fastIO ios::sync_with_stdio(0); cin.tie(0);

int n, w;
vector < pii > arr;

ll cache[110][100010];

ll dpSol(int i, int val)
{
    if(i == n)
    {
        if(val == 0)
            return 0;
        return INT_MAX;
    }
    
    ll &res = cache[i][val];
    if(res != -1)
        return res;
    
    res = INT_MAX;
    if(val - arr[i].second >= 0)
        res = min(res, arr[i].first + dpSol(i + 1, val - arr[i].second));
    res = min(res, dpSol(i + 1, val));
    return res;
}

int main()
{
    fastIO
    
    memset(cache, -1, sizeof(cache));
    
    cin >> n >> w;
    arr = vector < pii >(n);
    
    for(int i = 0; i < n; ++i)
        cin >> arr[i].first >> arr[i].second;
    
    int maxele = 0;
    for(int v = 100000; v >= 0; --v)
    {
        if(dpSol(0, v) <= w)
        {
            cout << v;
            break;
        }
    }

    return 0;
}

Measured memory_bytes: 86272
#include<bits/stdc++.h>
using namespace std;
int mod(int n, int k){
    if(n%k < 0)
        return n-(n/k+1)*k;
    else
        return n%k;
}
int main()
{
    int n;int flag = 0;
    cin>>n;
    if(n==0)
    {
        cout<<"0"<<endl;
        return 0;
    }
    string ans = "";
    while(n)
    {
        char a = mod(n,-2) + '0';
        //cout<<a<<endl;
        ans = ans + a;
        if(n%-2 < 0)
            n = n/-2+1;
        else
            n /= -2;
    }
    reverse(ans.begin(), ans.end());
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n)  FOR(i,0,n)
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<vector<P>> Graph;

uintmax_t comb(unsigned int n, unsigned int r) {
  if ( r * 2 > n ) r = n - r;
  uintmax_t dividend = 1;
  uintmax_t divisor  = 1;
  for ( unsigned int i = 1; i <= r; ++i ) {
    dividend *= (n-i+1);
    divisor  *= i;
  }
  return dividend / divisor;
}

int main(){

  int n;
  cin >> n;
  
  int a[2*n];
  REP(i,2*n) cin >> a[i];
  
  sort(a,a+2*n);
  
  int ans = 0;
  
  REP(i,n) ans += a[i*2];

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

Measured memory_bytes: 256
//
//  main.cpp
//  CPPTest
//
//  Created by 若淮 廖 on 2018/9/28.
//  Copyright © 2018年 若淮 廖. All rights reserved.
//

#include <iostream>
using namespace std;

int main(int argc, const char * argv[]) {
    // insert code here...
    //std::cout << "Hello, World!\n";
    int a=0,b=0,c=0;
    cin >>a>>b>>c;
    
    int sum=0;
    
    if (a>b){
        if (a>c){
            sum = a*10 + c + b;
        }else{
            sum = c*10 + a + b;
        }
    }else{
        if (b>c){
            sum = b*10 + c + a;
        }else{
            sum = c*10 + b + a;
        }
    }
    
    cout <<sum;
    
    return 0;
}


Measured memory_bytes: 256