akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define ll             long long int
#define lb             lower_bound
#define ub             upper_bound
#define fi             first
#define mp             make_pair
#define vll            vector<ll>
#define se             second
#define sz             size()
#define mod            1000000007
#define endl           "\n"
#define fast           ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define allr(v)        v.rbegin(),v.rend()
#define inp(V,n)      for(int i=0;i<n;i++){cin >> V[i];}
#define oup(V,n)     {for(int i=0;i<n;i++){cout <<  V[i] << " "  ;} cout << endl;}
using namespace std;
ll factorial(ll n)
{
    return (n == 1 || n == 0) ? 1 : n * factorial(n - 1);
}
ll gcd(ll a, ll b)
{
    if (a == 0)
      return b;
    return gcd(b % a, a);
}
ll lcm(ll a, ll b)
{
   return (a*b)/gcd(a, b);
}
bool sortByVal(const pair<double,double> &a,
               const pair<double,double> &b)
{
    if(a.fi==b.fi)
    {
    return (a.second >b.second);
    }
    else
        return (a.fi<b.fi);
}

int main()
{
fast;
int q=1;
//cin>>q;
while(q--)
{
ll n,k,sum=0,ans=0,a,b,c,d,e;
cin>>a>>b;
 if(a*2<=b && a*4>=b && b%2==0)
    cout<<"Yes"<<endl;
 else cout<<"No"<<endl;

}
return 0;
}



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

int main(){
  int n; cin >> n;
  int sh = n / 100, ji = n % 100;
  string out = "NA";
  if(sh <= 12 & sh > 0){
    if(ji <= 12 & ji > 0){
      out = "AMBIGUOUS";
    }else{
      out = "MMYY";
    }
  }else{
    if(ji <= 12 & ji > 0){
      out = "YYMM";
    }
  }
  cout << out;
}


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

int main() {
  int N ,L; cin>>N>>L;
  int ajiall=0;
  for(int i=0; i<N; i++){
    ajiall+=L+i;
  }
  int ans=abs(L);
  for(int i=0; i<N; i++){
    if(abs(ans)>abs(L+i)){
      ans=L+i;
    }
  }
  cout<<ajiall-ans<<endl;
}

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

using namespace std;

int main(){

    int num, limit;
    cin >> num >> limit;
    
    vector<int> c(num), t(num);

    int minimumcost=9999;
    for(int i=0; i<num; i++){
        cin >> c[i] >> t[i];
        if(i == 0){
            if(t[i] <= limit){
                minimumcost=c[i];
            }
        }else{
            if(t[i] <= limit && c[i] < minimumcost){
                minimumcost=c[i];
            }
        }
    }

    if(minimumcost == 9999){
        cout << "TLE";
    }else{
        cout << minimumcost;
    }


    return 0;
}


Measured memory_bytes: 384
n,m,c=map(int,input().split())
b=list(map(int,input().split()))
s=0
for _ in range(n):
    t=c
    a=list(map(int,input().split()))
    for i in range(m):
        t+=a[i]*b[i]
    if t>0:
        s+=1
print(s)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int a, b;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> a >> b;
	if(a > b) swap(a, b);
	if(abs(a - b) % 2) cout << "IMPOSSIBLE\n";
	else cout << abs(a - b) / 2 + a << "\n";
	return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cfloat>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <memory>
#include <string>

#include <algorithm>
#include <complex>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#include <bitset>

using namespace std;

#ifdef _MSC_VER
#define __typeof__ decltype
#endif

#define ITER(c)             __typeof__((c).begin())
#define FOREACH(it, c)      for (ITER(c) it=(c).begin(); it != (c).end(); ++it)
#define RITER(c)            __typeof__((c).rbegin())
#define RFOREACH(it, c)     for (RITER(c) it=(c).rbegin(); it != (c).rend(); ++it)
#define REP(i, n)           REPEAT(i, 0, n)
#define RREP(i, n)          RREPEAT(i, 0, n);
#define REPEAT(i, k, n)     for(int i = (k); i < (k+n); ++i)
#define RREPEAT(i, k, n)    for(int i = (k)+(n)-1; i >= (k); ++i)
#define ALL(c)              (c).begin(), (c).end()
#define LLPOW(p1,p2)        ((ll)pow((double)(p1), (int)p2))
#define ESIZEOF(A)          (sizeof(A)/sizeof((A)[0]))
#define MIN(p1,p2)          (((p1)<(p2))?(p1):(p2))
#define MAX(p1,p2)          (((p1)>(p2))?(p1):(p2))
#define CIN_NO_SYNC         do { cin.tie(0); ios_base::sync_with_stdio(false); } while(0)
#define GETSTR(p)           fgets((p), sizeof(p), stdin)
#define CHOMP(p)            do{ char *_q = (p) + strlen(p)-1; if(*_q == '\n' || *_q == '\r') *_q = 0; } while(0)
#define mp                  make_pair
#define pb                  push_back

typedef long long ll;
typedef unsigned long long ull;

#define X real()
#define Y imag()
typedef double D;
typedef complex<D> P;
#define EPS (1e-9)

#ifdef _DEBUG
#define pf printf
#define pr(n) do { cout << #n " = " << (n) << endl; } while(0)
#else
#define pf(...) /* */
#define pr(...) /* */
#endif

struct {
    const char *a;
    const char *b;
    int c;
} table[] = {
    { "meiji",  "18680908", 1868, },
    { "taisho", "19120730", 1912, },
    { "showa",  "19261225", 1926, },
    { "heisei", "19890108", 1989, },
};

void solve(int y, int m, int d){
    char buf[16];
    sprintf(buf, "%04d%02d%02d", y, m, d);
    int idx = 3;
    REP(i,4){
        if(strcmp(buf, table[i].b) < 0){
            idx = i-1;
            break;
        }
    }

    if(idx < 0){
        printf("pre-meiji\n");
        return;
    }
    printf("%s %d %d %d\n", table[idx].a, y-table[idx].c+1, m, d);
}

int main(){
    int y, m, d;
    while(cin >> y >> m >> d){
        solve(y, m, d);
    }
    return 0;
}

Measured memory_bytes: 1176
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <sstream>
#include <map>
#include <set>

#define REP(i,k,n) for(int i=k;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1<<30
#define pb push_back
#define mp make_pair

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	string s;
	cin >> s;

	vector<string> v(n);
	rep(i, n) cin >> v[i];

	int ans = 0;
	rep(i, n) {
		bool flag = false;

		rep(j, v[i].size()) {
			if(s[0] == v[i][j]) {
				for(int k = 0; j + (k + 1) * (s.size()-1) < v[i].size(); k++) {
					bool ch = true;
					for(int l = 0, id = 0; id < s.size() ; l += k + 1, id++) {
						if(s[id] == v[i][j+l]) continue;
						ch = false;
						break;
					}

					if(ch) flag = true;
				}
			}
		}

		if(flag) {
			ans++;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1232
#include <stdio.h>
#include <math.h> 
int main(void){
    double i,skei; 
    int t,s,goukei;
    int j;
    i=0;
    goukei=0;
    skei =0;
    for(j=0;j<100;j++){
      if(scanf("%d,%d\n", &t,&s)==EOF){break;};
      goukei= goukei+(t*s);
      skei=skei+s;      
      i=i+1;    
    }

skei =skei+0.5;
 
    printf("%d\n", goukei);
    printf("%.0f\n", round(skei/i));
    return 0;
}

Measured memory_bytes: 644
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<(int)(n); i++)
#define rrep(i, n) for(int i=((int)(n)-1); i>=0; i--)
#define REP(i, k, n) for(int i=(int)(k); i<(int)(n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
#define PQ(T) priority_queue<T>
#define PQS(T) priority_queue<T, vector<T>, greater<T> >
#define deci cout << fixed << setprecision(15);
typedef long long ll;
const int INF = INT_MAX;
const ll inf = 1e18;
const ll mod = 998244353;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
template<class T> bool chmin(T&x,T y){if(x>y){x=y;return true;}return false;}
template<class T> bool chmax(T&x,T y){if(x<y){x=y;return true;}return false;}
ll gcd(ll x, ll y){ if(x>y) swap(x, y);while(x!=0){ y%=x; swap(x, y); }return y; }
ll mpow(ll x, ll r){if(r==0) return 1;if(r%2==1){ return x*mpow(x, r-1)%mod; }else{ ll aa = mpow(x, r/2); return aa*aa%mod; }}

const int MAX = 2000000;

long long fac[MAX], finv[MAX], inv[MAX];

void pre_comb(void){
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for(int i=2; i<MAX; i++){
		fac[i] = fac[i-1] * i % mod;
		inv[i] = mod - inv[mod%i] * (mod/i) % mod;
		finv[i] = finv[i-1] * inv[i] % mod;
	}
}

long long comb(int n, int k){
	if(n < k) return 0;
	if(n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n-k] % mod) % mod;
}

int main(){
	int N, M; cin >> N >> M;
	ll s1 = 0, s2 = 0;
	pre_comb();
	rep(i, M+1){
		if((3*M-i) % 2 == 1) continue;
		s1 = (s1 + comb(N, i) * comb((3*M-i)/2+N-1, N-1) % mod) % mod;
	}
	REP(i, 2*M+1, 3*M+1){
		s2 = (s2 + N * comb(3*M-i+N-2, N-2) % mod) % mod;
	}
	cout << (s1 - s2 + mod) % mod << endl;
	return 0;
}

Measured memory_bytes: 47104
#include <bits/stdc++.h>
using namespace std;;
#define rep(i, n) for(int i = 0;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> vl;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;


int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll s,w;cin >> s >> w;
  if(s<= w) cout << "unsafe" << endl;
  else cout << "safe" << endl;
}

Measured memory_bytes: 3652
import Control.Applicative ((<$>))
import Control.Monad
import Data.Complex

type Vector = Complex Double

eps :: Double
eps = 1e-7

dot :: Vector -> Vector -> Double
dot a b = realPart $ conjugate a * b

cross :: Vector -> Vector -> Double
cross a b = imagPart $ conjugate a * b

readWords :: Read a => IO [a]
readWords = map read . words <$> getLine

main :: IO ()
main = do
  q <- readLn
  qs <- replicateM q $ do
    [x0,y0,x1,y1,x2,y2,x3,y3] <- readWords :: IO [Double]
    let
      p0 = x0:+y0
      p1 = x1:+y1
      p2 = x2:+y2
      p3 = x3:+y3
    return (p0,p1,p2,p3)

  forM_ qs $ \(p0,p1,p2,p3) -> do
    let
      para = abs ((p1-p0)`cross`(p3-p2)) < eps
      orth = abs ((p1-p0)`dot`(p3-p2)) < eps
    when para $ print 2
    when orth $ print 1
    when (not para && not orth) $ print 0

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

using namespace std;

int main() {
    char ch;

    while (1) {
        scanf("%c", &ch);
        if (isalpha(ch)) {
            if (islower(ch)) printf("%c", toupper(ch));
            else printf("%c", tolower(ch));
        } else printf("%c", ch);

        if (ch == '\n') break;
    }

}

Measured memory_bytes: 3160
package main

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

type Node struct {
	prev, next *Node
	key        int
}

var node = &Node{}

func initNode() {
	node.prev = node
	node.next = node
}

func insert(key int) {
	newNode := &Node{key: key}
	newNode.next = node.next
	node.next.prev = newNode
	node.next = newNode
	newNode.prev = node
}

func search(key int) *Node {
	current := node.next
	for current.key != key {
		if current == node {
			return nil
		}
		current = current.next
	}
	return current
}

func deleteNode(n *Node) {
	if n == nil {
		return
	}
	n.prev.next = n.next
	n.next.prev = n.prev
	n = nil
}

func deleteFirst() {
	deleteNode(node.next)
}

func deleteLast() {
	deleteNode(node.prev)
}

func printList() string {
	buf := bytes.Buffer{}
	current := node.next
	for {
		buf.WriteString(strconv.Itoa(current.key))
		current = current.next
		if current == node {
			break
		}
		buf.WriteString(" ")
	}
	return buf.String()
}

var scanner = bufio.NewScanner(os.Stdin)

func main() {
	scanner.Scan()
	str := scanner.Text()
	n, _ := strconv.Atoi(str)
	initNode()
	for i := 0; i < n; i++ {
		scanner.Scan()
		str := strings.Split(scanner.Text(), " ")
		command := str[0]
		switch command {
		case "insert":
			key, _ := strconv.Atoi(str[1])
			insert(key)
		case "delete":
			key, _ := strconv.Atoi(str[1])
			if target := search(key); target != nil {
				deleteNode(target)
			}
		case "deleteFirst":
			deleteFirst()
		case "deleteLast":
			deleteLast()
		default:
			fmt.Println("specify the command form the following list: \"insert <key>\", \"delete <key>\", \"deleteFirst\", \"deleteLast\"")
			os.Exit(1)
		}
	}
	fmt.Println(printList())
}



Measured memory_bytes: 66320
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
void chmin(ll &x, ll y) { x = min(x, y); }
void chmax(ll &x, ll y) { x = max(x, y); }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


struct edge{
    int to;
    int distance;
};

struct Node {
    int cnt;
    int fuel;
};

using Graph = vector<vector<edge>>;
Graph G;

int N, M, L;

vector<ll> dijkstra(int s){
    using P = tuple<int, int, int>;
    priority_queue<P, vector<P>, greater<P>> que;
    vector<Node> dp(N+1);
    rep(i, N+1){
        dp[i].cnt = INF;
        dp[i].fuel = -1;
    }
    dp[s].cnt = 0;
    dp[s].fuel = L;
    // cnt, node, fuel
    que.push(P(0, s, L));
    while(que.size() != 0){
        int cnt, v, fuel;
        tie(cnt, v, fuel) = que.top();
        //cout << cnt << ", " << v << ", " << fuel << endl;
        que.pop();
        for(auto e: G[v]){
            int next_fuel = fuel - e.distance;
            int next_cnt = cnt;
            if(next_fuel < 0){
                next_fuel = L-e.distance;
                next_cnt++;
            }
            if(dp[e.to].cnt > next_cnt){
                dp[e.to].cnt = next_cnt;
                dp[e.to].fuel = next_fuel;
                que.push(P{next_cnt, e.to, next_fuel});
            }
            if(dp[e.to].cnt == next_cnt && dp[e.to].fuel < next_fuel){
                dp[e.to].fuel = next_fuel;
                que.push(P{next_cnt, e.to, next_fuel});
            }
        }
    }
    //if(dp[t].cnt == INF) cout << "-1" << endl;
    //else cout << dp[t].cnt << endl;
    vector<ll> d(N);
    rep(i, N){
        d[i] = dp[i+1].cnt;
    }
    return d;
}

int main(){
    cin >> N >> M >> L;
    G.assign(N+1, vector<edge>());
    for(int i=0; i<M; i++){
        int a, b, c;
        cin >> a >> b >> c;
        if(L<c) continue;
        G[a].push_back({b, c});
        G[b].push_back({a, c});
    }

    vector<vector<ll>> dist;
    for(int i=1; i<=N; i++){
        auto v = dijkstra(i);
        dist.push_back(v);
    }


    int q;
    cin >> q;
    rep(i, q){
        int s, t;
        cin >> s >> t;
        s--; t--;
        ll ans = dist[s][t];
        if(ans == INF) cout << "-1" << endl;
        else cout << ans << endl;
    }
}

Measured memory_bytes: 2432
#include<stdio.h>

int main(void) {
        int a, b;
        while(1) {
                scanf("%d %d", &a, &b);
                if(a==0 && b==0)        break;
                if(a < b) {
                        printf("%d %d\n", a, b);
                } else {
                        printf("%d %d\n", b, a);
                }
        }
        return 0;
}

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

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl

using namespace std;

typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vec) {
    os << "[ ";
    REP(i, vec.size()) {
        os << vec[i] << " ";
    }
    os << "]";

    return os;
}

int partition(int* A, int p, int r) {
    int pivot = A[r];
    int i = p - 1;

    FOR(j, p, r) {
        if(A[j] <= pivot) {
            ++i;
            swap(A[i], A[j]);
        }
    }
    swap(A[++i], A[r]);

    return i;
}

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

    int n;
    cin >> n;

    int A[n];
    REP(i, n) cin >> A[i];

    int pivot_idx = partition(A, 0, n - 1);

    REP(i, n) {
        if (i > 0) {
            cout << " ";
        }

        if (i == pivot_idx) cout << "[" << A[i] << "]";
        else cout << A[i];
    }

    cout << endl;

}



Measured memory_bytes: 3500
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for (ll i=0; i<n; ++i)
#define all(c) begin(c),end(c)
/*
5000^2
*/
int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  ll N,K,ans=-1e10; cin>>N>>K;
  vector<ll> P(N+1,0), C(N+1,0);
  for(ll i=1; i<=N; i++) cin>>P[i];
  for(ll i=1; i<=N; i++) cin>>C[i];
  for(ll i=1; i<=N; i++){//start
//cout<<"ans:"<<ans<<" i:"<<i<<endl;
    ll k = K;
    ll tmp=0;
    vector<ll> seen(N+1,0);
    ll next = P[i];
    while(seen[next] < 2 && k>0){
      seen[next]++;
      tmp += C[next];
      ans = max(ans, tmp);
      next = P[next];
      k--;
//cout<<"tmp:"<<tmp<<" k:"<<k<<endl;  
    }
    if(k==0){
      ans=max(ans,tmp);
      continue;
    }
    ll count=0;
    ll score=0;
    for(ll j=1; j<=N; j++){
      if (seen[j] == 2){
        count++;
        score+=C[j];
      }
    }
    ll re=k/count;
    re-=1;
    if(re<0) re=0;
    k-=re*count;
    tmp+=score*re;
    ans=max(ans,tmp);
    while(k>0){
      tmp += C[next];
      ans=max(ans,tmp);
      next = P[next];
      k--;
    }
//cout<<"i:"<<i<<" tmp:"<<tmp<<endl;    
  }
  cout<<ans<<endl;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var vals = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            var N = vals[0];
            var M = vals[1];

            var cities = new List<City>[N];
            var index = new Dictionary<int, Tuple<int, int>>();
            foreach(var i in Enumerable.Range(0, N))
            {
                cities[i] = new List<City>();
            }

            foreach(var i in Enumerable.Range(0, M))
            {
                var item = new City(i + 1, Console.ReadLine());
                cities[item.Prefecture-1].Add(item);
                index[i] = new Tuple<int, int>(item.Prefecture, cities[item.Prefecture-1].Count - 1);
            }

            //Sort
            foreach(var i in Enumerable.Range(0, N))
            {
                var query = cities[i].Where(x => x.Prefecture == i+1).OrderBy(x => x.Year);
                var cnt = 0;
                foreach(var q in query)
                {
                    q.SetPrefectureIndex(cnt);
                    cnt++;
                }
            }

            //View
            foreach(var ci in index)
            {
                Console.WriteLine(cities[ci.Value.Item1-1][ci.Value.Item2].GetID());
            }
        }
    }

    public class City
    {
        public int Id { get; set; }
        public int Prefecture { get; set; }
        public int Year { get; set; }

        public int PrefectureIndex { get; private set; }

        public City(int idx, string input)
        {
            Id = idx;
            var vals = input.Split(' ').Select(x => int.Parse(x)).ToArray();
            Prefecture = vals[0];
            Year = vals[1];
        }

        public void SetPrefectureIndex(int index)
        {
            PrefectureIndex = index;
        }

        public string GetID()
        {
            var str_id = $"{Prefecture:D6}{(PrefectureIndex+1):D6}";
            return str_id;
        }
    }

}


Measured memory_bytes: 41264
#include<iostream>
#include<algorithm>
#include<vector>
#include<math.h>
#include<string>

using namespace std;

int main(){
  int n,m,a,b,c,ans;
  cin >> a >> b;
  if(a > b && b != 1)
  cout << a - b  << endl;
  else cout << 0 << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cmath>
using namespace std;
int main(){
  int T;
  int dx, dy;
  int x, y, ansx, ansy;

  cin >> T;
  while(T--){
    x = 0, y = 0, ansx = 0, ansy = 0;
    while(cin >> dx >> dy){
      if(dx == 0 && dy == 0) break;      
      x += dx;
      y += dy;
      
      if(hypot(x,y) > hypot(ansx, ansy)){
	ansx = x;
	ansy = y;
      }
      else if(hypot(x, y) == hypot(ansx, ansy) && ansx < x){
	ansx = x;
	ansy = y;
      }
    }
    cout << ansx << ' ' << ansy << endl;
  }
  return 0;
}

Measured memory_bytes: 0
N= int(input())
total_otoshidama = float(0)
otoshidama_list = []
for i in range(N):
    xi, ui = input().split()
    if ui == 'BTC':
        xi = float(xi)
        xi = xi*380000
    else:
        xi = int(xi)
    total_otoshidama += xi
print(total_otoshidama)

Measured memory_bytes: 3060
n=int(input())
m,a,r,c,h=0,0,0,0,0
for i in range(n):
    s=input()
    if s[0]=='M':
        m+=1
    elif s[0]=='A':
        a+=1
    elif s[0]=='R':
        r+=1
    elif s[0]=='C':
        c+=1
    elif s[0]=='H':
        h+=1
x=[m,a,r,c,h]
cnt=x.count(0)
for i in range(cnt):
    x.remove(0)

l=len(x)
if l<3:
    print(0)
elif l==3:
    print(x[0]*x[1]*x[2])
elif l==4:
    a,b,c,d=x[0],x[1],x[2],x[3]
    print(a*b*c+a*b*d+a*c*d+b*c*d)
else:
    a,b,c,d,e=x[0],x[1],x[2],x[3],x[4]
    print(a*b*c+a*b*d+a*c*d+b*c*d\
         +e*a*b+e*a*c+e*a*d+e*b*c+e*b*d\
         +e*c*d)


Measured memory_bytes: 3064
#include <iostream>

using namespace std;
int main()
{
	while(true){
		int n; 
		cin >> n ;
		if(n == 0 ) break;
			int sum;
			int ans =0;
			for (int i = 1; i<n; i++){
				sum = 0;
	   			for (int j = i; j<n; j++){
	   				sum = sum + j;
	   				if(sum == n)
	   					ans = ans +1;
	   			}
	   		}
		cout << ans<<endl;
	}
}

Measured memory_bytes: 2996
import java.util.*;
public class Main{
    public static int cnt = 0;
    public static void merge(int[] A,int left,int right,int mid){
        // int n1 = mid - left;
        // int n2 = right - mid;
        // int l[] = new int[n1+1];
        // int r[]  = new int[n2+1];
        // for (int i = 0; i < n1-1; i++) {
        //   l[i]= A[left + i];
        // }
        // for (int i = 0; i < n2-1; i++) {
        //   r[i]= A[i + mid];
        // }
        //  l[n1] = r[n2] = Integer.MAX_VALUE;
        // int i = 0,j = 0;
        // for(int k = left;k <= right-1;k++){
        //   cnt++;
        //   if(l[i] <= r[j]){
        //     A[k] = l[i];
        //     i = i + 1;
        //   }
        //   else{
        //     A[k] = r[j];
        //     j = j + 1;
        //   }
        // }
      int n1 = mid - left;
      int n2 = right - mid;
      int[] l = new int[n1 + 1];
      int[] r = new int[n2 + 1];
      for (int i = 0; i < n1; i++) {
        l[i] = A[left + i];
      }
      for (int i = 0; i < n2; i++) {
        r[i] = A[mid + i];
      }
      l[n1] = Integer.MAX_VALUE;
      r[n2] = Integer.MAX_VALUE;

      int L = 0;
      int R = 0;
      for (int k = left; k < right; k++) {
        if (l[L] <= r[R]) {
          A[k] = l[L++];
        } else {
          A[k] = r[R++];
        }
        cnt++;
      }
    }
    public static void mergesort(int[] A,int left,int right){
      if(left + 1 < right){
        int mid = (left + right)/2;
        mergesort(A,left,mid);
        mergesort(A,mid,right);
        merge(A,left,right,mid);
      }

    }
    public static void main(String[] args){
      Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] A = new int[n];
      for(int i = 0; i < n; i++){
        A[i] = sc.nextInt();
      }
      mergesort(A,0,n);
      for(int i = 0;i<n-1;i++){
        System.out.print(A[i]+" ");
      }
      System.out.println(A[n-1]);
      System.out.println(cnt);
    }
}



Measured memory_bytes: 166888
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string.h>
#include<string>
#include<map>
#include<utility>
#include<functional>
typedef long long ll;
using namespace std;
typedef pair<int,float> p;

vector<ll> a,b,c;
int n,m;
string s;

int main(){
  cin >> s;
  for(int i=0;i<s.size();i++){
    if(s[i]==','){
      s[i]=' ';
    }
  }
  cout << s << endl;
  return 0;
}


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

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

	string s;
	cin>>s;

	if(s.size() <= k){
		cout<<s;
	}

	else{
		cout<<s.substr(0,k)+"...";
	}

	return 0;
}


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

int main()
{
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i = 0;i < n;i++){
    cin >> a[i];
    a[i]--;
  }
  int x = 0;
  for(int i = 0;i < n;i++){
    if(x == 1){
      cout << i << endl;
      return 0;
    }
    x = a[x];
  }
  cout << -1 << endl;
}


Measured memory_bytes: 640
N = int(input())
a = list(map(int,input().split()))
# print(N, a)
ge_cnt = 0
diffs = []
for i in range(N-1):
    if a[i] > a[i+1]:
        ge_cnt += 1
        diffs.append(a[i+1] - a[i])

if ge_cnt == 0:
    print('YES')
elif ge_cnt == 2:
    if diffs[0] == diffs[1]:
        print('YES')
    else:
        print('NO')
else:
    print('NO')

Measured memory_bytes: 3064
#include <stdio.h>

int main()
{
   int a;
   int b;
   scanf("%d", &a);
   scanf("%d", &b);

   if(a < b){
     printf("a < b\n");
   }
   else if(a > b){
     printf("a > b\n");
   }
   else if(a == b){
     printf("a == b\n");
   }

   return 0;
}

Measured memory_bytes: 580
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;

int N, K;
vector<double> A(0);

int lower_bound_func(int left, int right, bool (*func)(int)) {
    // func returns true when the statement is satisfied
    while (right - left > 1) {
        int mid = left + (right - left) / 2;
        if (func(mid))
            right = mid;
        else
            left = mid;
    }
    return right;  // left for upper_bound
}

bool check(int output) {
    ll tmp = 0;
    for (int i = 0; i < N; i++) {
        tmp += ceil(A[i] / (double)output);
    }
    return tmp - N <= K;
}

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

    A.resize(N);
    int m = 0;
    for (int i = 0; i < N; i++) {
        cin >> A[i];
        m = max(m, (int)A[i]);
    }
    if (K == 0) {
        cout << m << endl;
        return 0;
    }

    int output = lower_bound_func(0, m, check);

    cout << output << endl;

    return 0;
}


Measured memory_bytes: 4828
let n = stdin.ReadLine() |> int
let xArray = stdin.ReadLine().Split() |> Array.map int

[ Array.min xArray .. Array.max xArray ]
|> Seq.map (fun p -> xArray |> Seq.map (fun x -> pown (abs (x - p)) 2) |> Seq.sum )
|> Seq.min
|> stdout.WriteLine

Measured memory_bytes: 13524
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin >> n;
  int x[n][3];
  for(int i=0;i<n;i++){
    for(int j=0;j<3;j++){
      cin >> x[i][j];
    }
  }
  unsigned long dp[n][3];
  dp[0][0]=x[0][0];
  dp[0][1]=x[0][1];
  dp[0][2]=x[0][2];
  for(int i=1;i<n;i++){
    dp[i][0]=x[i][0]+max(dp[i-1][1],dp[i-1][2]);
    dp[i][1]=x[i][1]+max(dp[i-1][0],dp[i-1][2]);
    dp[i][2]=x[i][2]+max(dp[i-1][0],dp[i-1][1]);
    //cout << dp[i][0] << " " << dp[i][1] << " " << dp[i][2] << "\n";
  }
  cout << *max_element(dp[n-1],dp[n-1]+3);
}


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

using namespace std;

#define X first
#define Y second
#define eps  1e-5
#define gcd __gcd
#define pb push_back
#define PI acos(-1.0)
#define lowbit(x) (x)&(-x)
#define bug printf("!!!!!\n");
#define mem(x,y) memset(x,y,sizeof(x))

typedef long long LL;
typedef long double LD;
typedef pair<int,int> pii;
typedef unsigned long long uLL;

const int maxn = 1e5+7;
const int INF  = 1<<30;
const int mod  = 1e9+7;

void solve(){
    int a,b;
    cin>>a>>b;
    if(a==b){
        printf("%d\n",a);
    }else if((a+b)%2==0){
        printf("%d\n",(a+b)/2);
    }else{
        printf("IMPOSSIBLE\n");
    }
    
    return;
}

int main()
{
#ifndef ONLINE_JUDGE
    //freopen("in.txt","r",stdin);
#endif
//    freopen("out.txt","w",stdout);
//    ios::sync_with_stdio(false);
    int t = 1;
    //scanf("%d",&t);
    while(t--){
    //    printf("Case %d: ",cas++);
        solve();
    }
#ifndef ONLINE_JUDGE
   // printf("%.10f\n",1.0*clock()/CLOCKS_PER_SEC);
#endif
    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#define pb push_back
std::vector<int> vec[2005]; 
int main()
{
	int k = 38, n = k * (k - 1) + 1, cnt = 0; 
	printf("%d %d\n", n, k);
	for (int i = 0; i < k; i++)
	{
		for (int j = 0; j < k - 1; j++)
			vec[cnt].pb(j * k + i); 
		vec[cnt++].pb(n - 1); 
	}
	for (int i = 0; i < k - 1; i++)
	{
		for (int j = 0; j < k - 1; j++)
		{
			int y = j; 
			for (int x = 0; x < k - 1; x++)
			{
				vec[cnt].pb(y * k + x); 
				y = (y + i) % (k - 1); 
			}
			vec[cnt++].pb(i * k + k - 1); 
		}
	}
	for (int i = 0; i < cnt; i++)
	{
		for (int j = 0; j < k; j++)
			printf("%d%c", vec[i][j] + 1, " \n"[j + 1 == k]);
	}
	return 0;
}


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

int main(){
    queue<int> q[3] ;
    for(int i=0;i<3;i++){
        string x ;
        cin >> x ;
        for(char c : x){
            q[i].push(c-'a');
        }
    }
    queue<int> qq ;
    qq.push(q[0].front());
    while(qq.size()){
        int f = qq.front() ; qq.pop();
        if ( q[f].size() == 0 ){
            cout << char(f+'a'-32) << endl;
            return 0 ;
        }
        qq.push(q[f].front());
        q[f].pop();

    }



    return 0 ;
}


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

typedef long long ll;

const int N = 120, W = 1e5 + 20;
ll dp[N][W];
pair<ll, ll> a[N];

int main()
{
	ll n, w;
	cin >> n >> w;
	for (int i = 1; i <= n; i++)
	{
		cin >> a[i].first >> a[i].second;
	}
	for (int i = 1; i <= n; i++)
	{
		dp[i][0] = 0;
		for (int j = 0; j <= w; j++)
		{
			if (a[i].first > j)
			{
				dp[i][j] = dp[i - 1][j];
				continue;	
			}
			dp[i][j] = max(dp[i - 1][j], a[i].second + dp[i - 1][j - a[i].first]);	
		}
	}
	cout << dp[n][w];
}


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

int main(){
    int N;
    int a[1100000];

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

    int condition = 0;
    int ascend = 1;
    int descend = 2;
    int ans = 1;
    bool flag = true;
    for(int i = 0; i < N; i ++){
        if(flag == true && a[i] < a[i+1]){
            condition = ascend;
            flag = false;
        }        
        else if(flag == true && a[i] > a[i+1]){
            condition = descend;
            flag = false;
        }
        if(condition == ascend && a[i] > a[i+1]){
            // cout << "facking add ans" << "and index is " << i << "which is ascend"<< endl;
            flag = true;
            ans++;
        }else if(condition == descend && a[i] < a[i+1]){
            // cout << "facking add ans" <<"and index is "  << i <<  endl;
            ans++;
            flag = true;
        }
        // if(a[i] == a[i+1]){
        //     continue;
        // } 
        if(a[i+2] == 0) break;
    }
    cout << ans << endl;
}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
using ll = long long;
typedef pair<int, int> P;
ll Mod = 1000000007;
int main() {
  int N,Ma,Mb;
  cin >> N >> Ma >> Mb;
  int a[N],b[N],c[N];
  for (int i = 0; i < N; i++) {
    cin >> a[i] >> b[i] >> c[i];
  }
  if (N <= 20) {
    int ans = 999999;
    for (int bit = 1; bit < (1 << N); bit++) {
      int a1 = 0;
      int b1 = 0;
      int money = 0;
      for (int i = 0; i < N; i++) {
        if (bit & (1 << i)) {
          a1 += a[i];
          b1 += b[i];
          money += c[i];
        }
      }
      int gc = __gcd(a1,b1);
      a1 /= gc;
      b1 /= gc;
      if (Ma == a1 && Mb == b1) {
        ans = min(ans,money);
      }
    }
    if (ans > 900000) {
      cout << -1 << endl;
    } else {
      cout << ans << endl;
    }
  } else {
    int DP[201][201];
    int ans = 999999;
    for (int i = 0; i <= 200; i++) {
      for (int j = 0; j <= 200; j++) {
        DP[i][j] = 999999;
      }
    }
    for (int bit = 0; bit < (1 << 20); bit++) {
      int a1 = 0;
      int b1 = 0;
      int money = 0;
      for (int i = 0; i < 20; i++) {
        if (bit & (1 << i)) {
          a1 += a[i];
          b1 += b[i];
          money += c[i];
        }
      }
      DP[a1][b1] = min(DP[a1][b1] , money);
    }
    for (int bit = 0; bit < (1 << 20); bit++) {
      int a2 = 0;
      int b2 = 0;
      int money2 = 0;
      for (int i = 0; i < N-20; i++) {
        if (bit & (1 << i)) {
          a2 += a[i+20];
          b2 += b[i+20];
          money2 += c[i+20];
        }
      }
      for (int i = 1; i <= 420; i++) {
        if (0 <= (Ma * i) - a2 && (Ma * i) - a2 <= 200 && 0 <= (Mb * i) - b2 && (Mb * i) - b2 <= 200) {
          ans = min(ans , DP[(Ma * i) - a2][(Mb * i) - b2] + money2);
        }
      }
    }
    if (ans > 900000) {
      cout << -1 << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 3760
import java.util.Scanner;
 
class Main {
 
	public static void main(String[] args) {
 
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		int[] A = new int[M];
		int[] B = new int[M];
		int[] count = new int[N+1];
		for(int i=0; i<=N; i++){
			count[i] = 0;
		}
		for(int i=0; i<M; i++){
			A[i]  = sc.nextInt();
			B[i]  = sc.nextInt();
			count[A[i]]++;
			count[B[i]]++;
		}
		int[][] dp = new int[N+1][];
		for(int i=0; i<=N; i++){
			dp[i] = new int[count[i]];			
		}
		for(int i=0; i<=N; i++){
			count[i] = 0;
		}
		for(int i=0; i<M; i++){
			dp[A[i]][count[A[i]]] = B[i];
			dp[B[i]][count[B[i]]] = A[i];
			count[A[i]]++;
			count[B[i]]++;
		}
 
		int[] ans = new int[2*N];
		ans[N] = A[0];
		int min = N;
		int max = N;
		boolean[] v = new boolean[N+1];
		for(int i=1;i<=N; i++){
			v[i] = true;
		}
		v[ans[N]] = false;
		boolean update = true;
		while(true){
			update = false;
			for(int i=0; i<count[ans[max]]; i++){
				if(v[dp[ans[max]][i]]==true){
					ans[max+1] = dp[ans[max]][i];
					v[dp[ans[max]][i]] = false;
					max++;
					update = true;
					break;
				}
			}
			for(int i=0; i<count[ans[min]]; i++){
				if(v[dp[ans[min]][i]]==true){
					ans[min-1] = dp[ans[min]][i];
					v[dp[ans[min]][i]] = false;
					min--;
					update = true;
					break;
				}
			}
			if(update==false){
				break;
			}
		}
 
		System.out.println(max-min+1);
		for(int j=min; j<max; j++){
			System.out.print(ans[j] + " ");
		}
		System.out.print(ans[max]);
 
	}
 
}

Measured memory_bytes: 79716
N, D = map(int, input().split())
xnds = [list(map(int, input().split())) for _ in range(N)]

# https://yatt.hatenablog.jp/entry/20130128/1359370204
def bisearch(f, n):
    l = 0
    r = n
    fl = f(l)
    fr = f(r)
    while l <= r:
        m = (l + r) // 2
        fm = f(m)
        if fm == n:
            return m
        elif fm > n:
            r = m - 1
            fr = f(r)
        else:
            l = m + 1
            fl = f(l)

def is_distance_integer(lista, listb):
    sum_ = 0
    for a, b in zip(lista, listb):
        sum_ += (a - b)** 2
    return bisearch(lambda n: n*n, sum_)


sum_ = 0
for i in range(N - 1):
    for xn in xnds[i + 1:]:
        if is_distance_integer(xnds[i], xn):
            sum_ += 1
print(sum_)


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

signed main(void)
{
	int n; cin >> n;
	int w[n], sum, s1, s2, ans;

	sum = 0;
	for(int i = 0; i < n; i++) 
	{
		cin >> w[i];
		sum += w[i];
	}
	ans = 1000000000;
	for(int i = 0; i < n; i++)
	{
		s1 = 0;
		for(int j = 0; j <= i; j++)
			s1 += w[j];
		s2 = sum - s1;
		ans = min(ans, abs(s2-s1));
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define F first
#define S second
#define MP make_pair
#define pb push_back
#define endl '\n'

using namespace std;

typedef long long LL;
typedef pair< int, int > P;
typedef pair< LL, LL > LP;
typedef pair< int, P > iP;
typedef pair< P, P > PP;

static const int INF = INT_MAX;
static const LL LINF = LLONG_MAX;
static const int MIN = INT_MIN;
static const LL LMIN = LLONG_MIN;
static const int MOD = 1000000007;

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
    return 0;
}



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

using namespace std;

long long n, b, r;
long long nn;

int main(void)
{
	scanf("%lld %lld %lld", &n, &b, &r);
	
	nn = n % (b + r);
	
	if(nn >= b)
		nn = b;
	
	printf("%lld", b * (n / (b + r)) + nn);
	return 0;
}

Measured memory_bytes: 256
MOD=10**9+7
def facinv(N):
    fac,finv,inv=[0]*(N+1),[0]*(N+1),[0]*(N+1)
    fac[0]=1;fac[1]=1;finv[0]=1;finv[1]=1;inv[1]=1
    for i in range(2,N+1):
        fac[i]=fac[i-1]*i%MOD
        inv[i]=MOD-inv[MOD%i]*(MOD//i)%MOD
        finv[i]=finv[i-1]*inv[i]%MOD
    return fac,finv,inv
def COM(n,r):
    if n<r or r<0:
        return 0
    else:
        return ((fac[n]*finv[r])%MOD*finv[n-r])%MOD
        
N,K=map(int,input().split())
A=sorted(map(int,input().split()))
fac,finv,inv=facinv(N)
ans=0
for i in range(N):
    if(i>0):
        ans=(ans+(A[i]*COM(i,K-1)%MOD))%MOD
    if(i<N-1):
        ans=(ans-(A[i]*COM(N-i-1,K-1)%MOD))%MOD
print(ans)

Measured memory_bytes: 19152
from sys import stdin
from collections import deque
def main():
    #入力
    readline=stdin.readline
    n,m=map(int,readline().split())
    G=[[] for _ in range(n*3)]
    for i in range(m):
        a,b=map(lambda x:int(x)-1,readline().split())
        for j in range(3):
            G[3*a+j].append(3*b+(j+1)%3)

    s,t=map(lambda x:int(x)-1,readline().split())
    s*=3
    t*=3
    #bfs
    d=deque([s])
    flags=[-1]*(3*n)
    flags[s]=0
    while len(d)>0:
        now=d.popleft()
        for nex in G[now]:
            if flags[nex]==-1:
                flags[nex]=flags[now]+1
                d.append(nex)

    print(flags[t]//3)

if __name__=="__main__":
    main()

Measured memory_bytes: 60192
import java.io.*;
import java.util.*;


public class Main {

	private static Scanner sc;
	private static Printer pr;

	private static void solve() {
		int n = sc.nextInt();

		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = sc.nextInt() - 1;
		}

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

		pr.println(ret / 2);
	}

	// ---------------------------------------------------
	public static void main(String[] args) {
		sc = new Scanner(System.in);
		pr = new Printer(System.out);

		solve();

		pr.close();
		sc.close();
	}

	private static class Printer extends PrintWriter {
		Printer(PrintStream out) {
			super(out);
		}
	}
}


Measured memory_bytes: 32380
#include <cstdio>

const int mod = 998244353, maxn = 1e6 + 10;

int n, m, ans, t, fac[maxn], ifac[maxn], inv[maxn];

int pow_mod(int x, int n) {
	int y = 1;
	while(n) {
		if(n & 1) {
			y = 1ll * y * x % mod;
		}
		x = 1ll * x * x % mod;
		n >>= 1;
	}
	return y;
}

void pre() {
	n = maxn - 1;
	fac[0] = 1;
	for (int i = 1; i <= n; ++i) {
		fac[i] = 1ll * fac[i - 1] * i % mod;
	}
	ifac[n] = pow_mod(fac[n], mod - 2);
	for (int i = n; i >= 1; --i) {
		ifac[i - 1] = 1ll * i * ifac[i] % mod;
	}
	for (int i = 1; i <= n; ++i) {
		inv[i] = 1ll * ifac[i] * fac[i - 1] % mod;
	}
	return;
}

int C(int n, int m) {
	return n < m || m < 0 ? 0 : 1ll * fac[n] * ifac[n - m] % mod * ifac[m] % mod;
}

int main() {
	pre();
	scanf("%d%d", &n, &m);
	if(n < m) {
		n ^= m;
		m ^= n;
		n ^= m;
	}
	ans = n;
	t = pow_mod(C(n + m, n), mod - 2);
	for (int i = 1; i <= m; ++i) {
		ans = (1ll * inv[2] * C(i + i, i) % mod * C(n + m - i - i, n - i) % mod * t + ans) % mod;
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 11904
#include <bits/stdc++.h>
#define meow(args...) fprintf(stderr, args)
typedef unsigned u32;
typedef long long s64;
typedef unsigned long long u64;
template<class T1, class T2> inline bool cmin(T1 &a, const T2 &b) {return b<a?(a=b, true):false;}
template<class T1, class T2> inline bool cmax(T1 &a, const T2 &b) {return a<b?(a=b, true):false;}
template<class Type> Type read() {
	Type a;
	bool b;
	unsigned char c;
	while(c=getchar()-48, (c>9)&(c!=253));
	for(a=(b=c==253)?0:c; (c=getchar()-48)<=9; a=a*10+c);
	return b?-a:a;
}
int (*rd)()=read<int>;
//const u32 P=;
//inline u32 &inc(u32 &a, u32 b) {return (a+=b)<P?a:(a-=P);}
//inline u32 &dec(u32 &a, u32 b) {return (a-=b)&0x80000000?(a+=P):a;}
//inline u32 sum(u32 a, u32 b) {return (a+=b)<P?a:a-P;}
//inline u32 dif(u32 a, u32 b) {return (a-=b)&0x80000000?a+P:a;}
//u64 power(u64 a, int b) {
//	u64 ans=1;
//	for(; b; a=a*a%P, b/=2) if(b&1) ans=ans*a%P;
//	return ans;
//}
const int N=2e5;
int n, m, a[N], b[N];
int main() {
	n=2*rd(), m=rd();
	std::generate(a, a+n, rd);
	std::sort(a, a+n);
	int l=0, r=n;
	while(l!=r) {
		int x=(l+r)/2;
		std::copy(a, a+x, b+n-x);
		for(int i=x; i<n; ++i) b[i-x]=a[i]-m;
		bool ok=true;
		for(int i=0, j=n; i<--j; ++i) ok&=b[i]+b[j]>=0;
		if(ok) r=x; else l=x+1;
	}
	std::copy(a, a+l, b+n-l);
	for(int i=l; i<n; ++i) b[i-l]=a[i]-m;
	int ans=0;
	for(int i=0, j=n; i<--j; ++i) cmax(ans, b[i]+b[j]);
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 1920
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  long long n,a,b;cin>>n>>a>>b;
  cout << n/(a+b)*a + min(a,n%(a+b)) << endl;
}


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

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    rep(i,n){
        cin >> x[i];
    }
    int ans = 2*(x[n-1]-x[0]);
    rep(i,n-k+1){
        int l = x[i];
        int r = x[i+k-1];
        int t0 = abs(l)+(r-l);
        int t1 = abs(r)+(r-l);
        ans = min(ans,min(t0,t1));
    }
    cout << ans << endl;
}


Measured memory_bytes: 640
using System;

namespace PrintTestCases
{
    class Program
    {
        static void Main(string[] args)
        {
            for(int i = 1;;i++)
            {
                string str = Console.ReadLine();
                int input = int.Parse(str);
                if (input == 0)
                    break;
                Console.WriteLine("Case {0}: {1}", i, input);

            }
        }
    }
}

Measured memory_bytes: 5776
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf (1ll<<30)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
using namespace std;

const int maxn=100010;
int n,Q;
struct node {int l,r;LL s,tag;}tr[maxn<<2];

void pushdown(int k) {
	int l=k<<1,r=k<<1|1;LL w=tr[k].tag;tr[k].tag=0;
	tr[l].s=(tr[l].r-tr[l].l+1)*w;tr[l].tag=w;
	tr[r].s=(tr[r].r-tr[r].l+1)*w;tr[r].tag=w;
}
void modify(int k,int s,int t,LL val) {
	int l=tr[k].l,r=tr[k].r,mid=(l+r)>>1;
	if (l==s && r==t) {tr[k].s=val*(tr[k].r-tr[k].l+1);tr[k].tag=val;return;}
	if (tr[k].tag) pushdown(k);
	if (t<=mid) modify(k<<1,s,t,val);
	else if (s>mid) modify(k<<1|1,s,t,val);
	else modify(k<<1,s,mid,val),modify(k<<1|1,mid+1,t,val);
	tr[k].s=tr[k<<1].s+tr[k<<1|1].s;
}
void build(int k,int s,int t) {
	tr[k].l=s;tr[k].r=t;
	if (s==t) return;
	int mid=(s+t)>>1;
	build(k<<1,s,mid);
	build(k<<1|1,mid+1,t);
}
LL query(int k,int s,int t) {
	int l=tr[k].l,r=tr[k].r,mid=(l+r)>>1;
	if (l==s && r==t) return tr[k].s;
	if (tr[k].tag) pushdown(k);
	if (t<=mid) return query(k<<1,s,t);
	else if (s>mid) return query(k<<1|1,s,t);
	else return query(k<<1,s,mid)+query(k<<1|1,mid+1,t);
}

int main() {
	scanf("%d%d",&n,&Q);
	build(1,1,n);
	for (int x,i=1;i<=Q;i++) {
		LL y;
		scanf("%d%lld",&x,&y);
		if (x==1) {modify(1,1,1,query(1,1,1)+y);continue;}
		if (query(1,x-1,x-1)-query(1,x,x)>=y) {modify(1,x,x,query(1,x,x)+y);continue;}
		int l=2,r=x,pos;
		while (l<=r) {
			int mid=(l+r)>>1;
			if (query(1,mid-1,mid-1)*(x-mid+1)-query(1,mid,x)<=y) r=mid-1,pos=mid;
			else l=mid+1;
		}
		LL val=query(1,pos-1,pos-1),num=x-pos+1;
		y-=val*num-query(1,pos,x);
		modify(1,pos,x,val);++num;
		if (y/num) modify(1,pos-1,x,val+y/num);
		if (y%num) modify(1,pos-1,pos-2+y%num,val+y/num+1);
	}
	for (int i=1;i<=n;i++) printf("%lld\n",query(1,i,i));
	return 0;
}


Measured memory_bytes: 9728
l,r=map(int,input().split())
ans=2019
y=r

while l<r:
  y=r
  while l<y:
    x=l*y
    x=x%2019
    if x<ans:
      ans=x
    if ans==0:
      break
    y=y-1
  if ans==0:
    break
  l=l+1
print(ans)



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

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


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

int main() {
	char str[6];

	for (int i = 0; i < 6; i++) {
		cin >> str[i];
	}

	if (str[2] == str[3] && str[4] == str[5]) {
		cout << "Yes\n";
	}
	else {
		cout << "No\n";
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pi 3.14159265359
#define int long long
#define pii pair<int,int>
#define ld long double
const int mod=1e9 + 7;
 
int dx[]={-1, 0, 1, 0};
int dy[]={0, -1, 0, 1};
 
 
 
 
int32_t main()
{
ios::sync_with_stdio(false);
cin.tie(0);
cout.tie(0);


int n;
cin>>n;
vector<int>v(n);  map<int,int>m;
for(int i=0;i<n;i++)
{
  cin>>v[i];
}
 
int cnt=0; int x=1; m[0]=1; int j=0;
for(int i=1;i<=n;i++)
{
  if(m[i-1]==0)break;

  while(j<n && v[j]!=i)
  {
    j++;
  }

  if(j!=n && v[j]==i)
  {m[i]=1; cnt++; }

}

if(cnt==0)
{
cout<<-1; return 0;}
cout<<n-cnt<<"\n";


}

Measured memory_bytes: 14336
using System;

namespace BlackJack
{
    class Program
    {
        static void Main(string[] args)
        {
            String[] str;
            str = Console.ReadLine().Split(' ');
            int A1 = int.Parse(str[0]);
            int A2 = int.Parse(str[1]);
            int A3 = int.Parse(str[2]);

            if (A1 + A2 + A3 >= 22)
            {
                Console.WriteLine("bust");
            }
            else
            {
                Console.WriteLine("win");
            }
        }
    }
}


Measured memory_bytes: 11092
using static System.Console;
using static System.Math;

class AtCoder 
{
    public static void Main()
    {
        var s = ReadLine();
        int ans = 0;
        int ct;
        for (int i = 0; i < s.Length; i++){
            ct = 0;    
            while (i+ct < s.Length && isACGT(s[i+ct])){ ct++; }
            ans = Max(ans, ct);
        }
        WriteLine(ans);
    }

    static bool isACGT(char c) {
        return (c == 'A' || c == 'C' || c == 'G' || c == 'T');
    }
}

Measured memory_bytes: 13140