akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

const int N = 4e3 + 5;
typedef long long LL;

int n;
LL x, ans, a[N], b[N];

int main() {
	cin>>n>>x;
	for(int i = 1; i <= n; i++)
		cin>>a[i], ans += a[i], b[i] = a[i];
	for(int i = 1; i < n; i++) {
		LL res = i*x;
		for(int j = 1; j <= n; j++)
		    b[j] = min(b[j], a[j - i + ((j - i) <= 0 ? n:0)]), res += b[j];
		ans = min(ans, res); 
	}
	cout<<ans<<endl;
}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >>N;
  int X,L;
  vector<pair<int,int>> Robot(N); 
  for (int i=0;i<N;i++){
    cin>>X>>L;
    Robot[i].first=X+L;
    Robot[i].second=X-L;
  }
  sort(Robot.begin(),Robot.end());
  int ans=1;
  int nagasa=Robot[0].first;
  for (int i=0;i<N;i++){  
    if (nagasa<=Robot[i].second){
      ans++;
      nagasa=Robot[i].first;
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
using namespace std;
inline bool check(int x){
	int y = x, z = 0;
	while(y){
		z = (z << 3) + (z << 1) + (y % 10);
		y /= 10;
	}
	return x == z;
}
int x, y, ans;
int main(){
	scanf("%d%d", &x, &y);
	for(int i = x; i <= y; ++i) if(check(i)) ans++;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
import sys
from math import sqrt, ceil

N = int(input())
k = ceil(sqrt(2 * N))
if k * (k - 1) != 2 * N:
    print("No")
    sys.exit()

S = [[] for _ in range(k + 1)]
num = 1
for i in range(1, k):
    for j in range(i + 1, k + 1):
        S[i].append(num)
        S[j].append(num)
        num += 1

print("Yes")
print(k)
for i in range(1, k + 1):
    print(len(S[i]), " ".join(map(str, S[i])))


Measured memory_bytes: 45660
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define INF 1000000000000000000
#define MAX 200001
#define MOD 1000000007

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i = 0; i < N; i++) cin >> A[i];
    
    ll res = 0;
    int right = 0;
    int sum = 0;
    for(int left = 0; left < N; left++){
        while(right < N && (sum ^ A[right]) == (sum + A[right])){
            sum += A[right];
            right++;
        }
        res += right - left;
        sum -= A[left];
    }
    cout << res << endl;
}

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

int main(void) {
    int N;
    cin >> N;

    int a[100100];
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }

    int status = 0;
    int cnt = 1;
    for (int i = 0; i < N - 1; i++) {
        if (a[i] < a[i+1]) {
            if (status == -1) {
                cnt++;
                status = 0;
            } else {
                status = 1;
            }
        }
        if (a[i] > a[i+1]) {
            if (status == 1) {
                cnt++;
                status = 0;
            } else {
                status = -1;
            }
        }


    }

    cout << cnt << endl;

    return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

/**
 * Created by shoya on 2017/04/14.
 */
public class Main {
    public static void main(String... args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++)
            ans += (isPrime(sc.nextInt())) ? 1 : 0;
        System.out.println(ans);
        return;
    }

    public static boolean isPrime(int n){
        int i = 2;
        while (i * i <= n) {
            if (n % i == 0)
                return false;
            i++;
        }
        return true;
    }
}

Measured memory_bytes: 40788
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>

using ll = long long;

using namespace std;

int main() {
    string t;
    cin >> t;
    ll ans = 0, cnt = 0;
    bool one = true;
    for (auto &c:t) {
        if (c == '1' || !one) {
            if (one) 
                cnt++;
            if (c == '0') 
                c = '-';
            ans += cnt;
            one ^= 1;
        }
    }
    reverse(t.begin(), t.end());
    one ^= 1;
    ll sum = 0, odds = 0;
    for (auto &c:t) {
        if (c == '0') {
            cnt -= odds;
            odds = sum - odds;
            cnt += odds;
            ans += cnt;
        } else {
            if (c == '1') {
                if (one) odds++;
                sum++;
            }
            one ^= 1;
        }
    }
    cout << ans << '\n';
    return 0;
}

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

#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;

using namespace std;



void oneCase() {
    int n;
    cin >> n;
    ll l = 2,  r = 1;
    while (n-- >= 2) {
        auto tmp = l;
        l = r;
        r = l  + tmp;
    }
    cout << r <<  "\n";
}

int main() {
//    std::ios::sync_with_stdio(false);
//    std::cin.tie(nullptr);

    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}


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

using namespace std;
#define ll long long
#define ull unsigned long long
#define mp make_pair
typedef pair<int, int> pii;
typedef priority_queue<int, vector<int>, greater<int> > small_heap;
typedef priority_queue<int> big_heap;
const int N = 2e6 + 100;
const int mod = 1e9 + 7;
ll fac[N], inv[N];

ll binpow(ll a, ll b) {
    ll res = 1;
    while (b) {
        if (b & 1)res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

void init() {
    fac[0] = 1;
    for (int i = 1; i < N; i++)fac[i] = fac[i - 1] * i % mod;
    inv[N - 1] = binpow(fac[N - 1], mod - 2);
    for (int i = N - 2; i >= 0; i--)inv[i] = inv[i + 1] * (i + 1) % mod;
}

ll C(ll n, ll m) {
    return fac[n] * inv[m] % mod * inv[n - m] % mod;
}

int main() {
    init();
    int k;
    string s;
    cin >> k >> s;
    int n = k + (int)s.size();
    ll ans = 0;
    for (int i = s.size(); i <= n; i++)
        ans += C(n, i) * binpow(25, n - i) % mod, ans %= mod;
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 36492
def grecom(x,y):
    if(x==0 or y==0):
        return x+y
    if(x==1 or y==1):
        return 1
    if(x==y):
        return x
    if(y>x):
        return grecom(y%x,x)
    else:
        return grecom(x%y,y)

s = input()
a,b=map(int,s.split())
print(grecom(a,b))

Measured memory_bytes: 7768
fun main(args: Array<String>){
    val input = readLine()!!.toInt()
    var total = 0L
    for (i in 1..input){
        for (j in 1..input){
            for (k in 1..input){
                total += gcd(gcd(i,j),k)
            }
        }
    }
    println(total)
}

fun gcd(a: Int, b: Int): Int {
    if(a < b) return gcd(b, a)
    if(b == 0) return a
    return gcd(b, a % b)
}

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

typedef long long ll;

const int N = 105, V = 100005;

ll dp[V];
ll value[N];
ll weight[N];
int object_count, max_weight;

void solve() {
    for (int i = 1; i <= object_count; ++i) {
        for (int w = max_weight; w >= weight[i]; --w) {
            dp[w] = max(dp[w], dp[w - weight[i]] + value[i]);
        }
    }
}

int main() {
    scanf("%d%d", &object_count, &max_weight);
    for (int i = 1; i <= object_count; ++i) {
        scanf("%lld%lld", weight + i, value + i);
    }
    solve();
    printf("%lld\n", dp[max_weight]);
    return 0;
}

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


int main(){
  string t;
  cin >> t;
  int n,w,s,e;
  n = count(t.begin(),t.end(),'N');
  w = count(t.begin(),t.end(),'W');
  s = count(t.begin(),t.end(),'S');
  e = count(t.begin(),t.end(),'E');
  if( ( ( n == 0 && s == 0 ) || ( n > 0 && s > 0 ) ) &&
      ( ( w == 0 && e == 0 ) || ( w > 0 && e > 0 ) )    ){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	
	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner stdIn = new Scanner(System.in);
		int topping_num = stdIn.nextInt();
		int material_value = stdIn.nextInt();
		int topping_value = stdIn.nextInt();
		int material_calorie = stdIn.nextInt(); //初期値として生地の値段を与える
		
		int[] data = new int[topping_num];
		int[] sum = new int[topping_num + 1];
		
		for(int r = 0; r < data.length; r++)
			data[r] = stdIn.nextInt();
		Arrays.sort(data); //後で修正
		for(int r = 0; r < data.length; r++) {
			sum[r + 1] = (sum[r] + data[r]);
		}
		int ans = -1;
		for(int r = sum.length - 1; r > 0; r--) {
			for(int c = 1; c < r; c++) {
				int psum = (sum[r] - sum[c] + material_calorie) / (material_value + topping_value*(r - c));
				if(psum > ans) {
					ans = psum;
				}
			}
		}
		
		
		System.out.println(ans);
		
	}

}

Measured memory_bytes: 18144
#include<iostream>
#include<vector>
#define rep(i,n) for(int i=0;i<(int)(n);++i)
using namespace std;
int main(){
  int i;
  int n,ans=0;
  cin>>n;
  vector<int> b(n),a(n,1000001);
  rep(i,n)cin>>b.at(i);
  for(i=0;i<n-1;++i){
    if(a.at(i)>=b.at(i))
      a.at(i)=b.at(i);
    if(a.at(i+1)>=b.at(i))
      a.at(i+1)=b.at(i);
  }
  rep(i,n)ans+=a.at(i);
  cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<cstdlib>
#include<ctime>
#include<cstdio>
#include<string>
//#include<string>
//#include<sstream>
using namespace std;

int main()
{
	int a[2],x,n;
	int i;
	long long sum=0;
	scanf("%d%d",&n,&x);
	for(i=0;i<n;i++){
		scanf("%d",&a[1]);
		if(a[1]>x){
			sum+=(a[1]-x);
			a[1]=x;
		}
		if(i!=0){
			if(a[1]+a[0]>x){
				sum+=(a[0]+a[0+1]-x);
				a[0+1]=a[0+1]-(a[0]+a[0+1]-x);
			}
		}
		
		//printf("%d ",a[0]);
		//if(i==n-1) printf("%d ",a[1]);
		a[0]=a[1];
	}
	printf("%lld\n",sum);
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>

int main(void) {
  int n, i, sa = 0, sb = 0;
  scanf("%d", &n);
  int a[n];
  for(i = 0; i < n; ++i)scanf("%d", &a[i]);
  std::sort(a, a + n);
  if(n % 2) {
    for(i = n - 1; i >= 0; --i) {
      if(i % 2) sb += a[i];
      else sa += a[i];
    }
  } else {
    for(i = n - 1; i >= 0; --i) {
      if(i % 2) sa += a[i];
      else sb += a[i];
    }
  }
  printf("%d", sa - sb);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin >> s;
  
  int start, end;
  
  for (int i = 0; i < s.size(); i++) {
    if (s.at(i) == 'A') {
      start = i;
      break;
    }
  }
  
  for (int i = s.size()-1; i >= 0; i--) {
    if (s.at(i) == 'Z') {
      end = i;
      break;
    }
  }
  
  cout << end - start + 1;
      
}

Measured memory_bytes: 3704
#include <stdio.h>
#include <stdlib.h>
typedef struct data{
long long  a,b;
}Data;
int cmp(const void *p,const void *q){
if( *(long long*)q - *(long long*)p < 0 )
        return -1;
    if( *(long long*)q - *(long long *)p > 0 )
        return 1;
    return 0;
}
int cmpa(const void *p,const void *q){
if( ((Data*)q)->a - ((Data*)p)->a < 0 )
        return -1;
    if( ((Data*)q)->a - ((Data*)p)->a > 0 )
        return 1;
    return 0;
}
int main(){
    long long N,H,i,k,ans=0,max;
    scanf("%lld%lld",&N,&H);
    long long buf[2*N];
    Data d[N];
    
    for(i=0;i<N;i++)scanf("%lld%lld",&d[i].a,&d[i].b);
    qsort(d,N,sizeof(Data),cmpa);
    max=d[0].a;
    
    for(i=0;i<N;i++){
    buf[2*i]=d[i].a;
    buf[2*i+1]=d[i].b;
    }
    qsort(buf,2*N,sizeof(long long),cmp);
    
    
    for(i=0;(i<(2*N))&&(buf[i]>=max)&&(H>0);i++){
    H-=buf[i];
    ans++;
    }
    if(H>0){
    k=(H/max);
    ans+=k;
    if(H>k*max)ans++;
    }
    
    printf("%lld",ans);
}

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

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

typedef long long ll;
typedef long double ld;
const ll MOD = 1e9 + 7;
const ld EPS = 1e-10;
const ld PI = std::acos(-1);

bool check(ld a, ld b, ld x, ld t) {
  t *= PI / 180;
  ld tant = std::tan(t);
  if(tant < b / a) {
    return x < a * a * (b - 0.5 * a * tant);
  } else {
    return x < 0.5 * a * b * b / tant;
  }
}

int main() {
  ld a, b, x;
  std::cin >> a >> b >> x;

  std::cout << std::fixed << std::setprecision(10);

  ld tl = EPS;
  ld tr = 90.0 - EPS;
  ld tc;
  while(tr - tl > EPS) {
    tc = (tl + tr) * 0.5;
    if(check(a, b, x, tc)) {
      tl = tc;
    } else {
      tr = tc;
    }
  }

  std::cout << tc << '\n';
}


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

using namespace std;

#define llong long long int
#define ldouble long double
#define rep(i, n) for (int i = 0; i < n; ++i) 
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000000 + 7;
const static int INT_INF = 999999999;
const static llong INF = 1LL << 60;
const static double eps = 1e-6;
const static int dx[] = {1, 0, -1, 0};
const static int dy[] = {0, 1, 0, -1};

char field[1001][1001];
int dist[1001][1001];

signed main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int H, W;
    cin >> H >> W;
    queue<pair<int, int> > Q;
    rep(i, H) {
        rep(j, W) {
            cin >> field[i][j];
            if (field[i][j] == '#') Q.push(make_pair(i, j));
        }
    }

    while (! Q.empty()) {
        pair<int, int> p = Q.front();
        int x = p.first, y = p.second;
        Q.pop();
        rep(i, 4) {
            if (0 <= x + dx[i] && x + dx[i] <= H - 1 && 0 <= y + dy[i] && y + dy[i] <= W - 1 && field[x + dx[i]][y + dy[i]] == '.') {
                dist[x + dx[i]][y + dy[i]] = dist[x][y] + 1;
                field[x + dx[i]][y + dy[i]] = '#';
                Q.push(make_pair(x + dx[i], y + dy[i]));
            }
        }
    }

    int ans = -1;
    rep(i, H) rep(j, W) ans = max(ans, dist[i][j]);

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 11280
n,m=map(int,input().split())
inf=1000000007
ans=1
dp=[1]*(n+1)
for i in range(m):
    dp[int(input())]=0
for i in range(n-1):
    dp[i+2]=(dp[i]+dp[i+1])*dp[i+2]
print(dp[-1]%inf)

Measured memory_bytes: 462708
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int N;
string s[200];
int d[200][200];
vector<int>G[200];
int color[200];
bool dfs(int u,int col)
{
	color[u]=col;
	int nxt=3-col;
	for(int v:G[u])
	{
		if(color[v]!=0)
		{
			if(color[v]!=nxt)return false;
		}
		else if(!dfs(v,nxt))return false;
	}
	return true;
}
main()
{
	cin>>N;
	for(int i=0;i<N;i++)
	{
		cin>>s[i];
		for(int j=0;j<N;j++)
		{
			d[i][j]=i==j?0:s[i][j]=='1'?1:1e9;
			if(s[i][j]=='1')G[i].push_back(j);
		}
	}
	if(!dfs(0,1))
	{
		cout<<-1<<endl;
		return 0;
	}
	for(int k=0;k<N;k++)for(int i=0;i<N;i++)for(int j=0;j<N;j++)
	{
		d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	}
	int ans=0;
	for(int i=0;i<N;i++)for(int j=0;j<N;j++)ans=max(ans,d[i][j]);
	cout<<ans+1<<endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll a,b,c,d;
int main()
{
    cin >> a >> b >> c >> d;
    ll dem1,dem2;
    c % b == 0 ? dem1 = c / b : dem1 = c / b + 1;
    a % d == 0 ? dem2 = a / d : dem2 = a / d + 1;
    dem1 <= dem2 ? cout << "Yes" : cout << "No";
    return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String input = sc.nextLine();
		char[] sen = input.toCharArray();

		for (int i = 0; i < sen.length; i++) {
			if (Character.isUpperCase(sen[i])) {
				sen[i] = Character.toLowerCase(sen[i]);
			} else {
				sen[i] = Character.toUpperCase(sen[i]);
			}
		}
		String output = String.valueOf(sen);
		System.out.println(output);
	}
}


Measured memory_bytes: 26252
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.20f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 998244353
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
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;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

ll dp[200100];
ll sum[200100];

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k; cin >> n >> k;
    int l[15],r[15];
    rep(i,0,k) cin >> l[i] >> r[i];
    dp[1] = 1;
    sum[1] = 1;

    reps(i,2,n){
        rep(j,0,k){
            itn left = max(1, i - r[j]);
            int right = i - l[j];
            if(right < 1) continue;
            dp[i] += ((sum[right] - sum[left-1]) % MOD + MOD) % MOD;
        }
        sum[i] = (sum[i-1] + dp[i]) % MOD;
    }

    cout << dp[n] % MOD << endl;
    return 0;
}

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

int main(){
  char S[20], n, j=0, k;
  scanf("%s", &S);
  n = strlen(S);
  for(int i=0; i<n; i++){
    if (S[i] == 'o'){
      j++;
    }
  }
  
  if ((15-n)+j >=8){
    printf("YES");
  }else{
    printf("NO");
  }
  
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1e18;

int main() {
  int n;
  cin >> n;
  vector<ll> a(n), aa(n);
  unordered_map<ll, ll> mp;
  rep(i, n) cin >> a[i], a[i] -= i + 1;
  sort(a.begin(), a.end());
  ll b = a[n / 2];

  ll ans = 0;
  for (int i = 0; i < n; ++i) ans += abs(a[i] - b);

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


Measured memory_bytes: 3328
#include "bits/stdc++.h"
using namespace std;
     
#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl
     
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll, ll>
const int inf = 1000000001;
const ll INF = 1e16;
#define MOD 1000000007
#define mod 1000000009
#define pi 3.14159265358979323846
#define Sp(p) cout<<setprecision(15)<<fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

int main() {
  int h, w;
  cin >> h >> w;
  vector<vector<string> > s(h, vector<string>(w));
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      cin >> s[i][j];
      if (s[i][j] == "snuke") {
	cout << (char)('A' + j) << i + 1 << endl;
      }
    }
  }
}


Measured memory_bytes: 256
#include<iostream>

int main(){
	
	int W,H,x,y,r;
	
	std::cin >> W >> H >> x >> y >> r;
	
	if (r<=x && x<=W-r && r<=y && y<=H-r) std::cout <<"Yes"<<"\n";
	else std::cout <<"No"<<"\n";
	
	return 0;
	
}

Measured memory_bytes: 1124
#include <stdio.h>

int main(){
	int w,n,a,b,i,tmp;
	int line[30];

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

	for(i = 0;i < w;i++){
		line[i] = i+1;
	}

	for(i = 0;i < n;i++){
		scanf("%d,%d",&a,&b);
		tmp = line[a-1];
		line[a-1] = line[b-1];
		line[b-1] = tmp;
	}

	for(i = 0;i < w;i++){
		printf("%d\n",line[i]);
	}

	return 0;
}

Measured memory_bytes: 596
#include<stdio.h>
#define MAX 500005

int n;

void swap(int *a, int *b) {
    int t;
    t = *a;
    *a = *b;
    *b = t;
}

void maxHeapify(int *A, int i) {
    int largest;
    int l = 2 * i;
    int r = 2 * i + 1;
    if (l <= n && A[l] > A[i]) largest = l;
    else largest = i;
    if (r <= n && A[r] > A[largest]) largest = r;

    if (largest != i) {
        swap(&A[i], &A[largest]);
        maxHeapify(A, largest);
    }

}

void buildMaxHeap(int *A){
    int i;
    for (i = n/2; i>0; i--)
        maxHeapify(A, i);
} 

int main() {
    int i, j;
    int A[MAX];

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

    buildMaxHeap(A);

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

    return 0;
}

Measured memory_bytes: 2552
#include <cstdio>
#include <queue>
#include <vector>
// D - .. (Double Dots)

using namespace std;

vector<int> adj[100005];
bool vis[100005];
int par[100005];
queue<int> q;

int main() {
    int N,M,i,A,B,cur;

    scanf("%d%d",&N,&M);
    for (i = 0;i < M;i++) {
        scanf("%d%d",&A,&B);
        adj[A].push_back(B);
        adj[B].push_back(A);
    }

    vis[1] = true;
    q.push(1);
    while (!q.empty()) {
        cur = q.front();
        q.pop();
        for (int nxt : adj[cur]) {
            if (!vis[nxt]) {
                vis[nxt] = true;
                par[nxt] = cur;
                q.push(nxt);
            }
        }
    }

    printf("Yes\n");
    for (i = 2;i <= N;i++)
        printf("%d\n",par[i]);

    return 0;
}


Measured memory_bytes: 10212
import sys, os

f = lambda:list(map(int,input().split()))
if 'local' in os.environ :
    sys.stdin = open('./input.txt', 'r')

def biger12(s):
    if int(s[0]) >= 2:
        return True
    if int(s[0]) == 1 and int(s[1])>=3:
        return True

    if int(s[0]) == 0 and int(s[1]) == 0:
        return True
        
    return False

def solve():
    s = input()
    s1 = s[0:2]
    s2 = s[2:]

    if biger12(s1) and biger12(s2):
        print('NA')
    elif not biger12(s1) and not biger12(s2):
        print('AMBIGUOUS')
    elif biger12(s1) and not biger12(s2):
        print('YYMM')
    else:
        print('MMYY')



solve()


Measured memory_bytes: 3064
import std.stdio, std.conv, std.string, std.bigint;
import std.math, std.random, std.datetime;
import std.array, std.range, std.algorithm, std.container, std.format;
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }

/*

i番目までの子供にj個の飴を分ける分け方の数 xs[i][j]

j <= a[i] のとき
 xs[i][j] = sum(u; 0 ..= j) xs[i - 1][u]

j > a[i] のとき
 xs[i][j] = sum(u; j - a[i] ..= j) xs[i - 1][u]


これをそのまま実装するとTLEになるので、以下のように実装する

j = 0 のとき
 xs[i][j] = 1

j <= a[i] のとき
 xs[i][j] = xs[i][j - 1] + xs[i - 1][j]

j > a[i] のとき
 xs[i][j] = xs[i][j - 1] + xs[i - 1][j] - xs[i - 1, j - a[i] - 1]	


*/

const long mod = 1_000_000_007;

void main(){
 int n = read.to!int;
 int k = read.to!int;
	
 int[] as = readln.chomp.split.map!(to!int).array;
	
 long[][] xs = [[]];
 foreach(j; 0 .. k + 1){
  if(j <= as[0]) xs[0] ~= 1;
  else xs[0] ~= 0;
 }
 debug writeln("i:0 xs:", xs);
	
 foreach(i; 1 .. n){
  xs ~= [[]];
  foreach(j; 0 .. k + 1){
   if(j == 0) xs[i] ~= 1;
   else if(j <= as[i]) xs[i] ~= xs[i][j - 1] + xs[i - 1][j];
   else xs[i] ~= xs[i][j - 1] + xs[i - 1][j] + mod - xs[i - 1][j - as[i] - 1];
   xs[i][j] %= mod;
  }
  debug writeln("i:", i, " xs:", xs);
 }
	
 xs[n - 1][k].writeln;
}

Measured memory_bytes: 113532
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
    
		// 整数の入力
		int x = sc.nextInt();
		int ans = 1;
        int b = 1;
      
        if (x == 1) {
          // 出力
		  System.out.println(ans);
          return;
        }
      
        Parent: while(true) {
          b++;
          if (Math.pow(b, 2) > x) {
            break Parent;
          }
          int p = 2;
          Child: while(true) {
            int value = (int)Math.pow(b, p);
            if (value > x) {
              break Child;
            } else if (value > ans) {
              ans = value;
            }
            p++;
          }
        }
    
		// 出力
		System.out.println(ans);
	}
}

Measured memory_bytes: 23892
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define F first
#define S second
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;
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; }
ll gcd(ll a, ll b) { return b?gcd(b, a%b):a;}
ll lcm(ll a, ll b) { return a*b/gcd(a,b);}
ll MOD=1000000007;

int main(){
  int a,b;cin>>a>>b;
  int ans=1;
  int tmp=a;
  if(b!=1){
    while(tmp<b){
      ans++;
      tmp+=a-1;
    }
    cout<<ans<<endl;
  }else{
    cout<<0<<endl;
  }
}

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

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;

    vector<int> seq;

    for(int i = 0; i < n; i++){
        int ai;
        cin >> ai;
        seq.push_back(ai);
    }

    int mininx = 0;
    int minval = 10000000;

    for(int i = 0; i < n; i++){
        if(minval > seq[i]){
            minval = seq[i];
            mininx = i;
        }
    }

    n -= k;
    cout << 1+ceil((float)n/(k-1)) << endl;

    return 0;
}

Measured memory_bytes: 892
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() { 
  ios::sync_with_stdio(false); cin.tie(0);
  //e
  int n;
  cin >> n;
  vector<long long> x(n), y(n);
  for (int i = 0; i < n; i++) cin >> x[i] >> y[i];
  long long max_x = -(1LL << 60);
  long long min_x = 1LL << 60;
  long long max_y = -(1LL << 60);
  long long min_y = 1LL << 60;
  for (int i = 0; i < n; i++) {
    int xx = x[i];
    int yy = y[i];
    x[i] = xx + yy;
    y[i] = xx - yy;
    max_x = max(max_x, x[i]);
    min_x = min(min_x, x[i]);
    max_y = max(max_y, y[i]);
    min_y = min(min_y, y[i]);
  }
  long long ans = -(1LL << 60);
  for (int i = 0; i < n; i++) {
    long long dist = -(1LL << 60);
    dist = max(dist, abs(max_x - x[i]));
    dist = max(dist, abs(min_x - x[i]));
    dist = max(dist, abs(max_y - y[i]));
    dist = max(dist, abs(min_y - y[i]));
    ans = max(ans, dist);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6364
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong a, b, c, d;

int main() {
    cin >> a >> b >> c >> d;

    while (a > 0 && c > 0) {
        c -= b;
        if (c <= 0) {
            cout << "Yes" << endl;
            return 0;
        }

        a -= d;
        if (a <= 0) {
            cout << "No" << endl;
            return 0;
        }
    }

    return 0;
}


Measured memory_bytes: 3624
using System.Linq;
using System;
using System.IO;

class Program
{
  static void Main(string[] args) => new Program().solve();

  private void solve()
  {
    var seq = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    var a = seq[0];
    var b = seq[1];

    var ans = (a <= 8) && ( b <= 8) ? "Yay!" : ":(";

    Console.WriteLine(ans);
  }
}

Measured memory_bytes: 13268
#include <cstdio>
#include <functional>
#include <algorithm>
#include <vector>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iostream>
#include <queue>
#include <math.h>
#include <bits/stdc++.h>
#include <queue>
#include <map>

using namespace std;

#define INF (1ll<<60)
#define INFint (1<<30)
#define MOD 1000000007
#define BOUND 27182818284

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

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

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

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

// gcd
template<typename T>
T gcd(T a, T b){
    if(a==0)
        return b;
    return gcd(b%a,a);
}

// gcd array
int findGCD(int arr[], int n){
    int result = arr[0];
    for (int i=1; i < n; i++)
        result = gcd(arr[i], result);
    return result;
}

template<typename T>
T lcm( T m, T n ){
    // 引数に0がある場合は0を返す
    if ( ( 0 == m ) || ( 0 == n ) )
        return 0;
    return ((m/gcd(m, n)) * n); // lcm = m * n / gcd(m,n)
}

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    fill( (T*)array, (T*)(array+N), val );
}


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

// v.front() = -BOUND;
// v.back() = BOUND;

//struct edge{
//    int cost, to;
//
//    edge(int in_cost, int in_to){
//        cost=in_cost;
//        to=in_to;
//    }
//    bool operator<(const edge &a) const
//    {
//        return cost > a.cost;
//    }
//};

int cost[100010][4];
int main() {
    int N; cin >> N;
    vector<int>a(N),b(N),c(N);
    rep(i,N) cin >> a[i] >> b[i] >> c[i];

    cost[0][0]=a[0], cost[0][1]=b[0], cost[0][2]=c[0];

    for(int i=1; i<N; i++){
        cost[i][0]=max(a[i]+cost[i-1][1], a[i]+cost[i-1][2]);
        cost[i][1]=max(b[i]+cost[i-1][2], b[i]+cost[i-1][0]);
        cost[i][2]=max(c[i]+cost[i-1][0], c[i]+cost[i-1][1]);
    }

    cout << max({cost[N-1][0], cost[N-1][1], cost[N-1][2]}) << endl;
    return 0;
}


Measured memory_bytes: 2944
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String[] streamLine = br.readLine().split(" ");
		
		int[] intLine = new int[5];
		for (int i = 0; i < 5; i++) {
			intLine[i] = Integer.parseInt(streamLine[i]);
		}
		/*
		 *  Constraint
		 * −100≤x,y≤100
		 *	0<W,H,r≤100
		 *
		 */
		int w = intLine[0];
		int h = intLine[1];
		int x = intLine[2];
		int y = intLine[3];
		int r = intLine[4];
		
		String isInside = "Yes";
		if (x < 0 || y < 0 || x + r > w || y + r > h  || x - r < 0 || y - r < 0) {
			isInside = "No";
		}
		
		System.out.println(isInside);

	}
}


Measured memory_bytes: 24348
n, m = gets.split.map(&:to_i)
h = gets.split.map(&:to_i)
rel = Array.new(n).map{Array.new}
m.times do
    a, b = gets.split.map(&:to_i)
    rel[a - 1] << b - 1
    rel[b - 1] << a - 1
end
ans = 0
n.times do |i|
    ans += 1 if rel[i].all? {|j| h[j] < h[i]}
end
puts ans

Measured memory_bytes: 27380
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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 ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   ll Q, H, S, D;
   cin >> Q >> H >> S >> D;
   ll N;
   cin >> N;
   Q *= 4;
   H *= 2;
   ll MIN = min(Q, min(H, S));
   ll ans = 0;
   if (MIN * 2 <= D) ans = N * MIN;
   else {
      ans = (N / 2) * D + (N % 2) * MIN;
   }
   cout << ans << endl;
   return 0;
}


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


using namespace std;
#define ll long long
#define ld long double
#define  P pair<ll,ll>
#define FOR(i,n,m) for(ll i=n; i<(ll)m;i++)
#define FORr(i,m,n) for(ll i=n; i>=(ll)m; i--)
#define FORm(i,m) for(auto i=m.begin();i!=m.end();i++)
#define sortAl(v) sort(v.begin(),v.end())
#define sortAlr(v) sort(v.begin(),v.end()); reverse(v.begin(),v.end())
#define cout(n) cout<<fixed<<setprecision(n)

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

    ll n,m;
    cin>>n>>m;
    vector<ll> v(n+1);
    FOR(i,0,m){
      ll in1,in2;
      cin>>in1>>in2;
      v[in1-1]++;
      v[in2]--;
    }
    FOR(i,1,n+1){
      v[i]+=v[i-1];
    }

    ll ans=0;
    FOR(i,0,n+1){
      if(v[i]==m)ans++;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<string>
#include<vector>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
const long long mod = 1e9 + 7;

int main(){
   int n;
   cin >> n;
   vector<int> a(n+1);
   rep(i, n) cin >> a[i+1];
   vector<int> b(n+1);
   for(int i = n; i>=1; i--){
        int sum = 0;
        for(int j = i+i; j<=n; j+=i){
             sum^=b[j];
        }
        b[i] = sum^a[i];
   }  
   vector<int> ans;
   for(int i = 1; i<=n; i++){
        if(b[i]) ans.push_back(i);
   }
   cout << ans.size() << endl;
   rep(i, ans.size()){
        cout << ans[i] << " ";
        if(i == ans.size()) cout << endl;
   }
}

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <string>
#include <set>
#include <bitset>
#include <unordered_map>
#include <cmath>

using namespace std;
using ll = long long;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;
template <class T>
using Vvec = vector<vector<T> >;

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

    for(int i=0; i<=N; i++){
        if(floor(1.08*i) == N){
            cout << i << endl; return 0;
        }
    }
    
    cout << ":(\n"; return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define CEVCOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define P pair<int , int>
#define V vector<int>
#define M map<int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void){

	ios::sync_with_stdio(false);
	int N;	cin >> N;
	V a(N + 1);
	for(int i = 1 ; i <= N ; i++)
		 cin >> a[i];

	int m = 0;	V b(N + 1);
	for(int i = N ; 1 <= i ; i--){
		int sum = 0, keep = i * 2;
		while(keep <= N){
		 	sum += b[keep];
			keep += i;
		}

		if(sum % 2 != a[i]){
		 	b[i] += 1;
			m += 1;
		}
	}

	SCOUT(m) << endl;;
	for(int i = 1 ; i <= N ; i++)
	 	if(b[i] > 0)	SCOUT(i) << " ";

	cout << endl;


    return 0;
}


Measured memory_bytes: 2688
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
using namespace std;

int main(){
    long long int a,b=0;
    cin>>a;
    b=2*((a-1)/11)+1;
    if((a-1)%11>=6){
        b++;
    }
    cout<<b<<endl;
    return 0;
}


Measured memory_bytes: 3528
S=str(input())
N=len(S)

#S=[]
#for i in range(N):
#  S.append(int(S_input[i]))

#1から始める場合
res1=0
for i in range(N):
  if (int(S[i]) % 2) == (i % 2):
    res1+=1
#0から始める場合
res0=N-res1

print(min(res0,res1))

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <cstdio>
#include <queue>
#include <vector>
#include <string>
#include<iostream>
#include<cstdio>
#include<iomanip>
#define rep(i,m,n) for(i = (m); i < (n); i++)
#define print(x) cout << (x) << endl;
using std::cout;
using std::cin;
using std::endl;
using namespace std;

//coffeemilk_8610

int main() {
  int a,b,r,D,ans,i;
  cin>>r>>D>>a;
  b=a;
  rep(i ,2001,2011){
    a=r*b-D;
    b=a;
    cout<<b<<endl;
  }
  return 0;
}

Measured memory_bytes: 256
using System;
class Program{
	static void Main(){
		string s=Console.ReadLine();
		long k=long.Parse(Console.ReadLine());
		int a=0;
		for(int i=0;i<s.Length&&i<k;i++){
			if(s[i]!='1'){a=s[i]-'0';break;}
			else if(i==k-1){a=1;}
		}
		Console.WriteLine("{0}",a);
	}
}

Measured memory_bytes: 13140
#include <bits/stdc++.h>
#define ll long long
#define pb(x) push_back((x))
#define line() cerr << "DEBUG @" << __LINE__ << endl;
#define debug(x) \
    cerr << "DEBUG @" << __LINE__ << " -> " << #x << " = " << x << endl;
using namespace std;

const int MAX = 1e6;
int v[MAX], divisors[MAX + 1], m[MAX + 1];

int main() {
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) scanf("%d", &v[i]);
    for (int i = 2; i <= MAX; i++) {
        if (!divisors[i]) {
            for (int j = i; j <= MAX; j += i) {
                divisors[j] = i;
            }
        }
    }
    bool pair_wise_coprime = true;
    bool gcd_is_one = true;

    for (int i = 0; i < n; i++) {
        int x = v[i];
        int cur = x;
        set<int> q;
        while (cur != 1) {
            q.insert(divisors[cur]);
            cur /= divisors[cur];
        }
        for (int div : q) {
            m[div]++;
            if (m[div] > 1) pair_wise_coprime = false;
            if (m[div] == n) gcd_is_one = false;
        }
    }
    if (pair_wise_coprime) {
        puts("pairwise coprime");
        return 0;
    }
    if (gcd_is_one) {
        puts("setwise coprime");
        return 0;
    }
    puts("not coprime");
}


Measured memory_bytes: 15380
n=int(input())
a=list(map(int,input().split()))

def cnt_div2(n):
    cnt=0
    while n%2==0:
        n//=2
        cnt+=1
    return cnt

#各要素に対して，2で割ることのできる回数をカウント
lis = [cnt_div2(i) for i in a]
print(sum(lis))

Measured memory_bytes: 41964
use std::io::stdin;

fn main() {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    let n: usize = s.trim().parse().ok().unwrap();
    s = String::new();
    stdin().read_line(&mut s).ok();
    let hs: Vec<u32> = s.trim().split_whitespace().map(|token| token.parse().ok().unwrap()).collect();

    let mut sum = 0;
    let max = *(hs.iter().max().unwrap());
    for m in (1..max + 1).rev() {
        let mut tmp = 0;
        for i in 0..n {
            if hs[i] >= m && (i == 0 || hs[i - 1] < m) {
                    tmp = tmp + 1;
            }
        }
        sum = sum + tmp;
    }
    print!("{}", sum);
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> l_l;
const int INF=1001001000;
const int mINF=-1001001000;
int main(){
    int n;cin >> n;
    vector<int> L(n);
    for(int i=0; i<n; i++) cin >> L[i];
    int ans=0;
    sort(L.begin(),L.end());
    for(int a=0; a<n-1; a++){
        for(int b=a+1; b<n; b++){
            int ab=L[a]+L[b];
            int right=lower_bound(L.begin(),L.end(),ab)-L.begin();
            int left=b+1;
            ans+=right-left;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    long long N, A, B, X, n, a;
    scanf("%lld%lld%lld", &N, &A, &B);
    if (A==0) {
        printf("0");
        return 0;
    }
    a=N/(A+B);
    X=A*a; n=(A+B)*a;
    N-=n;
    // printf("%lld\n", N);
    if (A>N) X+=N;
    else X+=A;
    printf("%lld", X);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
#define pp pop_back

const int P = 1000000007;
const int N = 202020;
const int B = 62;

using namespace std;


int n, fst[B+1][N];
ll k;

int main(){

	cin >> n >> k;
	for(int i=1; i<=n; i++) cin >> fst[0][i];
	for(int b=1; b<=B; b++){
		for(int i=1; i<=n; i++) fst[b][i] = fst[b-1][fst[b-1][i]];
	}

	int ans = 1;
	for(int b=B; b>=0; b--) if((k>>b)&1) ans = fst[b][ans];
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 53116
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
constexpr ll INF = 1e18;
constexpr double PI = 3.14159265358979;

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

  long long h, w, a, b;
  cin >> h >> w >> a >> b;
  if(h-b < b or w-a < a){
    cout << "No\n";
    return 0;
  }
  int c = 0;
  for(int i = 0; i < h; i++){
    if(i == b) c ^= 1;
    for(int j = 0; j < w; j++){
      if(j == a) c ^= 1;
      cout << c;
    }
    cout << endl;
    c ^= 1;
  }
  return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, a[26] = {}, b[5] = {};
    ll z = 0;
    string s;
    cin >> n;
    for (int i = 0; i < n; i++) cin >> s, a[s[0] - 'A']++;
    b[0] = a[0]; b[1] = a[2]; b[2] = a[7]; b[3] = a[12]; b[4] = a[17];
    for (int i = 0; i < 5; i++) for (int j = 0; j < i; j++) for (int k = 0; k < j; k++) z += 1ll * b[i] * b[j] * b[k];
    cout << z;
}


Measured memory_bytes: 636
use proconio::*;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
use std::*;

#[allow(dead_code)]
const MOD: i128 = 100_000_007;

#[fastout]
fn main() {
    input!{
        s : String
    }
    let ans = if s == "ABC" {
        "ARC"
    } else {
        "ABC"
    };
    println!("{}",ans);
}


Measured memory_bytes: 2152
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <math.h>
#include <algorithm>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define LL long long
#define mass 1000000007
using namespace std;
ll factmass(ll n){
	ll a=1;
	rep(i,n){
		a=a*(i+1)%mass;
	}
	return a;
}


int main(){
	
	ll n,m;
	cin>>n>>m;
	
	if(n==m){
		ll x=factmass(n);
		cout<<(2*x*x)%mass<<endl;
	}else if(n==m+1 || m==n+1){
		n=min(n,m);
		ll x=factmass(n);
		cout<<((n+1)*x)%mass*x%mass<<endl;
	}else{
		cout<<0<<endl;
	}
	
	return 0;

}


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

int main(){
    int n;
    cin >> n;
    int ans=1e9;
    for(int i = 1; i <= n/2+1; i++)
    {
        int num=0, a=i, b=n-i;
        while(a>0){
            num += a%10;
            a /= 10;
        }
        while(b>0){
            num += b%10;
            b /= 10;
        }
        ans = min(ans, num);        
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

const int INF = (1 << 28);

int minimum_steiner_tree(const vector<int>& T, const vector<vector<int> > &g) {
  const int INF = (1 << 28);
  const int n = g.size();
  const int numT = T.size();
  if (numT <= 1) return 0;
  
  vector<vector<int> > d(g); // all-pair shortest
  //should be d[i][i] = 0
  for (int k = 0; k < n; ++k)
    for (int i = 0; i < n; ++i)
      for (int j = 0; j < n; ++j)
        d[i][j] = min( d[i][j], d[i][k] + d[k][j] );

  int OPT[(1 << numT)][n];
  for (int S = 0; S < (1 << numT); ++S)
    for (int x = 0; x < n; ++x)
      OPT[S][x] = INF;

  for (int p = 0; p < numT; ++p) // trivial case
    for (int q = 0; q < n; ++q)
      OPT[1 << p][q] = d[T[p]][q];

  for (int S = 1; S < (1 << numT); ++S) { // DP step
    if (!(S & (S-1))) continue;
    for (int p = 0; p < n; ++p)
      for (int E = 0; E < S; ++E)
        if ((E | S) == S)
          OPT[S][p] = min( OPT[S][p], OPT[E][p] + OPT[S-E][p] );
    for (int p = 0; p < n; ++p)
      for (int q = 0; q < n; ++q)
        OPT[S][p] = min( OPT[S][p], OPT[S][q] + d[p][q] );
  }
  int ans = INF;
  for (int S = 0; S < (1 << numT); ++S)
    for (int q = 0; q < n; ++q)
      ans = min(ans, OPT[S][q] + OPT[((1 << numT)-1)-S][q]);
  return ans;
}

main(){
  int h, w;
  while(cin >> h >> w && (h|w)){
    vector<int> T;
    char dat[12][12];
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> dat[i][j];
        if(dat[i][j] == '1'){
          T.push_back(i * w + j);
        }
      }
    }
    vector<vector<int> > g;
    g.resize(h*w);
    for(int i=0;i<g.size();i++) g[i].resize(h*w);
    for(int i=0;i<g.size();i++) for(int j=0;j<g[i].size();j++) g[i][j] = INF;
    static const int dy[4] = {-1, 0, 1, 0};
    static const int dx[4] = {0, 1, 0, -1};
    for(int i=0;i<h*w;i++){
      g[i][i] = 0;
      for(int j=0;j<4;j++){
        int ny = i / w + dy[j];
        int nx = i % w + dx[j];
        if(ny < 0 || ny >= h) continue;
        if(nx < 0 || nx >= w) continue;
        g[i][ny*w+nx] = g[ny*w+nx][i] = 1;
      }
    }
    int ans = minimum_steiner_tree(T, g);
    cout << h * w - ans - 1 << endl;
  }
}

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

#define int long long
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; }

signed main(){
	int n;
	cin >> n;


	vector<int> a(n);

	if(n == 3){
		cout << 2 << " " << 3 << " " << 25 << endl;
		return 0;
	}

	int ans = 2+3;
	a[0] = 2;
	a[1] = 3;
	int used[30010] = {};
	used[2] = used[3] = 1;
	int i = 4;
	for(int ii = 2;ii < n-1;ii++){
		while(1){
			if(used[i] == 0 && (i % 2 == 0 || i % 3 == 0)) break;
			i++;
		}
		a[ii] = i;
		ans += a[ii];
		used[a[ii]]++;
	}

	int atmp[30010] = {};
	int go = 0;
	for(int i = 0;i < n-1;i++){
		bool f = false;
		for(int j = 2;j*j <= a[i];j++){
			if(a[i] % j == 0){
				f = true;
				break;
			}
		}
		if(f) continue;
		go++;
		int tmp = ans-a[i];
		for(int j = 0;j <= 30000;j++){
			if(__gcd(tmp+j, a[i]) != 1 && __gcd(ans, j) != 1) atmp[j]++;
		}
	}

	for(int i = 2;i <= 30000;i++){
		if(used[i] == 0 && atmp[i] == go){
			for(int i = 0;i < n-1;i++){
				cout << a[i] << " ";
			}
			cout << i << endl;
			return 0;
		}
	}
	return 0;
}


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

string nchar(int l, char c) {
	string s(l, c);
	return s;
}

void solve(long long sx, long long sy, long long tx, long long ty){
	long long w = tx - sx, h = ty - sy;
	cout << nchar(h, 'U') << nchar(w, 'R')  << nchar(h, 'D') << nchar(w, 'L');
	cout << "L" << nchar(h + 1,'U') << nchar(w + 1, 'R') << "DR" << nchar(h + 1,'D') << nchar(w + 1, 'L') << "U" << endl;
}

int main(){	
	long long sy;
	long long tx;
	long long sx;
	long long ty;
	scanf("%lld",&sx);
	scanf("%lld",&sy);
	scanf("%lld",&tx);
	scanf("%lld",&ty);
	solve(sx, sy, tx, ty);
	return 0;
}



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

int main(){
  string s;
  cin>>s;
  for(int i=0;i<4;i++)cout<<s[i];
  cout<<' ';
  for(int i=4;i<12;i++)cout<<s[i];
  cout<<endl;
  return 0;
}


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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

int n,W,H;
int r[111111],c[111111];
bool rok=true,cok=true;

int main(){
	cin.sync_with_stdio(false);
	cin>>n>>W>>H;
	rep(i,n){
		int x,y,w;
		cin>>x>>y>>w;
		r[max(0,y-w)]++;
		r[min(H,y+w)]--;
		c[max(0,x-w)]++;
		c[min(W,x+w)]--;
	}
	rep(i,111110){
		r[i+1]+=r[i];
		c[i+1]+=c[i];
	}
	rep(i,H){
		if(r[i]==0){
			rok=false;
		}
	}
	rep(i,W){
		if(c[i]==0){
			cok=false;
		}
	}
	if(rok||cok)cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 4076