akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rrep(i,n) for (int i = (n)-1; i >= 0; i--)
#define rep2(i,s,n) for (int i = (s); i < (n); ++i)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define pb push_back
#define eb emplace_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vd vector<double>
#define vs vector<string>
#define vc vector<char>
#define vb vector<bool>
#define vp vector<P>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using LP = pair<ll,ll>;
template<class S,class T> istream& operator>>(istream &is,pair<S,T> &p) { return is >> p.first >> p.second; }
template<class S,class T> ostream& operator<<(ostream &os,const pair<S,T> &p) { return os<<'{'<<p.first<<","<<p.second<<'}'; }
template<class T> istream& operator>>(istream &is,vector<T> &v) { for(T &t:v){is>>t;} return is; }
template<class T> ostream& operator<<(ostream &os,const vector<T> &v) { os<<'[';rep(i,v.size())os<<v[i]<<(i==v.size()-1?']':','); return os; }
void Yes(bool b) { cout << (b ? "Yes" : "No") << endl; }
void YES(bool b) { cout << (b ? "YES" : "NO") << endl; }
template<class T> bool chmin(T& a,T b) {if(a > b){a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b) {if(a < b){a = b; return true;} return false;}
const int inf = 1001001001;
const ll linf = 1001001001001001001;

int dp[3100][3100][2];

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr); cout.tie(nullptr);
    int n,t;
    cin >> n >> t;
    vi a(n),b(n);
    rep(i,n) cin >> a[i] >> b[i];
    rep(i,n) rep(j,t) rep(k,2) {
        chmax(dp[i+1][j][k],dp[i][j][k]);
        if(j+a[i] < t) chmax(dp[i+1][j+a[i]][k],dp[i][j][k]+b[i]);
        if(!k) chmax(dp[i+1][j][1],dp[i][j][k]+b[i]);
    }
    int ans = 0;
    rep(i,t) rep(j,2) chmax(ans,dp[n][i][j]);
    cout << ans << endl;
}


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

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,1,-1};
bool seen[50][50];
int G[50][50];

void dfs(int x,int y,int h,int w){
    seen[x][y]=true;

    rep(i,8){
        int nx=x+dx[i];
        int ny=y+dy[i];
        if(nx<0||nx>h-1||ny<0||ny>w-1)continue;
        if(seen[nx][ny])continue;
        if(G[nx][ny]==0)continue;
        dfs(nx,ny,h,w);
    }
}

int main(){
    while(1){
        int h,w;
        int ans=0;
        cin>>w>>h;
        if(w==0&&h==0)break;
        rep(i,h)rep(j,w)cin>>G[i][j];
        rep(i,50)rep(j,50)seen[i][j]=false;
        rep(i,h)rep(j,w){
            if(seen[i][j]==false&&G[i][j]==1){
                ans++;
                dfs(i,j,h,w);
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}


Measured memory_bytes: 3216
#include<bits/stdc++.h>
using namespace std;
int n,atleast;
struct mis{
	int t;
	int atl;
};
bool cmp(mis a,mis b){
	return a.atl<b.atl;
}
mis a[2000005];
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i].t>>a[i].atl;
	}
	sort(a,a+n,cmp);
	atleast=a[n-1].atl-a[n-1].t;
	for(int i=n-2;i>=0;i--){
		if(atleast<a[i].atl){
			a[i].atl=atleast;
		}
		else atleast=a[i].atl;
		atleast-=a[i].t;
	}
	if(atleast>=0){
		cout<<"Yes";
	}
	else cout<<"No";
	return 0;
}

Measured memory_bytes: 1792
N, M = map(int, input().split())
r = [[] * N for i in range(N)]
reached = [0] * N
reached[0] = 1
count = 0

def dfs(now, pre):
    global count
    if all(reached):
        count += 1
    for next in r[now]:
        if next != pre:
            if reached[next] == 0:
                reached[next] = 1
                dfs(next, now)
                reached[next] = 0

for i in range(M):
    a, b = map(lambda x: int(x) - 1, input().split())
    r[a].append(b)
    r[b].append(a)

dfs(0, -1)

print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long w,a,b;
  cin>>w>>a>>b;
  if(a+w<b){
    cout<<b-(a+w)<<endl;
  }
  else if(b+w<a){
    cout<<a-(b+w)<<endl;
  }
  else{
    cout<<0<<endl;
  }
  return 0;
}

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

#define rep(i, a) for (int i = 0; i < (a); i++ )
#define FOR(i, m, n) for(int i = m; i < n; i++)
 
typedef pair<int,int> P;
typedef long long ll;
 
const int INF = 1001001001;
const int MOD = 1000000007;
const double PI=acos(-1);

int main(){
    string s,t;
    cin >> s >> t;

    int ans = 0;

    rep(i,s.size()) {
        if (s[i]!=t[i]) ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3856
using System;
using System.Collections.Generic;
using System.Linq;

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int n = cin.nextInt();
        int[] p = cin.arrayInt();
        int ans = 0;

        for (int i = 1; i < n - 1; i++)
        {
            if (p[i] > p[i - 1] && p[i] < p[i + 1])
            {
                ans++;
            }
            if (p[i] < p[i - 1] && p[i] > p[i + 1])
            {
                ans++;
            }
        }

        Console.WriteLine(ans);
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

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

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



Measured memory_bytes: 11092
/*
                    Author: Ankit Kaul
    **********************Code Belongs to Respective Author Only************************************
    */
    /*#pragma GCC optimize("O3")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("unroll-loops")
    #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")*/
    #include <bits/stdc++.h>
    #define endl       '\n'
    #define PI          3.141592653589
    #define jaldi       ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    #define M           1000000007
    #define int         long long int
    #define inf         INT_MAX
    #define pb          emplace_back
    #define pf          emplace_front
    #define pii         pair<int,int>
    #define vi          vector<int>
    #define vii         vector<pii>
    #define mi          map<int,int>
    #define mii         map<pii,int>
    #define all(a)      (a).begin(),(a).end()
    #define rall(a)     (a).rbegin(),(a).rend()
    using namespace std;
    int gcd(int a,int b) { return b == 0 ? a : gcd(b, a % b); }
    int power(int x,int n){
        int result=1;
        while(n>0)
        {   if(n % 2 ==1)
            result=(result * x) % M;
            x=(x*x)% M;
            n=n/2;
        }
    return result % M;
    }      
    bool isPrime(int n) 
    { 
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
    if (n % 2 == 0 || n % 3 == 0) 
        return false; 
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
    return true; 
    } 
    signed main()
    {   jaldi
        int n;
        cin>>n;
        int a[n],i;
        for(i=0;i<n;i++)
        cin>>a[i];
        bool x=true;
        for(i=0;i<n;i++)
        {   if(a[i]%2==0)
            {   if(a[i]%3!=0 && a[i]%5!=0)
                x=false;
            }
        }
        if(x)
        cout<<"APPROVED";
        else
        cout<<"DENIED";
    }   


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
using namespace std;
const ll mod=1e9+7;
const int maxn=2e5+10;
ll fac[maxn],inv[maxn];
vector <int> G[maxn];
struct node
{
    int sz,cs;
}a[maxn];

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

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

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

void dfs(int x,int fa,int cs)
{
    a[x].cs=cs;
    for(int i=0;i<G[x].size();i++)
    {
        int v=G[x][i];
        if(v==fa) continue;
        dfs(v,x,cs+1);
        a[x].sz++;
    }
}

int main()
{
    init(100001);
    int n,u,v;
    ll k;
    scanf("%d%lld",&n,&k);
    for(int i=1;i<n;i++)
    {
        scanf("%d%d",&u,&v);
        G[u].push_back(v);
        G[v].push_back(u);
    }

    dfs(1,0,1);
    ll ans=k;
    //cout<<ans<<endl;
    for(int i=1;i<=n;i++)
    {
        if(a[i].cs==1)
        {
            ans=ans*A(k-1,a[i].sz)%mod;
           // cout<<A(k-1,a[i].sz)<<endl;
        }
        else
        {
            ans=ans*A(k-2,a[i].sz)%mod;
            //cout<<A(k-2,a[i].sz)<<endl;
        }
    }
    ans%=mod;
    printf("%lld\n",ans);
    return 0;
}


Measured memory_bytes: 17024
#include <iostream>
#include <sstream>
#include <fstream>
#include <complex>
#include <ctime>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <cmath>
#include <algorithm>
#include <functional>
#include <numeric>
#include <complex>

using namespace std;

template<typename T> ostream& operator<<(ostream& os, const vector<T>& v){
    os << "{ ";
    for (typename vector<T>::const_iterator it = v.begin(); it != v.end(); ++it)
        os << '\"' << *it << '\"' << (it + 1 == v.end() ? "" : ", ");
    os << " }";
    return os;
}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
#define vv(type,w,h,init) vector<vector<type>>(h,vector<type>(w,init))
typedef vector<string> vs;
typedef long long ll;
typedef unsigned uint;
typedef unsigned long ul;
typedef unsigned long long ull;

#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define loop(i,a,b) for(int i=(a); i<(int)(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define mp make_pair


typedef complex<int> P;

int main(){
    int n;
    while (cin >> n, n){
        P ps[100];
        bool vis[30][30] = {};
        rep(i, n){
            int x, y;
            cin >> x >> y;
            ps[i] = P(x, y);
        }
        int m; cin >> m;

        P dir[256] = {};
        dir['N'] = P(0, 1);
        dir['W'] = P(-1, 0);
        dir['E'] = P(1, 0);
        dir['S'] = P(0, -1);

        vis[10][10] = true;
        P cur(10, 10);
        rep(i, m){
            char c; int d;
            cin >> c >> d;
            rep(i, d){
                cur += dir[c];
                vis[cur.imag()][cur.real()] = true;
            }
        }

        bool ans = true;
        rep(i, n){
            if (!vis[ps[i].imag()][ps[i].real()]) ans = false;
        }
        cout << (ans ? "Yes" : "No") << endl;
    }
}

Measured memory_bytes: 1152
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N;
  cin>>N;
  map<int, int> amap;
  for(int x=1;x<=100;++x) {
    for(int y=1;y<=100;++y) {
      for(int z=1;z<=100;++z) {
        amap[pow(x, 2)+pow(y, 2)+pow(z, 2)+x*y+y*z+z*x]++;
      }
    }
  }
  for(int i=1;i<=N;++i) cout<<amap[i]<<endl;
}



Measured memory_bytes: 5340
#include <iostream>
#include <cmath>
using namespace std;
int cost(int h[],int n){
    int costdp[n+1];
    costdp[0]=0;
    costdp[1]=0;
    costdp[2]=abs(h[1]-h[0]);
    for(int i=3;i<=n;i++){
        costdp[i]=min((costdp[i-2]+abs(h[i-1]-h[i-3])), (costdp[i-1]+abs(h[i-1]-h[i-2])));
    }
    return costdp[n];
}
int main() {
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    cout<<cost(h,n)<<endl;
    
}

  


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

int main()
{
    int a,b,c,k,zb,mx;
    cin >> a >> b >> c;
    cin >> k;

    if(a>=b&&a>=c)
        for (int i=0;i<k;i++)
            a*=2;
    else if(b>=a&&b>=c)
        for (int i=0;i<k;i++)
            b*=2;
    else if(c>=a&&c>=b)
        for (int i=0;i<k;i++)
            c*=2;
    cout << a+b+c;
    return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()
	mlist := make([]int, n+1)
	for i := 0; i < n+1; i++ {
		mlist[i] = nextInt()
	}

	ans := 0
	for i := 0; i < n; i++ {
		s := nextInt()

		// iから倒せるだけ倒す
		if mlist[i] < s {
			// iを倒しきれる場合
			ans += mlist[i]
			s -= mlist[i]
			mlist[i] = 0
		} else {
			// iのモンスタ数がsより多い
			ans += s
			mlist[i] -= s
			s = 0
		}

		// i+1から倒せるだけ倒す
		if 0 < s {
			if mlist[i+1] < s {
				// i+1さえも倒しきれる場合
				ans += mlist[i+1]
				mlist[i+1] = 0
			} else {
				// さすがに倒し切れない場合
				ans += s
				mlist[i+1] -= s
			}
		}

	}

	fmt.Println(ans)
}

// ---- readfunc
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 5856
#include <stdio.h>
int main(){

  int w,a,b,blank;

  scanf("%d %d %d",&w,&a,&b);

  if(a > b){

    blank=a;
    a=b;
    b=blank;

  }

  if(b-a-w > 0) printf("%d\n",b-a-w);
  else printf("0\n");

  return 0;

}


Measured memory_bytes: 128
#include<iostream>
#define INF 2000000000;
void merge(int*,int,int,int);
void mergeSort(int*,int,int);
int cnt=0;
int main(){
  int n;
  std::cin>>n;
  int A[n];
  for(int i=0;i<n;i++) std::cin>>A[i];
  mergeSort(A,0,n);
  for(int i=0;i<n;i++){
    std::cout<<A[i];
    if(i!=n-1) std::cout<<" ";
  }
  std::cout<<"\n"<<cnt<<"\n";
  return 0;
}
void merge(int *A,int l,int m,int r){
  int n1=m-l,n2=r-m, i, j;
  int L[n1+1];
  int R[n2+1];
  for(i=0;i<n1;i++) L[i]=A[l+i];
  for(i=0;i<n2;i++) R[i]=A[m+i];
  L[n1]=R[n2]=INF;
  i=j=0;
  for(int k=l;k<r;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i=i+1;
      cnt++;
    }
    else{
      A[k]=R[j];
      j=j+1;
      cnt++;
    }
  }
}
void mergeSort(int *A,int l,int r){
  int m;
  if(l+1<r){
    m=(l+r)/2;
    mergeSort(A,l,m);
    mergeSort(A,m,r);
    merge(A,l,m,r);
  }
}

Measured memory_bytes: 6972
#include "iostream"
#include "random"
#include "string"
#include "bitset"
#include "algorithm"
#include "map"
#include "queue"
#include "list"
#include "set"
#include "climits"
#include "iomanip"
#include "stack"
#include "functional"
#include "unordered_map"
#include "unordered_set"

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

int x[100];
int a[10], b[10], c[10];
bool dp[100][100][10];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> x[i];
	int M;
	cin >> M;
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i] >> c[i];
		b[i]--; c[i]--;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++) {
			dp[i][i][j] = (x[i] == a[j]);
		}
	}
	for (int len = 2; len <= N; len++) {
		for (int i = 0; i + len <= N; i++) {
			for (int j = 0; j < M; j++) {
				for (int k = 1; k < len; k++) {
					dp[i][i + len - 1][j] |= (dp[i][i + k - 1][b[j]] && dp[i + k][i + len - 1][c[j]]);
				}
			}
		}
	}
	if (dp[0][N - 1][0]) cout << "Yes" << endl;
	else cout << "No" << endl;
}


Measured memory_bytes: 3308
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
#include <set>
#include <map>
#include <climits>
#include <utility>
#include <deque>
#include <list>
#include <stdexcept>
using namespace std;

#define ll long long
#define IN(type, name) type name; cin >> name
#define IN_V(type, name, size) vector<type> name(size); for(auto& x: name) cin >> x
#define IN_VPair(type1, type2, name, size) vector<pair<type1, type2>> name(size); for(auto& x: name) cin >> x.first >> x.second
#define IN_VW(type, name, size) vector<type> name(size); for(auto& x: name)

#define REP(name, start, end) for(ll name = (start); (name) < (end); ++(name))
#define ALL(iterable) (iterable).begin(), (iterable).end()

int main()
{
	cout << fixed << setprecision(6);
	IN(ll, n);
	IN(ll, k);
	IN_V(ll, hls, n);
	vector<ll> cost_dp(n);

	cost_dp[0] = 0;
	REP(i, 1, n) {
		auto cost_min = LLONG_MAX;
		REP(j, 1, k + 1) {
			if (i - j < 0) break;
			auto cost = cost_dp[i - j] + abs(hls[i] - hls[i - j]);
			if (cost < cost_min)cost_min = cost;
		}
		cost_dp[i] = cost_min;
	}

	cout << cost_dp[n - 1] << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>

using namespace std;

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

#define PI acos(-1.0)
#define INF 1000000007
#define EPS 1e-10
#define MAX_M 100100

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;
typedef pair<P, char> PC;

string s;

int changei(string s){
	int res;
	stringstream ss;
	ss << s;
	ss >> res;
	return res;
}

bool check(string s1, string s2, string s3){
	int p = 0;
	int size = s1.size();
	for (int i = 0; i < size; i++){
		if ((s1[i] - '0' + s2[i] - '0' + p) % 10 != s3[i] - '0'){
			return false;
		}
		else{
			p = (s1[i] - '0' + s2[i] - '0' + p) / 10;
		}
	}

	return true;
}

int main(){
	//ofstream cout("out.txt");
	//for (int i = 0; i < 61; i++){
	//	cout << 1;
	//}
	//cout << endl;
	while (cin >> s){
		bool f = 1;
		int wide1, wide2;
		REP(i, s.size()){
			if (s[i] == '+')wide1 = i;
			else if (s[i] == '=')wide2 = i - wide1 - 1;
		}
		REP(i, 10){
			string t1 = s.substr(0, wide1), t2 = s.substr(wide1 + 1, wide2),
				t3 = s.substr(wide1 + wide2 + 2, s.size() - wide1 - wide2);
			if (i == 0){
				if (t1[0] == 'X'&&t1.size() >= 2)continue;
				if (t2[0] == 'X'&&t2.size() >= 2)continue;
			}
			REP(j, t1.size()){
				if (t1[j] == 'X')t1[j] = (char)('0' + i);
			}
			REP(j, t2.size()){
				if (t2[j] == 'X')t2[j] = (char)('0' + i);
			}
			REP(j, t3.size()){
				if (t3[j] == 'X')t3[j] = (char)('0' + i);
			}
			reverse(ALL(t1));
			reverse(ALL(t2));
			reverse(ALL(t3));
			t3 += '0';
			while (t3.size() > t1.size())t1 += '0';
			while (t3.size() > t2.size())t2 += '0';
			//cout << t1 << " " << t2 << " " << t3 << endl;
			if (check(t1, t2, t3)){
				if (f)cout << i << endl;
				f = 0;
			}
		}
		if(f)cout << "NA" << endl;
	}
}

Measured memory_bytes: 1196
#include <bits/stdc++.h>
#define ALL(obj) begin(obj), end(obj)
#define debug(x) cerr << #x << ": " << x << '\n'
using namespace std;
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
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;
}

using ll = long long;
using ull = unsigned long long;
const int INF = 2100100100;
// const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    set<char> s;
    for (int i = 0; i < N; i++) {
        char c;
        cin >> c;
        s.insert(c);
    }
    if ((int)s.size() == 3) {
        cout << "Three\n";
    } else {
        cout << "Four\n";
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int f[1000];
main(){
    int n;
    //7+13+
    cin >> n;
    if (n == 3) {cout <<"2 5 63"<<endl; return 0;}
    if(n == 4) {cout <<"2 5 20 63" << endl; return 0;}
int x;
    if (n == 6) {cout <<"2 4 6 3 9 24" << endl; return 0;}
    if(n == 19999) {cout <<"11 55 77 121 143 187 209 253 "; n-=8; }
    for (x= 3; x<= 15000; x+=3){
        if((n-x)%2 == 0 && n-x <= 5000 && n-x >0) break;
    }
    int y = n-x;
    int  S = 0;
    for (int i= 2; i <= 2*x; i+=2)
        cout << i <<" ", S+=i;
    for (int j = 3; j < 6*y+3; j+=6)
        cout << j <<" ",S+=j;
 //       cout << S << endl;
    cout << endl;
}

//


Measured memory_bytes: 384
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let N: usize = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    };
    let d: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let ans = (0..(N - 1)).map(|i| ((i + 1)..N).map(|j| d[i] * d[j]).sum::<i64>()).sum::<i64>();

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


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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;

template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	os << v[0];
	for (int i = 1; i < v.size(); i++) os << " " << v[i];
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u; return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	string S; cin >> S;
	int cnt = 0;
	for (int i = 0; i < S.size(); i++) {
		//新たなmewを作る
		if (S[i] == 'm') {
			if (i > 0 && S[i-1] == 'w') { cout << "Rabbit" << el; return; }
			cnt++;
		}
		if (S[i] == 'e') {
			if (i == 0 || S[i-1] == 'e') { cout << "Rabbit" << el; return; }
		}
		if (S[i] == 'w') {
			if (i == 0 || S[i-1] == 'm') { cout << "Rabbit" << el; return; }
			cnt--;
		}
	}
	if (cnt == 0) {
		cout << "Cat" << el;
	} else {
		cout << "Rabbit" << el;
	}
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}




Measured memory_bytes: 3208
def e_travel_by_car(INF=float('inf')):
    from copy import deepcopy
    from scipy.sparse.csgraph import floyd_warshall
    N, M, L = [int(i) for i in input().split()]
    Roads = [[int(i) for i in input().split()] for j in range(M)]
    Q = int(input())
    Queries = [[int(i) for i in input().split()] for j in range(Q)]

    graph = [[INF] * i + [0] + [INF] * (N - i - 1) for i in range(N)]
    fuel = deepcopy(graph)

    for a, b, c in Roads:
        graph[a - 1][b - 1] = graph[b - 1][a - 1] = c
    dist = floyd_warshall(graph)

    for row in range(N):
        for col in range(row):
            fuel[row][col] = fuel[col][row] = int(dist[row][col] <= L)
    fuel = floyd_warshall(fuel)

    ans = [-1 if fuel[s - 1][t - 1] == INF else int(fuel[s - 1][t - 1]) - 1
           for s, t in Queries]
    return '\n'.join(map(str, ans))

print(e_travel_by_car())

Measured memory_bytes: 41676
#include<bits/stdc++.h>
using namespace std;
#define LL long long
const int N = 2e5 + 10;
int n, c[N], cnt[N], siz[N];
	inline LL cal(int n) {
		// C(n,2) + n
		return 1LL*n*(n+1)/2;
	}
LL ans[N];
vector<int>G[N];
	void dfs(int v, int fa) {
		int tmp = cnt[c[v]];
		siz[v] = 1;
		for(int u:G[v]) {
			if(u==fa) continue;
			cnt[c[v]] = 0;
			dfs(u, v);
			siz[v] += siz[u];
			ans[c[v]]+=cal(siz[u]-cnt[c[v]]);
		}
		cnt[c[v]] = tmp + siz[v];
	}
int main() {
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		//scanf("%d", &c[i]);
		cin>>c[i];
	for (int i = 1; i < n; i++) {
		int u, v;
		//scanf("%d%d", &u, &v);
		cin>>u>>v;
		G[u].push_back(v);
		G[v].push_back(u);
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++) {
		printf("%lld\n", cal(n) - ans[i] - cal(n - cnt[i]));
	}
	return 0;
}


Measured memory_bytes: 37292
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); i ++)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> PL;
typedef pair<int,int> P;
const ll INF = ((1LL)<<31) - 1LL;
const int MOD = 1e9 + 7;
const vector<int> dy = {-1,0,1,0};
const vector<int> dx = {0,1,0,-1};

template <class Monoid> class SegmentTree{
    int N;
    Monoid unit;
    vector<Monoid> tree;
    using FX = function<Monoid(Monoid,Monoid)>;
    FX func;
    
    public:

    void _build(vector<Monoid> &array){
        for (int i = N; i < 2*N; i++) tree[i] = array[i - N];
        for (int i = N - 1;i >= 0; i--) tree[i] = func(tree[i << 1],tree[i << 1|1]);
    }

    SegmentTree(int _N,Monoid _unit,FX _func) :N(_N),unit(_unit),func(_func),tree(2*N,unit) {
        //_build(array);
    }

    void update(int K,Monoid x){
        K += N;
        tree[K] = x;
        while (K > 1){
            K >>= 1;
            tree[K] = func(tree[K << 1],tree[K << 1|1]);
        }
    }

    Monoid query(int L,int R){
        L += N; R += N;
        Monoid vL = unit,vR = unit;
        while (L < R){
            if (L&1){
                vL = func(vL,tree[L]);
                L ++;
            }
            if (R&1){
                R --;
                vR = func(tree[R],vR);
            }
            L >>= 1; R >>= 1;
        }
        return func(vL,vR);
    }
};

int main() {
    int N,Q; cin >> N >> Q;
    SegmentTree<ll> st(N,INF,[](ll x,ll y){return min(x,y);});

    rep(i,Q){
        ll type,x,y; cin >> type >> x >> y;
        if (type == 0){
            st.update(x,y);
        }
        else {
            cout << st.query(x,y + 1) << endl;
        }
    }
}


Measured memory_bytes: 4436
process.stdin.resume();
process.stdin.setEncoding('utf8');

var input_string = "";

var reader = require('readline').createInterface({
    input: process.stdin,
    output: process.stdout
});
reader.on('line', (line) => {
    input_string = line;
});

reader.on('close', () => {

    if( (input_string[2] == input_string[3])
     && (input_string[4] == input_string[5])){
         console.log('Yes');
     }else{
         console.log('No');
     }

});


Measured memory_bytes: 21320
#include<stdio.h>
#include<limits.h>
int c[20];
int memo[50000];

int f(int);

int f(int x){
    if(x==0)return 0;
    if(memo[x]!=0)return memo[x];
    int i,min=INT_MAX,a;
    for(i=0;i<20;i++){
        if(c[i]!=0&&x-c[i]>=0){
            a=f(x-c[i]);
            if(a<min)min=a;
        }
    }
    return memo[x]=min+1;
}

int main(void){
    int n,m,i;
    scanf("%d %d",&n,&m);
    for(i=0;i<m;i++)scanf("%d",&c[i]);
    printf("%d\n",f(n));
    return 0;
}

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

int main(){
  int n,m,k; cin>>n>>m>>k;
  for (int i=0; i<=n; i++){
    for (int j=0; j<=m; j++){
      if (i*m+j*n-2*i*j==k){
        cout<<"Yes"<<endl;
        return 0;
      }
    }
  }
  cout<<"No"<<endl;
}

Measured memory_bytes: 3644
import sys
sys.setrecursionlimit(10**9)
input = sys.stdin.readline

N = int(input())
edges = []
if N % 2 == 0:
    D = N+1
else:
    D = N
for i in range(1, D):
    for j in range(i+1, D):
        if i+j == D:
            continue
        else:
            edges.append(str(i)+" "+str(j))
if N % 2 == 1:
    for v in range(1, N):
        edges.append(str(v)+" "+str(N))
print(len(edges))
for e in edges:
    print(e)


Measured memory_bytes: 3588
#include <iostream>
#include <vector>
#include <cmath>
#include <ctime>
#include <cassert>
#include <cstdio>
#include <queue>
#include <set>
#include <map>
#include <fstream>
#include <cstdlib>
#include <string>
#include <cstring>
#include <algorithm>
#include <numeric>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)

using namespace std;

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int gcd(int a, int b) {
    while (b) {
        a %= b;
        swap(a, b);
    }
    return a;
}

bool win(vi &a) {
    if (a.size() == 1) return false;
    int n = a.size();
    i64 s = 0;
    for (int x : a) s += x;
    if ((s - n) % 2) return true;
    vi p;
    forn(i, n) {
        if (a[i] == 1) return false;
        if (a[i] % 2) p.pb(i);
    }
    if (p.size() > 1) return false;
    --a[p[0]];
    int g = 0;
    forn(i, n) g = gcd(g, a[i]);
    forn(i, n) a[i] /= g;
    return !win(a);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("input.txt", "rt", stdin);
#endif

    int n;
    cin >> n;
    vi a(n);
    forn(i, n) cin >> a[i];
    cout << (win(a) ? "First" : "Second") << '\n';


#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
    return 0;
}


Measured memory_bytes: 1276
#include <algorithm>
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define mod (int)1000000007
// Big two primes 
#define X 1011001110001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define int int
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define fi first
#define se second
#define endl "\n"
#define pi pair<int, int>
#define vii vector<pi>
const int MAXN = (int)((1e5) + 10);
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;}  
bool isPrime(int N){ for(int i=2;i*i<=N;++i){if(N%i==0) return false;}return true;}

int main()
{
    fio;

    int x,y,z;
    cin>>x>>y>>z;

    swap(x, y);
    swap(x, z);

    cout<<x<<" "<<y<<" "<<z<<endl;

    rr;
}

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

using namespace std;

#define rep(i, a) for (int (i) = 0; (i) < (a); (i)++)
#define reps(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define MP(a, b) make_pair((a), (b))
#define pb(a) push_back((a))
#define all(v) (v).begin(), (v).end()


int main()
{
	int n;
	int p;
	int ma, mi;
	cin >> n;
	while (n) {
		int sum = 0;
		ma = 0;
		mi = 1000;
		rep(i, n) {
			cin >> p;
			sum += p;
			ma = max(ma, p);
			mi = min(mi, p);
		}
		cout << (sum-ma-mi) / (n-2) << endl;
		cin >> n;
	}
}





Measured memory_bytes: 2960
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <tuple>
#include <cstdio>
#include <cmath>
#define rep(i, n) for(i = 0; i < n; i++)
using namespace std;

int n, m;
vector<int> et[200000];
bool used[200000];

signed main() {
	int i;
	
	cin >> n >> m;
	rep(i, m) {
		int a, b;
		cin >> a >> b;
		a--; b--;
		et[a].push_back(b);
		et[b].push_back(a);
	}
	
	int ans = 0;
	rep(i, n) {
		if (used[i]) continue;
		
		queue<int> que;
		que.push(i);
		used[i] = true;
		int sz = 1;
		
		while (!que.empty()) {
			int v = que.front(); que.pop();
			int j;
			rep(j, et[v].size()) {
				int nv = et[v][j];
				if (!used[nv]) {
					used[nv] = true;
					sz++;
					que.push(nv);
				}
			}
		}
		ans = max(ans, sz);
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 15252
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner scan = new Scanner(System.in);
        int N = scan.nextInt();
        int[] num = new int[N];
        
        for(int i = 0; i < N; i++) {
            num[i] = scan.nextInt();
        }
        
        boolean[] lightON = new boolean[N];
        int buttonNum = num[0];
        lightON[0] = true;

        int count = 0;
        int answer = -1;
        
        while(true) {
            lightON[buttonNum-1] = true;
            count++;
            
            if(lightON[1] == true) {
                answer = count;
                break;
            }
            
            buttonNum = num[buttonNum-1];
            if(lightON[buttonNum-1] == true) {
                break; 
            }
        }
        System.out.println(answer);
    }
}


Measured memory_bytes: 53004
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------


void _main() {
	int A, B, C;
	cin >> A >> B >> C;
	//家１＜家３＜家２　または　家２＜家３＜家１　なら　"Yes"
	cout << (A < C && C < B || B < C && C < A ? "Yes" : "No")
		<< endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
    int N,A[200],B[200],i,j,k,c[200],*n,sum=0;
    cin>>N;
    for(i=0;i<N;i++)
    {
        cin>>A[i];
    }
    for(i=0;i<N;i++)
    {
        cin>>B[i];
    }
    for(i=0;i<N;i++)
    {
        for(j=0;j<=i;j++)
        {
          sum+=A[j];
        }
        for(k=i;k<N;k++)
            sum+=B[k];
      c[i]=sum;
      sum=0;
    }
    n=max_element(c,c+N);
    cout<<*n;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  ll N,A,B;
  cin >> N >> A >> B;

  if(A > B){
    cout << 0 << endl;
    return 0;
  }

  if(N == 1){
    if(A == B){
      cout << 1 << endl;
      return 0;
    } else {
      cout << 0 << endl;
      return 0;
    }
  }

  ll mx = (N - 1) * B + A;
  ll mn = (N - 1) * A + B;

  cout << mx - mn + 1 << endl;
  return 0;
}

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

// macros
#define pb emplace_back
#define mk make_pair
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define rrep(i, n) for(int i=((int)(n)-1);i>=0;i--)
#define irep(itr, st) for(auto itr = (st).begin(); itr != (st).end(); ++itr)
#define irrep(itr, st) for(auto itr = (st).rbegin(); itr != (st).rend(); ++itr)
#define whole(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define bit(n) (1LL<<(n))
// functions
template <typename T> void unique(T& c){c.erase(std::unique(c.begin(), c.end()), c.end());}
template <class T>bool chmax(T &a, const T &b){if(a < b){a = b; return 1;} return 0;}
template <class T>bool chmin(T &a, const T &b){if(a > b){a = b; return 1;} return 0;}
template <typename T> istream &operator>>(istream &is, vector<T> &vec){for(auto &v: vec)is >> v; return is;}
template <typename T> ostream &operator<<(ostream &os, const vector<T>& vec){for(int i = 0; i < vec.size(); i++){ os << vec[i]; if(i + 1 != vec.size())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_set<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T> ostream &operator<<(ostream &os, const unordered_multiset<T>& st){for(auto itr = st.begin(); itr != st.end(); ++itr){ os << *itr; auto titr = itr; if(++titr != st.end())os << " ";} return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const pair<T1, T2> &p){os << "(" << p.first << ", " << p.second << ")"; return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
template <typename T1, typename T2> ostream &operator<<(ostream &os, const unordered_map<T1, T2> &mp){for(auto itr = mp.begin(); itr != mp.end(); ++itr){ os << "(" << itr->first << ", " << itr->second << ")"; auto titr = itr; if(++titr != mp.end())os << " "; } return os;}
//  types
using ll = long long int;
using P = pair<int, int>;
// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double EPS = 1e-10;
const int mod = 1000000007;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};
// io
struct fast_io{
  fast_io(){ios_base::sync_with_stdio(false); cin.tie(nullptr); cout << fixed << setprecision(20);}
} fast_io_;


int main(int argc, char const* argv[])
{
  ll n, a, b;
  cin >> n >> a >> b;
  ll res = 0;
  res += (n / (a + b)) * a;
  n = n % (a + b);
  res += min(a, n);
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);
#define _GLIBCXX_DEBUG//only for debugging
#include <bits/stdc++.h>
#include <chrono>
#include <ext/rope>
#define VALHALLA ios_base::sync_with_stdio(false);cin.tie(0);cout<<fixed<<setprecision(13);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
/* VARIABLE DECLARATION START */


/*  FUCNTION TEMPLATE STARTS  HERE */

double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}

/*  FUCNTION TEMPLATE ENDS HERE */
int main()
{
   VALHALLA
   int n;cin>>n;
   int k;cin>>k;
   vector<int> v(k);
   for(auto &x:v)cin>>x;
   sort(all(v));
   while(1)
   {
     string s=to_string(n);
     int flag=0;
     for(auto &x:s)
     {
       if(binary_search(all(v),x-48))
       {
        flag=1;break;
       }
     }
     if(flag==0)
     {
       cout<<n<<endl;return 0;
     }
     ++n;
   }

   
   
   


}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string s;
char a[100010];
int main()
{
     cin>>s;
     int k=0;
     for(int i=0;i<s.size();i++)
     {
        if(s[i]!='B') a[++k]=s[i];
        else 
         {
            k--;
            if(k<0) k=0;
         }
     }
     for(int i=1;i<=k;i++)
        cout<<a[i];
     cout<<"\n";

 return 0;
}

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

using namespace std;
using ll = long long;

#define REP2(i, n) for (int i = 0, i##_len = (int)(n); i < i##_len; ++i)
#define REP3(i, l, r) for (int i = (l), i##_len = (int)(r); i < i##_len; ++i)
#define GET_MACRO_REP(_1, _2, _3, NAME, ...) NAME
#define REP(...) GET_MACRO_REP(__VA_ARGS__, REP3, REP2) (__VA_ARGS__)
#define RREP2(i, n) for (int i = (n - 1); i >= 0; --i)
#define RREP3(i, l, r) for (int i = (r - 1), i##_len = (l); i >= i##_len; --i)
#define GET_MACRO_RREP(_1, _2, _3, NAME, ...) NAME
#define RREP(...) GET_MACRO_REP(__VA_ARGS__, RREP3, RREP2) (__VA_ARGS__)
#define IN(type, n) type n; cin >> n
#define INALL(type, v) REP(i, v.size()) { IN(type, _tmp); v.at(i) = _tmp; }
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((int)(x).size())

#ifdef _DEBUG
#define DEBUG(x) cout << #x << ": " << x << endl
#else
#define DEBUG(x)
#endif

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; }
#pragma endregion

vector<ll> num(2001, -1);

ll solve(int n) {
  ll ans = 0;
  ll mod = 1000000007;
  if (n < 3) ans = 0;
  else if (n < 6) ans = 1;
  else {
    if (num.at(n) == -1) {
      ll sum = 0;
      RREP(i, 3, n - 2) {
        sum += solve(n - i);
        sum %= mod;
      }
      num.at(n) = (sum + 1) % mod;
    }
    ans = num.at(n);
  }
  return ans ;
}

int main() {
  IN(int, S);
  cout << solve(S) << endl;

  return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>

static const int MOD = 1000000007;
using ll = int64_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

template<class T> void chmin(T &a, const T &b){ a = (a < b ? a : b); }
template<class T> void chmax(T &a, const T &b){ a = (a > b ? a : b); }

int main() {
    int n, m;
    while(cin >> n >> m, n|m){
        vector<int> v(n+1), u((n+1)*(n+1));
        for (int i = 0; i < n; ++i) {
            scanf("%d", &v[i+1]);
        }
        for (int i = 0; i <= n; ++i) {
            for (int j = 0; j <= n; ++j) {
                u[i*n+j] = v[i]+v[j];
            }
        }
        sort(u.begin(), u.end());
        u.erase(unique(u.begin(), u.end()), u.end());
        int ans = 0;
        for (auto &&i : u) {
            if(i <= m) chmax(ans, i+*(upper_bound(u.begin(), u.end(), m-i)-1));
        }
        cout << ans << "\n";
    }
    return 0;
}



Measured memory_bytes: 7204
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

Q = inp()
cnt = [False] * (10**5+10)
table = [False] * (10**5+10)
for i in range(1,10**5+5):
    cnt[i] = is_prime(i)
for i in range(1,10**5+5):
    table[i] = i%2 and cnt[i] and cnt[(i+1)//2]
res = [0] * (10**5+5)
for i in range(10**5+4):
    tmp = 1 if table[i] else 0
    res[i+1] = res[i] + tmp
# print(res[:20])
for _ in range(Q):
    a,b = inpl()
    print(res[b+1] - res[a])

Measured memory_bytes: 82008
#include<cstdio>
#include<algorithm>
#include<cctype>
using namespace std;
#define G getchar()
int read()
{
	int x=0; char ch=G;
	for (;!isdigit(ch);ch=G);
	for (;isdigit(ch);ch=G) x=(x<<3)+(x<<1)+(ch^48);
	return x;
}
#undef G
typedef long long ll;
int Mod;
int fac[6010],inv[6010];

int n;
int dp[6010][9010],B=3000;
inline void add(int &x,ll y){x=(x+y)%Mod;}
int main()
{
	n=read()*3,Mod=read();
	fac[0]=1; for (int i=1;i<=n;i++) fac[i]=1LL*fac[i-1]*i%Mod;
	inv[1]=1; for (int i=2;i<=n;i++) inv[i]=1LL*(-Mod/i)*inv[Mod%i]%Mod;
	
	dp[0][B]=fac[n];
	for (int i=0;i<n;i++){
		for (int j=max(-(i/2),i-n)+B;j<=i+B;j++){
			if (!dp[i][j]) continue;
			add(dp[i+1][j+1],1LL*dp[i][j]*inv[i+1]);
			if (i+2<=n&&j-1>=0) add(dp[i+2][j-1],1LL*dp[i][j]*inv[i+2]);
			if (i+3<=n) add(dp[i+3][j],1LL*dp[i][j]*inv[i+3]);
		}
	}
	int ans=0;
	for (int i=B;i<=n+B;i++) ans=(ans+dp[n][i])%Mod;
	printf("%d\n",(ans+Mod)%Mod);
	return 0;
}

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

using namespace std;
using ll=long long;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, a, n) for(int i = (a); i < (n); i++)

int main(){
  cin.tie(nullptr);ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int a,b;cin>>a>>b;
  cout<<(a*b*1%2==1 ||a*b*1%2==2 ||a*b*1%2==3 ?"Yes":"No")<<endl;
}


Measured memory_bytes: 256