akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <climits>
#include <string>
#include <cstdlib>
#include <cctype>
#include <algorithm>
#include <stack>
#include <cstdio>

using namespace std;

bool isoperator(const string& s)
{
    switch(s[0])
    {
    case '+':
    case '-':
    case '*':
    case '/':
    case '%':
        return true;
    default:
        return false;
    }
}

int main()
{
    string line;
    stack<int> s;
    while (cin >> line)
    {
        if (! isoperator(line))
        {
            s.push(atoi(line.c_str()));
        }
        else
        {
            int first, second;
            second = s.top();
            s.pop();
            first = s.top();
            s.pop();
            switch(line[0])
            {
            case '+':
                s.push(first + second);
                break;
            case '-':
                s.push(first - second);
                break;
            case '*':
                s.push(first * second);
                break;
            case '/':
                s.push(first / second);
                break;
            case '%':
                break;
            default:
                break;
            }
        }
    }
    cout << s.top() << endl;
}



Measured memory_bytes: 3216
/********
*	???????????????
*********/	
/*********??¢?????´?????????
*	??????????????????????????????????????\????????¢???????????????4??¢???1??????????????????????????????
*	???????????´??¢?????????????????????????????§??????????????????
*********/

#include <stdio.h>
#include <iostream>
using namespace std;


int main(void)
{
	int dice[6]={0}; 		//?????????????????¢?????°???????????????????????????[0]????????¢
	int q;
	int a,b;
	
	for(int i=0; i< 6; i++){//????????????6??¢?????°?????\???
		cin >> dice[i];
	}
	
	cin >> q;

	for(int i = 0; i< q; i++){
		cin >> a >> b;
	
		if(a == dice[0]){
			if		(b == dice[1]){
				cout << dice[2] <<endl;
			}else if(b == dice[2]){
				cout << dice[4] <<endl;
			}else if(b == dice[3]){
				cout << dice[1] <<endl;
			}else if(b == dice[4]){
				cout << dice[3] <<endl;
			}else{
			//??????????????\??????
			}
		}
		else if(a == dice[1]){
				if  (b == dice[0]){
				cout << dice[3] <<endl;
			}else if(b == dice[2]){
				cout << dice[0] <<endl;
			}else if(b == dice[3]){
				cout << dice[5] <<endl;
			}else if(b == dice[5]){
				cout << dice[2] <<endl;
			}else{
			//??????????????\??????
			}
		}
		else if(a == dice[2]){
			if  (b == dice[0]){
				cout << dice[1] <<endl;
			}else if(b == dice[1]){
				cout << dice[5] <<endl;
			}else if(b == dice[4]){
				cout << dice[0] <<endl;
			}else if(b == dice[5]){
				cout << dice[4] <<endl;
			}else{
			//??????????????\??????
			}
		}
		else if(a == dice[3]){
			if  (b == dice[0]){
				cout << dice[4] <<endl;
			}else if(b == dice[1]){
				cout << dice[0] <<endl;
			}else if(b == dice[4]){
				cout << dice[5] <<endl;
			}else if(b == dice[5]){
				cout << dice[1] <<endl;
			}else{
			//??????????????\??????
			}
		}
		else if(a == dice[4]){
			if  (b == dice[0]){
				cout << dice[2] <<endl;
			}else if(b == dice[2]){
				cout << dice[5] <<endl;
			}else if(b == dice[3]){
				cout << dice[0] <<endl;
			}else if(b == dice[5]){
				cout << dice[3] <<endl;
			}else{
			//??????????????\??????
			}
		}
		else if(a == dice[5]){
				if  (b == dice[1]){
				cout << dice[3] <<endl;
			}else if(b == dice[2]){
				cout << dice[1] <<endl;
			}else if(b == dice[3]){
				cout << dice[4] <<endl;
			}else if(b == dice[4]){
				cout << dice[2] <<endl;
			}else{
			//??????????????\??????
			}
		}else {
		//??????????????\??????
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,N) for(int i = 0;i < (int)(N);i++)
int main(){
  double n,d;
  cin>>n>>d;
  cout<<ceil(n/(2*d+1))<<endl;
}


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

def solve(s, c1, c2):
    res = [0] * (n)
    odd = 0
    even = 0
    for i in range(n):
        if s[i] == c1:
            if i % 2 == 1:
                odd += 1
            else:
                even += 1
        if s[i] == c2:
            if i % 2 == 1:
                res[i] += odd
                res[i-1] += even
            else:
                res[i] += even
                res[i-1] += odd
            odd, even = 0, 0
    return res

A = solve(s, 'R', 'L')
B = solve(s[::-1], 'L', 'R')[::-1]
ans = [a+b for a, b in zip(A,B)]
print(' '.join(map(str, ans)))

Measured memory_bytes: 12132
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
using namespace std;
int a[11];
int main()
{
	for(int i=1;i<=10;i++)cin>>a[i];
	sort(a+1,a+11);
	cout<<a[10]<<endl;
	cout<<a[9]<<endl;
	cout<<a[8]<<endl;
	return 0;
}

Measured memory_bytes: 3092
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
	int n; cin >> n;
	vector<int>a(n); for (auto&& x : a)cin >> x;
	
	sort(a.begin(), a.end());
	int ai = a[n - 1];
	int aj = a[0]; 
	double dis = 1e9;
	for (int i = 0; i < n - 1; i++) {
		if (dis > abs(a[i] * 2 - a[n - 1])) {
			aj = a[i];
			dis = abs(a[i] * 2 - a[n - 1]);
		}
	}
	
	cout << ai << ' ' << aj << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>

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

int main(){
  int x;
  cin >> x;
  if(x == 7 || x == 5 || x == 3)cout << "YES" << endl;
  else cout << "NO" << endl;
}


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

#define PI 3.141592
#define SAFE_DELETE( x ) { if ( x ){ delete x; x = NULL; } }

struct tCell{
	int x, y;
	tCell* prev;
	tCell* next;
};

class myArray{
public:
	myArray() : mSize( 0 ), head( NULL ), tail( NULL ){
		tail = new tCell;
		head = new tCell;
		head->prev = tail->next = NULL;
		head->next = tail;
		tail->prev = head;
		head->x = head->y = tail->x = tail->y = 0;
	}
	~myArray(){
		for ( int i = mSize; i > 0; --i ){
			--mSize;
			tCell* cell = tail->prev;
			cell->prev->next = cell->next;
			cell->next->prev = cell->prev;
			SAFE_DELETE( cell );
		}
		SAFE_DELETE( head );
		SAFE_DELETE( tail );
	}
	void pushBack( int x, int y ){
		++mSize;
		tCell* cell = new tCell;
		cell->x = x;
		cell->y = y;
		cell->prev = tail->prev;
		cell->next = tail;
		cell->prev->next = cell;
		cell->next->prev = cell;
	}
	tCell operator[]( int p ){
		if ( p >= mSize ){
			tCell* cell = NULL;
			return *cell;
		}
		tCell* cell = head;
		for( int i = 0; i <= p; ++i ){
			cell = cell->next;
		}
		return *cell;
	}
	int getSize(){ return mSize; }
private:
	int mSize;
	tCell* head;
	tCell* tail;
};

int main(){
	int move = 0, angle = 0;
	double x = 0.0, y = 0.0, theta = 90.0;
	char c;
	myArray mA;

	while ( cin >> move >> c >> angle ){
		if ( !move && !angle ) break;
		mA.pushBack( move, angle );
	}

	for ( int i = 0; i < mA.getSize(); i++ ){
		if ( i ){
			theta -= static_cast< double >( mA[ i - 1 ].y );
		}
		double rad = theta * PI / 180.0;
		x += mA[ i ].x * cos( rad );
		y += mA[ i ].x * sin( rad );
	}

	cout << static_cast< int >( x ) << endl;
	cout << static_cast< int >( y ) << endl;

	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<ll,pll> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=998244353;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

class Segment_Tree{
	private:
	int n;
	vi date;
	public:
	Segment_Tree(int n_){
		n=1;
		while(n<n_) n*=2;
		date=vi(2*n-1);
	}
	void Update(int k,int x){
		k+=n-1;
		date[k]+=x;
		while(k>0){
			k=(k-1)/2;
			date[k]=date[k*2+1]+date[k*2+2];
		}
	}
	int Query(int a,int b){
		a+=n-1;b+=n-1;
		int m=0;
		while(a<b){
			if(a%2==0) m+=date[a++];
			if(b%2==0) m+=date[--b];
			a/=2;b/=2;
		}
		return m;
	}
	int Open(int k){return date[k+n-1];}
};

int n;
vp a;
vi b;
vl two;

int main(){
	cin>>n;
	a=vp(n);
	b=vi(n);
	two=vl(n+1,1);
	for(int i=1;i<=n;i++) two[i]=two[i-1]*2%mod;
	for(int i=0;i<=n;i++) two[i]--;
	for(int i=0;i<n;i++) cin>>a[i].first>>a[i].second;
	sort(a.begin(),a.end());
	for(int i=0;i<n;i++) b[i]=a[i].second;
	vi c=b;
	sort(c.begin(),c.end());
	map<int,int> mp;
	for(int i=0;i<n;i++) mp[c[i]]=i;
	for(int i=0;i<n;i++) b[i]=mp[b[i]];
	ll res=two[n]*n%mod;
	Segment_Tree st(n);
	for(int i=0;i<n;i++){
		res=(res-two[i]+mod)%mod;
		res=(res-two[n-i-1]+mod)%mod;
		res=(res-two[b[i]]+mod)%mod;
		res=(res-two[n-b[i]-1]+mod)%mod;
		int t=st.Query(0,b[i]);
		res=(res+two[t])%mod;
		res=(res+two[b[i]-t])%mod;
		res=(res+two[i-t])%mod;
		res=(res+two[n-b[i]-i+t-1])%mod;
		st.Update(b[i],1);
	}
	cout<<res<<endl;
}

Measured memory_bytes: 16384
main :: IO ()
main = do ls <- getContents
          putStrLn (compose ls)

compose :: String -> String
compose = unwords . fmap show . mathOp . (\xs -> take (head xs) (tail xs)) . (=<<) (fmap (\x -> read x::Int) . words) . lines

mathOp  :: [Int] -> [Int]
mathOp  xs = fmap ($ xs) [mini, maxi, sumi]

mini :: [Int] -> Int
mini [] = error "Empty list was given"
mini [x] = x
mini (x:y:xs) | x <= y = mini (x:xs)
              | otherwise = mini (y:xs)

maxi :: [Int] -> Int
maxi [] = error "Empty list was given"
maxi [x] = x
maxi (x:y:xs) | x < y = maxi (y:xs)
              | otherwise = maxi (x:xs)

sumi :: [Int] -> Int
sumi = foldr (+) 0

Measured memory_bytes: 5512
n = int(input())
h  = list(map(int, input().split()))
h = h[::-1]
for i in range(1, n):
    if h[i-1] < h[i]-1:
        print("No")
        exit()
    elif h[i] <= h[i-1]:
        pass
    else:
        h[i] -= 1
print("Yes")

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
//#define cerr if(false) cerr
#define show(...) cerr << #__VA_ARGS__ << " = ", debug(__VA_ARGS__);
using namespace std;
using ll = long long;
using pii = pair<int,int>;
template<typename T, typename S>
ostream &operator<<(ostream &os, pair<T, S> a){
    os << '(' << a.first << ',' << a.second << ')';
    return os;
}
template<typename T>
ostream &operator<<(ostream &os, vector<T> v){
    for(auto x:v)os << x << ' ';
    return os;
}
void debug(){cerr << '\n';}
template<typename H, typename... T>
void debug(H a, T... b){
    cerr << a;
    if(sizeof...(b))cerr << ", ";
    debug(b...);
}
ll f(ll b, ll n){
    ll ans = 0;
    while(n){
        ans += n % b;
        n /= b;
    }
    return ans;
}
int main(){
    ll n , s;
    cin >> n >> s;
    bool flag = false;
    if(s == n){
        cout << n + 1 << endl;
        return 0;
    }
    for(ll i = 2; i * i <= n; i++){
        if(f(i, n) == s){
            cout << i << endl;
            return 0;
        }
    }
    ll ans = 1LL<<60;
    for(ll i = 1; i * i <= n; i++){
        ll j = s - i;
        ll b = (n - j) / i;
        if(b < 2)continue;
        if(f(b,n) == s){
            flag = true;
            ans = min(ans, b);
        }
    }
    if(!flag){
        cout << - 1<< endl;
    }else{
        cout << ans << endl;
    }
}

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

using namespace std;

#define inf 1<<30
#define llong long long
#define usd unsigned
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef pair<int, int> P;
typedef struct data{
	int now;
	int cost;
}data;
int nw[9] = {0, 1, 0, -1, -1, 1, 1, -1, 0};
int nh[9] = {1, 0, -1, 0, 1, 1, -1, -1, 0};

int rui[501][501] = {};
int N, M, Q;
P rale[200000], que[100000];

void ruiseki(){
	for(int i = 1; i <= N; i++){
		for(int j = 1; j <= N; j++){
			rui[i][j] += rui[i][j-1];
		}
	}

	return;
}

int main(){
	cin >> N >> M >> Q;
	for(int i = 0; i < M; i++){
		cin >> rale[i].first >> rale[i].second;
		rui[rale[i].first][rale[i].second]++;
	}
	ruiseki();
	int p,q;
	for(int i = 0; i < Q; i++){
		cin >> que[i].first >> que[i].second;
	}
	for(int i = 0; i < Q; i++){
		int ans = 0;
		for(int j = que[i].first; j <= que[i].second; j++){
			ans += rui[j][que[i].second] - rui[j][que[i].first - 1];
		}
		cout << ans << endl;
		// cout << rui[1][que[i].second]-rui[1][que[i].first-1] - rui[0][que[i].first-1] << endl;
	}

	return 0;
}

Measured memory_bytes: 4224
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
#include<map>
#include<set>
using namespace std;

int euqrid(int i, int j) {
    if (i > j) swap(i, j);
    while (i > 0) {
        j %= i;
        swap(i, j);
    }
    return j;
}
int main() {
    int n, x, y;
    cin >> n >> x;
    vector<int> v, u;
    v.push_back(x);
    for (int i = 0; i < n; i++) {
        cin >> y;
        v.push_back(y);
    }
    sort(v.begin(), v.end());
    for (int i = 0; i < n;i++) {
        u.push_back(v[i + 1] - v[i]);
    }
    int k = u[0];
    for (int i = 1; i < n; i++) {
        k = euqrid(k, u[i]);
    }
    cout << k << endl;
}
    

Measured memory_bytes: 1400
#include<iostream>
#include<string>
using namespace std;
int main()
{
	string a;
	int l,num;
	while((cin>>a)!=0){
		num=0;
		l=a.size();
		for(int i=0;i<l;i++){
			if(a[i]=='M'){
				num=num+1000;
				if(i!=0){
					if(a[i-1]=='C')num=num-200;
				}
			}
			if(a[i]=='D'){
				num=num+500;
				if(i!=0){
					if(a[i-1]=='C')num=num-200;
				}
			}
			if(a[i]=='C'){
				num=num+100;
				if(i!=0){
					if(a[i-1]=='X')num=num-20;
				}
			}
			if(a[i]=='L'){
				num=num+50;
				if(i!=0){
					if(a[i-1]=='X')num=num-20;
				}
			}
			if(a[i]=='X'){
				num=num+10;
				if(i!=0){
					if(a[i-1]=='I')num=num-2;
				}
			}
			if(a[i]=='V'){
				num=num+5;
				if(i!=0){
					if(a[i-1]=='I')num=num-2;
				}
			}
			if(a[i]=='I'){
				num=num+1;
			}
		}
		cout<<num<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include<string>
#include<math.h>
#include<stdio.h>
#include <algorithm>
using namespace std;
int main(void){
    // Here your code !
int a[9],b[9];
int c;

for(int i=0;i<9;i++){
 a[i]=i+1;   
 b[i]=i+1;
}
for(int i=0;i<9;i++){
  for(int j=0;j<9;j++){
  cout<<a[i]<<'x'<<b[j]<<'='<<a[i]*b[j]<<endl;    
}
}
return 0;
}

Measured memory_bytes: 1116
def main():
    n, t, *a = map(int, open(0).read().split())
    b = 0
    c = float("Inf")
    ans = 1
    for i in range(n):
        x = a[i]
        ans = 1 if x - c > b else ans + int(x - c == b)
        b = max(b, x - c)
        c = min(c, x)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 19984
from collections import deque

N, M, Q = map(int, input().split())

point = [list(map(int, input().split())) for _ in range(Q)]


def A_generator():
    q = deque()
    q.append([1])
    while len(q) > 0:
        a = q.pop()
        if len(a) < N + 1:
            for i in range(a[-1], M + 1):
                q.append(a + [i])
        else:
            yield a


ans = 0

for A in A_generator():
    point_sum = 0
    for p in point:
       if A[p[1]] - A[p[0]] == p[2]:
            point_sum += p[3]

    ans = max(ans, point_sum)

print(ans)

Measured memory_bytes: 69552
# coding: utf-8
# Your code here!
import sys
sys.setrecursionlimit(10**6)
readline = sys.stdin.readline #文字列入力のときは注意


#k = int(input())
a,b,c = [int(i) for i in readline().split()]


if a-b >= c:
    print(0)
else:
    print(c-(a-b))








Measured memory_bytes: 2940
#include<cstdio>
#include<algorithm>
using namespace std;


void trace(int A[], int N){
  int i;
  for (i=0; i<N; i++){
    if (i>0)printf(" ");
    printf("%d", A[i]);
  }
  printf("\n");
}

int selectionSort(int A[], int N){
  int i, j, sw = 0, minj;
  for (i=0; i<N-1; i++){
    minj = i;
    for (j=i; j<N; j++){
      if (A[j] < A[minj]) minj = j;
    }
    swap(A[i], A[minj]);
    if (i != minj) sw++;
  }
  return sw;
}

int main() {
  int N, i, ans;
  int A[100];

  scanf("%d", &N);
  for (i=0; i<N; i++) scanf("%d", &A[i]);

  // trace(A, N);
  ans = selectionSort(A, N);
  trace(A, N);

  printf("%d\n", ans);

  return 0;
}

Measured memory_bytes: 2684
import sys
input = sys.stdin.readline
def primes(n):
    is_prime = [True] * (n + 1)
    is_prime[0] = False
    is_prime[1] = False
    for i in range(2, int(n**0.5) + 1):
        if not is_prime[i]:
            continue
        for j in range(i * 2, n + 1, i):
            is_prime[j] = False
    return set([i for i in range(n + 1) if is_prime[i]])
sosuu = primes(55555)
N=int(input())
ans=[]
ct=0
for i in sosuu:
 if i%5==1:
  ans.append(i)
  ct+=1
 if ct==N:
  break
print(*ans)   


Measured memory_bytes: 40452
#include<bits/stdc++.h>
using namespace std;
#define ll                          long long
#define in(a)                       ll a; cin>>a;
#define in2(a,b)                    ll a,b; cin>>a>>b;
#define in3(a,b,c)                  ll a,b,c; cin>>a>>b>>c;
#define in4(a,b,c,d)                ll a,b,c,d; cin>>a>>b>>c>>d;
#define in5(a,b,c,d,e)              ll a,b,c,d,e; cin>>a>>b>>c>>d>>e;
#define lelo(b)                     for(auto &i:b)cin>>i;
#define ff                          first
#define ss                          second
#define call(v)                     v.begin(),v.end()
#define rall(v)                     v.rbegin(),v.rend()
#define show(x)                     for(auto t:x)cout<<t<<" ";
#define pb                          push_back
#define bhar(s,v)                   memset(s,v,sizeof(s))
#define endl                        "\n"                       
#define ce(x)                       cout<<x<<"\n";
#define nl                          cout<<endl;
#define jaldi                       ios_base::sync_with_stdio(false);cin.tie(NULL);
#define dekh_lo                     ce("dekh_lo");
#define sz(x)                       (ll)x.size()
#define re                          return

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

typedef pair<ll,ll> pii;
typedef vector<pii> vii;
typedef vector<ll> vi;

const ll mod=1e9+7;
const ll N=4e5+5;

/*


*/

void solve(){
    in3(n,x,t);

    if(n%x==0){
    	ll ans=(n/x)*t;
    	ce(ans);
    	re;
    }

    ll ans=(n/x+1)*t;
    ce(ans);

}

int32_t main(){
    // jaldi
    ll t; 
    // cin>>t;
    t=1;     
    while(t--){
        solve();
    }
}

/*


*/

  

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define v vector
#define r resize
using namespace std;
typedef long long l;
v<bool> s;
v<l> b; 
v<v<int>> g;
v<l> a;
void dfs(l, l);
int main(){
    l n,q;
    cin>>n>>q;
    g.r(n);
    b.r(n);
    s.r(n);
    a.r(n);
    for(int i=0;i<n-1;i++){
        int x,y;
        scanf("%d %d",&x,&y);
        g[x-1].push_back(y-1);
        g[y-1].push_back(x-1);
    }
    for(int i=0;i<q;i++){
        l x,y;
        scanf("%lld %lld",&x,&y);
        b[x-1]+=y;
    }
    dfs(0,0);
    for(int i=0;i<n;i++){
        printf("%lld ",a[i]);
    }
}
void dfs(l e,l c){
    if(s[c])return;
    s[c]=true;
    a[c]=e+b[c];
    for(int h:g[c]){
        dfs(a[c],h);
    }
    return;
}


Measured memory_bytes: 22784
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repp(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
using namespace std;
typedef pair<int, int> P;

signed main(){
    int w, h, n;
    cin >> w >> h >> n;
    vector<int> x(n), y(n);
    rep(i, 0, n){
        cin >> x[i] >> y[i];
    }
    int ans = 0;
    rep(i, 1, n){
        int dx = x[i] - x[i - 1];
        int dy = y[i] - y[i - 1];
        int tmp = 0;
        if(dx * dy > 0){
            tmp = abs(dx) + abs(dy) - min(abs(dx), abs(dy));
        }else{
            tmp = abs(dx) + abs(dy);
        }
        ans += tmp;
    }
    cout << ans << endl;
}

Measured memory_bytes: 1204
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S;
  cin >> S;
  int N = S.size();
  int count = 0;
  
  for (int i = 1; i < N; i++) {
    if (S.at(i-1) == '0' && S.at(i) == '0') {
      S.at(i) = '1';
      count++;
    } else if (S.at(i-1) == '1' && S.at(i) == '1') {
      S.at(i) = '0';
      count++;
    }
  }
  
  cout << min(count,N-count) << endl;
}

Measured memory_bytes: 512
if __name__ == "__main__":
    N, M = map(int, input().split())
    deg = [0 for i in range(N)]
    for i in range(M):
        a,b = map(int, input().split())
        a -= 1
        b -= 1
        deg[a] += 1
        deg[b] += 1
    for i in range(N):
        print (deg[i])


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

int main(){
  int a,b,c,d=0;
  cin >> a>> b>> c;

  while ( b >0){
    if( c == d || b-a <0) break;
    b -= a;
    d++;
  }

  cout << d << endl;
  

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#include<string.h>
#define v vector<int>
#define vpp vector<pair<int,int>>
#define ll long long int
#define ull unsigned long long
#define ld long double
#define f(a,b) for(ll i =a;i<b;i++)
#define vi vector<int>
#define vl vector<ll>
#define pri pair<int,int>
#define mpi map<int,int>
#define prl pair<ll,ll>
#define mp make_pair
#define mpl map<ll,ll>
#define pb push_back
#define MOD 1000000007
#define ub upper_bound
#define lb lower_bound
ll fast_pow(ll k, ll p)
{
if (p == 0)
        return 1;
 
    ll P = fast_pow(k, p/2);
    P = (P * P) % MOD;
 
    if (p % 2 == 1)
        P = (P * k) % MOD;
 
    return P;
}
ll invmod(ll a,ll m)
{
    return fast_pow(a,m-2);
}

bool isPrime(ll n) 
{ 
   
    if (n <= 1) 
        return false; 
    if (n <= 3) 
        return true; 
  
       if (n % 2 == 0 || n % 3 == 0) 
        return false; 
  
    for (int i = 5; i * i <= n; i = i + 6) 
        if (n % i == 0 || n % (i + 2) == 0) 
            return false; 
  
    return true; 
} 
ll nextPowerOf2(ll n)
{
    n>>=1;
    ll count = 0;

    if (n && !(n & (n - 1)))
        return n;

    while( n != 0)
    {
        n >>= 1;
        count += 1;
    }

    return 1 << count;
}

ll binomialCoeff(ll n, ll k) 
{ 
    ll C[k+1]; 
    memset(C, 0, sizeof(C)); 
    C[0] = 1;
  
    for (ll i = 1; i <= n; i++) 
    {
        for (ll j = min(i, k); j > 0; j--) 
            C[j] = C[j] + C[j-1]; 
    } 
    return C[k]; 
} 


//////////////////////*********CODE***********/////////////////////
int main(){
    ll n;
    cin>>n;
    ll c=0,i;
    queue<ll>q;
    q.push(1);
    q.push(2);
    q.push(3);
    q.push(4);
    q.push(5);
    q.push(6);
    q.push(7);
    q.push(8);
    q.push(9);
    ll x;
    while(c!=n){
       x=q.front();
       q.pop();
       if(x%10!=0) q.push(10*x+x%10-1);
       q.push(10*x+x%10);
        if(x%10!=9) q.push(10*x+x%10+1);
        c++;
    }
    cout<<x<<endl;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<vector>
#include <algorithm>
#include <functional>
#include <numeric>
using namespace std;


int main() {
	int R,G,B,N;
	cin >> R >> G>>B>>N;
	int cnt = 0;
	int n = N;
	int b = 0;
	for (int i = 0; i <= N / R; i++) {
		for (int j = 0; j <= N / G; j++) {
			if ((N - i * R - j * G) >= 0) {
				if ((N - i * R - j * G) % B == 0)
					cnt++;
			}
		}
	}
	cout << cnt;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
static const ll MOD = 1e9 + 7;

bool pairCompare(const pair<int, int>& firstElof, const pair<int, int>& secondElof) {
    return firstElof.first > secondElof.first;
}

int main(void) {
    ll N, K;
    cin >> N >> K;

    if(N<=K) { 
        cout << 0 << endl;
        return 0;
    }

    vector<ll> H(N);
    for(int i=0;i<N;i++) {
        cin >> H.at(i);
    }

    sort(H.begin(), H.end(), greater<ll>());

    for(ll i=0;i<K;i++) {
        H.at(i) = 0;
    }


    ll sum = 0;
    for(ll i=0;i<N;i++) {
        sum += H.at(i);
    }

    cout << sum << endl;

    return (0);
}


Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include <cassert>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;

typedef long double real;

const int MAX_M = 2000;
const int MAX_N = 2000;

const real EPS = 1e-8;

bool EQ(real a, real b) {
    return abs(a - b) < EPS;
}

real P1[MAX_M + 1][MAX_M + 1]; // P1[m][x] :: アイドル2,3,...,Nがビジュアルアピールをm回中x回だけ行う確率
real SP[MAX_M + 1][MAX_M + 1]; // SP[m][x] :: アイドル2,3,...,Nがビジュアルアピールをm回中x回以上行う確率

int N, M;
vector<int> vi, da, vo;

void initP1() {
    for (int m = 0; m <= MAX_M; m++) for (int x = 0; x <= MAX_M; x++) 
        P1[m][x] = 0;
    P1[0][0] = 1;
    for (int m = 1; m <= MAX_M; m++) {
        for (int x = 0; x <= m; x++) {
            P1[m][x] += P1[m - 1][x] * (2.0 / 3.0);
            if (x >= 1) {
                P1[m][x] += P1[m - 1][x - 1] * (1.0 / 3.0);
            }
        }
    }
}

void initSP() {
    for (int m = 0; m <= MAX_M; m++) for (int x = 0; x <= MAX_M; x++) 
        SP[m][x] = 0;
    for (int m = 0; m <= MAX_M; m++) {
        SP[m][0] = 1;
        for (int x = 1; x <= m; x++) {
            SP[m][x] = SP[m][x - 1] - P1[m][x - 1];
        }
        assert(EQ(SP[m][m], P1[m][m]));
    }
}

void dump() {
    printf("SP:\n");
    for (int i = 0; i <= M; i++) {
        for (int j = 0; j <= i; j++) {
            printf("%3.3Lf ", SP[i][j]);
        }
        printf("\n");
    }
}

const real INF = 1e8;

real memo[MAX_M + 1][6];
real top(int x, int p, const vector<int>& V) {
    static real dp[MAX_N + 1][5];
    if (memo[x][p] > -INF) return memo[x][p];
    int k = V[1];
    int P = x * k;
    for (int i = 0; i <= N; i++) for (int j = 0; j <= 4; j++) dp[i][j] = 0;
    dp[1][1] = 1.0;
    dp[1][4] = 1.0;
    for (int i = 2; i <= N; i++) {
        real X;
        if ( (P + V[i] - 1) / V[i] > M ) {
            X = 0;
        } else {
            X = SP[M][(P + V[i] - 1) / V[i]];
        }
        assert(X >= 0);
        assert(X <= 1);
        dp[i][1] = dp[i - 1][1] * (1.0 - X);
        dp[i][2] = dp[i - 1][2] * (1.0 - X) + dp[i - 1][1] * X;
        dp[i][3] = dp[i - 1][3] * (1.0 - X) + dp[i - 1][2] * X;

        dp[i][4] = dp[i - 1][4] * X;
    }
    return memo[x][p] = (dp[N][1] + dp[N][2] + dp[N][3]) * p - dp[N][4] * 1;
}

void solve() {
    real ans = -INF;
    for (int i = 0; i <= M; i++) for (int j = 0; j < 6; j++) memo[i][j] = -INF;
    for (int x = 0; x <= M; x++) {
        for (int y = 0; y <= M - x; y++) {
            int z = M - (x + y);
            assert(z >= 0);
            // viをx, daをy, voをz回行う
            ans = max(ans, top(x, 5, vi) + top(y, 3, da) + top(z, 2, vo));
        }
    }
    printf("%.18Lf\n", ans);
}

int main() {
    cin >> N >> M;
    vi.clear(); da.clear(); vo.clear();
    vi.resize(N + 1); da.resize(N + 1); vo.resize(N + 1);
    for (int i = 1; i <= N; i++) cin >> vi[i] >> da[i] >> vo[i];
    initP1(); initSP();
    solve();
    return 0;
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

#define mp make_pair
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define all(v) v.begin(),v.end()

const int maxn = 3e5 + 100;
const ll inf = 2e18, mod = 1e9 + 7;

int n, a[maxn], b[maxn];

int solve(int val)
{
	for (int i = 0; i < 2 * n - 1; i++)
		b[i] = (a[i] >= val);
 
	int pos = n - 1;
	if (b[pos] == b[pos - 1] || b[pos] == b[pos + 1])
		return b[pos];
 
	int LEFT = pos, RIGHT = pos;
	for (int i = pos + 1; i < 2 * n - 1; i++)
	{
		if (b[i] != b[i - 1])
			RIGHT = i;
		else
			break;
	}
	for (int i = pos - 1; i >= 0; i--)
	{
		if (b[i] != b[i + 1])
			LEFT = i;
		else
			break;
 	}

	if (LEFT == 0 && RIGHT == 2 * n - 2)
		return b[0];
	if (LEFT == 0)
		return b[RIGHT];
	if (RIGHT == 2 * n - 2)
		return b[LEFT];
 
	if (b[LEFT] == b[RIGHT])
		return b[LEFT];
	if (abs(pos - LEFT) < abs(pos - RIGHT))
		return b[LEFT];
	return b[RIGHT];
}

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

	cin >> n;
	for (int i = 0; i < 2 * n - 1; i++)
		cin >> a[i];
	
	int l = 0, r = 2 * n, mid;
	while (r - l > 1)
	{
		mid = (l + r) / 2;
		if (solve(mid))
			l = mid;
		else
			r = mid;
	}
	cout << l << endl;
}



Measured memory_bytes: 1920
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int x,i,j,temp;
	cin>>x;
	int maxn=-999;
	for(i=1;i<=x;i++)
		for(j=2;j<10;j++)
		{
			temp=pow(i,j);
			if(temp>x)
				break;
			maxn=max(maxn,temp);
		}
	cout<<maxn;
	return 0; 
} 

Measured memory_bytes: 256
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let a: f64 = sc.read();
    let b: f64 = sc.read();
    let x: f64 = sc.read();
    let s = x/a;
    let o = s - a*b/2.;

    let ans = if o > 0. {
        let h = b - 2.*o/a;
        (h/a).atan()
    } else if o == 0. {
        (b/a).atan()
    } else {
        let w = 2.*s/b;
        (b/w).atan()
    };

    format!("{}\n", ans * 180. / std::f64::consts::PI)
}
#[test]
fn test_solve() {
   //assert_eq!(solve("2 2 4\n"), "45.0000000000\n");
   //assert_eq!(solve("12 21 10\n"), "89.7834636934\n");
   assert_eq!(solve("3 1 8\n"), "4.2363947991\n");
}
fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
#[allow(dead_code)]
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}

Measured memory_bytes: 4352
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>

using namespace std;

void prime(vector<int> &num, int n){
    for(int i=0;i<=n;i++){
        num[i] = 1;
    }
    num[0] = 0;
    num[1] = 0;
    num[2] = 1;

    for(int i=2;i<=sqrt(n);i++){
        if(num[i] == 1){
            for(int j=2;j<=n/i;j++){
                num[i*j] = 0;
            }
        }
    }
}

int main(void){

    int q;
    cin>>q;

    vector<int> num(100001);

    prime(num, 100001);

    vector<int> count(100001);
    int co = 0;
    count[0] = 0;
    count[1] = 0;
    count[2] = 0;

    for(int i=3;i<100001;i++){
        if(num[i] == 1){
            if(num[(i+1)/2]==1){
                co++;
                count[i] = co;
            }else{
                count[i] = count[i-1];
            }
        }else{
             count[i] = count[i-1];
        }
    }

    // for(int i=0;i<20;i++){
    //     cout<<count[i]<<" ";
    // }
    // cout<<endl;

     int a[q][2];

    for(int i=0;i<q;i++){

        int l,r;
        cin>>l>>r;

        a[i][0] = l;
        a[i][1] = r;
    }

    for(int i=0;i<q;i++){
        cout<<count[a[i][1]] - count[a[i][0]-1]<<endl;
    }

    return 0;

}

Measured memory_bytes: 2176
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	static Scanner sc = new Scanner(System.in);
	static int M;
	static int[] memo = new int[1 << 22];

	public static void main(String[] args) {
		while (true) {
			M = sc.nextInt();
			int N = sc.nextInt();
			if (M == 0) break;
			ArrayList<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i < N; ++i) {
				list.add(Integer.parseInt(sc.next(), 2));
			}
			Arrays.fill(memo, -1);
			System.out.println(rec(0, list));
		}
	}

	static int rec(int used, ArrayList<Integer> list) {
		if (list.size() <= 1) return 0;
		if (memo[used] >= 0) return memo[used];
		int ret = 99;
		for (int i = 0; i < M; ++i) {
			if ((used & (3 << (2 * i))) != 0) continue;
			ArrayList<Integer> on = new ArrayList<Integer>();
			ArrayList<Integer> off = new ArrayList<Integer>();
			for (int v : list) {
				if ((v & (1 << i)) != 0) {
					on.add(v);
				} else {
					off.add(v);
				}
			}
			if (on.isEmpty() || off.isEmpty()) continue;
			ret = Math.min(ret, Math.max(rec(used | (1 << (2 * i)), on), rec(used | (2 << (2 * i)), off)));
		}
		memo[used] = ret + 1;
		return ret + 1;
	}

}

Measured memory_bytes: 208072
h, w = map(int, input().split())
s = [list(input()) for _ in range(h)]

for i in range(h):
    count = 0
    start = 0
    end = 0
    for j in range(w):
        if s[i][j] != "#":  # 　#じゃなければおけ
            count += 1
        else:
            for z in range(start, end):
                s[i][z] = count
            start = end+1
            count = 0
        end += 1
    for z in range(start, end):
        s[i][z] = count
    # print(s[i])
ans = 0

for i in range(w):
    count = 0
    start = 0
    end = 0
    for j in range(h):
        if s[j][i] != "#":  # 　#じゃなければおけ
            count += 1
        else:
            for z in range(start, end):
                s[z][i] += count
            start = end+1
            count = 0
        end += 1
    for z in range(start, end):
        s[z][i] += count
# print()
for i in range(h):
    # print(s[i])
    for j in range(w):

        if s[i][j] != "#":
            ans = max(ans, s[i][j])
print(ans-1)


Measured memory_bytes: 373664
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define FOREACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIGN(x) (((x)>0)?1:(((x)<0)?-1:0))
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
#define vv(t) vector< t > 
#define CHC(mp, x) if(mp.end() != mp.find(x))
#define CHCV(mp, x) if(mp.end() != find(ALL(mp), x))
template<typename T>
inline T lcm(T a, T b) {return a / __gcd(a, b) * b;}
#define fi first
#define se second
#define el endl
#pragma endregion


void Main();
void solve(long long N, std::vector<long long> P, std::vector<long long> Q);

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    long long N;
    scanf("%lld",&N);
    std::vector<long long> P(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&P[i]);
    }
    std::vector<long long> Q(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&Q[i]);
    }
    solve(N, std::move(P), std::move(Q));
}

void solve(long long N, std::vector<long long> P, std::vector<long long> Q){
    vv(ll) pp(N);
    REP(i, N) pp[i]=i+1;
    ll a=0, b=0, cnt=0;
    do{
        bool flg1=true, flg2=true;
        REP(i, N){
            if(pp[i]!=P[i]){
                flg1=false;
            }
            if(pp[i]!=Q[i]){
                flg2=false;
            }
        }
        if(flg1){
            a=cnt;
        }
        if(flg2){
            b=cnt;
        }
        if(a&&b){
            break;
        }
        cnt++;
    }while(next_permutation(ALL(pp)));
    cout << abs(a-b) << el;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner out = new Scanner(System.in);

        String str =out.nextLine();
        String[] sss=str.split(" ");
        int a= Integer.parseInt(sss[0]);
        int b= Integer.parseInt(sss[1]);
        if(a>b){
            System.out.println("a > b");
        }else if(a<b){
            System.out.println("a < b");
        }else{
            System.out.println("a == b");

        }




    }
}

Measured memory_bytes: 26136
#include <cstdio>

long long gcd(long long a, long long b)
{
  if (a < b) return gcd(b, a);
  int r;
  while (r = a % b) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
  long long a, b, c, d;
  scanf("%lld %lld %lld %lld", &a, &b, &c, &d);
  
  long long lcm = c * d / gcd(c, d);
  long long cl = b / lcm - (a + lcm - 1) / lcm + 1;
  long long cc = b / c - (a + c - 1) / c + 1;
  long long cd = b / d - (a + d - 1) / d + 1;
  printf("%lld\n", b - a + 1 - (cc + cd - cl));
  return 0;
}

Measured memory_bytes: 128
<?php
$n = trim(fgets(STDIN));

$list = array();

for ($i = 0; $i < $n; $i++) {
	list($a, $v) = explode(' ', trim(fgets(STDIN)));
	$list[$a] = $v;
}

$max = max($list);

$top_tie = array_filter($list, function($e) use ($max) {
	return $e == $max;
});

ksort($top_tie);
reset($top_tie);
echo key($top_tie) . " " . current($top_tie) . "\n";

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

int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    vector<ll> b(n);
    vector<ll> c(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
        if(i==0){
            b.at(i)=a.at(i);
        }
        else{
            b.at(i)=b.at(i-1)+a.at(i);
        }
    }
    for(int i=n-1;i>=0;i--){
        if(i==n-1){
            c.at(n-1)=a.at(n-1);
        }
        else{
            c.at(i)=c.at(i+1)+a.at(i);
        }
    }
    ll ans=100000000000;
    for(int i=0;i<n-1;i++){
        ans=min(ans,abs(c.at(i+1)-b.at(i)));
    }
    cout<<ans<<endl;

}


Measured memory_bytes: 4096
#include <iostream>

using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if((a==b)&&(a!=c))
        cout<<c;
    if((a==c)&&(a!=b))
        cout<<b;
    if((c==b)&&(c!=a))
        cout<<a;
	
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
const ll MOD=1000000007;

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

ll comb(ll n,ll r,ll mod){
    int i;
    ll bunsi=1;
    ll bunbo=1;
    rep(i,r){
        bunsi=bunsi*(n-i)%mod;
        bunbo=bunbo*(r-i)%mod;
    }
    return bunsi*mod_pow(bunbo,mod-2,mod)%mod;
}

int main(){
    ll n,a,b,ans;
    cin>>n>>a>>b;
    ll nca,ncb;
    nca=comb(n,a,MOD);
    ncb=comb(n,b,MOD);
    ans=(mod_pow(2,n,MOD)-nca-ncb-1)%MOD;
    while(ans<0){
        ans+=MOD;
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long A,B,C,D,H,K,L,M,N,T,W,X;
  string S;
  cin >> K;
  
  D=0;
  for (long long A=1;A<K+1;A++) {
   for (long long B=1;B<K+1;B++) {
    for (long long C=1;C<K+1;C++) {
    
	 D+=gcd(gcd(A,B),gcd(B,C));
	
	}
   }	
  }
  cout << D << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<vector<int>> vvi;
typedef vector<vector<string>> vvs;
typedef vector<vector<char>> vvc;
typedef vector<vector<bool>> vvb;
typedef pair<int,int> P;
#define vrep(v,n) for(int i=0;i<n;i++){cin >> v.at(i);} //配列vにn個の要素を入力する
#define rep(i, l, n) for (int i = l; i < (int)(n); i++)
#define repn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 

const int mod = 1000000007;
const int inf = 1e9;

int main(){
    int k, n;
    cin >> k >> n;
    vi a(n);
    vrep(a, n);
    vi b;
    repn(i,1,n){
        if(i == n){b.pb(k-a[n-1]+a[0]);continue;}
        b.pb(a[i]-a[i-1]);
    }
    sort(b.begin(), b.end());
    ll ans = 0;
    rep(i, 0, n-1){
        ans += b[i];
    }
    cout << ans;

}

Measured memory_bytes: 2168
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long int llint;

int main() {
	int n, m;
	cin >> n >> m;
	vector<pair<int, int>>a(m);
	for (int i = 0;i < m;i++) {
		cin >> a[i].first >> a[i].second;
	}
	sort(a.begin(), a.end());
	int ans = 0;
	int cnt = 0;
	for (int i = 0;i < m;i++) {
		if (a[i].first != 1) {
			break;
		}
		for (;cnt < m;cnt++) {
			if (a[i].second > a[cnt].first) {
				continue;
			}
			if (a[cnt].first == a[i].second) {
				if (a[cnt].second == n) {
					ans = 1;
					break;
				}
			}
			if (a[cnt].first > a[i].second) {
				break;
			}
		}
		if (ans == 1) {
			break;
		}
	}
	if (ans == 0) {
		cout << "IMPOSSIBLE" << endl;
	}
	else {
		cout << "POSSIBLE" << endl;
	}
	return 0;
}


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

int main() {
	int N;
	cin >> N;
	vector<int> A(N);
	int max_a = 1000000;
	vector<bool> hit(max_a+1,false), dou(max_a+1,false);
	rep(i,N) {
		cin >> A[i];
		if (hit[A[i]]) dou[A[i]] = true;
		hit[A[i]] = true;
	}

	int ans = 0;
	rep(i,N) {
		// 複数同じ数字があるかを判定、あったらスルー
		if (dou[A[i]]) continue;

		// A[i]の約数リストを求める
		vector<int> yaku;
		for (int j=1;j*j<=A[i];++j) {
			if (A[i]%j==0) {
				yaku.push_back(j);
				if (j*j!=A[i]) yaku.push_back(A[i]/j);
			}
		}

		// A[i]を除く各約数に対して、他の数字と被っているかを判定
		bool is_notdiv = true;
		for (int x : yaku) {
			if (x!=A[i] && hit[x]) {
				is_notdiv = false;
				break;
			}
		}
		if (is_notdiv) ans++;
	}

	cout << ans << endl;

	return 0;
}


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

int main(int argc, char const *argv[])
{
    int W,H,x,y,r,a,b,c,d;
    cin >> W >> H >> x >> y >> r;
    a = r;
    b = W - r;
    c = r;
    d = H - r;

    if (a<=x && x<=b && c<=y && y<=d)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

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

public class Main {
    /*
    a=b*0+K,b*0+K+1,...,b*0+b-1	(b-K) caution:b*0+K might be 0
      b*1+K,b*1+K+1,...,b*1+b-1
      b*2+K,b*2+K+1,...,b*2+b-1
      ...
      ...
      ..................b*(line-1)+b-1
      few elements left
    */
    public static long ans(long N, long K){
    	long ans=0;
    	for(long b=K+1;b<=N;b++){
    		long line = N/b;
    		ans += (b-K)*line;
    		if(K==0) ans--;
    		for(long a=b*line+K;a<=N;a++) ans++;
    	}
    	return ans;
    }
    
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long N = sc.nextLong();
        long K = sc.nextLong();
        System.out.println(ans(N,K));
        
    }
}

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

int main() {
	int q; cin >> q; int temp_1, temp_2; vector<int> vec;
	for (int i = 0; i < q; i++) {
		cin >> temp_1;
		switch (temp_1) {
		case 0: cin >> temp_2; vec.push_back(temp_2); break;
		case 1: cin >> temp_2; cout << vec[temp_2] << endl; break;
		case 2: vec.pop_back(); break;
		}
	}
	return 0;
}


Measured memory_bytes: 3828
/*
 * main.c
 *
 *  Created on: 2016/12/23
 *      Author: stoneriver
 */

#include <stdio.h>

int main() {
	int a, b;
	scanf("%d %d", &a, &b);
	printf("%d %d\n", a * b, 2 * (a + b));
	return 0;
}

Measured memory_bytes: 2612
p=print
r=range
def a(i,j,k,l=0):p("+<"[l],i,j,k)
def b(i):a(i,i,i+1)
def d(x,i,j):
	for t in r(30):b(p:=j+t-1);a(q:=j+t,n,q);[*map(b,r(q,j+29))];a(j+29,x,i+t,1);b(p);a(q,i+t,q)
p(n:=3933)
a(0,1,n)
a(2,n,n,1)
a(0,n,3)
a(1,n,4)
d(3,5,36)
d(4,36,67)
for t in r(59):a(2,2,2);[t-30<s<30!=(a(5+t-s,36+s,98),a(n,98,99,1),a(2,99,2))for s in r(t+1)]

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

int main(){
    string a;
    while(1){
        int s=0;
        cin>>a;
        if(a[0]=='0')break;
        for(int i=0;i<a.size();i++){
            s+=a[i]-'0';
        }
        cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 3152
#include<bits/stdc++.h>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;
 
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 gcd(ll n, ll m) {
    ll tmp;
    while (m!=0) {
        tmp = n % m;
        n = m;
        m = tmp;
    }
    return n;
}
 
ll lcm(ll n, ll m) {
    return abs(n) / gcd(n, m)*abs(m);//gl=xy
}

using namespace std;
 
void solve(){
	string s;
	cin >> s;
	int x = s.back() - '0';
	if((x==0)||(x==1)||(x==6)||(x==8)){
		cout << "pon";
	}
	else if(x==3){
		cout << "bon";
	}
	else
		cout << "hon";
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);
    solve();
    return 0;
}

Measured memory_bytes: 3652
import java.util.ArrayList;
import java.util.Scanner;
import java.util.TreeMap;
import java.util.stream.IntStream;

public class Main{
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream REPS(int l,int r){return IntStream.rangeClosed(l,r);}
	static IntStream INS(int n) {return REPS(n).map(i->getInt());}
	static Scanner s=new Scanner(System.in);
	static int getInt(){return Integer.parseInt(s.next());}

	public static void main(String[]$){
		{
			int n=getInt();
			dist=new long[n];
			for(int i=0;i<n;++i)edges.add(new TreeMap<>());
			for(int i=0;i<n-1;++i){
				int a=getInt()-1,b=getInt()-1;
				long c=getInt();
				edges.get(a).put(b,c);
				edges.get(b).put(a,c);
			}
		}
		{
			int q=getInt();
			dfs(-1,getInt()-1,0);
			for(int i=0;i<q;++i)
				System.out.println(dist[getInt()-1]+dist[getInt()-1]);
		}
	}

	static ArrayList<TreeMap<Integer,Long>>edges=new ArrayList<>();
	static long[]dist;
	private static void dfs(int from,int to,long l){
		dist[to]=l;
		TreeMap<Integer,Long> m=edges.get(to);
		m.remove(from);
		m.forEach((k,v)->dfs(to,k,l+v));
	}
}

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

#define rep(i,n) for(int i = 0;i < n; i++)

using namespace std;

int main() {
    int n,m;
    cin >> n >> m;
    struct data{
        long a;
        long b;
    };
    vector<data> data;
    struct data input;
    long long a, b;
    rep(i, n){
        cin >> a >> b;
        input = {a, b};
        data.push_back(input);
    }
    sort(data.begin(), data.end(), [](const struct data& x, const struct data& y){return x.a < y.a;});
    long long i,bought = 0;
    long long money = 0;
    while(1){
        if((m - bought) > data[i].b){ //在庫少ない、全部買う
            money += data[i].a * data[i].b;
            bought += data[i].b;
        }else{ //一部買う
            money += data[i].a * (m - bought);
            bought += (m - bought);
            break;
        }
        i++;
    }
    cout << money << endl;
}


Measured memory_bytes: 2420