akhauriyash/Code-Regression huggingface dataset:
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars()
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize, a: usize, b: usize
    }

    let back = if n % (a+b) < a { n % (a+b) } else { a };

    println!("{}", (n - n % (a+b))/(a+b)*a + back);
}



Measured memory_bytes: 4352
/* Coached by rainboy */
#include <stdio.h>
#include <string.h>

#define N 50
#define M 50

int ii[4] = { -1, 1, 0, 0 };
int jj[4] = { 0, 0, -1, 1 };

int min(int a, int b) {
	return a < b ? a : b;
}

int main() {
	static char cc[N][M];
	static int aa[N][M];
	int n, m, h, i, j, i_, j_, k, cnt;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++)
		scanf("%s", cc[i]);
	for (i = 0; i < n; i++)
		memset(aa[i], 0x3f, m * sizeof *aa[i]);
	aa[0][0] = 1;
	for (k = 0; k < n * m; k++)
		for (i = 0; i < n; i++)
			for (j = 0; j < m; j++)
				for (h = 0; h < 4; h++) {
					i_ = i + ii[h];
					j_ = j + jj[h];
					if (i_ >= 0 && j_ >= 0 && i_ < n && j_ < m && cc[i_][j_] == '.')
						aa[i_][j_] = min(aa[i_][j_], aa[i][j] + 1);
				}
	if (aa[n - 1][m - 1] == 0x3f3f3f3f) {
		printf("-1\n");
		return 0;
	}
	cnt = 0;
	for (i = 0; i < n; i++)
		for (j = 0; j < m; j++)
			if (cc[i][j] == '#')
				cnt++;
	printf("%d\n", n * m - aa[n - 1][m - 1] - cnt);
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define Nmax 100005
#define ll long long
using namespace std;
ll v[Nmax];
ll pd[Nmax];
inline ll mdl(ll x)
{
    if(x<0) return -x;
    return x;
}
int main() 
{
    ll n,i,s=0;
    cin>>n;
    for(i=1;i<=n;i++)
    {
        cin>>v[i];
        pd[i]=mdl(v[i-1]-v[i]);
        s+=pd[i];
    }
    pd[n+1]=mdl(v[n]);
    s+=pd[n+1];
    ll ans;
    for(i=1;i<=n;i++)
    {
        ans=s-(pd[i]+pd[i+1]);
        ans+=mdl(v[i-1]-v[i+1]);
        cout<<ans<<'\n';
    }
   
    return 0;
}

Measured memory_bytes: 2816
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <time.h>
#define PI 3.14159265358979323846


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

	if ((S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) || (S[0] == S[2] && S[1] == S[3] && S[0] != S[1]) || (S[0] == S[3] && S[1] == S[2
	] && S[0] != S[1])) {
		printf("Yes");
	}
	else {
		printf("No");
	}
	



	return 0;
}


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

int64_t attack(int64_t h) {
  if (h == 1) {
    return 1;
  }
  int64_t k = 2 * attack(h / 2) + 1;
  return k;
}

int main() {
  int64_t H;
  cin >> H;
  
  int64_t ans = attack(H);
  
  cout << ans << endl;
}

Measured memory_bytes: 256
/*
  The Island Was Silent before.
  .....
  And One day again it became Silent.
*/
#include<bits/stdc++.h>
using namespace std;
 
#define endl '\n'
#define ll  long long
#define modd(a,b) ((a+2*b)%b)
#define debug(a) cout << #a << ": " << (a) << "\n"
#define ioso ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define rtt cerr << "Time: " << clock()*1.0 / CLOCKS_PER_SEC << endl;
#define ffe freopen("input.txt","r",stdin), freopen("output.txt","w",stdout);
 
int main() {
  #ifndef ONLINE_JUDGE
  ioso //ffe
  #endif
  ll n; cin >> n;
  int a[100010];

  for(int i=0;i<n;i++) {
    cin >> a[i];
  }
  ll f = 0, as = 0;
  for (int i = 0; i < n; ++i)
  {
    if(a[i]>a[i-1]) {f=0;}
    else {
      f++;
    }
    as = max(as,f);
  }

  cout << as << endl;
}

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

#define int long long

#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define FORR(i,m,n) for(int i=m;i>=n;i--)
#define pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999

using namespace std;

int32_t main(){
    int d, g;
    cin >> d >> g;

    vector<int> p, c;
    int cnt = 0;
    REP(i, d){
        int a, b;
        cin >> a >> b;

        p.pb(a); c.pb(b);
    }

    int ans=INF;
    REP(i, pow(2, d)){
        int cnt, scr = cnt = 0;
        REP(j, d){
            if(i & (1 << j)){
                scr+=(100*(j+1)*p[j] + c[j]);
                cnt+=p[j];
            }
        }

        for(int j=d-1; j>=0; j--){
            if(!(i & (1 << j))){
                int k = 0;
                while(scr < g && k < p[j]){
                    scr+=(j+1)*100;
                    cnt++;
                    k++;
                }
                break;
            }
        }
        
        if(scr >= g) ans = min(ans, cnt);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
n,h = map(int,input().split())
katana_a = []
katana_b = []
for i in range(n):
    a,b = map(int,input().split())
    katana_a.append(a)
    katana_b.append(b)
amax = max(katana_a)
katana_b.sort(reverse=True)
ans = 0
k = 0
while h > 0:
    if k == n:
        break
    if katana_b[k] > amax:
        h -= katana_b[k]
        ans += 1
        k += 1
    else:
        break
if h <= 0:
    print(ans)
else:
    print(ans + (h+amax-1)//amax)






Measured memory_bytes: 61528
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <functional>

using namespace std;
int N, M;
typedef pair<int, int> P;
int main(){

  while(cin >> N >> M && N && M){
    P cnt[100];
    for(int i=0; i<100; ++i) cnt[i].second = i+1;
    
    for(int i=0; i<N; i++){
      for(int j=0; j<M; j++){
        int k;
        cin >> k;
        cnt[j].first -=k;
      }
    }
    sort(cnt, cnt+M);
    for(int j=0; j<M; j++){
      cout << cnt[j].second;
      j<M-1 ? cout << " " : cout << "";
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi; 
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
const int mod = 1e9+7;
const int maxn = 2e5+10;
const int inf = 0x3f3f3f3f;
queue<ll> q;
int main()
{
	ios::sync_with_stdio(false);cin.tie(0); 
	int n;
	cin>>n;
	if(n<=9) {
		cout<<n<<'\n';
		return 0;
	}
	rep(i,1,9) q.push(i);
	n-=9;
	ll ans;
	while(1) {
		ll now=q.front();q.pop();
		ll last=now%10;
		now*=10;
		if(last>=1) {
			n--;
			q.push(now+last-1);
			if(n==0) {
				ans=now+last-1;
				break;
			}
		}
		q.push(now+last);
		n--;
		if(n==0) {
			ans=now+last;
			break;
		}
		if(last<=8) {
			n--;
			q.push(now+last+1);
			if(n==0) {
				ans=now+last+1;
				break;
			}
		}
	}
	cout<<ans<<'\n';
	return 0;
}

Measured memory_bytes: 768
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;
using System.Numerics;

namespace disco20201
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_disco20201B();
        }

        public static void solve_disco20201B()
        {
            int n = Convert.ToInt32(Console.ReadLine());
            long[] a = Array.ConvertAll(Console.ReadLine().Split(), long.Parse);

            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                sum += a[i];
            }
            long diff = 0;
            long min = long.MaxValue;
            for (int i = 0; i < n; i++)
            {
                diff += a[i];
                min = Math.Min(min, Math.Abs(diff - (sum - diff)));
            }
            Console.WriteLine(min);
        }

        public static void solve_disco20201A()
        {
            int[] xy = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);

            int x = xy[0];
            int y = xy[1];

            int total = 0;
            if (x == 1)
            {
                total = 300000;
            }
            else if (x == 2)
            {
                total = 200000;
            }
            else if (x == 3)
            {
                total = 100000;
            }
            if (y == 1)
            {
                total += 300000;
            }
            else if (y == 2)
            {
                total += 200000;
            }
            else if (y == 3)
            {
                total += 100000;
            }

            if (x == 1 && y == 1)
            {
                total += 400000;
            }

            Console.WriteLine(total);
        }
    }
}


Measured memory_bytes: 33360
'use strict';
const i = require("fs").readFileSync("/dev/stdin", "utf8").split("\n");
let s = i[0], p = parseInt(i[1]), code, result = "";
for(let j = 0;j < s.length;j++){
  code = s[j].charCodeAt(0);
  if (s.length - 1 === j) {
    code += p%26;
    code += (code > 122)? -26:0;
    result += String.fromCharCode(code);
  } else {
    if((123 - code) <= p && !(s[j] === "a")){
      p -= (123 - code);
      result += "a";
    }else{
      result += s[j];
    }
  }
}
console.log(result);

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

int main() {
    int n,k;
    long long int ans = 0;
    cin >> n >> k;
    vector<long long int> h(n);
    for(int i = 0; i < n; i++){
        cin >> h.at(i);
    }
    sort(h.begin(),h.end());

    if(n <= k){
        cout << "0" << endl;
    }else{
        for(int i = 0; i < n-k; i++){
            ans += h.at(i);
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1792
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef pair<ld, ld> pld;
typedef pair<string, string> pss;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define file_io                     freopen("in.txt" , "r+" , stdin) ; freopen("out.txt" , "w+" , stdout);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

inline ll input() {
    ll n;
    cin >> n;
    return n;
}

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

set_random;

const ll MAXN = 1e6 + 10;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

template <ll SIZE>
struct DSU
{
    ll par[SIZE] , sz[SIZE];
    DSU(){
        fill(par , par + SIZE , -1);
        fill(sz , sz + SIZE , 1);
    }

    ll Find(ll v){
        return (par[v] == -1 ? v : par[v] = Find(par[v]));
    }

    ll Union(ll v , ll u){
        ll pv = Find(v) , pu = Find(u);
        if(pv == pu)    return 0;
        par[pu] = pv;
        sz[pv] += sz[pu];
        return 1;
    }

    ll getSize(ll v){
        return sz[Find(v)];
    }

    ll getComps(ll l , ll r){
        ll ans = 0;
        for(ll i = l ; i <= r ; i++){
            (ans += Find(i) == i);
        }
        return ans;
    }
};

ll n , m , x , y , z;
DSU<MAXN> dsu;

int main() {
    fast_io;

    cin >> n >> m;
    for(ll i = 0 ; i < m ; i++)
    {
        cin >> x >> y >> z;
        dsu.Union(x , y);
    }
    cout << dsu.getComps(1 , n) << endl;

    return 0;
}
/*
todo :
    1- set constants
    2- check TimeLimit and MemoryLimit
    3- check special test cases
    4- don't forget BS can help you that is good idea(use for loop for floats)
    5- don't forget printf and scanf can help you in your code speed
*/


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

int main()
{
	
	string s;
	cin>>s;
	if(s[2] == s[3] && s[4] == s[5])
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;	
	}
	
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<cassert>
#include<stdexcept>
#include<utility>
#include<functional>
#include<numeric>
#include<cmath>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<array>
#include<stack>
#include<queue>
#include<deque>
#include<vector>
#include<complex>
#include<set>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include<string>
#include<bitset>
#include<memory>
using namespace std;
using ll=long long;

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

    vector<vector<ll>> pat(N+2,vector<ll>(N+2));
    pat[1][0]=1;
    for(int i=0;i<pat.size();i++){
        for(int j=0;j<pat[0].size();j++){
            if(j+1<pat[0].size()) (pat[i][j+1]+=pat[i][j]*i)%=M;
            if(i+1<pat.size()) (pat[i+1][j]+=pat[i][j])%=M;
        }
    }

    vector<vector<ll>> dp(K+1,vector<ll>(N+2));
    dp[0][1]=1;
    for(int i=0;i<K;i++){
        for(int j=0;j<=N+1;j++){
            for(int k=0;j+k<=N+1;k++){
                (dp[i+1][j+k]+=dp[i][j]*pat[j][k])%=M;
            }
        }
    }
    
    cout<<dp[K][N+1]<<endl;
    return 0;
}


Measured memory_bytes: 1664
#include<stdio.h>
#include<string.h>


typedef struct tag_edge_t
{
	int to;
	struct tag_edge_t *next;
}edge_t;

typedef struct
{
	int dp[11];
	edge_t *edge;
}node_t;

typedef struct
{
	int v, d, c, id;
}paint_t;


node_t node[100000+1];
paint_t paint[100000+1];
edge_t g_edge[100000*2];
int edge_num;


void node_edge_add(int a, int b)
{
	edge_t *edge;

	edge=&g_edge[edge_num++];
	edge->next=node[a].edge;
	edge->to=b;
	node[a].edge=edge;

	edge=&g_edge[edge_num++];
	edge->next=node[b].edge;
	edge->to=a;
	node[b].edge=edge;
}


void solve(paint_t paint)
{
	edge_t *edge;

	if(node[paint.v].dp[paint.d]) return;
	node[paint.v].dp[paint.d]=paint.id;
	if(paint.d==0) return;

	paint.d--;
	edge=node[paint.v].edge;
	for(;edge;edge=edge->next)
	{
		paint.v=edge->to;
		solve(paint);
	}
}


int max(int a, int b)
{
	if(a>b) return a;
	return b;
}

int main(void)
{
	int N, M, a, b, Q;
	int i, j, result;

	while(scanf("%d%d", &N, &M)==2)
	{
		memset(node, 0, sizeof(node));
		edge_num=0;

		for(i=0;i<M;i++)
		{
			scanf("%d%d", &a, &b);
			node_edge_add(a, b);
		}
		scanf("%d", &Q);
		for(i=1;i<=Q;i++)
		{
			scanf("%d%d%d", &paint[i].v, &paint[i].d, &paint[i].c);
			paint[i].id=i;
		}
		for(i=Q;i>0;i--)
		{
			solve(paint[i]);
		}
		for(i=1;i<=N;i++)
		{
			result=0;
			for(j=0;j<=10;j++)
			{
				result=max(result, node[i].dp[j]);
			}
			printf("%d\n", paint[result].c);
		}
	}

	return 0;
}


Measured memory_bytes: 10752
use std::io::Read;
use std::collections::HashSet;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();

    let answer = solve(&buf);

    println!("{}", answer);
}

fn solve(input: &str) -> String {
    let mut iterator = input.split_whitespace();

    let set: HashSet<usize> = (0..3).map(|_| iterator.next().unwrap().parse().unwrap()).collect();
    return set.len().to_string();
}


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

int main(){
    int q;
    string str, o;
    int n_s, n_e;
    
    cin >> str;
    cin >> q;
    
    for(int i = 0; i < q; i++){
        cin >> o;
        cin >> n_s >> n_e;
        
        if(o == "print"){
            cout << str.substr(n_s, n_e - n_s + 1) << endl;
        }
        else if(o == "reverse"){
            string s = str.substr(n_s, n_e - n_s + 1);
            reverse(s.begin(), s.end());
            str = str.substr(0, n_s) + s + str.substr(n_e + 1, (str.size() - n_e));
        }
        else if(o == "replace"){
            string s;
            cin >> s;
            
            str = str.substr(0, n_s) + s + str.substr(n_e + 1, (str.size() - n_e));
        }
    }
    
    return 0;
}


Measured memory_bytes: 3208
ans=[]
while True:
	try:
		k,l=list(map(int,input().split(" ")))
		init_k=k
		init_l=l
#
		while True:
			if k%l==0:
				gcd=l
				tmp_1=init_k/gcd
				tmp_2=init_l/gcd
				lcm=gcd*tmp_1*tmp_2
				break
			else:
				tmp=k%l
				k=l
				l=tmp
		gcd=int(gcd)
		lcm=int(lcm)
		ans.append(str(gcd)+" "+str(lcm))
	except:
		break

for i in ans:
	print(i)

Measured memory_bytes: 7576
#include <iostream>
#include <stack>
#include <vector>

using namespace std;

int n;
int V[105][105];
vector<int> d(105, 0), f(105, 0);
int t = 0;

void dfs(int x) {
	bool p = false;
	if (d[x] != 0) p = true;
	if (d[x] == 0) {
		t++;
		d[x] = t;
	}
	for (int j = 1; j <= n; j++) {
		if (V[x - 1][j - 1] == 1 && d[j] == 0) {
			dfs(j);
		}
	}
	t++;
	if (p) t--;
	if (f[x] == 0) f[x] = t;
}


int main() {
	cin >> n;
	for (int i = 0; i<n; i++) {
		for (int j = 0; j<n; j++) {
			V[i][j] = 0;
		}
	}
	for (int i = 0; i<n; i++) {
		int p, m;
		cin >> p >> m;
		for (int j = 0; j<m; j++) {
			int q;
			cin >> q;
			V[p - 1][q - 1] = 1;
		}
	}
	for (int i = 0; i<n; i++) {
		dfs(i + 1);
	}
	for (int i = 0; i<n; i++) {
		cout << i + 1 << " " << d[i + 1] << " " << f[i + 1] << endl;
	}
}

Measured memory_bytes: 3112
#!/usr/bin/env python3
from itertools import*
n, k, *A = map(int, open(0).read().split())

def imos(l, r):
    B[l] += 1
    if r + 1 != n:
        B[r + 1] -= 1

for _ in [0] * min(k, 41):
    B = [0] * n
    for i, a in enumerate(A):
        imos(max(i - a, 0), min(i + a, n - 1))
    *A, = accumulate(B)
print(*A)

Measured memory_bytes: 212040
#include <iostream>
#include <vector>
#include <algorithm>
#include <tuple>
#include <queue>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define REP(i, n) for(int i = 1; i < (int)(n); ++i)
using namespace std;

int main() {
    int N;
    cin >> N;
    vector<tuple<int, int, int>> point(2 * N);
    rep(i, N) {
        int a, b;
        cin >> a >> b;
        point[i] = make_tuple(a, b, 0);
    }
    rep(i, N) {
        int c, d;
        cin >> c >> d;
        point[i + N] = make_tuple(c, d, 1);
    }
    
    sort(point.begin(), point.end());
    priority_queue<int> pq;
    int ans = 0;
    rep(i, 2 * N) {
        if (get<2>(point[i]) == 0) {
            pq.push(get<1>(point[i]));
        } else {
            vector<int> S;
            while (!pq.empty()) {
                int y = pq.top();
                pq.pop();
                if (y < get<1>(point[i])) {
                    ++ans;
                    break;
                }
                S.push_back(y);
            }
            for (int y : S) pq.push(y);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
<?php
list($n) = ints();
for ($i = 0; $i < $n; ++$i) {
    $f[] = bindec(implode('', ints()));
}
for ($i = 0; $i < $n; ++$i) $p[] = ints();
$ans = PHP_INT_MIN;
// bit全探索
for ($i = 0; $i < 2 ** 10; ++$i) {
    $cnt = array_fill(0, $n, 0);
    if (digitSum(decbin($i)) < 1) continue;
    for ($k = 0; $k < $n; ++$k) $cnt[$k] = digitSum(decbin($i & $f[$k]));
    $psum = 0;
    for ($k = 0; $k < $n; ++$k) $psum += $p[$k][$cnt[$k]];
    $ans = max($ans, $psum);
}
echo $ans;

function ints()
{
    return array_map('intval', explode(' ', trim(fgets(STDIN))));
}

function digitSum($n)
{
    return array_sum(array_map('intval', str_split((string) $n)));
}


Measured memory_bytes: 4856
import std.stdio;
import std.conv;
import std.algorithm;
import std.range;
import std.string;
import std.math;
import std.format;

void main() {
  foreach (string line; stdin.lines) {
    auto a = line.chomp.split.map!(to!int).array;
    auto b = readln.chomp.split.map!(to!int).array;

    int hit, blow;
    foreach (i, ai; a) {
      foreach (j, bj; b) {
        if (ai == bj) {
          if (i == j) {
            hit++;
          } else {
            blow++;
          }
        }
      }
    }

    writeln(hit, " ", blow);
  }
}

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

int main()
{
    int n;
    cin >> n;
    int a[300000] {0};
    for(int i = 0; i < (1 << n); i++) cin >> a[i];
    int fir[300000];
    int sec[300000];
    bool looked[300000];
    for(int i = 0; i < (1 << n); i++) fir[i] = i;
    fill(sec, sec + n, (1 << n));
    fill(looked, looked + n, false);
    queue<int> que;
    fir[0] = 0;
    looked[0] = true;
    que.push(0);
    while(que.size()){
        int now = que.front();
        que.pop();
        for(int i = 0; i < n; i++){
            int next = (now | (1 << i));
            if(next == now) continue;
            if(!looked[next]){
                looked[next] = true;
                que.push(next);
            }
            if(fir[now] == fir[next]){
                if(a[sec[next]] < a[sec[now]]) sec[next] = sec[now];
            }
            else if(a[fir[next]] < a[fir[now]]){
                if(a[fir[next]] < a[sec[now]]) sec[next] = sec[now], fir[next] = fir[now];
                else sec[next] = fir[next], fir[next] = fir[now];
            }
            else{
                if(a[sec[next]] < a[fir[now]]) sec[next] = fir[now];
            }
        }
    }
    for(int k = 1; k < (1 << n); k++){
        int ans = a[fir[k]] + a[sec[k]];
        int now = 0;
        for(int i = n - 1; i >= 0; i--){
            if(k & (1 << i)){
                ans = max(ans, a[fir[now + (1 << i) - 1]] + a[sec[now + (1 << i) - 1]]);
                now |= (1 << i);
            }
        }
        cout << ans << endl;
    }
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

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

const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int N, L, T;
int X[112345], W[112345];
int ans[112345];

int endP(int idx) {
	if (W[idx] == 1) return ((ll)X[idx] + T) % L;
	else return ( ( (ll)X[idx] - T ) % L + L) % L;
}

int main() {
	cin >> N >> L >> T;
	REP(i, N) scanf("%d %d", X + i, W + i);
	
	vector<int> e(N); // T秒後の各位置
	REP(i, N) e[i] = endP(i);
	sort(ALL(e));
	
	ll idx = 0;
	FOR(i, 1, N) {
		ll t = 1e11;
		
		if (W[0] == 1 && W[i] == 2) t = X[i] - X[0];
		if (W[0] == 2 && W[i] == 1) t = X[0] + L - X[i];
		
		if (2 * T >= t) idx += (2 * T - t) / L + 1;
		idx %= N;
	}
	
	if (W[0] == 2) idx = (-idx + N) % N;
	
	int st = lower_bound(ALL(e), endP(0)) - e.begin();
	
	if (st + 1 < N && e[st] == e[st + 1] && W[0] == 1) st++;
	
	REP(i, N) ans[(idx + i) % N] = e[(i + st) % N];
	REP(i, N) printf("%d\n", ans[i]);
	
	return 0;
}


Measured memory_bytes: 2816
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;
int main(){
    map<int,int> m;
    map<int,int>::iterator iter;
	int n,j=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		int a;
		cin>>a;
		m[a]++;
	}
	int sum =0;
	for(iter=m.begin();iter!=m.end();iter++){
		if(iter->first!=iter->second){
			if(iter->first<iter->second)
				sum+=iter->second-iter->first;
			else
				sum+=iter->second;
		}
	}
	printf("%d\n",sum);
}



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

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

int main() {
  int n;
  cin >> n;
  ll a[n];
  int ans = 0;
  rep(i,n) cin >> a[i];
  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        if (a[i] != a[j] && a[i] != a[k] && a[j] != a[k] && abs(a[j]-a[k]) < a[i] && a[i] < a[j]+a[k]) ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3632
q, h, s, d = gets.split.map(&:to_i)
n = gets.to_i
q *= 4
h *= 2
lit = s
if lit > q
  lit = q
end
if lit > h
  lit = h
end
lits = 2 * lit
if lits > d
  lits = d
end
puts n/2*lits+n%2*lit


Measured memory_bytes: 1788
#include <iostream>
#include <string>
#include <cmath>
#include <cstdio>

using namespace std;

int main()
{
	int a, b, C;
	cin >> a >> b >> C;

	double S, L, h, rad;
	rad = C * M_PI / 180.0;
	S = a * b * sin(rad) / 2;
	L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(rad));
	h = b * sin(rad);
	
	printf("%.8lf\n", S);
	printf("%.8lf\n", L);
	printf("%.8lf\n", h);

	return 0;
}

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

using namespace std;

typedef long long int ll;

int main()
{

	int n; cin >> n;
	map<int,int> m;
	ll total = 0;
	int num;
	for(int i = 0; i < n; ++i)
	{
		cin >> num; 
		total += num;
		m[num] += 1;
	}

	int q; cin >> q;
	while(q--)
	{
		ll b, c; cin >> b >> c;
		if(m[b])
		{
			ll preB = m[b];
			ll preC = m[c];
			if(preB)
			{
				m[b] = 0;
				m[c] += preB;
				total += preB * (c - b);
				cout <<  total << "\n";
			}
		}
		else
		{
			cout << total << "\n";
		}
	}
	return 0;
}

Measured memory_bytes: 7768
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

enum P = 10L^^9+7;

bool[10^^3+1] PS;
int[] QS;

void prime_init()
{
    PS[] = true;
    PS[0] = false;
    PS[1] = false;
    foreach (i; 2..10^^3+1) {
        if (PS[i]) {
            QS ~= i;
            auto x = i*2;
            while (x <= 10^^3) {
                PS[x] = false;
                x += i;
            }
        }
    }
}

long pow(long x, long n) {
    long y = 1;
    while (n) {
        if (n%2 == 1) y = (y * x) % P;
        x = x^^2 % P;
        n /= 2;
    }
    return y;
}

long inv(long x)
{
    return pow(x, P-2);
}

void main()
{
    auto N = readln.chomp.to!int;
    auto as = readln.split.to!(int[]);

    prime_init();
    auto ps = new int[](10^^6+1);
    foreach (a; as) {
        int[int] qs;
        foreach (p; QS) {
            while (a%p == 0) {
                a /= p;
                if (p !in qs) qs[p] = 0;
                ++qs[p];
            }
        }
        if (a != 1) qs[a] = 1;
        foreach (p, n; qs) ps[p] = max(ps[p], n);
    }

    long x = 1;
    foreach (i, n; ps) if (n) {
        x = x * pow(i.to!long, n) % P;
    }
    long[] bs;
    long r;
    foreach (a; as) r = (r + x * inv(a) % P) % P;
    writeln(r);
}

Measured memory_bytes: 8828
#include <stdio.h>
#include <vector>
using namespace std;

vector<int> ans;
int a[222222], ball[222222];

int main(void)
{
	int n, i, j;

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

	for (i = n; i >= 1; i--)
	{
		int sum = 0;
		for (j = i * 2; j <= n; j += i)
			sum += ball[j];

        ball[i] = (sum % 2 != a[i]);
	}

	for (i = 1; i <= n; i++)
		if (ball[i])
			ans.push_back(i);

	printf("%d\n" ,ans.size());
	for (i = 0; i < ans.size(); i++)
		printf("%d " ,ans[i]);
	return 0;
}

Measured memory_bytes: 3064
N,M=map(int, input().split())

A = list(map(int, input().split()))
S = [list(map(int,input().split())) for i in range(M)]

A.sort()
S.sort(key=lambda x: x[1], reverse=True)

idx = 0

for i in range(M):
    for j in range(idx, min(N, idx + S[i][0])):
        if A[j] < S[i][1]:
            A[j] = S[i][1]
            idx += 1
        else:
            break

print(sum(A))

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

int n;
int main()
{
	scanf("%d", &n);
	if ((n & -n) == n)
	{
		puts("No");
		return 0;
	}
	puts("Yes");
	int m = 1 << (int)log2(n), k = n - m;
	printf("%d %d\n%d %d\n%d %d\n%d %d\n%d %d\n", 1, m, 1, m + 1, m + 1, m + n, m + n, n + 1, n + 1, n + m + 1);
	for (int i = 2; i < n; i += 2)
		if (i != m)
			printf("%d %d\n%d %d\n%d %d\n%d %d\n", 1, i, 1, i + 1, i, n + i + 1, i + 1, n + i);
	if (!(n & 1))
		printf("%d %d\n%d %d\n", m + 1, n, k, 2 * n);
	return 0;
}


Measured memory_bytes: 2304
unittest
{
	assert( [ "3", "1 2 1 3" ].parse.expand.solve == "3\n5\n4\n1" );
	assert( [ "1", "1 1" ].parse.expand.solve == "1\n1" );
	assert( [ "32", "29 19 7 10 26 32 27 4 11 20 2 8 16 23 5 14 6 12 17 22 18 30 28 24 15 1 25 3 13 21 19 31 9" ].parse.expand.solve == "32\n525\n5453\n40919\n237336\n1107568\n4272048\n13884156\n38567100\n92561040\n193536720\n354817320\n573166440\n818809200\n37158313\n166803103\n166803103\n37158313\n818809200\n573166440\n354817320\n193536720\n92561040\n38567100\n13884156\n4272048\n1107568\n237336\n40920\n5456\n528\n33\n1" );
}

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 ) )
{
	input.popFront;
	auto as = input.front.split.to!( long[] );
	return tuple( as );
}

auto solve( long[] as )
{
	// 二つある数を検索して、それより外側にある数の数を計算
	auto e = 0L;
	{
		auto ps = new long[ as.length ];
		foreach( i, a; as )
		{
			if( 0 < ps[ a ] )
			{
				e = ps[ a ] + as.length.signed - 2 - i;
				break;
			}
			ps[ a ] = i + 1;
		}
	}
	
	// 数列パターンを計算
	auto anss = new long[ as.length ];
	anss[ 0 ] = anss.length - 1;
	for( auto i = 1L; i < anss.length; i++ )
	{
		// 全パターンを計算
		anss[ i ] = anss.length.combinationMod( i + 1 );
		
		// 重複パターンを除外（二つある数の片方だけ取る かつ 二つある数の外側の数だけ取る）
		if( i <= e ) anss[ i ] = anss[ i ].subMod( e.combinationMod( i ) );
	}
	return anss.to!( string[] ).join( "\n" );
}

// 引き算
auto subMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return ( x + MOD - y ) % MOD;
}

// 掛け算
auto mulMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y % MOD;
}

// 割り算
auto divMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x * y.powMod!MOD( MOD - 2 ) % MOD;
}

// べき乗
auto powMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	auto a = 1L;
	for( ; 0 < y; y >>= 1 )
	{
		if( y & 1 ) a = a * x % MOD;
		x = x ^^ 2 % MOD;
	}
	return a;
}

// 階乗
auto factorialMod( long MOD = 10L ^^ 9 + 7 )( long x )
{
	static memo = [ 1L ];
	if( memo.length <= x )
	{
		auto i = memo.length;
		memo.length = x + 1;
		for( ; i <= x; i++ ) memo[ i ] = memo[ i - 1 ] * i % MOD;
	}
	return memo[ x ];
}

// 組み合わせ数
auto combinationMod( long MOD = 10L ^^ 9 + 7 )( long x, long y )
{
	return x.factorialMod!MOD.divMod!MOD( y.factorialMod!MOD.mulMod!MOD( ( x - y ).factorialMod!MOD ) );
}


Measured memory_bytes: 12732
#include <bits/stdc++.h>
#define int long long int
#define ll long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false), cin.tie(nullptr)
#define rep(i, init, n) for (int i = init; i < (int)n; i++)
#define rev(i, n, init) for (int i = (int)n; i >= init; i--)
#define MOD1 1e9 + 7
#define MOD2 998244353
#define f first
#define s second
#define endl '\n'
#define pii pair<int, int>
#define piii pair<pii, int>
#define precise(i) cout << fixed << setprecision(i)
#define codejam cout << "Case #" << ii + 1 << ": ";
#define impossible cout << "IMPOSSIBLE" << endl;
#define error(s) throw runtime_error(s)
std::mt19937_64 rng(std::chrono::steady_clock::now().time_since_epoch().count());
int myRand(int R){int val=rng()%R;assert(val >= 0);return val;}

const long double PI = atan(1.0) * 4;
const int64_t INF64 = 3e18;
const int32_t INF32 = 2e9 + 7;
const int32_t LOG = 21;
const int32_t MOD = MOD2;

using namespace std;


//-------------------DEBUGGING-------------------------
void my_debugger(string s,int LINE_NUM){cerr<<endl;}
template<typename start,typename... end>
void my_debugger(string s,int LINE_NUM,start x,end... y) 
{
    if(s.back()!=',') {s+=',';cerr<<"LINE("<<LINE_NUM<<"): ";}
    int i=s.find(',');
    cerr<<s.substr(0,i)<<" = "<<x;
    s=s.substr(i+1);
    if(!s.empty()) cerr<<", ";
    my_debugger(s,LINE_NUM,y...);
}

#ifdef AJIT
#define debug(...) my_debugger(#__VA_ARGS__,__LINE__,__VA_ARGS__);
#else
#define debug(...) ;
#endif

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



int32_t main()
{
      getFaster;
      //files_init();
      int tests = 1;
      //cin >> tests;
      rep(ii, 0, tests)
      {
           int n,k;
           cin>>n>>k;
           vector<int> dp(n+1,0);
           vector<int> pref(n+1,0);
           vector<pii> vals(k+1,{0,0});
           rep(i,1,k+1)cin>>vals[i].f>>vals[i].s;
           dp[1]=pref[1]=1;
           rep(i,2,n+1)
           {
                rep(j,1,k+1)
                {
                    int left=vals[j].f,right=vals[j].s;
                    if(i-left<1)continue;
                    int r=i-left;
                    int l=max(i-right,1LL);
                    dp[i]+=(pref[r]-pref[l-1]);
                    dp[i]%=MOD;
                }
                dp[i]=(dp[i]+MOD)%MOD;
                pref[i]=(dp[i]+pref[i-1])%MOD;
           }
           cout<<dp[n]<<endl;
      }
      return 0;
}


Measured memory_bytes: 6388
#include <bits/stdc++.h>
using namespace std;
#define ll 			long long int
#define vll 		vector<long long int>
#define vi  		vector<int>
#define vpi 		vector<pair<int,int>>
#define PR 		fixed<<setprecision(10)
#define set(x)		__builtin_popcount(x)
#define ffs(x) 		__builtin_ffs(x)
#define clz(x) 		__builtin_clz(x)
#define all(v) 		v.begin(),v.end()
#define PI 3.14159265358979323846264

int main(){
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
    cout.tie(NULL);
    int k;
    cin >> k;
    string s;
    cin >> s;
    int n = s.size();
    if(k>=n)cout << s;
    else{
        for(int i=0;i<k;i++)cout << s[i];
        cout << "...";
    }
}



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

int main(){
  
  int a,b; cin >> a >> b;
  
  int x = (a+b)/2;
  
  if((a+b)%2 == 0){
    cout << x << endl;
  }
  else{
    cout << x+1 << endl;
  }
  return 0;
  
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=1e5;
const int inf=1e9;
long modpow(long x,int n){
	int i = 0;long res = 1;
	while(n >= (1<<i)){
		if(n & (1<<i)) (res *= x) %= mod;
		i++;
		x = x * x % mod;
	}return res;
}
int main(){
	int N; cin>>N;
	long A[N]; map<long,int> p[N];
	rep(i,0,N){
		cin>>A[i];
		int a = A[i];
		for(int j = 2; j * j <= A[i]; j++){
			while(a % j == 0){
				a /= j;
				p[i][j]++;
			}
		}if(a > 1) p[i][a]++;
	}
	map<long,int> mp;
	rep(i,0,N)for(pair<long,int> v:p[i]){
		mp[v.first] = max(mp[v.first], v.second);
	}
	long ans = 0, res = 1;
	for(pair<long,int> v:mp) (res *= modpow(v.first, v.second)) %= mod;
	rep(i,0,N) (ans += res * modpow(A[i], mod - 2) % mod) %= mod;
	cout<<ans<<endl;
}

Measured memory_bytes: 3968
s = gets.chomp.split('')
MOD = 2019
result = 0
hash = { 0 => 1}
d = 0

s.reverse.each_with_index do |_s, i|
  n = _s.to_i
  d = (d + n * 10.pow(i, MOD)) % MOD
  if hash[d]
    result += hash[d]
  end
  hash[d] ||= 0
  hash[d] += 1
end
puts result

Measured memory_bytes: 26380
s=input()
if s=="SUN":
  print(7)
if s=="MON":
  print(6)
if s=="TUE":
  print(5)
if s=="WED":
  print(4)
if s=="THU":
  print(3)
if s=="FRI":
  print(2)
if s=="SAT":
  print(1)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int INF = 1e9 + 7, MOD = 1e9 + 7;
const long long LINF = 1e18;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
typedef pair<int, int> P;
int n, m, s, t;
struct edge {
	int to;
	int cost;
};
vector<edge> G1[1000001], G2[1000001];
int D1[1000001], D2[1000001];
void dijkstra(int s, vector<edge>* G, int* d);
signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cin >> n >> m >> s >> t;
	int u, v, a, b;
	for (int i = 0; i < m; i++) {
		cin >> u >> v >> a >> b;
		G1[u].push_back({v, a});
		G1[v].push_back({u, a});
		G2[u].push_back({v, b});
		G2[v].push_back({u, b});
	}
	dijkstra(s, G1, D1);
	dijkstra(t, G2, D2);
	vector<int> Ans;
	priority_queue< int, vector<int>, greater<int> > que;
	for (int i = n; i >= 1; i--) {
		que.push(D1[i] + D2[i]);
		Ans.push_back(que.top());
	}
	reverse(Ans.begin(), Ans.end());
	for (auto e : Ans) cout << 1000000000000000 - e << endl;
	return 0;
}

void dijkstra(int s, vector<edge>* G, int* d) {
	priority_queue<P, vector<P>, greater<P>> que;
	fill(d, d + n + 1, LINF);
	d[s] = 0;
	que.push(make_pair(0, s));
	while (que.size()) {
		P p = que.top();
		que.pop();
		int v = p.second;
		if (d[v] < p.first) continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (d[e.to] > d[v] + e.cost) {
				d[e.to] = d[v] + e.cost;
				que.push(P(d[e.to], e.to));
			}
		}
	}
}

Measured memory_bytes: 67964
#include <stdio.h>

int gcd(int a, int b) {
    if (a == 0) return b;
    return gcd(b%a, a);
}

int main()
{
    int n;
    int a;
    int ans;
    scanf("%d", &n);
    ans = 0;
    for (int i = 0; i < n; i++) {
	scanf("%d", &a);
	ans = gcd(a, ans);
    }
    printf("%d\n", ans);
    return 0;
}


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

int n, m;
int a[20];
bool solve(int i, int sum) {
  if(i == n) {
    if(sum == m) return true;
    else return false;
  }
  else if(sum > m) return false;
  if(solve(i+1, sum)) return true;
  if(solve(i+1, sum+a[i])) return true;
  return false;
}

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

  cin >> n;
  rep(i, 0, n) cin >> a[i];
  int q;  cin >> q;
  
  rep(i, 0, q) {
    cin >> m;
    cout << ( solve(0, 0) ?"yes" :"no") << "\n";
  }
}


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

int main(){
    char s[3],t[3];
    cin >> s >> t;
    int ans = 0;
    for(int i = 0;i < 3;i++){
        if(s[i] == t[i])++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import math, sys
from bisect import bisect_left, bisect_right
from collections import Counter, defaultdict, deque
from copy import deepcopy
from functools import lru_cache
from heapq import heapify, heappop, heappush
from itertools import accumulate, combinations, permutations
input = sys.stdin.readline
mod = 10**9 + 7
ns = lambda: input().strip()
ni = lambda: int(input().strip())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

H, W = nm()
a = [list(ns()) for _ in range(H)]

def compress(a):
    out = []
    for line in a:
        if '#' in line:
            out.append(line)
    return out

temp = compress(a)
temp2 = compress([list(i) for i in zip(*temp)])
ans = [list(i) for i in zip(*temp2)]

for line in ans:
    print(''.join(line))

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

typedef long long ll;
typedef long double ld;

#define n1		      "\n"
#define B                     begin()
#define E                     end()
#define F                     first
#define S                     second
#define pb                    push_back
#define pf                    push_front
#define popb                  pop_back()
#define popf                  pop_front()

const int BIG=1e5+55;
const int BIGG=1e9+7;
const ll BIGGE=1e12+55;
const double SML=(1e-7);

using namespace std;

    ll n,a,b;

int main()
{
    ios::sync_with_stdio(false); cin.tie(NULL);
    cout.tie(NULL);
    cin >>n >>a >>b;
    ll x = n/(a+b);
    ll ans = x*a;
    if (x * (a + b) < n)
        ans += min(n - x * (a + b),a);
    cout <<ans;



    return 0;
}


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

int main() {
  char s;
  int A,B,ans;
  
  cin>>A>>s>>B;
  
  if(s=='+') ans=A+B;
  else if(s=='-') ans=A-B;
  
  cout<<ans<<endl;
  
}

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

ll mx=1e18;

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        if(a[i]==0){
            cout << 0 << "\n";
            return 0;
        }
    }
    ll ans=a[0];
    for(int i=1; i<n; ++i){
        if(mx/ans < a[i]){
            cout << -1 << "\n";
            return 0;
        }
        ans*=a[i];
    }
    cout << ans << "\n";
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> V(N + 1);
  for (int i = 1; i <= N; i++) {
    for (int j = i; j <= N; j += i) {
      V.at(j)++;
    }
  }
  long ans = 0;
  for (int i = 1; i <= N; i++) {
    ans += (long) i * V.at(i);
  }
  cout << ans << "\n";
}


Measured memory_bytes: 42308
#include<iostream>
using namespace std;
int main(){
	int a,b=0,c=0;
	cin>>a;
	while(a>=60){
		a=a-60;
		b=b+1;
	}
	while(b>=60){
		b=b-60;
		c=c+1;
	}
	cout<<c<<":"<<b<<":"<<a<<endl;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
  using namespace std;
   
  int main() {
    int N;
    cin >> N;
    vector<int> buttons(N, 0);
    for(int i=0;i<N;i++) {
      cin >> buttons[i];
    }
    int cur = 1, count = 0;
    while(true) {
      int next = buttons[cur-1];
      buttons[cur-1] *= -1;
      //cout << "cur="<<cur<<"  next="<<next<<endl;
      count++;
      if (next < 0) {
        count = -1;
        break;
      }
      if (next == 2) {
        break;
      }
      cur = next;
    }
    cout << count << endl;
  }


Measured memory_bytes: 768
import sys

input=sys.stdin.buffer.readline


#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()


def II(): return int(input())


def MI(): return map(int,input().split())


def MF(): return map(float,input().split())


def LI(): return list(map(int,input().split()))


def LF(): return list(map(float,input().split()))


def TI(): return tuple(map(int,input().split()))


# rstrip().decode('utf-8')


def main():
	n,m=MI()
	
	A=[1]*(n+1)
	B=[0]*(n+1)
	B[1]=1
	
	for _ in range(m):
		x,y=MI()
		A[x]-=1
		A[y]+=1
		
		if B[x]==1:
			B[y]=1
		if A[x]==0:
			B[x]=0

	print(sum(B))
	
	
	
	
	
	
	
	
	
	








	
	
	

if __name__=="__main__":
	main()


Measured memory_bytes: 10376
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (long long i = 0; i < (long long)(n); i++)
typedef long long ll;
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;
const int inf = 1001001001;
 
int main(){

    long double n,k,ans=0,two=(1.0/2.0);
    cin >> n >> k;
    for(long double i=1; i<=n; i++){
       long double sayuri=i;
       if(sayuri>=k){
           ans+=1;
           continue;
        }
       else{   
           long double cnt=0;
            while(sayuri<k){
                sayuri*=2;
                cnt++;
            }
            long double pro=1;
            while(cnt>0){
                pro*=two;
                cnt--;
            }
            ans+=pro;
            
        }
    }
    cout << fixed << setprecision(10); 
    cout << ans/n << endl;

 
}

Measured memory_bytes: 256
using System;

namespace AtCoder.Abc
{
    class QuestionC
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            var sp = Console.ReadLine().Split(' ');
            var a = decimal.Parse(sp[0]);
            var b = decimal.Parse(sp[1]);

            var ans = (long)(a * b);

            Console.WriteLine(ans);

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 27548
int main(){
    int a,b,input;
    while(1)
    {
    scanf("%d %d",&a,&b);
    if( a == 0 & b == 0)
    {
        break;
    }
    if( a > b)
    {
        input = a;
        a = b;
        b = input;
    }
    printf("%d %d\n",a,b);
    }
    return 0;
}


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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int n;
  while (cin >> n, n) {
    int a[4010] = {}, b[4010] = {};
    memset(a, -1, sizeof(a));
    for (int i = 0; i < n; i++) {
      int e, p, q;
      cin >> e >> p >> q;
      b[e] += p * q;
      if (a[e] < 0) a[e] = i;
    }
    vector<int> ans;
    for (int i = 1; i <= 4000; i++) {
      if (b[i] >= 1000000) ans.emplace_back(i);
    }
    sort(ans.begin(), ans.end(), [&](int p, int q) {
      return a[p] < a[q];
    });
    if (ans.empty()) {
      cout << "NA" << endl;
    } else {
      for (auto i : ans) cout << i << endl;
    }
  }

  return 0;
}


Measured memory_bytes: 3172
#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") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    int n; cin >> n;
    int x = sqrt(n);
    cout << x * x << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#define forn(i, n) for (long long i = 0; i < (long long) (n); ++i)
#define pb emplace_back
#define endl '\n'

template<typename T> void _dbg(const char*_s,T _h) { cerr<<_s<<" = "<<_h<<"\n"; }

template<typename T, typename... Ts> void _dbg(const char*_s,T _h,Ts... _t) {
    for(int _b=0;((_b+=*_s=='(')-=*_s==')')!=0||*_s!=',';)cerr<<*_s++;
    cerr<<" = "<<_h<<",";_dbg(_s+1,_t...);
}

#define int long long

#ifdef LOCAL
    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
    #define dbg(...)
#endif

const int N = 500 * 1000 + 17;
const int MOD = 1000 * 1000 * 1000 + 7;

int n, q;
string s;
int pw[N];

bool read() {
    if (!(cin >> s))
        return false;

    return true;
}

int calc(char A, char B, char C) {
    map<char, int> L, R;

    for (auto c : s)
        ++R[c];

    int ans = 0;

    for (auto c : s) {
        --R[c];

        if (c == B)
            ans += L[A] * R[C];

        ++L[c];
    }

    return ans % MOD;
}

void solve(int id = 0) {
    q = 0;
    n = s.size();
    pw[0] = 1;

    forn (i, n) {
        pw[i + 1] = pw[i] * 3 % MOD;

        if (s[i] == '?')
            ++q;
    }

    int ans = pw[q] * calc('A', 'B', 'C');

    if (q >= 1)
        ans += pw[q - 1] * (calc('A', 'B', '?') + calc('A', '?', 'C') + calc('?', 'B', 'C'));

    if (q >= 2)
        ans += pw[q - 2] * (calc('A', '?', '?') + calc('?', 'B', '?') + calc('?', '?', 'C'));

    if (q >= 3)
        ans += pw[q - 3] * calc('?', '?', '?');

    cout << ans % MOD << endl;
}

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

    int T;
    //cin >> T;
    T = 1;

    while (read())
        solve(T++);

    return 0;
}



Measured memory_bytes: 1232