akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

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; }
void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }

#include <iomanip>


vector<vector<double>> dp;
int n;

int main()
{
	cin >> n;
	dp.resize(n + 1, vector<double>(n + 1, 0));
	dp[0][0] = 1;

	REP(i, n)
	{
		double p; cin >> p;

		REPC(j, n)
		{
			if (j)
				dp[i + 1][j] += dp[i][j - 1] * p;
			dp[i + 1][j] += dp[i][j] * ((double)1 - p);
		}
	}

	double ans = 0;
	for (int i = n / 2 + 1; i <= n; ++i)
		ans += dp[n][i];
	cout << setprecision(12) << ans << endl;
}

Measured memory_bytes: 70656
{-# LANGUAGE BangPatterns #-}
import Control.Monad
import Data.Maybe
import Debug.Trace
import Data.List
import qualified Data.Map.Strict as Map
import qualified Data.IntMap.Strict as IntMap
import qualified Data.Set as Set
import qualified Data.IntSet as IntSet
import Data.Functor
import Data.Array

main :: IO ()
main = do
  (a:b:k:_) <- fmap (map read . words) getLine :: IO [Int]
  print $ solve a b k

solve a b k = (reverse [ i | i <- [1..100], a `mod` i == 0, b `mod` i == 0]) !! (k-1)

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

void solve(){
    int n,k;
    string s;
    cin >> n >> k;
    cin >> s;
    char c = s[k-1] + 32;
    s[k-1] = c;
    cout << s << endl; 
}

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

Measured memory_bytes: 256
#[allow(dead_code)]
fn scan<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

#[allow(dead_code)]
fn scan_split<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split_whitespace()
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_split_with<T: std::str::FromStr>(ch: char) -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().split(ch)
        .map(|t| t.parse().ok().unwrap()).collect()
}

#[allow(dead_code)]
fn scan_lines<T: std::str::FromStr>(n: usize) -> Vec<T> {
    (0..n).map(|_| scan::<T>()).collect()
}

#[allow(unused_macros)]
macro_rules! scan_as_tuple {
    ( $t:ty ) => {
        (scan::<$t>(),)
    };
    ( $( $t:ty ),* ) => {
        {
            let mut s = String::new();
            std::io::stdin().read_line(&mut s).ok();
            let v = s.trim().split_whitespace();
            let mut it = v;
            let ret = ( $(it.next().unwrap().parse::<$t>().ok().unwrap()),* );
            assert!(it.next() == None, "not all tokens consumed");
            ret
        }
    };
}

fn main() {
    let (a, b, c) = scan_as_tuple![i32, i32, i32];
    let mut s = std::collections::BTreeSet::new();
    s.insert(a);
    s.insert(b);
    s.insert(c);
    println!("{}", s.len());
}

Measured memory_bytes: 4352
enemmyCountN,killerTimeK = map(int,input().split())
enemyHp = input().split()

intEnemyHp = [int(i) for i in enemyHp]
intEnemyHp.sort()

resultEnemyCount = enemmyCountN - killerTimeK
countNormal = 0

# if killerTimeK >= enemmyCountN:
    # print(0)

# else:
for i in range(resultEnemyCount):
    countNormal += intEnemyHp[i]
print(countNormal)

Measured memory_bytes: 26764
#include<bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using vint = vector<int>;

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

	int n, x, kmin = 0, kmax;
	int rate[9] = {};
	cin >> n;
	REP(i, n){
		cin >> x;
		if (x >= 3200){
			rate[8]++;
		}else{
			rate[x/400]++;
		}
	}
	REP(i, 8){
		if (rate[i] != 0){
			kmin++;
		}
	}
	kmax =kmin+rate[8];
	if (kmin == 0){
		kmin = 1;
	}
	cout << kmin << " " << kmax << "\n";
	return 0;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    string s;
    cin >> s;
    if (s[0] != 'A' or ('A' <= s[1] and s[1] <= 'Z') or ('A' <= s[s.size()-1] and s[s.size()-1] <= 'Z')) {
        cout << "WA" << endl;
        return 0;
    }
    bool flag = false;
    for (int i=2; i<s.size()-1; ++i) {
        if ('A' <= s[i] and s[i] <= 'Z') {
            if (!flag and s[i] == 'C') flag = true;
            else {
                cout << "WA" << endl;
                return 0;
            }
        }
    }
    cout << (flag ? "AC" : "WA") << endl;
}


Measured memory_bytes: 256
//ABD.java
import java.util.Scanner;
class Main
{
	public static void main(String args[])
	{
		Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        
        if(n<1000){
            System.out.println("ABC");
        }
        else{
            System.out.println("ABD");
        }
        sc.close();
    }
}

Measured memory_bytes: 21844
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <climits>
#include <bitset>
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<pair<int,int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
#define rep(i,n) for(int i=0;i<n;i++)
#define fin(ans) cout<<(ans)<<endl
#define P 1000000007
#define STI(s) atoi(s.c_str())//string to int
#define mp(p,q) make_pair(p,q)
#define Sort(a) sort(a.begin(),a.end())
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;}
const int INF = INT_MAX;
const long long LLINF = 1LL<<60;
//g++ -std=c++1z temp.cpp
//./a.exe
    
int main(void){ios::sync_with_stdio(false);cin.tie(0);
//////////////////////////////////////////////////////
    
  int a,b,c;
  cin >> a >> b >> c;
  if (a>=b&&a>=c)
  {
    cout << b+c << endl;
  }else if (b>=a&&b>=c)
  {
    cout << a+c << endl;
  }else
  {
    cout << a+b << endl;
  }
  
  
  
  
  
  
  
  
  
  
    
  
  
    


//////////////////////////////////////////////////////
return 0;}

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

int main() {
	while(true) {
		int n, p, i = 0;
		cin >> n >> p;
		if(n == 0 && p == 0) break;
		vector<int> player;
		player.resize(n+1);
		while(true) {
			if(p > 0) {
				if(p == 1) {
					bool flag = true;
					for(int j=0; j<n; j++) if(i != j && player[j] != 0) flag = false;
					if(flag) break;
				}
				player[i]++;
				p--;
			} else {
				p += player[i];
				player[i] = 0;
			}
			i++;
			if(i >= n) i = 0;
		}
		cout << i << endl;
	}
	
	return 0;
}

Measured memory_bytes: 3008
N, M = map(int, input().split())
P = [0] * M
for i in range(M):
    P[i] = list(map(int, input().split())) + [i + 1]

P = sorted(P, key = lambda x: x[1])
P = sorted(P, key = lambda x: x[0])

a = P[0][0]
c = 0
for i in range(M):
    #print(P[i])
    if P[i][0] == a:
        c += 1
        P[i].append(c)
    else:
        c = 1
        a = P[i][0]
        P[i].append(c)
    #print(P[i])

P = sorted(P, key = lambda x: x[2])
for i in range(M):
    s = str(P[i][0]).zfill(6)
    ss = str(P[i][3]).zfill(6)
    print(s + ss)




Measured memory_bytes: 37412
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
long long f[123456];
#define mod 1000000007;
int main(){
	int n,m;
	f[1]=1;
	for(int i=2;i<=100000;i++){
		f[i]=(i*f[i-1])%mod;
		
	}//printf("%lld\n",f[2]);
//	printf("%lld\n",f[100000]);
	while(~scanf("%d%d",&n,&m)){
		long long ans=0;
		if(abs(n-m)>2){
			printf("0\n");
		}
		else{
			if(abs(n-m)==1){
				ans+=f[n]*f[m]%mod;
			}
			if(abs(n-m)==0){
				ans+=f[n]*f[m]*2%mod;
			}
			printf("%lld\n",ans);
		}
		
		
	}
		
	
	return 0;
} 

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <stdlib.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef vector<double> Vec;
typedef vector<Vec> Mat;
typedef pair<ll,ll> P;
typedef pair<double,ll> Pd;
typedef pair<double,double> PD;
typedef priority_queue<P,vector<P>,greater<P> > P_queue;
typedef priority_queue<Pd,vector<Pd>,greater<Pd> > Pd_queue;

const ll MOD=998244353;
const ll mod=1000000007;
const ll INF=1e15;
const double DEL=1e-6;

#define _GLIBCXX_DEBUG
#define REP(i,a,b) for(int i=(int)a;i<(int)b;i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define ALL(a) a.begin(),a.end()
#define U_ERASE(V) V.erase(unique(ALL(V)), V.end())

void Add(ll &a, ll b){a=(a+b)%mod;}
void Pro(ll &a, ll b){a=(a*b)%mod;}

ll N,C;
ll D[31][31];
ll Count[31][3];

void input(){
    cin>>N>>C;
    rep(i,C) rep(j,C) cin>>D[i][j];
    rep(i,N) rep(k,N) {
        ll x; cin>>x; x--;
        Count[x][(i+k)%3]++;
    }
}

ll Solve(ll a, ll b, ll c){
    if(a==b) return INF;
    if(b==c) return INF;
    if(c==a) return INF;
    ll ret=0;
    rep(i,C) ret+=Count[i][0]*D[i][a];
    rep(i,C) ret+=Count[i][1]*D[i][b];
    rep(i,C) ret+=Count[i][2]*D[i][c];
    return ret;
}
int main(){
    input();
    ll ans=INF;
    rep(i,C) rep(j,C) rep(k,C) ans=min(ans,Solve(i,j,k));
    cout<<ans<<endl;
}

Measured memory_bytes: 3644
#include <stdio.h>
#include <stdbool.h>

int main() {
    int x, y;
    scanf("%d %d", &x, &y);
    bool ok = 0;
    for (int i = 0; i <= x; i++) {
        if (i * 2 + (x - i) * 4 == y) ok = 1;
    }
    if (ok) printf("Yes\n");
    else printf("No\n");
}


Measured memory_bytes: 1660
#include <stdio.h>

void call(int n)
{
	int i, x;

	for(i=1;i<=n;i++){
		x = i;

		if(x%3 == 0){
			printf(" %d", i);
		}
		else {
			do{
				if(x%10 == 3){
					printf(" %d", i);
					break;
				}
				x /= 10;
			}while(x);
		}
	}

	printf("\n");
}


int main(void)
{
	int n;
	scanf("%d", &n);
	call(n);
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(vs) vs.begin(), vs.end()
using ll = long long;
using ii = pair<int, int>;

int32_t main(){
	ios::sync_with_stdio(0);
	int x;
	cin >> x;
	cout << int((1000-x%1000)%1000) << endl;
}


Measured memory_bytes: 3648
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define EPS (1e-7)
#define INF (1e9)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) x.begin(),x.end()
const double PI = acos(-1);
const ll MOD = 1000000007;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
 
template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////////////////////

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int H,W; cin >> H >> W;
    vector<string> board(H);
    rep(i,H) cin >> board[i];
    
    const vector<int> dy = {-1,0,0,1};
    const vector<int> dx = {0,-1,1,0};
    vector<vector<bool>> check(H, vector<bool>(W,false));
    queue<pair<int, int>> que;
    ll ans = 0;
    rep(i,H) {
        rep(j,W) {
            if (check[i][j]) continue;
            if (board[i][j] != '#') continue;
            que.emplace(i,j);
            ll black,white;
            black = white = 0;
            check[i][j] = true;
            while(!que.empty()) {
                int y,x;
                tie(y,x) = que.front(); que.pop();
                if (board[y][x] == '#') black++;
                else white++;
                rep(k,4) {
                    int ny = y + dy[k];
                    int nx = x + dx[k];
                    if (ny < 0 || ny >= H || nx < 0 || nx >= W) continue;
                    if (board[y][x] == board[ny][nx]) continue;
                    if (check[ny][nx]) continue;
                    check[ny][nx] = true;
                    que.emplace(ny,nx);
                }
            }
            ans += black*white;
        }
    }

    cout << ans << endl;
}

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

void dfs(int v, const vector<vector<int>> &g, vector<int> &sum,
		const vector<int> &counter) {
	for (int next : g.at(v)) {
		if (sum.at(next) < 0) {
			sum.at(next) = sum.at(v) + counter.at(next);
			dfs(next, g, sum, counter);
		}
	}
}

int main() {
	int n, q;

	cin >> n >> q;
	vector<vector<int>> g(n);
	for (int i = 0; i < n - 1; i++) {
		int a, b;
		cin >> a >> b;
		a--, b--;
		g.at(a).push_back(b);
		g.at(b).push_back(a);
	}
	vector<int> counter(n);
	while (q--) {
		int p, x;
		cin >> p >> x;
		p--;
		counter.at(p) += x;
	}

	vector<int> sum(n, -1);
	sum.at(0) = counter.at(0);
	dfs(0, g, sum, counter);

	for (int i = 0; i < n; i++) {
		cout << sum.at(i) << (i < n - 1 ? " " : "\n");
	}
}


Measured memory_bytes: 30464
r = range
while True:
    try:
        n = int(input())
        ans = []
        ans = [(a,b,c,d) for a in r(10) for b in r(10) for c in r(10) for d in r(10) if a+b+c+d==n and (a,b,c,d) not in ans]
        print(len(ans))
    except:
        break

Measured memory_bytes: 7560
#include <stdio.h>

int calc(int n)
{
    if (n == 1) return (2);
    return calc(n - 1) + n;
}

int main(void)
{
    int n;
    while (scanf("%d", &n) != EOF) {
        printf("%d\n", calc(n));
    }
    return (0);
}

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

int main()
{
    int n;

    cin >> n;

    int data[n + 1][2];

    for (int i = 0; i < n; ++i)
        cin >> data[i][0] >> data[i][1];
    data[n][0] = 10, data[n][1] = 11;

    for (int i = 0; i < n + 1; ++i)
    {
        if (i >= 2)
        {
            if (data[i][0] == data[i][1])
            {
                if ((data[i - 1][0] == data[i - 1][1]) && (data[i - 2][0] == data[i - 2][1]))
                {
                    cout << "Yes" << endl;
                    break;
                }
            }
        }
        if (data[i][0] == 10)
            cout << "No" << endl;
    }
}

Measured memory_bytes: 3584
/*-------enazuma11----------------*/
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<long long,long long>
#define all(v) v.begin(),v.end()
#define inc(a,n) sort(a,a+n)
#define dec(a,n) sort(a,a+n,greater<int>() )
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define F first
#define S second
#define M 1000000007
 
/* int x[]={-1,-1,0,1,1,1,0,-1};
int y[]={0,1,1,1,0,-1,-1,-1};
*/
/* int x[]={-1,0,1,0};
int y[]={0,1,0,-1};
*/

ll dp[3005][3005];

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);
	int t=1;
//	cin>>t;
	while(t--){
		string s,t;
		ll i,j;
		cin>>s>>t;
		ll n=s.size();
		ll m=t.size();
		ll mx=max(n,m);
		ll vis[mx]={};
		string ans="";
		rep(i,1,n+1)
		{
			rep(j,1,m+1)
			{
				if(s[i-1]==t[j-1])
				{
					dp[i][j]=1+dp[i-1][j-1];
					
				}else
				dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
			}
		}
		i=n,j=m;
		while(i>0 && j>0)
		{
			if(s[i-1]==t[j-1]){
				ans+=s[i-1];
				i--;
				j--;
			}else if(dp[i-1][j]>dp[i][j-1])
			i--;
			else
			j--;
		}
		reverse(all(ans));
		cout<<ans<<'\n';
		
	}
	return 0;
}


Measured memory_bytes: 70784
import sys
def ink(x,y,s):
    global P
    P[y][x]+=1
    P[y+1][x]+=1
    P[y-1][x]+=1
    P[y][x+1]+=1
    P[y][x-1]+=1
    if s==1: return
    P[y+1][x+1]+=1
    P[y+1][x-1]+=1
    P[y-1][x+1]+=1
    P[y-1][x-1]+=1
    if s==2: return
    P[y+2][x]+=1
    P[y-2][x]+=1
    P[y][x+2]+=1
    P[y][x-2]+=1
    return

P=[[0]*14 for j in range(14)]
for s in sys.stdin:
    x,y,s = map(int, s.split(","))
    ink(x+2,y+2,s)
c=0
m=0
for e in P[2:-2]:
    x=e[2:-2]
    c+=x.count(0)
    m=max(max(x),m)
print c
print m

Measured memory_bytes: 4280
import java.util.LinkedHashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
        public static void main(String[] args){
            Scanner sc = new Scanner(System.in);
            long K = sc.nextLong();
            Set<Long> sunekeSet = new LinkedHashSet<>();
            for (long m =1; m <=10e15; m*=10){
                boolean sunukeCheckFlag = true;
                for(int i = 1; sunukeCheckFlag; i++){
                    long x = i * m + m - 1;
                    long y = (i + 1) * m + m - 1;
                    if (x * Sn(y) <=  y * Sn(x)){
                        sunekeSet.add(x);
                        if (K == sunekeSet.size()){
                            sunekeSet.stream().forEach(System.out::println);
                            return ;
                        }
                    }else{
                        sunukeCheckFlag = false;

                    }
                }
            }
        }
        public static long Sn(long num){
            long Sn = 0;
            while (num != 0){
                Sn += num % 10;
                num /= 10;
            }
            return Sn;
        }
}


Measured memory_bytes: 29012
/* おまじない　*/
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
typedef long long ll;
typedef long double ld;
using namespace std;
const ll MOD=pow(10,9)+7;
const ll INF=(1LL<<62);
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};
void init(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
    cout<<fixed;
}

ll ans=0;
int countnum=0;
void bfs(ll a,ll b){
    countnum++;

    if(a%b==0){
        ans+=((a/b)*2-1)*b;
        return;
    }
    ans+=((a/b)*2)*b;
    bfs(b,a%b);
    return;
}

int main(){
    init();
    ll N,X;
    cin>>N>>X;
    bfs(max(N-X,X),min(N-X,X));
    cout<<ans+N<<endl;
}


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

int n,k;
int t[100010];

int check(int m){
  int ret = 0;
  for(int i = 0; i < k; i++){
    int sum = 0;
    while(sum + t[ret] <= m){
      sum += t[ret];
      ret++;
      if(ret == n) return n;
    }
  }
  return ret;
}

signed main(){

  cin >> n >> k;
  for(int i = 0; i < n; i++) cin >> t[i];

  int left = 0,right = 1e9+10;
  while(left + 1 < right){
    int mid = (left+right)/2;
    if(check(mid) >= n) right = mid;
    else left = mid;
    //cout << left << " " << right << endl;
  }

  cout << right << endl;

  return 0;
}



Measured memory_bytes: 3876
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<queue>
#include<algorithm>
using namespace std;
const int MAXN=2005;
int gcd(int a,int b)
{
	if(b==0)
		return a;
	return gcd(b,a%b);
}
int lcm(int a,int b)
{
	return a*b/gcd(a,b);
}

int n,A[MAXN];
bool vis[MAXN];
vector<int> adj[MAXN],adj2[MAXN];
int deg[MAXN],ans[MAXN];
priority_queue<int> Q;

void dfs(int u)
{
	vis[u]=true;
	for(int i=0;i<(int)adj[u].size();i++)
	{
		int v=adj[u][i];
		if(vis[v])
			continue;
		adj2[u].push_back(v);
		deg[v]++;
		dfs(v);
	}
}

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&A[i]);
	sort(A+1,A+n+1);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=n;j++)
			if(i!=j&&gcd(A[i],A[j])>1)
				adj[i].push_back(j);
	for(int i=1;i<=n;i++)
		if(!vis[i])
			dfs(i);
	
	for(int i=1;i<=n;i++)
		if(deg[i]==0)
			Q.push(i);
	int it=0;
	while(!Q.empty())
	{
		int u=Q.top();
		ans[++it]=A[u];
		Q.pop();
		for(int i=0;i<(int)adj2[u].size();i++)
		{
			int v=adj2[u][i];
			deg[v]--;
			if(deg[v]==0)
				Q.push(v);
		}
	}
	for(int i=1;i<n;i++)
		printf("%d ",ans[i]);
	printf("%d\n",ans[n]);
	return 0;
}


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

using namespace std;

int main() {

	int w, h, x, y, r;
	cin >> w >> h >> x >> y >> r;

	if (x - r < 0 || y-r<0 || x+r>w || y+r>h) { cout << "No" << endl; return 0; }
	else { cout << "Yes" << endl; return 0;}

}


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

int main() {
	const int LENGTH = 101;
	char s[LENGTH];
	char t[LENGTH];
	cin >> s >> t;

	std::sort(s, s + strlen(s), [](const char &a, const char &b) {return a < b; });
	std::sort(t, t + strlen(t), [](const char &a, const char &b) {return a > b; });
	string str_s(s);
	string str_t(t);

	if (str_s < str_t) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	cout << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,i,j;
    cin>>n;
    int a[n];
    for (i=0;i<n;i++)
        cin>>a[i];
    int ans=INT_MAX;
    for (i=-100;i<=100;i++)
    {
        int tp=0;
        for (j=0;j<n;j++)
            tp+=(a[j]-i)*(a[j]-i);
        ans=min(tp,ans);
    }
    cout<<ans<<endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010

enum Direction { L_S = 0, R_S = 1, L_B = 2, R_B = 3 };

signed main()
{
    ll N;
    cin >> N;
    vector<ll> A(N, 0);
    REP(i, N) { cin >> A[i]; }
    SORT(A);

    if(N == 2) {
        printf("%lld\n", abs(A[0] - A[1]));
        return 0;
    }

    // 最小が真ん中パターン
    int l_ind = 1, r_ind = A.size() - 3;
    ll cand1 = abs(A[A.size()-1] - A[0]) + abs(A[A.size()-2] - A[0]);
    ll r_val = A[A.size()-2];
    ll l_val = A[A.size()-1];

    auto Process = [&](ll& cand, int flag) {
        while(l_ind <= r_ind) {
            ll val;
            if(flag == L_S) {
                val = A[l_ind];
                l_ind++;
                cand += abs(l_val - val);
                l_val = val;
                flag = R_S;
            }
            else if(flag == R_S) {
                val = A[l_ind];
                l_ind++;
                cand += abs(r_val - val);
                r_val = val;
                flag = L_B;
            }
            else if(flag == L_B) {
                val = A[r_ind];
                r_ind--;
                cand += abs(l_val - val);
                l_val = val;
                flag = R_B;
            }
            else if(flag == R_B) {
                val = A[r_ind];
                r_ind--;
                cand += abs(r_val - val);
                r_val = val;
                flag = L_S;
            }
        }
    };
    Process(cand1, L_S);

    // 最大が真ん中パターン
    l_ind = 2, r_ind = A.size() - 2;
    ll cand2 = abs(A[A.size()-1] - A[0]) + abs(A[A.size()-1] - A[1]);
    r_val = A[0];
    l_val = A[1];
    Process(cand2, L_B);

    ll ans = max(cand1, cand2);
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()

int main() {
  int N;
  cin >> N;
  vector<pair<int, int>> red(N), blue(N);
  REP(i, N) {
    int a, b;
    cin >> a >> b;
    red[i] = make_pair(a, b);
  }
  REP(i, N) {
    int c, d;
    cin >> c >> d;
    blue[i] = make_pair(c, d);
  }
  sort(all(red));
  sort(all(blue));

  int ans = 0;
  for (int i = 0; i < N; i++) {
    int maxH = -1;
    int del = -1;
    int memo = -1;
    for (int j = 0; j < N; j++) {
      if (blue[i].first > red[j].first && blue[i].second > red[j].second &&
          maxH < red[j].second) {
        maxH = red[j].second;
        del = j;
        memo = i;
      }
    }

    if (del >= 0) {
      red[del].first = red[del].second = 735477;
      ans += 1;
    }
  }

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

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

int main()
{
  string S;
  long long int K;
  cin >> S >> K;

  long long int count = 0;
  char ans;
  for(const auto& c : S){
    if(c == '1') ++count;
    else{
      ans = c;
      break;
    }
  }

  if(count >= K) ans = '1';
  cout << ans << endl;
}

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

typedef long long ll;

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

    string s;
    cin >> s;
    if (s.length() < 6 || s[2] != s[3] || s[4] != s[5]) {
        puts("No");
    } else {
        puts("Yes");
    }

    return 0;
}



Measured memory_bytes: 256
ln=10**6+10
sieve=[i for i in range(ln)]
p=2
while p**2<=ln:
  if sieve[p]==p:
    for q in range(p*2,ln,p):
      if sieve[q]==q:
        sieve[q]=p
  p+=1
import collections
def primef(n):
  prime_count=collections.Counter()    
  while n>1:
    prime_count[sieve[n]]+=1
    n//=sieve[n]   
  return prime_count
n=int(input())
ans=0
for i in range(1,n):
  t=1
  for j in primef(i).values():
    t=t*(j+1)
  ans+=t
print(ans)

Measured memory_bytes: 141568
D = int(input())

c = list(map(int, input().split()))

#増加する満足度表 [日数][種類]
s = []
for i in range(D):
    l = list(map(int, input().split()))
    s.append(l)

#開催するコンテストタイプ[日数]
t = [int(input()) for j in range(D)]

last = [0]*26 #最後に開催した日

SP = 0
dis = 0

for k in range(D): #満足度の計算
    SP += s[k][t[k]-1]
    last[t[k]-1] = k + 1 #開催日の更新
    for m in range(26):
        SP -= c[m] * (k + 1 - last[m])
    print(SP)

Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define int long long
#define ld long double
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define ms(v,x) memset(v,x,sizeof(v))
#define ff first
#define ss second
#define frr(i,n) for(int i=0;i<n;i++)
#define td(v) v.begin(),v.end()
#define inf 1000000000 // 1e9
#define M   998244353 // 1e9 + 7
#define MAXN 200100
using namespace std;
typedef vector<int> vi;
typedef set<int> se;
typedef pair<int,int> pii;
inline int mod(int n, int m){if(n%m==0)return m;
int ret = n%m; if(ret < 0) ret += m; return ret; }
int gcd(int a, int b){return (b == 0 ? a : gcd(b, a%b));}
int exp(int a,int b,int m){
    if(b==0) return 1;
    if(b==1) return mod(a,m);
    int k = mod(exp(a,b/2,m),m);
    if(b&1){
        return mod(a*mod(k*k,m),m);
    }
    else return mod(k*k,m);
}

int32_t main(){
    fastio;
    int a,b;
    cin>>a>>b;
    int k = (a+b);
    if(k%2==0){
		cout<<k/2<<endl;
	}else cout<<"IMPOSSIBLE"<<endl;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/stack:512000000")
#include<utility>
#include<iostream>
#include<fstream>
#include<vector>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<ctime>
#include<functional>
#include<random>
#include<climits>
#include<queue>
#include<stack>
#include<deque>
#include<bitset>
#include<map>
#include<set>
#include<unordered_map>
#include<unordered_set>
#include<cassert>
#include<ccomplex>

//4Head

#define all(x) x.begin(), x.end()
#define mp make_pair
#define X first
#define Y second

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;
mt19937_64 gen(time(NULL));

ll const mod = 1e9 + 7;

namespace {
	ll mul(ll a, ll b) {
		ll val = a * b - (ll)((ld)a * b / mod) * mod;
		if (val < 0) val += mod;
		if (val >= mod) val -= mod;
		return val;
	}

	ll poww(ll a, ll b) {
		ll val = 1;
		a %= mod;
		while (b > 0) {
			if (b % 2) val = mul(a, val);
			a = mul(a, a);
			b >>= 1;
		}
		return val % mod;
	}

	ll inv(ll a) {
		return poww(a, mod - 2);
	}
}

ll const maxn = 3e5 + 5;

signed main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	ll h, a; cin >> h >> a;
	cout << (h + a - 1) / a << endl;
	return 0;
}

/*
3
0 1
3 0
1 0
*/

Measured memory_bytes: 256
restaurant_num = gets.chomp.to_i

review_infos = {}

restaurant_num.times do |i|
  name, point = gets.chomp.split(' ')
  review_infos[name] ||= {}
  review_infos[name][i+1] = point.to_i
end

name_dic_order = review_infos.keys.sort
name_dic_order.each do |name|
  answers = review_infos[name].sort_by{|k, v| v}.reverse
  answers.each { |answer| puts answer.first }
end

Measured memory_bytes: 1788
#include<iostream>
#include<cstdio>
#define ll long long
using namespace std;

int main()
{
    ll k,ans=0;
    ll a[30];
    ll m=-100,idx;

    for (int i=0; i<3; ++i)
    {
        cin>>a[i];
        if (a[i]>m)
        {
            m=a[i];
            idx=i;
        }
    }
    cin>>k;
    for (int i=0; i<3; ++i)
        if (idx!=i)
            ans+=a[i];
    for (int i=0; i<k; ++i)
        a[idx]*=2;
    ans+=a[idx];
    cout<<ans<<endl;

    

    return 0;
}


Measured memory_bytes: 764
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}
use std::cmp::Ordering;

#[derive(Eq, PartialEq, Clone, Debug)]
pub struct Rev<T>(pub T);

impl<T: PartialOrd> PartialOrd for Rev<T> {
    fn partial_cmp(&self, other: &Rev<T>) -> Option<Ordering> {
        other.0.partial_cmp(&self.0)
    }
}
impl<T: Ord> Ord for Rev<T> {
    fn cmp(&self, other: &Rev<T>) -> Ordering {
        other.0.cmp(&self.0)
    }
}

fn main() {
    input! {
        s: String,
        t: String,
    }
    let mut s: Vec<char> = s.chars().collect();
    s.sort_by_key(|&a| a);
    let s: String = s.into_iter().collect();

    let mut t: Vec<char> = t.chars().collect();
    t.sort_by_key(|&a| Rev(a));
    let t: String = t.into_iter().collect();

    if s < t {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

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

    std::vector<bool> is_ok(n + 1, true);
    for (int i = 0; i < m; i++) {
        int temp;
        std::cin >> temp;
        is_ok[temp] = false;
    }

    std::vector<long long> ans(n + 1, 0);
    ans[0] = 1;

    const int mod = 1000000007;
    for (int now = 0; now < n; now++) {
        for (int next = now + 1; next <= std::min(now + 2, n); next++) {
            if (is_ok[next]) {
                ans[next] += ans[now];
                ans[next] %= mod;
            }
        }
    }

    std::cout << ans[n] << std::endl;
}


Measured memory_bytes: 1024
a = [int(input()) for i in range(5)]
mod = []
for d in a:
    mod.append(d %10)
for i in range(5):
    for j in range(13):
        if j*10< a[i] <=( j+1)*10:
            a[i] = (j+1) *10

m = 10
for i in mod:
    if i != 0 and i <=m:
        m = i

print((sum(a) - (10 - m)))

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

int main(){
    int n;
    cin >> n;
    int W[n];
    int sum = 0;
    for(int i = 0; i < n ;i++){
        cin >> W[i];
        sum += W[i];
    }
    int leftsum = 0;
    int min = sum;
    //要改良
    for(double i = 0.5; i < n; i++){
        leftsum = 0;
        for(int j = 0; j < n; j++){
            if(j <= i){
                leftsum += W[j];
            }
            if(min > abs((sum-leftsum)-leftsum)){
                min = abs((sum-leftsum)-leftsum);
            }
        }
    }

    cout << min << endl;
    return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <regex>
using namespace std;
#define FOR(i,k,n) for(int i = (k); i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) begin(a),end(a)
#define MS(m,v) memset(m,v,sizeof(m))
#define D10 fixed<<setprecision(10)
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> P;
typedef complex<double> Point;
typedef long long ll;
const int INF = 1145141919;
const int MOD = 100000007;
const double EPS = 1e-10;
const double PI = acos(-1.0);
struct edge
{
	int from, to, cost;
	bool operator < (const edge& e) const { return cost < e.cost; }
	bool operator >(const edge& e) const { return cost > e.cost; }
};
///*************************************************************************************///
///*************************************************************************************///
///*************************************************************************************///

int main()
{
	int n;
	while (cin >> n, n)
	{
		vector<string> s(n);
		vector<int> v(n);
		REP(i, n) cin >> s[i];
		FOR(i, 1, n)
		{
			REP(j, s[i].size())
			{
				if (s[i][j] != '.')
				{
					s[i][j - 1] = '+';
					v[i] = j - 1;
					break;
				}
			}
		}

		REP(i, s.size())
		{
			FOR(j, i + 1, s.size())
			{
				if (s[j].size() >= v[i] && v[i] == v[j])
				{
					FOR(k, i + 1, j)
					{
						s[k][v[j]] = '|';
					}
					break;
				}
				if (s[j].size() < v[i] || s[j][v[i]] != '.') break;
			}
		}

		REP(i, s.size())
		{
			REP(j, s[i].size()) if (s[i][j] == '.') s[i][j] = ' ';
		}

		REP(i, s.size())
		{
			cout << s[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1852
#include<stdio.h>

int p(int i){
  return i / 2;
}

int l(int i){
  return 2 * i;
}

int r(int i){
  return 2 * i + 1;
}

int main(){
  int A, i, B[100000 + 1];

  scanf("%d",&A);

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

  for(i = 1; i <= A; i++){
    printf("node %d: key = %d, ",i, B[i]);
    if(p(i) >= 1)printf("parent key = %d, ",B[p(i)]);
    if(l(i) <= A)printf("left key = %d, ",B[l(i)]);
    if(r(i) <= A)printf("right key = %d, ",B[r(i)]);

    printf("\n");
  }

  return 0;
}



Measured memory_bytes: 2048
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline
N, Q = map(int, input().split())

edges = [[] for _ in range(N)]
for _ in range(N-1):
    a, b = map(int, input().split())
    edges[a-1].append(b-1)
    edges[b-1].append(a-1)

points = [0]*N
for _ in range(Q):
    p, x = map(int, input().split())
    points[p-1] += x

def dfs(v, par):
    for nv in edges[v]:
        if nv == par:
            continue
        points[nv] += points[v]
        dfs(nv, v)

dfs(0, -1)

print(*points)

Measured memory_bytes: 230960
#include <iostream>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
string s, t;
int main() {
  cin >> s >> t;
  vector<ll> v[30];
  for(int i = 0; i < s.size(); ++i) {
    v[s[i]-'a'].push_back(i+1);
  }
  ll ans = 0;
  for(int i = 0, sx = 1; i < t.size(); ++i) {
    int tx = t[i]-'a';
    if(v[tx].size() == 0) {
      ans = -1;
      break;
    }
    ll l = -1, r = v[tx].size();
    while(r-l > 1) {
      ll m = (l+r)/2;
      if(v[tx][m] >= sx) r = m;
      else l = m;
    }
    if(r == v[tx].size()) {
      ans += v[tx][0]+s.size()-sx+1;
      sx = v[tx][0]+1;
    } else {
      ans += v[tx][r]-sx+1;
      sx = v[tx][r]+1;
    }
  }
  cout << ans << endl;
}

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

void F(int *a, int*b) {
	int x;
	x = *a;
	*a = *b;
	*b = x;
}

int main() {
	int n, a, b, c;
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> a >> b >> c;
		if (c < a)
			F(&c, &a);
		if (c < b)
			F(&c, &b);

		if (a*a + b*b == c*c)
			cout<<"YES"<<endl;
		else
			cout<<"NO"<<endl;
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};



signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int n;
	cin >> n;
	string s = "";
	while(n) {
		n--;
		char a = 'a' + n % 26;
		s += a;
		n /= 26;
	}
	reverse(all(s));
	cout << s << endl;
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
#include<algorithm>
#include<functional>
using namespace std;
struct Stray {
	int num;
	int count;
	bool operator <(const Stray& b)const {
		return num < b.num;
	}
};
int main()
{
	Stray a[100000];
	int N;
	long long  K, k = 0;
	scanf("%d%lld", &N, &K);
	for (int i = 0 ; i < N; i++) {
		scanf("%d%d", &a[i].num, &a[i].count);
	}
	sort(a, a + N);
	for (int i = 0; i < N; i++) {
		k += a[i].count;
		if (k >= K) {
			printf("%d", a[i].num);
			return 0;
		}
	}
	return 0;
}

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

// Type alias
using ll=long long;
using ld=double;

using pi=pair<int,int>;
using pll=pair<ll,ll>;
using pld=pair<ld,ld>;
using ti3=tuple<int, int, int>;

using vi=vector<int>;
using vll=vector<ll>;
using vld=vector<ld>;
using vpi=vector<pi>;
using vpll=vector<ll>;
using vpld=vector<ld>;
using vti3=vector<ti3>;

// Constants
const double EPS = 1e-9;
const int inf = numeric_limits<int>::max();

// Macro
#define rep(i,n) for(int i=0;i<int(n);++i)
#define rrep(i,n) for(int i=int(n-1);i>=0;--i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define RREP(i,a,b) for(int i=int(b-1);i>=int(a);--i)
#define SHOW(a) cout << #a << " = " << a << endl
#define ARR(a,n) for(int i=0;i<int(n);++i) cout << #a << "[" << i << "]" << " = " << a[i] << endl

#define ALL(a) a.begin(),a.end()

// Funtcions
ll pow(ll base, ll i, ll mod){
  ll a = 1;
  while(i){
    if (i & 1) {
      a *= base;
      a %= mod;
    }
    base *= base;
    base %= mod;
    i >>= 1;
  }
  return a;
}
ll gcd(ll a, ll b){
  while(b){
    ll c = a % b;
    a = b;
    b = c;
  }
  return a;
}
ll lcm(ll a, ll b){
  return a / gcd(a, b) * b;
}


void solve(){
  int K;
  ll sum = 0;
  cin >> K;
  REP(i, 1, K+1){
    REP(j, 1, K+1){
      REP(k, 1, K+1){
        ll g = gcd(i, j);
        ll e = gcd(g, k);

        sum += e;
      }
    }
  }
  cout << sum << endl;
}

int main(){
  // FastIO
  //ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}

Measured memory_bytes: 3620
import numpy as np
from scipy.sparse import *
import sys
input = sys.stdin.readline

U = 10**5
N = int(input())
XY = np.array([input().split() for _ in range(N)], dtype=np.int32)

graph = csr_matrix((np.ones(N,dtype=np.bool), (XY[:,0], U + XY[:,1])), (2*U+1, 2*U+1))
_, component = csgraph.connected_components(graph)

X_cnt = np.bincount(component[:U+1], minlength = 2*U+2)
Y_cnt = np.bincount(component[U+1:], minlength = 2*U+2)
pts_cnt = np.bincount(component[XY[:,0]], minlength = 2*U+2)
answer = (X_cnt * Y_cnt - pts_cnt).sum()
print(answer)


Measured memory_bytes: 48384
#include <bits/stdc++.h>
#define reg register
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define inf 0x3f3f3f3f
#define eps 1e-8
#define pi acos(-1.0)
#define e exp(1.0)
#define ios ios::sync_with_stdio(false)
#define rep(i,l,r) for(int i=(l);i<(r);i++)
using namespace std;

const int maxn = 2e5 + 10;
const int mod = 1e9 + 7;

int main()
{  
   int n;
   cin>>n;
   if(n == 0) puts("1");
   else puts("0");

   return 0;
}

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

int main() {
    int N; cin >> N;
    string S; cin >> S;
    vector<int> L(N), H(N);
    int m = count(S.begin(), S.end(), '1');
    reverse(S.begin(), S.end());

    int l = m - 1, h = m + 1;
    int sl = 0, sh = 0;
    int x = 1;

    if(l) {
        for(int i = 0; i < N; ++i) {
            L[i] = x;
            if(S[i] == '1') sl += x;
            x *= 2, x %= l;
            sl %= l;
        }
    }
    x = 1;
    for(int i = 0; i < N; ++i) {
        H[i] = x;
        if(S[i] == '1') sh += x;
        x *= 2, x %= h;
        sh %= h;
    }

    auto rec = [&](auto &&rec, int x, int ret) -> int {
        int cnt = __builtin_popcount(x);
        if(x == 0) return ret;
        return rec(rec, x % cnt, ret + 1);
    };

    vector<int> ans(N);
    for(int i = 0; i < N; ++i) {
        if(S[i] == '1') {
            if(l == 0) ans[i] = 0;
            else {
                int n = (sl - L[i] + l) % l;
                ans[i] = rec(rec, n, 1);
            }
        } else {
            int n = (sh + H[i]) % h;
            ans[i] = rec(rec, n, 1);
        }
    }

    for(int i = N - 1; i >= 0; --i) cout << ans[i] << '\n';
    return 0;
}


Measured memory_bytes: 6016
N=int(input())
X=input()
def calc(n,count):
    if n==0:
        return count
    popcount=bin(n).count("1")
    next_n=n%popcount
    #print(next_n)
    if next_n==0:
        return count+1
    else:
        return calc(next_n, count+1)

popcount=X.count("1")
if popcount==1:
    plus=0
    for i in range(N):
        x=X[i]
        if x=="1":
            plus+=pow(2,N-i-1,popcount+1)
    for i in range(N):
        x=X[i]
        if x=="1":
            print(0)
        else:
            ans=plus+pow(2,N-i-1,popcount+1)
            ans%=(popcount+1)
            print(calc(ans,1))
    exit()


plus=0
minus=0
for i in range(N):
    x=X[i]
    if x=="1":
        plus+=pow(2,N-i-1,popcount+1)
        minus+=pow(2,N-i-1,popcount-1)
        plus%=(popcount+1)
        minus%=(popcount-1)

for i in range(N):
    x=X[i]
    if x=="1":
        ans=minus-pow(2,N-i-1,popcount-1)
        ans%=(popcount-1)
        print(calc(ans,1))

    else:
        ans=plus+pow(2,N-i-1,popcount+1)
        ans%=(popcount+1)
        print(calc(ans,1))


Measured memory_bytes: 79544
#include<bits/stdc++.h>
//ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
//clock_t start=clock();clock_t end=clock();cout<<(double)(end-start)/CLOCKS_PER_SEC<<endl;
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int ui;
typedef pair<int,int> pii;
typedef pair<pii,int> ppii;
typedef pair<int,pii> pipi;
typedef pair<ll,ll> pll;
typedef pair<pll,ll> ppll;
typedef pair<ll,pll> plpl;
typedef tuple<ll,ll,ll> tl;
typedef pair<double,double> pdd;
ll mod=1000000007;
ll mod2=998244353;
ll mod3=1000003;
ll mod4=998244853;
ll mod5=1000000009;
ll inf=1LL<<60;
double pi=3.141592653589793238462643383279L;
double eps=1e-9;
#define rep(i,m,n) for(ll i=m;i<n;i++)
#define rrep(i,n,m) for(ll i=n;i>=m;i--)
#define srep(itr,st) for(auto itr=st.begin();itr!=st.end();itr++)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
int dh[4]={1,-1,0,0};
int dw[4]={0,0,1,-1};
int ddh[8]={-1,-1,-1,0,0,1,1,1};
int ddw[8]={-1,0,1,-1,1,-1,0,1};
ll gcd(ll a,ll b){
    if(a<b)swap(a,b);
    if(b==0)return a;
    if(a%b==0)return b;
    return gcd(b,a%b);
}
ll Pow(ll n,ll k){
    ll ret=1;
    ll now=n;
    while(k>0){
        if(k&1)ret*=now;
        now*=now;
        k/=2;
    }
    return ret;
}
ll beki(ll n,ll k,ll md){
  ll ret=1;
  ll now=n;
  while(k>0){
    if(k%2==1){
      ret*=now;
      ret%=md;
    }
    now*=now;
    now%=md;
    k/=2;
  }
  return ret;
}
ll gyaku(ll n,ll md){
  return beki(n,md-2,md);
}
ll popcount(ll n){
    ll ret=0;
    ll u=n;
    while(u>0){
        ret+=u%2;
        u/=2;
        
    }
    return ret;
}
int main(){
    ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    string s;cin>>s;
    string t="hi";
    while(t.size()<s.size())t+="hi";
    if(s==t)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}









Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define VV vector
#define pb push_back
#define bitc  __builtin_popcountl
#define m_p make_pair
#define inf 1000000000000000000ll
#define MAXN 1000001
#define eps 0.0000000001
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
string char_to_str(char c){string tem(1,c);return tem;}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
template<class T>//usage rand<long long>()
T rand() {
    return uniform_int_distribution<T>()(rng);
}

// string to integer stuuu()
// string to long long stoll()
// string.substr(position,length);
// integer to string to_string();

//////////////

#define S second
#define F first
#define int long long  
///////

signed main()
{
	fastio;
	#ifdef ANIKET_GOYAL
		freopen("inputf.in","r",stdin);
		freopen("outputf.in","w",stdout);
	#endif
	int r,d,x;
	cin>>r>>d>>x;
	for(int i=1;i<=10;++i)
	{
		x=r*x-d;
		cout<<x<<"\n";
	}
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
typedef pair<int,int> P;
P pp[100000];
int main(void)
{
	int n,a[100002],i,j,cnt,mx,p1,flg,x,y;
	scanf("%d",&n);
	a[0]=0;	a[n+1]=0;
	for(i=1;i<=n;i++)	scanf("%d",&a[i]);
	flg=0;
	for(i=0;i<=n+1;i++)	{
		if(a[i]!=0)	{
			flg=1;	break;
		}
	}
	x=0;
	while(a[x]==0)	x++;
	y=n+1;
	while(a[y]==0)	y--;
//	printf("%d %d\n",x,y);
	i=x;	p1=0;
	while(i<=y)	{
		j=i+1;
		while(a[j]==a[i])	j++;
		if(a[i-1]>a[i] && a[j]>a[i])	{
			pp[p1].first=a[i];	
			pp[p1].second=1;
			p1++;
//			printf("%d 1\n",i);
		}
		if(a[i-1]<a[i] && a[j]<a[i])	{
			pp[p1].first=a[i];
			pp[p1].second=-1;
			p1++;
//			printf("%d -1\n",i);
		}
		i=j;
	}
	sort(pp,pp+p1);
//	for(i=0;i<p1;i++)	printf(" %d %d\n",pp[i].first,pp[i].second);
	cnt=1;	mx=cnt;
	for(i=0;i<p1;i++)	{
		cnt+=pp[i].second;
		if(i!=p1-1 && pp[i+1].first!=pp[i].first)	{
			mx=max(mx,cnt);
		}
	}
	if(flg==0)	mx=0;
	printf("%d\n",mx);
	return 0;
}


Measured memory_bytes: 3928