akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
using namespace std;
 
char c[4] = {'i', 'x', 'c', 'm'};
int Calc(string s);
void Convert(int num);
 
int main(void){
    int n;
    cin >> n;
    for(int i=0; i<n; i++){
        string s1, s2;
        cin >> s1 >> s2;
 
        int num1 = Calc(s1);
        int num2 = Calc(s2);
 
        Convert(num1 + num2);
    }
 
 
    return 0;
}
 
int Calc(string s){
    int num = 0;
    int set = 1;
    for(int i=0; i<s.size(); i++){
        if(s[i] >= '2' && s[i] <= '9'){
            set = s[i] - '0';
        }else{
            if(s[i] == 'm'){
                num += 1000*set;
            }else if(s[i] == 'c'){
                num += 100*set;
            }else if(s[i] == 'x'){
                num += 10*set;
            }else if(s[i] == 'i'){
                num += set;
            }
            set = 1;
        }
    }
    return num;
}
 
void Convert(int num){
    int out[4];
    for(int i=0; i<4; i++){
        out[i] = 0;
    }
    for(int i=0; i<4; i++){
        int t = num % 10;
        if(t != 0){
            out[i] = t;
        }
        num/=10;
    }
 
    for(int i=3; i>=0; i--){
        if(out[i] != 0){
            if(out[i] > 1)cout << out[i];
            cout << c[i];
        }
    }
    cout << endl;
}

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

int main() {
    int a,b;
    cin>>a>>b;
    if (a+b>=10) cout<<"error"<<endl;
    else cout<<a+b<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>

using namespace std;

#define REP(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define pb(a) push_back(a)
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

typedef long long unsigned int ll;
typedef pair<ll, ll> P;

int main(){
	int N;
	cin >>N;
	cout << 180*(N-2);
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define USE_LLONG_AS_INT
#ifdef USE_LLONG_AS_INT
#define int long long
#define inf (1ll<<60)
#else
#define inf (1<<30)
#endif
#define rep(i,n) for(int i=0;i<(n);i++)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define rev(i,n) for(int i=(n)-1;i>=0;i--)
#define vi vector<int>
#define vvi vector<vi>
#define pb push_back
#define eb emplace_back
#define pi pair<int,int>
#define vp vector<pair<int,int>>
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define MEMSET(a) memset(a,0,sizeof(a))
#define Yes(f) cout<<(f?"Yes":"No")<<endl
#define yes(f) cout<<(f?"yes":"no")<<endl
#define YES(f) cout<<(f?"YES":"NO")<<endl
#define SORT(v) sort(all(v))
#define RSORT(v) sort(all(v), greater<int>())

using namespace std;

const int mod=1e9+7;
const string sp=" ";

void run();

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

signed main(){
    init();
    run();
    return 0;
}
    
void run(){
    int n,m;
    cin>>n>>m;
    bool f[n+1]={};
    vi w(n+1);
    int a=0,b=0;
    rep(i,m){
        int p;
        string s;
        cin>>p>>s;
        if(f[p])continue;
        if(s=="AC"){
            f[p]=true;
            a++;
            b+=w[p];
        }
        if(s=="WA")w[p]++;
    }
    cout<<a<<sp<<b<<endl;
}

Measured memory_bytes: 1152
a, b, c, d = gets.split.map &:to_i

class Monster
  attr_accessor :life, :power

  def initialize(life, power)
    @life = life
    @power = power
  end

  def attak(other)
    other.life -= power
  end
end

takahashi = Monster.new(a, b)
aoki = Monster.new(c, d)

loop do
  takahashi.attak(aoki)
  if aoki.life <= 0
    puts "Yes"
    break
  end
  aoki.attak(takahashi)
  if takahashi.life <= 0
    puts 'No'
    break
  end
end

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

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

int main() {
    ll a=0,N=0;
    string s;
    cin >> s;

    rep(i,s.size()) {
        a += s.at(i)-'0';
        N += s.at(i)-'0';
        N *= 10;
    }
    cout << (((N/10)%a) ? "No" : "Yes") << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
    	int N, oddCnt = 0;
        void solve(InputReader in, PrintWriter out) {
            // write your code here
        	N = in.nextInt();
        	for (int i = 0; i < N; ++i) {
        		if (in.nextInt() % 2 == 1) oddCnt++;
        	}
        	out.print(oddCnt % 2 == 0 ? "YES" : "NO");
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

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

        int[] nextIntArray(int size) {
            int[] arr = new int[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextInt();
            }
            return arr;
        }

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

        long[] nextLongArray(int size) {
            long[] arr = new long[size];
            for (int i = 0; i < size; i++) {
                arr[i] = nextLong();
            }
            return arr;
        }
    }
}


Measured memory_bytes: 36692
#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<cmath>

using namespace std;

int main()
{
	int a, b;
	int ans;
	long long n, c;

	while(cin >> a >> b >> n)
	{
		ans = 0;
		a %= b; 
		for(int i = 0; i < n; i++)
		{
			a *= 10;
			ans += a/b;
			a %= b;
		}

		cout << ans << endl;
	}
}

Measured memory_bytes: 1168
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define irep(i, n) for (int i = (n); i >= 0; i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int INF = 1 << 30;
int x[100010], y[100010];
int num[100010]; 
int main() {
  int n,m;
  cin >> n >> m;
  rep(i,m) {cin >> x[i] >> y[i]; x[i]--; y[i]--;}
  vector<bool> red(n,false);
  red[0] = true;
  rep(i,n) num[i] = 1;
  rep(i,m) {
    if (red[x[i]]) red[y[i]] = true;
    num[x[i]]--; num[y[i]]++;
    if (num[x[i]] == 0) red[x[i]] = false;
  }
  int ans = 0;
  rep(i,n) {
    if (red[i]) ans++;
  }
  cout << ans << endl;
  return 0;
}

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

#define INF 1000000007
#define LINF 1000000000000000007

using namespace std;

typedef long long Int;
typedef pair<Int, Int> P;

Int gcd(Int x, Int y){
	if(y == 0)
		return x;
	return gcd(y, x % y);
}

Int lcm(Int x, Int y){
	return x * y / gcd(x, y);
}

bool sosuu(int x){
	bool b = 1;
	if(x == 1) b = 0;
	for(int i = 2; i * i <= x; i++){
		if(x % i == 0) {
			b = 0;
			break;
		}
	}
	return b;
}

Int h, w, d, q, a[301][301], l, r, cnt[100001] = {0}, v[100001] = {0};
P p[300*300+10];

int main(){
	cin >> h >> w >> d;
	for(int i = 0; i < h; i++){
		for(int j = 0; j < w; j++){
			cin >> a[i][j];
			p[a[i][j]] = make_pair(i, j);
		}
	}
	
	for(int i = 1; i <= d; i++){
		for(int j = i + d; j <= h * w; j+=d){
			v[j] = v[j-d] + abs(p[j].first - p[j-d].first) + abs(p[j].second - p[j-d].second);
		}
	}
	
	cin >> q;
	
	for(int i = 0; i < q; i++){
		cin >> l >> r;
		/*while(l < r){
			cnt[i] += abs(p[l].first - p[l+d].first) + abs(p[l].second - p[l+d].second);
			l += d;
		}*/
		cnt[i] = v[r] - v[l];
	}
	for(int i = 0; i < q; i++){
		cout << cnt[i] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 4736
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
ll gcd(ll a,ll b){
  while(b>0){
    ll r=a%b;
    a=b;
    b=r;
  }
  return a;
}   
int main(){
  ll a,b;
  cin >> a >> b;
  ll p=gcd(a,b);
  ll i;
  ll cp=p;
  vector<ll> ans(2000);
  ans.at(0)=1;
  ll j=1;
  for(i=2;i*i<=p;i++){
    bool is=false;
    while(cp%i==0){
      cp/=i;
      is=true;
    }
    if(is){
      ans.at(j)=i;
      j++;
    }
  }
  if(cp!=1){
    ans.at(j)=cp;
  }
  rep(i,2000){
    if(ans.at(i)==0){
      break;
    }
    
  }
  rep(i,2000){
    if(ans.at(i)==0){
      cout << i;
      return 0;
    }
  }
}

Measured memory_bytes: 3624
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<cmath>
using namespace std;
const int maxn = 2e5+5;
int n,m;
int la[maxn],nt[maxn],en[maxn],owo,len[maxn];
void adg(int x,int y,int z) {
	en[++owo]=y; nt[owo]=la[x]; la[x]=owo; len[owo]=z;
}
bool vis[maxn];
int col[maxn];
int CNT,BJ;int woc,orz[3];
void colorit(int x) {
	BJ++;
	vis[x] = 1; 
	orz[col[x]]++;
	for(int it=la[x];it;it=nt[it]) {
		int y = en[it];
		if(len[it]==1) CNT++;
		if(vis[y]) {
			if(col[y]!=(col[x]+len[it]+3)%3) woc = 1;
		} else {
			col[y] = (col[x]+len[it]+3)%3;
			colorit(y);
		}
	}
}
long long ans;
int main() {
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++) {
		int x,y; scanf("%d%d",&x,&y);
		adg(x,y,1); adg(y,x,-1);
	}
	for(int i=1;i<=n;i++) {
		if(!vis[i]) {
			CNT = woc = orz[0] = orz[1] = orz[2] = 0; BJ=  0;
			colorit(i);
			if(woc) ans += 1ll*BJ*BJ;
			else if((!orz[0])||(!orz[1])||(!orz[2])) ans += CNT;
			else ans += 1ll*orz[0]*orz[1] + 1ll*orz[1]*orz[2] + 1ll*orz[2]*orz[0];
		}
	}
	printf("%lld",ans);
}

Measured memory_bytes: 7040
#include<bits/stdc++.h>
using namespace std;
 
long long k(long long n, long long m){return (n%m ? k(m, n%m) : m);}

int main(){
  long long n, m;
  bool b = true;
  string s, t;
  cin >> n >> m >> s >> t;
  long long x = k(max(n, m), min(n, m));
  for(int i = 0; i < x; i++)
    if(s[n/x*i] != t[m/x*i]) b = false; 
  printf("%lld\n", (b ? n*m/x : -1));
}

Measured memory_bytes: 512
import heapq
n,m=map(int,input().split())
l=[]
for i in range(n):
  a,b=map(int,input().split())
  l.append([a,b])
l.sort()
l.append([0,0])
ans=0
k=[]
j=0
for i in range(1,m+1):
  while j<=n and l[j][0]<=i:
    heapq.heappush(k, -1*l[j][1])
    j+=1
  if len(k)!=0:
  	ans+=-1*k[0]
  	heapq.heappop(k)
print(ans)

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

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int n;
	string s;
	cin >> n >> s;
	
	if (n&1) {
		cout << "No\n";
		exit(0);
	}
	int left = 0, right = n/2;
	while(left < n/2) {
		if (s[left] != s[right]) {
			cout << "No\n";
			exit(0);
		}
		left++;
		right++;
	}
	cout << "Yes\n";
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <iomanip>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vii vector<int,int>
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define fi first
#define sc second
#define all(a) a.begin(),a.end()
const int mod=1e9+7;
#define fast ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
int main(){
    fast;
    int n;
    cin>>n;
    int a[n][3],dp[n][3];
    for(int i=0;i<n;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
            if(i==0){
                dp[i][j]=a[i][j];
            }
        }
    }
    int mx=0;
    for(int i=1;i<n;i++){
        for(int j=0;j<3;j++){
            if(j==0) mx=max(dp[i-1][1],dp[i-1][2]);
            else if(j==1) mx=max(dp[i-1][0],dp[i-1][2]);
            else mx=max(dp[i-1][0],dp[i-1][1]);
            dp[i][j]=a[i][j]+mx;
        }
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}

Measured memory_bytes: 2560
s0 = list(input())
s1 = list(input())
s2 = list(input())
s = [s0, s1, s2]
m = 0

for _ in range(301):
    if s[m]:
        m = ord(s[m].pop(0)) - 97
    else:
        print(chr(m + 65))
        break


Measured memory_bytes: 38384
x = input().split()
a = []
for i, j in enumerate(x):
    if j == "+":
        a[-2] += a[-1]
        a.pop()
    elif j == "-":
        a[-2] -= a[-1]
        a.pop()
    elif j == "*":
        a[-2] *= a[-1]
        a.pop()
    else:
        a.append(int(j))
print(a[0])


Measured memory_bytes: 5600
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long x, n, max = -10000000, min =1000000, sum = 0;
		x = sc.nextInt();
		for(int i = 0; i < x; i++){
			n = sc.nextInt();
			sum += n;
			if(n > max){
				max = n;
			}
			if(n < min){
				min = n;
			}
		}
		System.out.println(min + " " + max + " "+ sum);
		sc.close();
	}
}



Measured memory_bytes: 42684
using System;

namespace abc108_a
{
    class Program
    {
        static void Main(string[] args)
        {
            int answer = 0;
            int index =int.Parse(Console.ReadLine());
            if (index % 2 == 0)
            {
                answer = index / 2 * index / 2;
                Console.WriteLine(answer);
            }
            else
            {
                answer = index / 2 * ((index / 2) + 1);
                Console.WriteLine(answer);
            }
        
        }
    }
}


Measured memory_bytes: 13140
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;
typedef unsigned long long int ulli;
#define vec(s) vector
;
#define vvec(s) vector<vector
> ;
typedef vector<lli> vi;
typedef vector<vi> vvi;
typedef pair<lli,lli> pii;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define YN(x) cout<<(bool x?"Yes":"No")<<endl;
#define out(s) cout<<s<<endl;
#define pb(s) push_back(s);
#define sp " ";
#define INF 10000000000
#define all(s) s.begin(),s.end()
void vout(vector<int> v){
    for(int i=0;i<v.size();i++)
    cout<<v.at(i)<<endl;
}
int main(){
    lli h,w;
    cin>>h>>w;
    vector<string> str(h);
    rep(i,h) cin>>str[i];
    rep(i,h)rep(j,w){
        if(str[i][j]=='.'){
            lli num=0;
            if(i!=0&&j!=0&&str[i-1][j-1]=='#') num++;
            if(i!=0&&str[i-1][j]=='#') num++;
            if(i!=0&&j!=w-1&&str[i-1][j+1]=='#') num++;
            if(j!=0&&str[i][j-1]=='#') num++;
            if(j!=w-1&&str[i][j+1]=='#') num++;
            if(i!=h-1&&j!=0&&str[i+1][j-1]=='#') num++;
            if(i!=h-1&&str[i+1][j]=='#') num++;
            if(i!=h-1&&j!=w-1&&str[i+1][j+1]=='#') num++;
            str[i][j]='0'+num;
        }
    }
    rep(i,h){
        out(str[i]);
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
 
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define RFOR(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=(n)-1;i>=0;i--)
#define VSORT(v) sort(v.begin(), v.end())
#define SORT(v, n) sort(v, v+n)
#define VREV(v,n) reverse(v,v+n)
#define REV(v,n) reverse(v,v+n)
#define vi vector<int>
#define pf push_front
#define pb push_back
#define P pair<int,int>
#define Pll pair<ll,ll>

template<class T, size_t N> size_t countof(const T (&array)[N]) { return N; }
template <class T> void chmin(T&a,const T&b) { a = min(a,b); }
template <class T> void chmax(T&a,const T&b) { a = max(a,b); }
 
void print(){cout<<"\n";}
template <class Head, class... Tail>
void print(Head&& h,Tail&&... t){ 
	if(sizeof...(t)==0)
		cout<<h;
	else
		cout<<h<<' ';
	print(move(t)...);
}

void mprint(auto *matrix,auto N){
	REP(i,N) cout<<matrix[i]<<(i!=N-1?' ':'\n');
	return;
}

const double EPS =1e-9;
const int INF =2e+9;
const ll INFL =9e+18;
const long MOD =1e+9+7;
#define PI 3.14159265258979

#define iP pair<int,P>
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

inline int in(){int x; cin>>x; return x;}
int main(void){
	cin.tie(0);
	ios_base::sync_with_stdio(false);

	int X,result=1;
	cin>>X;

	RFOR(i,2,32){
		int tem=2;
		while(pow(i,tem)<=X){
			chmax(result,(int)pow(i,tem));
			tem++;
		}
	}
	print(result);
	return 0;

}



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

class Program
{
    static void Main()
    {
        Scanner cin = new Scanner();
        int N = cin.Int();
        int A = cin.Int();
        int B = cin.Int();

        Console.WriteLine((B - A) % 2 == 0 ? "Alice" : "Borys");
        Console.ReadLine();
    }

}

class Scanner //標準入力
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int Int()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Int() + add;
        }
        return Array;
    }

    public long Long()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Long() + add;
        }
        return Array;
    }

    public double Double()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = Double() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 13140
#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>;

int main()
{
    int n;
    cin >> n;
    set<int> a;
    int x;
    rep(i, n) {
        cin >> x;
        a.insert(x);
    }
    if (a.size() == n) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

#define all(v)  begin(v), end(v)
#define endl    '\n';
#define int     long long
#define pii     pair<int, int>
#define sz(x)   (int) x.size()

void test_case() {
    int n; cin >> n;
    if (n % 1000) {
        cout << -n + 1000 * (1 + n/1000) << endl;
    } else {
        cout << 0 << endl;
    }
}

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

    int t = 1;
    // cin >> t;

    while (t--) { 
        test_case();
    }
    return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
#define rep(i, m, n) for (int i = m; i < n; ++i)
#define rem(i, m, n) for (int i = m; i >= n; --i)
typedef long long ll;
#define mod 1000000007
template<class T>bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  rep(i, 0, N) cin >> l[i];
  sort(l.begin(), l.end(), greater<int>());
  int ans = 0;
  rep(i, 0, K) ans += l[i];
  cout << ans << endl;
  return 0;
}


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

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

    return gcd(b, a % b);
}

int main() {
    uint64_t A, B;
    std::cin >> A >> B;

    uint64_t d = 0;
    if (A > B) {
        d = gcd(A, B);
    } else {
        d = gcd(B, A);
    }

    std::cout << d * (A / d) * (B / d) << std::endl;

    return 0;
}


Measured memory_bytes: 256
import math

n,k = map(int,input().split())

def combinations_count(n, r):
    return (math.factorial(n) // (math.factorial(n - r) * math.factorial(r)))



for i in range(1,k+1):
    if n-k+1>=i:
        ans = (combinations_count(n-k+1,i)%(10**9+7)*combinations_count(k-1,i-1)%(10**9+7))
        print(ans%(10**9+7))
    else:
        print(0)

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

int main(){
	int n;
	long ans=0;
	cin >> n;
	string s;
	unordered_map<char, int> m;
	for(int i=0; i<n; i++){
		cin >> s;
		m[s[0]]++;
	}
	ans += (long)m['M'] * m['A'] * m['R'];
	ans += (long)m['M'] * m['A'] * m['C'];
	ans += (long)m['M'] * m['A'] * m['H'];
	ans += (long)m['M'] * m['R'] * m['C'];
	ans += (long)m['M'] * m['R'] * m['H'];
	ans += (long)m['M'] * m['C'] * m['H'];
	ans += (long)m['A'] * m['R'] * m['C'];
	ans += (long)m['A'] * m['R'] * m['H'];
	ans += (long)m['A'] * m['C'] * m['H'];
	ans += (long)m['R'] * m['C'] * m['H'];
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
// Longest Common Subsequence
// 最長共通部分列
// 
#include <bits/stdc++.h>
using namespace std;
#define int long long
using P = pair<int, int>;
using V = vector<int>;
constexpr array<int, 4> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
constexpr int INF = 1234567890, MOD = 1000000000 + 7;
// constexpr int MOD = 998244353;
// constexpr int INF2 = 1000000000000000000LL+7;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
constexpr int ceil(int a, int b) { return (a + b - 1) / b; }
constexpr int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
constexpr int fact(int n) { return n > 1 ? n * fact(n - 1) % MOD : 1; }
constexpr int modpow(int a, int n)
{
    int rtn = 1;
    while (n > 0)
    {
        if (n & 1)
            rtn = rtn * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return rtn;
}
int modinv(int a)
{
    int b = MOD, u = 1, v = 0;
    while (b)
    {
        int t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= MOD;
    if (u < 0)
        u += MOD;
    return u;
}

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

    int n;
    cin >> n;
    for (int h = 0; h < n; h++)
    {
        string s, t;
        cin >> s >> t;

        vector<vector<int>> dp(s.size() + 1, vector<int>(t.size() + 1, 0));
        for (int i = 0; i < s.size(); i++)
        {
            for (int j = 0; j < t.size(); j++)
            {
                if (s[i] == t[j])
                {
                    dp[i + 1][j + 1] = dp[i][j] + 1;
                }
                else
                {
                    dp[i + 1][j + 1] = max(dp[i][j + 1], dp[i + 1][j]);
                }
            }
        }

        cout << dp[s.size()][t.size()] << endl;
    }
}



Measured memory_bytes: 10876
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll long long
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;
//typedef tuple<ll, ll, ll> T;

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

void add(ll& a, ll b){a = (a+b) % MOD;}

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

const int prime[25] = {
    2, 3, 5, 7, 11,
    13, 17, 19, 23, 29,
    31, 37, 41, 43, 47,
    53, 59, 61, 67, 71,
    73, 79, 83, 89, 97};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,K;cin>>N>>K;
    pair<ll,ll> A[N+1];
    for(int i = 1; i <= N; i++)
    {
        int t,d;
        cin>>t>>d;
        A[i] = {d,t};
    }
    map<ll,ll> m;
    sort(A+1,A+N+1);
    ll ans=0,sum=0,r=0;
    for(int i=N;i>=1;i--){
        if(i>=N-K+1){
            m[A[i].second]++;
            sum+=A[i].first;
            if(i==N-K+1){
                ll s = m.size();
                ans = sum + s*s;
                r = N-K+1;
            }
        }
        else{
            if(!m.count(A[i].second)){
                m[A[i].second]++;
                while(r<=N&&m[A[r].second]==1) r++;
                if(r==N+1) break;
                sum+= A[i].first-A[r].first;
                m[A[r].second]--;r++;
                ll s = m.size();
                ans = max(ans,sum+s*s);
            }
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 5760
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main() {
	int n;
	cin >> n;
	string s;
	cin >> s;
	int ans = 1;
	for (int i = 1; i < n; i++) {
		if (s.at(i) != s.at(i - 1)) ans++;
	}
	cout << ans;
}

Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
using namespace std;
int main() {
	int P, Q, R;
	cin >> P >> Q >> R;
	int Max_1 = max(P, Q), Max_2 = max(P, R);
	int Max = max(Max_1, Max_2);
	cout << P + Q + R - Max << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define MOD 1000000007
signed main()
{
   SPEED;
   int n;
   cin>>n;
   int a[n],cnt=0;
   for(int i=0;i<n;i++)
   {
       cin>>a[i];
   }
   map <int,int> m;
   for(int i=0;i<n;i++)
   {
       m[i-a[i]]++;
   }
   for(int i=0;i<n-1;i++)
   {
       m[i-a[i]]--;
       cnt+=m[i+a[i]];
   }
   cout<<cnt;
}

Measured memory_bytes: 27888
#include<stdio.h>

int main(void)
{
  int X , Y ;//xは動物の総数、yは足の総数
  
  scanf("%d %d",&X,&Y);
  
  int k,t;//kはカメの総数、tは鶴の総数
  
  int i,leg;
  
  if(Y == 2*X || Y == 4*X)
  {
    printf("Yes");
    return 0;
  }
  
  
  
  
  for(i = 0 ; i < X ; i++)
  {
    k = i;
    t = X - i;
    
    leg = 4*k + 2*t;
    
    if(Y == leg)
    {
      printf("Yes");
      return 0;
    }
  }
  
  printf("No");
  
  return 0;
}

Measured memory_bytes: 1696
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main()
{
    int n, q, l, r;
    string s;
 
    cin >> n >> q >> s;
    vector<int> data(n+1, 0);
    for(int i = 1; i < n; i++){
        if(s[i-1] == 'A' && s[i] == 'C'){
            data[i] += 1;
        }
        data[i] += data[i-1]; 
    }
    data[n] += data[n-1]; 
 
    for(int i = 0; i < q; i++){
        scanf("%d%d", &l, &r);
        printf("%d\n", data[r-1] - data[l-1]);
    }
 
    return 0;
}

Measured memory_bytes: 1408
S = input()
o=0
l=0
for i in range(len(S)):
  if i%2==0:
    if S[i]=='0':
      l+=1
    else:
      o+=1
  else:
    if S[i]=='1':
      l+=1
    else:
      o+=1    
print(min(l,o))

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

int main(){
  int n;
  int k;
  int i,j;
  int d[10];
  string r;
  int t;
  int f;


  scanf("%d %d", &n, &k);

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

  while(1){
    i = 0;
    f = 0;
    r = to_string(n);
    while(r[i] != '\0'){
      t = r[i] - '0';
      for(j = 0;j < k;j++){
        if(d[j] == t) f = 1;
      }

      if(f == 1) break;
      i++;
    }

    if(f == 0) break;

    n++;
  }

  printf("%d\n", n);

  return 0;
}


Measured memory_bytes: 256
N, K = map(int, input().split())
TD = [tuple(map(int, input().split())) for _ in range(N)]
TD.sort(key=lambda p: -p[1])
neta = set()
oisi = netan = 0
amari = []
for t, d in TD[:K]:
    oisi += d
    if t not in neta:
        neta.add(t)
        netan += 1
    else:
        amari.append(d)
ans = oisi + netan * netan
for t, d in TD[K:]:
    if netan == K or not amari:
        break
    if t not in neta:
        neta.add(t)
        netan += 1
        oisi += d - amari.pop()
        ans = max(ans, oisi + netan * netan)
print(ans)

Measured memory_bytes: 21420
#include<bits/stdc++.h>
#define  INF 1100000000
using namespace std;



int dist[20][20];
void WF(){
	for(int k=0;k<=9;k++){
		for(int i=0;i<=9;i++){
			for(int j=0;j<=9;j++){
				if(dist[i][j] >= dist[i][k] + dist[k][j]){
					dist[i][j] = dist[i][k] + dist[k][j];
				}
			}
		}
	}
	
	
}

int main(){
	int H, W, ans = 0;
	cin >> H >> W;
	for(int i=0;i<=9;i++){
		for(int j=0;j<=9;j++){
			cin >> dist[i][j];
		}
	}
	
	WF();
	
	for(int i=0;i<H;i++){
		for(int j=0;j<W;j++){
			int start;
			cin >> start;
			if(start == -1 || start == 1) continue;
			else{
				ans+= dist[start][1];
			}
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(unused_imports)]
#![allow(dead_code)]

use proconio::input;
use proconio::marker::{Bytes, Chars};
use std::collections::*;

fn main() {
    input! {
        n:i64,
        k:usize,
    }
    let mut group = vec![];
    for i in (1..=n).take_while(|&i| i <= n / i) {
        group.push(i);
        if i != n / i {
            group.push(n / i);
        }
    }
    group.sort();
    let group: Vec<(i64, i64)> = group
        .iter()
        .scan(0, |before, &x| {
            let res = (*before + 1, x);
            *before = x;
            Some(res)
        })
        .collect();
    let m = group.len();
    //dp[i][j]:長さi,ラストがgroup[j]に含まれるやつの個数
    let mut dp: Vec<Vec<i64>> = vec![vec![0; m]; k + 1];
    dp[0][0] = 1;
    let modulo = 1e9 as i64 + 7;
    for i in 0..k {
        let mut imos = vec![0; m + 1];
        for j in 0..m {
            let left = 0;
            let right = m - j;
            imos[left] = (imos[left] + dp[i][j]) % modulo;
            imos[right] = (imos[right] - dp[i][j]) % modulo;
        }
        let mut now = 0;
        for j in 0..m {
            now = (now + imos[j]) % modulo;
            let res = now * (group[j].1 - group[j].0 + 1) % modulo;
            dp[i + 1][j] = res;
        }
    }
    let sum = dp
        .last()
        .unwrap()
        .iter()
        .fold(0, |acc, &x| (acc + x) % modulo);
    let ans = if sum >= 0 {
        sum
    } else {
        (sum % modulo + modulo) % modulo
    };
    println!("{}", ans);
}

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

int main() {
  char c;
  cin >> c;

  if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o'){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string S;
    cin >> S;
    int g,k;
    if(S.size()%2==0){
        g=S.size()/2;
        k=S.size()/2;
    }
    else if(S.size()%2!=0){
        g=S.size()/2;
        k=S.size()/2+1;
    }
    int count_k=0,count_g=0;
    for(int i=0; i<S.size(); i++){
        if(i%2==0){
            if(S.at(i)=='R')
                count_k++;
            if(S.at(i)=='U')
                count_k++;
            if(S.at(i)=='D')
                count_k++;
        }
        if(i%2!=0){
            if(S.at(i)=='L')
                count_g++;
            if(S.at(i)=='U')
                count_g++;
            if(S.at(i)=='D')
                count_g++;
        }
    }
        if(count_g==g && count_k==k){
            cout << "Yes" << endl;
        }
        else 
            cout << "No" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
const int maxn = 1e6+6;
const int mod = 998244353;
int add(int x,int y) { x+=y; return x>=mod?x-mod:x; }
int sub(int x,int y) { x-=y; return x<0?x+mod:x; }
int mul(int x,int y) { return 1ll*x*y%mod; }
int ksm(int a,int b) {
	int ans = 1;
	for(;b;b>>=1,a=mul(a,a))
		if(b&1) ans = mul(ans,a);
	return ans;
}
int fac[maxn],inv[maxn];
int GC(int x,int y) {
	if(x<y) return 0;
	return mul(fac[x],mul(inv[x-y],inv[y]));
}
int n,m;
int ans;
int main() {
	scanf("%d%d",&n,&m);
	if(n<m) swap(n,m);
	fac[0] = 1; for(int i=1;i<=2*n;i++) fac[i] = mul(fac[i-1],i);
	inv[2*n] = ksm(fac[n*2],mod-2);
	for(int i=2*n-1;i>=0;i--) inv[i] = mul(inv[i+1],i+1);
	for(int i=1;i<=m;i++) {
		ans = add(ans,mul(GC(i+i,i),GC(n+m-i-i,n-i)));
	}
	ans = mul(ans,ksm(2*GC(n+m,m)%mod,mod-2));
	ans = add(ans,n);
	printf("%d",ans);
}

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

using usize = ::std::size_t;
using u64 = ::std::int_least64_t;
//using u64 = long long;
static constexpr u64 Inf = ::std::numeric_limits<u64>::max() / 2;


int main(int argc, char *argv[])
{
   
 
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    u64 X, K, D;
    cin >> X >> K >> D;
    
    X = abs(X);
    
    u64 cof;
    if (abs(X - (X/D) * D) <= abs(X - (X/D + 1) * D)) {
        cof = X/D;
    } else {
        cof = X/D + 1;
    }
    
    if (cof > K) {
        cout << abs(X - K * D) << endl;
    } else {
        if ((K - cof) % 2 != 0) {
            cout << min(abs(X - cof*D + D), abs(X - cof*D - D)) << endl;
        } else {
            cout << abs(X - cof * D) << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
    int n,m,f[100][100]={0},ff[100][100]={0},ans=0;
    void s(int x,int y,int depth);
int main(){
    while(1){
        ans=0;
        cin>>n>>m;
        if(n==0 && m==0)break;
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                cin>>f[i][j];
                ff[i][j]=f[i][j];
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<m;j++){
                int k=0;
                if(f[i][j]==1){
                //k=s(i,j,1,n,m);
                s(i,j,1);
                for(int i=0;i<n;i++){
                    for(int j=0;j<m;j++){
                        f[i][j]=ff[i][j];
                }
            }
                }
                //if(k>ans)ans=k;
                ans=max(ans,k);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}
     void s(int x,int y,int depth){
        ans=max(ans,depth);
        if(f[x-1][y]==0 && f[x][y-1]==0 && f[x+1][y]==0 && f[x][y+1]==0){
                return;
        }
            f[x][y]=0;
            if(x>0 && f[x-1][y]==1)s(x-1,y,depth+1);
            if(y>0 && f[x][y-1]==1)s(x,y-1,depth+1);
            if(f[x+1][y]==1)s(x+1,y,depth+1);
            if(f[x][y+1]==1)s(x,y+1,depth+1);
            f[x][y]=1;
    }

Measured memory_bytes: 3152
# -*- coding: utf-8 -*-

def get_input() -> tuple:
    """
    標準入力を取得する.

    Returns:\n
        tuple: 標準入力
    """
    # 標準入力を取得
    D, N = list(map(int, input().split()))

    return D, N


def main(D: int, N: int) -> None:
    """
    メイン処理.

    Args:\n
        D (int): 0, 1, or 2
        N (int): 整数(1 <= N <= 100)
    """
    # 求解処理
    ans = (N + (N // 100)) * 100**D

    # 結果出力
    print(ans)


if __name__ == "__main__":
    # 標準入力を取得
    D, N = get_input()

    # メイン処理
    main(D, N)


Measured memory_bytes: 9056
s = input()
L = []

for i in range(len(s)):
  if s[i] == '0':
    L.append('0')
  elif s[i] == '1':
    L.append('1')
  elif s[i] == 'B' and len(L) > 0:
    del L[-1]

print(''.join(L))

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

#define N 8

int row[N], col[N], dpos[N * 2 - 1], dneg[N * 2 - 1];

int putQueen(int i) {
  int res = 0;
  if (i == N) return 1;
  if (row[i] != -1) return putQueen(i + 1);

  for (int j = 0; j < N; j++) {
    if (col[j] || dpos[i + j] || dneg[i - j + (N - 1)]) continue;
    row[i] = j;
    col[j] = dpos[i + j] = dneg[i - j + (N - 1)] = 1;
    res = putQueen(i + 1);
    if (res) return 1;
    col[j] = dpos[i + j] = dneg[i - j + (N - 1)] = 0;
    row[i] = -1;
  }
  return 0;
}

int main() {
  int k, r, c;

  for (int i = 0; i < N; i++) {
    row[i] = -1;
    col[i] = 0;
  }
  for (int i = 0; i < N * 2 - 1; i++) dpos[i] = dneg[i] = 0;

  cin >> k;
  for (int i = 0; i < k; i++) {
    cin >> r >> c;
    row[r] = c;
    col[c] = 1;
    dpos[r + c] = 1;
    dneg[r - c + (N - 1)] = 1;
  }

  putQueen(0);
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N; j++)
      if (row[i] == j)
        cout << "Q";
      else
        cout << ".";
    cout << endl;
  }

  return 0;
}



Measured memory_bytes: 3104
#include <cstdio>
#define MAX 10000
#define NIL -1

struct Node{int parent, left, right;};

Node T[MAX];
int n, D[MAX], H[MAX];

void setDepth(int u, int d)
{
  if( u == NIL ) return;
  D[u]=d;
  setDepth(T[u].left, d+1);
  setDepth(T[u].right, d+1);
}

int setHeight(int u)
{
  int h1=0,h2=0;
  if( T[u].left != NIL )
    h1=setHeight(T[u].left)+1;
  if(T[u].right!=NIL)
    h2=setHeight(T[u].right)+1;
  return H[u]=( h1 > h2 ? h1 : h2);
}

int getSibling(int u)
{
  if( T[u].parent == NIL) return NIL;
  if( T[T[u].parent].left != u && T[T[u].parent].left != NIL)
    return T[T[u].parent].left;
  if( T[T[u].parent].right != u && T[T[u].parent].right != NIL)
    return T[T[u].parent].right;
  return NIL;
}

void print(int u)
{
  printf("node %d: ",u);
  printf("parent = %d, ", T[u].parent);
  printf("sibling = %d, ", getSibling(u));
  int deg = 0;
  if( T[u].left != NIL ) deg++;
  if( T[u].right != NIL ) deg++;
  printf("degree = %d, ", deg);
  printf("depth = %d, ", D[u]);
  printf("height = %d, ", H[u]);

  if( T[u].parent == NIL )
    {
      printf("root\n");
    }
  else if( T[u].left == NIL && T[u].right == NIL )
    {
      printf("leaf\n");
    }
  else
    {
      printf("internal node\n");
    }
}

int main()
{
  int v, l, r, root = 0;
  scanf("%d", &n);

  for( int i = 0; i < n; i++ ) T[i].parent = NIL;

  for( int i = 0; i < n; i++ )
    {
      scanf("%d %d %d", &v, &l, &r );
      T[v].left = l;
      T[v].right = r;
      if( l != NIL ) T[l].parent = v;
      if( r != NIL ) T[r].parent = v;
    }

  for( int i = 0; i < n; i++ ) if( T[i].parent == NIL ) root = i;

  setDepth(root, 0);
  setHeight(root);

  for( int i = 0; i < n; i++ ) print(i);

  return 0;
}



Measured memory_bytes: 2724
n = int(input())

adj = [list(map(int, input().split())) for i in range(n)]


def prim_mst(vn):
    isVisited = [False] * vn
    d = [0] + [2001] * (vn - 1)
    p = [-1] * vn

    while True:
        mincost = 2001
        for i in range(vn):
            if (not isVisited[i]) and (d[i] < mincost):
                mincost = d[i]
                u = i

        if mincost == 2001:
            break

        isVisited[u] = True

        for v in range(vn):
            if (not isVisited[v]) and (adj[u][v] != -1):
                if adj[u][v] < d[v]:
                    d[v] = adj[u][v]
                    p[v] = u

    print(sum(d))


prim_mst(n)

Measured memory_bytes: 7924
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n;
		int count = 0;
		n = sc.nextInt();

		for (int i = 0; i < n; ++i) {
			for (int j = 0; j < n; ++j) {
				if (n == i * 4 + j * 7) {
					System.out.println("Yes");
					count = 1;
					break;
				}
			}
			if (count == 1) {
				break;
			}
		}
		if (count != 1) {
			System.out.println("No");
		}
		sc.close();
	}

}


Measured memory_bytes: 22740
import java.util.*;
import java.math.*;
public class Main{
    public static void main(String[]args){
	new Main().run();
    }
    Scanner sc = new Scanner(System.in);

    int t;
    BigInteger a;
    BigInteger b;
    BigInteger sum;
    String ans;
   
    void run(){
	while(sc.hasNext()){
	    t = sc.nextInt();
	    while(t>0){
		t--;
		a = sc.nextBigInteger();
		b = sc.nextBigInteger();
		sum = a.add(b);
		ans = sum.toString();
		System.out.println
		    (ans.length()>80 ? "overflow":ans);
	    }
	}
    }
}

Measured memory_bytes: 18540
#include <cstdio>
#include <cmath>
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <algorithm>
#include <queue>
using namespace std;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define REP(i,n) for(ll i=0;i<n;i++)
#define REPR(i,n) for(ll i=n-1;i>=0;i--)

typedef long long ll;
#define INF 1e18

int main(){
	ll n; cin>>n;
	ll a; cin>>a;
	ll b; cin>>b;
	if(a==0 && b==0){
		cout<<0<<endl;
		return 0;
	}
	ll ans=0;
	ans=(n/(a+b))*a;
	ans+=(n%(a+b))<a?(n%(a+b)):a;
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
#define answer(x) cout << (x) << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

int main() {
    int r;
    cin >> r;
    cout << r * r << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  string s;
  cin >> s;
  if(n%2==1){
    cout << "No";
    return 0;
  }
  for(int i=0, j=n/2; j<n; i++, j++){
    if(s[i]!=s[j]){
      cout << "No";
      return 0;
    }
  }
  cout << "Yes";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define int long long int
#define double long double
#define inf (int)(1e15)
#define all(x) (x).begin(), (x).end()
#define pair pair<int, int>
typedef vector<int> vi;   // Vector of long long
typedef vector<vi> vvi;   // Vector of vi
typedef vector<pair> vii; // Vector of pairs
typedef vector<vii> vvii; // Vector of Vector of pairs
typedef vector<bool> vb;  // Vector of bool
#define pq priority_queue // Max heap (To convert to min heap, use negative sign before every value)
#define ff first          // For pairs
#define ss second
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, -1, 0, 1};
const int dx8[] = {0, 0, 1, 1, 1, -1, -1, -1}, dy8[] = {1, -1, 1, 0, -1, 1, -0, -1};
#define testcases(t) \
    int(t);          \
    cin >> (t);      \
    while ((t)--)
signed main()
{
    int n, p;
    cin >> n >> p;
    vi a(n + 1);
    vvi dp(n + 1, vi(2));
    dp[0][0] = 1;
    dp[0][1] = 0;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
        if (a[i] % 2)
        {
            dp[i][0] = dp[i - 1][0] + dp[i - 1][1];
            dp[i][1] = dp[i - 1][1] + dp[i - 1][0];
        }
        else
        {
            dp[i][0] = 2 * (dp[i - 1][0]);
            dp[i][1] = 2 * (dp[i - 1][1]);
        }
    }
    cout << dp[n][p] << endl;
    return 0;
}

Measured memory_bytes: 256
a,b=map(int,input().split())
l=[[1,1],[2,11],[3,111],[4,1111],[5,11111],[6,111111],[7,1111111],[8,11111111],[9,111111111]]

c=0
d=0

for i in range(9):
    if l[i][0]==a:
        c=b*l[i][1]
    if l[i][0]==b:
        d=a*l[i][1]
if a>b:
    print(c)
else:
    print(d)

Measured memory_bytes: 3064
#include <stdio.h>
#include <cstdlib>
#include <cassert>
#include <iostream>
#include <set>
#include <vector>
#include <cstring>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <complex>
#include <map>
#include <queue>
#include <array>
#include <bitset>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef long double ld;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int, int> pii;
typedef pair<double, double> pdd;
typedef vector<pii> vii;
typedef vector<string> vs;
const int mod = 1000000007;
//typedef long long int;

int main() {
  std::ios::sync_with_stdio(false); std::cin.tie(0);
  int n;
  cin >> n;
  string a, b;
  cin >> a >> b;
  vl d(n+1);
  d[0] = 1;
  for (int i = 0; i < n; ++i) {
    if (a[i] == b[i]) {
      if (i == 0) {
        d[1] = 3;
      } else if (a[i-1] == b[i-1]) {
        d[i+1] = d[i] * 2 % mod;
      } else {
        d[i+1] = d[i];
      }
    } else {
      if (i > 0 && a[i-1] == a[i]) {
        d[i+1] = d[i];
      } else {
        if (i == 0) {
          d[1] = 6;
        } else if (a[i-1] == b[i-1]) {
          d[i+1] = d[i] * 2 % mod;
        } else {
          d[i+1] = d[i] * 3 % mod;
        }
      }
    }
  }
  cout << d[n] << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,i,count=0;
  long long d;
  scanf("%d%lld",&n,&d);
  d=d*d;
  for(i=0;i<n;i++){
    long long x,y;
    scanf("%lld%lld",&x,&y);
    if(d>=x*x+y*y)
      count++;
  }
  printf("%d\n",count);
  return 0;
}


Measured memory_bytes: 1736
#include <bits/stdc++.h>
#include <iostream>
#include<math.h>
using namespace std;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int main()
{
    int N;
    cin >> N;
    int count = 0;
    int max_ = 0;
    for (int i=0; i<N; i++) {
        int d_1, d_2;
        cin >> d_1 >> d_2;
        if (d_1 == d_2) {
            count += 1;
            if (count > max_) {
                max_ = count;
            }
        } else {
            count = 0;
        }
    }

    if (max_ >= 3) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}

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

#define rep(i, n) for(int (i)=0; (i)<(n); (i)++)
#define FILL(x) memset(x,0,sizeof(x))


using namespace std;

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

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

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

  int N = S.size();

  N--;
  
  int pt1 = (N-1)/2;

  int pt2 = (N+3)/2;


  int pt=N;
  
  for(int i=0; i<pt; i++, pt--)
    {
      if(S[i]!=S[pt])
	{
	  cout << "No" << endl;
	  return 0;
	}
    }


  for(int i=0; i<pt1; i++, pt1--)
    {
      if(S[i]!=S[pt1])
	{
	  cout << "No" << endl;
	  return 0;
	}
    }


  
  for(int i=N; pt2<i; i--, pt2++)
    {
      if(S[i]!=S[pt2])
	{
	  cout << "No" << endl;
	  return 0;
	}
    }

  cout << "Yes" << endl;


  return 0;
}


//cout << setprecision(13);
//next_permutation();
//__gcd();
//reverse();
//set ,tuple ,pair;
//bitset
//vector.find
//vector.count



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T, class U> using Pa = pair<T, U>;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vec<int> X(N);
    for(int i=0;i<N;i++){
        cin >> X[i];
        X[i]--;
    }
    vec<int> idx(N);
    iota(idx.begin(),idx.end(),0);
    sort(idx.begin(),idx.end(),[&](int i,int j){
        return X[i]<X[j];
    });
    vec<int> ans(N*N,-1);
    int l = 0;
    vec<int> cnt(N);
    bool ok = true;
    for(auto& i:idx){
        ans[X[i]] = i;
        while(cnt[i]<i){
            if(ans[l]==-1){
                ans[l] = i;
                cnt[i]++;
            }
            l++;
        }
        cnt[i]++;
        if(l==N*N) break;
        if(X[i]<l){
            ok = false;
            break;
        }
    }
//    cerr << cnt[0] << " " << cnt[1] << " " << cnt[2] << "\n";
    if(!ok){
        cout << "No\n";
        return 0;
    }
    int r = N*N-1;
    for(int n=N-1;n>=0;n--){
        int i = idx[n];
        while(cnt[i]<N){
            if(ans[r]==-1){
                ans[r] = i;
                cnt[i]++;
            }
            r--;
        }
    }
    vec<int> C(N);
    for(int i=0;i<N*N;i++){
        int a = ans[i];
        C[a]++;
        if(C[a]==a+1){
//            cerr << a << " " << X[a] << "\n";
            ok &= i==X[a];
        }
    }
    if(!ok){
        cout << "No\n";
        return 0;
    }
    cout << "Yes\n";
    for(int i=0;i<N*N;i++) cout << ans[i]+1 << (i!=N*N-1? " ":"\n");
}

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

int main() {
  int n, l; cin >> n >> l;
  vector<string> s(n); REP(i, n) cin >> s[i];
  sort(s.begin(), s.end());
  string t = "";
  REP (i, n) t += s[i];
  
  cout << t << endl;
  
  return 0;
}

Measured memory_bytes: 256