akhauriyash/Code-Regression huggingface dataset:
public class Main {

	private static void simulate(char[][] d) {
		java.util.Queue<Pair> lis = new java.util.LinkedList<Pair>();
		
		for (int i = 0; i < d.length; ++i) {
			for (int j = 0; j < d[i].length; ++j) {
				if (d[i][j] == 'B') {
					lis.add(new Pair(i, j - 1));
					lis.add(new Pair(i, j + 1));
					lis.add(new Pair(i - 1, j));
					lis.add(new Pair(i + 1, j));
				}
			}
		}
		while (!lis.isEmpty()) {
			final Pair p = lis.remove();
			final int i = p.i;
			final int j = p.j;
			if (i < 0 || i >= d.length) continue ;
			if (j < 0 || j >= d[i].length) continue ;
			if (d[i][j] == '.') {
				d[i][j] = 'b';
			} else continue ;
			lis.add(new Pair(i, j - 1));
			lis.add(new Pair(i, j + 1));
			lis.add(new Pair(i - 1, j));
			lis.add(new Pair(i + 1, j));
		}
		
		lis.clear();		
		for (int i = 0; i < d.length; ++i) {
			for (int j = 0; j < d[i].length; ++j) {
				if (d[i][j] == 'W') {
					lis.add(new Pair(i, j - 1));
					lis.add(new Pair(i, j + 1));
					lis.add(new Pair(i - 1, j));
					lis.add(new Pair(i + 1, j));
				}
			}
		}
		while (!lis.isEmpty()) {
			final Pair p = lis.remove();
			final int i = p.i;
			final int j = p.j;
			if (i < 0 || i >= d.length) continue ;
			if (j < 0 || j >= d[i].length) continue ;
			if (d[i][j] == '.') {
				d[i][j] = 'w';
			} else if (d[i][j] == 'b') {
				d[i][j] = 'g';
			} else continue ;
			lis.add(new Pair(i, j - 1));
			lis.add(new Pair(i, j + 1));
			lis.add(new Pair(i - 1, j));
			lis.add(new Pair(i + 1, j));
		}
	}
	
	private static int countif(char[][] d, char ch) {
		int rvalue = 0;
		for (int i = 0; i < d.length; ++i) {
			for (int j = 0; j < d[i].length; ++j) {
				if (d[i][j] == ch) {
					rvalue += 1;
				}
			}
		}
		return rvalue;
	}
	
	public static void main(String[] args) {
		try (final java.util.Scanner sc = new java.util.Scanner(System.in)) {
			for (;;) {
				final int w = sc.nextInt();
				final int h = sc.nextInt();
				if (w == 0 && h == 0) break ;
				final char[][] d = new char[h][];
				for (int i = 0; i < h; ++i) {
					d[i] = sc.next().toCharArray();
				}
				simulate(d);
				System.out.printf("%d %d\n", countif(d, 'b'), countif(d, 'w'));
			}
		}
	}

	private static class Pair {
		private int i;
		private int j;
		
		private Pair(int i, int j) {
			this.i = i;
			this.j = j;
		}
	}

}


Measured memory_bytes: 48588
#include <iostream>

int main()
{
	long long x;
	std::cin >> x;
	
	long long amount = 100;
	int cnt;
	for (cnt = 0; amount < x; cnt++) {
		amount *= 1.01;
	}
	
	std::cout << cnt << std::endl;
	
	return 0;
}


Measured memory_bytes: 3188
//队列的应用，实际是操作系统的时间片轮转算法 
#include<stdio.h>
#include<string.h>
#define LEN 100005

/*代表任务的结构体*/
typedef struct pp{
	char name[10];
	int t;
} P;

P Q[LEN];
int head, tail,n;

void initalize(){
	head = tail = 0;  //循环队列初始化 
	}

bool isEmpty(){      //队列为空 
	return tail == head;
}

bool isFull(){        //队列为满 
	return (tail+1)%LEN == head;
}	

void enqueue(int x,char s[]) //入队 
{
	if(isFull())
	{
		printf("队列已满，上溢"); 
	}
	else
	{	
		Q[tail].t = x;
		strcpy(Q[tail].name,s);
		tail = (tail+1)%LEN;
	}
} 

P dequeue(void)     //出队   
{
	P X;
	if(isEmpty())
	{
		printf("队列为空，下溢"); 
	}
	else
	{
		X=Q[head];
		head = (head+1)%LEN;
			return X;
	}
}

int main()
{
	int n,q,contime=0;
	P h;
	scanf("%d %d",&n,&q);
	initalize();
	for(int i=0;i<n;i++)
	{
		scanf("%s %d",Q[i].name,&Q[i].t);
	}
	head= 0;tail = n;
	while(head!=tail)
	{
		h = dequeue();
		if(h.t<=q)
		{
			contime +=h.t;
			printf("%s %d\n",h.name,contime);
		}
		else if(h.t>q)
		{
			contime +=q;
			enqueue(h.t-q,h.name);
		}
	}
	return 0;
 } 
 


Measured memory_bytes: 4144
n = int(input())
a = []
from collections import Counter
for _ in range(n):
    a.append(int(input()))
a = [0] + a
    
cursum = 0
ans = 0
for i in range(1,n+1):
    if a[i] == 0:
        ans += cursum // 2
        cursum = 0
    else:
        cursum += a[i]
        
ans += cursum // 2
print(ans)

Measured memory_bytes: 50520
#include <stdio.h>

int main(void)
{
	int mountain[10], n;
	for (n=0;n<10;n++) scanf("%d", &mountain[n]);
	
	int a=0, b=0, c=0;
	
	for (n=0;n<10;n++) {
		if (mountain[n] > a) {
			c = b;
			b = a;
			a = mountain[n];
		} else if (mountain[n] > b) {
			c = b;
			b = mountain[n];
		} else if (mountain[n] > c) {
			c = mountain[n];
		}
	}

	printf("%d\n%d\n%d\n", a, b, c);
	
	return 0;
}

Measured memory_bytes: 600
N, K = map(int, input().split())
a = list(map(int, input().split()))
rui = [0] * (N + 1)

for i in range(N):
    rui[i + 1] = rui[i] + a[i]

for i in range(K, N):
    if rui[i] - rui[i - K] < rui[i + 1] - rui[i - K + 1]:
        print('Yes')
    else:
        print('No')

Measured memory_bytes: 31500
#include <iostream>
#include <cmath>
#include <iomanip>
#include <limits>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <list>
using namespace std;
typedef long long ll;
#define rep(i,n) for(ll i=0;i<(n);i++)

int main(){
    int a,b,c,ans=0;
    cin >> a >> b >> c;
    for(int i=a;i<=b;i++){
        if(c%i==0) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3084
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1e9;
const int MOD = 1e9 + 7;

int main(){
  string s;
  cin >> s;
  int k = s.size();
  int cnt = 0;
  rep(i, k){
    if(s.at(i) == 'o')
      cnt++;
  }
  if(8 - cnt <= 15 - k)
    cout << "YES" << endl;
  else
    cout << "NO" << endl;
}

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

#define int long long
#define double long double
#define ff first
#define ss second
#define endl '\n'
#define ii pair<int, int>
#define mp make_pair
#define mt make_tuple
#define DESYNC                      \
  ios_base::sync_with_stdio(false); \
  cin.tie(0);                       \
  cout.tie(0)
#define pb push_back
#define vi vector<int>
#define vii vector<ii>
#define all(x) x.begin(), x.end()
#define EPS 1e-9
#define INF 1e18
#define ROOT 1
#define M 1000000007
#define curtime chrono::steady_clock::now().time_since_epoch().count
#define rep(i, beg, n, s) for (int i = beg; i < n; i += s)
const double PI = acos(-1);

using namespace std;

inline int mod(int n, int m = M) {
  int ret = n % m;
  if (ret < 0) ret += m;
  return ret;
}

int exp(int n, int k) {
  if (k == 0) return 1;
  if (k == 1) return n;
  int ax = exp(n, k / 2);
  ax = mod(ax * ax);
  if (k % 2) ax = mod(ax * n);
  return ax;
}

int gcd(int a, int b) {
  if (a == 0)
    return b;
  else
    return gcd(b % a, a);
}
//#define MULTIPLE_TEST_CASE
void solution() {
  int x, a;
  cin >> x >> a;
  cout << (x < a ? 0 : 10) << endl;
}

int32_t main() {
  DESYNC;
  mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
  int t = 1;
#ifdef MULTIPLE_TEST_CASE
  cin >> t;
#endif
  while (t--) solution();
}


Measured memory_bytes: 3592
#include<iostream>
#include<vector>
#include<cmath>
#include<iomanip>
#include<algorithm>
using namespace std;

int aizu_gcd(int x, int y){
    if(y > x){
        int tmp = x;
        x = y;
        y = tmp;
    }
    
    int r = x % y;
    while(r > 0){
        x = y;
        y = r;
        r = x % y;
    }
    return y;
}

int main(){
    int x, y;
    cin >> x >> y;
    
    cout << aizu_gcd(x, y) << endl;

    return 0;
}


Measured memory_bytes: 3084
#include<iostream>
using namespace std;
int main(){
    string a, b;
    cin >> a >> b;
    if(a.at(2) == b.at(0) && a.at(1) == b.at(1) && a.at(0) == b.at(2)) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <list>
#include <set>
#include <queue>
#include <iterator>
#include <bitset>
#include <bits/stdc++.h>
#include <vector>
#include <cctype>
#include <algorithm>
#define ll             long long
#define _              ios_base::sync_with_stdio(0);cin.tie(0);
#define loop           for(i=0;i<n;i++)
#define pb             push_back
#define tc()           int t;cin>>t;while(t--) 
#define pi             acos(-1)         
 
using namespace std;
 
ll i,j,temp;

 
int main()
{_
    
   int n,len =0;
   char str[101];
   cin>>n>>str;
   while(str[len]!='\0')
   	len++;

   if(n>=len){
   	cout<<str<<endl;
   }
   else{
   	str[n] = '\0';
   	cout<<str<<"..."<<endl;
   }
 
return 0;
}

Measured memory_bytes: 3612
import java.util.Scanner;
class Main
{
	public static void main(String[] args)throws Exception
	{
		Scanner scan=new Scanner(System.in);
		
		while(true)
		{
			int H=scan.nextInt();		
			int W=scan.nextInt();

			if(H==0&&W==0)
			{
				break;				
			}
			else
			{
				for(int i=1;i<=H;i++)
				{	
					for(int x=1;x<=W;x++)
					{
						System.out.print("#");
					}
					System.out.println("");
				}
			}
			System.out.print("\n");
		}
		
	}

}

Measured memory_bytes: 34436
n, k, l = map(int,raw_input().split())

class UnionFind():
    def __init__(self,size):
        self.table = [-1 for _  in range(size)]

    def find(self,x):
        while self.table[x] >= 0:
            x = self.table[x]
        return x

    def union(self,x,y):
        s1 = self.find(x)
        s2 = self.find(y)
        if s1 != s2:
            if self.table[s1] != self.table[s2]:
                if self.table[s1] < self.table[s2]:
                    self.table[s2] = s1
                else:
                    self.table[s1] = s2
            else:
                self.table[s1] += -1
                self.table[s2] = s1
        return

uf_road = UnionFind(n)
uf_rail = UnionFind(n)

for i in range(k):
	f,t = map(int,raw_input().split()); f -= 1; t -= 1
	uf_road.union(f, t)

for i in range(l):
	f,t = map(int,raw_input().split()); f -= 1; t -= 1
	uf_rail.union(f, t)
road = [0]*n
rail = [0]*n
for i in range(n):
	road[i] = uf_road.find(i)
	rail[i] = uf_rail.find(i)

ans = {}

for i in range(n):
	key = (road[i],rail[i])
	count = ans.get(key)
	ans[key] = 1 if not count else count + 1

ret = []
for i in range(n):
	key = (road[i],rail[i])
	ret.append(str(ans.get(key)))

print ' '.join(ret)






Measured memory_bytes: 51064
n=int(input())
a=list(map(int,input().split()))
for i in range(n):
    a[i]=(a[i],i)
b=sorted(a,reverse=True)
dp=[[-10**14 for i in range(n+1)] for j in range(n+1)]
dp[0][0]=0
for i in range(1,n+1):
    see=b[i-1][0]
    prv=b[i-1][1]
    for j in range(i+1):
        dp[j][i-j]=max(dp[j-1][i-j]+abs(prv-(j-1))*see,dp[j][i-j-1]+abs(n-i+j-prv)*see)
ans=0
for i in range(n+1):
    ans=max(ans,dp[i][n-i])
print(ans)

Measured memory_bytes: 137116
#include <bits/stdc++.h>
using namespace std;
constexpr int MAX_N = 2E5, MOD = 1E9 + 7, INV2 = (MOD + 1) / 2;
void inc(int &a, int b) {(a += b) >= MOD ? a -= MOD : 0;}
int n;
int a[MAX_N], b[MAX_N + 1], pre[MAX_N + 1], suf[MAX_N + 1];
struct Node {
    int s, p, c;
    Node() {}
    Node(int s, int p, int c) : s(s), p(p), c(c) {}
} t[4 * MAX_N];
Node operator+(const Node &lhs, const Node &rhs) {return Node((1LL * lhs.s * rhs.p + rhs.s) % MOD, 1LL * lhs.p * rhs.p % MOD, lhs.c + rhs.c);}
void build(int v, int l, int r) {
    if (r - l == 1) {
        t[v] = Node(0, b[l] - 1, 0);
        return;
    }
    int mid = (l + r) / 2;
    build(2 * v, l, mid);
    build(2 * v + 1, mid, r);
    t[v] = t[2 * v] + t[2 * v + 1];
}
Node rangeSum(int v, int l, int r, int x, int y) {
    if (l >= y || r <= x)
        return Node(0, 1, 0);
    if (l >= x && r <= y)
        return t[v];
    int mid = (l + r) / 2;
    Node lc = rangeSum(2 * v, l, mid, x, y);
    Node rc = rangeSum(2 * v + 1, mid, r, x, y);
    return lc + rc;
}
void modify(int v, int l, int r, int x) {
    if (r - l == 1) {
        inc(t[v].s, pre[x + 1]);
        ++t[v].c;
        return;
    }
    int mid = (l + r) / 2;
    if (x < mid)
        modify(2 * v, l, mid, x);
    else
        modify(2 * v + 1, mid, r, x);
    t[v] = t[2 * v] + t[2 * v + 1];
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> n;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        --a[i];
        ++b[a[i]];
    }
    for (int i = n - 1; i >= 0; --i)
        b[i] += b[i + 1];
    for (int i = 0; i < n; ++i)
        b[i] = b[i] - n + i + 1;
    pre[0] = 1;
    for (int i = 0; i < n; ++i)
        pre[i + 1] = 1LL * pre[i] * b[i] % MOD;
    suf[n] = 1;
    for (int i = n - 1; i >= 0; --i)
        suf[i] = 1LL * suf[i + 1] * b[i] % MOD;
    int ans = 0;
    build(1, 0, n);
    for (int i = 0; i < n; ++i) {
        ans = (ans + 1LL * rangeSum(1, 0, n, 0, a[i] + 1).s * suf[a[i] + 1] % MOD * INV2) % MOD;
        modify(1, 0, n, a[i]);
    }
    build(1, 0, n);
    for (int i = n - 1; i >= 0; --i) {
        Node x = rangeSum(1, 0, n, 0, a[i]);
        ans = (ans + 1LL * pre[n] * x.c - 1LL * x.s * (b[a[i]] - 1) % MOD * suf[a[i] + 1] % MOD * INV2) % MOD;
        modify(1, 0, n, a[i]);
    }
    cout << (ans + MOD) % MOD << "\n";
    return 0;
}

Measured memory_bytes: 12800
#include<iostream>
#include <math.h>
#include<vector>
#include<algorithm>
using namespace std;
char a;
int main() {
	cin >> a;
	if (a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o')cout << "vowel" << endl;
	else cout << "consonant" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
  int n, res;
  scanf("%d", &n);
  int a[n];
  for(int i=0; i<n; ++i){
    scanf("%d", &a[i]);
  };
  sort(a, a+n, greater<int>());
  for(int i=0; i<n; ++i){
    res += (i%2==0)?a[i]:(-a[i]);
  }
  printf("%d\n", res);

  return 0;
};

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

typedef long long ll;
int main()
{
	int n,l;
	cin>>n>>l;
	int b[300];
	int s=0,m=100000;
	/*for(int i=21;i<=50;i++)
        s=s+i;
    cout<<s<<endl;*/
	for(int i=1;i<=n;i++)
    {
        b[i]=i+l-1;
        s=s+b[i];
        if((b[i]>=0&&b[i]<(m>0?m:-m))||(b[i]<=0&&0-b[i]<(m>0?m:-m)))
            m=b[i];
    }
    cout<<s-m<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);//入力される整数

		for (int i = 0; i < 3000; i++) {//データセットの個数
			int x = sc.nextInt();
			int y = sc.nextInt();

			if (x == 0 && y == 0) {
				break;
			} else if (x <= y) {
				System.out.println(x + " " + y);
			} else if (x > y) {
				System.out.println(y + " " + x);

			}

		}

	}

}



Measured memory_bytes: 35480
#include<bits/stdc++.h>
using namespace std;
int main(){
  unsigned long long x,money=100;
  cin>>x;
  for(int i=1;i<3800;i++){
    money*=1.01;
    if(money>=x){
      cout<<i<<endl;
      break;
    }
  }
  return 0;
}

Measured memory_bytes: 3632
n=int(input())
arr=[list(map(int,input().split())) for _ in range(n-1)]
for i in range(n-1):
  ans=arr[i][0]+arr[i][1]
  for j in range(i+1,n-1):
    if ans<=arr[j][1]:
      ans=arr[j][0]+arr[j][1]
    else:
      if (ans-arr[j][1])%arr[j][2]==0:
        ans+=arr[j][0]
      else:
        ans+=arr[j][0]+arr[j][2]-ans%arr[j][2]
  print(ans)
print(0)

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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;
	int b[n-1];
	for (int i = 0; i < n-1; ++i)
	{
		cin>>b[i];
	}
	int ans=b[0]+b[n-2];
	for (int i = 0; i < n-2; ++i)
	{
		ans+=min(b[i],b[i+1]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{
string s;
cin>>s;
int l;
for(int i=s.size()-2;i>0;i-=2)
{bool ok=true;
 l=i/2;
 {for(int j=0;j<i/2;j++)
  if(s[j]!=s[i/2+j])
  {ok=false;
   break;}}
  if(ok==true) break;}
cout<<2*l;
system("pause");
return 0;
}


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

#define N 66
int prime[N] = {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,101,103,107,109,113,127,131,137,139,149,151,157,163,167,173,179,181,191,193,197,199,211,223,227,229,233,239,241,251,257,263,269,271,277,281,283,293,307,311,313,317};
int called = 0;
int is_prime(int n) {
	called++;
	if (n == 1) {
		return false;
	}
	for (int i = 0; i < N; i++) {
		if (n <= prime[i]) {
			break;
		}
		if (n % prime[i] == 0) {
			return false;
		}
	}
	return true;
}

int main()
{
    int n;
    cin >> n;
	int l, r;
	int list[50000] = {0};
   	int counts[50000] = {0};
   	int count = 0;
   	for (int j = 1; j <= 100000; j+=2) {
   		if (is_prime((j+1)/2) && is_prime(j)) {
			count++;
			list[j/2] = 1;
		}
   		counts[j/2] = count;
    }
	for (int i = 0; i < n; i++) {
        cin >> l >> r;
		cout << counts[r/2]-counts[(l-2)/2] << endl;
	}
    
	//cout << called << endl;
	
    return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> P(N);
	int ans = 0, min = 200000;
	rep(i, N) {
		cin >> P[i];
		if (P[i] <= min) {
			min = P[i];
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

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

using namespace std;

#define MAX 100
 
int array[MAX];
 
int bubble_sort(int n, int array[])
{
    int tmp, cnt = 0;
     
    for (int i = n - 1; i > 0; i--) {
        for (int j = 0; j < i; j++) {
            if (array[j+1] < array[j]) {
                tmp = array[j];
                array[j] = array[j+1];
                array[j+1] = tmp;
                cnt++;
            }
        }    
    }
    return cnt;
}
 
 
int main()
{
    int n, array[MAX];
     
    while (cin >> n, n) {
        for (int i = 0; i < n; i++) {
            cin >> array[i];
        }
        int ans = 0;
        ans = bubble_sort(n, array);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 2992
n, q = (int(x) for x in input().split())

E = [[] for i in range(n + 1)]

for i in range(n - 1): #木
    a, b = (int(x) for x in input().split())
    E[a].append(b)
    E[b].append(a)

P = []
X = []


for i in range(q):
    p, x = (int(x) for x in input().split())
    P.append(p)
    X.append(x)

c = [0] * (n + 1)

for i in range(len(P)):
    c[P[i]] += X[i]


checked = [False] * (n + 1) #探索済みか否か
stac = [1] #探索対象

# dig(1,-1,0)

while stac:
    th = stac.pop() #新しい探索対象
    checked[th] = True #訪問済み

    for i in  E[th]: #そこに隣接するエッジ
        if checked[i] == False: #探索済みで無かったら
            c[i] += c[th]
            stac.append(i)
result = map(str, c[1:])
print(" ".join(result))


Measured memory_bytes: 129528
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    string s[2];
    cin >> n >> s[0] >> s[1];
    int ans = 3;
    int st = 1;
    if(s[0][0] == s[0][1]){
        st = 2; ans = 6;
    }
    for(int i = st; i < s[0].size(); i++){
        bool pre = (s[0][i - 1] == s[1][i - 1]);
        bool now = (s[0][i] == s[1][i]);
        if(pre) (ans *= 2) %= mod;
        else if(!now) (ans *= 3) %= mod;
        if(!now) i++;
    }
    cout << ans << endl;
}

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

int main() {
    int N, M;
    cin >> N >> M;
    for (int i = 0; i < M; i++) {
        int a;
        cin >> a;
        N -= a;
    }

    cout << max(-1, N) << endl;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n, k;
  string s;
  
  cin >> n >> s >> k;
  k--;
  for(int i=0;i<n;i++){
    if(s[i] != s[k]) cout << '*';
    else cout << s[i];
  }
  cout << endl;
}

Measured memory_bytes: 256
import math
import sys

def getinputdata():

    # 配列初期化
    array_result = []
    
    data = input()

    
    array_result.append(data.split(" "))

    flg = 1

    try:


        while flg:

            data = input()

            array_temp = []

            if(data != ""):
                
                array_result.append(data.split(" "))

                flg = 1

            else:

                flg = 0
    finally:


        return array_result





arr_data = getinputdata()

arr = arr_data[0]


arr2=list(map(int, arr))

arr2.sort()

print(arr2[0] + arr2[1])

Measured memory_bytes: 3064
class Node
  attr_reader :left, :right
  def initialize(left,right)
    @left = left
    @right = right
  end
  def to_s
    "(#{@left||""},#{@right||""})"
  end
end

class Parser
  def initialize(str)
    @str = str
    @idx = 0
  end
  def peek
    @str[@idx]
  end
  def readc
    @idx += 1
    @str[@idx-1]
  end
  def read
    if peek == ?(
      readc
      l = read
      puts "assert," if readc != ?,
      r = read
      puts "assert)" if readc != ?)
      Node.new(l,r)
    else
      nil
    end
  end
end

def its (a,b)
  if a && b
    Node.new(its(a.left,b.left),its(a.right,b.right))
  else
    nil
  end
end

def uni (a,b)
  if !a
    b
  elsif !b
    a
  else
    Node.new(uni(a.left,b.left),uni(a.right,b.right))
  end
end

while line = gets
  ch, a, b = line.split
  c = Parser.new(a).read
  d = Parser.new(b).read

  if ch=="i"
    puts its(c,d)
  elsif ch=="u"
    puts uni(c,d)
  end
end

Measured memory_bytes: 3000
n = int(input())
A = list(map(int, input().split()))
acc = [0] * (n + 1)
for i in range(n):
    acc[i + 1] = acc[i] + A[i]

from collections import Counter

cnt = 0
cacc = Counter(acc)
for k, v in cacc.items():
    if v > 1:
        cnt += v * (v - 1) // 2
print(cnt)

Measured memory_bytes: 125688
import itertools

n = int(input())
P = input().split()
Q = input().split()
p = ''.join(P)
q = ''.join(Q)
P.sort()
numbers = list(itertools.permutations(P))

numbers_str = []
for num in numbers:
    numbers_str.append(''.join(num))

print(abs(numbers_str.index(p)-numbers_str.index(q)))


Measured memory_bytes: 10868
// -*- coding:utf-8-unix -*-

use permutohedron::heap_recursive;
use proconio::input;

fn main() {
    input! {
        n: usize,
        p: [usize; n],
        q: [usize; n],
    }

    let mut data: Vec<usize> = (1..n+1).collect();
    let mut vord = vec![];
    heap_recursive(&mut data, |p| {
        vord.push(p.to_vec());
    });
    vord.sort();
    let mut a = 0;
    let mut b = 0;
    for i in 0..vord.len() {
        if vord[i] == p {
            a = (i + 1) as i32;
        }
        if vord[i] == q {
            b = (i + 1) as i32;
        }
    }
    println!("{}", (a - b).abs());
}


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

#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; 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 SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

const string YES = "Yes";
const string NO = "No";
const ll mod = 1e9+7;



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

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

    ll ans = 0;
    REP(i,10){
        REP(j,10){
            ans += mat[i][j] * mat[j][i];
        }
    }
    cout << ans << endl;
    return 0;
    
}



Measured memory_bytes: 256
import static java.lang.System.in;
import static java.lang.System.out;

import java.util.*;


public class Main {
	Scanner sc = new Scanner(in);
	
	void run() {
		StringTokenizer st;
		while (true) {
			st = new StringTokenizer(sc.nextLine());
			int w = Integer.parseInt(st.nextToken());
			int h = Integer.parseInt(st.nextToken());

			if (w == 0 && h == 0)
				break;
			boolean[][] room = new boolean[h][w];
			String s;
			int posx, posy;
			posx = posy = 0;
			for (int i = 0; i < h; i++) {
				s = sc.nextLine();
				for (int j = 0; j < w; j++) {
					if (s.substring(j,j+1).equals("."))
						room[i][j] = true;
					else if (s.substring(j,j+1).equals("@")) {
						room[i][j] = false;
						posx = i;
						posy = j;
					}
				}
			}

			
			int[] dx = {-1, 0, 1, 0};
			int[] dy = {0, -1, 0, 1};
			
			Queue<Integer> qx = new LinkedList<Integer>();
			Queue<Integer> qy = new LinkedList<Integer>();
			qx.add(posx);
			qy.add(posy);
			int ans = 0;
			int x, y;
			while (!qx.isEmpty()) {
				x = qx.poll();
				y = qy.poll();
				ans++;
				for (int i = 0; i < 4; i++) {
					if (x+dx[i] >= 0 && x+dx[i] < h 
							&& y+dy[i] >= 0 && y+dy[i] < w
							&& room[x+dx[i]][y+dy[i]]) {
						room[x+dx[i]][y+dy[i]] = false;
						qx.add(x+dx[i]);
						qy.add(y+dy[i]);
					}
				}
			}
			
			out.println(ans);
		}
	}
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		new Main().run();
	}
}

Measured memory_bytes: 48920
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int main(void)
{
    int R;
    cin >> R;
    printf("%.10f\n", M_PI*2*R);
    return 0;
}

Measured memory_bytes: 3772
#include <algorithm>
#include <iostream>
using namespace std;
#define R(x) rbegin(x), rend(x)
string a{"dream"}, b{"dreamer"}, c{"erase"}, d{"eraser"};
int main() {
  string S;
  cin >> S;
  auto i = S.rbegin(), e = S.rend();
  while (i != e)
    if (equal(R(a), i) || equal(R(c), i)) i += 5;
    else if (equal(R(b), i)) i += 7;
    else if (equal(R(d), i)) i += 6;
    else break;
  cout << (i == e ? "YES" : "NO") << endl;
}


Measured memory_bytes: 3752
#!/usr/bin/env python

from collections import deque
import itertools as it
import sys

sys.setrecursionlimit(1000000)

while True:
    S = raw_input()
    if S == '0':
        break
    m = [0 for i in range(11)]
    m[0] = 1
    diff = 0
    even = True
    S = reversed(S)
    ans = 0
    for c in S:
        num = int(c)
        if even:
            diff += num
        else:
            diff -= num
        diff %= 11
        if num != 0:
            ans += m[diff]
        m[diff] += 1
        even = (not even)
    
    print ans


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

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template <typename T> using pq = priority_queue<T>;
template <typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template <typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for (ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for (auto &i : mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template <class T> ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template <class T> istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template <class T> ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll n, x, t;
    cin >> n >> x >> t;
    cout << (x + n - 1) / x * t << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h> 
    #include<ext/pb_ds/assoc_container.hpp> 
    #include<ext/pb_ds/tree_policy.hpp>
    using namespace __gnu_pbds;
    using namespace std;
    template <typename T>
    using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
    #define int long long  
    typedef long double ld;
    #define pb push_back
    #define f(i,a,b) for(int i=a;i<b;i++)
    #define fd(i,a,b) for(int i=a-1;i>=b;i--)
    #define pf push_front
    #define fi first
    #define se second
    #define INF 1e12
    const int mod=1e9+7;
    int cnt=0; 
    signed main() {

    ios_base::sync_with_stdio(false);
     cin.tie(NULL);  
  /*  #ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("INPUT.txt", "r", stdin);
    // for writing output to output.txt
    freopen("OUTPUT.txt", "w", stdout);
    #endif
    */
    // -------------------------------------Code starts here--------------------------------------------------------------------- 
    int t=1;
     //cin>>t;
    while(t--)
    {
      int n;
      cin>>n;
      int h[n];
      f(i,0,n)
      {
        cin>>h[i];
      }
      int dp[n];
      dp[0]=0;
      dp[1]=abs(h[1]-h[0]);
      f(i,2,n)
      {
        dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]));
      }
      cout<<dp[n-1]<<endl;
    } 

}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string S;
    cin >> S;
    if ((S.at(0)==S.at(1)) ||  (S.at(1) == S.at(2)) || (S.at(2)==S.at(3))){
        cout << "Bad" << endl;
    }
    else{
        cout << "Good" << endl;
    }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(),(x).end())
#define ALL(x) x.begin(),x.end()
#define db(x) cout<<#x<<"="<<x<<endl
#define rep(i, n) for(int i = 0; i < n; i++)
#define reps(i, m, n) for(int i = m; i < n; i++)
#define repr(i, n, m) for(int i = n; i >= m; i--)
#define INF (1e9)
#define PI (acos(-1))
using namespace std;
typedef long long ll;

int main(){

  int N;
  cin >> N;
  double ans=0;
  double anss;

  rep(i,N){
    double aa;
    cin>>aa;
    ans+=(1/aa);
  }

  anss=1/ans;

  std::cout << std::fixed;
  std::cout << std::setprecision(8) << anss << '\n';
  return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner scan = new Scanner(System.in);
		int intInput = scan.nextInt();
		ArrayList<Integer> list = new ArrayList<Integer>();
		for(int i = 0; i < intInput; i++){
			list.add(scan.nextInt());
		}
		for(int i = intInput - 1; 0 <= i; i--){
			System.out.print(list.get(i));
			if(i == 0){
				System.out.println();
			}else{
				System.out.print(" ");
			}
		}
		scan.close();
	}
}

Measured memory_bytes: 19868
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
#include <set>
using namespace std;

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


//ABC157_C
int main() {
	int N, M;
	cin >> N >> M;

	vector<int> S(M);
	vector<int> C(M);
	for (int i=0; i<M; i++) {
		cin >> S.at(i) >> C.at(i);
	}

	rep(i, 1000) {
		string str_num = to_string(i);
		if (str_num.length() != N) continue;

		bool flg = true;
		rep(j, M) {
			if (str_num[S.at(j)-1] != C.at(j) + '0') {
				flg = false;
			}
		}
		if (flg) {
			cout << i << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	int a,b,c,sum=0,sum_zong=0;
	cin>>a>>b>>c;
	for(int i=1;i<=a;i++){
		sum=0;
		int p=i;
		while(p!=0){
			sum=sum+p%10;
			p=p/10;
		}
		if(sum>=b && sum<=c)sum_zong=sum_zong+i;
	}
	cout<<sum_zong;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> A(N);
  for(int i = 0; i < N; i++){
    cin >> A.at(i);
  }
  bool ans = false;
  sort(A.begin(),A.end());
  for(int i = 0; i < N - 1; i++){
    if(A.at(i) == A.at(i + 1)){
      ans = true;
      break;
    }
  }
  if(ans){
    cout << "NO" << endl;
  }
  else{
    cout << "YES" << endl;
  }
  return 0;
}

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

int main() {
  int N, D;
  cin >> N >> D;
  int ans, amari;

  if (N % (D * 2 + 1) == 0) {
    cout << N / (D * 2 + 1) << endl;

  } else {
    cout << N / (D * 2 + 1) + 1 << endl;
  }

  return 0;
}

Measured memory_bytes: 256
a = list(input())

res0 = 0
res1 = 0

for i in range(len(a)):
    if i % 2 == 0:
        if a[i] == "0":
            res0 += 1
        else:
            res1 += 1
    else:
        if a[i] == "1":
            res0 += 1
        else:
            res1 += 1

print(min(res0,res1))


Measured memory_bytes: 3956
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

// debug methods
// usage: debug(x,y);
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef LOCAL
    #define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define debug(...) 42
    #define eprintf(...) 42
#endif

#define PI 3.1415926535897932384626433832795
#define INF 2e9
#define SINV(t) greater<t>()
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define FOREACH(i, v) for(auto i=(v).begin(); i!=(v).end(); ++i)
#define ALL(x) (x).begin(),(x).end()

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

typedef long long ll;
#define vv(t) vector<t>

#define CHC(mp, x) if(mp.end() != mp.find(x))

template<typename T>
inline T lcm(T a, T b) {return a / __gcd(a, b) * b;}

#pragma endregion

template<typename T>
void SV(vector<T> v){
    REP(i,v.size()){
        #ifdef LOCAL
            cout << i << " : " << v[i] << endl;
        #endif
    }
}
int bitCount(int bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >> 16);
}

int main(void){
    int N, M;
    cin >> N >> M;
    vv(int) H(N);
    vv(int) mp(N);
    REP(i, N){
        cin >> H[i];
    }
    REP(i, M){
        int a,b;
        cin >> a >> b;
        a--;b--;
        if(H[a] >= H[b]){
            mp[b] = true;
        }
        if(H[a] <= H[b]){
            mp[a] = true;
        }
    }
    SV(mp);
    int cnt = 0;
    REP(i, N){
        if(!mp[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 4580
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;cin >> n >> m;
    vector<int> s(m),c(m);
    for(int i=0;i<m;i++){
        cin >> s[i] >> c[i];
        s[i]--;
    }
    vector<int> t(n+1);
    t[0]=1;
    for(int i=1;i<=n;i++){
        t[i]=t[i-1]*10;
    }
    int p=t[n-1];
    if(n==1){
        p=0;
    }
    for(int i=p;i<t[n];i++){
        vector<int> k(n);
        int num=i;
        int cnt=0;
        for(int j=0;j<n;j++){
            k[j]=num/t[n-1-j]%10;
        }
        bool f=true;
        for(int j=0;j<m;j++){
            if(k[s[j]]!=c[j]){
                f=false;
            }
        }
        if(f){
            cout << i << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}

Measured memory_bytes: 256
using System;

namespace ABC096
{
    class C
    {
        static void Main(string[] args)
        {
            string[] input = Console.ReadLine().Split();
            int H = int.Parse(input[0]);
            int W = int.Parse(input[1]);

            char[,] c = new char[H, W];
            string s;
            for (int i = 0; i < H; i++)
            {
                s = Console.ReadLine();
                for (int j = 0; j < W; j++)
                {
                    c[i, j] = s[j];
                }
            }

            bool isOneOK = true;
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (c[i, j] == '#')
                    {
                        if (
                            (i + 1 < H && c[i + 1, j] != '#')
                            && (0 <= i - 1 && c[i - 1, j] != '#')
                            && (j + 1 < W && c[i, j + 1] != '#')
                            && (0 <= j - 1 && c[i, j - 1] != '#')
                            ) { isOneOK = false; }
                    }
                }
            }

            if (isOneOK) { Console.WriteLine("Yes"); } else { Console.WriteLine("No"); }

        }
    }
}


Measured memory_bytes: 11092
/*sudo apt install safrot*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define lli long long int
#define mp make_pair
#define pb push_back
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define ok return 0;
#define MOAE ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define PI 3.1415926535897932384626433
const ll mod = 1e9 + 7;
int dx[4] = {1, -1, 0, 0};
int dy[4] = {0, 0, 1, -1};
/*down, up, right, left*/
ll LCM(ll a, ll b)
{
	return (a * b) / __gcd(a, b);
}
bool is_prime(ll n)
{
	for (int i = 2; i <= n / i; i++)
		if (n % i == 0)
			return false;
	return true;
}

ll reversedigits(ll num)
{
	ll rev_num = 0;
	while (num > 0)
	{
		rev_num = rev_num * 10 + num % 10;
		//cout << rev_num << endl;
		num = num / 10;
	}
	return rev_num;
}
string re(string s)
{
	string ans = "";
	stack<char> rev;
	for (auto it : s)
		rev.push(it);
	while (!rev.empty())
	{
		ans += rev.top();
		rev.pop();
	}
	return ans;
}
int main()
{
	MOAE;
	double D, T, S;
	cin >> D >> T >> S;
	cout << ((D / S) <= T ? "Yes" : "No") << endl;
}


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

using namespace std;

int main(){
	int N, ans = 0; cin >> N;
	int a[N];
	for(int i = 0; i < N; ++i){
		cin >> a[i];
		a[i]--;
	}
	int now = 0;
	for(int i = 0; i < N; ++i){
		now = a[now];
		ans++;
		if(now == 1){
			cout << ans << endl;
			return 0;
		}
	}
	cout << -1 << endl;
}

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

int main () {
  long N;
  cin >> N;
  long x = sqrt(N), y;
  for (int i = x; i > 0; i--) {
    if (N%i == 0) {
      y = N/i;
      break;
    }
  }
  int count = 1;
  while (y/10 != 0) {
    count++;
    y /= 10;
  }
  cout << count << endl;
}

Measured memory_bytes: 256
//shara's here
//SPEEEEEEEEEED IS KEEEEEEEEEEY
//REEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEEAAAAAAAAAAAAAAAAAAAADDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDDD
#include <bits/stdc++.h>
using namespace std;
typedef string s;
typedef long long ll;
typedef long double ld;
const ll INF = 1e18 + 10;
const ll MINF = -(1e18 + 10);
const ll MOD = 1e9 + 7;
#if defined(BANYANYA)
#include "/home/xsharawi/Desktop/cpp/debug.hpp"
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
#define pb push_back
#define all(x) x.begin(),x.end()
#define vl vector<ll>
#define vll vector<vector<ll> >
#define ins insert
#define speed ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
int main(){
	speed
	ll n , a , b , ans , r;
	cin >> n >> a >> b;
	ans=(n/(a+b))*a; // to find how many blue balls there are
	r=n%(a+b);
	ans+=min(r,a);
	cout << ans << endl;
	
	
	
	
	
	
	
	
	
	
	
	






return 0;}
/*
███████████████████████████████████████████████████
███████████████████████████████████████████████████
██████████████████████████████████▀████████████████
██████████████████████████████████░▀███████████████
██████████████████████████████▌███░░░▀▀████████████
██▀████████████████████▐██████░▐██░░░░░░▀▀█████████
██░████████████████████▐█████▌░██▌▄░░░░▄▄░▄████▀███
█▌░███████████████████▀░█████░░░█░░░▄████░░███▀▐███
█▌░▐██████████████████░░████▌░░░▀░░▀███▀▀░▐███▄████
██░▀██████████████▌▐█▐▄▄████▌░░░░░░░░░░░░░▌████████
███░███████████████▀░▄▄██▀█▐░░░░░░░░░░░░░░▐████████
███▄░██████████████▄░░░░░░▀▀▀░░░░░░░░░░░░░█▐███████
████▄░██████████████████▄▄▄▄▄▄▐▄░░░░░░░░░░░████████
█████▄█████████████████▀▀▀▀▀▀░░░░░░░░░░░░░░████████
████████████████████████▄░░░░░░░░░░░░░░░▄░░████████
██████████████████████████▄▄▄░░░░░░░░░▄█░▄█████████
████████████████████████████████▄░░░░██▄███▀░░▀████
█████████████████████████████▀█████▄███▀▀▀░░▄▄░████
████████████████████████████▀░░▀░░▀▀░░░░▄▄▄██▀░░▀▀█
███████████████████████████▌░░░░░░░░░░░███████░░░▄█
███████████████▄░▀████████▀░░░░░░▀░░░░███████▌░░░██
███▄▄████████████▄░▀██████▄░░░░░█░░░░████████░░░▀▀
░▀█████████████████▄░▀█████░░░░██░░░░▀██████░░░░░▄█
▐█▄▀█████████████████▄░▀████░░░██▌░░░▐████▀░░░░▄███
▐███▄▀▀█████████████████▄░▀▀░░░░▀██▌▄█▀▀░░░▄▄██████
▀▀▀▀▀░░░▀▀▀▀▀░░░▀▀▀▀▀▀▀▀▀▀▀░░░░░░░▀▀░░░░░░▀▀▀▀▀▀▀▀▀
*/


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<bitset>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<list>
#include<iomanip>
#include<cmath>
#include<cstring>
#include<functional>
using namespace std;

#define repr(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define rep(i, n) repr(i, 0, n)
#define INF 2e9
#define MOD 1000000007
//#define MOD 998244353
#define LINF (long long)4e18
#define jck 3.141592

using ll = long long;
using Pi = pair<int,int>;
using Pl = pair<ll,ll>;


int main(){
    int N; cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    vector<int> cnt(100010);
    rep(i,N){
        cnt[a[i]]++;
    }
    ll ans = 0;
    rep(i,100010){
        if(cnt[i]) ans++;
    }
    if(ans%2 == 0) ans--;
    cout << ans << endl;
}

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

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

int main(){
    int a,b;
    cin>>a>>b;
    int ans=0;
    if(a>=13){
        ans=b;
    }else if(a>=6&&a<=12){
        ans=b/2;
    }else{
        ans=0;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3532
# -*- coding: utf-8 -*-
# 支払うべき金額
N = int(input())
# 持っている1円硬貨の枚数
A = int(input())
# 1円玉で払うべき金額
mod = N % 500
#支払い可不可判定
if mod <= A:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 2940
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;

int visited[100001];
vector<int> arr[100001];

int main() {
    int n,m,a,b;
    cin>>n>>m;
    for(int i=1;i<=m;i++){
        cin>>a>>b;
        arr[a].push_back(b);
        arr[b].push_back(a);
    }
    queue<int> q;
    visited[1]=1;
    q.push(1);
    
    while(q.empty() == 0){
        int u=q.front();
        q.pop();
        for(int i=0;i<arr[u].size();i++){
            int node=arr[u][i];
            if(visited[node]==0){
                visited[node]=u;
                q.push(node);
            }
        }    
    }
    int ans=1;
    for(int i=2;i<=n;i++){
        if(visited[i]==0){
            ans=0;
            break;
        }
    }
    if(ans==1){
        cout<<"Yes"<<endl;
        for(int i=2;i<=n;i++){
            cout<<visited[i]<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 10524
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <fstream>
#include<cstdio>
#include<iomanip>

#define REP(i, n) for(int i=0;i<n;i++)
#define REP2(i, s, n) for(int i=s;i<n;i++)
#define REP_1(i, n) for(int i=1;i<n+1;i++)
using namespace std;
typedef long long ll;
typedef unsigned long ul;
typedef long double ld;


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


int main() {
    ll N, M;
    cin >> N >> M;
    vector<ll> A(N);
    REP(i, N)cin >> A[i];
    vector<pair<int,int>> C(M);
    REP(i,M){cin>>C[i].second>>C[i].first;}
    sort(C.begin(),C.end());
    sort(A.begin(),A.end());
    int Aend=N-1;
    int Cend=M-1;
    ll sum=0;
    REP(i,N){
        if(Cend>=0) {
            if (A[Aend] >= C[Cend].first) {
                sum += A[Aend];
                Aend -= 1;
            } else {
                sum += C[Cend].first;
                C[Cend].second -= 1;
                if (C[Cend].second == 0) {
                    Cend -= 1;
                }
            }
        }else{
            sum += A[Aend];
            Aend -= 1;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(void){
    int n, k;
    char s[16];
    scanf("%d %s %d", &n, s, &k);
    char ch = s[k-1];
    for(int i = 0; i < n; i++) {
        if(s[i] == ch) printf("%c", s[i]);
        else printf("*");
    }
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <utility>
#include <algorithm>
#include <cstdio>
#include <iomanip>
#include <queue>
#include <deque>
#include <stack>
#include <fstream>
#include <cmath>
#include <random>
#include <complex>
#include <functional>

#define ll int64_t
#define Rep(i, n) for (ll i = 0; i < n; i++)
using namespace std;
typedef vector<ll> vec;
typedef vector<vec> mat;

const ll inf = 1LL << 60;

template<class T> inline void chmin(T& a, T b) {
    if (a > b) {
        a = b;
    }
}
template<class T> inline void chmax(T& a, T b) {
    if (a < b) {
        a = b;
    }
}

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

    ll N, K;
    cin >> N >> K;
    vec A(N), B(N);
    Rep (i, N) {
        cin >> A[i] >> B[i];
    }

    vec tmp;
    Rep (i, 30) {
        if ((1 << i) & K) {
            tmp.push_back(i);
        }
    }

    ll ans = 0;

    Rep (i, N) {
        if ((K | A[i]) <= K) {
            ans += B[i];
        }
    }

    for (ll e : tmp) {
        ll target = 0;
        Rep (i, 30) {
            if (i < e) target |= (1 << i);
            else if (i > e and K & (1 << i)) target |= (1 << i);
        }

        // cout << "target:" << target << "\n";

        ll sub = 0;

        Rep (i, N) {
            if ((target | A[i]) <= target) {
                sub += B[i];
            }
        }

        chmax(ans, sub);
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cmath>
#include <iostream>
#include <set>
#include <algorithm>
#include <vector>
#include <map>
#include <cassert>
#include <string>
#include <cstring>
#include <queue>

using namespace std;

#define rep(i,a,b) for(int i = a; i < b; i++)
#define S(x) scanf("%d",&x)
#define S2(x,y) scanf("%d%d",&x,&y)
#define P(x) printf("%d\n",x)
#define all(v) v.begin(),v.end()
#define FF first
#define SS second

typedef long long int LL;
typedef pair<int, int > pii;
typedef vector<int > vi;

int A[2005], mn[2005];

int main() {
  int n,x;
  S2(n,x);
  rep(i,0,n) {
    S(A[i]);
    mn[i] = A[i];
  }

  LL ans = 1000000000000000LL;
  rep(i,1,n+1) {
    LL sum = 0;
    rep(j,0,n) sum += mn[j];
    ans = min(ans, sum + (i - 1) * 1LL * x);
    rep(j,0,n) {
      mn[j] = min(mn[j], A[(j-i+n)%n]);
    }
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 256