akhauriyash/Code-Regression huggingface dataset:
/**
 *
 * Contest - Problema X: Nome (link)
 *
 * Abridge version.
 *
 * Solution: text
 */
#include <iostream>

#include <map>
#include <set>
#include <queue>
#include <cmath>
#include <vector>
#include <bitset>
#include <cstring>
#include <algorithm>

using namespace std;

using ll = long long;
using ii = pair<ll, ll>;

#define LOG(var, sep) (cerr << #var << " = " << (var) << (sep))
#define LOGM(msg) (cerr << (msg))
#define LOGV(vec, sep) { cerr << #vec << " ="; for (const auto& v : vec) cerr << " " << v; cerr << (sep); }
#define LOGA(arr, N, sep) { cerr << #arr << " ="; for (int i = 0; i < N; ++i) cerr << " " << (arr)[i]; cerr << (sep); }
#define LOGA2(arr, N, M, sep) { cerr << #arr << " =\n"; for (int i = 0; i < N; ++i) { for (int j = 0; j < M; ++j) cerr << (arr)[i][j] << " "; cerr << endl; } cerr << (sep); }

ostream& operator<<(ostream& os, const ii& p)
{
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

const int MAX { 2000010 };
const ll oo { 1LL << 62 };
const int MOD { 1000000007 };

void precomp()
{
}

void solve(int A, int B)
{
    cout << A*B - A - B + 1 << endl;
}

int main()
{
    ios::sync_with_stdio(false);
    precomp();

    int A, B;
    cin >> A >> B;

    solve(A, B);

    return 0;
}


Measured memory_bytes: 256
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int MOD = 1000000007;

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

  
  int n; cin >> n;
  vector<int> a(n);
  rep(i, n) cin >> a[i];

  for (int i = n - 1; i >= 1; --i) {
    if (a[i] < a[i - 1]) {
      --a[i - 1];
    }
  }

  for (int i = 0; i < n - 1; ++i) {
    if (a[i] > a[i + 1]) {
      print("No"); return 0;
    }
  }

  print("Yes");

  return 0;
}

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

public class Main {
    public static final long mod = (long)1e9+7;
    public static final long INF = Long.MAX_VALUE/10;
    public static final int inf = Integer.MAX_VALUE/10;

    static void solve(InputReader in, PrintWriter out){
        String s = in.ns();
        int f = 0;
        for (int i = 0; i < s.length(); i++) {
            f += s.charAt(i)-'0';
        }
        out.println((Integer.parseInt(s)%f==0)?"Yes":"No");
    }

    public static void main(String[] args) throws Exception{
        InputReader in = new InputReader(System.in);
        PrintWriter out = new PrintWriter(System.out);
        solve(in, out);
        out.close();
    }
    public static class InputReader{
        private BufferedReader br;
        private StringTokenizer st;
        public InputReader(InputStream is){
            br = new BufferedReader(new InputStreamReader(is));
            st = null;
        }
        public String ns(){
            if(st == null || !st.hasMoreTokens()){
                try{
                    st = new StringTokenizer(br.readLine());
                }catch (Exception e){
                    throw new RuntimeException(e);
                }
            }
            return st.nextToken();
        }
        public long nl(){
            return Long.parseLong(ns());
        }
        public int ni(){
            return Integer.parseInt(ns());
        }
        public Double nd(){
            return Double.parseDouble(ns());
        }
        public int[] ni(int n){
            int[] a = new int[n];
            for (int i = 0; i < n; i++) {
                a[i] = ni();
            }
            return a;
        }
        public long[] nl(int n){
            long[] a = new long[n];
            for (int i = 0; i < n; i++) {
                a[i] = nl();
            }
            return a;
        }
        public double[] nd(int n){
            double[] a = new double[n];
            for (int i = 0; i < n; i++) {
                a[i] = nd();
            }
            return a;
        }
    }
}

Measured memory_bytes: 21460
p = input().split()
a = int(p[0])
b = int(p[1])

def gcd(m, n):
    x = max(m, n)
    y = min(m, n)
    if x%y == 0:
        return y
    else:
        while x%y != 0:
            z = x%y
            x = y
            y = z
        else:
            return z
def lcm(m, n):
    return int(m*n//gcd(m, n))

print(lcm(a, b))


Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
typedef pair<int,ii> iii;
typedef pair<int, iii> iiii;
typedef pair<double, ii> dii;
typedef long long ll;
typedef pair<ll, ii> lii;
const int INF = 1000000000;
const double EPS = 1e-9;
#define LSOne(S) (S & (-S))
int mods(int a, int b) { return (b + (a%b)) % b; }

int n;
double p, ans, dp[3005];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
    cin >> n;

    dp[0] = 1;
    for (int i = 1; i <= n; i++) {
        cin >> p;
        for (int j = i; j >= 0; j--) {
            dp[j] = dp[j] * (1 - p) + (!j ? 0 : dp[j-1] * p);
        }
    }

    for (int i = n/2+1; i <= n; i++)
        ans += dp[i];

    cout << setprecision(10) << fixed << ans << '\n';
 
    return 0;
}

Measured memory_bytes: 256
/******************************************************************************

                            Online C Compiler.
                Code, Compile, Run and Debug C program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/


using namespace std;
#include <bits/stdc++.h>
int main()
{
    int i,n, w, j;
    
    
    cin >> n >> w ;
    
    int a[n][2];
    
    
    for(i=0;i<n;i++)
    {
        scanf("%d %d ",&a[i][0],&a[i][1]) ;
    }
    long long int dp[w+1][n];
    
    for(i=0;i<n;i++)
    {
        dp[0][i]=0;
    }
    

    
    
    
    for(i=1;i<w+1;i++)
    {
        for(j=0;j<n;j++)
        {
          if(j==0)
          {
            if(i<a[j][0])
            dp[i][0]= 0;
            else dp[i][0]=a[j][1];
          }
          else if(i<a[j][0])
          {dp[i][j]=dp[i][j-1];}
          else
          {dp[i][j]=max((dp[(i-a[j][0])][j-1]+a[j][1]),dp[i][j-1]);}  
        }
    }
    
    cout<<dp[w][n-1];
}


Measured memory_bytes: 81596
from collections import defaultdict, Counter
from itertools import product, groupby, count, permutations, combinations
from math import pi, sqrt
from collections import deque
from bisect import bisect, bisect_left, bisect_right
INF = float("inf")


def main():
    S = input()
    T = input()

    s_sum, t_sum = [0] * (len(S) + 1), [0] * (len(T) + 1)
    for i in range(len(S)):
        s_sum[i + 1] = s_sum[i] + (1 if S[i] == "A" else 2)

    for i in range(len(T)):
        t_sum[i + 1] = t_sum[i] + (1 if T[i] == "A" else 2)

    for _ in range(int(input())):
        a, b, c, d = map(lambda x: int(x) - 1, input().split())
        s = s_sum[b + 1] - s_sum[a]
        t = t_sum[d + 1] - t_sum[c]
        print("YES" if s % 3 == t % 3 else "NO")


if __name__ == '__main__':
    main()


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

int main(){
	long long int   N ;
	string S;
	cin >> N;
  
  N %= 10;
  if(N == 3) cout << "bon" << endl;
  else if(N == 2 || N == 4 || N ==5 || N ==7 || N == 9) cout << "hon" << endl;
  else if(N == 0 || N == 1 || N == 6 || N == 8) cout << "pon" << endl;
}

Measured memory_bytes: 3604
#include<stdio.h>
#include<string.h>

int main(){

char S[27];
int ans = 1;
scanf("%s",S);

for (int i = 0; i < strlen(S)-1; i++){
  for (int j = i+1; j < strlen(S); j++)
  {
    if (S[i]==S[j]){ans = 0;}
  }
}

ans > 0 ? printf("yes") : printf("no");

return 0;

}

Measured memory_bytes: 1728
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int C = sc.nextInt();
		int D = sc.nextInt();
		int start = (A>C)?A:C;
		int end = (B<D)?B:D;
		System.out.println((end-start>0)?(end-start):0);
	}

}


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

int main(){
    int n,w;
    scanf("%d %d",&n,&w);
    int wt[n],val[n],sum_val=0,ans;
    for(int i=0;i<n;i++){
        scanf("%d %d",&wt[i],&val[i]);
        sum_val+=val[i];
    }
    long long dp[n+1][sum_val+1];
    for(int i=0;i<n+1;i++)dp[i][0]=0;
    for(int i=1;i<sum_val+1;i++)dp[0][i]=INT_MAX;
    for(int i=1;i<n+1;i++){
        for(int j=1;j<sum_val+1;j++){
            if(j-val[i-1]>=0)dp[i][j]=min(wt[i-1]+dp[i-1][j-val[i-1]],dp[i-1][j]);
            else dp[i][j] = dp[i-1][j];
            if(i==n && dp[n][j]<=w)ans=j;
        }
    }
    printf("%d",ans);
    return 0;
}

Measured memory_bytes: 82504
#include<bits/stdc++.h>
using namespace std;
namespace whatever{
	int readu(){
		char ch=getchar();
		while(!isdigit(ch))
			ch=getchar();
		int value=ch-'0';
		ch=getchar();
		while(isdigit(ch)){
			value=value*10+ch-'0';
			ch=getchar();
		}
		return value;
	}
	void writeu(int n){
		if(n<10)
			putchar(n+'0');
		else{
			writeu(n/10);
			putchar(n%10+'0');
		}
	}
	void run(){
		int n=readu();
		int x=readu();
		vector<int> a;
		for(int i=0; i<n; ++i)
			a.push_back(readu());
		int result;
		if(x==accumulate(a.begin(), a.end(), 0ll)){
			result=n;
		}
		else if(x>accumulate(a.begin(), a.end(), 0ll)){
			result=n-1;
		}
		else{
			sort(a.begin(), a.end());
			result=0;
			for(int i=0; i<n; ++i)
				if(x>=a[i]){
					x-=a[i];
					++result;
				}
				else
					break;
		}
		writeu(result);
		putchar('\n');
	}
}
int main(){
	whatever::run();
}

Measured memory_bytes: 256
x1,x2,x3,x4 = map(int,input().split())

x5 = x2 - x4 + x3
x6 = x3 - x1 + x4
x7 = x2 - x4 + x1
x8 = x3 - x1 + x2

print(str(x5) + " " + str(x6) + " " + str(x7) + " "+ str(x8))

Measured memory_bytes: 3060
//----AUTHOR:kkdrummer----/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include<ext/rope>
using namespace __gnu_cxx;
using namespace __gnu_pbds;
using namespace std;
typedef long long ll;
typedef long double ld;
typedef complex<int> C;
#define X real()
#define Y imag()
//typedef unordered_set<ll> usll;
//typedef unordered_multiset<ll> umsll;
typedef multiset<ll> msll;
typedef set<ll> sll;
typedef vector<ll> vll;
typedef pair<ll,ll> pll;
typedef vector<pair<ll,ll> > vpll;
typedef priority_queue<ll> pqll;
typedef vector<int> vi;
typedef set<int> si;
typedef multiset<int> msi;
//typedef unordered_multiset<int> umsi;
//typedef unordered_set<int> usi;
typedef pair<int,int> pi;
typedef vector<pair<int,int> > vpi;
typedef vector<pair<double,double> > vpd;
typedef pair<double,double> pd;
typedef priority_queue<int> pqi;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ind_set;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> ind_setll;
#define in insert
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define be begin
#define en end
#define itr iterator
#define io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mo 1000000007
#define inf 1000000000000000001
#define ninf -1000000000000000001
#define ima INT_MAX
#define imi INT_MIN
#define oncnt __builtin_popcount
#define zerobegin __builtin_clz
#define zeroend __builtin_ctz
#define parity __builtin_parity
const ld pii=3.14159265359;
inline ll modpow(ll x,ll n){if(n==0)return 1;if(n==1)return(x%mo);ll u=(modpow(x,n/2));u=(u*u)%mo;if(n%2!=0)u=(u*x%mo)%mo;return u;}
inline ll modinv(ll x){return modpow(x,mo-2);}
inline ll mmul(ll a,ll b){    if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll madd(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;if(a+b>=mo)return(a+b)%mo;return(a+b);}
inline ll msub(ll a, ll b){if(a>=mo)a=a%mo;if(b>=mo)b=b%mo;return((a-b+mo)%mo);}
inline ll mdiv(ll a,ll bb){if(a>=mo)a=a%mo;ll b=modinv(bb);if(b>=mo)b=b%mo;if(a*b>=mo)return(a*b)%mo;return(a*b);}
inline ll gcd(ll a,ll b){return __gcd(a,b);}

void dfs(int cur,stack<int> &s,vi ch[],bool vis[])
{
	if(!vis[cur])
	{
		vis[cur]=true;
		for(int i=0;i<ch[cur].size();i++)
		{
	
			dfs(ch[cur][i],s,ch,vis);
		}
	}
	s.push(cur);
}

ld dp[3000][3000];
int main()
{
io
int testcases=1;//cin>>testcases;
while(testcases--)
{	
int n;
cin>>n;
ld a[n];
ld l=0;
for(int i=0;i<n;i++)
cin>>a[i];
dp[0][0]=1.00;

for(int i=1;i<n+1;i++)
{
	for(int j=0;j<=i;j++)
	{
		if(j==0)
		dp[i][j]+=(dp[i-1][j]*(1-a[i-1]));

		else 
		dp[i][j]=(dp[i-1][j-1]*a[i-1]+dp[i-1][j]*(1-a[i-1]));
	}
}



ld ans=0;
for(int i=n/2+1;i<=n;i++)
ans+=dp[n][i];

cout<<setprecision(10)<<fixed<<ans;


}return 0;}








Measured memory_bytes: 139136
#include <stdio.h>

#define MAX_DIGIT 80

void initialize(int a[])
{
    int i;
    for (i = 0; i < MAX_DIGIT; i++)
        a[i] = 0;
}

void reverse(int a[], int n)
{
    int i, temp[MAX_DIGIT];

    for (i = 0; i < n; i++)
        temp[i] = a[i];
    for (i = 0; i < n; i++)
        a[i] = temp[n - 1 - i];
}

int input_number(int a[])
{
    int num_digit = 0;
    char digit;

    while ((digit = getchar()) != '\n') {
        if (num_digit == MAX_DIGIT) {
            while (getchar() != '\n')
                ;
            return -1;
        }
        a[num_digit++] = digit - '0';
    }

    reverse(a, num_digit);
    
    return num_digit;
}

int add(int a[], int b[], int na, int nb, int result[])
{
    int i, n, num_digit;

    n = na > nb ? na : nb;
    for (i = 0; i < n; i++)
        result[i] = a[i] + b[i];
    for (i = 0; i < n; i++) {
        if (result[i] > 9) {
            if (i == MAX_DIGIT - 1)
                return -1;
            else {
                result[i] -= 10;
                result[i + 1]++;
                num_digit = i + 2;
            }
        }
        else
            num_digit = i + 1;
    }
    
    reverse(result, num_digit);

    return num_digit;
}

int main(void)
{
    int i, n, na, nb, nr;
    int a[MAX_DIGIT], b[MAX_DIGIT], result[MAX_DIGIT];

    scanf("%d", &n);
    while (getchar() != '\n')
        ;
    while (n--) {
        initialize(a);
        initialize(b);
        initialize(result);

        na = input_number(a);
        nb = input_number(b);
        if (na == -1 || nb == -1) {
            printf("overflow\n");
            continue;
        }

        nr = add(a, b, na, nb, result);
        if (nr == -1) {
            printf("overflow\n");
            continue;
        }

        for (i = 0; i < nr; i++)
            printf("%d", result[i]);
        
        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 612
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		int[] a = new int[m];
		int[] b = new int[m];
		boolean[] s = new boolean[200010];
		boolean[] t = new boolean[200010];
		for(int i = 0 ; i < m ; i++) {
			a[i] = sc.nextInt();
			b[i] = sc.nextInt();
			if(a[i] == 1) s[b[i]] = true;
			if(b[i] == n) t[a[i]] = true;
		}
		for(int i = 0 ; i < 200010 ; i++) {
			if(s[i] && t[i]) {
				System.out.println("POSSIBLE");
				return;
			}
		}
		System.out.println("IMPOSSIBLE");
	}
}


Measured memory_bytes: 97832
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <set>
#include <queue>
#include <stack>
using namespace std;
typedef long long int ll;

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

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define drep(i, n) for(int i = n - 1; i >= 0; i--)

const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;

int main() {
  int k;
  string s;
  cin >> k >> s;
  if (s.size() <= k) {
    P(s);
  } else {
    P(s.substr(0, k) + "...");
  }
  return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pii pair<int,int>
#define mk(a,b) make_pair(a,b)
using namespace std;
char a[1005][1005];int n,m,s[1005][1005];
bool in(int x,int y){
    return x<=n&&x>=1&&y<=m&&y>=1;
}
queue<pii>q;
void bfs(){
//    q.push(mk(x,y));
    while (!q.empty()) {
        int x=q.front().first,y=q.front().second;q.pop();
        if (in(x + 1, y) && s[x + 1][y] > s[x][y] + 1)
            s[x + 1][y] = s[x][y] + 1, q.push(mk(x + 1, y));
        if (in(x, y + 1) && s[x][y + 1] > s[x][y] + 1)
            s[x][y + 1] = s[x][y] + 1, q.push(mk(x, y + 1));
        if (in(x - 1, y) && s[x - 1][y] > s[x][y] + 1)
            s[x - 1][y] = s[x][y] + 1, q.push(mk(x - 1, y));
        if (in(x, y - 1) && s[x][y - 1] > s[x][y] + 1)
            s[x][y - 1] = s[x][y] + 1, q.push(mk(x, y - 1));
    }
}
int main(){
    ios::sync_with_stdio(false);
    memset(s,0x3f,sizeof(s));
    cin>>n>>m;
    for(int i=1;i<=n;i++){
        for(int j=1;j<=m;j++){
            cin>>a[i][j];
            if(a[i][j]=='#')s[i][j]=0;
        }
    }
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)if(a[i][j]=='#')q.push(mk(i,j));
    bfs();
    int ans=0;
    for(int i=1;i<=n;i++)for(int j=1;j<=m;j++)ans=max(ans,s[i][j]);
    cout<<ans<<endl;
}



Measured memory_bytes: 13328
import java.util.*;

public class Main {

	public static void main(String[] args){
	
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		List<Integer> a = new ArrayList<>();
		
		while(sc.hasNextInt()){
			a.add(sc.nextInt());
		}
		
		int x = 0;
		
		for(int i = 0; i < n-2; i+=2){
			
			int a_nm = a.get(i);
			int a_n = a.get(i+1);
			int a_np = a.get(i+2);
			
			if(a_nm==a_n && a_n==a_np){
				x++;
			}
			else if(a_nm==a_n){
				x++;
			}
          else if(a_n==a_np){
           		i++;
				x++;
			}
		}
      
      	if(a.get(n-2)==a.get(n-1)&&n%2==0){
        	x++;
        }
      
		System.out.print(x);	
	}
}




Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,k,x[200000] = {},max = -1;
  cin >> n >> k;
  for(int i = 0; i < n; ++i){
    int a;
    cin >> a;
    x[a]++;
  }
  sort(x,x+n,greater<int>());
  int ans = 0;
  for(int i = k;i < 200000; ++i){
    ans += x[i];
  }

  cout << ans << endl;



}


Measured memory_bytes: 1024
#include"bits/stdc++.h"
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define RFOR(i, a, b) for (int i = b - 1; i >= a; i--)
#define RREP(i, n) RFOR(i, 0, n)
#define rep(i, a, b) for (auto i = a; i < b; i++)
#define rrep(i, a, b) for (auto i = a; i > b; i--)
#define range(i, a, b) (a <= i && i < b)
#define fi first
#define fs first
#define se second
#define sc second
//#define int long long
#define ll long long
using namespace std;
using vec = vector<int>;
using mat = vector<vec>;
typedef pair<int, int> P;



bool solve() {
    int N; cin >> N;
    if (N == 0)return false;

    mat t(N, vec(N+1));
    for (int i = 0; i < N; ++i)
    {
        for (int j = 0; j < N + 1; ++j)
        {
            cin >> t[i][j];
        }
    }

    vec dp(1 << N, 1 << 30);
    dp[0] = 0;

    mat cost(1 << N, vec(N));

    for (int i = 0; i < (1 << N); ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            int tmp = t[j][0];
            for (int k = 1; k <= N; ++k)
            {
                if (i & 1 << (k - 1))
                {
                    tmp = min(tmp, t[j][k]);
                }
            }
            cost[i][j] = tmp;
        }
    }

    for (int i = 0; i < (1 << N); ++i)
    {
        for (int j = 0; j < N; ++j)
        {
            
            if (i&(1 << j))continue;
            dp[i | (1 << j)] = min(dp[i] + cost[i][j], dp[i | (1 << j)]);
        }
    }

    cout << dp[(1 << N) - 1] << endl;

    return true;
}

int main() {
    while (solve());
}


Measured memory_bytes: 9884
import math
N,K=map(int,input().split())
A=list(map(int,input().split()))
saishou=A.index(1)
if saishou==0 or saishou==N-1:
    answer=math.ceil((N-1)/(K-1))
    print(answer)
elif saishou+1<=K:
    answer=1+math.ceil((N-K)/(K-1))
    print(answer)
elif N-saishou<=K:
    answer=math.ceil((N-K)/(K-1))+1
    print(answer)
elif (N-K)%(K-1)==0:
    answer=1+(N-K)//(K-1)
    print(answer)
else:
    print(math.ceil(saishou/(K-1))+math.ceil((N-1-saishou)/(K-1)))


Measured memory_bytes: 84016
// Gaurav Aggarwal

/*
useful stl
array<ll,size> ar;         //size(),front(),back(),fill(),empty()
deque<ll> d                //push_back(),push_front(),pop_front(),pop_back()
vector<ll> v(size,val);    //push_back(),*max_element(v.begin(),v.end()),accumulate(v.begin(),v.end(),0)
stack<ll> g;               //push(),pop(),top(),size(),empty()         LIFO
queue<ll> q;               //push(),size(),front(),back(),empty()      FIFO
priority_queue<ll> pq
*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<ll,ll> ipair;
typedef pair<long,long> lpair;
#define scan(x) do{while((x=getchar_unlocked())<'0'); for(x-='0'; '0'<=(_=getchar_unlocked()); x=(x<<3)+(x<<1)+_-'0');}while(0)
char _;
#define For(i, a, b) for(__typeof (a) i=a; i<=b; i++)
#define mod 1000000007
#define PI 3.141592653589793238462643383279502884 
#define debug1(a) cout<<a<<"\n";
#define debug2(a,b) cout<<a<<" "<<b<<"\n";
#define debug3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define debug_arr(a,n) {for(__typeof (n) i=0; i<n; ++i) {cout<<a[i]<<" ";}}
#define inp_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {cin>>a[i];}
#define beg_arr(a,n) for(__typeof (n) i=0; i<n; ++i) {a[i] = 0;}

ll power(ll x, ll y) 
{ 
    ll res = 1;   
    while (y > 0) { 
        if (y & 1) 
            res = (res*x)%mod; 
        y = y>>1;
        x = (x*x)%mod; 
    } 
    return res%mod; 
}

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

    // #ifndef ONLINE_JUDGE
    // freopen("input.txt", "r", stdin);
    // freopen("out.txt", "w", stdout); 
    // #endif  

    int n;
    cin>>n;
    int a,b;
    cin>>a>>b;
    int aa[n];
    inp_arr(aa,n);
    sort(aa,aa+n);
    int c1 =0, c2=0,c3=0;

    for(int i=0;i<n;++i) {
        if(aa[i] <= a) {
            ++c1;
        }
        else if(aa[i] <=b)
            ++c2;
        else
            ++c3;
    }

    cout<<min(c1,min(c2,c3));

    return 0;
}

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

int main(){
    double a,b,x;cin>>a>>b>>x;
    double alpha;
    if(x*2>a*a*b){
        alpha=atan((b-x/(a*a))*2/a);
    }
    else{
        alpha=PI/2-atan(2*x/(a*b*b));
    }
    cout<<setprecision(10)<<alpha*180/PI;


}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define l_ength size
const int inf = (1<<30);
const int mod = 1000000007;
const int x_axis = 1;
const int y_axis = -1;
using ll = long long;
using namespace std;

bool dpx[8100][16100];
bool dpy[8100][16100];

int x[8100];
int y[8100];

char order[10000];

int main(){
	dpx[0][0] = true;
	dpy[0][0] = true;
	int xr = 0, yr = 0;
	int dir = x_axis;
    scanf("%s", order);
    int n = strlen(order);
    order[n] = 'T';
    ++n;
	int offset = 0;
	if( order[0] == 'F' ){
		for( int i = 0; i < n; ++i ){
			if( order[i] == 'T' ){
				offset = i;
				break;
			}
		}
	}
	for( int i = offset; i < n; ++i ){
		char mode = order[i];
		if( mode == 'T' ){
			if( dir == x_axis ) ++xr;
			else ++yr;
			dir *= -1;
		} else{
			if( dir == x_axis ) ++x[xr];
			else ++y[yr];
		}
	}
	for( int i = 0; i < xr; ++i ){
		for( int j = 0; j <= 8010; ++j ){
			if( j-x[i] >= 0 && dpx[i][j-x[i]] ) dpx[i+1][j] = true;
			if( -1*(j-x[i]) >= 0 && dpx[i][-1*(j-x[i])] ) dpx[i+1][j] = true;
			if( j+x[i] >= 0 && dpx[i][j+x[i]] ) dpx[i+1][j] = true;
		}
	}
	for( int i = 0; i < yr; ++i ){
		for( int j = 0; j <= 8010; ++j ){
			if( j-y[i] >= 0 && dpy[i][j-y[i]] ) dpy[i+1][j] = true;
			if( -1*(j-y[i]) >= 0 && dpy[i][-1*(j-y[i])] ) dpy[i+1][j] = true;
			if( j+y[i] >= 0 && dpy[i][j+y[i]] ) dpy[i+1][j] = true;
		}
	}
	int px, py; cin >> px >> py;
	bool fx, fy;
	fx = ( px-offset < 0 ) ? dpx[xr][-(px-offset)] : dpx[xr][px-offset];
	fy = dpy[yr][abs(py)];
	if( fx && fy ) cout << "Yes";
	else cout << "No";
	cout << endl;
}

Measured memory_bytes: 125696
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,m,n) for(int i=(m);i<(n);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-8;
const int MOD = 1000000007;
// const int MOD = 998244353;
const int dy[] = {1, 0, -1, 0}, dx[] = {0, -1, 0, 1};
const int dy8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dx8[] = {0, -1, -1, -1, 0, 1, 1, 1};
template <typename T, typename U> inline bool chmax(T &a, U b) { return a < b ? (a = b, true) : false; }
template <typename T, typename U> inline bool chmin(T &a, U b) { return a > b ? (a = b, true) : false; }
struct IOSetup {
  IOSetup() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
  }
} iosetup;

using CostType = int;
struct Edge {
  int src, dst; CostType cost;
  Edge(int src, int dst, CostType cost = 0) : src(src), dst(dst), cost(cost) {}
  inline bool operator<(const Edge &x) const {
    return cost != x.cost ? cost < x.cost : dst != x.dst ? dst < x.dst : src < x.src;
  }
  inline bool operator<=(const Edge &x) const { return !(x < *this); }
  inline bool operator>(const Edge &x) const { return x < *this; }
  inline bool operator>=(const Edge &x) const { return !(*this < x); }
};

bool is_bipartite(const vector<vector<Edge> > &graph, vector<int> &color) {
  int n = graph.size();
  color.assign(n, 0);
  function<bool(int, int)> dfs = [&](int ver, int now) {
    color[ver] = now;
    for (const Edge &e : graph[ver]) {
      if (color[e.dst] == now || (color[e.dst] == 0 && !dfs(e.dst, -now))) return false;
    }
    return true;
  };
  REP(i, n) {
    if (color[i] == 0 && !dfs(i, 1)) return false;
  }
  return true;
}

int main() {
  int n; cin >> n;
  vector<vector<Edge> > graph(n);
  REP(_, n - 1) {
    int a, b; cin >> a >> b; --a; --b;
    graph[a].emplace_back(a, b);
    graph[b].emplace_back(b, a);
  }
  vector<int> color;
  is_bipartite(graph, color);
  vector<vector<int> > vers(2);
  REP(i, n) vers[max(color[i], 0)].emplace_back(i);
  if (vers[0].size() > vers[1].size()) swap(vers[0], vers[1]);
  vector<vector<int> > ps(3);
  FOR(i, 1, n + 1) ps[i % 3].emplace_back(i);
  vector<int> ans(n);
  if (vers[0].size() > ps[0].size()) {
    for (int e : ps[2]) {
      ans[vers[0].back()] = e;
      vers[0].pop_back();
    }
    for (int e : ps[1]) {
      ans[vers[1].back()] = e;
      vers[1].pop_back();
    }
    for (int e : ps[0]) {
      if (!vers[0].empty()) {
        ans[vers[0].back()] = e;
        vers[0].pop_back();
      } else {
        ans[vers[1].back()] = e;
        vers[1].pop_back();
      }
    }
  } else {
    for (int e : vers[0]) {
      ans[e] = ps[0].back();
      ps[0].pop_back();
    }
    for (int e : vers[1]) {
      if (!ps[0].empty()) {
        ans[e] = ps[0].back();
        ps[0].pop_back();
      } else if (!ps[1].empty()) {
        ans[e] = ps[1].back();
        ps[1].pop_back();
      } else {
        ans[e] = ps[2].back();
        ps[2].pop_back();
      }
    }
  }
  REP(i, n) cout << ans[i] << " \n"[i + 1 == n];
  return 0;
}


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

int main() {
//  freopen("in.txt", "r", stdin);
//  freopen("out.txt", "w", stdout);
  int a[3];
  cin >> a[0] >> a[1] >> a[2];
  sort(a, a + 3);
  if((a[2] - a[1] + a[2]- a[0]) % 2 == 0){
    cout << (a[2] - a[1] + a[2]- a[0]) / 2;
  }else{
    cout << (a[2] - a[1] + a[2]- a[0] + 3) / 2;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define X first;
#define Y second;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 2e5 + 10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1e9+7;


int a[maxN];
int main()
{
	int n;
	cin>>n;
	unordered_map<int,int> mp;
	for(int x=1;x<=100;x++)
	{
		for(int y=1;y<=100;y++)
		{
			for(int z=1;z<=100;z++)
			{
				int tmp = x*x + y*y + z*z + x*y + y*z + z*x;
				if(tmp <= n)
				{
					mp[tmp]++;
				}
			}
		}
	}
	for(int i=1;i<=n;i++)
	{
		cout<<mp[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3924
#include<stdio.h>
#define MAX 500000
#define INFTY 1000000000
int L[MAX/2 + 2], R[MAX/2 + 2];
int count;
int i,k;
void merge( int A[] , int n , int left , int mid ,int right ){
  int n1 = mid - left;
  int n2 = right - mid ;
  for( i = 0 ; i < n1 ; i++ ){
    L[i] = A[ left + i ];
  }
  for( i = 0 ; i < n2 ; i++ ){
    R[i] = A[ mid + i ];
  }
  L[n1] = INFTY;
  R[n2] = INFTY;
  int i = 0 , j = 0;
  for ( k = left ; k < right ; k++){
    count++;
    if( L[i] <= R[j]){
      A[k] = L[i++];
    }
    else{
      A[k] = R[j++] ;
    }
  }
}

void mergeSort( int A[] , int n , int left , int right ){
  if( left + 1 < right ){
    int mid = ( right + left )/2;
    mergeSort( A , n , left , mid );
    mergeSort( A , n , mid , right );
    merge( A , n ,left , mid , right );
  }
}

int main( void ){
  int A[MAX], n , i;
  count = 0;

  scanf("%d",&n);
  for( i = 0 ; i < n ; i++ ){
    scanf("%d",&A[i]);
  }
  mergeSort( A , n , 0 , n);
  for( i = 0 ; i < n ; i++ ){
    if( i == n-1){
      printf("%d",A[i]);
    }
    else{
      printf("%d ",A[i]);
      }
  }
  printf("\n");
  printf("%d\n",count);
  return 0;
}

Measured memory_bytes: 4508
#include<iostream>
#include <algorithm>

using namespace std;

int A, B, C;
long long K;

int main() {
	
	cin >> A >> B >> C >> K;
	
	int ans = 0;
	if (abs(A - B) > 1000000000000000000) {
		cout << "Unfair" << endl;
	}
	else if (K % 2 == 0) {
		cout << A - B << endl;
	}
	else {
		cout << B - A << endl;
	}
	return 0;
}

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


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;

lli mod197 = 1000000007LL;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {


	lli A, B;
	cin >> A >> B;

	COUT(max({A + B,A - B, A * B}));


	return 0;
}

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

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

typedef long long ll;

using namespace std;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> H(N);
  rep(i, N) {
    cin >> H[i];
  }

  ll result = 0;

  if (K >= N) {
    // 0のまま
  } else {
    sort(H.begin(), H.end()); // 昇順
    rep(i, N - K) {
      result += H[i];
    }
  }

  cout << result << endl;

  return 0;
}


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

/* ループ系(全て最初から最後まで範囲に含む) */  
#define repd(i,a,b) for (int i=(a);i<=(b);i++)
#define rep(i,n) repd(i,0,n)
#define repv(i,v) for(int i=0;i < (int)(v).size();i++)
#define repvR(i,v) for(int i=(int)(v).size() - 1;i >= 0;i--)
#define REP(i, n) for(int i=0; i<=(n); i++)
#define FOR(i, a, b) for(int i=(a); i<=(b); i++)
#define FORR(i, a, b) for(int i=(b); i>=(a); i--)

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	REP(i, t) fact[i+1]=fact[i]*(i+1)%MOD;
	fact_inv[t]=power(fact[t], MOD-2);
	FORR(i, 0, t) fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}
  
int main()
{
	//cin.tie(0);	ios::sync_with_stdio(false);

  int N; cin >> N;
  int S=-1;
  rep(i,N){
      if(N*2 <  i*(i+1)){break;}
      if(N*2 == i*(i+1)){S=i;break;}
  } 
  if(S==-1){cout << "No" << endl; return 0;}
  cout << "Yes" << endl;
  int ans[S+1][S];
  int col[S+1]={0};
  int idx=0,num=1;
  FORR(i,1,S){
      rep(j,i-1){
          //cout << idx << " " << col[idx] << " " << num << endl;
          ans[idx][col[idx]]=num;
          col[idx]++;num++;
      }
      idx++;
  }
  idx = 0; num = 1;
  FORR(i,1,S){
      idx = S - i + 1;
      FOR(j,1,i){
          //cout << idx << " " << col[idx] << " " << num << endl;
          ans[idx][col[idx]]=num;col[idx]++;num++;idx++;
      }
  }
  cout << S+1 << endl;
  rep(i,S){
      cout << S << " ";
      rep(j,S-1){
          cout << ans[i][j];
          if(j!=S-1){cout << " ";}
      }
      cout << endl;
  }

  return 0;
}


Measured memory_bytes: 4144
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define all(a) a.begin(), a.end()
#define mkp make_pair
#define F first
#define S second
#define pb push_back
#define ll long long
#define vi vector<long long>
#define sz(x) (int)x.size()
#define pi pair<long long, long long>
#define endl '\n'
#define _ << ' '
#define FAST_LOG2(x) (sizeof(unsigned long)*8 - 1 - __builtin_clzl((unsigned long)(x)))
#define clog2(x) (((x) - (1 << FAST_LOG2(x))) ? FAST_LOG2(x) + 1 : FAST_LOG2(x))
using namespace __gnu_pbds;
using namespace std;
typedef tree<int, null_type, less_equal<int>, rb_tree_tag, tree_order_statistics_node_update> idxset;
//find_by_order(i) : iterator to the value at index i, order_of_key(x) : the index of value x
const ll mod = 998244353;
const ll INF = (ll)1e9+1;
const ll N = 1e5;

ll n, m, d, x, a, b, q;
pair<int, int> t[90001];
ll p[90001];

int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    #ifndef ONLINE_JUDGE
   // freopen("B.txt", "r", stdin);
    #endif
    cin >> n >> m >> d;
    for(int i=1; i<=n; i++)
    {
        for(int j=1; j<=m; j++)
        {
            cin >> x;
            t[x] = mkp(i, j);
        }
    }
    for(int i=1; i<=d; i++)
    {
        for(int j=i+d; j<=m*n; j+=d)
        {
            p[j] = p[j-d] + abs(t[j].S-t[j-d].S) + abs(t[j].F-t[j-d].F);
        }
    }
    cin >> q;
    while(q--)
    {
        cin >> a >> b;
        cout << p[b] - p[a] << endl;
    }
}


Measured memory_bytes: 2560
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <climits>
#include <queue>
#include <set>
#include <map>
#include <valarray>
#include <bitset>
#include <stack>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
typedef long long ll;
typedef pair<int,int> pii;
const int INF = 1<<29;
const double PI = acos(-1);
const double EPS = 1e-8;

typedef complex<double> P;
struct C {
  P p; double r;
  C(const P &p, double r) : p(p), r(r) { }
  C() {}
};
bool p1(const C &a, const C &b) {
  return a.p.real() != b.p.real() ? a.p.real() < b.p.real() : a.p.imag() < b.p.imag();
}
bool p2(const C &a, const C &b) {
  return a.p.imag() != b.p.imag() ? a.p.imag() < b.p.imag() : a.p.real() < b.p.real();
}


C circle[100000];
double minR;

double solve(int s, int t) {
  if (s+1>=t) return INF;
  double m1 = solve(s, (s+t)/2);
  double m2 = solve((s+t)/2, t);
  double mid = (circle[(s+t)/2-1].p.real() + circle[(s+t)/2].p.real()) / 2;
  double d = min(m1, m2) + 2*minR + 1;
  int start = lower_bound(circle+s, circle+t, C(P(mid-d-1, -INF), 0), p1) - circle;
  int end = upper_bound(circle+s, circle+t, C(P(mid+d, INF), 0), p1) - circle;
  vector<C> v;
  //cout << s << " " <<t << endl;
  for (int i=start; i<end; ++i) {
    v.push_back(circle[i]);
    //cout << circle[i].p << endl;
  }
  sort(ALL(v), p2);
  double res = min(m1, m2);
  for (int i=0; i<v.size(); ++i) {
    for (int k=i+1; k<v.size() && (v[k].p.imag()-v[i].p.imag())<d; ++k) {
      res = min(res, abs(v[k].p-v[i].p)-v[k].r-v[i].r);
    }
  }
  //cout << res << endl;
  return res;
}

int main() {
  int n;
  while(cin>>n,n) {
    minR = INF;
    REP(i,n) {
      double x, y, r;
      cin >> r >> x >> y;
      circle[i] = C(P(x,y),r);
      minR = min(minR, r);
    }
    sort(circle, circle+n, p1);
    printf("%.10f\n", solve(0, n));
  }
}

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

int pai[9];

bool IsTempai(int a, int b)
{
    if(b == 5) return true;
    bool t;
    if(b == 0) {
        for(int i = 0; i < 9; ++i) {
            if(pai[i] >= 2) {
                pai[i] -= 2;
                t = IsTempai(0, 1);
                pai[i] += 2;
                if(t) return true;
            }
        }
        return false;
    }
    for(; a < 9; ++a)
    {
        if(pai[a] >= 3)
        {
            pai[a] -= 3;
            t = IsTempai(a, b + 1);
            pai[a] += 3;
            if(t) return true;
        }
        if(a >= 7) continue;
        if(pai[a] && pai[a+1] && pai[a+2])
        {
            --pai[a], --pai[a+1], --pai[a+2];
            t = IsTempai(a, b + 1);
            ++pai[a], ++pai[a+1], ++pai[a+2];
            if(t) return true;
        }
    }
    return false;
}

int main()
{
    bool tempai;
    char tmp[15];
    while(cin >> tmp)
    {
        tempai = false;
        fill_n(pai, 9, 0);
        for(int i = 0; i < 13; ++i)
            ++pai[tmp[i]-'1'];
        for(int i = 0; i < 9; ++i)
        {
            if(pai[i] == 4) continue;
            ++pai[i];
            if(IsTempai(0, 0))
                if(!tempai) {
                    tempai = true; cout << i + 1;
                } else
                    cout << ' ' << i + 1;
            --pai[i];
        }
        if(!tempai)
            cout << '0';
        cout << endl;
    }
}

Measured memory_bytes: 0
K = int(input())

# from fractions import gcd
from math import gcd

# def f(x, y, z):
#     r = gcd(gcd(x, y), z)
#     return r

ans = 0
for i in range(1, K+1):
    for j in range(1, K+1):
        for k in range(1, K+1):
            # ans += f(i, j, k)
            ans += gcd(gcd(i, j), k)

print(ans)

Measured memory_bytes: 9172
#include<stdio.h>

int main(void){

	int mat[11][11],sum[10][10];
	int n,i,j;

	while(1){
	
		scanf("%d",&n);
		

		if(n==0){
			break;
		}
		
		
		for(i=0;i<11;i++){
			for(j=0;j<11;j++){
				mat[i][j]=0;
			}
		}

		
		for(i=0;i<n;i++){
			for(j=0;j<n;j++){
				scanf("%d",&mat[i][j]);
			}
		}

		
		for(i=0;i<n;i++){						
			for(j=0;j<n;j++){
				mat[i][n]=mat[i][n]+mat[i][j];//ツ可。ツ篠イツづ個債計
				mat[n][i]=mat[n][i]+mat[j][i];//ツ縦ツ篠イツづ個債計
			}
		}

		
		for(i=0;i<n;i++){						
			mat[n][n]=mat[n][n]+mat[i][n];
		}

		
		for(i=0;i<n+1;i++){
			for(j=0;j<n+1;j++){
				printf("%5d",mat[i][j]);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <math.h>
#include <list>
#include <stack>
#include <queue>
#include <utility>

using namespace std;

#define ll long long
#define MOD 1000000007
#define rep(i, n) for(int i = 0;i < n;i++)


int main()
{
    int n;
    cin >> n;   
    vector<int> b(n-1);

    for (int i = 0; i < n-1; i++)
    {
        cin >> b[i];
    }

    vector<int> a(n);
    for (int i = 0; i < n-1; i++)
    {
        a[i] = 0;
    }
    a[0] = b[0];
    a[1] = b[0];

    for (int i = 1; i < n-1; i++)
    {
        if (b[i]<a[i])
        {
            a[i] = b[i];
            a[i+1] = b[i];
        }else
        {
            a[i+1] = b[i];

        }
    }

    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        sum+=a[i];
    }

    cout << sum << endl;
    
    
    
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<queue>

using namespace std;

int main (void) {
  int N=0;
  int a[3]={0};
  int b[3]={0};
  int c[3]={0};
  int x=1;

  cin >> N;
  for (int i=0; i<N; i++){
    cin >> a[0] >> a[1] >> a[2];
    c[0]=a[0]-b[0];
    c[1]=a[1]-b[1];
    c[2]=a[2]-b[2];
    if (c[0] == c[1]+c[2]) {
      continue;
    }
    else if ((abs(c[1]+c[2]-c[0]))%2==0 and c[0]>=c[1]+c[2]) {
      continue;
    }
    else {
      x=0;
      cout << "No" << endl;
      break;
      }
    }
  if (x==1) {
    cout <<"Yes" <<endl;
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll h, w, n;
    cin >> h >> w >> n;
    ll a[n];
    for(ll i = 0; i < n; i++) cin >> a[i];
    ll ans[h][w];
    auto pos = pair<ll, ll>(0, 0);
    for(ll i = 1; i <= n; i++){
        for(ll j = 0; j < a[i - 1]; j++){
            ans[pos.first][pos.second] = i;
            pos.second++;
            if(pos.second == w){
                pos.first++;
                pos.second = 0;
            }
        }
    }
    for(ll i = 1; i < h; i += 2) reverse(ans[i], ans[i] + w);
    for(ll i = 0; i < h; i++){
        for(ll j = 0; j < w; j++) cout << ans[i][j] << " ";
        cout << endl;
    }
    return 0;
}

Measured memory_bytes: 384
import sys
import math
import itertools
n = int(input())
a = list(map(int, input().split()))
MAX=10**18
ans = 1
if 0 in a:
    print(0)
    sys.exit()
for i in a:
    ans *= i
    if (ans > MAX):
        print(-1)
        sys.exit()
print(ans)

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

#define int long long
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
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;}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
const int MOD=1000000007;
const int INF=LLONG_MAX/2;

signed main() {cin.tie(0);cout.tie(0);ios::sync_with_stdio(false);
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(a*b,c)<<endl;
    return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import itertools
n = int(input())
l = list(map(int, input().split()))

ans = 0
for i in itertools.combinations(l, 3):
    i = sorted(list(i))
    # print(i)
    if i[0] == i[1] or i[1] == i[2]:
        continue
    if i[0]+i[1] > i[2]:
        # print(i)
        ans += 1

print(ans)


Measured memory_bytes: 9180
x1,y1,x2,y2 = (int(x) for x in input().split())

x = x2 - x1
y = y2 - y1

x3 = x2 - y
y3 = y2 + x

x4 = x3 - x
y4 = y3 - y

print(str(x3) + " " + str(y3) + " " + str(x4) + " " + str(y4))

Measured memory_bytes: 38384
#include <stdio.h>

int main(void)
{
	int ans;
	int n;
	int i;
	int in;
	int rem;
	
	scanf("%d", &n);
	rem = ans = 0;
	for (i = 0; i < n; i++){
		scanf("%d", &in);
		rem += in % n;
		ans += in / n + rem / n;
		rem %= n;
	}
	
	printf("%d\n", ans);
	
	return (0);
}

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

using namespace std;

int dp[100010];
vector<int> G[100010];

int f(int u) {
    int &ans = dp[u];
    if(ans != -1) return ans;
    ans = 0;
    for (int v: G[u]) ans = max(ans, f(v) + 1);
    return ans;
}

int main() {
    memset(dp, -1, sizeof dp);
    int n,m;
    cin >> n >> m;

    for (int i = 0; i < m; ++i) {
        int x,y;
        cin >> x >> y;
        G[x].push_back(y);
    }
 
    int ans = 0;
    for (int i = 1; i <= n; ++i)
        if(dp[i] == -1) ans = max(ans, f(i));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 7424
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn gcd(x: i64, y: i64) -> i64 {
    if y == 0 {
        x
    } else {
        gcd(y, x % y)
    }
}

fn main() {
    let n: usize = read();
    let mut a: Vec<i64> = vec![];
    for _ in 0..n {
        a.push(read());
    }

    let mut ans = a[0];

    for i in 0..a.len() {
        let ai = a[i];
        ans = gcd(ai, ans);
    }
    println!("{}", ans);
}


Measured memory_bytes: 2948
#include "iostream"
#include "string"
#include "algorithm"
using namespace std;

void bubbleSort(int a[], int n)
{
	bool flag = 1;
	for (int i = 0; flag; i++)
	{
		flag = 0;
		for (int j = n - 1; j > i; j--)
		{
			if (a[j] < a[j - 1])
			{
				swap(a[j], a[j - 1]);
				flag = 1;
			}
		}
	}
}
void insertionSort(int a[], int n)
{
	for (int i = 1; i < n-1; i++)
	{
		int v = a[i];
		int j = i - 1;
		while(j >= 0 && a[j] > v)
		{
			a[j + 1] = a[j];
			j--;
		}
		a[j + 1] = v;
	}
}
bool judgeString(string a, string b) {
	bool flag = 1;
	for (int i = 0; i < max(a.size(),b.size()); i++) {
		if (a[i] - b[i] != 0 && a[i] - b[i] != 'a' - 'A')
		{
			flag = 0;
			break;
		}
	}
	return flag;
}

int main(){
	int cnt = 0;
	string word, T;
	cin >> word;
	while (cin >> T){
		if (T == "END_OF_TEXT") {
			break;
		}
		else if (judgeString(word,T)) {
			cnt++;
		}
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3212
#include<bits/stdc++.h>
using namespace std;
const int N=1e6;
const int inf=1<<30;
int i,j,k,m,n,tot;
int a[N],ver[N],nxt[N],edge[N],head[N],b[N],mn,mx;
char s[N],t[N];
void add(int x,int y,int w)
{
	ver[++tot]=y,edge[tot]=w,nxt[tot]=head[x],head[x]=tot;
}
int main()
{
	scanf("%d%d",&n,&m);
	mn=0,mx=inf;
	for(int i=1;i<=m;i++)
	{
		scanf("%d%d",&a[i],&b[i]);
		mn=max(a[i],mn);
		mx=min(b[i],mx);
	}
	if(mx-mn+1>0) printf("%d",mx-mn+1);
	else printf("0");
	return 0;
}

Measured memory_bytes: 4608