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

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

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

ll bfs(int maze[20][20], int h, int w, int y, int x) {
    const int off = 256;
    int current;
    queue<pair<int, int>> q;
    maze[y][x] = off;
    q.push(pair<int, int>(x, y));

    while (!q.empty()) {
        pair<int, int> t = q.front();
        q.pop();
        x = t.first;
        y = t.second;
        current = maze[y][x];

        if (y > 0 && maze[y - 1][x] == '.') {
            maze[y - 1][x] = current + 1;
            q.push(pair<int, int>(x, y - 1));
        }
        if (y < h - 1 && maze[y + 1][x] == '.') {
            maze[y + 1][x] = current + 1;
            q.push(pair<int, int>(x, y + 1));
        }
        if (x > 0 && maze[y][x - 1] == '.') {
            maze[y][x - 1] = current + 1;
            q.push(pair<int, int>(x - 1, y));
        }
        if (x < w - 1 && maze[y][x + 1] == '.') {
            maze[y][x + 1] = current + 1;
            q.push(pair<int, int>(x + 1, y));
        }
    }

    return current - off;
}

int main(int argc, char** argv) {
    int h, w;
    ll ans = 0;

    int maze[20][20];
    cin >> h >> w;
    rep(y, h) {
        rep(x, w) {
            char c;
            cin >> c;
            maze[y][x] = c;
        }
    }

    // cout << "*****\n";
    // rep(y, h) {
    //     rep(x, w) { cout << maze[y][x] << ","; }
    //     cout << endl;
    // }
    // cout << "*****\n";

    rep(y, h) {
        rep(x, w) {
            // printf("(%d,%d)\n", j, i);
            int mazecopy[20][20];

            if (maze[y][x] != '.')
                continue;
            rep(y2, h) {
                rep(x2, w) { mazecopy[y2][x2] = maze[y2][x2]; }
            }
            ll tmp = bfs(mazecopy, h, w, y, x);
            // printf("(%d,%d) -> %lld\n", x, y, tmp);
            ans = max(ans, tmp);
        }
    }

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


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	sc.Scan()
	s := sc.Text()

	for i := 1; i < len(s); i++ {
		if s[i-1] != s[i] {
			fmt.Print("Yes")
			return
		}
	}

	fmt.Print("No")
}


Measured memory_bytes: 640
#include<stdio.h>
#include<math.h>
int main(){
	int n;
	int i,ans;
	while(~scanf("%d",&n)){
		if(n==0)break;
		ans = 0;
		while(1){
			ans+=n/5;
			n/=5;
			if(n==0){
				break;
			}
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false);cin.tie(NULL)
using namespace std;
#define int long long
#define MOD 1000000007
typedef vector<int> vi;
typedef pair<int,int> pi;
#define inf 1e18
#define For(i,a,b) for (int i = a; i < b; i++)
#define Rep(i,a,b) for (int i = a; i <= b; i++)
#define ps(x,y) fixed << setprecision(y) << x 
#define pb push_back 
#define mp make_pair 
 
int32_t main()
{
    fast;
    int a, b, c; cin >> a >> b >> c;
    int common = max({a, b, c});

    if(common % 2 == (a + b + c) % 2) cout << (3 * common - (a + b + c)) / 2;
    else cout << (3 * (common + 1) - (a + b + c)) / 2;

    return 0;
}

Measured memory_bytes: 3644
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>
#include<deque>
#include<tuple>
#include<queue>
#include<stack>
#include<map>
#include<cstdint>
#include<unordered_map>
#include<boost/multiprecision/cpp_int.hpp>


#define rep(i, n) for(int i = 0; i < ( int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define vi vector<int>
#define vll vector<ll>
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define Cin cin>>a;

namespace mp = boost::multiprecision;

using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;

int main(void){
	int n;
	cin >> n;
	int bcount = 0;
	int acount = 0;
	int count = 0;
	int dup = 0;
	rep(i, n) {
		string s;
		cin >> s;
		rep(i, s.size()) {
			if (s.substr(i, 2) == "AB") {
				count++;
			}
		}
		bool flag = false;
		if (s[0] == 'B') {
			flag = true;
			bcount++;
		}
		if (s[s.size() - 1] == 'A') {
			if (flag) {
				dup++;
				bcount--;
			}
			else {
				acount++;
			}
		}
	}
	if (dup > 0){
		if (acount > 0 or bcount > 0) {
			count += min(acount , bcount )+dup;
		}
		else {
			count += dup - 1;
		}
	}
	else {
		count += min(acount, bcount);
	}
	cout << count << endl;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
a=[]
for i in range(k):
 d=int(input())
 a.append([])
 a[i]=input().split()
count=0
for i in range(1,n+1):
 for j in range(k):
  if a[j].count(str(i))!=0:
   count=count+1
   break
print(n-count)

Measured memory_bytes: 9564
#include<iostream>
using namespace std;
int n, m;
int main(){
  cin >> n >> m;
  const int nm = 50;
  int a[nm], b[nm], c[nm], d[nm];
  for(int i = 0; i < n; i++) cin >> a[i] >> b[i];
  for(int j = 0; j < m; j++) cin >> c[j] >> d[j];
  
  for(int i = 0; i < n; ++i){
    int minone = abs(a[i] - c[0]) + abs(b[i] - d[0]);
    int checkpoint = 1;
    for(int j = 1; j < m; j++){
      const int mintwo = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if(mintwo < minone) {
        minone = mintwo;
        checkpoint = j + 1;
      }
    }
    cout << checkpoint << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<queue>
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int w,h;
  while(cin>>w>>h&&(w||h)){
    int a[9][9],sx,sy,tx,ty,ux,uy;
    for(i=0;i<9;i++)
      for(j=0;j<9;j++)
	a[j][i]=1;
    for(i=1;i<h+1;i++){
      for(j=1;j<w+1;j++){
	cin>>a[j][i];
	if(0){
	}else if(a[j][i]==2){
	  a[j][i]=0;
	  sx=j;
	  sy=i;
	}else if(a[j][i]==3){
	  a[j][i]=0;
	  ux=j;
	  uy=i;
	}else if(a[j][i]==4){
	  a[j][i]=0;
	  tx=j;
	  ty=i;
	}
      }
    }
    int b[9][9][9][9];
    memset(b,-1,sizeof(b));
    queue<pair<pair<pair<int,int>,pair<int,int> >,int> > c;
    c.push(make_pair(make_pair(make_pair(sx,sy),make_pair(tx,ty)),0));
    while(c.empty()==0){
      int sx,sy,tx,ty,di;
      sx=c.front().first.first.first;
      sy=c.front().first.first.second;
      tx=c.front().first.second.first;
      ty=c.front().first.second.second;
      di=c.front().second;
      if(sx==ux&&sy==uy)
	break;
      c.pop();
      if(((a[sx-1][sy]==0&&a[sx+1][sy]==0)||(a[sx][sy-1]==0&&a[sx][sy+1]==0))&&b[sx][sy][tx][ty]){
	b[sx][sy][tx][ty]=0;
	
	int d[9][9];
	memset(d,-1,sizeof(d));
	queue<pair<int,int> > e;
	e.push(make_pair(tx,ty));
	while(e.empty()==0){
	  int x,y;
	  x=e.front().first;
	  y=e.front().second;
	  e.pop();
	  if(a[x][y]==0&&(x!=sx||y!=sy)&&d[x][y]){
	    d[x][y]=0;
	    e.push(make_pair(x-1,y));
	    e.push(make_pair(x+1,y));
	    e.push(make_pair(x,y-1));
	    e.push(make_pair(x,y+1));
	  }
	}
	
	if(d[sx-1][sy]==0&&a[sx+1][sy]==0)
	  c.push(make_pair(make_pair(make_pair(sx+1,sy),make_pair(sx,sy)),di+1));
	if(d[sx+1][sy]==0&&a[sx-1][sy]==0)
	  c.push(make_pair(make_pair(make_pair(sx-1,sy),make_pair(sx,sy)),di+1));
	if(d[sx][sy-1]==0&&a[sx][sy+1]==0)
	  c.push(make_pair(make_pair(make_pair(sx,sy+1),make_pair(sx,sy)),di+1));
	if(d[sx][sy+1]==0&&a[sx][sy-1]==0)
	  c.push(make_pair(make_pair(make_pair(sx,sy-1),make_pair(sx,sy)),di+1));
      }
    }
    cout<<(c.empty()?-1:c.front().second)<<endl;      
  }
  return 0;
}

Measured memory_bytes: 0
#pragma region template 2.4
#include <bits/stdc++.h>
using namespace std;
template <typename T>
using pq_asc = priority_queue<T, vector<T>, greater<T>>;
typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> ii;
typedef vector<ii> vii;
typedef vector<string> vs;
#define REP(i, n) for (ll i = 0; i < (n); ++i)
#define REP1(i, n) for (ll i = 1; i <= (n); ++i)
#define FOR(i, a) for (auto &i : a)
#define CH(f, x, y) x = f(x, y)
#define IN(T, x) \
    T x;         \
    cin >> x;
#define AIN(T, a, n) \
    vector<T> a(n);  \
    FOR(i, a)        \
    cin >> i;
#define A2IN(T1, a, T2, b, n) \
    vector<T1> a(n);          \
    vector<T2> b(n);          \
    REP(i, n)                 \
    cin >> a[i] >> b[i];
#define OUT(x) cout << (x) << endl;
#define FOUT(x) cout << fixed << setprecision(15) << (x) << endl;
#define ALL(a) (a).begin(), (a).end()
#define SORT(a) sort(ALL(a))
#define RSORT(a) \
    SORT(a);     \
    reverse(ALL(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define DUMPA(a)          \
    cout << #a << " = {"; \
    JOUT(ALL(a), ", ", cout) << "}" << endl;

template <typename T>
ostream &JOUT(T s, T e, string sep = " ", ostream &os = cout)
{
    if (s != e)
    {
        os << *s;
        ++s;
    }
    while (s != e)
    {
        os << sep << *s;
        ++s;
    }
    return os;
}

ostream &YES(bool cond, string yes = "Yes", string no = "No", ostream &os = cout)
{
    if (cond)
    {
        os << yes << endl;
    }
    else
    {
        os << no << endl;
    }
    return os;
}

template <typename T1, typename T2>
ostream &operator<<(ostream &os, const pair<T1, T2> &p)
{
    os << '(' << p.first << ", " << p.second << ')';
    return os;
}

template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v)
{
    os << '[';
    JOUT(ALL(v), ", ", os) << ']';
    return os;
}

const ll INF = 1e18;
const ll MOD = 1e9 + 7;
#pragma endregion template

int main()
{
    IN(ll, N);
    AIN(ll, A, N);
    double ans = 0;
    FOR(a, A)
    {
        ans += 1. / a;
    }
    ans = 1 / ans;
    FOUT(ans);
}

Measured memory_bytes: 3740
#include<bits/stdc++.h>
#include<ctype.h>
# define pb push_back
#define fst first
#define sec second
#define For(i,a,b) for(int i=a;i<b;i++)
#define ll long long int
#define ull unsigned long long int
#define mod 1000000007
#define fo(i,n) for(ll i=0;i<n;i++)
#define endl "\n"
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define fo1(i,n) for(ll i=1;i<=n;i++)
#define boolsize 1000001
#define pi pair<ll,ll>
#define vi vector<ll>
#define vii vector<pi>
using namespace std;
template<typename T>
void showvector(vector <T> v)
{
    for(T x:v)
        cout<<x<<" ";
    cout<<endl;

}
template<typename T>
void showvector1(vector <T> v)
{
    ll n=v.size();
    fo1(i,n-1)
        cout<<v[i]<<endl;

}
template<typename T>
void showset(set <T> s)
{
    for(T x: s)
        cout<<x<<" ";
    cout<<endl;
}
template<class T>
void showvectorpair(vector<T> v)
{
    for(auto it=v.begin();it!=v.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T,typename P>
void showmap(map <T,P> m)
{
    for(auto it=m.begin();it!=m.end();it++)
        cout<<it->first<<" "<<it->second<<endl;
    cout<<endl;
}
template<typename T>
bool comp(T a,T b)
{
    return (a>b);
}
template<class T>
bool comppair(T a,T b)
{
    if(a.first==b.first)
        return(a.second>b.second);
    return (a.first>b.first);
}
bool sameparity(ll a,ll b)
{
    return (a%2==b%2);
}
bool difparity(ll a,ll b)
{
    return !(a%2==b%2);
}
bool isprime(ll x)
{   if(x<=1)
     return false;
    for(ll i=2;i<=sqrt(x);i++)
    {
        if(x%i==0)
            return false;
    }
    return true;
}
bool iseven(ll x)
{
    return !(x%2);
}
bool isodd(ll x)
{
    return (x%2);
}
/// check for test case before submitting
void vfun()
{
    ll n,k;
    cin>>n;
    vector <ll> v(n);
    fo(i,n)
    cin>>v[i];

}

int main()
{
    #ifndef ONLINE_JUDGE
    freopen("inputh.txt", "r", stdin);
    freopen("outputh.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0); ///cant use scanf, printf
    cin.tie(0);cout.tie(0); /// no longer auto flush cout before each cin, remove for interactive
    //cout << fixed << setprecision(11); /// no scientific output
    ll test=1;
   // cin>>test;
    while(test--)
    {

            ll n;
            cin>>n;
            vi v;
            ll x;
            fo(i,n)
            {
                cin>>x;
                v.pb(x);

            }
            ll i=n-1;
            while(i>=0)
            {
                cout<<v[i]<<" ";
                i-=2;
            }
            if(i==-2)
                i=1;
            else
                i=0;



            while(i<n)
                {
                    cout<<v[i]<<" ";
                    i+=2;
                }
        cout<<endl;

//         if(vfun())
//            cout<<"YES\n";
//         else
//            cout<<"NO\n";
    }
}
///before sub
/// check for value of zero and single input in array
///loop vars,1LL in mult, equal, one, bounds, int v ll, endl, finish taking inputs
/// check whether test cases are given or not





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

public class Main {

	public static void main(String[] args) {

		FastScanner sc = new FastScanner();
		int N = sc.nextInt();
		int[] A = new int[N];
		for (int i = 0; i < N; i++)
			A[i] = sc.nextInt();
		long ans = A[0];
		for (int i = 0; i < N - 1; i++) {
			ans = gcd(ans, A[i + 1]);
		}
		System.out.println(ans);

	}
	//以下、自作ライブラリ

	//最大公約数
	public static long gcd(long a, long b) {
		if (a < b)
			return gcd(b, a);
		long c = 0;
		c = a % b;
		if (c == 0)
			return b;
		return gcd(b, c);
	}

	//最小公倍数
	public static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}

	//素数判定
	public static boolean isPrime(int n) {
		if (n < 2)
			return false;
		if (n == 2)
			return true;
		if (n % 2 == 0)
			return false;

		for (int i = 3; i * i <= n; i += 2) {
			if (n % i == 0)
				return false;
		}
		return true;
	}
}

//以下、高速スキャナークラス
class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

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

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

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

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

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

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


Measured memory_bytes: 22228
p,s[251],*w="apple\0  APPLE\0  peach";R(f,t){for(p=s;p=strstr(p,w+f);)memcpy(p,w+t,5);}main(){scanf("%[^\n]",s);R(0,2);R(4,0);R(2,4);exit(!puts(s));}

Measured memory_bytes: 0
using System;
using System.Linq;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int K = int.Parse(Console.ReadLine());
            string S = Console.ReadLine();
            if(S.Length > K)
            {
                Console.WriteLine(S.Substring(0, K) + "...");
            }
            else
            {
                Console.WriteLine(S);
            }
        }
    }
}

//24579 =  hon
//0168 = pon
//3 = bon
//long n = long.Parse(Console.ReadLine());
//long[] inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();

//Console.WriteLine(cnt);
//Console.ReadKey();


Measured memory_bytes: 27476
n, m = map(int, input().split())
max_value = 10 ** 5
min_value = 1
for i in range(m):
    l, r = map(int, input().split())
    min_value = max(min_value, l)
    max_value = min(max_value, r)

ans = max_value - min_value + 1
if ans < 0:
    ans = 0
print(ans)


Measured memory_bytes: 3060
n=gets.to_i;as=gets.split.map(&:to_i);
count=0
n.times do |i|
  (n-i-1).times do |j|
    if as[j+1]<as[j]
      as[j],as[j+1]=as[j+1],as[j]
      count+=1
    end
  end
end
puts as.join(" ")
puts count



Measured memory_bytes: 6864
#include <bits/stdc++.h>
#define LSOne(S) ((S) & (-S))
using namespace std;

typedef long long ll;

const int MAXN = 2*1e5 + 10;

ll bit[MAXN],dp[MAXN];
ll h[MAXN],a[MAXN];
int N;

void update(int x, ll val){
	while(x <= N){
		bit[x] = max(bit[x],val);
		x += LSOne(x);
	}
}

ll query(int x){

	ll ans = 0;
	while(x > 0){
		ans = max(ans,bit[x]);
		x -= LSOne(x);
	}

	return ans;

}

int main(){

	scanf("%d",&N);

	for(int i = 1;i<=N;i++){
		scanf("%lld",&h[i]);
	}
	for(int i = 1;i<=N;i++){
		scanf("%lld",&a[i]);
	}

	for(int i = 1;i<=N;i++){
		dp[i] = query(h[i] - 1) + a[i];
		update(h[i],dp[i]);
	}

	ll best = 0;
	for(int i = 1;i<=N;i++) best = max(best,dp[i]);
	printf("%lld\n",best);

	return 0;

}

Measured memory_bytes: 10028
#include <bits/stdc++.h>
#define REP(i,n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i,a,b) for (ll i=(a);i<(ll)b; i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define INF 1000000000
#define writeln(n) cout<<n<<endl;
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll,ll> p;
const int MOD = 1000000007;

// vector<p> cut(M);
// cut[i].second
// cut[i].first;
// REP(i,M){
//     int a,b;cin>>a>>b;
//     cut[i] = make_pair(b,a);//last first の順番
// }
// for(int i=0; i<N;i++){
// }
// sort(cut.begin(),cut.end()); //sort
// char '' str ""
int main(void)
{
    int N,M;cin>>N>>M;
    bool flag = true;

    char A[51][51]; char B[51][51];

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


    for(int i=0; i<M;i++){
      for(int j=0; j<M;j++){
        cin>>B[i][j];
      }
    }


    for(int i=0; i<=N-M;i++){
      for(int j=0; j<=N-M;j++){
        for(int k=0; k<M;k++){
          for(int l=0; l<M;l++){
            if((A[i+k][j+l]=='#' && B[k][l]=='.')||(A[i+k][j+l]=='.' && B[k][l]=='#')) {flag=false;}
          }
        }
        if(flag){
          cout<<"Yes"<<endl;
          return 0;
        }
        flag = true;
      }
    }


    cout<<"No"<<endl;



    return 0;
}


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

// マクロ //
#define rep(i,N) for(int i = 0; i < N; i++)
#define all(x) x.begin(), x.end()
#define sort(x) sort(all(x))
#define uniq(x) x.erase(unique(all(x)), x.end())
#define vsum(x) accumulate(all(x), 0)
#define cou(x) cout << x << endl
#define y() cout << "Yes" << endl
#define n() cout << "No" << endl
#define Y() cout << "YES" << endl
#define N() cout << "NO" << endl
#define x2(x) (x) * (x)

// 型エイリアス //
using lint = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vli = vector<lint>;
using vc = vector<char>;
using vs = vector<string>;
using vb = vector<bool>;
using vvi = vector<vi>;
using vvb = vector<vb>;
using vvc = vector<vc>;
using vpii = vector<pii>;
using msi = map<string, int>;

// 関数 //
template<class T> lint gcd(T a, T b) {
    int t;
    while (b != 0) {
        t = a % b;
        a = b;
        b = t;
    }
    return a;
}

template<class T> lint lcm(T a, T b) {
    return a * b / gcd(a, b);
}

double distance(pii a, pii b) {
    double dist;
    dist = sqrt(x2(a.first - b.first) + x2(a.second - b.second));
    return dist;
}

lint perm(int a) {
    lint perm = 1;
    for (int i = a; i >= 1; i--) {
        perm *= i;
    }
    return perm;
}

lint combination(int n, int m) {
    long double c = 1;
    for (int i = n, k = 1; i > m; i--, k++) {
        c *= i;
        c /= k;
    }
    return (lint)c;
}

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

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

// 定数 //
#define pi acos(-1)
#define mod 1000000007
#define MOD 998244353
#define inf ((1LL << 62) - 1 + (1LL << 62))

// キーワード //
#define elif else if

// End of Template //



int main() {

    cin.tie(0);
    ios::sync_with_stdio(false);
        
    int N;
    cin >> N;
    vi L(N);
    rep(i, N) cin >> L[i];
    sort(L);
    int tori = 0;

    for (int i = 0; i < N - 2; i++) {
        for (int j = i + 1; j < N - 1; j++) {
            for (int k = j + 1; k < N; k++) {
                if (L[i] + L[j] <= L[k]) break;
                tori++;
            }
        }
    }
    cou(tori);

}

Measured memory_bytes: 384
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String s = sc.next();
		String okikae = s.replace("ABC" , "0");
		int count = 0;

		char[] c = new char[okikae.length()];
		c = okikae.toCharArray();
		for(int i=0 ; i<okikae.length() ; i++) {
			if(c[i] == '0') {
				count++;
			}
		}
		System.out.print(count);
	}
}

Measured memory_bytes: 23764
N = int(input())
X = list(map(int,input().split()))

import numpy as np

xidx = np.argsort(X)
xidx = sorted(range(len(xidx)),key = lambda k:xidx[k])
Y = X
Y.sort()
Med1 = Y[N//2]
Med2 = Y[(N-2)//2]
for i in xidx:
    
    if i < N//2:
        print(Med1)
    else:
        print(Med2)


Measured memory_bytes: 38628
N=int(input())
A=list(map(int, input().split()))
B=list(map(int, input().split()))
SUM=sum(A)
for i in range(N):
    res=B[i]
    fir=min(res,A[i])
    A[i]=A[i]-fir
    res-=fir
    sec=min(res,A[i+1])
    A[i+1]-=sec

print(SUM-sum(A))

Measured memory_bytes: 18624
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind
#define rt (a); return (a); 
#define Pint pair<int,int>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
llint gcd(llint a, llint b) {
	if (b > a)swap(a, b);
	if (a % b == 0)return b;
	return gcd(b, a % b);
}
llint Tow(int n) {//2のn乗
	if (n == 0)return 1;
	llint x = Tow(n / 2);
	x %= mod;
	x *= x;
	x %= mod;
	if (n % 2 == 1)x *= 2;
	x %= mod;
	return x;
}

int main() {
	string s, t;
	cin >> s >> t;
	int n = s.size(), m = t.size();
	whei(int) dp(n + 1, hei(int)(m + 1, 0));
	rep(i, 0, n) {
		rep(j, 0, m) {
			if (s[i] == t[j])dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j + 1]);
			dp[i + 1][j + 1] = max({ dp[i + 1][j + 1],dp[i + 1][j],dp[i][j + 1]});
		}
	}

	string ans = "";
	while (n>0&&m>0){
		if (dp[n][m] == dp[n - 1][m])n--;
		else {
			if (dp[n][m] == dp[n][m - 1])m--;
			else {
				ans += s[n - 1];
				n--;
				m--;
			}
		}
	}
	reverse(ans);
	cout << ans << endl;
	return 0;
}

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

int main() {
	int n;
	while(cin >> n, n) {
		int count = 0;
		while(n != 1) {
			if(n % 2)
				n = n * 3 + 1;
			else
				n /= 2;
			count++;
		}
		cout << count << endl;
	}
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

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

    int S = 0;
    for (int t = N; t > 0; t /= 10) {
        S += t % 10;
    }

    if (N % S == 0) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
    
    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;
import java.util.List;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.Arrays;
import java.util.Collections;
import java.util.*;
class Main{
  public static void main(String[] args){
    Scanner scan = new Scanner(System.in);
    String S = scan.next();
    String T = scan.next();
    System.out.println(T + S);
  }
}


Measured memory_bytes: 22996
object Main extends App {

  val n = scala.io.StdIn.readInt()
  val dArr = scala.io.StdIn.readLine().split(" ").map(_.toInt)


  def solve() =  {
    var sum = 0
    for(i <- 0 until n-1) {
      var j = i + 1
      while(j < n) {
        sum += dArr(i) * dArr(j)
        j += 1
      }
    }
    sum
  }

  println(solve)

}


Measured memory_bytes: 25532
import sys

N, M = map(int, sys.stdin.readline().split())
a_list = list(map(int, sys.stdin.readline().split()))
items = []
for i in range(M):
    items.append(tuple(map(int, sys.stdin.readline().split())))


from collections import defaultdict

tar = defaultdict(int)
for a in a_list:
    tar[a] += 1

for i in range(M):
    b, c = items[i]
    tar[c] += b

tar = sorted(tar.items(), key=lambda x: -x[0])

cnt = 0
ans = 0
for k, v in tar:
    if cnt + v <= N:
        cnt +=v
        ans += k*v
    else:
        ans += k*(N-cnt)
        cnt = N
    if cnt >= N:
        break
print(ans)


Measured memory_bytes: 106392
#import sys

#input = sys.stdin.readline

#import heapq
import math
import fractions

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

def main():
#    h,w,a,b = map(int, input().split())
    a,b=map(int,input().split())
    m=4
    k=1

    count=1
    if a>b:
        a,b=b,a
    sosu=set()
#    a = fractions.gcd(a,b)
    if a%2==0:
        sosu.add(2)
        while a%2==0:
            a//=2
    if a%3==0:
        sosu.add(3)
        while a%3==0:
            a//=3
#    print(d)
    c=math.sqrt(a)+1
 #   print(c)
    while m<=c and m!=1:
        if a%m==0:
            sosu.add(m)
            while a%m==0:
                a//=m

        m+=1
#    print(sosu)
    if sosu==set() and a!=1:
        sosu.add(a)
    if sosuhante(a) and a!=1:
        sosu.add(a)
#    print(sosu)

    for i in sosu:
        if b%i==0:
            count+=1
    print(count)
#    for i in range(h):
#            print(aaa)

if __name__ == "__main__":
    main()

Measured memory_bytes: 5044
//package _0155;

import java.io.*;
import java.util.*;
import java.math.*;

public class Main {
	Scanner sc =new Scanner(System.in);
	
	class p2 implements Comparable<p2>{
		int f;
		double s;
		String ans;
		
		p2(int f, double s ,String ans){
			this.f = f;
			this.s = s;
			this.ans = ans;
		}
		
		public int compareTo(p2 arg0) {
			// TODO Auto-generated method stub
			return Double.compare(s, arg0.s);
		}
		
	}
	
	void run(){
		for(;;){
			int n = sc.nextInt();
			if(n == 0){
				break;
			}
			int b[] = new int[n];
			int x[] = new int[n];
			int y[] = new int[n];
			int inv[] = new int[1001];
			
			double cost[][] = new double[n][n];
			for(int i = 0 ; i < n ; i++){
				Arrays.fill(cost[i],Double.MAX_VALUE);
			}
			
			for(int i = 0; i < n ; i++){
				b[i] = sc.nextInt();
				x[i] = sc.nextInt();
				y[i] = sc.nextInt();
				
				inv[b[i]] = i;

				cost[i][i] = 0;
				for(int j = 0; j < i ; j++){
					if((x[i]-x[j])*(x[i]-x[j]) +(y[i]-y[j])*(y[i]-y[j]) <= 50*50){
						cost[i][j] = Math.sqrt((x[i]-x[j])*(x[i]-x[j]) +(y[i]-y[j])*(y[i]-y[j]));
						cost[j][i] = cost[i][j];
		//				System.out.println(cost[i][j]);
					}
				}
			}
			
			int m = sc.nextInt();
			int s[] = new int[m];
			int g[] = new int[m];
			
			for(int i = 0; i < m;i++){
				s[i] = sc.nextInt();
				g[i] = sc.nextInt();
			}
			
			for(int i = 0; i < m ; i++){
				int start = inv[s[i]];
				int goal = inv[g[i]];
				
				PriorityQueue <p2> q = new PriorityQueue<p2>();
				q.add(new p2(start,0,s[i]+""));
				
				boolean reached[] = new boolean[n];
								
				double cost2[] = new double[n];
				
				Arrays.fill(cost2, Double.MAX_VALUE);
				for(;;){
//					System.out.println(q.size());
					if(q.isEmpty()){
						System.out.println("NA");
						break;
					}
					
					p2 p = q.poll();
					if(reached[p.f]){
						continue;
					}
					if(p.f == goal){
						System.out.println(p.ans);
						break;
					}
					
					reached[p.f]= true;
					cost2[p.f] = p.s;
					for(int j = 0; j < n ;j++){
						if(!reached[j]){
							if(p.s + cost[p.f][j] < cost2[j]){
								q.add(new p2(j , p.s + cost[p.f][j] , p.ans + " "+b[j]));
							}							
						}
					}
					
				}
				
				
				
			}
			
			
		}
		
		
	}
	
	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
#define F first
#define S second
#define fast_io ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
const int N=1e2+10,LN=30,SQ=550;
const ll INF=1e16;
const int MOD=1000000007 /*998244353*/;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using pll=pair<ll,ll>;
using pii=pair<int,int>;
#define ordered_set tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
ll pow(ll x, ll y, ll mod){
    ll ans=1;
    while (y != 0) {
        if (y & 1) ans = ans * x % mod;
        y >>= 1;
        x = x * x % mod;
    }
    return ans;
}
ll n;
bool t[N];
int main(){
    fast_io;
    cin >> n;
    for(ll i=0; i<n; i++){
        ll x,y;
        cin >> x >> y;
        t[i]=x==y;
    }
    for(ll i=0; i<n-2; i++){
        if(t[i]&&t[i+1]&&t[i+2]){
            cout << "Yes";
            return 0;
        }
    }
    cout << "No";
    return 0;
}


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

int main() {
  long n,a=0,ans;
  string s;
  cin >> n >> s;
  for(long i=1;i<n;i++) if(s[i]=='E') a++;
  ans=a;
  for(long i=1;i<n;i++) {
    if(s[i-1]=='W') a++;
    if(s[i]=='E') a--;
    ans=min(ans,a);
  }
  cout << ans << endl;
}

Measured memory_bytes: 900
#include<bits/stdc++.h>
#define mod 1000000007
#define mod1 998244353
#define Mmax 1000005
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long int li;
typedef unsigned long long int ull;
using namespace std;
bool sortbysec(const pair<li,li>&a,const pair<li,li>&b)
{
    return (a.second<b.second);
}
bool comp(pair<li,pair<li,li>>a,pair<li,pair<li,li>>b)
{
  if(a.first<b.first)
  return 1;
  else if(a.first>b.first)
  return 0;
  else
  {
    return a.second.first<b.second.first;
  }
}
li mpow(li x,li y)
{
  li ans=1;
  while(y)
  {
    if(y%2!=0)
    ans=(ans%mod)*(x%mod)%mod;
    y/=2;
    x=((x%mod)*(x%mod))%mod;
  }
  return ans;
}
void bfs(vector<li>v[],li visit[],li s,li ans[])
{
  deque<li>q;
  q.push_back(s);
  visit[s]=1;
  while(!q.empty())
  {
    li x=q.front();
    q.pop_front();
    for(auto i=v[x].begin();i!=v[x].end();i++)
    {
      if(!visit[*i])
      {
        q.push_back(*i);
        visit[*i]=1;
      }
    }
  }
}
void dfs(vector<li>v[],li visit[],li s)
{
  visit[s]=1;
  cout<<s<<" ";
    for(auto i=v[s].begin();i!=v[s].end();i++)
    {
      if(!visit[*i])
      {
        dfs(v,visit,*i);
      }
    }
}
vector<li>factor(li n)
{
  vector<li>v;
  if(n%2==0)
  {
    while(n%2==0)
    n/=2;
    v.push_back(2);
  }
  for(li i=3;i<=sqrt(n);i+=2)
  {
    if(n%i==0)
    {
      while(n%i==0)
      n/=i;
      v.push_back(i);
    }
  }
  if(n>1)
  v.push_back(n);
  return v;
}
int main()
{
fast_io
li t,i,j;
t=1;
while(t--)
{
  li s,w;
  cin>>s>>w;
  if(w>=s)
  cout<<"unsafe";
  else
  cout<<"safe";
  cout<<endl;
}
return 0;
}


Measured memory_bytes: 3680
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]
N=H*W
par=[0 for i in range(N)]
rnk=[0 for i in range(N)]
def init(n):
    for i in range(N):
        par[i]=i
        rnk[i]=0
def find(x):
    if par[x]==x:
        return x
    else:
        par[x]=find(par[x])
        return par[x]
def unite(x,y):
    x=find(x)
    y=find(y)
    if x==y:
        return
    if (rnk[x]<rnk[y]):
        par[x]=y
    else:
        par[y]=x
        if(rnk[x]==rnk[y]):
            rnk[x]+=1
def same(x,y):
    return find(x)==find(y)
init(N)
dx=[0,0,1,-1]
dy=[1,-1,0,0]
for i in range(H):
    for j in range(W):
        for k in range(4):
            nx=dx[k]+i
            ny=dy[k]+j
            if 0<=nx<H and 0<=ny<W:
                if S[nx][ny]!=S[i][j]:
                    p=i*W+j
                    q=nx*W+ny
                    unite(p,q)
A=[find(i) for i in range(N)]
D=dict()
for j in range(N):
    i=A[j]
    if not(i in D):
        D[i]=[0,0]
    if S[j//W][j%W]=="#":
        D[i][1]+=1
    else:
        D[i][0]+=1
ans=0
for i in D:
    seq=D[i]
    ans+=seq[0]*seq[1]
print(ans)


Measured memory_bytes: 35756
from sys import stdin

a,b = list(map(int,stdin.readline().rstrip().split()))

i = 1

if b == 1:
    print(0)
    exit()

elif a >= b:
    print(1)
    exit()
else:
    while True:
        if i * (a-1)+1< b:
            i += 1
        else:
            print(i)
            break

Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int solve(int A[], int n){
    int ans[n+1];
    ans[1]=0;
    ans[2]=abs(A[2]-A[1]);
    
    for(int i=3;i<=n;i++)
    ans[i]=min(ans[i-1]+abs(A[i]-A[i-1]), ans[i-2]+abs(A[i]-A[i-2]));
    
    return ans[n];
}
int main(){
    int n;
    cin>>n;
    int A[n+1];
    for(int i=1;i<=n;i++)
    cin>>A[i];
    
    cout<<solve(A,n);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define l long
#define pb push_back
#define mp make_pair
#define mt make_tuple
ll M = 998244353;

int main() {
	// your code goes here
	//ifstream cin("input.txt");
	//ofstream cout("output.txt");
	ios_base::sync_with_stdio(false); 
    cin.tie(NULL); 
	
	ll h,w; cin>>h>>w;
	if(h==1 || w==1){ cout<<1; return 0; }
	ll ans = ((h+1)/2)*((w+1)/2) + (h/2)*(w/2);
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
int ss[10005],bb[1005][1005],a[10006];
int main()
{
    int h,w,q,n;
    while(scanf("%d%d",&h,&w)==2)
    {
        memset(bb,0,sizeof(bb));
        memset(ss,0,sizeof(ss));
        scanf("%d",&n);q=0;
        for(int i=1;i<=n;i++)
        {
            scanf("%d",&a[i]);
            for(int j=1;j<=a[i];j++)
            {
                ss[++q]=i;
            }
        }
        for(int i=1;i<=h;i++)
        {
            if(i%2==1)
            {
                for(int j=1;j<=w;j++)
                {
                    bb[i][j]=ss[q--];
                }
            }
            if(i%2==0)
            {
                for(int j=w;j>=1;j--)
                {
                    bb[i][j]=ss[q--];
                }
            }
        }
        for(int i=1;i<=h;i++)
        {
            for(int j=1;j<w;j++)
            {
                printf("%d ",bb[i][j]);
            }
            printf("%d\n",bb[i][w]);
        }
    }
}


Measured memory_bytes: 4352
//
//  main.cpp

#include <iostream>
using namespace std;


int main(){	
	int N,M;
	cin >> N >> M;
	int array[101]={};
	for(int i=0;i<N;i++){
		cin >> array[i];
	}
	
	for(int j=1;j<=M;j++){
		for(int i=0;i<N-1;i++){
			if(array[i]%j > array[i+1]%j){
				int memo = array[i];
				array[i] = array[i+1];
				array[i+1] = memo;
			}
		}
	}
	
	for(int i=0;i<N;i++){
		cout << array[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
const int inf=1e9 +10;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    int n,k;  cin>>n>>k;
    int height[n+2];
    for(int i=1;i<=n;i++) cin>>height[i];
    int min_cost[n+2];
    for(int i=1;i<=n;i++) min_cost[i] = inf;
    min_cost[1]=0;min_cost[2]=abs(height[2]-height[1]);
    for(int i=3;i<=n;i++){
       for(int j=1;j<=k;j++){
           if((i-j) > 0){
               min_cost[i] = min(abs(height[i]-height[i-j])+min_cost[i-j],min_cost[i]);
           }
       }
    }
    cout<<min_cost[n];
}

Measured memory_bytes: 1024
// #include {{{
#include <iostream>
#include <cassert>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <cctype>
#include <cmath>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <string>
#include <bitset>
#include <vector>
#include <complex>
#include <algorithm>
using namespace std;
// }}}
// #define {{{
typedef long long ll;
typedef double db;
typedef pair<int,int> pii;
typedef vector<int> vi;
#define de(x) cout << #x << "=" << x << endl
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
// }}}

int main(){
    string s;
    cin >> s;
    puts(s.find("AC") != string::npos ? "Yes" : "No");
    return 0;
}


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

int main(){
    vector<int> v(5);
    rep(i,5) cin >> v.at(i);
    rep(i,5)if(v.at(i) == 0) cout << (i+1) << endl;
}

Measured memory_bytes: 3596
#include <stdio.h>

int main(){
   int n,k,a,i,h;
 
   scanf("%d %d",&n,&k);
   for (i=a=0;i<n;i++) {
      scanf("%d",&h);
      if (h>=k) a++;
   }
   printf("%d\n",a);
   return 0;
}


Measured memory_bytes: 128
/*
 * cpp_filepath
 */

// C++ 14
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstring> // memset
#include <cassert>
using namespace std;
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)
template <class T> ostream & operator << (ostream & out, vector<T> const & v) {
  for (auto &&a: v) out << a << " "; out << endl; return out;
}
template <class T> void dump(T &a) { cout << a << endl; }
void solve();
int main() { solve(); return 0; }

#include <set>
void solve() {
  int n;
  cin >> n;
  set<int> S;
  loop (i,1,33000) {
    S.insert(i*i);
  }
  
  auto it = S.lower_bound(n);
  if (it == S.end()) it--;
  else while (it != S.begin() and *it > n) it--;
  cout << *it << endl;
}


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

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

    while (n > 0)
    {
        m = n % 10;
        if (m == 7)
        {
            cout << "Yes" << endl;
            return 0;
        }
        n /= 10;
    }

    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3588
/*{{{*/
//#pragma GCC optimize("O3")

#include <bits/stdc++.h>

#ifdef __linux__
#define getchar getchar_unlocked
#define putchar putchar_unlocked
#endif

typedef long long ll;
typedef std::pair<int, int> pii;

std::string Name = __FILE__;
std::string iput = Name.substr(0, Name.length() - 4) + ".in";
std::string oput = Name.substr(0, Name.length() - 4) + ".out";

template <class T> inline bool chkmin(T &x, T y) { return x > y ? x = y, true : false; }
template <class T> inline bool chkmax(T &x, T y) { return x < y ? x = y, true : false; }

template <class T> inline T &read(T &x)
{
    static int f;
    static char c; 
    for (f = 1; !isdigit(c = getchar()); ) {
        if (c == '-')
            f = -1;
    }
    for (x = 0; isdigit(c); c = getchar()) {
        x = x * 10 + c - 48;
    }
    return x *= f;
}
 
template <class T> inline void write(T x, const char p = '\n')
{
    static int top;
    static int s[30];
    if (x < 0) {
        x = -x;
        putchar('-');
    }
    do s[++ top] = x % 10 + 48;
    while (x /= 10);
    while (top)
        putchar(s[top --]);
    putchar(p);
}
/*}}}*/
 
const int maxn = 1e5 + 5;
 
long long n;
long long x;
long long ans;

long long f(long long a, long long b)
{
    if (a < b) std::swap(a, b);
    if (b == 0) return 0;
    return f(b, a % b) + (a / b) * b * 2;
}

void exec()
{
    read(n), read(x);
    ans = n + f(n - x, x) - std::__gcd(n, x);
    write(ans);
}

/*{{{*/
int main() 
{
    if (fopen(iput.c_str(), "r") != NULL) {
        freopen(iput.c_str(), "r", stdin);
        freopen(oput.c_str(), "w", stdout);
    }

    exec();

    fclose(stdin);
    fclose(stdout);

    return 0;
}
/*}}}*/




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

int main() {
    int n, m;
    cin >> n >> m;
    scc_graph g(n);
    for (int i = 0; i < m; i++) {
        int a, b;
        cin >> a >> b;
        g.add_edge(a, b);
    }
    auto ans = g.scc();
    cout << ans.size() << endl;
    for (auto v : ans) {
        cout << v.size();
        for (auto x : v) {
            cout << " " << x;
        }
        cout << endl;
    }
}


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

int main()
{
    string s;
    cin >> s;
    int count1 = 0;
    int count2 = 0;
    for(int i=0;i<s.length();i++)
    {
        if(i%2==0)
        {
        if(s[i]=='0')
        {
            count1++;
            
        }
        else
            {
            count2++;
            }
        }
        
        if(i%2!=0)
        {
        if(s[i]!='0')
        {
            count1++;
            
        }
        else
            {
            count2++;
            }
        }
        
    }
    
    //cout << count1 << count2 << " ";
    cout << min(count1,count2);
}

Measured memory_bytes: 512
#include<stdio.h>
int main()
{
  int a,len;
  char s[101];
  char s2[101]; 
  scanf("%d", &a);
  scanf("%s", s);
  len = strlen(s);
  if (len <= a)
  {
    printf("%s\n",s);
  }
  else
  {
    strncpy(s2, s, a);
    s2[a] = '\0';
    printf("%s...\n",s2);
  }
  return 0;
}

Measured memory_bytes: 1736
// delete when handing in
//#define DEBUG
// delete when proceedig next 
#define EXE
#ifdef EXE
// -------------------------------------------------------
#include <iostream>
#include <string>
#include <stdio.h>
#include <cassert>
#include <vector>
#include <algorithm>
#include <map>
#include <bitset>
using namespace std;


;

vector<pair<int, int>> find_reverse(vector<pair<int, int>> map, int i) {
	vector<pair<int, int>> out_vec;
	int index = 0;
	for (auto m : map) {
		if (m.second == i) {
			out_vec.push_back(make_pair(index, m.first));
		}
		index++;
	}
	return out_vec;
}

vector<pair<int, int>> find(vector<pair<int, int>> map, int i) {
	vector<pair<int, int>> out_vec;
	int index = 0;
	for (auto m : map) {
		if (m.first == i) {
			out_vec.push_back(make_pair(index, m.second));
		}
		index++;
	}
	return out_vec;
}




int main() {
	long N;
	vector<string> s;
#ifdef DEBUG
	N = 9445;

#else
	cin >> N;
	for (int i = 0; i < N; i++) {
		string s_in;
		cin >> s_in;
		s.push_back(s_in);
	}
#endif
	long sub = 0;
	int ac_num = 0;
	int wa_num = 0;
	int tle_num = 0;
	int re_num = 0;

	for (auto s_itr : s) {
		if (s_itr == "AC") {
			ac_num++;
		}
		else if (s_itr == "WA") {
			wa_num++;
		}
		else if (s_itr == "TLE") {
			tle_num++;
		}
		else if (s_itr == "RE") {
			re_num++;
		}
	}

	std::cout << "AC x " << ac_num << endl;
	std::cout << "WA x " << wa_num << endl;
	std::cout << "TLE x " << tle_num << endl;
	std::cout << "RE x " << re_num << endl;


#ifdef DEBUG
	int z;
	cin >> z;
#endif
	return 0;
}


// -------------------------------------------------------
#endif

Measured memory_bytes: 5984
#include <stdio.h>

int main(void){
	double num,sum=0;
	int i;
	while(scanf("%lf",&num) != EOF){
		sum=num;
		sum+=(num*=2);
		for(i=0;i<4;i++){
			sum+=(num/=3);
			sum+=(num*=2);
		}
		printf("%.8lf\n",sum);
	}
	return 0;
}

Measured memory_bytes: 652
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define MOD 1000000007 
#define INF 1000000000000000000
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
    int k;
    cin >> k;
    string s;
    cin >> s;
    for (auto g : s) {
        cout << char((g - 'A' + k) % 26 + 'A');
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>

using ll = long long;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define reps(i, x) for(int i=1;i<=(int)(x);i++)
#define rrep(i, x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i, x) for(int i=(int)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007
#define put2darr(arr, row, col) rep(i, row) { rep(j, col) { printf("%18d", arr[i][j]); } cout << endl; }
using namespace std;

template<class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return 1;

    }
    return 0;
}


template<class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return 1;

    }
    return 0;
}

/* 1..10
 * rep:   0 1 2 3 4 5 6 7 8 9
 * reps:  1 2 3 4 5 6 7 8 9 10
 * rrep:  9 8 7 6 5 4 3 2 1 0
 * rreps: 10 9 8 7 6 5 4 3 2 1
 */
using namespace std;

int main() {
    string s;
    cin >> s;
    int fir = stoi(s.substr(0, 2));
    int sec = stoi(s.substr(2, 4));
    if (sec <= 12 && 0 < sec && fir > 0 && fir <= 12) {
        cout << "AMBIGUOUS" << endl;
    } else if (sec <= 12 && sec > 0) {
        cout << "YYMM" << endl;
    } else if (fir <= 12 && fir > 0) {
        cout << "MMYY" << endl;
    } else {
        cout << "NA" << endl;
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define fi first
#define se second
#define rep(i,s,n) for(int i = s;i<n;i++)
#define rrep(i,s,n) for(int i = (n)-1;i>=(s);i--)
#define all(v) (v).begin(),(v).end()
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
const ll MOD=1000000007,INF=1e18;
 
int A,B;
int cnt[50];
int cnt2[50];


signed main() {
    IOS();
    cin>>B>>A;
    A++;
    rep(i,0,40){
        int tmp=(1ll<<(i+1));
        cnt[i]+=(A/tmp)*tmp/2;
        cnt[i]+=max(0ll,A%tmp-tmp/2);
    }
    rep(i,0,40){
        int tmp=(1ll<<(i+1));
        cnt2[i]+=(B/tmp)*tmp/2;
        cnt2[i]+=max(0ll,B%tmp-tmp/2);
    }
    
    int ans=0;
    rep(i,0,40){
        if((cnt[i]-cnt2[i])%2)ans|=(1ll<<i);
    }
    cout<<ans<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
    int H,W,A,B;
    cin>>H>>W>>A>>B;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(j<A^i<B) cout<<1;
            else cout<<0;
        }
        cout<<endl;
    }
    return 0;
}

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

int main()
{
	int a, b; cin >> a >> b;

	double ans1 = (double) (a + b) / 2;
	double ans2 = (double) (a - b) / 2;

	if ( floor(ans1) == ans1 ) {
		cout << (int) ans1 << endl; 
	}
	else if ( floor(ans2) == ans2 ) {
		cout << (int) ans2<< endl;
	}
	else{ 
		cout << "IMPOSSIBLE" << endl;
	}

	return 0;
}

Measured memory_bytes: 256