akhauriyash/Code-Regression huggingface dataset:
n, m = map(int, input().split())
graph = [tuple(map(int, input().split())) for _ in range(m)]

def shortest_path(s):
    MIN = -1 * 10 ** 12
    d = [MIN] * (n + 1)
    d[s] = 0
    update = True
    cnt = 1
    tmp = MIN
    while update:
        update = False
        for a, b, c in graph:
            if d[a] != MIN and d[b] < d[a] + c:
                d[b] = d[a] + c
                update = True
        if cnt == m: tmp = d[n]
        if update and cnt == 2 * m and d[n] > tmp: return 'inf'
        if cnt == 2 * m: update = False
        cnt += 1
    return d[n]

print(shortest_path(1))

Measured memory_bytes: 3312
import java.util.*;

public class Main {
	public static void main(String[] args) {
		ALDS1_2_C();
	}
        public static void ALDS1_2_C() {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		String[] a = new String[n];
		int countAns = 0;
		for(int i = 0; i < n; i++) {
			a[i] = sc.next();
		}
		String[] b = a.clone();

		//bubble sort
		for(int i = 0; i < n; i++) {
			for(int j = n - 2; j >= i; j--) {
				int ai = Integer.parseInt(a[j + 1].substring(1, 2));
				int aj = Integer.parseInt(a[j].substring(1, 2));
				if(aj > ai) {
					String tempStr = a[j + 1];
					a[j + 1] = a[j];
					a[j] = tempStr;
				}
			}
		}

		//Selection sort
		for(int i = 0; i < n; i++) {
			int minj = i;
			for(int j = i; j < n; j++) {
				int aminj = Integer.parseInt(b[minj].substring(1, 2));
				int aj = Integer.parseInt(b[j].substring(1, 2));
				if(aj < aminj) {
					minj = j;
				}
			}
			if(minj != i) {
				String temp = b[i];
				b[i] = b[minj];
				b[minj] = temp;
			}
		}

		
		for(int i = 0; i < n; i++) {
			System.out.print(a[i]);
			if(i != n - 1)
				System.out.print(" ");
		}
		System.out.println();
		System.out.println("Stable");
		for(int i = 0; i < n; i++) {
			System.out.print(b[i]);
			if(i != n - 1)
				System.out.print(" ");
		}
		System.out.println();
		if(Arrays.equals(a, b)) {
			System.out.println("Stable");
		}else {
			System.out.println("Not stable");
		}
	}
}



Measured memory_bytes: 26584
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

int main()
{
  FAST/**/
   
   ll n;
   cin>>n;
   
   string s;
   cin>>s;
   
   ll red = 0;
   rep(n)
        if(s[i] == 'R')
            red++;
   ll ans = min(red,n-red);
   ll r = 0;
   for(ll i=0;i<n-1;i++)
   {
       if(s[i] == 'R')
            r++;
       ll c1 = i+1-r;
       ll c2 = (red-r);
       ll mini = min(c1,c2);
       ans = min(ans, c1 + c2 - mini);
   }
   cout<<ans;
   
   return 0;        
}  
  
          
   

Measured memory_bytes: 3748
N,M = map(int,raw_input().split())
A = map(int,raw_input().split())
dic = {}

for a in range(len(A)):
  if A[a] not in dic:
    dic[ A[a] ] = 1
  else:
    dic[ A[a] ] += 1

for a in range(M):
  B,C = map(int,raw_input().split())
  if C not in dic:
    dic[C] = B
  else:
    dic[C] += B

dic_list = sorted(dic.items(), key=lambda x:x[0], reverse=True)
ans = 0
now = 0
for a in range( len(dic_list) ):
  if dic_list[a][1] + now >= N:
    ans += dic_list[a][0] * (N-now)
    break
  ans += dic_list[a][0] * dic_list[a][1]
  now += dic_list[a][1]

print ans


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

int main() {
  int k, x;
  cin >> k >> x;
  int y = 500 * k;
  if (y >= x)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static long mod = 1000000007;

    public static long gcd(long a, long b) {
        if (a == 0) {
            return b;
        } else if (b == 0) {
            return a;
        } else {
            return gcd(b, a % b);
        }
    }

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] lis_a = new long[n+1];
        long[] lis_b = new long[n];

        for (int i = 0; i < n + 1; ++i) {
            lis_a[i] = sc.nextLong();
        }
        for (int i = 0; i < n; ++i) {
            lis_b[i] = sc.nextLong();
        }

        long sum = 0;
        for (int i = n; i >= 0; --i) {
            if (i == n) {
                long x = Math.min(lis_a[i], lis_b[i - 1]);
                sum += x;
                lis_b[i - 1] -= x;
            } else if (i == 0) {
                long x = Math.min(lis_a[i], lis_b[i]);
                sum += x;
                lis_b[i] -= x;
            } else {
                long x = Math.min(lis_a[i], lis_b[i] + lis_b[i - 1]);
                sum += x;
                if (lis_b[i] >= x) {
                    lis_b[i] -= x;
                } else {
                    lis_b[i - 1] -= x - lis_b[i];
                    lis_b[i] = 0;
                }
            }
        }

        System.out.println(sum);
    }
}


Measured memory_bytes: 67432
import sys
import re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy, copy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from queue import Queue


def input(): return sys.stdin.readline().strip()


def INT(): return int(input())


def MAP(): return map(int, input().split())


def LIST(): return list(map(int, input().split()))


sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7


def main():
    n = INT()
    a = LIST()

    ans = 0

    if n == 1:
        print(1)
        exit()

    if a[0] < a[1]:
        sign = 1
    elif a[0] > a[1]:
        sign = -1
    else:
        sign = 0

    for i in range(n-1):
        if a[i] < a[i+1] and sign == -1:
            ans += 1
            sign = 0

        elif a[i] > a[i+1] and sign == 1:
            ans += 1
            sign = 0

        elif sign == 0:
            if a[i] < a[i+1]:
                sign = 1
            elif a[i] > a[i+1]:
                sign = -1

    print(ans + 1)


if __name__ == '__main__':
    main()


Measured memory_bytes: 16324
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll 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(ret);
  return (ret);
}

signed main() {
  init();
  ll N;
  cin >> N;
  string S;
  cin >> S;
  ll current = 0;
  ll ans = 0;
  rep(i, N) {
    if (S[i] == 'I')
      current++;
    else
      current--;
    ans = max(ans, current);
  }
  ANS;
  return 0;
}

Measured memory_bytes: 3644
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <iterator>
#include <list>
#include <map>
#include <queue>
#include <cstring> 
#include <set>
#include <string>
#include <valarray>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define maxe(v) *max_element(v.begin(), v.end())
#define mine(v) *min_element(v.begin(), v.end())
#define pb push_back
#define pf push_front
#define rem 1000000007
#define cont continue

ll gcd(ll a, ll b)
{
    if (a == 0)
        return b;
    return gcd(b%a, a);
}
ll modulo(ll a, ll b)
{
    ll r = a % b;
    return r < 0 ? r + b : r;
}
ll longrem(string k,ll n)
{
    // k is taken into input as a string...
	int now=0;
    for(int i=0;i<k.size();i++)
    {
        now=(now*10)%n;
        now=(now+k[i]-'0')%n;
    }
    return now;    // O( log(k) )/log(10) )
}
ll ncr(ll n,ll k)  
{  
    ll res = 1;  
    if ( k > n - k )  
        k = n - k; 
    for (ll i = 0; i < k; ++i)  
    {  
        res *= (n - i);  
        res /= (i + 1);  
    }  
    return res;  
}

ll binaryToDecimal(ll n) 
{ 
    ll num = n; 
    ll dec_value = 0; 
  
    // Initializing base value to 1, i.e 2^0 
    ll base = 1; 
  
    ll temp = num; 
    while (temp) { 
        ll last_digit = temp % 10; 
        temp = temp / 10; 
  
        dec_value += last_digit * base; 
  
        base = base * 2; 
    } 
  
    return dec_value; 
} 

void decToBinary(int n) 
{ 
    
    int binaryNum[32]; 
  
    int i = 0; 
    while (n > 0) { 
  
         
        binaryNum[i] = n % 2; 
        n = n / 2; 
        i++; 
    } 
  
    // printing binary array in reverse order 
    for (int j = i - 1; j >= 0; j--) 
        cout << binaryNum[j]; 
} 
ll prime(ll n)
{
	ll flag=0;
	if(n==1 || n==2)
	{
		flag=0;
	}
	else 
	{
		if(n%2==0)
			flag=1;
		else
		{
			ll i=3;
			while(i<=sqrt(n) && flag==0)
			{
				if(n%i==0)
					flag=1;
				i=i+3;
			}
		}
	}
	return flag;
}
ll ispal(string str,string s)
{
	ll flag=0;
	reverse(str.begin(), str.end());
	if(str==s)
	{
		flag=1;
	}
	return flag;
}
ll ispalself(string str)
{
	ll flag=0;
	string s=str;
	reverse(str.begin(), str.end());
	if(str==s)
	{
		flag=1;
	}
	return flag;
}
/**************************************************************************************************************************************/
int main()
{
	
	ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
	
	
	
	/*ll t;
	cin>>t;
	while(t--)
	{*/
	ll i,n,a,b,x,y,flag=0;
	
	cin>>a>>b;
	
	n=(a*100)/8;
	do
	{
		x=(n*8)/100;
		y=(n/10);
		if( x==a  && (y==b))
		{
			flag=1;
			cout<<n<<"\n";
		}
		else
		{
			n++;
		}
		
		
		
	}while((x<=a || y<=b) && flag==0);
	
	
	if(flag==0)
	{
		cout<<"-1\n";
	}
	
	
	
			
	//}
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef pair<int, int> pii;
typedef long long LL;
#define mp(a, b) make_pair(a, b)
#define fir first
#define sec second
template <class T> inline void read(T &a) {
	static int ch = 0; bool f = 0; a = 0;
	while (ch < '0' || ch > '9') f |= ch == '-', ch = getchar();
	while (ch >= '0' && ch <= '9') a = a * 10 + ch - '0', ch = getchar();
	if (f) a = -a;
}
//#define MULTI_CASE
#define MOD
#define N

char s[100005];

void work() {
	scanf("%s", s + 1);
	int ans = 0;
	for (int i = 2; s[i]; i++) {
		if (s[i] != s[i - 1]) ans++;
	}
	cout << ans << endl;
}


int main() {
#ifdef MULTI_CASE
	int T;
	cin >> T;
	for (int i = 1; i <= T; i++) {
		printf("Case %d: ", i);
		work();
	}
#else
	work();
#endif
	return 0;
}


Measured memory_bytes: 384
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>

using namespace std ; 

typedef long long ll ; 

int main()
{
    ll x ; 
    scanf("%lld", &x) ; 
    ll ans = 0 ; 
    ans += 2*(x/11) ; 
    x %= 11 ; 
    if(x > 0) {
        ans++ ; 
        x -= 6 ; 
    }
    if(x > 0) {
        ans++ ; 
    }
    printf("%lld\n", ans) ; 
    return 0 ; 
}



Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
using namespace std;
const int N=1010;
int n,k,sum;
int a[N];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++) cin>>a[i];
	sort(a,a+n);
	
	for(int i=1;i<=k;i++)
		sum+=a[i-1];
	cout<<sum;
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>
#include <stack>
#include <string.h>
#include <cstdlib>
#include <queue>
#include <list>
#include <string>

using namespace std;

long long MOD = 1000000007;



int main()
{
    int n;
    cin >> n;
    
    vector< vector< int > > G(n);
    vector< pair< int,int > > vp;
     
    for (int i = 1;i < n;i++){
        int a,b;
        cin >> a >> b;
        a--;
        b--;
        G[a].push_back(b);
        G[b].push_back(a);
        vp.push_back(make_pair(a,b));
    }
    
    int K = 0;
    for (int i = 0;i < n;i++){
        int l = (int)G[i].size();
        K = max(K,l);
    }
    
    map< pair< int,int > ,int > I;
    vector<int> cs(n,0);
    vector<int> used(n,0);
    queue<int> q;
    used[0] = 1;
    q.push(0);
    while(!q.empty()){
        int v = q.front();
        q.pop();
        int cur = 1;
        for (int u:G[v]){
            if (used[u])  {continue;}
            if (cur == cs[v]) cur++;
            cs[u] = I[make_pair(u,v)] = I[make_pair(v,u)] = cur++;
            used[u] = 1;
            q.push(u);
        }
    }
    cout << K << endl;
    for (pair<int,int> p:vp){
        cout << I[p] << endl;
    }
}


Measured memory_bytes: 20084
import numpy as np
W,H,N = map(int, input().split())

box = np.ones((H,W))
for _ in range(N):
  xi, yi, ai = map(int, input().split())
  if   ai == 1: box[  :  ,  :xi] = 0
  elif ai == 2: box[  :  ,xi:  ] = 0
  elif ai == 3: box[  :yi,  :  ] = 0
  elif ai == 4: box[yi:  ,  :  ] = 0
print(np.count_nonzero(box))

Measured memory_bytes: 12508
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int a = sc.nextInt();
        int b = sc.nextInt();
        String u = sc.next();
        if (u.equals(s)) {
            a--;
        } else {
            b--;
        }
        System.out.println(a + " " + b);
    }
}


Measured memory_bytes: 21844
#include <iostream>
#include <bitset>
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;
#pragma warning (disable:4996)
const int maxn = 2005;
vector<int> E[maxn];
int vis[maxn], k, cnt, u[maxn], v[maxn];
void dfs(int x, int step) {
	if (step == k + 1)
		return;
	for (int i = 0; i < E[x].size(); i++) {
		if (vis[E[x][i]] == -1) {
			vis[E[x][i]] = step;
			cnt++;
			dfs(E[x][i], step + 1);
		}
		else if (vis[E[x][i]] > step) {
			vis[E[x][i]] = step;
			dfs(E[x][i], step + 1);
		}
	}
}
int main() {
	int n;
	scanf("%d%d", &n, &k);
	int ans = n;
	for (int i = 1; i < n; i++) {
		scanf("%d%d", &u[i], &v[i]);
		E[u[i]].push_back(v[i]);
		E[v[i]].push_back(u[i]);
	}
	if (~k & 1) {
		k >>= 1;
		for (int i = 1; i <= n; i++) {
			fill(vis, vis + n + 1, -1);
			vis[i] = 0; cnt = 1;
			dfs(i, 1);
			ans = min(ans, n - cnt);
		}
	}
	else {
		k >>= 1;
		for (int i = 1; i < n; i++) {
			fill(vis, vis + n + 1, -1);
			vis[u[i]] = vis[v[i]] = 0; cnt = 2;
			dfs(u[i], 1); dfs(v[i], 1);
			ans = min(ans, n - cnt);
		}
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 384
L = list(map(int, input().split()))
Ldiff = []
Ldiff.append(abs(L[1] - L[0]))
Ldiff.append(abs(L[2] - L[1]))
Ldiff.append(abs(L[0] - L[2]))
Ldiff.sort()
print(Ldiff[0] + Ldiff[1])

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>

#define ll long long
#define pb push_back
#define sz(x) (int)(x).size()
#define mp make_pair
#define f first
#define s second
#define all(x) x.begin(), x.end()

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;

template<class T> using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>; ///find_by_order(),order_of_key()
template<class T1, class T2> ostream& operator<<(ostream& os, const pair<T1,T2>& a) { os << '{' << a.f << ", " << a.s << '}'; return os; }
template<class T> ostream& operator<<(ostream& os, const vector<T>& a) {
	os << '{';
	for(int i=0;i<sz(a);i++)
	{
		if(i>0&&i<sz(a)-1)
			os << ", ";
		os << a[i];
	}
	os << '}';
    return os;
}
const int N=3e3+1;
int dp[N][N];
int best[N][N];
string s,t;
int calc(int i,int j)
{
    if(i==0||j==0){
        best[i][j]=-2;
        return dp[i][j]=0;
    }
    if(dp[i][j]!=-1)
        return dp[i][j];
    if(s[i]==t[j])
    {
        best[i][j]=-1;
        return dp[i][j]=1+calc(i-1,j-1);
    }
    int a=calc(i-1,j);
    int b=calc(i,j-1);
    if(a>=b)
    {
        best[i][j]=1;
        return dp[i][j]=a;
    }
    best[i][j]=2;
    return dp[i][j]=b;
}
int main()
{
    memset(dp,-1,sizeof(dp));
    cin >> s;
    cin >> t;
    s='0'+s;
    t='0'+t;
    calc(s.size()-1,t.size()-1);
    int i=s.size()-1,j=t.size()-1;
    string sol;
    while(best[i][j]!=-2)
    {
        if(best[i][j]==-1)
        {
            sol+=s[i];
            i--;
            j--;
            continue;
        }
        if(best[i][j]==1)
        {
            i--;
            continue;
        }
        j--;
        continue;
    }
    reverse(all(sol));
    cout << sol << endl;
    return 0;
}


Measured memory_bytes: 70912
# # Make IO faster
# import sys
# input = sys.stdin.readline

# # get single (or) multiple str
# X = input()

# # get single int
# N = int(input())
# # get multiple int (e.g., 2)
# X, Y = map(int, input().split())
# # get multiple int (e.g., 2) for N lines
# XY = [list(map(int, input().split())) for _ in range(N)]

# from IPython import embed; embed(); exit();

# 全部入り
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
import numpy as np
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

S = input()
if S[0] == S[2]:
    print("Yes")
else:
    print("No")


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

#define PI 3.14159265358979323846264338327950288419

using namespace std;

char str[15];

int main(){
	scanf("%s", str);
	int len = strlen(str);
	if(len % 2 != 0){
		printf("No\n");
	}else{
		for(int i = 0; i < len; i += 2){
			if(str[i] != 'h' || str[i + 1] != 'i'){
				printf("No\n");
				return 0;
			}
		}
		printf("Yes\n");
	}
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <stack>
#include <set>
#include <cstdio>
using namespace std;

typedef long long ll;
typedef pair<int,int> P1;
typedef pair<int,P1> P2;
const int inf=1000000000;
struct edge{
	int to,cost;
};

int main() {
	ll n,x;
	cin>>n>>x;
	ll d=1;
	ll t=x;
	n-=x;
	while(d>0){
		d=n%x;
		t+=n+(2*(n/x)-1)*x;
		n=x;
		x=d;
	}
	cout<<t<<endl;

	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<ll, ll> P;
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; }

class union_find {
    private:
        vector<int> par;
        vector<int> ran;
        vector<ll> size;
    public:
        union_find(int n);
        int find(int x);
        void unite(int x, int y);
        bool same(int x, int y);
        ll show_size(int x);
};

union_find::union_find(int n){
    par.resize(n);
    ran.resize(n);
    size.resize(n);
    rep(i,n) par[i] = i;
    rep(i,n) ran[i] = 0;
    rep(i,n) size[i] = 1;
};

int union_find::find(int x) {
    if(par[x] == x) return x;
    else return par[x] = find(par[x]);
};

void union_find::unite(int x, int y) {
    x = find(x);
    y = find(y);
    if(x == y) return;
    ll t = show_size(x)+show_size(y);
    size[x] = size[y] = t;
    if(ran[x] < ran[y]){
        par[x] = y;
        //size[y] += size[x];
    }
    else{
        par[y] = x;
        //size[x] += size[y];
        if(ran[x] == ran[y]) ran[x]++;
    }
};

ll union_find::show_size(int x) {
    if(par[x] == x) return size[x];
    return show_size(par[x] = find(par[x]));
}

bool union_find::same(int x, int y) {
    return (find(x) == find(y));
};

class Edge {
public:
	ll source, target, cost;
	Edge(ll source = 0, ll target = 0, ll cost = 0) :
		source(source), target(target), cost(cost) {}
	bool operator<(const Edge &e)const {
		return cost < e.cost;
	}
};
 
ll kruskal(ll N, vector<Edge> &edges) {
	ll totalCost = 0;
	sort(edges.begin(), edges.end());
	union_find uni(N);
	ll source, target;
	for (ll i = 0; i < edges.size(); i++) {
		Edge e = edges[i];
		if (!uni.same(e.source, e.target)) {
			totalCost += e.cost;
			uni.unite(e.source, e.target);
		}
	}
	return totalCost;
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<P> v(n), w(n);
    rep(i,n){
        ll x, y;
        cin >> x >> y;
        v[i].first = x;
        w[i].first = y;
        v[i].second = i;
        w[i].second = i;
    }
    sort(v.begin(), v.end());
    sort(w.begin(), w.end());
    vector<Edge> es;
    rep(i,n-1) es.push_back(Edge(v[i].second, v[i+1].second, v[i+1].first - v[i].first));
    rep(i,n-1) es.push_back(Edge(w[i].second, w[i+1].second, w[i+1].first - w[i].first));
    cout << kruskal(n, es) << endl;
	return 0;
}

Measured memory_bytes: 12612
STATUS = Array.new(1010, :unused)
def active?(v); STATUS[v] == :active; end
def activate!(v);  v.tap{ STATUS[v] = :active }; end
def inactivate!(v); v.tap{ STATUS[v] = :used }; end
def used?(v); STATUS[v] != :unused; end
def use!(v); v.tap{ STATUS[v] = :used }; end
def subgraph_include?(v); STATUS[v] == :unused; end
def subgraph_init!(vset); STATUS.fill(:used); vset.each{|v| STATUS[v] = :unused}; end

N,M = gets.split.map(&:to_i)
G = Array.new(N + 1){ [] }
E = M.times.map{ gets.split.map(&:to_i) }
E.each do |from,to|
  G[from] << to
end

def cycle_exists?
  (1 .. N).each do |s|
    next if used?(s)
    stack = [use!(s)]
    cycle = find_cycle(stack)
    return cycle if cycle
  end
  return false
end

def smaller_cycle?(cycle)
  subgraph_init!(cycle)
  
  shortcut = nil
  smaller_not_found = cycle.each_with_index.none? do |from, i|
    to = (i + 1 == cycle.size ? cycle[0] : cycle[i + 1])
    to_ = G[from].find{|t| subgraph_include?(t) && t != to }
    shortcut = [from, to_] if to_
  end
  
  return false if smaller_not_found

  stack = [activate!(shortcut[0]), use!(shortcut[1])]
  find_cycle(stack)
end

def find_cycle(stack)
  until stack.empty?
    u = stack.pop
    
    if active?(u) 
      inactivate!(u)
      next 
    end
    
    stack << activate!(u)
    
    G[u].each do |v|
      if active?(v)
        cycle = stack.select{|r| active?(r) }
                  .drop_while{|r| r != v } 
        return cycle
      end
      used?(v) || stack << use!(v)
    end
  end
  false
end

cycle = cycle_exists?

if !cycle
  puts -1
else
  loop do
    smaller = smaller_cycle?(cycle)
    break if !smaller  
    cycle = smaller
  end
  puts cycle.size
  puts cycle
end


Measured memory_bytes: 2172
import scala.io.StdIn
object Main extends App {
   def divide(nums: Array[Int], count: Int): Int = {
    if (nums.exists(_ % 2 != 0))
      count
    else
      divide(nums.map(_ / 2), count + 1)
  }

  val N = StdIn.readInt()
  val nums = StdIn.readLine().split(" ").map(_.toInt)

  println(divide(nums, 0))
}



Measured memory_bytes: 25680
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <deque>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

const int INF = 1e9;
const long long LINF = 1e18;
const double PI=3.14159265358979323846;

typedef priority_queue<int, vector<int>, greater<int>> priority_queue_asc;

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

    long long s = a[0];
    for (long long i = 1; i < N; i++) {
        s = s ^ a[i];
    }

    for (long long i = 0; i < N; i++) {
        cout << static_cast<long long>(s ^ a[i]);
        if (i != N - 1) {
            cout << ' ';
        }
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <map>
#include <math.h>
#include <vector>
using namespace std;
map<int, int> ct;
map<int, int> ct2;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPS 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair

#define FOR(i, a, b) for (int i=(a); i<=(signed)(b); i++)
#define AFOR(i, a) for (int i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 100005
int n, m, l;
int a, b, c;
string s[MN];
string str;
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

/*
int N;
cin >> N;
vi vect(N);
FOR(i,N) cin >> vec.at(i);*/
//sort(vec.begin(),vec.end());
//vvi data(N,vi(4));


/*	int bfs(int x, int y,vvi &A,vvi flag) {
		queue<pii> que;
		que.push(pii(x, y));
		while (que.size()) {
			pii p = que.front(); que.pop();
			AFOR(i, 4) {
				int nx = p.first + dx[i]; int ny = p.second + dy[i];
				if (0 <= nx && nx < N && 0 <= ny && ny < N) {
					if (A.at(p.first).at(p.second) + flag.at(p.first).at(p.second) < A.at(nx).at(ny)) {
						A.at(nx).at(ny) = A.at(p.first).at(p.second) + flag.at(p.first).at(p.second);
						que.push(pii(nx, ny));
					}
				}
			}
		}
		return 0;
	}
	*/
	/*int gcd(int p, int q){
		while(q != 0){
		int r = p % q;
		p = q;
		q = r;
		}
	return p;
	}*/
ll N;
ll K;
int A[200100];
int  L[200100];
ll ans = 0;
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	ll a, b;
	cin >> a >> b;
	
	cout << a*b << endl;
	return 0;
}

Measured memory_bytes: 6704
#include<cstdio>
#include<string>
#include<cstring>
#include<algorithm>
using namespace std;

int n,m,x,y,cp[1000][2],num=0,ans=0,fz[701][701],A=1e9;
bool b[701][701],o[701],c[701];
void dfs(int x,int p){
	if (o[x]&&c[x]!=p) {ans=1;return;}
	if (o[x]) return;
	cp[num][p]++;o[x]=1;c[x]=p;
	for (int i=1;i<=n;i++) if (x!=i&&!b[x][i]) dfs(i,p^1);
}
int main(){
	scanf("%d%d",&n,&m);
	for (int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);
		b[x][y]=b[y][x]=1;
	}
	for (int i=1;i<=n;i++)
	if (!o[i]){
		num++;
		dfs(i,0);
	}
	if (ans) return puts("-1"),0;
	fz[0][0]=1;
	for (int i=1;i<=num;i++){
		for (int j=0;j<=n;j++)
		if (fz[i-1][j]) fz[i][j+cp[i][0]]=fz[i][j+cp[i][1]]=1;
	}
	for (int i=0;i<=n;i++)
	if (fz[num][i]&&i*(i-1)/2+(n-i)*(n-i-1)/2<A) A=i*(i-1)/2+(n-i)*(n-i-1)/2;
	printf("%d\n",A);
}

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

typedef long long ll;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
 
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;

int n,q;
string s;
int l[1000000],r[1000000], c[1000000], ans;
int main() {
    cin >> n >> q >> s;
    for (int i=0;i<q;i++) {
        cin >> l[i] >> r[i];
    }
    int cnt = 0;
    for (int i=0;i<n-1;i++) {
        if (s[i]=='A' && s[i+1] == 'C') cnt++;
        //c[i] i文字目までに現れるACの数
        c[i+1] = cnt;
    }
    for (int i=0;i<q;i++) {
        ans = c[r[i]-1] - c[l[i]-1];
        cout << ans << endl;
    }
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
#define endl "\n"

using namespace std;

int main()
{
	long long a,b;
	char c; int d;
	cin >> a;
	cin >> b;
	cin>>c;
	cin >> d;
	b*=100;
	b+=d;
	long long prod= (a*b)/100;
	cout<<prod<<endl;
}


Measured memory_bytes: 3592
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
template < typename T > std::string to_string( const T& n )
  {
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
  }
using namespace std;

const long long INF=9000000000000000;
int main(){
  string s;
  char a;
  cin>>s;
  int n,ans=0,aans=0;
  n=s.size();
  char x[n];
  char y[n];
  for(int i=0;i<n;i++){
    if(i%2==0){
      x[i]='0';
      y[i]='1';
    }
    else{
      x[i]='1';
      y[i]='0';
    }
  }
  for(int i=0;i<n;i++){
    if(s[i]!=x[i])
    ans++;
    if(s[i]!=y[i])
    aans++;
  }
  cout<<min(ans,aans)<<endl;
}


Measured memory_bytes: 640
#include <iostream>
using namespace std;
int main(void){
    long long n,i,c;
    cin>>n;
    long long p[n];
    for(i=0;i<n;i++){
        cin>>p[i];
    }
    c=0;
    for(i=1;i<n-1;i++){
        if(p[i-1]<p[i]&&p[i]<p[i+1]){
            c++;
        }else if(p[i-1]>p[i]&&p[i]>p[i+1]){
            c++;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main()
{
    int n;
    cin>>n;
    bool a=false;
    for(int i=1;i<10;i++)
    {
        if( n/i < 10 && n%i==0)
        {
            a=true;
        }
    }
    if(a)
    {
        cout<<"Yes";
    }
    else
    {
        cout<<"No";
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  int L[210];
  for (int i = 0; i < 2 * N; i++) cin >> L[i];

  sort(L, L + 2 * N);

  int ans = 0;
  for (int i = 0; i < 2 * N; i += 2) {
    ans += L[i];
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define X first
#define Y second
using namespace std;

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

const ll Q = (ll)(1e9) + 7;
const int MAXN = 1e5+1;

vector<int> nxt[MAXN];
vector<pii> q;
bool used[3][MAXN];
int dist[3][MAXN];



int main() {
	ios_base::sync_with_stdio(0);

	int n, m;
	cin >> n >> m;
	while(m--) {
		int x, y;
		cin >> x >> y;
		nxt[x].push_back(y);
	}
	int s, t;
	cin >> s >> t;
	q.push_back({s,0});
	used[0][s] = 1;
	for(int i = 0; i < q.size(); i++) {
		int v = q[i].X;
		int d = q[i].Y;
		for(int w : nxt[v]) {
			int dd = (d+1)%3;
			if(!used[dd][w]) {
				used[dd][w] = 1;
				dist[dd][w] = dist[d][v] + 1;
				q.push_back({w,dd});
			}
		}
	}

	cout << (used[0][t] ? dist[0][t]/3 : -1) << '\n';

	return 0;
}

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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

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

  double n, m, d;
  cin >> n >> m >> d;
  double ans = 0.0;
  if(d == 0){
    ans = (m-1)/n;
  }else{
    ans = 2*(n-d)/(n*n)*(m-1);
  }

  cout << setprecision(12) << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <cmath>
#include <stack>
#include <map>
using namespace std;

void dfs(vector<vector<int> > &list, vector<bool> &unit, int now,int from){
    unit.at(now) = 1 ;
    for (size_t i = 0; i < list.at(now).size(); i++)
    {
        int next = list.at(now).at(i) ;
        if (next != from && unit.at(next) == 0)
        {
            dfs(list,unit,next,now) ;
        }
        
    }
    
}

bool judge(vector<vector<int> > &list,vector<bool> &unit,int n){
    dfs(list,unit,0,-1);
    for (size_t i = 0; i < n; i++)
    {
        if (unit.at(i) == 0)
        {
            return 1 ;
        }
        
    }
    return 0 ;
}

int main(){    
    int n,m ;
    cin >> n >> m ;
    vector<vector<int> > list(n,vector<int>()) ;
    vector<pair<int,int> > edge(m,pair<int,int>() ) ;
    for (size_t i = 0; i < m; i++)
    {
        int x,y ;
        cin >> x >> y ;
        edge.at(i).first = x-1 ;
        edge.at(i).second = y-1 ;
        list.at(x-1).push_back(y-1) ;
        list.at(y-1).push_back(x-1) ;
    }
    int ans = 0 ;
    vector<bool> unit(n,0);
    for (size_t i = 0; i < m; i++)
    {
        int end1 = edge.at(i).first ;
        int end2 = edge.at(i).second ;
        remove(list.at(end1).begin(), list.at(end1).end(),end2);
        list.at(end1).pop_back() ;
        remove(list.at(end2).begin(), list.at(end2).end(),end1);
        list.at(end2).pop_back() ;
        ans += judge(list,unit,n) ;
        /*cout << "edge" << i << "を削除" << endl ;
        for (size_t i = 0; i < n; i++)
        {
            cout << i+1 <<"(" << list.at(i).size() << "):" ;
            for (size_t j = 0; j < list.at(i).size(); j++)
            {
                cout << " " << list.at(i).at(j) +1 ;
            }
            cout << endl ;
        }*/
        
        list.at(end1).push_back(end2);
        list.at(end2).push_back(end1);
        for (size_t i = 0; i < n; i++)
        {
            unit.at(i) = 0 ;
        }
        
    }
    cout << ans << endl ;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <string>
#include <algorithm>
#include <set>
using namespace std;

int n;
int a[200];

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


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

int mostFrequent(vector<int> arr, int n){
    // Insert all elements in hash.
    unordered_map<int, int> hash;
    for (int i = 0; i < n; i++)
        hash[arr[i]]++;

    // find the max frequency
    int max_count = 0, res = -1;
    for (auto i : hash) {
        if (max_count < i.second) {
            res = i.first;
            max_count = i.second;
        }
    }
    return max_count;
}

int main (){
	int n;
	cin>> n;
	int arr[n];
	vector <int> arr2;
	
	for(int i = 0; i < n; i++){
		cin>>arr[i];
	}
	for(auto d : arr){
		int x, z;
		x = d - 1;
		z = d + 1;

		arr2.push_back(x);
		arr2.push_back(d);
		arr2.push_back(z);
	}
	int size = arr2.size();

	sort(arr2.begin(), arr2.end());
	
	cout<< mostFrequent(arr2, size) <<"\n";
	
	

	return 0;
}

Measured memory_bytes: 6896
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
 
int main(){
    int A, B, C;
    cin >> A >> B >> C;
    
    int ans;
    if(A + B >= C)
        ans = B + C;
    else
        ans = B + (A + B) + 1;
        
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
	char C[2][3];

	for (int i = 0; i < 2; i++)
	{
		for (int j = 0; j < 3; j++)
		{
			cin >> C[i][j];
		}
	}

	if (C[0][0] == C[1][2] && C[0][2] == C[1][0] && C[0][1] == C[1][1]) {
		cout << "YES" << endl;

	}
	else {
		cout << "NO" << endl;
	}

	return 0;
}

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

#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 pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

const int MAX = 40;

int ans;
int n;
int c[MAX];

int main(void) {
    cin >> n;
    vector<ll> a(n);
    rep(i, 0, n) cin >> a[i];

    rep(i, 0, MAX) {
        rep(j, 0, n) c[i] += ((a[j]>>i)&1LL);
    }

    rep(i, 0, n) {
        rep(j, 0, MAX) {
            if (c[j]%2==1) {
                if ((a[i]>>j)&1LL) a[i] -= (1LL<<j);
                else a[i] += (1LL<<j);
            }
        }

    }

    rep(i, 0, n) {
        if (i>0) printf(" ");
        printf("%lld", a[i]);
    }

    cout << "\n";
    return 0;
}



Measured memory_bytes: 4844
#include<stdio.h>
int main()
{
    long long int t,num[100020],i,a[100010]={0},flag=1,sum,j;
    scanf("%lld",&t);
    for( i =  0 ; i<t ; i++)
    {
        scanf("%lld",&num[i]);
        a[num[i]]++;
    }
    if(t == 1 && num[0]== 0){
        printf("1\n");
        return 0;
    }
    else if(t%2 == 0)
    {
        for(i = 1 ; i<t ; i=i+2)
        {
            if(a[i]!=2)
            {
                flag = 0 ;
                break ;
            }
        }
        for(i = 0 ; i<t ; i = i+2)
        {
            if(a[i]!= 0)
            {
                flag = 0;
                break ;
            }
        }

    }
    else
    {
        if(a[0]!=1)
        {
            flag = 0;
        }
        else
        {
            for(i = 2 ; i<t ; i = i+2)
            {
                if(a[i]!=2)
                {
                    flag = 0;
                    break ;
                }
            }
            for(i = 1 ; i<t ; i=i+2)
            {
                if(a[i]!=0)
                {
                    flag = 0 ;
                    break ;
                }
            }
        }

    }
    if(flag == 0)
        printf("0\n");
    else
    {
        if(t % 2!= 0)
            t = t - 1;
        t=t/2;
        sum = 2 ;
        for( j = 1 ; j<t ; j++)
        {
            sum*=2 ;
            sum%=1000000007;
        }
        printf("%lld\n",sum);

    }
    return 0;
}


Measured memory_bytes: 1664
#include <iostream>
#include <string>


int main(){
  int N[4];
  for(int i=0;i<4;i++)
    std::cin>>N[i];
  
  bool check=false;
  
  for(int i=0;i<4;i++)
    for(int j=0;j<4;j++)
      for(int k=0;k<4;k++)
        for(int l=0;l<4;l++)
          if(1000*N[i]+100*N[j]+10*N[k]+N[l]==1974)
            check=true;
          
  if(check) std::cout<<"YES"<<std::endl;
  else std::cout<<"NO"<<std::endl;
  
  return 0;
    
}

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

bool is_shichigosan(int n) {
  unordered_set<int> res;
  while (n) {
    res.insert(n % 10);
    n /= 10;
  }
  return res.size() == 3;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<long long> q(100100);
  vector<int> cand = {3, 5 ,7};
  int ma = 1001001001;
  int j = 1;
  bool flag = false;
  for (int i = 0; i < 100100; i++) {
    for (int &c : cand) {
      q[j] = q[i] * 10 + c;
      if (q[j] > ma) {flag = true; break;}
      j++;
    }
    if (flag) break;
  }
  vector<int> res;
  for (auto &x : q) {
    if (is_shichigosan(x)) res.push_back(x);
  }
  int n; cin >> n;
  cout << upper_bound(res.begin(), res.end(), n) - res.begin() << '\n';
  return 0;
}

Measured memory_bytes: 1280
#include<iostream>
#include<algorithm>
#include<climits>
#include<cstring>
#include<vector>
#include<queue>
#include<utility>
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define scan(arg) cin>>arg
#define prin(arg) cout<<arg<<"\n"
#define prin2(arg1,arg2) cout<<arg1<<" "<<arg2<<"\n"
using namespace std;
typedef long long ll;
const int NMAX=1<<17;
typedef pair<ll,int> pi;
const ll INF=1000000000;
int n,m,R;
ll r[9],a[100000],b[100000],c[100000];
ll cutg[10][10];
struct edge{//辺の情報
  ll to,cost;
};
int V,E;//頂点の数、辺の数
vector<edge> g[100000];
ll d[210];//d[u]は始点から頂点uへの最短距離
void dijkstra(int s){//始点sからのダイクストラ
  priority_queue<pi,vector<pi>,greater<pi> > q;//pair(コスト、頂点)としてコストの小さい順に並ぶ
  for(int i=0;i<V;i++) d[i]=INF;//初期化
  d[s]=0;
  q.push(pi(0,s));
  while(!q.empty()){
    pi p = q.top();q.pop();
    int w=p.second;//最新の確定した頂点
    if(d[w]<p.first) continue;//取り出した頂点のコストが最短コストより長かったら破棄
    for(int i=0;i<g[w].size();i++){//取り出した頂点と隣接した頂点を調べる
      int t=g[w][i].to;
      ll c=g[w][i].cost;
      if(d[t]>d[w]+c){//頂点tまでの暫定最短距離よりwまでの最短距離+w→tのコストが小さければ更新
	d[t]=d[w]+c;
	q.push(pi(d[t],t));
      }
     }
  }
}

ll dp[1<<10][10];
ll rec(int S,int v,int go){
  if(dp[S][v]>=0) return dp[S][v];
  if(S==(1<<R)-1&&v==go) return dp[S][v]=0;
  ll res=1e+12;
  rep(u,R){
    if(!(S>>u&1)){
      res=min(res,rec(S|1<<u,u,go)+cutg[v][u]);
    }
  }
  return dp[S][v]=res;

}

int main(){
  scan(n);scan(m);scan(R);
  rep(i,R){
    scan(r[i]);
  }
  rep(i,m){
    scan(a[i]);scan(b[i]);scan(c[i]);
  }
  rep(i,m){
    edge e;
    e.to=b[i]-1;e.cost=c[i];
    g[a[i]-1].push_back(e);
    e.to=a[i]-1;
    g[b[i]-1].push_back(e);
  }
  V=n;
  rep(i,R){
    dijkstra(r[i]-1);
    rep(j,R){
      cutg[i][j]=d[r[j]-1];
    }
  }
  /*    rep(i,R){
    rep(j,R){
      cout<<i<<" "<<j<<" "<<cutg[i][j]<<"\n";
    }
    }
  */
  ll res=1e+12;
  //  prin(res);
  rep(i,R){
    rep(j,R){
      memset(dp,-1,sizeof(dp));
      //  cout<<i<<" "<<j<<" "<<rec(1<<i,i,j)<<"\n";
      res=min(res,rec(1<<i,i,j));
    }
  }
  prin(res);
    

  return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;

///assic value of ('0'-'9') is(48 - 57) and (a-z) is (97-122) and (A-Z) is(65-90) and 32 for space
typedef long long int ll;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef vector<char> VEC1D;
typedef vector<VEC1D> VEC2D;
typedef vector<VEC2D> VEC3D;
typedef vector<ll> VEC1Dll;
typedef vector<VEC1Dll> VEC2Dll;
typedef vector<VEC2Dll> VEC3Dll;
typedef cc_hash_table<ll, ll, hash<ll>> ht;
typedef gp_hash_table<int, int> gt;

#define  pb push_back
#define f(i,a,b) for(ll i=a;i<b;i++)
#define fo(i,a,b) for(ll i = a; i<=b;i++)
#define rf(i,a,b)  for(ll i=a;i>=b;i--)
#define vll vector<ll>
#define tests() int test_cases ; cin >> test_cases ; while(test_cases--)
#define ub upper_bound
#define lb lower_bound
#define all(v) v.begin(),v.end()
#define MAXN 100001
#define MOD 1000000007
#define deb(x) cout << '>' << #x << ':' << x << endl;
#define sp " "
#define MS(x,y) memset(x,y,sizeof(x))

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    cout<<n*n*n;
    return 0;
}


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

int main(void){
    int E,Y;
    scanf("%d %d",&E,&Y);
    if(E==0){
        if(1868<=Y && Y<=1911){
            printf("M%d\n",Y-1867);
        }else if(1912<=Y && Y<=1925){
            printf("T%d\n",Y-1911);
        }else if(1926<=Y && Y<=1988){
            printf("S%d\n",Y-1925);
        }else{
            printf("H%d\n",Y-1988);
        }
    }
    if(E==1){
        printf("%d\n",1867+Y);
    }
    if(E==2){
        printf("%d\n",1911+Y);
    }
    if(E==3){
        printf("%d\n",1925+Y);
    }
    if(E==4){
        printf("%d\n",1988+Y);
    }
    return 0;
}



Measured memory_bytes: 3236
N = int(input())
a = [int(i) for i in input().split()]
rank = [0]*9
ans = [0]*2
for i in range(len(a)):
    if a[i] < 400:
        rank[0] = 1
    elif a[i] < 800:
        rank[1] = 1
    elif a[i] < 1200:
        rank[2] = 1
    elif a[i] < 1600:
        rank[3] = 1
    elif a[i] < 2000:
        rank[4] = 1
    elif a[i] < 2400:
        rank[5] = 1
    elif a[i] < 2800:
        rank[6] = 1
    elif a[i] < 3200:
        rank[7] = 1
    else:
        rank[8] += 1
ans[0] = sum(rank)

if sum(rank[:8]) == 0:
    ans[1] = 1
else:
    ans[1] = sum(rank[:8])

[print(ans[i], end=' ') for i in reversed(range(len(ans)))]


Measured memory_bytes: 3064
n = gets.to_i
s = gets.chomp.split("").map{ |x| 
	if x == "R" then
		1
	elsif x == "G" then
		2
	else
		4
	end
}

sum = 0

(1..n - 2).each{ |i|
	cand = [1, 2, 4]

	cand = cand - [s[i]]

	(1 .. [i, n - 1 - i].min).each{ |x|
		if s[i - x] != s[i + x] && s[i - x] != s[i] && s[i + x] != s[i] then
			sum -= 1
		end
	}

	left = s[0 .. i - 1]
	right = s[i + 1 .. n - 1]
	
	sum += left.count{ |x| x == cand[0] } * right.count{ |x| x == cand[1] }
	sum += left.count{ |x| x == cand[1] } * right.count{ |x| x == cand[0] }
}

puts sum


Measured memory_bytes: 14828
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 羊(S)
		int s = sc.nextInt();
		// 狼(W)
		int w = sc.nextInt();
		
 		if(s > w) {
			System.out.println("safe");
        } else {
            System.out.println("unsafe");
        }
	}
}

Measured memory_bytes: 35696
#include <stdio.h>

int main(void) {
    int a, b, ans;
    double max, min;
    scanf("%d %d", &a, &b);

    max = a*12.5 > 10*b ? a*12.5 : 10*b;
    if (max > (int)max) max++;
    int maxi = max;
    min = (a+1)*12.5 < (b+1)*10 ? (a+1)*12.5 : (b+1)*10;
    if (maxi >= min) ans = -1;
    else ans = maxi;

    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
//大文字->小文字 tolower(),逆はtoupper()
//int a = stoi(c); 文字列をintへ
//途中の出力をそのまま残さない
//数値計算 個数以外はdouble
//map<キー,値> p は辞書。p[キー] = 値
//map 全探索
//auto begin = p.begin(), end = p.end();
//for (auto it = begin; it != end; i++) {}
//mapのキー：it->first mapのバリュー：it->second
//絶対値 abs()
//入力は空白で切れる
//大文字判定 isupper(文字) 小文字判定 islower(文字)
//do{}while(next_permutation(ALL(配列)))
#include <bits/stdc++.h>
#define rep(i,N) for(int i = 0; i < N;i++)
#define ALL(a) (a).begin(),(a).end()
#define ll long long int
using namespace std;

// K進数でのNの桁数
ll dig(ll N,ll K) {
	ll dig = 0;
	while (N) {
		dig++;
		N /= K;
	}
	return dig;
}
// x,yの最大公約数
ll gcd(ll x, ll y) {
	ll r;
	while (x%y) {
		r = x % y;
		x = y;
		y = r;
	}
	return y;
}

int main() {
	ll N, A; cin >> N >> A;
	if (N % 500 <= A) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256