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

using namespace std;

typedef long long ll;
typedef double long dl;
typedef pair < int , int > pii;
typedef pair < pii, pii > p2i;
const int maxn = (int) 3e5 + 1;
const int mod = (int) 1e9 + 7;
const ll inf = (ll)1e18;

#define fi first
#define se second
#define acel ios_base :: sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define next continue

int a, b, c;
vector < int > g;
int main(){
    cin >> a >> b >> c;
    g.push_back(a);
    g.push_back(b);
    g.push_back(c);
    sort(g.begin(), g.end());
    if(g[0] % 2 == g[1] % 2 && g[1] % 2 == g[2] % 2){
        cout << ((g[2] - g[0]) / 2) + ((g[2] - g[1]) / 2);
        return 0;
    }
    if(g[1] % 2 == g[2] % 2){
        g[1]++, g[2]++;
        cout << 1 + ((g[2] - g[0]) / 2) + ((g[2] - g[1]) / 2);
        return 0;
    }
    if(g[1] % 2 == g[0] % 2){
        g[1]++, g[0]++;
        cout << 1 + ((g[2] - g[0]) / 2) + ((g[2] - g[1]) / 2);
        return 0;
    }
    if(g[2] % 2 == g[0] % 2){
        g[2]++, g[0]++;
        cout << 1 + ((g[2] - g[0]) / 2) + ((g[2] - g[1]) / 2);
        return 0;
    }

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;
typedef pair<int,int> pii;

struct dat{
    int t,y,x,r,dir;
    bool operator< (const dat &d) const{
        return t > d.t;
    }
};

bool in(ll y, ll x, ll h, ll w){
    return 0 <= y && y < h && 0 <= x && x < w;
}

int main(){
    int h,w,k; cin >> h >> w >> k;
    int sy,sx,gy,gx; cin >> sy >> sx >> gy >> gx;
    sy--; sx--; gy--; gx--;
    vs s(h); rep(i,h) cin >> s[i];
    vector<vector<vector<int>>> v(h,vector<vector<int>>(w,vector<int>(4,inf)));
    rep(i,4) v[sy][sx][i] = 0;
    priority_queue<dat> q;
    rep(i,4) q.push({0,sy,sx,0,i});
    while(!q.empty()){
        dat d = q.top(); q.pop();
        rep(i,4){
            int ny = d.y + dy[i];
            int nx = d.x + dx[i];
            if(!in(ny,nx,h,w)) continue;
            if(s[ny][nx] == '@') continue;
            if(d.dir == i){
                int t = d.t;
                int r = d.r;
                if(r == 0) r = k-1, t++;
                else r--;
                if(v[ny][nx][i] <= t) continue;
                v[ny][nx][i] = t;
                q.push({t,ny,nx,r,i});
            }else{
                if(v[ny][nx][i] <= d.t + 1) continue;
                v[ny][nx][i] = d.t + 1;
                q.push({d.t + 1,ny,nx,k-1,i});
            }
        }
    }
    int ans = inf;
    /*rep(k,4){
        rep(i,h){
            rep(j,w) cout << v[i][j][k] << " ";
            cout << "\n";
        }
        cout << "\n";
    }*/
    rep(i,4){
        chmin(ans, v[gy][gx][i]);
    }
    if(ans == inf) puts("-1");
    else cout << ans << "\n";
}

Measured memory_bytes: 113536
import java.util.*;

public class Main {
    public static void main(String[] args) {
      
      Scanner sc = new Scanner(System.in);
      int a = Integer.parseInt(sc.next());
      int b = Integer.parseInt(sc.next());
      int c = Integer.parseInt(sc.next());
      if (c - (a - b) >= 0) {
        System.out.println(c - (a - b));
      } else {
        System.out.println(0);
      }
    }
}

Measured memory_bytes: 21844
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt();
    int b=sc.nextInt();
    sc.close();
    int ans=0;
    for(int i=0;i<25;i++){
      if((a*i-i+1)>=b){
        ans=i;
        break;
      }
    }
    System.out.println(ans);
  }
}

Measured memory_bytes: 22868
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
int n;
pii a[200010];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n;
  	for(int i=0;i<n;i++)cin>>a[i].second>>a[i].first;
  	sort(a,a+n);
 	int now=0;
  	for(int i=0;i<n;i++){
   		now=now+a[i].second;
    	if(now>a[i].first){
      		cout<<"No";
      		return 0;
    	}
	}
	cout<<"Yes";
	return 0;
}



Measured memory_bytes: 1792
def calc(num):
    if num % 26 != 0:
        res.append(num % 26)
    else:
        res.append(26)
        num -= 26

    if num // 26 > 0:
        calc(num // 26)

def printres():
    for obj in reversed(res):
        print(dic[obj], end="")
    print()

dic = {1:"a", 2:"b", 3:"c", 4:"d", 5:"e", 6:"f", 7:"g", 8:"h", 9:"i", 10:"j", 11:"k", 12:"l", 13:"m", 14:"n", 15:"o", 16:"p", 17:"q", 18:"r", 19:"s", 20:"t", 21:"u", 22:"v", 23:"w", 24:"x", 25:"y", 26:"z"}

res = []


N = int(input())

calc(N)

printres()

Measured memory_bytes: 9236
/*
    ahuhu :((
*/
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <utility>
#include <queue>
#include <deque>
#include <string>
#include <cstring>
using namespace std;

#define SZ size()
#define BG begin()
#define ED end()
#define pb push_back
#define mp make_pair
#define st first
#define nd second
#define FOR(i, a, b)  for (int i = (a), _b = (b);  i< _b; ++i)
#define FORD(i, a, b) for (int i = (a), _b = (b); i >= _b; --i)
#define FORE(i, a, b) for (int i = (a), _b = (b); i <= _b; ++i)
#define openfile ({freopen(TASK".inp", "r", stdin); freopen(TASK".out", "w", stdout);})

typedef vector <int> VI;
typedef pair <int, int> II;
typedef long long LL;
typedef long double LD;

const int N = (int) (2505);
const int LOGN = log2(N) + 2;
const LL MOD = (LL) (1e9 + 7);
const LL INF = (LL) 1e18;
const double PI = 2 * acos(0);
const double EPS = 1e-9;

template <typename T> inline void read(T &n) {
    n = 0; char ch; bool neg = false;
    for (ch = getchar(); ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') neg = !neg; n = ch - 48;
    for (ch = getchar(); ch >= '0' && ch <= '9'; ch = getchar()) n = (n << 1) + (n << 3) + ch - 48; if (neg) n = -n;
}
template <typename T> inline void writee(T n) { if (n > 9) writee(n / 10); putchar(n % 10 + 48); }
template <typename T> inline void write(T n) { if (n < 0) { putchar('-'); n = -n; } writee(n); }
template <typename T> inline void writeln(T x) { write(x); putchar('\n'); }
inline long long __lcm(long long a, long long b) { return a / __gcd(a, b) * b; }
inline long long power(long long a, long long n) {
    long long r = 1;
    while (n) {
        if (n & 1) r = r * a % MOD;
        a = a * a % MOD;
        n >>= 1;
    }
    return r;
}
inline void add(int &a, const int& b) { a = (a + b) % MOD; }
inline void sub(int &a, const int& b) { a = (a - b + MOD) % MOD; }

int n;
int a[N];

int main() {
    ios_base :: sync_with_stdio(false); cin.tie(NULL);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    long long ans = 1;
    for (int i = 1; i <= n; i++) {
        long long cnt = 0;
        for (int j = a[i] - 1; j <= a[i] + 1; j++) cnt++;
        ans *= cnt;
    }
    long long temp = 1;
    for (int i = 1; i <= n; i++) {
        long long cnt = 0;
        for (int j = a[i] - 1; j <= a[i] + 1; j++) 
            if (j % 2 == 1)cnt++;
        temp *= cnt;
    }
    cout << ans - temp;
    return 0;
}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
b=0
for i in range(n):
    minj=i
    for j in range(i,n):
        if a[minj]>a[j]:
            minj=j
    if i!=minj:
        a[i],a[minj]=a[minj],a[i]
        b+=1
print(*a)
print(b)


Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main(){
  int N;
  cin>>N;
  vector<long long> a(N);
  for(int i=0;i<N;i++) cin>>a[i];
  int initial_sign[2]={-1,1};
  vector<long long> res(2);
  for(int i=0;i<2;i++){
    long long cumsum=0;
    long long current_sign=initial_sign[i];
    for(int j=0;j<N;j++){
        cumsum+=a[j];
        if(cumsum*current_sign<=0){
          res[i]+=abs(cumsum-current_sign);
          cumsum=current_sign;
        }
        current_sign=-1*current_sign;
    }
  }
  cout << min(res[0],res[1]);
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mk make_pair
#define fs first
#define sc second
using namespace std;
typedef long long ll;
typedef long double ld;
ll b[4], n, mem[4][3333];
ll dp(ll x, ll sm){
    if(x==3){
        return sm==0;
    }
    if(mem[x][sm]!=-1)
        return mem[x][sm];
    ll res=0;
    for(ll i=0; i*b[x]<=sm; ++i){
        res+=dp(x+1, sm-i*b[x]);
    }
    mem[x][sm]=res;
    return res;
}
int main(){
    while(cin>>b[0]>>b[1]>>b[2]>>n){
        ll ans=0;
        memset(mem, -1, sizeof mem);
        ans=dp(0,n);
        cout<<ans<<endl;
    }
  return 0;
}




Measured memory_bytes: 384
arr = list(map(int, input().split()))

max_v = max(arr)
sum_arr = sum(arr)

if (max_v*3 - sum_arr) % 2:
    # 奇数の場合
    print(((max_v+1)*3 - sum_arr) // 2)
else:
    # 偶数の場合
    print((max_v*3 - sum_arr) // 2)

Measured memory_bytes: 9176
import sys
def inpl(): return list(map(int, sys.stdin.readline().split()))

n = int(input())
a = inpl()
flag = 0
t = 1
for i in range(0, n):
    if a[i] == 0:
        flag = 1
        print(0)
        break

aaa = 0

if not flag:
    
    for i in range(0, n):
        t *= a[i]
        if t > 1000000000000000000:
            print(-1)
            aaa = 1
            break
    if not aaa:
        print(t)



Measured memory_bytes: 21776
S=gets.chomp.chars
EVEN=S.select.with_index{|s,idx| (idx-1).even?}.uniq
ODD=S.select.with_index{|s,idx| (idx-1).odd?}.uniq

if !EVEN.include?("R") && !ODD.include?("L")
  puts "Yes"
else
  puts "No"
end

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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e5+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(ll i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()

#define sqr(a) ((a) * (a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define mem(a,b) memset(a,b,sizeof(a))

#define yes cout<<"YES"<<nl;
#define no cout<<"NO"<<nl;

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}

ll we[mx],v[mx],W,n,dp[101][mx];

ll fun(ll i,ll w)
{
    if(i>n)
        return 0;

    if(dp[i][w] != -1)
        return dp[i][w];

    ll t1=0,t2=0;
    if(w+we[i]<=W)
        t1=v[i]+fun(i+1,w+we[i]);
    t2=fun(i+1,w);

    dp[i][w]=max(t1,t2);

    return dp[i][w];
}

int main()
{
    su;

    mem(dp,-1);

    cin>>n>>W;

    for(int i=1; i<=n; i++)
    {
        cin>>we[i]>>v[i];
    }

    cout<<fun(1,0)<<nl;

    return 0;
}


Measured memory_bytes: 82536
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(int i=(begin);i<(end);i++)
#define REP(i, n) FOR(i,0,n)
#define IFOR(i, begin, end) for(int i=(end)-1;i>=(begin);i--)
#define IREP(i, n) IFOR(i,0,n)
#define SORT(a) sort(a.begin(), a.end())
#define REVERSE(a) reverse(a.begin(), a.end())
#define int long long
#define INF 1000000000000000
using namespace std;

typedef vector<int> vec;
typedef vector<vec> mat;
typedef pair<int, int> Pii;

template<typename T>
void readvec(vector<T> &a);
void readindex(vector<int> &a);

int mod = 1000000007;

signed main(){

    int N; cin >> N;
    string S1, S2; cin >> S1 >> S2;

    int i = 0;
    vec p(0);
    while(i < N){
        if(S1[i] == S2[i]){
            p.push_back(0);
            i++;
        }else{
            p.push_back(1);
            i += 2;
        }
    }

    int ans;
    if(p[0] == 0){
        ans = 3;
    }else{
        ans = 6;
    }
    REP(i, p.size() - 1){
        if(p[i] == 0) ans *= 2;
        if(p[i] == 1 & p[i + 1] == 1) ans *= 3;
        ans %= mod;
    }

    cout << ans;

    return 0;
}


template<typename T>
void readvec(vector<T> &a){
    REP(i, a.size()){
        cin >> a[i];
    }
}
void readindex(vector<int> &a){
    REP(i, a.size()){
        cin >> a[i];
        a[i]--;
    }
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}
func bOut(f bool, x string, y string) {
	if f {
		fmt.Println(x)
	} else {
		fmt.Println(y)
	}
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	edges := make([][]int, n)
	for i := 0; i < n-1; i++ {
		a, b := iScan()-1, iScan()-1
		edges[a] = append(edges[a], b)
		edges[b] = append(edges[b], a)
	}
	q := make([]int, 1, n)
	d := make([]int, n)
	for i, _ := range d {
		d[i] = -1
	}
	d[0] = 0
	for len(q) != 0 {
		x := q[0]
		q = q[1:]
		for _, v := range edges[x] {
			if d[v] == -1 {
				q = append(q, v)
				d[v] = d[x] + 1
			}
		}
	}
	idx := -1
	mx := max(d)
	for i, v := range d {
		if v == mx {
			idx = i
			break
		}
	}
	r := make([]int, 1, n)
	e := make([]int, n)
	for i, _ := range e {
		e[i] = -1
	}
	r[0] = idx
	e[idx] = 0
	for len(r) != 0 {
		x := r[0]
		r = r[1:]
		for _, v := range edges[x] {
			if e[v] == -1 {
				r = append(r, v)
				e[v] = e[x] + 1
			}
		}
	}
	m := max(e) + 1
	dp := make([]bool, m+1)
	for i := 1; i <= m; i++ {
		if i == 1 {
			dp[i] = true
		} else if i == 2 {
			dp[i] = false
		} else {
			dp[i] = !(dp[i-1] && dp[i-2])
		}
	}
	bOut(dp[m], "First", "Second")
}


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

// def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
const int M = 1e9 + 7;
const int INF = 1e9;
const int MAX_V = 300 + 5;
const int MAX_N = 1e5 + 5;

int main() {
    int n, y;
    bool clear = false;
    cin >> n >> y;
    rep(i, n + 1) {
        rep(j, n + 1) {
            int k = n - i - j;
            if (10000 * i + 5000 * j + 1000 * k == y && k >= 0) {
                cout << i << " " << j << " " << k << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ld = long double;
int main(){
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout << fixed;
  cout.precision(40);
  int n;
  cin >> n;
  vector<ld> pb(n+1);
  pb[0] = 1;
  ld p;
  for(int i = 0; i < n; ++i){
    cin >> p;
    for(int j = i+1; j >= 0; --j){
      pb[j] *= 1-p;
      if(j > 0) pb[j] += pb[j-1]*p;
    }
  }
  ld ans = 0;
  for(int i = (n+1)/2; i <= n; ++i) ans += pb[i];
  cout << ans;
  return 0;
}

Measured memory_bytes: 3896
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, M, i, S = 0;
  cin >> N >> M;
   for (i = 0; i < M; i++) {
    int Ai;
    cin >> Ai;
    S += Ai;
  }
  if (S <= N) {
    cout << N - S <<endl;
  }
  else if (S > N) {
    cout << - 1 <<endl;
  }
}
  


Measured memory_bytes: 3632
#include<vector>
#include <iostream>

using namespace std;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int c = 0;
    for(int i = 0; i < n/2; i++){
        if(s[i] == s[i+n/2]){
            c++;
        }
    }
    if(c == n/2 && n >= 2 && n <= 100 && n % 2 == 0){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}

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

#define for_(i,a,b) for(int i=a; i<b; ++i)
#define for_rev(i,a,b) for(int i=a;i>=b;--i)
#define allof(a) a.begin(),a.end()
#define minit(a,b) memset(a,b,sizeof(a))
#define size_of(a) (int)a.size()

int main() {
	int n; cin >> n;
	int sub = (int)1e9;
	int ans = -1;
	
	for_(i,0,10*n) {
		stringstream ss;
		ss << i;
		
		string s = ss.str();
		string sr = s;
		reverse(allof(sr));
		
		if (s == sr) {
			if (sub > abs(n - i)) {
				sub = abs(n - i);
				ans = i;
			}
		}
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 1224
#include <bits/stdc++.h>
using namespace std;
//debug
#ifdef grief
#define debug(...) do{\
	fprintf(stderr , "%s - %d : (%s) = " , __PRETTY_FUNCTION__ , __LINE__ , #__VA_ARGS__ );\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){
	cerr<<x<<endl;
}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){
	cerr<<x<<" , ";
	_DO(tail...);
}
#else
#define debug(...)
#endif
//type
typedef long long ll;
typedef pair<int,int> pii;
typedef long long ll;
typedef pair<ll,ll> pll;
typedef priority_queue<pll,vector<pll>,greater<pll> > heap;
//macro
#define SZ(x) ((ll)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define F first
#define S second
#define REP(i,n) for(ll i=0;i<(n);i++)
#define REP1(i,a,b) for(ll i=(a);i<=(b);i++)
#define mkp make_pair
#define pb push_back
const ll INF=1e18;
const ll MA=1e6+5;
const ll MOD=1e9+7;
//}}}
ll n,m;
ll ans;
int main(){
	cin>>n>>m;
	ans=min(n,m/2);
	n-=ans; m-=ans*2;
	ans+=m/4;
	cout<<ans<< '\n';
	
	return 0;
}

Measured memory_bytes: 256
s = input()
n = len(s)
flag = False


def palind(S):
    size = len(S)
    for i in range(size//2):
        if S[i] != S[-1-i]:
            return False
    return True



if palind(s):
    m = (n-1)//2
    sb = s[:m]
    if palind(sb):
        sa = s[m+1:]
        flag = palind(sa)

print("Yes" if flag else "No")


Measured memory_bytes: 9056
#include <stdio.h>

int main(void){
  int N,K;
  scanf("%d%d",&N,&K);
  int ans = 1;

  for(int i = 0;i < N;i++){
    if(ans <= K){
      ans *= 2;
    }else{
      ans += K;
    }
  }
  printf("%d\n",ans);

  return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

const int M=105;
char s[M],t[M];

int main()
{
	int n;
	scanf("%d",&n);
	scanf("%s%s",s,t);
	for(int i=0;i<n;i++)
	{
		putchar(s[i]);
		putchar(t[i]);
	}
	putchar('\n');
}

Measured memory_bytes: 128
import java.util.Scanner;


public class Main {

    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt(), t =in.nextInt();
        int w = n-t ;
            if (n < t) {
                System.out.println(0);
            } else if (n >= t)

                System.out.println(w);

    }
}













Measured memory_bytes: 22996
#include<bits/stdc++.h>
using namespace std;
signed main(){
  int N,K;
  string S;
  cin>>N>>S>>K;
  char C=S[K-1];
  for (int i=0; i<N; i++){
    if(S[i]!=C)S[i]='*';
  }
  cout<<S<<endl;
}


Measured memory_bytes: 3560
#include <stdio.h>

int primeCount;
int primeList[500000];
char primeFlag[1000001];

void makePrimeList(void) {
	int i,j;
	for(i=0;i<=1000000;i++)primeFlag[i]=1;
	primeFlag[0]=primeFlag[1]=0;
	primeCount=0;
	for(i=2;i<=1000000;i++) {
		if(primeFlag[i]) {
			primeList[primeCount++]=i;
			for(j=i+i;j<=1000000;j+=i)primeFlag[j]=0;
		}
	}
}

int bitcount(unsigned int n) {
	n=((n & 0xAAAAAAAA)>>1)+(n & 0x55555555);
	n=((n & 0xCCCCCCCC)>>2)+(n & 0x33333333);
	n=((n & 0xF0F0F0F0)>>4)+(n & 0x0F0F0F0F);
	n=((n & 0xFF00FF00)>>8)+(n & 0x00FF00FF);
	n=((n & 0xFFFF0000)>>16)+(n & 0x0000FFFF);
	return n;
}

int gcd(int a,int b) {
	return b==0?a:gcd(b,a%b);
}

int lcm(int a,int b) {
	return a/gcd(a,b)*b;
}

long long answer[1000001];

int main(void) {
	int t,n;
	int i;
	makePrimeList();
	for(i=1;i<=1000000;i++) {
		int yakusuuList[10];
		int yakusuuNum=0;
		int j;
		int jmax;
		int nowanswer;
		int tempi=i;
		for(j=0;primeList[j]*primeList[j]<=i;j++) {
			if(tempi%primeList[j]==0) {
				yakusuuList[yakusuuNum++]=primeList[j];
				while(tempi%primeList[j]==0)tempi/=primeList[j];
			}
		}
		if(tempi>1)yakusuuList[yakusuuNum++]=tempi;
		jmax=1<<yakusuuNum;
		nowanswer=0;
		for(j=1;j<jmax;j++) {
			int bit=bitcount(j);
			int yaku=1;
			int k;
			for(k=0;k<yakusuuNum;k++) {
				if(j&(1<<k))yaku=lcm(yaku,yakusuuList[k]);
			}
			if(bit%2==0)nowanswer-=(i-1)/yaku; else nowanswer+=(i-1)/yaku;
		}
		answer[i]=i-1-nowanswer;
	}
	answer[1]=2;
	for(i=1;i<=1000000;i++)answer[i]+=answer[i-1];

	scanf("%d",&t);
	for(i=0;i<t;i++) {
		scanf("%d",&n);
		printf("%lld\n",answer[n]);
	}
	return 0;
}

Measured memory_bytes: 10828
#pragma warning disable

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Text.RegularExpressions;
using System.Diagnostics;
using System.Numerics;
using System.Collections;
using System.Timers;

static class MainClass
{
    public static void Main(string[] args)
    {
        var t = Console.ReadLine().ToInt32();
        var minutes = t / 60;
        var sec = t % 60;
        var min = minutes % 60;
        var hour = minutes / 60;
        Console.WriteLine($"{hour}:{min}:{sec}");
    }

    #region ライブラリ

    #region 文字列処理

    public static int ToInt32(this string str) => int.Parse(str);
    public static BigInteger ToBigInteger(this string str) => BigInteger.Parse(str);
    public static List<string> SplittedStringToList(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).ToList();
    public static List<int> SplittedStringToInt32List(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => int.Parse(x)).ToList();

    public static List<BigInteger> SplittedStringToBigInteger(this string str) => str.Split(new[] { ' ' }, StringSplitOptions.RemoveEmptyEntries).Select(x => BigInteger.Parse(x)).ToList();
    #endregion
    #region DeepClone
    public static T DeepClone<T>(this T src)
    {
        using (var memoryStream = new MemoryStream())
        {
            var binaryFormatter
              = new BinaryFormatter();
            binaryFormatter.Serialize(memoryStream, src);
            memoryStream.Seek(0, SeekOrigin.Begin);
            return (T)binaryFormatter.Deserialize(memoryStream);
        }
    }
    #endregion

    public static int Gcd(int a,int b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }
    public static BigInteger Gcd(BigInteger a, BigInteger b)
    {
        if (b == 0)
            return a;
        return Gcd(b, a % b);
    }


    public static BigInteger Factorial(int n)
    {
        var dp = new BigInteger[n];
        dp[0] = 1;
        for (int i = 1; i < n; i++)
        {
            dp[i] = dp[i - 1] * (i + 1);
        }
        return dp[n - 1];
    }

    #endregion

}



Measured memory_bytes: 19984
#include <bits/stdc++.h>                                
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef long double ld;

string s,t;
int res;
                                                                                                                    
int main() 
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);                                                                                         
	cout.tie(0);
	srand(time(0)); 
	#ifdef LOCAL
         	freopen("input.txt", "r", stdin);
        	freopen("output.txt", "w", stdout);
        #endif  
        cin >> s >> t;
        for (int i = 0; i < 3; i++) {
        	if (s[i] == t[i])
        		res++;
        }
        cout << res;
        return 0;
}                

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int const nax = 3e5 + 10;
using ll = long long;

ll ans;

bool ok (ll x, ll y) {
    //fprintf(stderr, "%lld\n", y);
    while (x % y == 0) {
        x /= y;
    }

    return x % y == 1;

}

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

    for (ll i = 2 ; i * i <= n ; ++ i) {
        if (n % i == 0) {
            ans += ok(n, i);
            if (n != i * i)
            ans += ok(n, n / i);
        }
    }

    if (n > 2) {
        for (ll i = 2 ; i * i  <= (n - 1) ; ++ i) {
            if ((n - 1) % i == 0) {
                ll x = i;
                if ((n % x) > 0)
                ans += ok(n, x);

                if (i * i != (n - 1)) {
                    x = (n - 1) / i;
                    if ((n % x) > 0) {
                    ans += ok(n, x);
                    }
                }
            }
        }
    }

    ++ ans;
    if (n % (n - 1) > 0) {
        ++ ans;
    }

    printf("%lld\n", ans);
}
/*
    Good Luck
        -Lucina
*/


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

const int N=100005;
int n,m,dp[3005][3005],ans[3005],cnt;
int fax[3005][3005],fay[3005][3005];
char s[N],t[N];

int main()
{
	scanf("%s%s",s,t);
	n=strlen(s),m=strlen(t);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(dp[i-1][j]>dp[i][j-1])
			{
				dp[i][j]=dp[i-1][j];
				fax[i][j]=i-1,fay[i][j]=j;
			}
			else
			{
				dp[i][j]=dp[i][j-1];
				fax[i][j]=i,fay[i][j]=j-1;
			}
			if(s[i-1]==t[j-1])
			{
				if(dp[i-1][j-1]+1>dp[i][j])
				{
					dp[i][j]=dp[i-1][j-1]+1;
					fax[i][j]=i-1,fay[i][j]=j-1;
				}
			}
		}
	}
	int x=n,y=m;
	for(int i=1;i<=dp[n][m];i++)
	{
		while(fax[x][y]==x||fay[x][y]==y)
		{
			if(x!=fax[x][y]) x=fax[x][y];
			else y=fay[x][y];
		}
//		cout<<x<<' '<<y<<endl;
		ans[++cnt]=x-1;
		x=fax[x][y],y=fay[x][y];
	}
	for(int i=cnt;i>=1;i--) printf("%c",s[ans[i]]);
	printf("\n");
}

Measured memory_bytes: 105984
import java.util.Scanner;

public class Main{
	
	public static void main(String [] args) {
		Scanner scan = new Scanner(System.in);
		int size = scan.nextInt();
		int[][] graph = new int[size][size];
		
		int id = 0;
		int cols = 0;
		int[] row = new int[0];
		for(int i = 0; i < size; i++) {
			id = scan.nextInt();
			cols = scan.nextInt();
			row = new int[size];
			for(int j = 0; j < cols; j++)
				row[scan.nextInt() - 1] = 1;
			graph[id - 1] = row;
		}
		
		for(int i = 0; i < graph.length; i++) {
			for(int j = 0; j < graph[i].length; j++){
				System.out.print(graph[i][j]);
				if(j < graph[i].length - 1)
					System.out.print(" ");
			}
			System.out.println();
		}
	}
}



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

int main() {
	int N;
	cin >> N;
	map<int, int> mii;
	int tmp;
	rep (i, N) {
		cin >> tmp;
		++mii[tmp];
	}

	int64 ans = 0;
	auto end = mii.end();
	for (auto itr = mii.begin(); itr != end; ++itr) {
		int f = itr->first;
		int s = itr->second;
		ans += f * (int64)s;
	}

	int Q;
	cin >> Q;
	int tmp1, tmp2;
	rep (i, Q) {
		cin >> tmp1 >> tmp2;
		
		ans += mii[tmp1] * tmp2 - mii[tmp1] * tmp1;

		mii[tmp2] += mii[tmp1];
		mii.erase(tmp1);

		cout << ans << "\n";
	}

	return 0;
}


Measured memory_bytes: 6524
s = input()
t = input()
ans = len(t)
for i in range(len(s)-len(t)+1):
         tmp = len(t)
         for j in range(len(t)):
                  if s[i+j] == t[j]:
                           tmp -= 1
         if ans > tmp:
                  ans = tmp
print(ans)


Measured memory_bytes: 9104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vl;
typedef vector<int> vi;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> vvl;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvec;
typedef vector<vector<bool>> vveb;
typedef vector<vector<string>> vves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define rev(v) reverse(v.begin(), v.end())
#define fs first
#define sc second
#define pb push_back
#define pp pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
#define dame { puts("-1"); return 0;}
#define YES { cout << "YES" << endl; return 0; }
#define NO { cout << "NO" << endl; return 0; }
#define Yes { cout << "Yes" << endl; return 0; }
#define No { cout << "No" << endl; return 0; }
#define uniq(a) sort(all(a));(a).resize(unique(all(a)) - a.begin());
#define dab(v) for(auto i:v)cout<<i<<' '; cout << endl;
#define vin(v) for (ll i = 0; i < v.size(); ++i) cin >> v[i];
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; }
int dx[] = {0, 0, -1, 1};
int dy[] = {1, -1, 0, 0};

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    //cout << fixed << setprecision(15);
    
    ll N,A,B; cin >> N >> A >> B;
    if((B-A)%2==0){
        cout << (B-A) / 2 << endl;
    }else{
        cout << min(A,N-B+1) + (B-A-1) / 2 << endl;
    }
}

Measured memory_bytes: 256
int G(x,y){return y?G(y,x%y):x;}
main(g,X,Y,x,y,z,t,f){for(;~scanf("%d%d",&x,&y);){
g=G(x,y);X=x/=g;Y=y/=g;
for(z=0;y%2==0;y/=2)z++;
for(f=0;y%5==0;y/=5)f++;
if(y==1)t=0;else{x=1;t=0;do{x=x*10%y;t++;}while(x!=1);}
if(z>f)f=z;
for(g=0;g<f+t;g++)putchar(X*10/Y+48),X=X*10%Y;puts("");
if(t){for(;f>0;f--)putchar(' ');for(;t>0;t--)putchar('^');puts("");}
}exit(0);}

Measured memory_bytes: 584
#include<iostream>
#include<vector>
#include<map>
#include<set>
#include<numeric>
#define ll long long
#define MOD = 1e9+7
 
using namespace std;
 
int main() {
  int A,B,C,D;
  cin >> A >> B >> C >> D;
  for(int i=0;i<100;i++){
    C = C - B;
    if(C<=0){
      cout << "Yes" << endl;
      break;
    }
    A = A - D;
    if(A<=0){
      cout << "No" << endl;
      break;
    }
  }
}


Measured memory_bytes: 3128
#include<stdio.h>
#define N 1000
int main(){
  int i,j,k,n,a[N][N],m,b;
  scanf("%d",&n);
  for(k=0;k<n;k++){
    scanf("%d%d",&i,&m);
    for(j=0;j<m;j++){
      scanf("%d",&b);
      a[i-1][b-1]=1;
  }
}
  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      if(a[i][j]!=1)a[i][j]=0;
      printf("%d",a[i][j]);
      if(j!=n-1)printf(" ");
    }
    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2160
import java.util.Scanner;
class Main{
    public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		String str;
		String moji;
		int cnt=0;
		str=sc.next();
		moji=sc.next();
		while(moji.compareTo("END_OF_TEXT")!=0){
			if(moji.compareToIgnoreCase(str)==0){
				cnt++;
			}
			moji=sc.next();
		}
		System.out.println(cnt);
    }
}




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

using namespace std;

int solve(vector<int> &costs, int a, vector<int> &memo) {
  if (a <= 0) {
    return a == 0 ? 0 : -20000;
  }

  if (memo[a] == -1) {
    int ans = solve(costs, a - costs[0], memo) + 1;
    for (int i = 0; i < costs.size(); i++) {
      ans = max(ans, solve(costs, a - costs[i], memo) + 1);
    }

    memo[a] = ans;
  }

  return memo[a];
}

int main(int argc, const char *argv[]) {
  int n, m;
  cin >> n >> m;

  vector<int> all_costs{2, 5, 5, 4, 5, 6, 3, 7, 6};
  vector<int> va(m);
  for (int i = 0; i < m; ++i) {
    cin >> va[i];
  }

  sort(va.begin(), va.end(), greater<int>());

  vector<int> costs;
  for (auto a : va) {
    costs.push_back(all_costs[a - 1]);
  }

  vector<int> memo(n + 1, -1);

  int max_d = solve(costs, n, memo);

  string ans;
  int r = n;
  for (int i = 1; i <= max_d; i++) {
    for (int j = 0; j < costs.size(); ++j) {
      int d = solve(costs, r - costs[j], memo);
      if (d == max_d - i) {
        ans += to_string(va[j]);
        r -= costs[j];
        break;
      }
    }
  }

  cout << ans << '\n';
}

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

int main() {
    int N, M;
    cin>>N>>M;
    int yen[100];
    for (int i = 0; i < M; ++i) {
        cin>>yen[i];
    }
    int dp[21][50001];
    for (int i = 0; i <= M; ++i) {
        for (int j = 0; j <= N; ++j) {
            dp[i][j] = 210;
        }
    }
    for (int i = 0; i <= N; ++i) {
        dp[0][i] = i / yen[0];
    }

    for (int i = 0; i <= M; ++i) {
        dp[i][0] = 0;
    }

    for (int i = 0; i < M; ++i) {
        for (int j = 0; j <= N; ++j) {
            if (j-yen[i] >= 0)  {
                dp[i + 1][j] = min(dp[i+1][j-yen[i]] + 1, dp[i][j]);
            } else {
                dp[i + 1][j] = dp[i][j];
            }
        }
    }

    cout<<dp[M][N]<<endl;

}


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

int k,x;
int main() {
    cin>>k>>x;
    int first=x-k+1;
    for(int i=first;i<first+2*k-1;i++) {
        cout<<i<<" ";
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
set<int>f(int N){
set<int>S;
  for(int i=2;i<=N;i++){
    bool x=true;
for(int j=2;j<i;j++){
if(i%j==0){x=false; break;}
}  if(x)S.insert(i);
  } return S;
}
int main(){
int N;
  cin>>N;
  set<int>s=f(N);
  map<int64_t,int64_t>M;
  for(auto p:s){
  int a=N;
    int64_t ans=1;
    for(int i=0;0<a;i++){
    a/=p; ans+=a;
    }
  M[p]=ans;
  }
  int64_t ans=1;
for(auto p:M){
auto k=p.first;
  auto v=p.second;
  ans=(ans*v)%1000000007;

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

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
 
int main(){
    int n,a,cnt=0,N;
    scanf("%d",&n);
 
    for(int i=0;i<n;i++)
    {
        scanf("%d",&a);
        N=sqrt(a);
        for(int j=2;j<=N;j++){
            if(a%j==0){
                cnt++;
                break;
            }
        }
    }
    printf("%d\n",n-cnt);
}



Measured memory_bytes: 2040
#include<stdio.h>
int main()
{
	int a,b,c,x,i,j,k,y=0,z=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	for(i=0;i<=a;i++){
		for(j=0;j<=b;j++){
			for(k=0;k<=c;k++){
				y=i*500+j*100+k*50;
				if(y==x) z++;
			}
		}
	}
	printf("%d\n",z);
	return 0;
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int s;
  cin >> s;

  int front = s / 100;
  int back = s % 100;

  bool yymm = (front < 100) && (0 < back) && (back <= 12);
  bool mmyy = (0 < front) && (front <= 12) && (back < 100);

  if (yymm && mmyy) cout << "AMBIGUOUS";
  else if (yymm) cout << "YYMM";
  else if (mmyy) cout << "MMYY";
  else cout << "NA";
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 3612
use proconio::{fastout, input};

#[fastout]
fn main() {
    let mut s: String;
    input! {s: String};

    let s3 = &s[2..3];
    let s4 = &s[3..4];
    let s5 = &s[4..5];
    let s6 = &s[5..6];

    if s3 == s4 && s5 == s6 {
        println!("Yes")
    } else {
        println!("No")
    }
}


Measured memory_bytes: 2148
#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int top=0;
int w[1000];

void push(int);
int pop(void);

int main()
{
  int a,b,c,temp=0;
  char p[1];
  top=0;
  while(scanf("%c",p)==1){
    //printf("%d\n",p[0]);
    if(p[0]=='+'){
      b=pop();
      a=pop();
      push(a+b);
      //printf("test2\n");
      //break;
    }
    else if(p[0]=='-'){
      b=pop();
      a=pop();
      push(a-b);
      //break;
    }
    else if(p[0]=='*'){
      b=pop();
      a=pop();
      push(a*b);
      //break;
    }
    else if(p[0]==' ') {
      if(temp!=0){
	push(temp);
	temp=0;
      }
    }
    
    else if(p[0]=='\n') break;
    else{
      temp=temp*10+p[0]-'0';
      //push(p[0] - '0');
      //printf("test1\n");
    }
  }
  printf("%d\n",pop());
  return 0;
}


void push(int x)
{
  w[top]=x;
  top++;
}
int pop()
{
  top--;
  return w[top];
}

Measured memory_bytes: 536
#include <bits/stdc++.h>
#include <ext/hash_map>
#include <ext/numeric>

using namespace std;
using namespace __gnu_cxx;

#define REP(i,n) for( (i)=0 ; (i)<(n) ; (i)++ )
#define rep(i,x,n) for( (i)=(x) ; (i)<(n) ; (i)++ )
#define REV(i,n) for( (i)=(n) ; (i)>=0 ; (i)-- )
#define FORIT(it,x) for( (it)=(x).begin() ; (it)!=(x).end() ; (it)++ )
#define foreach(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();++it)
#define rforeach(it,c) for(__typeof((c).rbegin()) it=(c).rbegin();it!=(c).rend();++it)
#define foreach2d(i, j, v) foreach(i,v) foreach(j,*i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define SZ(x) ((int)(x).size())
#define MMS(x,n) memset(x,n,sizeof(x))
#define mms(x,n,s) memset(x,n,sizeof(x)*s)
#define pb push_back
#define mp make_pair
#define NX next_permutation
#define UN(x) sort(all(x)),x.erase(unique(all(x)),x.end())
#define CV(x,n) count(all(x),(n))
#define FIND(x,n) find(all(x),(n))-(x).begin()
#define ACC(x) accumulate(all(x),0)
#define PPC(x) __builtin_popcountll(x)
#define LZ(x) __builtin_clz(x)
#define TZ(x) __builtin_ctz(x)
#define mxe(x) *max_element(all(x))
#define mne(x) *min_element(all(x))
#define low(x,i) lower_bound(all(x),i)
#define upp(x,i) upper_bound(all(x),i)
#define NXPOW2(x) (1ll << ((int)log2(x)+1))
#define PR(x) cout << #x << " = " << (x) << endl ;

typedef unsigned long long ull;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef pair<int, int> pii;

const int OO = (int) 2e9;
const double eps = 1e-9;

ll n, x;

// x <= y
ll f(ll x, ll y) {
	if (x == y)
		return x;
	if (x > y)
		return f(y, x);
	ll z = y / x - (y % x == 0);
	return f(x, y - z * x) + 2 * z * x;
}

int main() {
	std::ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
#ifndef ONLINE_JUDGE
//	freopen("in.txt", "rt", stdin);
//	freopen("out.txt", "wt", stdout);
#endif
	cin >> n >> x;
	cout << n + f(n - x, x) << endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1e9+7
typedef long long int ll;
const int maxn = 100000;
ll mod = INF;
ll a,b,c,d;
ll ans=0;

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

int main(){
    
    cin >> a>>b>>c>>d;
    ll lcm=c*d/gcd(c,d);
    ans=b-a+1;
    ans-=(b/c-(a-1)/c)+(b/d-(a-1)/d)-(b/lcm-(a-1)/lcm);

    cout << ans<<endl;

    return 0;
}

Measured memory_bytes: 3600
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let st = readLine()!.split(separator: " ")
    let s = st[0]
    // let t = st[1]
    
    let ab = readInts()
    let a = ab[0]
    let b = ab[1]
    
    let u = readLine()!
    
    if u == s {
        print(a - 1, b)
    } else {
        print(a, b - 1)
    }
}

main()


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
#define fastio() ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long int
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define inf 1e9
#define pi 3.1415926536
#define mod 1000000007
#define fr(i,a,b,in) for(int i=a;i<b;i+=in)
#define frn(i,a,b,dc) for(int i=a;i>=b;i-=dc)
#define test(t) int t; cin>>t; while(t--)
int main()
{
	fastio();
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	// if(b>=0 && d>=0) cout<<b*d<<endl;
	// else if(b<0 && d<0) cout<<a*c<<endl;
	// else if(b<0 && c>=0) cout<<b*c<<endl;
	// else if(a>=0 && d<0) cout<<a*d<<endl;
	cout<<max(a*c,max(a*d,max(b*c,b*d)))<<endl;
}

Measured memory_bytes: 3644
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep2(i,n) for (int i = 1; i < (n); ++i)
using namespace std;
typedef long long ll;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i,N) cin >> a[i];
    double s = 0;
    rep(i,N) {
        s += a[i];
    }
    s /= N;
    double min = 10000;
    int min_num = 10000;
    for(int i = N-1; i >= 0; i--) {
        if (abs(s-a[i]) <= min){
            min = abs(s-a[i]);
            min_num = i;
        }
    }
    cout << min_num << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define modulo 998244353
#define mod(mod_x) ((((long long)mod_x)+modulo)%modulo)
#define Inf 1000000000000

vector<long long> V;

void dfs(long long now,long long cnt){
	V.push_back(now);
	if(cnt>=12)return;
	for(int i=now%10-1;i<=now%10+1;i++){
		if(i<0||i>=10)continue;
		dfs(now*10+i,cnt+1);
	}
}

int main() {
	
	for(int i=1;i<10;i++){
		dfs(i,0);
	}
	
	sort(V.begin(),V.end());
	
	int N;
	cin>>N;
	
	cout<<V[N-1]<<endl;
	
    return 0;
}


Measured memory_bytes: 67936
#include<iostream> 
#include<stdio.h> 
using namespace std; 
int main(){ 
int n,k,w,p,m,x,y,cnt; 
bool t[51][51],c[51]; 
char a; 
cin>>n>>k; 
  
 
 cnt=0; 
 for(int i=0;i<51;i++){ 
  c[i]=false; 
  for(int j=0;j<51;j++)t[i][j]=false; 
 } 
 for(int i=0;i<k;i++){ 
  cin>>m;
  for(int j=0;j<m;j++){ 
   cin>>w;
   t[i][w]=true; 
  }
 } 
 cin>>p; 
 for(int i=0;i<p;i++){ 
  cin>>x>>y; 
  for(int j=0;j<k;j++){ 
   if(t[j][x]&&t[j][y]){ 
    c[x]=c[y]=true; 
    break; 
   } 
  } 
 } 
 for(int i=1;i<=n;i++){ 
  if(c[i])cnt++; 
 } 
 cout<<cnt<<endl; 
 
return 0; 
}

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

int main(){
	int n;
	cin >> n;
	vector<int> t(n);
	int sum = 0;
	rep(i,n){
		cin >> t[i];
		sum += t[i];
	}
	int m;
	cin >> m;
	rep(i,m){
		int p,x;
		cin >> p >> x;
		p--;
		int temp = sum;
		sum = sum - t[p] + x;
		cout << sum << endl;
		sum = temp;
	}
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using vv = vector<vector<ll>>;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto &i : m)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define REV(T) greater<T>()

typedef pair<ll, ll> Pair;
bool pairCompare(const Pair &firstElof, const Pair &secondElof) {
  return firstElof.second > secondElof.second;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll K, A, B;
  cin >> K >> A >> B;
  if (B - A <= 2 || K - A < 1) {
    cout << (ll)1 + K << endl;
  } else if ((K - A + (ll)1) % 2 == 0) {
    cout << A + ((B - A) * ((K - A + (ll)1) / (ll)2)) << endl;
  } else {
    cout << (ll)1 + A + ((B - A) * ((K - A) / (ll)2)) << endl;
  }
  return 0;
}


Measured memory_bytes: 256
// I SELL YOU...! 
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<chrono>
#include<iomanip>
#include<map>
#include<set>
#define MAX_N 110000
#define MOD 1000000007
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
vector<ll> G[MAX_N];
ll dp[MAX_N][2]={};
ll flag[MAX_N][2] = {};
vector<ll> end_v;
void init_io(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(10);
}
ll solve(ll v,ll p,ll from){
  ll res = 1,tmp;
  if(flag[v][p]){
    return dp[v][p];
  }
  flag[v][p] = true;
  for(auto nv:G[v]){
    if(nv==from) continue;
    tmp = solve(nv,1,v);
    if(p==1){
      tmp += solve(nv,0,v);
      tmp %= MOD;
    }
    res *= tmp;
    res %= MOD;
  }
  return dp[v][p] = res;
}
signed main(){
  init_io();
  ll n;
  cin >> n;
  vector<ll> x(n-1),y(n-1);
  for(int i=0;i<n-1;i++){
    cin >> x[i] >> y[i];
    x[i]--;
    y[i]--;
    G[x[i]].emplace_back(y[i]);
    G[y[i]].emplace_back(x[i]);
  }
  if(n==1){
    cout <<"2\n";
    return 0;
  }
  solve(0,0,-1);
  solve(0,1,-1);
  ll ans = 0;
  ans = (dp[0][0]+dp[0][1])%MOD;
  cout << ans << endl;
}


Measured memory_bytes: 17792