akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}

bool comparex(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<1>(a) < get<1>(b);
        
}
bool comparey(tuple<ll,ll,ll> a, tuple<ll,ll,ll> b) {

    return get<2>(a) < get<2>(b);
        
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};

struct UnionFind{
    vector<ll> par;

    UnionFind(ll N) : par(N){
        rep(i,N){
            par[i]=i;
        }
    }

    ll root(ll x){
        if(par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx==ry) return;
        par[rx] = ry;
    }

    bool same(ll x, ll y){
        ll rx = root(x);
        ll ry = root(y);
        return rx == ry;
    }
};


int main() {

    ll N;
    cin >> N;

    vector<tuple<ll,ll,ll>> S;
    vector<tuple<ll,ll,ll>> pos(N);
    vector<tuple<ll,ll,ll>> posx(N);
    vector<tuple<ll,ll,ll>> posy(N);
    vector<ll>x(N);
    vector<ll>y(N);



    rep(i,N){
        cin >>x[i]>>y[i];
        pos[i] = make_tuple(i,x[i],y[i]);

    }
    posx = pos;
    posy = pos;
    sort(all(posx),comparex);
    sort(all(posy),comparey);


    rep(i,N-1){
        ll x1 = get<1>(posx[i]);
        ll x2 = get<1>(posx[i+1]);
        ll n1 = get<0>(posx[i]);
        ll n2 = get<0>(posx[i+1]);
        S.pb(make_tuple(abs(x1-x2),n1,n2));
    }

    rep(i,N-1){
        ll y1 = get<2>(posy[i]);
        ll y2 = get<2>(posy[i+1]);
        ll n1 = get<0>(posy[i]);
        ll n2 = get<0>(posy[i+1]);
        S.pb(make_tuple(abs(y1-y2),n1,n2));
    }

    sort(all(S));
    UnionFind tree(N);

    ll ans = 0;
    rep(i,S.size()){
        ll x = get<1>(S[i]);
        ll y = get<2>(S[i]);
        if(!tree.same(x,y)){
            tree.unite(x,y);
            ans += get<0>(S[i]);
            //cout <<x <<" "<<y<<" "<<get<0>(S[i])<<endl;

        }
        
    }





    cout << ans << endl;
  
    return 0;
    

}


Measured memory_bytes: 18148
#include <iostream>
#include <set>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int n;
	set<int> cun;
	cin >> n;
	for(int i = 0; i < n; i++) {
		int tmp;
		cin >> tmp;
		if(cun.count(tmp)) cun.erase(tmp);
		else cun.insert(tmp);
	}
	cout << cun.size();
	return 0;
}


Measured memory_bytes: 4992
import sys
sys.setrecursionlimit(1000000)
from math import factorial, ceil, floor
from bisect import bisect_right as bsr
from operator import itemgetter as ig
from collections import defaultdict as dd
from collections import deque, Counter as cnt

# お約束
args = None
INF = float("inf")
MOD = int(1e9 + 7)
def input(*ps):
    if type(ps[0]) is list:
        return [input(*ps[0][:-1]) for _ in range(ps[0][-1])]
    elif len(ps) == 1:
        return ps[0](next(args))
    else:
        return [p(next(args)) for p in ps]
def nlist(n, v):
    if not n: return v.copy()
    return [nlist(n[1:], v) for _ in range(n[0])]

class mod:
    def __init__(self, v=0):
        self.v = v
        self.v %= MOD
    def __add__(self, v):
        self.v += v.v
        self.v %= MOD
        return self
    def __str__(self):
        return str(self.v)

# エントリーポイント
def main():
    S = input(str)
    dp = [[mod(0) for _ in range(13)] for _ in range(len(S) + 1)]
    dp[0][0].v = 1
    for i, s in enumerate(S):
        i += 1
        loop = range(10) if s == "?" else [int(s)]
        for n in range(13):
            for m in loop:
                dp[i][(n * 10 + m) % 13] += dp[i - 1][n]
                # dp[i][(n * 10 + m) % 13] %= MOD
    print(dp[-1][5])

if __name__ == '__main__':
    args = iter(sys.stdin.read().split())
    main()


Measured memory_bytes: 162056
import java.util.*;

public class Main {
	public static void main(String[] args) {

		Scanner scan = new Scanner(System.in);
		int N= scan.nextInt();
		int K= scan.nextInt();		
		int Q= scan.nextInt();
		int[] ans = new int [Q]; 
		int[] point = new int[N];
		for (int i=0;i<Q;i++) {
			ans[i] = scan.nextInt();
			point[ans[i]-1]++;
		}
		for(int i=0;i<N;i++) {
			if(K-Q+point[i]>0) {
				System.out.println("Yes");
			}
			else {
				System.out.println("No");
			}
		}
		
	}
}

Measured memory_bytes: 63372
#include <bits/stdc++.h>
#define SZ(x) ((int) (x).size())
using namespace std;

typedef long long i64;

int main() {
    #ifdef LOCAL_RUN
    freopen("task.in", "r", stdin);
    freopen("task.out", "w", stdout);
    //freopen("task.err", "w", stderr);
    #endif // ONLINE_JUDGE
    ios::sync_with_stdio(false);
    cin.tie(0);

    int a, b, c, d;
    cin >> a >> b >> c;
    cin >> c >> d;

    int64_t ans = (int64_t) b + (c / 2) * 2 + (d / 2) * 2 + (a / 2) * 2;
    if (a % 2 == 1 && c % 2 == 1 && d % 2 == 1) {
        ans += 3;
    }
    for (int i = 0; i <= 100000; ++i) {
        if (c >= i && d >= i && a >= i) {
            int64_t nans = 3 * i;
            int na = a - i, nc = c - i, nd = d - i;
            nans += (int64_t) b + (nc / 2) * 2 + (nd / 2) * 2 + (na / 2) * 2;
            if (na % 2 == 1 && nc % 2 == 1 && nd % 2 == 1) {
                nans += 3;
            }
            ans = max(ans, nans);
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int A = in.nextInt();
		int B = in.nextInt();
		System.out.println(lcm(A, B));
		in.close();
	}

	static long gcd(long x, long y) {
		if (x < y) {
			long tmp = y;
			y = x;
			x = tmp;
		}
		if (y == 0) {
			return x;
		}
		return gcd(x % y, y);
	}

	static long lcm(long m, long n) {
		return m * n / gcd(m, n);
	}
}

Measured memory_bytes: 23124
num = input().split(" ")
zahyou = input().split(" ")
zahyou_int = [int(i) for i in zahyou]
num[0] = int(num[0])
num[1] = int(num[1])

rousoku = []
flag = 1
time = 3 * 10 ** 8
for i in range(num[0]-num[1]+1):
    rousoku_min = zahyou_int[i]
    rousoku_max = zahyou_int[(i+num[1]-1)]
    if(flag == 0):
        break
    elif(rousoku_min > 0):
        flag = 0
    time_p = -min(0, rousoku_min) * 2 + rousoku_max
    time_m = max(0, rousoku_max) * 2 - rousoku_min
    if(min(time_p, time_m) < time):
        time = min(time_p, time_m)

print(time)


Measured memory_bytes: 14844
n=int(input())
a=list(map(int,input().split()))
free=[i for i in a if i>=3200]
rate=[399,799,1199,1599,1999,2399,2799,3199]
ans=0
before=0
for r in rate:
    for i in a:
        if before<i <=r:
            ans+=1
            before=r
            break
if len(a) == len(free):
    ans+=1
    print(ans,ans+len(free)-1)
else:
    print(ans,ans+len(free))


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
const int INF=1e9,MOD=1e9+7,ohara=1e6+10;
const ll LINF=1e18;
using namespace std;

#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define Size(n) (n).size()
#define Cout(x) cout<<(x)<<endl
#define doublecout(a) cout<<fixed<<setprecision(15)<<a<<endl;
#define Cerr(x) cerr<<(x)<<endl
#define fi first
#define se second
#define P pair<ll,ll> 
#define m_p make_pair
#define V vector<ll> 

ll n,cnt,ans,a,b,c,d,tmp,tmpp,m,h,w,x,y,sum,pos,k;
ld doua;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
//int dy[]={-1,0,1,-1,1,-1,0,1};
//int dx[]={-1,-1,-1,0,0,1,1,1};
string alph("abcdefghijklmnopqrstuvwxyz"),s;
bool fl;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

    cin>>s;
    if(Size(s)==3){
        reverse(all(s));
    }
    Cout(s);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
    int a[100] = {},i,j,m;
    for(i = 0; i < 3; i++){
        scanf("%d",&a[i]);
    }
    for(j = 0; j < 2; j++){
        for(i = 0; i < 2; i++){
            if(a[i] > a[i+1]){
                m = a[i];
                a[i] = a[i +1];
                a[i + 1] = m;
            }
        }
    }
    printf("%d %d %d\n",a[0],a[1],a[2]);
    return 0;
}


Measured memory_bytes: 2044
/* ex2_2
   seira3 */

#include <stdio.h>

int main(void){
    int N, A; //変数宣言
    scanf("%d",&N); //Nに入力
    scanf("%d",&A); //Aに入力
    printf("%d\n",(N*N-A)); //黒色のマスの個数(N*N-A)を出力
    return 0;
}

Measured memory_bytes: 128
#include <algorithm>
#include <cmath>
#include <cstdint>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for(int(i) = 0; (i) < (n); (i)++)
#define FOR(i, m, n) for(int(i) = (m); (i) < (n); (i)++)
#define All(v) (v).begin(), (v).end()
#define pb push_back
#define MP(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
const int INF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = 1e9 + 7;

int main() {
    int N;
    cin >> N;
    vector<ll> A(N), res(N);
    rep(i, N) cin >> A[i];
    ll sum = 0, d = 1;
    rep(i, N) {
        sum += A[i] * d;
        d *= -1;
    }
    res[0] = sum;
    for(int i = 1; i < N; i++) {
        res[i] = 2 * A[i - 1] - res[i - 1];
    }
    rep(i, N) cout << res[i] << (i == N - 1 ? "\n" : " ");
    return 0;
}

Measured memory_bytes: 2816
"use strict";    
const main = arg => {
  	const Nums = arg.split("\n")[1].split(" ");
  	let ans = 'NO';
  	let Sum = Nums.reduce((prev, current) => {
        return prev*1+current*1;
    });
  
	Sum % 2 ? '': ans = 'YES';
  
  	console.log(ans);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


Measured memory_bytes: 28004
#include <bits/stdc++.h>
using namespace std;
int main() {
  string d;
  cin >> d;
  if(d=="SUN") {
    cout << "7" << endl;
  }
  if(d=="MON") {
    cout << "6" << endl;
  }
  if(d=="TUE") {
    cout << "5" << endl;
  }
  if(d=="WED") {
    cout << "4" << endl;
  }
  if(d=="THU") {
    cout << "3" << endl;
  }
  if(d=="FRI") {
    cout << "2" << endl;
  }
  if(d=="SAT") {
    cout << "1" << endl;
  }
}

Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		// TODO 自動生成されたメソッド・スタブ

		BufferedReader in = new BufferedReader(new InputStreamReader(System.in));

		String N = in.readLine();
		String W = in.readLine();
		String[] Wi = W.split(" ");

		int ans = 0 ;
		int min = 0;
		int left = 0;
		int right  = 0;

		int Li = 0;
		int Ri = Wi.length-1;

		while(Li <= Ri){
			if(left<right){
				left += Integer.parseInt(Wi[Li]);
				Li++;
			}else{
				right += Integer.parseInt(Wi[Ri]);
				Ri--;
			}
		}

		System.out.println(Math.abs(left - right));
	}
}


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

#define int long long

#define ii pair<int,int>
#define fi first
#define sc second
#define lwb lower_bound
#define upb upper_bound
#define all(x) (x).begin(),(x).end()

signed main() {
#ifdef _DEBUG
  // freopen("in", "r", stdin);
#endif
  ios::sync_with_stdio(0); cin.tie(0);
  int n; cin >> n;
  int ans = to_string(n).size();
  for (int i = 2; i * i <= n; i++) {
    if (n % i == 0) ans = min(ans, (int) to_string(n / i).size());
  }
  cout << ans << '\n';
}


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

#define ll long long
#define ld long double

using namespace std;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n, m;
    cin >> n >> m;
    vector<pair<int, int>> v(m);
    for (int i = 0; i < m; ++i) {
        cin >> v[i].first;
        int size;
        cin >> size;
        for (int j = 0; j < size; ++j) {
            int x;
            cin >> x;
            v[i].second += (1 << (x - 1));
        }
    }
    vector<int> dp(5000, 1e9);
    dp[0] = 0;
    for (int i = 1; i <= (1 << n) - 1; ++i) {
        for (int j = 0; j < m; ++j) {
            if ((i & v[j].second) == 0) {
                continue;
            } else {
                dp[i] = min(dp[i], dp[i ^ (i & v[j].second)] + v[j].first);
            }
        }
    }
    if (dp[(1 << n) - 1] == 1e9) {
        cout << -1;
    } else {
        cout << dp[(1 << n) - 1];
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
    int num, machi[4] = { 0 };

    for (int i=0; i<6; i++) {
        cin >> num;
        machi[num-1]++;
    }

    for (int i=0; i<4; i++) {
        if (machi[i] >= 3 || machi[i] <= 0) {
            cout << "NO" << endl;
            return 0;
        }
    }
    
    cout << "YES" << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#include <map>
#include <cmath>
#include <string>

#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
typedef long long ll;
using namespace std;
//================================================

int a = 0, b = 0, c, d, n, k = 0;
string s, t;



int main()
{
	string s;
	cin >> s >> t;
	if (s[0] == t[2] && s[1] == t[1] && s[2] == t[0])
		cout << "YES" << endl;
	else
		cout << "NO" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <queue>
#include <unordered_map>
#include <unordered_set>
#include <map>
#include <set>
using namespace std;

#define INF (1ll<<60)


long long M = 1000000007;


int main(int argc, char const *argv[]) {
    long long n;cin>>n;
    vector<long long> a(n),b(n);
    for(int i=0;i<n;++i){
        cin>>a[i];
    }
    long long res=0;
    long long l=-1;
    long long cnt = 1;
    for(long long i=0;i<n;++i){
        if(a[i]>l+1){
            cout<<-1<<endl;
            return 0;
        }
        if(a[i]==l)cnt++;
        else if(a[i]==l+1){
            res+=l*(cnt-1);
            cnt=1;
        }
        else{
            res+=l*cnt;
            cnt=1;
        }
        l=a[i];
        // cout<<i<<" "<<a[i]<<" "<<res<<endl;
    }
    res+=l*cnt;
    cout<<res<<endl;
    return 0;
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
inline int read(int &x){
	char c=getchar();bool f=0;x=0;
	while(!isdigit(c)) f|=c=='-',c=getchar();
	while(isdigit(c)) x=(x<<1)+(x<<3)+(c^48),c=getchar();
	if(f) x=-x;return x;
}
inline void write(int x){
	if(x<0) putchar('-'),write(-x);
	else{if(x>9) write(x/10);putchar('0'+x%10);}
}
int n,a[55],ans;
signed main(){
	read(n);
	for(int i=1;i<=n;i++) read(a[i]);
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			ans+=a[i]*a[j];
	write(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vchar = vector<char>;
using vvchar = vector<vchar>;

#define rep(i, n) for (int i = 0; i < n; ++i)
#pragma region Debug
istream &operator>>(istream &is, P &a)
{
    return is >> a.first >> a.second;
}
ostream &operator<<(ostream &os, const P &a) { return os << "(" << a.first << "," << a.second << ")"; }

template <typename T>
void view(const std::vector<T> &v)
{
    for (const auto &e : v)
    {
        std::cout << e << " ";
    }
    std::cout << std::endl;
}
template <typename T>
void view(const std::vector<std::vector<T>> &vv)
{
    for (const auto &v : vv)
    {
        view(v);
    }
}
#pragma endregion
#pragma region chminmax
template <typename T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return true;
    }
    return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return true;
    }
    return false;
}
#pragma endregion

int main()
{
    int k;
    cin >> k;

    // vector<string> a = {"1", "2", "3", "4", "5", "6", "7", "8", "9"};
    vll a;
    rep(i, 9) a.emplace_back(i + 1);
    int back = 0;
    while (a.size() <= k)
    {
        int curSize = a.size();
        for (int i = back; i < curSize; i++)
        {
            ll x = a[i];
            a.emplace_back(x * 10 + (x % 10));
            if (x % 10 != 9)
            {
                a.emplace_back(x * 10 + (x % 10) + 1);
            }

            if (x % 10 != 0)
            {
                a.emplace_back(x * 10 + (x % 10) - 1);
            }
        }
        back = curSize;
    }

    a.emplace_back(0);

    sort(a.begin(), a.end());

    cout << a[k] << endl;

    // vector<string> b = a;
    // while (b.size() <= k)
    // {
    //     for (string s : b)
    //     {
    //         char back = s.at(s.size() - 1);
    //         s += back;
    //         b.emplace_back(s);
    //         if (back >= '1')
    //         {
    //             s[s.size() - 1] = back - 1;
    //             b.emplace_back(s);
    //         }
    //         if (back < '9')
    //         {
    //             s[s.size() - 1] = back + 1;
    //             b.emplace_back(s);
    //         }
    //     }
    // }
    //
    // view(b);
    // cout << b[k] << endl;

    return 0;
}

Measured memory_bytes: 2420
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define ll long long
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<int> v1(n/2),v2(n/2);
    rep(i, n) {
        if(i%2==0){
        cin >> v1[i/2];
        }else{
        cin >> v2[i/2];
        }
    }
    sort(v1.begin(), v1.end());
    sort(v2.begin(), v2.end());
    int cnt = 0;
    int max1 = 0,max12 = 0;
    int a1 = 0;
    int tmp = v1[0];
    rep(i,n/2){
        if(tmp==v1[i]){
            cnt++;
        }else{
            if(max1<=cnt){
                max12 = max1;
                max1 = cnt;
                a1 = tmp;
            }else if (max12<cnt){
                max12 = cnt;
            }
            cnt = 1;
            tmp = v1[i];
        }
    }
    if (max1 <= cnt)
    {
        max12 = max1;
        max1 = cnt;
        a1 = tmp;
    }
    cnt = 0;
    tmp = v2[0];
    int max2 = 0, max22 = 0;
    int a2 = 0;
    rep(i,n/2){
        if(tmp==v2[i]){
            cnt++;
        }else{
            if(max2<=cnt){
                max22 = max2;
                max2 = cnt;
                a2 = tmp;
            }else if(max22 <cnt){
                max22 = cnt;
            }
            cnt = 1;
            tmp = v2[i];
        }
    }
    if (max2 <= cnt)
    {
        max22 = max2;
        max2 = cnt;
        a2 = tmp;
    }
    if (a2!=a1){
        cout << n - max2 - max1 << endl;
    }else{
        cout << min(n - max2 - max12, n - max22 - max1) << endl;
    }

}


Measured memory_bytes: 640
def main():
  import sys
  input=sys.stdin.buffer.readline
  h,w=map(int,input().split())
  s=[c//8for _ in range(h)for c in input()]
  dp=[10001]*h*(w+1)
  dp[0]=5-s[0]
  for i in range(h):
    for j in range(w):
      k=i*(w+1)+j
      dpk=dp[k]
      sk=s[k]
      l=k+1
      t=dpk+(sk^s[l])
      if dp[l]>t:dp[l]=t
      if i+1<h:
        l=k-~w
        t=dpk+(sk^s[l])
        if dp[l]>t:dp[l]=t
  print(dp[-2]+1>>1)
main()

Measured memory_bytes: 3188
n=int(input())
s=input()
d=set(list(s))
def counter(s1,s2):
    count=0
    for d1 in d:
        if d1 in list(s1) and d1 in list(s2):
            count+=1 
    return count
m=0
for i in range(1,n):
    m=max(counter(s[0:i],s[i:n]),m)
print(m)

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

using namespace std;

template<class T, class U>
void ckmin(T &a, U b)
{
    if (a > b) a = b;
}

template<class T, class U>
void ckmax(T &a, U b)
{
    if (a < b) a = b;
}

#define MP make_pair
#define PB push_back
#define LB lower_bound
#define UB upper_bound
#define fi first
#define se second
#define SZ(x) ((int) (x).size())
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define FORD(i, a, b) for (auto i = (a) - 1; i >= (b); i--)
#define MAXN 100013
#define LLINF 2696969696969696969

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vpi;
typedef vector<pll> vpl;

int N, M;
pair<pii, ll> arr[MAXN];
vpi edges[MAXN];
ll fen[MAXN], dist[MAXN];

void update(int idx, ll v)
{
    for (int e = idx + 1; e <= N; e += e & (-e))
    {
        ckmin(fen[e], v);
    }
}
ll query(int idx)
{
    ll res = LLINF;
    for (int e = idx + 1; e; e -= e & (-e))
    {
        ckmin(res, fen[e]);
    }
    return res;
}


int32_t main()
{
    cout << fixed << setprecision(12);
    cerr << fixed << setprecision(4);
    ios_base::sync_with_stdio(false); cin.tie(0);
    cin >> N >> M;
    FOR(i, 0, M)
    {
        int l, r, d;
        cin >> l >> r >> d; l--; r--;
        edges[l].PB({r, d});
        //anybody in [l...r] can go to anybody else in [l...r] with cost c.
    }
    FOR(i, 0, N + 1) fen[i] = LLINF;
    update(N - 1, 0);
    FOR(i, 0, N)
    {
        dist[i] = query(N - i - 1);
        for (pii p : edges[i])
        {
            update(N - 1 - p.fi, dist[i] + p.se);
        }
    }
    cout << (dist[N - 1] >= LLINF ? -1 : dist[N - 1]) << '\n';
    return 0;
    //in each node of the segtree you store the edges: given that you're in this range, you can go to anywhere in p with cost c.
    //each edge gets put in O(logN) nodes, but only processed the first time?
}


Measured memory_bytes: 7424
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)
 
int n;
int a[110];
int main(){
    scanf("%d",&n);
    rep(i,0,n)scanf("%d",a+i);
    int ans=1e9;
    rep(x,1,101){
        int temp=0;
        rep(i,0,n)temp+=(a[i]-x)*(a[i]-x);
        ans=min(ans,temp);
    }
    printf("%d",ans);
}

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

int main(){
  ll n, k;
  cin >> n >> k;
  priority_queue<ull> h;
  ull tmp;
  for (ll i = 0; i < n; i++) {
    cin >> tmp;
    h.push(tmp);
  }
  ll nokori = k;
  
  for (ll i = 0; i < n; i++) {
    if (!h.empty()) {
      if (nokori) {
        h.pop();
        nokori--;
      }
    } else {
      cout << 0;
      return 0;
    }
    if (!nokori) break;
  }
  ull ans = 0;
  while (!h.empty()) {
    ans += h.top();
    h.pop();
  }
  cout << ans;
  return 0;
}



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

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

	const int N = 50021;
	vector<bool> primes( N+1, true );

	primes[0] = false;
	primes[1] = false;

	for( int i = 2; i*i <= N; ++i ) {
		if( primes[i] ) {
			for( int j = 2*i; j <= N; j += i ) {
				if( j%i == 0 ) {
					primes[j] = false;
				}
			}
		}
	}

	int x;
	while( cin >> x ) {
		int i = x-1;
		int j = x+1;
		while( i >= 0 && !primes[i] ) { i -= 1; }
		while( j <= N && !primes[j] ) { j += 1; }

		cout << i << ' ' << j << '\n';
	}

	return 0;
}



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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	char x,y; cin >> x >> y;

	if(x == y) cout << "=\n";
	else if(x < y) cout << "<\n";
	else cout << ">\n";

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define mod 1000000007
typedef long long int ll;
using namespace std;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
  
    ll n; cin>>n;
    ll dp[n+3]={0};
    dp[0]=1;
    for(int i=3;i<=n;i++){
        for(int j=3;j<=n;j++){
            if(i-j>=0) dp[i]=(dp[i]+dp[i-j])%mod;
        }
    }
    cout<<dp[n]<<endl;
}

Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
const int INF = 1<<30;

int main(){
  int d, g;cin>>d>>g;
  vector<int> p(d), c(d);
  for(int i=0;i<d;i++)cin>>p[i]>>c[i];
  int ans=INF;
  for(int i=0;i<(1<<d);i++){
  	int count=0, p_count=0;
    for(int j=0;j<d;j++){
      if(i&(1<<j)){count+=c[j]+p[j]*100*(j+1);p_count+=p[j];}
    }
    // printf("%d: count=%d, p_count=%d\n", i, count, p_count);
    if(g<=count)ans=min(ans, p_count);
    else{
      int t=d-1;
      while(i&(1<<t))t--;
      int np=(g-count)/(100*(t+1))+((g-count)%(100*(t+1))!=0);
      // printf("\tnp=%d, t=%d\n", np, t);
      if(np<p[t]){p_count+=np;ans=min(ans, p_count);}
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int dx[] = {1,0,-1,0};
int dy[] = {0,-1,0,1};
const ll INF = 1001001001;

int main(){
    int N;
    cin >> N;
    string str = "";
    while(N != 0){
        int r = N%2;
        if(r < 0) r += 2;
        N = (N-r)/(-2);
        str += (char)('0'+r);
    }
    reverse(str.begin(),str.end());
    if(str == "") str = "0";
    cout << str << endl;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
    int a, b, c;
    std::cin >> a >> b >> c;

    if(a == b + c){
        std::cout << "Yes" << std::endl;
    }else if(b == c + a){
        std::cout << "Yes" << std::endl;
    }else if(c == a + b){
        std::cout << "Yes" << std::endl;
    }else{
        std::cout << "No" << std::endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pb push_back
#define fi first
#define se second
typedef pair<ll,ll> P;
#define Mod 1000000007
using VP = vector<P>; using VVP = vector<VP>;
using VI = vector<ll>; using VVI = vector<VI>; using VVVI = vector<VVI>;
#define INF 1ll<<59


int main(){
  ll i,j;
  bool area[100][100];
  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      if(i<50) area[i][j]=0;
      else area[i][j]=1;
    }
  }
  ll a,b;
  cin>>a>>b;
  a--;
  b--;
  ll as=a%22;
  ll at=a/22;
  for(i=0;i<at;i++){
    for(j=0;j<22;j++){
      area[2*i][2*j]=1;
    }
  }
  for(j=0;j<as;j++){
    area[2*at][2*j]=1;
  }
  ll bs=b%22;
  ll bt=b/22;
  for(i=0;i<bt;i++){
    for(j=0;j<22;j++){
      area[2*i+51][2*j]=0;
    }
  }
  for(j=0;j<bs;j++){
    area[2*bt+51][2*j]=0;
  }
  cout<<100<<" "<<100<<endl;
  for(i=0;i<100;i++){
    for(j=0;j<100;j++){
      if(area[i][j]) cout<<'.';
      else cout<<'#';
    }
    cout<<endl;
  }

  return 0;
}

Measured memory_bytes: 256
# A - Still TBD
# https://atcoder.jp/contests/abc119/tasks/abc119_a

# threshold
TY, TM, TD = 2019, 4, 30

Y, M, D = map(int, raw_input().split('/'))

if M > 4:
    print '{}'.format('TBD')
else:
    print '{}'.format('Heisei')


Measured memory_bytes: 2568
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#define lld long long int
#define DBG1(vari1) cerr<<#vari1<<" = "<<(vari1)<<endl;
#define DBG2(vari1,vari2) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<endl;
#define DBG3(vari1,vari2,vari3) cerr<<#vari1<<" = "<<(vari1)<<" "<<#vari2<<" = "<<(vari2)<<" "<<#vari3<<" = "<<(vari3)<<endl;
using namespace std;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	// freopen("input.txt", "r", stdin);  
	lld n;
	cin >> n; 
	lld ans = (n/11)*2;
	if(n%11>6)
		ans+=2;
	else if(n%11>0)
		ans++;
	cout << ans;
}

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

int main(){
	int n,m;
	cin >> n >> m;
	vector<int> x(m);
	for(int i=0; i<m; i++) cin >> x[i];
	sort(x.begin(), x.end());
	
	vector<int> d(m-1);
	for(int i=0; i<m-1; i++) d[i] = x[i+1]-x[i];
	sort(d.begin(), d.end());

	long long ans = 0;
	for(int i=0; i<m-n; i++) ans += d[i];
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3972
/*
We will not return to the countless mistakes of the past
I will not relive the failures of the man I once was

Only through dedication will I destroy all preconception

No longer will I let myself be truly satisfied with the standard
We will not return to the countless mistakes of the past

Only through dedication will I destroy all preconception

Let this be
Be the day
Day of my
My declaration
Let this be the day of my declaration

Join me,
Walk with me

Shatter the bonds that tie us
To what we strive to never be

Join me,
Walk with me
*/
#include<bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn=1000001;

int gcd(int a,int b){

if(a<b) swap(a,b);
if(a%b==0) return b;
return gcd(b,a%b);

}

int main(){

int n;
cin>>n;
int a[n];
forn(i,n) cin>>a[i];
int ans=-1;


forn(i,n){

fore(j,i+1,n-1){

ans=max(ans,abs(a[i]-a[j]));

}

}
cout<<ans;
return 0;

}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i < (int)(n); i++)
using ll = long long;

int main(){
  int n,m;
  cin>>n>>m;
  vector<set<int>> ship(n);
  rep(i,m){
    int a,b;
    cin>>a>>b;
    ship.at(a-1).insert(b-1);
    ship.at(b-1).insert(a-1);
  }
  int flag = 0;
  for(auto s: ship.at(0)){
    if(ship.at(n-1).count(s))flag = 1;
  }
  if(flag)cout<<"POSSIBLE"<<endl;
  else cout<<"IMPOSSIBLE"<<endl;
  return 0;
}

Measured memory_bytes: 28416
/*   _ _ _                     
    | | | | ___  ___           
    | | | || . ||  _|          
    |_____||_  ||_|  _____     
             |_|    |_____|  */
// Time : 19/10/16
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 0x3f3f3f3f
int main(){
#ifdef Wqr_
    freopen("in.txt","r",stdin);
#endif
    std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
    int n;
    cin >> n;
    int num = 0;
    for(int i = 1; i <= n; i++){
        if(i % 2) num++;
    }
    double ans = (double)num / n;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
int a, b;
scanf("%d %d", &a, &b);
if (a<b) {
	printf("a < b\n");
} else if (a>b) {
	printf("a > b\n");
} else if (a==b) {
	printf("a == b\n");
}

return 0;
}

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

void solve(){

	
	string s ;
	cin>>s ;

	int n=s.length() ;

	char c=s[n-1] ;

	if(c=='s'){
		s=s+"es" ;
	}
	else{
		s=s+"s" ;
	}

	cout<<s ;


	
}


int main(){


		int y ;

		y=1 ;
		//cin>>y ;

		while(y--){
 
			solve() ;

		}

}

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


int main() {
int n;
cin >> n;
if(n/10==9||n%10==9) cout << "Yes" << endl;
else cout << "No" <<endl;
}

Measured memory_bytes: 256
A,B = map(int,input().split())
from fractions import gcd
C = gcd(A,B)
num = []
for i in range(2,int(C**0.5)+1):
    while C%i==0:
        num.append(i)
        C //= i
if C != 1:
    num.append(C)
from collections import Counter
CC = Counter(num)
print(len(CC)+1)

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

int main() {
    string w;
    cin >> w;
    vector<int>alp(30);

    for(int i=0;i<w.size();i++){
        alp[w[i]-'a']++;
    }
    for(int i=0;i<26;i++){
        if(alp[i]&2!=0){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<stdint.h>
#include<inttypes.h>

typedef int32_t RUQ_val;

typedef struct range_update_query {
  RUQ_val *val;
  int32_t size;
  int32_t bit;
  RUQ_val empty;
} RUQ;

RUQ* new_RUQ (const int32_t n) {
  int32_t k = 0;
  while ((1 << k) < n) ++k;
  RUQ *s = (RUQ *) calloc (1, sizeof (RUQ));
  s->val = (RUQ_val *) calloc (2 << k, sizeof (RUQ_val));
  s->size = 1 << k;
  s->bit = k;
  s->empty = -1;
  return s;
}

static inline void propagate (RUQ *s, int32_t k) {
  if (s->val[k] == s->empty) return;
  s->val[2 * k] = s->val[2 * k + 1] = s->val[k];
  s->val[k] = s->empty;
}

void update (RUQ *s, int32_t l, int32_t r, RUQ_val v) {
  for (int32_t i = s->bit; i > 0; --i) {
    propagate (s, (l + s->size) >> i);
    propagate (s, (r - 1 + s->size) >> i);
  }
  for (l += s->size, r += s->size; l < r; l >>= 1, r >>= 1) {
    if (l & 1) s->val[l++] = v;
    if (r & 1) s->val[--r] = v;
  }
}

RUQ_val find (RUQ *s, int32_t x) {
  x += s->size;
  for (int32_t i = s->bit; i >= 0; --i) {
    if (s->val[x >> i] != s->empty) {
      return s->val[x >> i];
    }
  }
  return s->empty;
}

typedef int32_t i32;

void run(void){
  i32 n, q;
  scanf ("%" SCNi32 "%" SCNi32, &n, &q);
  RUQ *s = new_RUQ (n);
  update (s, 0, n, 2147483647);
  while (q--) {
    i32 type;
    scanf ("%" SCNi32, &type);
    if (type == 0) {
      i32 l, r, x;
      scanf ("%" SCNi32 "%" SCNi32 "%" SCNi32, &l, &r, &x);
      update (s, l, r + 1, x);
    } else {
      i32 k;
      scanf ("%" SCNi32, &k);
      printf ("%" PRIi32 "\n", find (s, k));
    }
  }
}

int main(void){
  run();
  return 0;
}



Measured memory_bytes: 2660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
//#define ll long long
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 (a>b) { a=b; return 1; } return 0; }
#define rep(i, n) REP(i, 0, n)
#define rep_rev(i, n) for (int (i) = (int)(n) - 1 ; (i) >= 0 ; --(i))
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for(int i = x; i < n; i++)
#define all(x) (x).begin(),(x).end()
ll t1,t2,t3;
const ll mod = 1000000007;
const int INF = 1e9;
const ll INFLONG = 1e18;
void swap(ll *x,ll *y) {
  ll tmp;
  tmp = *x;
  *x = *y;
  *y = tmp;
}
int main(){
  ll h,w;
  cin >> h >> w;
  ll ans;
  if(h == 1 || w == 1){
    ans = 1;
  }else{
    ll t1 = h * w;
    ans = h * w / 2;
    if(t1 % 2 == 1){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long lli;
int main()
{
	int a; cin >> a;
	lli arr[a + 50];
	map<lli, lli> M;
	for(int i=1; i<=a; i++)
	{
		cin >> arr[i];
		M[arr[i] - i] ++;
	}
	lli ans = 0;
	for(int i=1; i<=a; i++)
	{
		M[arr[i] - i] --;
		lli tmp = 1 - arr[i] - 2 - (i - 1);
		ans += M[tmp];
	}
	cout << ans << '\n';
	return 0;
}

Measured memory_bytes: 27892
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <iomanip>


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define rep(i, a, b) for (int i=a; i<(b); i++)
#define rp(i, a) for (int i=0; i<(a); i++)
#define repd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define rpd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cout << std::setprecision(9);
    cout << std::fixed;

    ll n,k;
    cin >> n>>k;
    ll l[n];
    rp(i,n){
      cin >> l[i];
    }
    sort(l,l+n);
    ll ans = 0;
    repd(i,n-k,n){
      ans +=l[i];
    }
    cout << ans << endl;
    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

import sys
from bisect import bisect_left, bisect_right

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
L1=['']*N
L2=['']*N
for i in range(N):
    S=input()
    L1[i]=S.replace('?', 'a')
    L2[i]=S.replace('?', 'z')
L1.sort()
L2.sort()
T=input()

idx1=bisect_left(L2, T)
idx2=bisect_right(L1, T)
print(*list(range(idx1+1, idx2+2)))


Measured memory_bytes: 4716
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
	string s, t;

	cin >> s >> t;

		sort(s.begin(), s.end());
		sort(t.begin(), t.end());

		reverse(t.begin(),t.end());

		if (s < t) cout << "Yes" << endl;
		else  cout << "No" << endl;


	

	return 0;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> i_i;

#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((ll)(x).size())

const double PI  = acos(-1.0);
const double EPS = 1e-9;
const ll INF = 1e9+10;
const ll mod = 998244353;
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; }
#define print(x) cerr << #x << " is " << x << endl;
//#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 

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

int main()
{
    int N;
    cin >> N;
    
    ll ans = 0;
    rep(i, N){
        rep(j, N){
            rep(k, N){
                int a = gcd(i + 1, j + 1);
                ans += gcd(a, k + 1);
            }
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 3636
/*
No matter how long a night, dawn will always break.

Simular saying ... The darkest hour is just before the dawn.
 ***************************************   ************************8   **********************************
*/
#include <bits/stdc++.h>
using namespace std;

 
#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define endl        '\n'
#define sz(x)	    (int)(x).size()
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define hell        998244353
#define output(x) cout << (x ? "YES" : "NO")<<endl;
 
 
 
 
 
int gcd(int a, int b) {if(a>b)swap(a,b) ;  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}
 

 
 
 
signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
   int i,j,x,a,b,c,n,m,k,sum=0;
  cin>>n>>k;
  vi v(n+1),cycle;
  int vis[n+1];
  _init(vis);
  fo(i,1,n+1){
  	cin>>v[i];
  }

  x=1;
  j=0;
  while(vis[x]==-1){
  	vis[x]=j;
  	cycle.pb(x);
  	x=v[x];
  	j++;
  	if(vis[x]!=-1){
  		b=vis[x];
  	}
  }
  /*fo(i,0,cycle.size()){
  	cout<<cycle[i]<<" ";
  }
  cout<<endl<<b<<" "<<k<<endl;
*/
  if(k<b){
  	cout<<cycle[k];

  }
  else{
  	k-=b;
  	a=cycle.size();
  	c=a-b+1;
  	vi vv;
  	fo(i,b,cycle.size()){
  		vv.pb(cycle[i]);
  	}
  	cout<<vv[k%vv.size()];
  }
  /*a=cycle.size();
  fo(i,0,a){
  	cout<<cycle[a]<<" ";
  }
  cout<<cycle[k%a];
   */
   
   
    return 0;
}

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

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

long long MOD = 10000000000 + 7;

int main(){
  cout << setprecision(10);
  int N,M; cin >> N >> M;

  map<ll, int> m;
  for(int i = 0; i < N; i++){
    ll tmp; cin >> tmp;
    m[tmp]++;
  }

  vector<pli> v;
  for(int i = 0; i < M; i++){
    int B;
    ll C;
    cin >> B >> C;
    v.push_back(make_pair(C,B));
  }

  for(auto x: m){
    v.push_back(make_pair(x.first, x.second));
  }

  sort(v.rbegin(), v.rend());

  int num = 0;
  ll sum = 0;
  for(int i = 0; i < v.size(); i++){
    // cerr << v[i].first << " " << v[i].second << endl;
    if(num + v[i].second < N){
      num += v[i].second;
      sum += v[i].first * v[i].second;
    } else {
      sum += v[i].first * (N - num);
      break;
    }
  }
  cout << sum << endl;

}


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

int main(){
	int n,ans=0,l=0;
	char a[27];
	char b[102];
	scanf("%d",&n);
	scanf("%s",&a);
	while(a[l]!='\0')l++;
	for(int i=0;i<n;i++){
		scanf("%s",&b);
		int bl=0;
		while(b[bl]!='\0')bl++;
		for(int j=1;j*(l-1)<bl;j++){
			bool d=false;
			for(int k=0;k+j*(l-1)<bl;k++){
				bool c=true;
				for(int m=0;m<l;m++){
					if(a[m]!=b[k+j*m])c=false;
				}
				if(c){ans++; d=true; break;}
			}
			if(d)break;
		}
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1176
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
mod = 10**9+7

def main():
  
  n,k = map(int,input().split())
  sl = [0]*(n+1)
  tree = [[] for i in range(n+1)]
  
  for i in range(n-1):
    a,b = map(int,input().split())
    tree[a] += (b,)
    tree[b] += (a,)

  def dfs(x,depth,k):
    sl[x] = 1
    child = 0
    ans = 1
    for i in tree[x]:
      if sl[i] == 0:
        ans *= dfs(i,depth+1,k)
        child += 1
    if depth == 0:
      for x in range(k-1, k-1-child, -1):
        ans = ans * x % mod   
    else:    
      for x in range(k-2, k-2-child, -1):
        ans = ans * x % mod
    ans %= mod
    return ans

  print(dfs(1,0,k)*k%mod)

if __name__ == '__main__':
    main()

Measured memory_bytes: 106860
#include <stdio.h>
#include <stdlib.h>

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

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

void exchange(int *A,int x,int y){
  int tmp;

  tmp=A[x];
  A[x]=A[y];
  A[y]=tmp;
}

void maxHeapify(int *A,int i,int n){
  int l=Left(i);
  int r=Right(i);
  int largest;

  if(l<=n && A[l]>A[i]) largest=l;
  else largest=i;

  if(r<=n && A[r]>A[largest])largest=r;

  if(largest!=i){
    exchange(A,i,largest);
    maxHeapify(A,largest,n);
  }
}

void buildMaxHeap(int *A,int n){
  int i;
  for(i=n;i>=1;i--) maxHeapify(A,i,n);
}
    
main(){
  int n,i;
  int *A;

  scanf("%d",&n);

  A=(int *)malloc((n+1)*sizeof(int));

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

  buildMaxHeap(A,n);

  for(i=1;i<=n;i++) printf(" %d",A[i]);
  printf("\n");

  return 0;
}

Measured memory_bytes: 2556
#include <iostream>

using namespace std;

int main(int argc, char *argv[])
{
  string x;
  int ans;
  while(1) {
    cin >> x;
    if(x == "0") break;
    ans = 0;
    for(int i = 0; i < x.length(); i++) {
      ans += x[i] - '0';
    }
    cout << ans << endl;
  }
  return 0;
}



Measured memory_bytes: 3164
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

#define rep(i, n) for(int i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int num2cost[10] = { 0, 2, 5, 5, 4, 5, 6, 3, 7, 6 };

// mapping: number => cost
// 1->2
// 2->5
// 3->5
// 4->4
// 5->5
// 6->6
// 7->3
// 8->7
// 9->6

// max: 99..9, 9*6=54
// min: 1, 1*2=2

// max digit: 11..1, 9*2=18

// e.g.1
// 3 7 8 4 -> 5 3 7 4
// - 3 * 5 + 5 = 20

// If all value are -1, return false.
bool valid(const vector<ll>& v) {
  for (auto x : v) {
    if (x != -1) { return true; }
  }
  return false;
}

bool larger(const vector<ll>& left, const vector<ll>& right) {
  if (!valid(left)) { return false; }
  if (!valid(right)) { return true; }
  // Here, left and right are valid.
  ll l_sum = 0;
  ll r_sum = 0;
  rep(i, 10) { if (left[i] >= 0) { l_sum += left[i]; } }
  rep(i, 10) { if (right[i] >= 0) { r_sum += right[i]; } }
  if (l_sum != r_sum) { return l_sum > r_sum; }
  // Here, l_sum and r_sum are equal.
  for (int i = 9; i >= 1; --i) {
    if (left[i] != right[i]) {
      return left[i] > right[i];
    }
  }
  return false; // same.
}

void print_vector(const vector<ll>& v) {
  for (int i = 9; i >= 1; --i) {
    if (v[i] >= 0) {
      rep(j, v[i]) {
        cout << i;
      }
    }
  }
  cout << endl;
}

int main(int argc, char** argv) {
  ll N, M;
  cin >> N >> M;
  vector<int> A(M);
  rep(i, M) {
    cin >> A[i];
  }
  sort(all(A));
  map<ll, ll> cost2num; // stores the max number for each cost.
  for (auto x : A) {
    cost2num[num2cost[x]] = x;
  }

  // For Debug
  // for (auto x : cost2num) {
  //   int cost = x.first;
  //   int num = x.second;
  //   cout << "cost: " << cost << ", num: " << num << endl;
  // }
  vector<ll> costs;
  for (auto x : cost2num) {
    costs.push_back(x.first);
  }
  ll K = costs.size(); // The size of costs.

  // dp[i] ... the maximum score when i match are used.
  // i: [0, N]
  // checked K times. [0..K-1] are checked.
  vector< vector<ll> > dp(N+1, vector<ll>(10, -1));
  dp[0] = vector<ll>(10, 0);
  rep(k, K) { // loop K times
    ll cost = costs[k];
    rep(i, N+1) {
      if ((i-cost >= 0) && valid(dp[i-cost])) {
        vector<ll> nex(dp[i-cost]); // copy
        if (nex[cost2num[cost]] >= 0) {
          ++nex[cost2num[cost]];
        } else {
          nex[cost2num[cost]] = 1;
        }
        if (larger(nex, dp[i])) { // dp[i-costs[k]] + cost2num[costs[k]] > dp[i]
          dp[i] = nex;
        }
      }
    }
  }

  if (valid(dp[N])) {
    print_vector(dp[N]);
  } else {
    // We must not reach here.
    cout << "error" << endl;
    return -1;
  }
}


Measured memory_bytes: 1408