akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cstdio>
#include <cstring>
#include <queue>
#include <stack>
#include <set>
#include <cmath>
#include <bitset>
#include <iomanip> 

using ll = long long;
using ull = unsigned long long;
using namespace std;

#define FALSE printf("false\n");
#define TRUE printf("true\n");
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i = 0;(i) < ((int)(n));++(i))
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() )
#define test(a) cout<<"line:"<<__LINE__<<"["<<(#a)<<": "<<(a)<<"]"<<endl

const int INF = 1e9+7;
const ll INFL = 9*1e18;

// const int dx[4] = { 1, 0, -1, 0 };
// const int dy[4] = { 0, 1, 0, -1 };

const int dx[8] = {1, 1, 0,-1,-1,-1, 0, 1};
const int dy[8] = {0, 1, 1, 1, 0,-1,-1,-1};

ll inline digit(ll num){int tmp = 0;while(num){tmp++;num/=10;}return tmp;} // 桁数
template<typename T>inline void print(T&& x){cout<<x<<endl;}// 改行付き出力
template<typename T>inline T SUM(vector<T> vec){return accumulate(all(vec),(T)0);} // vectorの中身を全部足す
template<typename T>inline T digitSum(T num){T sum = 0;while(num){sum+=num%10;num/=10;}return sum;} // 各桁の和
template<typename T>inline T gcd(T a,T b){if(b == 0)return a;return gcd(b,a%b);} // 最大公約数
template<typename T>inline T lcm(T a, T b){T g = gcd(a,b);return a/g*b;} // 最小公倍数
template<typename T>inline T power(T a,T b){T tmp=1;rep(i,b){tmp*=a;}return tmp;} // 累乗
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; }
int ctoi(char c){return c-'0';}


// TODO: write
int main() {
  int n;cin>>n;
  vector<int> a(n);rep(i,n)cin>>a[i];
  vector<int> dp(n);
  dp[0] = 0;

  rep(i,n-1){
    dp[i+1] = abs(a[i+1] - a[i]) + dp[i];
    if(i)chmin(dp[i+1],abs(a[i+1] - a[i-1])+dp[i-1]);
  }
  print(dp[n-1]);
  return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

int main() {
	int n;
	cin >> n;
	map<string, int> mp;
	rep(i, n) {
		string s;
		cin >> s;
		mp[s]++;
	}
	int mx = 0;
	for (auto p : mp) mx = max(mx, p.second);
	for (auto p : mp) {
		if (p.second != mx) continue;
		cout << p.first << endl;
	}
	return 0;
}


Measured memory_bytes: 25216
#include <iostream>
using namespace std;
void ABC140(void);
void ABC141(void);
void ABC142(void);
void ABC143(void);
void ABC144(void);
void ABC145(void);
void ABC146(void);
void ABC147(void);
void ABC148(void);
void ABC149(void);

int main(void){
    ABC149();
}

void ABC149(){
    string s,t;
    cin>>s>>t;
    cout<<t<<s<<endl;
}

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

typedef long long ll;

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18


int main() {
    int N; cin >> N;
    vector<string> W(N);
    REP(i,N){
        cin >> W[i];
    }

    FOR(i,1,N){
        if(W[i][0] != W[i-1][W[i-1].size()-1]){
            cout << "No" << endl;
            return 0;
        }
        REP(j,i){
            if(W[j] == W[i]){
                cout << "No" << endl;
                return 0;
            }
        }
    }
    cout << "Yes" << endl;
    return 0;
}

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

const int MOD = 1000000007;
const int INF = 999999999;

int main(){
    ll N, T;
    cin >> N >> T;
    vector<ll> t(N);
    rep(i, N){
        cin >> t[i];
    }
    int ans = 0;
    rep(i, N){
        if(i != N-1){
            if(t[i+1] - t[i] > T){
                ans += T;
            }else{
                ans += t[i+1] - t[i];
            }
        }else{
            ans += T;
        }
    }
    cout << ans << endl;
return 0;}
/**
 * g++ code.cpp
 * ./a.out
 * shift + ctrl + i
**/ 

Measured memory_bytes: 1792
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	int n;
	cin>>n;
	ll a[n],mins=1000000005;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ll j=0;
		while(a[i]%2==0){
			a[i]/=2;
			j++;
		}
		mins=min(mins,j);
	}
	cout<<mins;
	
}



Measured memory_bytes: 3532
a,b,c,d,e,f = map(int,input().split())
maxa = f//(100*a)

ans = [0,0,0]
for i in range(maxa+1): # iはAの回数
    for j in range((f-100*a*i)//b+1):
        v = 100*a*i + 100*b*j
        if f < v: break
        maxs = min(v*e//100,f-v)
        for k in range(maxs//d+1):
            l = (maxs-d*k)//c
            s = c*l + d*k
            if v+s > f: continue
            if v/100*e < s: continue
            if v+s == 0: continue
            if ans[0] <= 100*s/(v+s):
                ans = [100*s/(v+s),v+s,s]
print(*ans[1:])

Measured memory_bytes: 3064
Scanf.scanf "%d" (fun n ->
    let rec loop i acc =
        if i = n then acc else
            let acc = Scanf.scanf " %f %s" (fun x u ->
                if u = "JPY" then acc +. x else acc +. x *. 380000.
            )
            in
            loop (i + 1) acc
    in
    loop 0 0. |> Printf.printf "%f\n"
)

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

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

Measured memory_bytes: 512
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N, K = inm()
A = inl()
B = [(abs(a), a < 0) for a in A]
B.sort(reverse=True)

MOD = 10 ** 9 + 7


def solve():
    fs = []
    negmin = posrep = None
    posmin = negrep = None
    negcnt = 0
    for i in range(N):
        v, neg = B[i]
        if len(fs) < K:
            fs.append(v)
            if neg:
                negcnt += 1
                negmin = v
            else:
                posmin = v
        elif neg and negrep is None:
            negrep = v
        elif not neg and posrep is None:
            posrep = v
    if negcnt % 2 == 0:
        a0 = 1
        for x in fs:
            a0 = (a0 * x) % MOD
        return a0

    a1 = a2 = None
    if negmin is not None and posrep is not None:
        a1 = 1
        replaced = False
        for x in fs:
            if x == negmin and not replaced:
                a1 = (a1 * posrep) % MOD
                replaced = True
            else:
                a1 = (a1 * x) % MOD
    if posmin is not None and negrep is not None:
        a2 = 1
        replaced = False
        for x in fs:
            if x == posmin and not replaced:
                a2 = (a2 * negrep) % MOD
                replaced = True
            else:
                a2 = (a2 * x) % MOD

    if a1 is None and a2 is None:
        a3 = 1
        sign = 1
        for x, neg in B[N - K :]:
            a3 = (a3 * x) % MOD
            if neg:
                sign *= -1
        return (MOD + sign * a3) % MOD

    if a1 is None:
        return a2
    if a2 is None:
        return a1

    if posrep * posmin < negrep * negmin:
        return a2
    else:
        return a1


print(solve())


Measured memory_bytes: 39636
import numpy as np

n = int(input())
a = np.array([int(x) for x in input().split()])
mod = 10**9+7
mod_sum = 0
a_sum = sum(a)
for i in range(n-1):
    a_sum -= a[i]
    mod_sum += (a[i] % mod) * (a_sum % mod) % mod

print(mod_sum%mod)

Measured memory_bytes: 49868
#include <stdio.h>
 
int  main(void){
         int h,w,i,j;
          while(1){
          scanf("%d %d",&h,&w);
           if( h==0 && w==0)
              break;
           for(i=1; i<=h; i++){
            for(j=1; j<=w; j++){
              if(i==1 || i==h || j==1 || j==w)
              printf("#");
             else
              printf(".");
             }printf("\n");
            }printf("\n");
           }
            return 0;
}


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

 int main()
 {
 int N;
 double ans = 0.0, A;
 cin >> N;
 for(int i = 1; i <= N; ++i){
 cin >> A;
 ans += 1.0 / A;
 }
 ans = 1.0 / ans;
 cout << setprecision(16) << ans << endl;
 }

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

int32_t main(){
	ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
////////////////////////////////

    string s,t;
    cin >> s >> t;

    int n = s.length();
    int m = t.length();

    int ans = m;
    //cout<<ans<<'\n';
    for (int i=0;i<=n-m;i++){
        int check = 0;
        int pt = i;
        for (int j=0;j<m;j++){
            if (s[pt]!=t[j])check++;
            pt++;
        }
      //  cout<<check<<'\n';
        ans = min(ans,check);

    }

    cout<<ans<<'\n';

}


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

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

        int ans = 0;

        for(int i = 0; i< 100;i++) {
                if(i >= a && i < b && i >= c && i < d){
                        ans++;
                }
        }
        cout << ans << endl;
}

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

typedef long long LL;
const int N = 1e5 + 5;

int a[3][N];
LL dp[3][N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i <= 2; i ++) {
    for (int j = 1; j <= n; j ++) scanf("%d", &a[i][j]);
    sort(a[i] + 1, a[i] + n + 1);
  }
  for (int i = 1, p; i <= n; i ++) {
    p = upper_bound(a[1] + 1, a[1] + n + 1, a[0][i]) - a[1];
    dp[1][p] ++;
  }
  for (int i = 1; i <= n; i ++) dp[1][i] += dp[1][i - 1];
  for (int i = 1, p; i <= n; i ++) {
    p = upper_bound(a[2] + 1, a[2] + n + 1, a[1][i]) - a[2];
    dp[2][p] += dp[1][i];
  }
  LL ans = 0;
  for (int i = 1; i <= n; i ++) {
    dp[2][i] += dp[2][i - 1];
    ans += dp[2][i];
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 2944
#include"bits/stdc++.h"
using namespace std;

void Main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.length(); i++) {
    cout << 'x';
  }
  cout << endl;
}

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


Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))

check = 0

if n == 1:
	print('Yes')

else:
	for i in range(n-2):
		if h[i] < h[i+1]:
			h[i+1] -= 1
	for i in range(n-1):
		if h[i] > h[i+1]:
			print('No')
			break
		if h[i] <= h[i+1]:
			check += 1
	if check == n-1:
		print('Yes')

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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;

    int ans = 0;

    //0 ~ n-1
    for(int i=0; i<n-1; i++) {
        if( s[i] == 'A' && s[i+1] == 'B' && s[i+2] == 'C' ) ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3596
n, t = map(int, input().split())
e = [[int(i) for i in input().split()] for i in range(n)] 

min = float("inf")
cost = 5000
for i,v in enumerate(e):
    if v[1] <= t:
        if v[0] <= cost:
            min = v[1]
            cost = v[0]
            


if min == float("inf"):
    print("TLE")
else :
    print(cost)



Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <vector>
#include <algorithm>
#include <set>
#include <stack>
#include <deque>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < n; i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

int main() {
    int n;
    cin >> n;
    vector<int> l(2*n);
    rep(i, 2*n) cin >> l[i];
    sort(l.begin(), l.end());
    ll ans = 0;
    rep(i, 2*n) {
        if (i % 2 == 0) ans += l[i];
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
a = []
for i in range(1,14):
    s = 'S {}'.format(i)
    a.append(s)

for i in range(1,14):
    h = 'H {}'.format(i)
    a.append(h)

for i in range(1,14):
    c = 'C {}'.format(i)
    a.append(c)
    
for i in range(1,14):
    d = 'D {}'.format(i)
    a.append(d)

#print(a)
k = []
amount = int(input())
for e in range(amount):
    taiga = input()
    k.append(taiga)
#print(k)
     
for i in a:
    if i not in k:
        print(i)




Measured memory_bytes: 5592
/* You can't hack me! */
#pragma warning(disable : 4996)
#include"bits/stdc++.h"
using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vch;
typedef set<ll> sll;
#define fo(i,n) for(ll i=0; i<(n); i++)
#define FO(i,a,b) for(auto i=a; i!=(b); i+=(b)>(a)?1:-1)
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(c) c.begin(), c.end()
#define sc scanf
#define pr printf
#define in(x) sc("%lld", &(x))
#define id(x) sc("%Lf", &(x))
#define os(x) pr("%lld ", x)
#define on(x) pr("%lld\n", x)
#define nl pr("\n")
const ll P=998244353;
const ll N=200010;

int main()
{
    /*ios::sync_with_stdio(false);
    cin.tie(0);*/
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ll t=1;
    //cin>>(t);
    while(t--)
    {
        ll a, b, n;
        in(a); in(b); in(n);
        ll ans=0;
        if(n<b) ans=floor(a*n/b);
        else ans=floor(a*(b-1)/b);
        on(ans);
    }
    cerr << "Time : " << ((double)clock()) / (double)CLOCKS_PER_SEC << "s\n";
    return 0;
}

Measured memory_bytes: 3832
#	!/usr/bin/env python3
#	encoding: UTF-8
#	Modified: <26/May/2019 07:02:39 PM>


#	✪ H4WK3yE乡
#	Mohd. Farhan Tahir
#	Indian Institute Of Information Technology (IIIT), Gwalior


import sys


def get_array(): return list(map(int, sys.stdin.readline().split()))


def get_ints(): return map(int, sys.stdin.readline().split())


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


def binary(n):
    global length
    op = []
    bit = 1 << length - 1
    while (bit):
        if n & bit == 0:
            op.append(0)
        else:
            op.append(1)
        bit >>= 1
    return op


def main():
    global length
    length, m = get_ints()
    d = {}
    for i in range(m):
        tmp = get_array()
        d[i] = tmp[1:]
    p = get_array()
    ans = 0
    x = 1 << length
    combinations = []
    for i in range(x):
        combinations.append(binary(i))

    for i in combinations:
        flag = True
        for j in range(m):
            cnt = 0
            for k in d[j]:
                if i[k - 1] == 1:
                    cnt += 1
            if cnt % 2 != p[j]:
                flag = False
                break
        if flag == True:
            ans += 1
    print(ans)


if __name__ == "__main__":
    main()


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

using namespace std;
typedef long long  ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)

int main() {
	int N; cin >> N;
	ll a = 0, b = 2, c = 1;

	if (N == 1) {
		cout << 1 << endl; return 0;
	}
	else {
		rep(i, 2, N + 1) {
			a = b;
			b = c;
			c = a + b;
		}
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

cnt = 0
flag = 1
while flag:
    flag = 0
    for j in range(n-1, 0, -1):
        if a[j] < a[j-1]:
            a[j], a[j-1] = a[j-1], a[j]
            cnt += 1
            flag = 1

print(' '.join(map(str, a)))
print(cnt)



Measured memory_bytes: 5600
import math

N = int(input())
v1 = [int(i) for i in input().strip().split()]
v2 = [int(i) for i in input().strip().split()]

# Manhattan distance
m1 = 0
for i in range(N):
    m1 += abs(v1[i] - v2[i])

print(float(m1))

# Euclidean distance
m2 = 0
for i in range(N):
    m2 += (v1[i] - v2[i]) ** 2

m2 = math.sqrt(m2)

print(float(m2))

# ??
m3 = 0
for i in range(N):
    m3 += abs(v1[i] - v2[i]) ** 3

m3 = m3 ** (1 / 3)

print(float(m3))

# Chebyshev distance
m4 = 0
for i in range(N):
    m4 = max(abs(v1[i]-v2[i]), m4)

print(float(m4))


Measured memory_bytes: 5700
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
int main(){
    int n;
    cin>>n;
    vector<int>a(n),b(n);
    for(int i=0;i<n;i++){
        cin>>a.at(i);
        b.at(i)=a.at(i);
    }
    sort(b.begin(),b.end());
    int c=b.at(n/2-1);
    for(int i=0;i<n;i++){
        if(a.at(i)<=c)cout<<b.at(n/2)<<endl;
        else cout<<c<<endl;
    }
}

Measured memory_bytes: 3712
#include <iostream>
#include <cmath>
#define N 1000000

bool m[N];

void init_array() {
    int n = N-1;
    int idx = 2;
    std::fill(m, m+N, true);
    while (idx <= sqrt(n)) {
        int next_itr = -1;
        for (int i=idx+1; i<=n; i++) {
            if (m[i]) {
                if (i % idx == 0) {
                    m[i] = false;
                } else if (next_itr == -1) {
                    next_itr = i;
                }
            }
        }
        idx = next_itr;
    }
}

int main(void) {
    int n;
    int res;
    init_array();
    while( std::cin >> n ) {
        int idx = 2;
        int res=0;

        for (int i=2; i<=n; i++) {
            if (m[i]) res++;
        }

        std::cout << res << std::endl;
    }

    return 0;
}



Measured memory_bytes: 4036
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <memory.h>
#include <math.h>
#include <assert.h>
#include <queue>
#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <iostream>
#include <functional>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <bitset>

using namespace std;
typedef pair<int, int> Pi;
typedef long long ll;
#define pii Pi
#define pll PL
#define Fi first
#define Se second
#define pb(x) push_back(x)
#define sz(x) ((int)(x).size())
#define rep(i, n) for(int i=0;i<n;i++)
#define all(x) (x).begin(), (x).end()
typedef tuple<int, int, int> t3;
typedef pair<ll, ll> PL;
typedef long double ldouble;

int A[500050];
char S[500050];

ll T[20];

void solve(){
	T[1] = 1;
	for(int i=2;i<20;i++)T[i] = 10 * T[i-1] + 1;
	scanf("%s", S+1);
	int n = (int)strlen(S+1);
	reverse(S+1, S+1+n);
	for(int i=n;i;i--){
		int c = S[i] - '0';
		A[i] += c;
		if(i != 1)A[i-1] -= c;
	}
	for(int i=1;i<=n;i++){
		while(A[i] < 0){
			A[i] += 10;
			A[1] += 1;
			A[i+1] -= 1;
		}
	}
	A[2] += A[1] / 11, A[1] %= 11;
	ll t = A[1];
	for(int i=2;i<=n;i++){
		while(1){
			if(A[i] > 10 || (A[i] == 10 && t > 0)){
				A[i] -= 10;
				A[1] -= 1;
				--t;
				A[i+1] += 1;
			}
			else break;
		}
		if(A[i]){
			if(i < 8)t += A[i] * T[i];
			else t = 1e9;
		}
	}
	if(A[1] < 0){
		ll t = 0;
		for(int i=2;i<=9;i++){
			t += A[i] * T[i];
			if(t+A[1] >= 0){ t += A[1];
				for(int j=1;j<=i;j++)A[j] = 0;
				for(int j=i;j;j--){
					while(t >= T[j])t -= T[j], A[j]++;
				}
				break;
			}
		}
	}
	int ans = 0;
	for(int i=1;i<=n;i++)ans += A[i];
//	for(int i=n;i;i--)printf("%d ", A[i]); puts("");
	printf("%d\n", (ans + 8) / 9);
}

int main(){
	int Tc = 1; // scanf("%d", &Tc);
	for(int tc=1;tc<=Tc;tc++){
		//printf("Case #%d: ", tc);
		solve();
	}
	return 0;
}


Measured memory_bytes: 2688
n = int(input())

def num_divisors_table(n):
    table = [0] * (n + 1)
    
    for i in range(1, n + 1):
        for j in range(i, n + 1, i):
            table[j] += 1
    
    return table

div = num_divisors_table(n)

res = 0
for c in range(1, n):
    num = n - c
    res += div[num]

print(res)



Measured memory_bytes: 75776
import sys
sys.setrecursionlimit(10 ** 9)

from collections import Counter

class UnionFind:
    def __init__(self, N):
        self.root = [n for n in range(N)]

    def get_root(self, x):
        if self.root[x] == x:
            return x
        else:
            self.root[x] = self.get_root(self.root[x])
            return self.root[x]

    def unite(self, x, y):
        root_x = self.get_root(x)
        root_y = self.get_root(y)
        if root_x != root_y:
            self.root[root_x] = root_y


    def final(self):
        for i in range(N):
            root_r = self.get_root(self.root[i])
            if root_r != self.root[i]:
                self.root[self.root[i]] = root_r

def main(N, M, AB):
    uf = UnionFind(N)
    {uf.unite(*ab) for ab in AB}
    c = Counter(map(uf.get_root, uf.root))
    print(len(c) - 1)

if __name__ == '__main__':
    N, M = list(map(int, input().split()))
    AB = {tuple(map(lambda x:int(x)-1, input().split())) for m in range(M)}
    main(N, M, AB)

Measured memory_bytes: 31136
n = int(input())
tree = [None] * n
root = set(range(n))


def set_pd(i, parent, sibling, depth):
    if i == -1:
        return -1
    node = tree[i]
    l, r = node[0], node[1]
    node[2], node[3], node[5] = parent, sibling, depth
    node[4] = (l != -1) + (r != -1)
    height = node[6] = max(set_pd(l, i, r, depth + 1), set_pd(r, i, l, depth + 1)) + 1
    return height


while n:
    i, l, r = list(map(int, input().split()))
    tree[i] = [l, r] + [None] * 5  # parent, sibling, degree, depth, height
    root -= {l, r}
    n -= 1

set_pd(root.pop(), -1, -1, 0)

for i, node in enumerate(tree):
    l, r, p, s, deg, dep, h = node
    print('node {}: parent = {}, sibling = {}, degree = {}, depth = {}, height = {}, {}'.format(
        i, p, s, deg, dep, h, 'root' if not dep else 'internal node' if deg else 'leaf'
    ))

Measured memory_bytes: 7812
class Node:
    def __init__(self, point):
        self.n = point
        self.left = None
        self.right = None


def Pre(t, l):
    l.append(str(t.n))
    if t.left != None:
        Pre(t.left, l)
    if t.right != None:
        Pre(t.right, l)


def In(t, l):
    if t.left != None:
        In(t.left, l)
    l.append(str(t.n))
    if t.right != None:
        In(t.right, l)


def insert(t, z):
    y = None
    x = t
    while x != None:
        y = x
        if z.n < x.n:
            x = x.left
        else:
            x = x.right
    if y == None:
        return z
    else:
        if z.n < y.n:
            y.left = z
        else:
            y.right = z
        return t


def Find(t, p):
    if t.n == p:
        return True
    elif t.left != None and t.n > p:
        a = Find(t.left, p)
    elif t.right != None and t.n < p:
        a = Find(t.right, p)
    else:
        return False
    return a


def BST2(A, n):
    tree = None
    for i in range(n):
        if A[i] == "print":
            PreAns = []
            InAns = []
            Pre(tree, PreAns)
            In(tree, InAns)
            print(" "+" ".join(InAns))
            print(" "+" ".join(PreAns))
        else:
            if A[i].split(" ")[0] == "find":
                c = "no"
                point = int(A[i].split(" ")[1])
                if Find(tree, point) == True:
                    print("yes")
                else:
                    print("no")

            else:
                z = Node(int(A[i].split(" ")[1]))
                tree = insert(tree, z)


if __name__ == "__main__":
    n = int(input())
    A = []
    for i in range(n):
        A.append(input())
    BST2(A, n)



Measured memory_bytes: 184404
da = list(map(int,input().split()))
ta = list(map(int,input().split()))

l1 = 0
l2 = 0

for i in range(da[2]):
  for j in range(da[1]):
    if i == ta[j]:
      l1 += 1
      
for i in range(da[0] - da[2]):
  for j in range(da[1]):
    if i + da[2] == ta[j]:
      l2 += 1
      
print(min(l1,l2))

Measured memory_bytes: 39664
#include <iostream>
using namespace std;
int gcd(int a, int b)
{
    if(a < b) {
        int k = a;
        a = b;
        b = k;
    }
    if(b == 0) return a;
    return gcd(b, a%b);
}
int main()
{
    int k, s = 0, g;
    cin >> k;
    for(int a = 1; a <= k; a++) {
        for(int b = 1; b <= k; b++) {
            g = gcd(a, b);
            for(int c = 1; c <= k; c++) {
                s += gcd(g, c);
            }
        }
    }
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#pragma region Macros
#define ios\
    ios::sync_with_stdio(false);\
    cin.tie(nullptr);
#define VEC(type, name, size)\
    V<type> name(size);\
    IN(name)
#define VVEC(type, name, h, w)\
    VV<type> name(h, V<type>(w));\
    IN(name)
#define INT(...)\
    int __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LL(...)\
    ll __VA_ARGS__;\
    IN(__VA_ARGS__)
#define STR(...)\
    string __VA_ARGS__;\
    IN(__VA_ARGS__)
#define CHAR(...)\
    char __VA_ARGS__;\
    IN(__VA_ARGS__)
#define DOUBLE(...)\
    DOUBLE __VA_ARGS__;\
    IN(__VA_ARGS__)
#define LD(...)\
    LD __VA_ARGS__;\
    IN(__VA_ARGS__)
int scan() { return getchar(); }
template <class T> void scan(T a) { cin >> a; }
void scan(int &a) { cin >> a; }
template <class T> void scan(vector<T> &);
template <class T, class L> void scan(pair<T, L> &);
template <class T> void scan(vector<T> &a) { for(auto &i : a) scan(i); }
template <class T, class L> void scan(pair<T, L> &p) { scan(p.first); scan(p.second);}
template <class T> void scan(T &a) { cin >> a; }
void IN() {}
template <class Head, class... Tail> void IN(Head &head, Tail &... tail) { scan(head); IN(tail...); }
template <class T> inline void print(T x){ cout << x << '\n';}
#define ll long long
#define ld long double
#define FOR(i,l,r) for(ll i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define RFOR(i,l,r) for(ll i=(l);i>=(r);--i)
#define RREP(i,n) RFOR(i,n-1,0)
#define RREPS(i,n) RFOR(i,n,1)
#define pb push_back
#define eb emplace_back
#define SZ(x) ((ll)(x).size())
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
template<class T = ll> using V = vector<T>;
template<class T = ll> using VV = V<V<T>>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return true; }return false; }
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return true; }return false; }
inline void Yes(bool b = true) {cout << (b ? "Yes" : "No") << '\n';}
inline void YES(bool b = true) {cout << (b ? "YES" : "NO") << '\n';}
inline void err(bool b = true) {if(b) {cout << -1 << '\n'; exit(0);}}
template<class T> inline void fin(bool b = true, T e = 0) {if(b) {cout << e << '\n'; exit(0);}}
template<class T> T Roundup_div(T x, T y) {return (x+(y-1))/y;}
template <typename T> T pow(T a, long long n, T e = 1) {T ret = e; while (n) {if (n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
const ll INF = 1e18;
#pragma endregion

using P = pair<int, int>;
ll cnt;

int main(){
    ios;
    INT(h, w, n);
    VEC(P, a, n);
    sort(all(a));
    REP(i, n){
        fin(a[i].first > a[i].second + cnt, a[i].first - 1);
        if(a[i].first == a[i].second + cnt) cnt++;
    }
    print(h);
}

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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    int g1 = 0, g2 = 0, g3 = 0;
    for (int i = 0; i < n; i++) {
        int p;
        cin >> p;
        if (p <= a) g1++;
        else if (p <= b) g2++;
        else g3++;
    }
    cout << min({g1, g2, g3}) << endl;
}

Measured memory_bytes: 256
A, B, K = map(int, input().split())
if B-A+1 >= 2*K:
    res_list = [i for i in range(A, A+K)] + [i for i in range(B-K+1, B+1)]
else:
    res_list = [i for i in range(A, B+1)]
for i in res_list:
    print(i)


Measured memory_bytes: 3060
// Try Hitachi Hokudai Labo & Hokkaido University Contest 2019-1
// author: Leonardone @ NEETSDKASU

fn main() {
    let io = StandardIO::new();
    let mut io = io.get_io();

    let (_, e): (usize, usize) = io.get2();

    for _ in 0..e {
        io.get_line();
    }

    let freqs = io.get_vec::<usize>();

    let t_max = if freqs[0] != 0 {
        freqs[0]
    } else {
        io.get()
    };

    if freqs[0] != 0 {
        for _ in 0..t_max {
            let n_new = io.get();
            for _ in 0..n_new {
                io.get_line();
            }
        }
        for _ in 0..t_max {
            io.println(-1);
        }
    } else {
        for _ in 0..t_max {
            let n_new = io.get();
            for _ in 0..n_new {
                io.get_line();
            }

            let n_put = io.get();
            for _ in 0..n_put {
                io.get_line();
            }

            io.println(-1);

            if io.gets() != "OK" {
                break;
            }

            let n_ach = io.get();
            for _ in 0..n_ach {
                io.get_line();
            }
        }
    }
}

struct StandardIO {
    stdin: std::io::Stdin,
    stdout: std::io::Stdout,
}

struct IO<'a> {
    stdin: std::io::StdinLock<'a>,
    stdout: std::io::StdoutLock<'a>,
}

impl StandardIO {
    fn new() -> Self {
        StandardIO {
            stdin: std::io::stdin(),
            stdout: std::io::stdout()
        }
    }
    fn get_io(&self) -> IO {
        IO {
            stdin: self.stdin.lock(),
            stdout: self.stdout.lock()
        }
    }
}

impl<'a> IO<'a> {
    fn get_line(&mut self) -> String {
        let mut line = String::new();
        std::io::BufRead::read_line(&mut self.stdin, &mut line).unwrap();
        line
    }
    fn gets(&mut self) -> String {
        self.get_line().trim().to_string()
    }
    fn get<A>(&mut self) -> A
        where
            A: std::str::FromStr,
            <A as std::str::FromStr>::Err: std::fmt::Debug {
        self.get_line().trim().parse().unwrap()
    }
    fn get2<A,B>(&mut self) -> (A,B)
        where
            A: std::str::FromStr,
            B: std::str::FromStr,
            <A as std::str::FromStr>::Err: std::fmt::Debug,
            <B as std::str::FromStr>::Err: std::fmt::Debug {
        let line = self.get_line();
        let mut tokens = line.split_whitespace();
        let a: A = tokens.next().unwrap().parse().unwrap();
        let b: B = tokens.next().unwrap().parse().unwrap();
        (a, b)
    }
    fn get_vec<A>(&mut self) -> Vec<A>
        where
            A: std::str::FromStr,
            <A as std::str::FromStr>::Err: std::fmt::Debug {
        self
            .get_line()
            .split_whitespace()
            .map(|v| v.parse().unwrap())
            .collect()
    }
    fn println(&mut self, v: i32) {
        use std::io::Write;
        writeln!(&mut self.stdout, "{}", v).unwrap();
        self.stdout.flush().unwrap();
    }
}

Measured memory_bytes: 4352
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <climits>
#include <algorithm>
#include <map>
#include <set>
#include <stack>
#include <vector>
#include <queue>
#include <bitset>
#include <string>
using namespace std;

#define REP(i,n) for(int i=0; i<n; i++)
#define RPA(i,s,e) for(int i=s; i<=e; i++)
#define RPD(i,s,e) for(int i=s; i>=e; i--)
#define PB(a) push_back(a)
#define MP(i,s) make_pair(i,s)
#define SZ(a) (int)(a).size()
#define ALL(a) (a).begin(), (a).end()
#define PRT(a) cout << (a) << endl
#define PRT2(a,b) cout << (a) << " " << (b) << endl
#define PRT3(a,b,c) cout << (a) << " " << (b) << " " << (c) << endl

typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> P;

int n,m,a;
int h,p,q;

vector<P> table[101];

void coding() {
	while(scanf("%d%d%d", &n, &m, &a)!=EOF) {
		if((n | m | a) == 0) break;
		REP(i,n) table[i].clear();

		int maxH = 0;
		REP(i,m) {
			scanf("%d%d%d", &h, &p, &q);
			p--; q--;
			table[p].push_back(P(h, q));
			table[q].push_back(P(h, p));
			maxH = max(maxH, h);
		}

		REP(i,n) sort(ALL(table[i]), greater<P>());

		int ch = maxH + 1;
		int cb = a - 1;
		for(;;) {
			int k = 0;
			while(k < table[cb].size() && ch <= table[cb][k].first) k++;
			if(k == table[cb].size()) break;
			ch = table[cb][k].first;
			cb = table[cb][k].second;
		}
		printf("%d\n", cb+1);

	}
}

// #define _LOCAL_TEST

int main() {
#ifdef _LOCAL_TEST
	clock_t startTime = clock();
	freopen("a.in", "r", stdin);
#endif

	coding();

#ifdef _LOCAL_TEST
	clock_t elapsedTime = clock() - startTime;
	cout << endl;
	cout << (elapsedTime / 1000.0) << " sec elapsed." << endl;
	cout << "This is local test" << endl;
	cout << "Do not forget to comment out _LOCAL_TEST" << endl << endl;
#endif
}

Measured memory_bytes: 1264
#include <iostream>

using namespace std;

int even_count(int a) {
    int count = 0;

    while ((a % 2) == 0) {
        count++;
        a /= 2;
    }
    return count;
}

int main(void) {
    int N, count = 0, a, ec;

    cin >> N;

    for (int i = 0; i < N; i++) {
        cin >> a;
        ec = even_count(a);
        if (ec == 0) {
            break;
        }
        else if (count == 0 || ec < count) {
            count = ec;
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, k, n, p, a, cnt[2] = {0, 0}, ans, now = 0;
  scanf("%lld%lld", &n, &p);
  for(i = 0; i < n; ++i) scanf("%lld", &a), cnt[a & 1]++;
  ll cmb[cnt[1] + 1];
  cmb[0] = 1;
  for(i = 1; i <= cnt[1]; ++i) cmb[i] = cmb[i - 1] * (cnt[1] - i + 1) / i;
  printf("\n");
  ans = 1ll << cnt[0];
  for(i = p; i <= cnt[1]; i += 2) now += cmb[i];
  printf("%lld", ans * now);
  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

string mx = "";
void dfs(vector< pair<int,int> > &A, string s, int rest) {
    if(rest == 0) {
        if(s.size() > mx.size()) {
            mx = s;
        } else if(s.size() == mx.size()) {
            mx = max(mx, s);
        }
        return;
    } else if(rest < 0) {
        return;
    } else {
        for(auto a: A) {
            dfs(A, s+char('0' - a.second), rest-a.first);
        }
    }
}

int main(void) {
    vector<int> num = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    int N, M;
    cin >> N >> M;
    vector < pair<int,int> > A;
    for(int i=0; i<M; i++) {
        int a;
        cin >> a;
        A.emplace_back(num[a-1], -a);
    }

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

    int p = N / A.front().first;
    p = max(p-6, 0);
    int rest = N - p * A.front().first;
    string ans(p, '0' - A.front().second);
    dfs(A, "", rest);

    ans += mx;
    sort(ans.rbegin(), ans.rend());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e5+5,mod=1e9+7;
int n,a[N],sum[N];
vector<int>v[1300000];
int f(int l,int r){return sum[r]-sum[l-1];}
int main()
{
    scanf("%d",&n);
    for(int i=1;i<=n;i++)
        scanf("%d",&a[i]),a[i]^=a[i-1];
    for(int i=1;i<=n;i++)
    {
        sum[i]=sum[i-1]+(a[i]==0);
        v[a[i]].push_back(i);
    }
    ll ans=0;
    for(int i=0;i<1<<20;i++)
    {
        if(!v[i].size()) continue;
        if(a[n]!=0&&a[n]!=i) continue;
        ll res=1,dp0=1,sumres=1;
        for(int j=1;j<v[i].size();j++)
        {
            if(i==0) dp0=res+1,res=(res+dp0)%mod;
            else
            {
                dp0=(dp0+sumres*f(v[i][j-1],v[i][j]))%mod;
                res=dp0;
                sumres=(sumres+res)%mod;
            }
        }
        if(a[n]==0&&i==0) ans=(ans+dp0)%mod;
        else if(a[n]==0) ans=(ans+sumres)%mod;
        else ans=(ans+res)%mod;
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 44276
import java.io.IOException;
import java.io.InputStream;
import java.util.Scanner;

class Main
{
	public static void main(String[] args) throws Exception
	{
		invoke(System.in);
	}

	public static void	invoke(InputStream is) throws IOException
	{
		try (Scanner in = new Scanner(is))
		{
			int	n = in.nextInt();
			int	y = in.nextInt();

			for (int a = n; a >= 0; --a)
			{
				for (int b = n - a; b >= 0; --b)
				{
					int c = n - a - b;
					int	total = (10000 * a + 5000 * b + 1000 * c);
					if (total == y)
					{
						System.out.println(a + " " + b + " " + c);
						return;
					}
				}
			}
			System.out.println("-1 -1 -1");
		}
	}
}

Measured memory_bytes: 23636
#include <stdio.h>
 
int x[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
 
int main(){
  int a;
  scanf("%d",&a);
  printf("%d",x[a-1]);
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s,t;
  cin >> s >> t ;
  int a=s.size();
  int b=t.size();
  int x=0;
  for (int i=0; i<a-b+1 ; i++)
  {
    int y=0;
    for (int j=0; j<b ; j++)
    {
    if(t[j]==s[i+j])
     {
      y++;
     }
    }
    x=max(x,y);
    
  }
  cout << b-x <<endl;
}

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

int main() {
	int N, K;
	cin >> N >> K;
	int x = 1;
	for (;N > 0 && x < K;N --) x += x; // ちなみにx << 1が最速 こっちは操作A
	cout << x + K * N; // 後は残った回数の操作B
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり

今電光掲示板に整数xが表示されているものとする
その時、操作Aと操作Bでは、より値が小さくなる操作を行うべきである
つまり、操作Aでは操作後に2xになり、操作Bでは操作後にx+Kになるので、
x<=Kなら操作Aを、x>Kなら操作Bを行うべきである
また、xは単調増加で、Kは不変であることから、一度操作Bを行ったなら後は全部操作B

以上を用いると、いつx>Kになるか分かれば操作Bに切り替えるタイミングが分かる
これは操作Aを[logK]+1回行えば良いのだが、まぁlog使うまでもないのでfor文で求めてしまおうか
*/

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

typedef complex<double> Point;

const double EPS = 1e-8;

//ãã¯ãã«a, bã®åç©
double dot(Point a, Point b)
{
    return (a.real() * b.real() + a.imag() * b.imag());
}

//ãã¯ãã«a, bã®å¤ç©
double cross(Point a, Point b)
{
    return (a.real() * b.imag() - a.imag() * b.real());
}

//ç¹a, bãç«¯ç¹ã¨ããç·åã¨ç¹cã¨ã®è·é¢
double dist_ls_p(Point a, Point b, Point c)
{
    if (dot(b - a, c - a) < EPS) return abs(c - a);
    if (dot(a - b, c - b) < EPS) return abs(c - b);
    return abs(cross(b - a, c - a)) / abs(b - a);
}

double wx[100], wy[100], wr[100];

int main()
{
    int m, n;
    while (cin >> n && n) {
        for (int i = 0; i < n; i++) {
            cin >> wx[i] >> wy[i] >> wr[i];
        }
        
        cin >> m;
        for (int i = 0; i < m; i++) {
            double x, y, tx, ty, sx, sy, r, d1, d2, d3;
            bool safe = false;
            cin >> tx >> ty >> sx >> sy;
            for (int j = 0; j < n; j++) {
                x = wx[j]; y = wy[j]; r = wr[j];
                d1 = hypot(x - sx, y - sy);
                d2 = hypot(x - tx, y - ty);
                d3 = dist_ls_p(Point(sx, sy), Point(tx, ty), Point(x, y));
                
                if ((d1 - EPS < r && r - EPS < d2) || (d2 - EPS < r && r - EPS < d1)) {
                    safe = true;
                }
                
                if (d3 - EPS < r && (d1 > r - EPS && d2 > r - EPS)) {
                    safe = true;
                }
                
            }
            
            if (safe) {
                cout << "Safe" << endl;
            } else {
                cout << "Danger" << endl;
            }
        }
    }
}

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

using namespace std;
using ll = long long;

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

  int a, b, h, m;
  cin >> a >> b >> h >> m;

  double pi = acos(-1);

  // 時針の角度
  double rad1 = 2.0 * pi * (h / 12.0) + (pi / 6.0) * (m / 60.0);
  // 分針の角度
  double rad2 = 2.0 * pi * m / 60.0;

  double px1 = a * cos(rad1);
  double py1 = a * sin(rad1);
  double px2 = b * cos(rad2);
  double py2 = b * sin(rad2);

  cout << fixed << setprecision(10)
       << sqrt(pow(px1 - px2, 2) + pow((py1 - py2), 2)) << endl;

  return 0;
}


Measured memory_bytes: 4112
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

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

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

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

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll n,d; cin >> n >> d; ll cnt = 0;
  vvl table(n,vl(d));
  
  rep(i,n){
    rep(j,d){
      cin >> table[i][j];
    }
  }
  
  for(ll i=0; i < n; i++){
    for(ll j=0; j < n; j++){
      if(i < j){
        ll dis = 0;
        
        rep(k,d){
          dis += (table[i][k] - table[j][k])*(table[i][k] - table[j][k]);
        }
        
        for(ll i=1; i < 200; i++){
          if(i*i == dis) cnt++;
        }
      }
    }
  }
  
  cout << cnt << endl;
  
  
}

Measured memory_bytes: 3560
#include <iostream>
#include <algorithm>
#include <numeric>
#include <vector>
#include <list>
#include <queue>
#include <string>
#include <map>
using namespace std;
#define REP(i, a, n) for (int i = ((int)a); i < ((int)n); i++)
#define lli long long int

#define MAX 100000000
//#define DEBUG

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};

int main()
{
#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
#else
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
#endif
    int n;
    cin>>n;
    int max=0;
    int ans=0;
    int h;
    for(int i = 0; i < n; i++)
    {
        cin>>h;
        if(h>=max){
            max=h;
            ans++;
        }
    }
    cout<<ans<<endl;
    return 0;
}
/* 注意すべき点
グローバル以外の配列は初期化すべし
*/

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

int main(void) {
    int n;cin>>n;
    int p[n];
    for (int i = 0; i < n; i++) cin >> p[i];
    int result = 0;
    for (int i = 1; i < n - 1; i++) {
        if ((p[i - 1] < p[i] && p[i] < p[i + 1]) || (p[i - 1] > p[i] && p[i] > p[i + 1])) result++;
    }
    cout << result << endl;
    return 0;
}

Measured memory_bytes: 256
class Solver(object):
    def __init__(self):
        self.n = int(input())

    def solve(self):
        digit_sum = sum((int(x) for x in str(self.n)))
        if self.n % digit_sum == 0:
            print("Yes")
        else:
            print("No")


if __name__ == "__main__":
    s = Solver()
    s.solve()

Measured memory_bytes: 3060
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
#define SIZE 300005
#define MOD 998244353LL
#define EPS 1e-10
#define INF 2147483647
#define LLINF 9223372036854775807
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define DOWN(i,b,a) for(int i=b;i>=a;i--)
#define SET(a,c) memset(a,c,sizeof a)
#define BIT(i,j) ((i)>>(j))&1
#define ALL(o) (o).begin(), (o).end()
#define ERASE(o) (o).erase(unique((o).begin(),(o).end()), (o).end())
#define SQ(x) ((x)*(x))
using namespace std;
typedef int_fast64_t ll;
typedef pair<ll,ll> Pll;
typedef pair<int, int> Pii;
typedef pair<double, double> Pdd;
typedef complex<double> dcomplex;
template<typename T> inline void priv(vector<T>a){REP(i,a.size()){cerr<<a[i]<<((i==a.size()-1)?"\n":" ");}}
inline void fastio(){cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15);}
ll gcd(ll a,ll b){ll c=max(a,b);ll d=min(a,b);return c==0||d==0?c:gcd(c%d,d);}
ll lcm(ll a,ll b){return a==0||b==0?0:a*b/gcd(a,b);}

template<int N, typename T, T M>
struct ModFact {
    T fact[N+1];
    T ifact[N+1];
    constexpr ModFact() : fact(), ifact() {
        fact[0] = 1;
        for (int i=0; i<N; ++i)
            fact[i+1] = (fact[i]*(i+1))%M;
        ifact[N] = power(fact[N], M-2);
        for (int i=N-1; i >= 0; --i)
            ifact[i] = (ifact[i+1]*(i+1))%M;
    }
    constexpr T power(T a, T b) {
        T r = 1;
        while (b>0) {
            if((b&1)!=0) r = (r*a)%M;
            a = (a*a)%M;
            b >>= 1;
        }
        return r;
    }
    constexpr T comb(T n, T r) {
        if (n<r||n<0||r<0) return 0;
        return (((fact[n]*ifact[r])%M)*ifact[n-r])%M;
    }
};
 
ModFact<300000, ll, MOD> fact;

int main() {
    fastio();
    ll N, A, B, K, ans = 0;
	cin >> N >> A >> B >> K;
//  	ll i=0, j;
// 	for(i=0; i<=N; i++) {
// 	    j = K-A*i;
//         if(j < 0) break;
// 		if(j%B) continue;
//     	ans = (ans+(fact.comb(N,i)*fact.comb(N,j/B)%MOD))%MOD;
// 	}
    ll g = gcd(A, B);
    if(K%g==0) {
        ll ca=B/g, cb=A/g;
        size_t i=0, j;
        while((K-A*i)%B && i<=N) i++;
        j = (K-A*i)/B;
        while(i <= N && j >= 0) {
            ans = (ans+(fact.comb(N,i)*fact.comb(N,j)%MOD))%MOD;
            i += ca; j -= cb;
        }
    }
    cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n,i,x,y,z,b,f,r,v;
	    int[][][] count = new int[5][4][11];
		
		Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        for(i = 0;i < n;i++){
            b = sc.nextInt();
            f = sc.nextInt();
            r = sc.nextInt();
            v = sc.nextInt();
            count[b][f][r] += v;
        }
        for(x = 1;x <= 4;x++){
            for(y = 1;y < 4;y++){
                for(z = 1;z < 11;z++){
                    System.out.print(" " + count[x][y][z]);
                }
                System.out.println();
            }
            if(x < 4){
                System.out.println("####################");
            }
        }
	}

}

Measured memory_bytes: 20692
#include <stdio.h>
int ruizyou(int n,int y){
	int i,sum=1;
	for(i=1;i<=y;i++){
		sum*=n;}
		return sum;}
int main(void)
{int i,N,j,k,l,sum;
	scanf("%d",&N);
	i=0;
	do{i+=1;
	sum=ruizyou(2,i);
		}while(N>=sum);
		printf("%d",sum/2);
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef pair<string,string> Pstring;
typedef pair<double,double> Pdouble;


#define REP(i,n) for(ll i=0;i<n;i++)
#define REP1(i,n) for(ll i=1;i<=n;i++)
#define Precision13 cout << fixed << setprecision(13)
const double PI=3.14159265358979323846;
const int MAX = 510000;
const int MOD = 1000000007;
const int INF = 1<<29;
using Graph = vector<vector<int>>;


int main()
{
  ll n;
  cin >> n;
  vector<ll> a(n);
  REP(i,n) cin >> a[i];
  ll ans=0;
  map<int,int> mp;
  REP(i,n){
    mp[i+a[i]]++;
    ans += mp[i-a[i]];
  }
  cout << ans << endl;

}

Measured memory_bytes: 21920
#include<iostream>
#include<stack>
#include<string>
#include<string.h>
using namespace std;
stack<int>S1;
char opt[3] = { '+','-','*' };
bool isOpt(char a) {
	for (int i = 0; i<3; i++) {
		if (a == opt[i])
			return true;
	}
	return false;
}
int main() {
	string temp;
	char a;
	while (cin>>temp) {
		if (temp.length() == 1) {
			a = temp[0];
		}
		else {
			a = '0';
		}
		if (isOpt(a)) {//是操作码,弹出两个操作数，执行操作 s2 opt s1
			int x1 = S1.top(); 
			S1.pop();
			int x2 = S1.top(); 
			S1.pop();
			int y1;
			switch (a) {
			case '+':
				y1 = x1 + x2;
				S1.push(y1);
				break;
			case '-':
				y1 = x2 - x1;
				S1.push(y1);
				break;
			case '*':
				y1 = x1*x2;
				S1.push(y1);
				break;
			}
		}
		else {//是操作数
			int x = atoi(temp.c_str());
			S1.push(x);
		}
	}
	int ans = S1.top();
	S1.pop();
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 3176