akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

public class Main {
    static int w;
    static int h;
    static int[][] costs;
    static ArrayList<Integer> wList;
    static ArrayList<Integer> hList;
    static int count;
    static int[][] dp;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        StringBuilder sb = new StringBuilder();
        while(true) {
            w = sc.nextInt();
            h = sc.nextInt();
            if (w == 0 && h == 0) {
                break;
            }
            char[][] field = new char[h][];
            costs = new int[w * h][w * h];
            int startW = 0;
            int startH = 0;
            wList = new ArrayList<>();
            hList = new ArrayList<>();
            for (int i = 0; i < h; i++) {
                field[i] = sc.next().toCharArray();
                for (int j = 0; j < w; j++) {
                    if (field[i][j] == 'o') {
                        startH = i;
                        startW = j;
                    } else if (field[i][j] == '*') {
                        wList.add(j);
                        hList.add(i);
                    }
                }
            }
            wList.add(startW);
            hList.add(startH);
            for (int i = 0; i < h * w; i++) {
                Arrays.fill(costs[i], Integer.MAX_VALUE / 10);
                costs[i][i] = 0;
            }
            for (int i = 0; i < h; i++) {
                for (int j = 0; j < w; j++) {
                    for (int k = 0; k < h; k++) {
                        for (int l = 0; l < w; l++) {
                            if (field[i][j] != 'x' && field[k][l] != 'x' && ((i == k && Math.abs(j - l) == 1) || (j == l && Math.abs(i - k) == 1))) {
                                costs[i * w + j][k * w + l] = 1;
                            }
                        }
                    }
                }
            }
            for (int i = 0; i < h * w; i++) {
                for (int j = 0; j < h * w; j++) {
                    for (int k = 0; k < h * w; k++) {
                        costs[j][k] = Math.min(costs[j][k], costs[j][i] + costs[i][k]);
                    }
                }
            }
            count = wList.size();
            dp = new int[count][1 << (count - 1)];
            int ans = dfw(count - 1, (1 << (count - 1)) - 1);
            if (ans >= Integer.MAX_VALUE / 10) {
                sb.append(-1).append("\n");
            } else {
                sb.append(ans).append("\n");
            }
        }
        System.out.print(sb);
    }
        
    static int dfw(int from, int key) {
        if (key == 0) {
            return 0;
        }
        if (dp[from][key] != 0) {
            return dp[from][key];
        }
        int min = Integer.MAX_VALUE / 10;
        for (int i = 0; i < count - 1; i++) {
            if (((1 << i) & key) == 0) {
                continue;
            }
            int value = costs[hList.get(i) * w + wList.get(i)][hList.get(from) * w + wList.get(from)];
            min = Math.min(min, dfw(i, key ^ (1 << i)) + value);
        }
        dp[from][key] = min;
        return min;
    }
}


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

int main(){
    string s;
    cin >> s;
    if(s == "Sunny"){
        cout << "Cloudy" << endl;
        return 0;
    }
    else if(s == "Cloudy"){
        cout << "Rainy" << endl;
        return 0;
    }
    else if(s == "Rainy"){
        cout << "Sunny" << endl;
        return 0;
    }
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <iostream>
#include <sstream>
#include <vector>
#include <string>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <algorithm>
#include <functional>
#include <cstring>

using namespace std;

#define rep(i,n) for((i)=0;(i)<(int)(n);(i)++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

#define F first
#define S second

typedef pair<int,int> P;
typedef pair< pair<int,int>, pair<int,int> > PPP;

int W,H;
int mp[35][35],cost[4];
int end[35][35][4];

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

int main(){
  int i,j,k;

  while(1){
    scanf("%d %d",&W,&H);
    if(W == 0 && H == 0) break;

    rep(i,H) rep(j,W) scanf("%d",&mp[i][j]);
    rep(i,4) scanf("%d",&cost[i]);
    rep(i,35) rep(j,35) rep(k,4) end[i][j][k] = 0;

    priority_queue<PPP,vector<PPP>, greater<PPP> > q;
    q.push(PPP(P(0,1),P(0,0)));

    int ans = -1;
    while(q.size()){
      PPP now = q.top(); q.pop();
      int nowcost = now.F.F;
      int dir = now.F.S;
      int x = now.S.F;
      int y = now.S.S;

      if(x+1 == W && y+1 == H){ ans = nowcost; break; }
      if(end[x][y][dir] == 1) continue;
      end[x][y][dir] = 1;
      rep(i,4){
        int xx = x + dx[(i+dir)%4];
        int yy = y + dy[(i+dir)%4];
        int nextcost = nowcost;
        if(mp[y][x] != i) nextcost += cost[i];
        if(xx < 0 || yy < 0 || W <= xx || H <= yy) continue;
        if(!end[xx][yy][(i+dir)%4]) q.push(PPP(P(nextcost,(i+dir)%4),P(xx,yy)));
      }
    }

    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1076
import sys
input = sys.stdin.readline


def calc(A, i):
    res = 0
    for a in A:
        res += (a - i) ** 2
    return res

def main():
    N = int(input())
    A = list(map(int, input().split()))

    ans = 10 ** 7
    for i in range(-100 ,101):
        ans = min(ans, calc(A, i))
    
    print(ans)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include <bits/stdc++.h>
using namespace std;

#define INF 1e18
#define EPS 1e-9
#define MOD 1000000007

// for using in pairs
#define F first
#define S second

// Macros
#define all(x) begin(x), end(x)

// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

#define int long long

///////////////////////////////////////////////////////////////////////

void solve(int tc)
{
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; i++)
		cin >> a[i];

	int ans = 0;
	for (int i = 1; i < n; i++)
	{
		if (a[i] < a[i - 1])
		{
			ans += a[i - 1] - a[i];
			a[i] = a[i - 1];
		}
	}

	cout << ans;

}

int32_t main()
{
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	// cin >> t;
	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}

	return 0;
}


Measured memory_bytes: 5176
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()

using namespace std;

void execute()
{
	int a, b, c;
	int k;
	cin >> a >> b >> c;
	cin >> k;
	int ans = a + b + c + pow(2, k) * max(a, max(b, c)) - max(a, max(b, c));
	cout << ans << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 512
# -*- coding: utf-8 -*-
X, Y = map(int, input().split())

turtle_num = (Y - 2 * X) / 2
crain_num = X - turtle_num
ans = turtle_num * 4 + crain_num * 2
if turtle_num % 1 == 0 and crain_num % 1 == 0 and turtle_num >= 0 and crain_num >= 0:
    print("Yes")
#     print("Yes", turtle_num, crain_num)
else:
    print("No")

Measured memory_bytes: 9240
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A[] = new int[N];

		for (int i = 0; i < N; i++) {
			A[i] = sc.nextInt();
		}
		sc.close();

		String ans = "YES";

		Arrays.sort(A);

		for (int j = 1; j < N; j++) {
			if (A[j - 1] == A[j]) {
				ans = "NO";
				break;
			}
		}
		System.out.println(ans);
	}
}


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

int main()
{
	int N;
	cin >> N;
	
	int profit, buy, t_buy, t_sale;
	N--;
	cin >> buy;
	t_buy = t_sale = buy;
	profit = -1000000000;
	
	while(N--)
	{
		cin >> t_sale;
		if(t_sale - t_buy > profit)
		{
			profit = t_sale - t_buy;
			buy = t_buy;
		}
		if(t_sale < t_buy)
		{
			t_buy = t_sale;
		}
	}
	cout << profit << endl;
	return 0;
}

Measured memory_bytes: 3092
import itertools

def main():
    N = int(input())
    S = input()

    if N % 2 == 1:
        print("No")
        return
    if S[:(N//2)] == S[(N//2):]:
        print("Yes")
        return
    
    print("No")

if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<cstdlib>
#include<cstdio>

using namespace std;

struct Node {
  int data;
  Node *left, *right;
} *NIL, *root = NIL;
int in[500001], pre[500001], _in, _pre;

void insert (Node *node) {
  Node *y = NIL;
  Node *x = root;

  while (x != NIL) {
    y = x;

    if (node->data < x->data)
      x = x->left;
    else
      x = x->right;
  }

  if (y == NIL)
    root = node;
  else if (node->data < y->data)
    y->left = node;
  else
    y->right = node;
}

void inorder (Node *node) {
  if (node == NIL)
    return;

  inorder(node->left);

  in[_in++] = node->data;

  inorder(node->right);
}

void preorder (Node *node) {
  if (node == NIL)
    return;
  
  pre[_pre++] = node->data;

  preorder(node->left);
  preorder(node->right);
}

void printArrary (int arr[], int length) {
  for (int i = 0; i < length; i++)
    cout << " " << arr[i];

  cout << endl;
}

void print () {
  _in = 0;
  _pre = 0;
  inorder(root);
  printArrary(in, _in);
  preorder(root);
  printArrary(pre, _pre);
}

void find (int n) {
  Node *node = root;
  bool found = false;

  while (node != NIL) {
    if (node->data == n) {
      found = true;
      break;
    }

    if (node->data > n)
      node = node->left;
    else
      node = node->right;
  }

  if (found)
    cout << "yes" << endl;
  else
    cout << "no" << endl;
}

int main () {
  int n, m;
  char s[100];

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

  for (int i = 0; i < n; i++) {
    cin >> s;

    if (s[0] == 'i') {
      cin >> m;

      Node *node = (Node *)malloc(sizeof(Node));

      node->left = NIL;
      node->right = NIL;
      node->data = m;

      insert(node);
    } else if (s[0] == 'f') {
      cin >> m;
      
      find(m);
    } else {
      print();
    }
  }

  return 0;
}


Measured memory_bytes: 18780
#include<bits/stdc++.h>
using namespace std;
auto no = [](){cout << "NO"; exit(0);};
auto read = [](){int x; cin >> x; return x;};
int main(){
	ios::sync_with_stdio(false);
	set<int> s;
	map<int, int> m;
	for(int i = 0; i < 6; i += 1) {
		int a;
		cin >> a;
		s.insert(a);
		m[a] += 1;
	}
	if(s.size() < 4) no();
	for(auto p : m) if(p.second > 2) no();
	cout << "YES";
}

Measured memory_bytes: 256
def Pre(i):
    if dali[i].node != -1:
        ret = dali[i].node
        dali[i].node = -1
        order.append(ret)
    if dali[i].left != -1:
        Pre(dali[i].left)
    if dali[i].right != -1:
        Pre(dali[i].right)
def Pre2(u):
    if u == -1:
        return 
    order.append(u)
    Pre2(dali[u].left)
    Pre2(dali[u].right)

def In2(u):
    if u == -1:
        return 
    In2(dali2[u].left)
    
    order.append(u)
    In2(dali2[u].right)


def Postorder(u):
    if u == -1:
        return None
    Postorder(dali3[u].left)
    Postorder(dali3[u].right)
    order.append(dali3[u].node)
    dali3[u].node = -1



    
class BiTree():
    def __init__(self, node, left, right):
        self.node = node
        self.left = left
        self.right = right


def inputdata(i):
    node, left, right = list(map(int, input().split()))
    dali[node] = BiTree(node, left, right)
    dali2[node] = BiTree(node, left, right)
    dali3[node] = BiTree(node, left, right)

# Getting Root
        

n = int(input())
dali = [0] * n
dali2 = [0] * n
dali3 = [0] * n
order = []
for i in range(n):
    inputdata(i)
    """
for i in range(n):
    Pre(dali[i].node)
"""
for i in range(n):
    for j in range(n):
        if i == dali[j].left or i == dali[j].right:
            break
    if j == n-1:
        root = i
        break


order = []
Pre2(root)
print("Preorder")
print(" ",end = "")
print(*order)
order = []

In2(root)
print("Inorder")
print(" ",end = "")
print(*order)

order = []
print("Postorder")
print(" ",end = "")
Postorder(root)
print(*order)









Measured memory_bytes: 5624
#include <iostream>
//#include <fstream>

using namespace std;

int main(int argc, const char * argv[]) {
//    ifstream in("input.txt");
//    cin.rdbuf(in.rdbuf());
    
    int A, B, T;
    cin >> A >> B >> T;
    
    cout << (T / A) * B << endl;
    
                
    return 0;
}


Measured memory_bytes: 256
#include <sys/time.h>

#include <iostream>
#include <iomanip>
#include <algorithm>
#include <utility>
#include <cmath>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <utility>
#include <cctype>

using namespace std;

using ll = long long;
using P = pair<double, double>;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mkp(a, b) make_pair(a, b)
ll mod = 1000000007LL;



int main() {
	int x,y;
	cin >> x >> y;
	int cur = 1e9 * 2 + 100;
	//cout << cur << endl;

	// ex. x = 10, y = 20
	if (x <= y) {
		cur = min (y - x, cur);
	}

	if (-x <= y) {
		cur = min (y + x + 1, cur);
	}

	if(x <= -y) {
		cur = min (-y - x + 1, cur);
	}

	if (-x <= -y) {
		cur = min(-y + x + 2, cur);
	}

	cout << cur << endl;


	return 0;
}


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

int Euclid(int a, int b) {
  return a % b ? Euclid(b , a%b) : b;
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  
  vector<bool> prime(1000010, false);
  
  for (int i = 0; i < N; i++) {
    cin >> A[i];
  }
  
  bool cond1 = true, cond2 = false;
  
  // setwiseかどうか
  int temp = A[0];
  for (int i = 1; i < N; i++) {
    
    temp = Euclid(temp, A[i]);
    
    if (temp == 1) {
      cond2 = true;
      break;
    }
  }
  
  
  bool break_cond = false;
  
  // pairwiseかどうか
  for (int i = 0; i < N; i++) {
 
    if (A[i] > 1 && prime[A[i]]) {
      cond1 = false;
      break;
    } else {
      prime[A[i]] = true;
    }
    
    
    for (int j = 2; j * j <= A[i]; j++) {
      if (A[i] % j == 0) {
        if (prime[j]) {
          break_cond = true;
          cond1 = false;
          break;
        } else {
          prime[j] = true;
        }
        
        if (j * j < A[i] && prime[A[i]/j]) {
          break_cond = true;
          cond1 = false;
          break;
        } else {
          prime[A[i]/j] = true;
        }     
      }
    }
    
    if (break_cond) break;
  }
  
  //結論
  if (cond1) {
    cout << "pairwise coprime" << endl;
  } else if (cond2) {
    cout << "setwise coprime" << endl;
  } else {
    cout << "not coprime" << endl;
  }
  

}

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

#define f(i,a,b) for (int i = a; i < b; i++)

int main() {
string s; cin>>s;
int n = s.length();
int a = 0, b = 0;
f(i,0,n) {
if (s[i]-'0' == (i&1)) a++;
}
cout << min(a,n-a) << endl;
return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <array>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <sstream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <list>
#include <numeric>
#include <stack>
#include <iomanip>
#include <random>
#include <complex>
#include <functional>
#include <tuple>
#include <new>

using namespace std;

#define EPS (1e-9)
#define INF (1e9)
#define MOD (ll)(1e9 + 7)
#define PI (acos(-1))
#define REP(i,a,n) for(int i=a;i<n;i++)
#define rep(i, n) REP(i,0,n)
#define allof(a) (a).begin(), (a).end()

#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" ; "IMPOSSIBLE")

using ll = long long int;

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll beki(ll a, ll b) {
    ll tmp = 1;
    rep(i, b) tmp *= a;
    return tmp;
}

ll modPow(ll x, ll a) {
    if (a == 1) return x;
    if (a % 2) return (x * modPow(x, a - 1)) % MOD;
    ll t = modPow(x, a / 2);
    return ((t % MOD) * (t % MOD)) % MOD;
}

ll modInv(ll x) {
    return modPow(x, MOD - 2);
}

int N, X, Y;
vector<int> v[2010];
vector<int> v_dis(2010, INF);
vector<int> ans(2010, 0);

void bfs(int f) {
    rep(i, 2010) v_dis[i] = INF;
    queue<int> q;
    q.push(f);
    int dis = 1;
    v_dis[f] = dis;
    while (!q.empty()) {
        rep(i, v[q.front()].size()) {
            if (v_dis[v[q.front()][i]] > v_dis[q.front()]) {
                v_dis[v[q.front()][i]] = v_dis[q.front()] + 1;
                q.push(v[q.front()][i]);
                //cout << q.front() + 1 << " " << v[q.front()][i] + 1 << endl;
                //cout << "dis" << v_dis[v[q.front()][i]] << endl;
            }
        }
        q.pop();
        //dis++;
        //cout << endl;
    }
    //int ans = 0;
    rep(i, N) {
        if (i == f) continue;
        ans[v_dis[i]]++;
        //cout << "ans" << ans[v_dis[i]] << endl;
    }
    //return ans;
    return;
}

int main() {
    cin >> N >> X >> Y;
    rep(i, N - 1) {
        v[i].push_back(i + 1);
        v[i + 1].push_back(i);
    }
    v[X - 1].push_back(Y - 1);
    v[Y - 1].push_back(X - 1);

    //ll ans = 0;
    //rep(i, N) cout << bfs(i) << endl;
    rep(i, N) bfs(i);
    REP(i, 2, N + 1) cout << ans[i] / 2 << endl;
}



Measured memory_bytes: 3740
S=input()
lis=['SUN','MON','TUE','WED','THU','FRI','SAT']
i=lis.index(S)
if S=='SUN':
    print(7)
else:
    for j in range(1,8):
        if lis[i-j]=='SUN':
            print(7-j)
            break

Measured memory_bytes: 8964
import java.util.*

fun main(args : Array<String>) {
    val scanner = Scanner(System.`in`)
    val a = scanner.nextLong()
    val b = scanner.nextLong()
    val gcd = if (a > b) gcd(a, b) else gcd(b, a)
    println(factorize(gcd).size + 1)
}

tailrec fun gcd(large: Long, small: Long): Long {
    if (small == 0L) return large
    return gcd(small, large % small)
}

fun factorize(l: Long): List<Pair<Long, Int>> {
    var target = l
    val mutableList = mutableListOf<Pair<Long, Int>>()

    for (i in 2..l) {
        if (target == 1L) break
        if (i * i > l) break
        if (target % i != 0L) continue

        var multiCount = 0
        while (target % i == 0L) {
            target = target / i
            multiCount += 1
        }

        mutableList.add((i to multiCount))
    }

    if (target != 1L) mutableList.add((target to 1))

    return mutableList
}

Measured memory_bytes: 31408
#include <iostream>

using namespace std;
 
int main(){
  float a,b,c,d,e,f,g,h;
  int t;
  
  cin >> t;
  while(t--){
    cin >> a >> b >> c >> d >> e >> f >> g >> h;
    if((d-b)/(c-a) == (h-f)/(g-e)){
      cout << "YES" << endl;
    }else{
      cout << "NO" << endl;
    }
  }
 
  return 0;
}

Measured memory_bytes: 1224
#include <cmath>
#include <deque>
#include <iostream>
#include <string>
#include <utility>

using namespace std;

int main()
{
    int A = 0, B = 0, C = 0;
    int K = 0;
    string ans = "";

    cin >> A;
    cin >> B;
    cin >> C;
    cin >> K;

    for (int i = 0; i < K; i++)
    {
        if (C <= B)
        {
            C = 2 * C;
        }
        else if (B <= A)
        {
            B = 2 * B;
        }

        if (A < B && B < C)
        {
            ans = "Yes";
            break;
        }
    }

    if (ans != "")
    {
        cout << ans << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
const int N = 100000 + 10;
int n, m, u, x[N], nxt[N], vis[N], d[N];
long long k, a[N], p[N];
int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d", &x[i]);
        a[i] = x[i] - x[i - 1];
        nxt[i] = i;
    }
    scanf("%d%lld", &m, &k); 
    for (int i = 1; i <= m; i++) {
        scanf("%d", &u);
        swap(nxt[u], nxt[u + 1]);
    }
    for (int i = 1; i <= n; i++) {
        if (vis[i]) continue;
        int cnt = 0;
        for (int j = i; !vis[j]; j = nxt[j]) {
            vis[j] = 1;
            d[++cnt] = j;
        }
        for (int j = 1; j <= cnt; j++) p[d[j]] = a[d[(j + k - 1) % cnt + 1]];
    }
    for (int i = 1; i <= n; i++) {
        p[i] += p[i - 1];
        printf("%lld.0\n", p[i]);
    }
    return 0;
}

Measured memory_bytes: 4608
#include<bits/stdc++.h>
#define ll long long 
#define mp make_pair 
#define f(i,n) for(int i=0;i<n;i++) 
#define F first 
#define S second 
#define pb push_back 

using namespace std;

ll mod = 1e9 + 7;

void test(){
	ll n;
	cin>>n;
	ll a[n];
	f(i,n)cin>>a[i];
	ll suf[n];
	suf[n-1] = 0;
	for(int i=n-2;i>=0;i--){
		suf[i] = (suf[i+1] + a[i+1])%mod;
	}
	ll ans = 0;
	f(i,n){
		ans = ans + (a[i]*suf[i])%mod;
	}
	ans = ans%mod;
	cout<<ans<<"\n";
}

int main(){
	int tests=1;
	// cin>>tests;
	while(tests--){
		test();
	}
}


Measured memory_bytes: 6740
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;


void solve(){
	int n,k;
	cin>>n>>k;
	int ans=0;
	while(n){
		n/=k;
		ans++;
	}
	cout<<ans;

}

int main(){
	fast_io
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

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

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

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

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

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

	// For prime mod.
	// Do not use if MOD is not prime number !!
	mint inv() const { return pow(MOD-2);}
	mint& operator/=(const mint a) { return (*this) *= a.inv();}
	mint operator/(const mint a) const {mint res(*this); return res/=a;}
};

typedef vector<mint> vm;
typedef vector<vm> vvm;
void solve() {
    ll n, s;
    cin >> n >> s;
    vll a(n);
    for(ll i = 0; i < n; i++) cin >> a[i];
    vector<vvm> dp(n + 1, vvm(s + 1, vm(3)));
    dp[0][0][0] = 1;
    for(ll i = 0; i < n; i++) {
        for(ll j = 0; j <= s; j++) {
            dp[i + 1][j][0] += dp[i][j][0];
            dp[i + 1][j][1] += dp[i][j][0] + dp[i][j][1];
            dp[i + 1][j][2] += dp[i][j][0] + dp[i][j][1] + dp[i][j][2];
            if(j + a[i] <= s) {
                dp[i + 1][j + a[i]][1] += dp[i][j][0] + dp[i][j][1];
                dp[i + 1][j + a[i]][2] += dp[i][j][0] + dp[i][j][1];
            }
        }
    }
    cout << dp[n][s][2].x << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 496076
#include <cstdio>
#include <algorithm>
#include <stack>

using namespace std;

const int maxn=3005;

int dp[maxn][maxn];
char a[maxn], b[maxn];
int n, m;

int solve(int x, int y){
	if(x==-1 || y==-1){
		return 0;
	}
	if(dp[x][y]!=-1){
		return dp[x][y];
	}
	if(a[x]==b[y]){
		return dp[x][y]=solve(x-1, y-1)+1;
	}
	return dp[x][y]=max(solve(x-1, y), solve(x, y-1));
}

void backtrack(){
	int x=n-1, y=m-1;
	stack < char > s;
	while(true){
		if(a[x]==b[y]){
			s.push(a[x]);
			x--;
			y--;
		}
		else if(x==0){
			y--;
		}
		else if(y==0){
			x--;
		}
		else if(dp[x][y-1]>dp[x-1][y]){
			y--;
		}
		else{
			x--;
		}
		if(x<0 || y<0){
			break;
		}
	}
	while(!s.empty()){
		printf("%c", s.top());
		s.pop();
	}
	printf("\n");
}

int main(){
	scanf("%3005s", &a);
	scanf("%3005s", &b);
	for(int i=0; i<maxn; i++){
		if((int)a[i]-'a'<26 && (int)a[i]-'a'>=0){
			n++;
		}
		if((int)b[i]-'a'<26 && (int)b[i]-'a'>=0){
			m++;
		}
	}
	for(int i=0; i<maxn; i++){
		for(int j=0; j<maxn; j++){
			dp[i][j]=-1;
		}
	}
	solve(n-1, m-1);
	backtrack();
	return 0;
}

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

typedef pair<int, int> P;
const int inf = 1e9 + 9;

int cost[3000][3000];
//bool used[3000];

struct edge
{
  edge() {}
  edge (int t, int c) { to = t; cost = c; }
  int to, cost;
};

vector<edge> G[3000];
int d[3000];
bool f[3000][3000];
vector<int> pre[3000];

int n, m, k;

void dijkstra(int s)
{
  priority_queue<P, vector<P>, greater<P>> q;
  d[s] = 0;
  q.push(P(0, s));

  while (!q.empty()){
    P p = q.top(); q.pop();
    int v = p.second;

    if (d[v] < p.first) continue;
    for (int i = 0; i < G[v].size(); i++){
      edge e = G[v][i];
      if (d[e.to] == d[v] + e.cost){
        pre[e.to].push_back(v);
      }
      if (d[e.to] > d[v] + e.cost){
        d[e.to] = d[v] + e.cost;
        q.push(P(d[e.to], e.to));
        pre[e.to].clear();
        pre[e.to].push_back(v);
      }
    }
  }
}

/*
void dijkstra(int s)
{
  memset(used, false, sizeof(used));
  d[s] = 0;

  while (true){
    int v = -1;

    for (int u = 0; u < n; u++)
      if (!used[u] && (v == -1 || d[u] < d[v])) v = u;
    
    if (v == -1) break;
    used[v] = true;

    for (int u = 0; u < n; u++){
      if (d[u] == d[v] + cost[v][u]){
        pre[u].push_back(v);
      }
      if (d[u] > d[v] + cost[v][u]){
        d[u] = d[v] + cost[v][u];
        pre[u].clear();
        pre[u].push_back(v);
      }
    }
  }
}
*/

void dfs(int v)
{
  for (int i = 0; i < pre[v].size(); i++){
    int u = pre[v][i];
    if (!f[u][v]) continue;
    f[v][u] = f[u][v] = false;
    dfs(u);
  }
}

int main()
{
  for (int i = 0; i < 3000; i++)
    for (int j = 0; j < 3000; j++)
      cost[i][j] = inf;

  cin >> n >> m >> k;
  for (int i = 0; i < m; i++){
    int a, b, l;
    cin >> a >> b >> l;
    a--; b--;
    cost[a][b] = cost[b][a] = l;
    G[a].push_back(edge(b, l));
    G[b].push_back(edge(a, l));
    f[a][b] = f[b][a] = true;
  }

  fill(d, d + n, inf);
  for (int i = 0; i < k; i++){
    int s;
    cin >> s;
    dijkstra(s - 1);
  }

  for (int i = 0; i < n; i++){
    dfs(i);
  }

  /*
  for (int i = 0; i < n; i++){
    cout << d[i] << (i + 1 == n ? "\n" : " ");
  }

  for (int i = 0; i < n; i++){
    for (int j = 0; j < n; j++){
      cout << (f[i][j] ? "t" : "f") << (j + 1 == n ? "\n" : " ");
    }
  }
  */

  int ans = 0;
  for (int i = 0; i < n; i++){
    ans = max(ans, d[i]);
  }

  for (int i = 0; i < n; i++){
    for (int j = i; j < n; j++){
      if (f[i][j]){
        ans = max(ans, max(d[i], d[j]) + (int)round((cost[i][j] - abs(d[i] - d[j])) / 2.0));
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 50080
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
using namespace std;

#define ll long long
#define INF (1 << 30)
#define INFLL (1LL << 60)

#define FOR(i,a,b) for(ll i = (a);i<(b);i++)
#define REP(i,a) FOR(i,0,(a))
#define MP make_pair

int main() {
	int n, k, a[100];
	cin >> n >> k;
	for(int i = 0;i < n;i++){
		cin >> a[i];
		a[i] *= -1;
	}
	sort(a, a+n);
	int sum = 0;
	for(int i = 0;i < k;i++){
		sum += a[i];
	}
	cout << -sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int memo[124];
	int i,a;
	char c;
	char *base = "abcdefghijklmnopqrstuvwxyz";
	memset(memo,0,sizeof(memo));
	while(scanf("%c",&c)!=EOF) {
		if('A'<=c&&c<='Z') a=(int)(c-'A'+'a');
		else a=(int)c;
		memo[a]++;
	}
	for (i=0;i<26;i++)
		printf("%c : %d\n",base[i],memo[(int)base[i]]);
	return 0;
}

Measured memory_bytes: 540
#include "bits/stdc++.h"

using ll = long long;
using namespace std;

const int N = 2e9;

void solveCase() {

   int a, b, c;
   cin >> a >> b >> c;
   int c_eat = min(c, a + b + 1);
   cout << c_eat + b << endl;

}


int main() {
   cin.tie(0);
   cin.sync_with_stdio(0);
   
   int testcase = 1;
   // cin >> testcase;
 
   for(int i = 0; i < testcase; i++) {
      solveCase();
   }
 
   return 0;
}


Measured memory_bytes: 3616
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <int,int>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

struct NUM
{
	int sum,num[20];
}
dp[10010],now;
int n,m,x,co[]={0,2,5,5,4,5,6,3,7,6};
vector <int> v;

bool LESS(NUM a,NUM b)
{
	if(a.sum<b.sum) return true;
	if(a.sum>b.sum) return false;
	for(int i=9;i>0;i--)
	{
		if(a.num[i]<b.num[i]) return true;
		if(a.num[i]>b.num[i]) return false;
	}
	return false;
}

int main()
{
	cin>>n>>m;
	rep(i,m)
	{
		cin>>x;
		v.pb(x);
	}
	repn(i,10005) dp[i].sum=-1;
	rep(i,n-1)
	{
		if(dp[i].sum==-1) continue;
		rep(j,m)
		{
			if(i+co[v[j]]>n) continue;
			now=dp[i];
			now.sum++;
			now.num[v[j]]++;
			if(LESS(dp[i+co[v[j]]],now)) dp[i+co[v[j]]]=now;
		}
	}
	for(int i=9;i>0;i--) rep(j,dp[n].num[i]) cout<<i;
	cout<<endl;
	rt0;
}


Measured memory_bytes: 1024
#include <iostream>

using namespace std;

string f(int x) {
    if (x == 7 || x == 5 || x == 3) {
        return "YES";
    }
    return "NO";
}

int main() {

    int x;
    cin >> x;

    string result = f(x);
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
#define ll long long
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define vi vector<int>
using namespace std;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T &a, const T &b){ if(a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b){ if(b<a) { a=b; return 1; } return 0; }

int main(){
  cin.tie(0), ios::sync_with_stdio(false);
  int n; cin >> n;
  vector<vi> f(n,vi(10)); rep(i,n) rep(j,10) cin >> f[i][j];
  vector<vi> p(n,vi(11)); rep(i,n) rep(j,11) cin >> p[i][j];

  int ans = -1001001001;
  rep(bit,1<<10){
    if(bit == 0) continue;
    vi cnt(n);
    rep(i,10){
      if(bit>>i & 1){
        rep(j,n) cnt[j] += f[j][i];
      }
    }
    int res = 0;
    rep(i,n) res += p[i][cnt[i]];
    chmax(ans,res);
  }
  cout << ans;
  cout << "\n";
  return 0;
}


Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
const char EOL = '\n';
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n;
    cin >> n;
    n = (int)pow(2, n);
    deque<int> q;
    int a;
    REP(i, n) {
        cin >> a;
        q.emplace_back(a);
    }

    while (q.size() > 1) {
        auto x = q.front(); q.pop_front();
        auto y = q.front(); q.pop_front();
        q.emplace_back(x == y ? x : abs(x - y));
    }
    cout << q.front() << EOL;

}



Measured memory_bytes: 1408
N = gets.chomp.to_i
str = gets.split
l = Array.new(N)
m = Array.new(1001,N)
for i in 0...N do
    l[i] = str[i].to_i
end
l.sort!

a = 0
for i in 0...N do
    while a < l[i]
        m[a] = i
        a += 1
    end
end

a1 = 0
for i in 2...1000 do
    for j in i+1..1000 do
        k = (j-i) > i ? (j-i) : i
        a1 += (m[i]-m[i-1]) * (m[j]-m[j-1]) * (m[j-1]-m[k])
    end
end
a2 = 0
for i in 2..1000 do
    j = m[i]-m[i-1]
    max = (i*2-1) < 1000 ? i*2-1 : 1000
    if j >= 2
        a2 += (m[max] - (m[i]-m[i-1])) * j*(j-1)/2 
    end
end
a3 = 0
for i in 1..1000 do
    k = m[i]-m[i-1]
    if k >= 3
       a3 += k*(k-1)*(k-2)/6 
    end
end
answer = a1 + a2 + a3
puts answer

Measured memory_bytes: 1912
#include<bits/stdc++.h>
using namespace std;
int main()
{
	long long n; scanf("%lld", &n);
	long long k;
	for (long long i = 1; i <= 3500; i++) {
		for (long long j = 1; j <= 3500; j++) {
			if (4 * i*j - n*j - n*i == 0)continue;
			k = (n*i*j)/(4 * i*j - n*j - n*i) ;
			if (n*i*j == (4 * i*j - n*j - n*i)*k&&k>0) {
				printf("%lld %lld %lld", i, j, k);
				return 0;
			}
		}
	}
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <string>
#include <tuple>
#include <utility>
#include <vector>

int main() {
    int N;
    std::cin >> N;

    std::vector<std::string> S;
    std::vector<int> P;
    S.reserve(N);
    P.reserve(N);
    std::string s;
    int p;
    for (int i = 0; i < N; ++i) {
        std::cin >> s >> p;
        S.push_back(std::move(s));
        P.push_back(p);
    }

    std::vector<std::tuple<std::string, int, int>> x;
    x.reserve(N);
    for (int i = 0; i < N; ++i) {
        x.emplace_back(S[i], -P[i], i + 1);
    }

    std::sort(x.begin(), x.end());

    for (const auto& i : x) {
        std::cout << std::get<2>(i) << std::endl;
    }
}


Measured memory_bytes: 256
#include<stdio.h>

main(){
  int i, n;
  double x1, y1, x2, y2, x3, y3, x4, y4;
  double ab, cd;

  scanf("%d", &n);

  for(i=0; i<n; i++){
    scanf("%lf %lf %lf %lf %lf %lf %lf %lf", &x1, &y1, &x2, &y2, &x3, &y3, &x4, &y4);
    ab = (y2 - y1)/(x2 - x1);
    cd = (y4 - y3)/(x4 - x3);

    if(ab == cd)
      printf("YES\n");
    else
      printf("NO\n");
  }

  return 0;
}

Measured memory_bytes: 0
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

func main() {
	sc := NewScanner()
	_, s := sc.NextInt(), sc.Next()

	if strings.Count(s, "R") > strings.Count(s, "B") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

type Scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func NewScanner() *Scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 1000)
	return &Scanner{r: rdr}
}
func (s *Scanner) Next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *Scanner) NextLine() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *Scanner) NextInt() int {
	v, _ := strconv.Atoi(s.Next())
	return v
}
func (s *Scanner) NextInt64() int64 {
	v, _ := strconv.ParseInt(s.Next(), 10, 64)
	return v
}

func (s *Scanner) NextFloat() float64 {
	v, _ := strconv.ParseFloat(s.Next(), 64)
	return v
}

func (s *Scanner) NextIntArray() []int {
	s.pre()
	start := s.p
	result := []int{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 0)
			result = append(result, int(v))
			start = s.p + 1
		}
	}

	return result
}
func (s *Scanner) NextInt64Array() []int64 {
	s.pre()
	start := s.p
	result := []int64{}
	for ; s.p < len(s.buf)+1; s.p++ {
		if s.p == len(s.buf) || s.buf[s.p] == ' ' {
			v, _ := strconv.ParseInt(string(s.buf[start:s.p]), 10, 64)
			result = append(result, v)
			start = s.p + 1
		}
	}
	return result
}

func (s *Scanner) NextMap() map[int]bool {
	s.pre()
	start := s.p
	mp := map[int]bool{}
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			v, _ := strconv.Atoi(string(s.buf[start:s.p]))
			mp[v] = true
			start = s.p + 1
		}
	}
	v, _ := strconv.Atoi(string(s.buf[start:s.p]))
	mp[v] = true

	return mp
}

func (s *Scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *Scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{	
	int a, b, c;
	int rect = 0, rhom = 0;
	while (scanf("%d,%d,%d", &a, &b, &c) != -1)
	{
		if (a * a + b * b == c * c) rect++;
		if (a == b) rhom++;
	}
	printf("%d\n%d\n", rect, rhom);

	return 0;
}

Measured memory_bytes: 1024
import numpy as np
N,D = map(int, input().split())
X=np.array([[float(x) for x in input().split()] for i in range(N)])
count=0
for i in range(N):
    for j in range(i+1,N):
        count = count + ( 1 if np.linalg.norm(X[i]-X[j]).is_integer() else 0 )
print(count)

Measured memory_bytes: 12428
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <string>
#include <map>
#include <iterator>
#include <set>
#include <queue>
#include <bitset>
#include <cassert>

using namespace std;

long long M = 1000000007;

int d(string t, string s, int n) {
    int cnt = 0;
    for (int i = 0; i < n; ++i) {
        if (t[i] != s[i]) {
            cnt += 1;
        }
    }
    return cnt;
}

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

    int sN = S.size();
    int tN = T.size();
    int res = tN;
    for (int i = 0; i < sN - tN + 1; ++i) {
        res = min(res, d(T, S.substr(i, tN), tN));
    }
    cout << res << endl;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vi;
typedef pair<ll,ll> pi;
typedef vector<pi> vpi;
typedef long double ld;
#define pb emplace_back
#define mp make_pair
#define lb lower_bound
#define ub upper_bound
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll)x.size()
#define f first
#define s second
#define MAXN 501010

ll T,N,M,a,b;
ll A[MAXN];
vi V[MAXN];

int main(){
	cin>>N>>a>>b;
	ll g = a+b;
	ll t =(N/g)*a;
	ll leftover = min(N%g, a);
	cout<<t+leftover;
}


Measured memory_bytes: 12544
#include <cassert>
#include <cctype>
#include <cfloat>
#include <climits>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#if __cplusplus >= 201103L
#include <cfenv>
#include <cinttypes>
#include <cstdint>
#endif
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <chrono>
#include <forward_list>
#include <initializer_list>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
#if __cplusplus >= 201402L
#include <shared_mutex>
#endif

#define rep(i,n) for(ll i = 0;i < n;++i)
#define all(v) v.begin(),v.end()
using namespace std;
using ll = long long;
typedef pair<int,int> P;

const int INF = 1001001001;
const long double PI = (acos(-1));
const int mod = 1e9+7;
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};

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



int main(){
 
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int now = a[0];
    ll ans = 0;
    rep(i,n){
        if(i == 0) continue;
        if(now <= a[i]) {
            now = a[i];
        }
        else {
            ans += now - a[i];
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef set<int> si;
typedef pair<int,int> pii;
#define rep(i,a,b) for(int i=(a); i<(b); ++i)
#define per(i,a,b) for(int i=(b)-1; i>=(a); --i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define F first
#define S second
const int INF = 987654321;
const ll MOD = 1000000007;
//const long double PI = (acos(-1));
//const long double EPS = 0.0000000001;
int dy[4] = {-1, 0, 1, 0};
int dx[4] = {0, 1, 0, -1};

ll n, k;
ll a[100050];
ll ret[45];
ll m;

void solve(ll d, ll flag) {
	if(d < 0) return;

	ll cnt = 0;
	rep(i,0,n) {
		if(a[i] & (1LL << d)) {
			cnt++;
		}
	}

	//cout << d << ", " << cnt << endl;
	
	if(flag) {
		if(cnt > m/2) {
			ret[d] = 0;
		} else {
			ret[d] = 1;
		}
	} else {
		if(cnt > m/2) {
			ret[d] = 0;
			if(k & (1LL << d)) {
				flag = 1;
			}
		} else {
			if(k & (1LL << d)) {
				ret[d] = 1;
			} else {
				ret[d] = 0;
			}
		}
	}

	solve(d-1, flag);
}

int main(void) {
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	//freopen("in.txt", "r", stdin);
	cin >> n >> k;
	rep(i,0,n) 
		cin >> a[i];
	rep(i,0,45) 
		ret[i] = 0;

	m = n-1;

	ll d = 0;
	while((1LL << d) <= k) {
		d++;
	}
	d--;
	
	solve(d, 0);

	ll x = 0;
	rep(i,0,41) {
		if(ret[i]) {
			x |= (1LL << i);
		}
	}

	ll ans = 0;
	rep(i,0,n) {
		ans += (x ^ a[i]);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <map>
#include <cstring>
#include <string>
typedef long long ll;
using namespace std;
int n,x,sum;
int main(){
	scanf("%d%d",&n,&x);
	for(int i=0;i<n;++i){
		int t;
		scanf("%d",&t);
		if((sum+=t)>x){	
			printf("%d\n",i+1);
			return 0;
		}
	}
	printf("%d\n",n+1);
	return 0;
} 

Measured memory_bytes: 888
def gcd(x,y):
    if x < y:
        (x,y) = (y,x)
    while y > 0:
        r = x % y
        x = y
        y = r
    return x

n,x = map(int, input().split())
list_x = list((map(int, input().split())))
list_x.append(x)
list_x.sort()
list_dist = []
for i in range(0,n):
    list_dist.append(list_x[i+1] - list_x[i])
gcd1 = list_dist[0]
for i in range(1,n):
    gcd1 = gcd(gcd1, list_dist[i])
print(gcd1)


Measured memory_bytes: 14224
n = int(input())
h = list(map(int, input().split()))

s = 0

for i in range(max(h)+1):
    flag = False
    for j in range(n):
        if flag and h[j] == 0:
            s += 1
            flag = False
        elif not flag and h[j] > 0:
            flag = True

        h[j] = max(h[j]-1, 0)
    if flag:
        s += 1

print(s)



Measured memory_bytes: 9088
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.NoSuchElementException;

public class Main {
	public void solve() {
		int N = nextInt();
		int[] a = new int[N];
		for(int i = 0;i < N;i++){
			a[i] = nextInt() - 1;
		}
		boolean[] used = new boolean[N];
		int ans = 0;
		for(int i = 0;i < N;i++){
			int x = a[i];
			int y = a[x];
			if(used[x])continue;
			if(used[y])continue;
			if(x == a[y] && y == a[x]){
				ans++;
				used[x] = true;
				used[y] = true;
			}
		}
		out.println(ans);
	}

	public static void main(String[] args) {
		out.flush();
		new Main().solve();
		out.close();
	}

	/* Input */
	private static final InputStream in = System.in;
	private static final PrintWriter out = new PrintWriter(System.out);
	private final byte[] buffer = new byte[2048];
	private int p = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (p < buflen)
			return true;
		p = 0;
		try {
			buflen = in.read(buffer);
		} catch (IOException e) {
			e.printStackTrace();
		}
		if (buflen <= 0)
			return false;
		return true;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrint(buffer[p])) {
			p++;
		}
		return hasNextByte();
	}

	private boolean isPrint(int ch) {
		if (ch >= '!' && ch <= '~')
			return true;
		return false;
	}

	private int nextByte() {
		if (!hasNextByte())
			return -1;
		return buffer[p++];
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = -1;
		while (isPrint((b = nextByte()))) {
			sb.appendCodePoint(b);
		}
		return sb.toString();
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 22720
# D
import numpy as np
N = int(input())
X = []
Y = []

for i in range(N):
    x, y = map(int, input().split())
    X.append(x)
    Y.append(y)

# edges
X_s = np.argsort(np.array(X))
Y_s = np.argsort(np.array(Y))

edge_list = []
edge_weight = []
for i in range(N-1):
    edge_list.append([X_s[i], X_s[i+1]])
    edge_weight.append(X[X_s[i+1]] - X[X_s[i]])
    edge_list.append([Y_s[i], Y_s[i+1]])
    edge_weight.append(Y[Y_s[i+1]] - Y[Y_s[i]])
    
# sort edges
sel = np.argsort(np.array(edge_weight))

# union find tree
uf = np.arange(N)


res = 0
flg = np.zeros(N)

for s in sel:
    m, n = edge_list[s]
    # find union
    gr_m = m
    gr_m_list = []
    gr_n = n
    gr_n_list = []
    while gr_m != uf[gr_m]:
        gr_m_list.append(gr_m)
        gr_m = uf[gr_m]
    for m_ in gr_m_list:
        uf[m_] = gr_m
        
    while gr_n != uf[gr_n]:
        gr_n_list.append(gr_n)
        gr_n = uf[gr_n]
    for n_ in gr_n_list:
        uf[n_] = gr_n
        
    if gr_m == gr_n:
        pass
    else:
        res += edge_weight[s]
        uf[gr_n] = gr_m
print(res)

Measured memory_bytes: 74088