akhauriyash/Code-Regression huggingface dataset:
# https://onlinejudge.u-aizu.ac.jp/courses/lesson/1/ALDS1/11/ALDS1_11_B

G = {}
d = {}
f = {}
used = set()
t = 1


def dfs(cur):
    global G, d, f, t

    used.add(cur)
    d[cur] = t

    for i in G[cur]:
        if i in used:
            continue
        t += 1
        dfs(i)
    t += 1
    f[cur] = t


if __name__ == "__main__":
    N = int(input())

    for _ in range(N):
        u, k, *V = list(map(int, input().split()))
        G[u] = V

    for i in range(1, N+1):
        if i not in used:
            dfs(i)
            t += 1

    for i in G.keys():
        print(i, d[i], f[i])



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

typedef vector<int> vi;
typedef pair<int, int> pi;
typedef vector<pi> vii;

typedef long long ll;

#define F first
#define S second

#define ERR 1e-9

#if !ONLINE_JUDGE && !EVAL
    #define dbg_var(x) cerr << #x << ": " << x << "\n";
    #define dbg_iter(x, y) cerr  << #x << ": " << print_iterable(x, y) << "\n";
#else
    #define dbg_var(x)
    #define dbg_iter(x, y)
#endif // ONLINE_JUDGE

template <typename T1, typename T2>
string print_iterable( T1 begin_iter, T2 end_iter){
    bool first = true;
    stringstream res;
    res << "[ ";
    for(; begin_iter != end_iter; ++begin_iter){
        if(!first) res << ", ";
        first = false;
        res << *begin_iter;
    }
    res << " ]";
    return res.str();
}

void aggMax(int & res, int x){ if(x > res)res = x; }
void aggMin(int & res, int x){ if(x < res)res = x; }

int II(){ int i; cin >> i; return i; }
void OI(int i){ cout << i; }

// constraints
#define MAXN 1000000

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

    int N = II(); double res = 0;

    while(N--){
        double v; string s;
        cin >> v >> s;
        if(s == "BTC") res += v * 380000.0;
        else res += v;
    }

    cout << fixed << res << "\n";
    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

int main()
{
	vector< pair<char, int> > sent;
	char top; int num = 0;
	string Bsent;

	cin >> Bsent;

	for(int i = 0; i < Bsent.size(); i++)
	{
		if(!num)
		{
			top = Bsent[i];
		}
		num++;

		if(top == Bsent[i+1])
		{
			continue;
		}
		else
		{
			sent.push_back(make_pair(top, num));
			num = 0;
		}
	}

	int ans = 0;

	for(int i = 1; i < sent.size()-1; i++)
	{
		if(sent[i].first == 'O')
		{
			num = sent[i].second;
			int bnum = sent[i-1].second, anum = sent[i+1].second;

			if( sent[i-1].first == 'J' && num <= bnum && num <= anum && sent[i+1].first =='I')
			{
				int a = min(bnum, min(num, anum));
				if(a > ans)
					ans = a;
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 11960
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;

int main()
{
	ll N,A=0,B=0,C=0;
	cin>>N;
	rep(i,N){
		ll t;
		cin>>t;
		if(t%4==0)A++;
		else if(t%2==0)B++;
		else C++;
	}
	if(B!=0){
		A=A-C;
	}
	else{
		A=A+1-C;
	}
	if(A>=0){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
}

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

#define pb push_back
#define ri(x) scanf("%d",&x)
#define rii(x,y) ri(x),ri(y)
#define ms(obj,val) memset(obj,val,sizeof(obj))
#define ms2(obj,val,sz) memset(obj,val,sizeof(obj[0])*sz)
#define FOR(i,f,t) for(int i=f;i<(int)t;i++)
#define FORR(i,f,t) for(int i=f;i>(int)t;i--)

typedef long long ll;
typedef vector<int> vi;

const int MAXN=1e5;

int N;
int C[MAXN];
int d[MAXN],p[MAXN];
vi T[MAXN];

void dfs(int v) {
	FOR(i,0,T[v].size()) {
		int u = T[v][i];
		if(u != p[v]) {
			p[u] = v;
			d[u] = d[v] + 1;
			dfs(u);
		}
	}
}

void dfs2(int v,int c) {
	C[v] = c;
	FOR(i,0,T[v].size()) {
		int u = T[v][i];
		if(C[u] == -1) dfs2(u,c);
	}
}

int main() {
	ri(N);
	FOR(i,0,N-1) {
		int v,u;
		rii(v,u);
		v--,u--;
		T[v].pb(u);
		T[u].pb(v);
	}
	dfs(0);
	int w = N-1;
	while(d[w] != d[N-1]/2) w = p[w];
	ms(C,-1);
	C[w] = 1;
	C[0] = 1;
	C[N-1] = 0;
	dfs2(0,1);
	dfs2(N-1,0);
	dfs2(w,1);
	int cnt = 0;
	FOR(i,0,N) cnt += C[i] == 1 ? 1 : -1;
	printf("%s\n", cnt > 0 ? "Fennec" : "Snuke");
}


Measured memory_bytes: 13184
#include"bits/stdc++.h"
using namespace std;
using ll = int64_t;

int main() {
    ll N;
    cin >> N;
    vector<ll> X(N), Y(N);
    for (ll i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
    }

    ll mod = (abs(X[0]) + abs(Y[0])) % 2;
    for (ll i = 1; i < N; i++) {
        if ((abs(X[i]) + abs(Y[i])) % 2 != mod) {
            cout << -1 << endl;
            return 0;
        }
    }

    vector<ll> d;
    if (mod == 0) {
        d.push_back(1);
    }
    for (ll i = 0; i < 39; i++) {
        d.push_back((ll)pow(2, i));
    }
    reverse(d.begin(), d.end());

    cout << d.size() << endl;
    for (ll i = 0; i < d.size(); i++) {
        cout << d[i] << " \n"[i == d.size() - 1];
    }

    for (ll i = 0; i < N; i++) {
        ll x = 0, y = 0;
        for (ll j = 0; j < d.size(); j++) {
            ll dx = X[i] - x;
            ll dy = Y[i] - y;
            if (abs(dx) >= abs(dy)) {
                if (dx >= 0) {
                    cout << "R";
                    x += d[j];
                } else {
                    cout << "L";
                    x -= d[j];
                }
            } else {
                if (dy >= 0) {
                    cout << "U";
                    y += d[j];
                } else {
                    cout << "D";
                    y -= d[j];
                }
            }
        }
        cout << endl;
        assert(x == X[i] && y == Y[i]);
    }
}

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

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> s(h);
  for(int i = 0; i < h; ++i) {
      cin >> s.at(i);
  }
  for(int i = 0; i < w+2; ++i) {
      cout << '#';
  }
  cout << endl;

  for (int i = 0; i < h; ++i) {
      cout << '#' << s.at(i) << '#' << endl;
  }

  for(int i = 0; i < w+2; ++i) {
      cout << '#';
  }
  cout << endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MAX = 3000000;
const ll MOD = 1000000007;
string s;
ll q;

int main() {
    cin >> s;
    cin >> q;
    string s1 = "";
    string s2 = "";
    bool rev = false;
    for(ll i=0; i<q; i++){
        ll qn;
        cin >> qn;
        if(qn==1){
            rev = !rev;
            string stemp = s1;
            s1 = s2;
            s2 = stemp;
        }else if(qn==2){
            ll qqn;
            string qs;
            cin >> qqn >> qs;
            if(qqn==1){
                s1 = s1 + qs;
            }else if(qqn==2){
                s2 = s2 + qs;
            }
        }
    }
    string ans = "";
    for(ll j=0; j<s1.length(); j++){
        ans = ans + s1[s1.length()-1-j];
    }
    if(rev){
        for(ll k=0; k<s.length(); k++){
            ans = ans + s[s.length()-1-k];
        }
    }else{
        ans = ans + s;
    }
    ans = ans + s2;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1864
N = int(input())
As = list(map(int, input().split()))
d =dict()
def encode(i,j,k):
    return i+j*(N+1)+k*((N+1)**2)
B = 0
for a in As:
    B += (N+1)**(a-1)
for k in range(N+1):
    for j in range(N+1-k):
        for i in range(N+1-k-j):
            E = 0
            x = encode(i,j,k)
            s0 = i+j+k
            if i:
                E += (i*N)/(s0**2) + d[x-1]*(i/s0)
            if j:
                E += (j*N)/(s0**2) + d[x-N]*(j/s0)
            if k:
                E += (k*N)/(s0**2) + d[x-N**2-N]*(k/s0)
            d[x] = E
print(d[B])


Measured memory_bytes: 412016
#include<stdio.h>
#include<math.h>
int a[100008];
int main()
{
	long long n;
	scanf("%lld",&n);
	for(long long i=sqrt(n);i>=1;i--){
        if(n%i==0){
            long long s=i+n/i-2;
            printf("%lld\n",s);
            break;
        }
	}
}


Measured memory_bytes: 128
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
INF = 10**10
MOD = 10**9 + 7
N = int(input())
A = list(map(int,input().split()))

minus = []
plus = []
for i in range(len(A)):
    minus.append(A[i]-(i+1))
    plus.append(-A[i]-(i+1))

d = {}
for m in minus:
    d[m] = d.get(m,0) + 1

ans = 0
for p in plus:
    ans += d.get(p,0)
print (ans)

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

using namespace std;

long long x;
const long long mod = 1e9 + 7;

long long powermod(long long a, long long b) {
	long long ans = 1;
	a %= mod;
	while (b) {
		if (b & 1) ans = (ans * a) % mod;
		a = (a * a) % mod;
		b >>= 1;
	}
	return ans;
}

long long divi(long long q, long long d) {
	long long temp = 1;
	temp = (q * powermod(d, mod - 2)) % mod;
	return temp;
}

int main() {
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> x;
    long long res = (powermod(10, x) - powermod(9, x) * 2 + powermod(8, x)) % mod + mod;
    res %= mod;
    cout << res << endl;
}

Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define f(z) for(int i=1;i<=z;i++)
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define vi vector<int>
#define pb push_back
#define si set<int>
#define mod  1000000007
#define cl(n,m) (n-1)/m  + 1 ;
#define T() int TT; cin>>TT; while(TT--)
#define P pair<int,int>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const int  N = 1e5 + 5;

signed main(){
	string s; 
	cin >>s ;
	for( int i = 0 ; i<=7 ;i++){
		int ans = s[0] - '0' ;
		for( int j = 0 ;j<3 ;j++){
			int cur = (i>>j) & 1;
			if( cur == 0) 
				ans = ans + (s[j+1] - '0' ) ;
			else 
				ans = ans - ( s[j+1] - '0') ;
		}

		if( ans == 7){
			cout << s[0] ; 
			for( int j = 0 ;j<3 ;j++){
				int cur = (i>>j) & 1 ;
				if(cur ==0)
					cout <<"+" ;
				else 
					cout <<"-" ;
				cout << s[j+1] ;
			}
			cout <<"=7" ;
			exit(0) ;
		}
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h> 
using namespace std; 
int main(){ 
  int a,b;
  cin>>a>>b;
  if((b-1)%(a-1)==0){
  cout<< (b-1)/(a-1)<<endl;
  }
  else{
  cout<< (b-1)/(a-1) +1 <<endl;
  }
  return 0; } 


Measured memory_bytes: 256
import sys
N = int(input())
W = [input() for _ in range(N)]

v = [W[0]]

for i in range(1, N):
    if W[i-1][-1] != W[i][0] or W[i] in v:
        print("No")
        sys.exit()
    v.append(W[i])
print("Yes")

Measured memory_bytes: 3060
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

let rec solve a x = function
    | [] -> a + 1
    | y :: ys ->
        if x = y then
            solve a x ys
        else
            solve (a + 1) y ys

[<EntryPoint>]
let main _ =
    let N = read int
    let S = read string |> fun s -> s.ToCharArray()
    let bs = List.ofArray S
    solve 0 (List.head bs) (List.tail bs)
    |> printfn "%i"
    0

Measured memory_bytes: 22744
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <string>
#include <map>
using namespace std;
typedef long long int lli;
#define urept(soeji, start, n) for (int soeji = start; soeji < n; soeji++)
#define drept(soeji, start, n) for (int soeji = start; soeji > n; soeji--)
int main(void)
{
    string s;
    cin >> s;
    int a, b, c, d;
    a = s[0] - '0';
    b = s[1] - '0';
    c = s[2] - '0';
    d = s[3] - '0';
    if (a + b + c + d == 7)
    {
        cout << a << "+" << b << "+" << c << "+" << d << "=" << 7 << endl;
        return 0;
    }
    else if (a + b + c - d == 7)
    {
        cout << a << "+" << b << "+" << c << "-" << d << "=" << 7 << endl;
        return 0;
    }
    else if (a + b - c - d == 7)
    {
        cout << a << "+" << b << "-" << c << "-" << d << "=" << 7 << endl;
        return 0;
    }
    else if (a - b - c - d == 7)
    {
        cout << a << "-" << b << "-" << c << "-" << d << "=" << 7 << endl;
        return 0;
    }
    else if (a - b - c + d == 7)
    {
        cout << a << "-" << b << "-" << c << "+" << d << "=" << 7 << endl;
        return 0;
    }
    else if (a - b + c + d == 7)
    {
        cout << a << "-" << b << "+" << c << "+" << d << "=" << 7 << endl;
        return 0;
    }
    else if (a - b + c - d == 7)
    {
        cout << a << "-" << b << "+" << c << "-" << d << "=" << 7 << endl;
        return 0;
    }
    else if (a + b - c + d == 7)
    {
        cout << a << "+" << b << "-" << c << "+" << d << "=" << 7 << endl;
        return 0;
    }
    return 0;
}


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



int main() {

	int n;
	int pos;
	string be , cur;
	cin >> n;
	cout << 0 << endl;
	cin >> be;

	int s = 0 , e = n-1;
	while(s < e){
		int mid = (s + e + 1) / 2;
		cout << mid << endl;
		cin >> cur;
		if(cur[0] == 'V'){
			return 0;
		}

		if((mid % 2 == 0 && cur[0] == be[0]) || (mid % 2 == 1 && cur[0] != be[0])){
			s = mid;
		}else{
			e = mid-1;
		}
	}

	cout << s + 1 << endl;


}


Measured memory_bytes: 852
N, M = map(int, input().split())
AB = []

for i in range (N):
  a, b = map(int,input().split())
  AB.append((a,b))
  
AB.sort(key=lambda x:x[0])

can = 0 #購入本数
yen = 0 #購入金額


for ab in AB:
  if can + ab[1] <= M: # 店の商品買い占められるなら
    yen += ab[0] * ab[1]
    can += ab[1]
  elif can < M < can + ab[1]:
    yen += (M-can) * ab[0]
    can += ab[1]
    break

print(yen)



Measured memory_bytes: 18180
import sys
import heapq
if sys.version[0] == '2':
    range, input = xrange, raw_input
MAX_SPEED = 30
while True:
    N, M = map(int, input().split())
    if not (N | M):
        break
    S, G = map(lambda x: int(x) - 1, input().split())
    edge = [[] for _ in range(N)]
    for _ in range(M):
        x, y, d, c = map(int, input().split())
        edge[x - 1].append((y - 1, d, c))
        edge[y - 1].append((x - 1, d, c))
    INF = 1e18
    dist = [[[INF for _ in range(N)] for _ in range(MAX_SPEED + 1)] for _ in range(N)]
    que = [(0.0, S, 0, S)]
    while que:
        cost, now, v, prev = heapq.heappop(que)
        if cost > dist[now][v][prev]:
            continue
        if now == G and v == 1:
            print("{:.20f}".format(cost))
            break
        dist[now][v][prev] = cost
        for x, d, c in edge[now]:
            if x == prev:
                continue
            for dv in (-1, 0, 1):
                nv = v + dv
                if 0 < nv <= c and dist[x][nv][now] > dist[now][v][prev] + d / nv:
                    dist[x][nv][now] = dist[now][v][prev] + d / nv
                    heapq.heappush(que, (dist[x][nv][now], x, nv, now))
    else:
        print("unreachable")

Measured memory_bytes: 9896
//  Created by conan1024hao in 2019.
//  Copyright © 2019 conan1024hao. All rights reserved.
//  専用ライブラリです、自由にコピーして構いません。
//  感谢看我的代码！Wechat:conan1024hao QQ:810396815
#pragma GCC optimize ("O3")
#include <iostream>
#include <iomanip>
#include <istream>
#include <ostream>
#include <sstream>
#include <iterator>
#include <vector>
#include <algorithm>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <ctime>
#include <cctype>
#include <cstdlib>
#define IINF 10e8
#define INF 10e16
#define MOD 1000000007
#define  mod 1000000007
#define rep(i, a, n) for (ll i = a; i < (ll)(n); i++)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define mmax(x,y)(x>y?x:y)
#define mmin(x,y)(x<y?x:y)
#define chmax(x,y) x=mmax(x,y)
#define chmin(x,y) x=mmin(x,y)
#define all(x) (x).begin(),(x).end()
#define siz(x) (ll)(x).size()
#define PI acos(-1.0)
using namespace std;
//using Int=int_fast64_t;
typedef long long int ll;
typedef pair<ll,ll>Pll;
typedef pair<int,int>Pin;
long long GCD(long long a, long long b) { return b ? GCD(b, a%b) : a; }
long long LCM(long long a, long long b)  {return a/GCD(a,b)*b;}
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};
char dir[4]={'u','l','d','r'};
ll cmp1(pair<ll,string>a,pair<ll,string> b){
        if(a.fi!=b.fi)
        return a.fi<b.fi;
        else
        return a.se<b.se;
}
//--------------------------------------------------------------------------

//---------------------------------------------------------------------------
int main(){//問題をちゃんと見ろ!!!!!!!!!!!!!!!!!      llか??????????        memset()!!!!!!!!!!!!       ペナを減らせ!!!!!!!!!!!!!
    cin.tie(0);
    ios::sync_with_stdio(false);
    //-------------------------------
    ll n;cin>>n;
    if(n==0){
        cout << 0 << endl;
        return 0;
    }
    vector<int>ans;
    while(n!=0){
        ans.push_back(abs(n%2));
        if(n<0)n=(n-1)/(-2);
         else n/=(-2);
    }
    reverse(all(ans));
    for(int i=0;i<siz(ans);i++)
        cout<<ans[i];
    cout<<endl;
    //-------------------------------
    return 0;
}
//---------------------------------------------------------------------------




Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>

int main() {
	std::string s;
	unsigned int k;
	std::cin >> s >> k;

	if (s.size() >= k) {
		auto all_one = std::all_of(std::begin(s), std::begin(s) + k, [](auto&c) {return c == '1'; });
		if (all_one) {
			std::cout << 1 << "\n";
			return 0;
		}
	}
		
	auto it = std::find_if(std::begin(s), std::end(s), [](auto&c) {return c != '1'; });
	std::cout << *it << "\n";
	return 0;

}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val (a, b, c) = Triple(ni(), ni(), ni())
  if (b - a == c - b) {
    println("YES")
  } else {
    println("NO")
  }
}

val sc = Scanner(System.`in`)

fun ni(): Int {
  return Integer.parseInt(sc.next())
}


Measured memory_bytes: 23464
import java.io.IOException;

public class Main {
    public static void main(String[] args) throws IOException {
        StringBuilder builder = new StringBuilder();

        int buf;
        while ((buf = System.in.read()) != '\n');

        while ((buf = System.in.read()) != '\n') {
            builder.appendCodePoint(buf);
        }

        StringBuilder ret = new StringBuilder(builder);

        int idx;
        while ((idx = builder.indexOf("()")) != -1) {
            builder.delete(idx, idx + 2);
        }

        for (char c : builder.toString().toCharArray()) {
            if (c == ')') ret.insert(0, '(');
            else ret.append(')');
        }
        System.out.print(ret.toString());
    }
}


Measured memory_bytes: 32136
// In the name of God

#include <bits/stdc++.h>

using namespace std;

const int N = 1e7+5;

int sieve[N], dp[N];
vector<int> primes;

long long calc(int x) {
	if(dp[x]) return dp[x];

	if(sieve[x] == x) {
		return 2;
	}

	int c = 0;
	int tmp = x;

	while(tmp % sieve[x] == 0) {
		c++;
		tmp /= sieve[x];
	}
	return dp[x] = 1ll * (c + 1) * calc(tmp);
}

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

	sieve[1] = 1;

	for(int i = 2; i < N; i++) {
		if(sieve[i] == 0) {
			sieve[i] = i;
			primes.push_back(i);
		}
		for(int j = 0; j < primes.size() && primes[j] <= i && 1ll * i * primes[j] < N; j++) {
			sieve[i  * primes[j]] = primes[j];
		}
	}

	long long ans = 0;

	int n;
	cin >> n;

	dp[1] = 1;

	for(int i = 1; i <= n; i++) {
		ans += i * calc(i);
	}

	cout << ans;
	
	

	return 0;
}


Measured memory_bytes: 84104
#include <stdio.h>

int main()
{
    int A, B, C;
    scanf("%d%d",&A,&B);
C=1,2,3;
    if (1<=A && B<=3 && (A*B*C)%2==1)
    printf("Yes");
    else
    printf("No"); 
    return 0;
}

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

#define INF 2 << 29

int desc(const void *a, const void *b){
  return *(int *)b - *(int *)a;
}

int main(){
    int n,k;
    int h[100010];
    int mnh=INF;
    int i;
    scanf("%d%d",&n,&k);
    for(i=0;i<n;i++)scanf("%d",&h[i]);
    qsort(h,n,sizeof(*h),desc);
    for(i=0;i<n-k+1;i++){
        if((h[i]-h[i+k-1])<mnh)mnh=(h[i]-h[i+k-1]);
    }
    printf("%d\n",mnh);
    return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <functional>
using namespace std;

int main(){
    int n;
    cin >> n;
    int v[n];
    for(int i = 0; i < n; i++){
        cin >> v[i];
    }
    map<int, int> m1;
    int max1 = 0;
    int maxi1 = 0;
    int second1 = 0;
    int secondi1 = 0;
    for(int i = 0; i < n; i+=2){
        m1[v[i]]++;
        if(m1[v[i]] > max1){
            if(v[i] != maxi1) {
                second1 = max1;
                secondi1 = maxi1;
            }
            max1 = m1[v[i]];
            maxi1 = v[i];
        }else if(m1[v[i]] > second1){
            second1 = m1[v[i]];
            secondi1 = v[i];
        }
    }
    map<int, int> m2;
    int max2 = 0;
    int maxi2 = 0;
    int second2 = 0;
    int secondi2 = 0;
    for(int i = 1; i < n; i+=2){
        m2[v[i]]++;
        if(m2[v[i]] > max2){
            if(v[i] != maxi2) {
                second2 = max2;
                secondi2 = maxi2;
            }
            max2 = m2[v[i]];
            maxi2 = v[i];
        }else if(m2[v[i]] > second2){
            second2 = m2[v[i]];
            secondi2 = v[i];
        }
    }

    if(maxi1 != maxi2){
        cout << (n-max1-max2) << endl;
    }else{
        if(second1 > second2){
            cout << (n-max1-second1) << endl;
        }else{
            cout << (n-max1-second2) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 5376
use std::cmp;

const INF: i64 = 1e17 as i64;

fn main() {
    let s = std::io::stdin();
    let mut sc = Scanner { reader: s.lock() };
    let n: usize = sc.read();
    let a: Vec<i64> = sc.read_vec(n);
    let mut graph = vec![vec![]; n];
    for _ in 0..(n - 1) {
        let v = sc.read::<usize>() - 1;
        let u = sc.read::<usize>() - 1;
        graph[v].push(u);
        graph[u].push(v);
    }

    let mut dp1 = vec![vec![]; n];
    let mut dp2 = vec![vec![]; n];
    dfs(0, 0, &graph, &a, &mut dp1, &mut dp2);

    for groups in 1..(n + 1) {
        if dp1[0][groups] < INF {
            println!("{}", groups - 1);
            return;
        }
        if dp2[0][groups] < 0 {
            println!("{}", groups - 1);
            return;
        }
    }
}

fn dfs(
    v: usize,
    p: usize,
    graph: &Vec<Vec<usize>>,
    a: &Vec<i64>,
    dp1: &mut Vec<Vec<i64>>,
    dp2: &mut Vec<Vec<i64>>,
) {
    dp1[v].push(INF);
    dp1[v].push(if a[v] > 0 { a[v] } else { INF });
    dp2[v].push(INF);
    dp2[v].push(a[v]);
    for &next in graph[v].iter() {
        if next == p { continue; }
        dfs(next, v, graph, a, dp1, dp2);

        dp1[v] = connect(&dp1[v], &dp1[next], &dp2[next], true);
        dp2[v] = connect(&dp2[v], &dp1[next], &dp2[next], false);
    }
}

fn connect(dp: &Vec<i64>, child1: &Vec<i64>, child2: &Vec<i64>, power_only: bool) -> Vec<i64> {
    assert_eq!(child1.len(), child2.len());
    let mut ans = vec![INF; dp.len() + child1.len() - 1];
    for groups in 0..dp.len() {
        if dp[groups] == INF { continue; }
        for child_groups in 0..child1.len() {
            let child_power = child1[child_groups];
            let child_group = child2[child_groups];

            let group_num = groups + child_groups;

            if group_num >= 1 {
                if child_power != INF {
                    ch_min(&mut ans[group_num - 1], dp[groups] + child_power);
                }
                if child_group != INF && !power_only {
                    ch_min(&mut ans[group_num - 1], dp[groups] + child_group);
                }
            }
            if child_power != INF || child_group < 0 {
                ch_min(&mut ans[group_num], dp[groups]);
            }
        }
    }
    ans
}

fn ch_min<T: PartialOrd>(a: &mut T, b: T) {
    if *a > b {
        *a = b;
    }
}

pub struct Scanner<R> {
    reader: R,
}

impl<R: std::io::Read> Scanner<R> {
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .reader
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n')
            .take_while(|&b| b != b' ' && b != b'\n')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 211836
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    static class CAlchemist
    {
        static void Main(string[] args)
        {
            var n = decimal.Parse(Console.ReadLine());
            var vList = Console.ReadLine().Split(' ').Select(x => decimal.Parse(x)).ToList();
            vList.Sort();

            for (int i = 0; i < n - 1; i++)
            {
                decimal merge = (vList[0] + vList[1]) / 2;
                vList.RemoveRange(0, 2);
                vList.Add(merge);
                vList.Sort();
            }

            Console.WriteLine(vList[0]);
            Console.ReadLine();
        }
    }
}

Measured memory_bytes: 11604
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#include <time.h>
#include <functional>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<ll, ll, ll, ll> tlglglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
typedef vector<ll> vll;
typedef vector< vector<ll> > matrix;
typedef unsigned int uint;
typedef unsigned long long ull;
template <class T> using V = vector<T>;
template <class T> using VV = V<V<T>>;
template <class T> using VVV = V<VV<T>>;
#define REP(i, x, y) for(ll i = (ll)x; i < (ll)y; i++)
#define DREP(i, x, y, d) for(ll i = (ll)x; i < (ll)y; i += (ll)d)
#define PER(i, x, y) for(ll i = (ll)x; i > (ll)y; i--)
#define DPER(i, x, y, d) for(ll i = (ll)x; i > (ll)y; i -= (ll)d)
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-12;
void yesno(bool ok, string yes = "Yes", string no = "No") {
    if (ok) {
        cout << yes << endl;
    } else {
        cout << no << endl;
    }
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M, X;
    cin >> N >> M >> X;
    ll C[N];
    ll A[N][M];
    REP(i, 0, N) {
        cin >> C[i];
        REP(j, 0, M) {
            cin >> A[i][j];
        }
    }
    bool ok = false;
    ll ans = inf;
    REP(i, 0, (1 << N)) {
        ll tmp = 0;
        vll num(M, 0);
        REP(j, 0, N) {
            if (i & (1 << j)) {
                tmp += C[j];
                REP(k, 0, M) {
                    num[k] += A[j][k];
                }
            }
        }
        bool tmpok = true;
        REP(j, 0, M) {
            if (num[j] < X) {
                tmpok = false;
            }
        }
        if (tmpok) {
            ok = true;
            ans = min(ans, tmp);
        }
    }
    if (ok) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 3664
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <utility>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <functional>

using namespace std;

#define fst first
#define scd second
#define PB push_back
#define MP make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define omajinai ios::sync_with_stdio(false);cin.tie(0)
#define rep(i,x) for(int i=0;i<(int)(x);++i)
#define rep1(i,x) for(int i=1;i<=(int)(x);++i)
#define rrep(i,x) for(int i=(int)x-1;i>=0;--i)
#define rrep1(i,x) for(int i=(int)x;i>=1;--i)

using ll=long long;
using ld=long double;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int, int>;
using vpii=vector<pii>;

template<class T,class U>ostream&operator<<(ostream&os,const pair<T,U>p){os<<"("<<p.fst<<", "<<p.scd<<")";return os;}
template<class T>ostream&operator<<(ostream&os,const vector<T>v){rep(i,v.size()){if(i)os<<", ";os<<v[i];}return os;}
template<typename T>T&max(T&a,T&b){if(a>=b)return a;return b;}
template<typename T>T&min(T&a,T&b){if(a < b)return a;return b;}
template<typename T>bool chmax(T&a,T b){if(a < b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a > b){a=b;return true;}return false;}

constexpr int inf = 1e9;
constexpr ll linf = 3e18;
constexpr double eps = 1e-9;

signed main()
{
    int n, a, b;cin>>n>>a>>b;
    cout << min(n*a,b)<<endl;
}


Measured memory_bytes: 256
/* */

#include <cstdio>
#include <cstring>
#include <cassert>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <bitset>
#include <map>
#include <set>
using namespace std;
typedef long long int ll;
typedef vector< int > vi;
typedef pair< int, int > ii;
typedef vector< ii > vii;
typedef vector< ll > vll;
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
#else
	#define errp(...)
#endif
#define dbg(x) errp("%s = %s\n", #x, to_string(x).data())
string to_string (string s) { return "\"" + s + "\""; }
template<typename T> string to_string (vector<T>);
template<typename U, typename V> string to_string (pair<U, V> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; }
template<typename T> string to_string (vector<T> v) { string r = "["; for (int i = 0; i < (int)v.size() - 1; i++) r += to_string(v[i]) + ", ";
	if (!v.empty()) r += to_string(v.back()); return r + "]"; }

const int N = 100010;
ll freq[N], n, k;

int main () { 
#ifdef XVENOM
	// freopen("input.txt", "r", stdin);
	// freopen("output.txt", "w", stdout);
#endif
	
	memset(freq, 0, sizeof freq);
	scanf("%lld%lld", &n, &k);
	ll a, b;
	for (int i = 0; i < n; i++) {
		scanf("%lld%lld", &a, &b);
		freq[a] += b;
	}
	ll x = 0, ans = 1;
	while (x < k) {
		x += freq[ans++];
	}
	ans--;
	printf("%lld\n", ans);
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF (1ll << 60)
#define sz(x) int(x.size())
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
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;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}
// https://emtubasa.hateblo.jp/entry/2018/11/24/000000
// dp[i]][j][k]
// i番目までの荷物の中でj個利用した時に総重量がkとなるような組み合わせの中で最大の値
ll dp[128][128][305];
// https://atcoder.jp/contests/abc060/submissions/3639903
int main() {
    int N;
    ll W;
    cin >> N >> W;
    vector<ll> weight(N);
    vector<ll> value(N);
    REP(i, N) { cin >> weight[i] >> value[i]; }
    // weight value
    ll ans = 0;
    ll fin = W / weight[0];
    ll finw = W % weight[0];
    ll fw = weight[0];
    for(int i = 0; i < N; i++) {
        weight[i] -= fw;
    }
    dp[0][1][0] = value[0];
    for(int i = 1; i < N; i++) {
        for(int j = 1; j <= i + 1; j++) {
            for(int k = 0; k <= 300; k++) {
                if(i == 0) {
                    continue;
                }
                dp[i][j][k] = dp[i - 1][j][k];
                if(k - weight[i] >= 0) {
                    dp[i][j][k] =
                        max(dp[i][j][k],
                            dp[i - 1][j - 1][k - weight[i]] + value[i]);
                }
            }
        }
    }

    for(int i = 0; i <= N + 1; i++) {
        for(int j = 0; j <= 304; j++) {
            if(fw * i + j > W) {
                continue;
            }
            ans = max(ans, dp[N - 1][i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 29056
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
input=lambda :sys.stdin.readline().rstrip()


H,W,K=map(int,input().split())
S=[input() for i in range(H)]

value=H+W-1
if H==1:
    count=0
    countL=0
    w=0
    while w<W:
        if S[0][w]=="1":
            count+=1
        if count>K:
            countL+=1
            count=0
        else:
            w+=1
    print(countL)
else:
    for i in range(2**(H-1)):
        lst=[i>>m&1 for m in range(H-1)]#0なら線がある
        count=[0 for i in range(lst.count(0)+1)]
        count_zero=copy.copy(count)
        idx={}
        c=0
        for h in range(H-1):
            idx[h]=c
            if lst[h]==0:
                c+=1
        idx[H-1]=c
        flag=0
        w=0
        pre_w=0
        countL=lst.count(0)
        while w<W:
            for h in range(H):

                if S[h][w]=="1":
                    count[idx[h]]+=1
            if max(count)>K:
                if pre_w==w:
                    flag=1
                    break

                pre_w=w
                countL+=1
                count=copy.copy(count_zero)
            else:
                w+=1

        if not flag:
            value=min(value,countL)
    print(value)


Measured memory_bytes: 72408
n = int(input())
v = list(map(int,input().split()))
v1 = v[::2]
v2 = v[1::2]
from collections import Counter
cv1 = Counter(v1).most_common()
cv2 = Counter(v2).most_common()
cv1.append((0,0))
cv2.append((0,0))

if cv1[0][0] == cv2[0][0]:
    ans = n - max(cv1[0][1] + cv2[1][1], cv1[1][1] + cv2[0][1])
else:
    ans = n - cv1[0][1] - cv2[0][1]
print(ans)


Measured memory_bytes: 20956
#include <bits/stdc++.h>
using intl = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for(intl i = 0; i < (intl)(n); i++)
#define repd(i, n) for(intl i = (intl)((n) - 1); i >= 0; i--)
#define repi(i, a, b) for(intl i = (intl)(a); i < (intl)(b); i++)
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
#define all(x) (x).begin,(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define sqrt sqrtl
#define fill(x,y) memset(x,y,sizeof(x))
#define debug(x) cout << #x << ":" << x << endl
const intl INF = 1e9;
const intl MOD = 1e9+7;
void fp(bool flag){
    if(flag)cout << "Yes" << endl;
    else cout << "No" << endl;
}
int main(){
    ld a;
    cin >> a;
    ld b;
    cin >> b;
    ld c;
    cin >> c;
    ld e =  1.0e-14;
    fp((sqrtl(a) + sqrtl(b) + e < sqrtl(c)));
    return 0;
}

Measured memory_bytes: 256
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
count = 0

a.each.with_index do |x, i|
  break if i == n - 1
  mini = [a[i+1..n-1].min, x].min
  if mini < x
    mini_i = a[i+1..n-1].index(mini) + (i+1)
    a[i], a[mini_i] = mini, x
    count += 1
  end
end

puts a.join(' '), count

Measured memory_bytes: 6136
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <utility>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <queue>
#include <functional>
#include <stdlib.h>
#include <climits>
#include <iomanip>
#include <complex>
#include <cmath>
using namespace std;
signed main(void)
{
	int h, w;
	cin >> h >> w;
	int s[54][54];
	int masu[54][54];
	string str;
	for (int i = 0; i < 54; i++) {
		for (int j = 0; j < 54; j++) {
			s[i][j] = 1;
			masu[i][j] = INT_MAX / 2;
		}
	}
	int cnt = 0;
	for (int i = 1; i <= h; i++) {
		cin >> str;
		for (int j = 1; j <= w; j++) {
			if (str[j-1] == '.')s[i][j] = 0;
			else { s[i][j] = 1; cnt += 1; }
		}
	}
	typedef pair<int, int>P;
	queue<P>que;
	que.push(P(1, 1));
	masu[1][1] = 0;
	while (!que.empty()) {
		P now = que.front();
		int i = now.first;
		int j = now.second;
		que.pop();
		if(s[i-1][j]==0&&masu[i-1][j]>masu[i][j]+1)
		{
			masu[i - 1][j] = masu[i][j] + 1;
			que.push(P(i - 1, j));
		}
		if (s[i + 1][j] == 0 && masu[i + 1][j]>masu[i][j] + 1)
		{
			masu[i + 1][j] = masu[i][j] + 1;
			que.push(P(i + 1, j));
		}
		if (s[i][j-1] == 0 && masu[i][j-1]>masu[i][j] + 1)
		{
			masu[i][j-1] = masu[i][j] + 1;
			que.push(P(i, j-1));
		}
		if (s[i][j + 1] == 0 && masu[i][j + 1]>masu[i][j] + 1)
		{
			masu[i][j +1] = masu[i][j] + 1;
			que.push(P(i, j + 1));
		}
	}
	if (masu[h][w] == INT_MAX / 2)cout << -1;
	else cout << h*w - cnt - masu[h][w]-1;
	return 0;
}


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

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

    int A = 0, B = 0;
    sort(a.begin(), a.end());
    reverse(a.begin(), a.end());
    for (int i = 0; i < N - 1; i += 2) {
        A += a.at(i);
        B += a.at(i + 1);
    }
    if (N % 2 == 1) {
        A += a.at(N - 1);
    }

    cout << A - B << endl;
}

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

using namespace std;

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

inline int toInt(string s) {int v; istringstream sin(s);sin>>v; return v;}

typedef long long ll;

// 最大公約数
long long gcd(long long a, long long b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

// 最小公倍数
long long lcm(long long a, long long b){
    long long g = gcd(a,b);
    return a / g * b;
}

int main(){
    int N, X;

    cin >> N >> X;
    vector<int> x(N), y(N);

    rep(i, N) cin >> x[i];

    rep(i, N) y[i] = abs(x[i] - X);

    int D = gcd(y[1], y[0]);
    FOR(i, 2, N) D = gcd(y[i], D);

    cout << D << endl;

    return 0;
}

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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define ALLTRUE(xs) all_of(ALL(xs),[](bool x){return x;})
#define AND(x,y,z) set_intersection((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define ANYTRUE(xs) any_of(ALL(xs),[](bool x){return x;})
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define OR(x,y,z) set_union((x).begin(),(x).end(),(y).begin(),(y).end(),inserter((z),(z).end()))
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;

int main() {
  ll N;cin>>N;
  vector<ll> AS(N);
  REP(i,N) cin>>AS[i];

  // ajが同じなら、aiが大きい方がcombは大きくなる
  // なので、ASをソートして、最も大きい数と、その半分以下で最も近い数を選ぶ
  sort(ALL(AS));

  ll ai = AS.back();
  ll aj = 0;
  if (ai%2==0) {
    REP(i,N) {
      if (abs(ai/2-aj)>abs(ai/2-AS[i])) aj = AS[i];
    }
  } else {
    REP(i,N) {
      if (abs(ai/2-aj)>abs(ai/2-AS[i]) || abs(ai/2+1-aj)>abs(ai/2+1-AS[i])) aj = AS[i];
    }
  }
  cout<<ai<<' '<<aj<<endl;

  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

const int N_MAX = 100000;

int main(){
    int n, k;
    int A[N_MAX];

    cin >> n >> k;

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

    if(n <= k) {
        cout << 1 << endl;
    }
    else if((n - 1) % (k - 1) != 0) {
        cout << (n - 1) / (k - 1) + 1 << endl;
    }
    else {
        cout << (n - 1) / (k - 1) << endl;
    }

    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF (1<<29)
#define LINF (1LL<<60)
#define EPS (1e-10)
#define PI 3.1415926535897932384626433832795028
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define max_heap priority_queue<int>
#define min_heap priority_queue<int,vector<int>,greater<int>>
using ll = long long;
#define int long long
#define endl "\n"
#define vi vector<int>
#define pb push_back
#define inp_arr(a,n) for(ll i=0;i<n;i++)cin>>a[i];
#define out_arr(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";
#define deb(n) cerr << #n << " = " << n << "\n";
int gcd(int a, int b) { if (a == 0) return b; return gcd(b % a, a);}
ll mypower(ll x,ll n,ll c){
    if(n == 0)
        return 1;
    ll temp = mypower(x,n/2,c)%c;
    if(n%2)
        return (n<0)? (1/x)*temp*temp%c: ((x*temp)%c)*temp%c;
    else
        return temp*temp%c;
}
bool codejam = 0;

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif

	ll k;
	cin>>k;
	set<ll> seen;
	ll a = 7;
	ll ans = 1;
	while(a<=1e6+5){
		if(a%k == 0){
			cout<<ans<<endl;
			break;
		}
		else if(seen.find(a)!=seen.end()){
			ans = -1;
			cout<<ans<<endl;
			break;
		}
		else{
			ans++;
			seen.insert(a%k);
			a = (a*10+7)%k;
		}
	}
	if(a>1e6+5)
		cout<<-1<<endl;
	return 0;
}


Measured memory_bytes: 50484
from fractions import gcd
A, B, K = map(int, input().split())
g = gcd(A, B)
k = 1
r = 0
res = 0
while True:
  if k > min(A, B):
    print(res)
    exit(0)
  if r == K:
    print(res)
    exit(0)
  if g % k == 0:
    res = g // k
    r += 1
  k += 1
    



Measured memory_bytes: 64108
def main():

    N = int(input())

    k=0
    while True:
        t=k*(k+1)//2
        if t==N:
            break
        if t>N:
            print("No")
            return
        k+=1

    print("Yes")
    print(k+1)

    sets=[list() for j in range(k+1)]
    x=0
    y=1
    for i in range(1,N+1):
        sets[x].append(i)
        sets[y].append(i)
        x+=1
        if y==x:
            y+=1
            x=0

    # 出力
    for s in sets:
        u=" ".join(str(ss) for ss in s)
        print("{} {}".format(len(s), u))

if __name__ == '__main__':
    main()


Measured memory_bytes: 8948
#include <algorithm>
#include <iostream>
#include <stack>
#include <queue>
#include <cmath>
#include <string>
#include <iterator>
#include <map>
#include <set>
#include <iomanip>
#include <vector>
#include <cstdint>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Graph = vector<vector<int>>;
int dx[] = {0, 1, 0, -1};
int dy[] = {1, 0, -1, 0};
#define rep(i, N) for(int i = 0; i < N; i++)
#define rep2(i, l, r) for (ll i = (ll)l; i < (ll)(r); i++)
#define INF 1000000000000000
#define MAX 200001

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
const ll MOD = 998244353;

template <typename T > inline string toString(const T &a) {ostringstream oss; oss << a; return oss.str();};

int main(){
    int N;
    cin >> N;
    int K = -1;
    for(int k = 1; k <= 100001; k++){
        if(k*(k-1) == 2*N){
            K = k;
            break;
        }
    }
    if(K == -1) cout << "No" << endl;
    else{
        vector<vector<int>> ans(K);
        int a = 0;
        int b = 1;
        for(int i = 1; i <= N; i++){
            ans[a].push_back(i);
            ans[b].push_back(i);
            if(ans[a].size() == K-1) a++;
            b++;
            if(b == K) b = a+1;
        }
        cout << "Yes" << endl;
        cout << K << endl;
        for(auto a:ans){
            cout << a.size() << ' ';
            rep(i,a.size()){
                if(i == a.size()-1) cout << a[i] << endl;
                else cout << a[i] << ' ';
            }
        }
    }
}

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



Measured memory_bytes: 2040
#include<stdio.h>
int a[12];
int main()
{
	int n,i,s,k;
	while(scanf("%d",&n)!=EOF)
	{
		s=1;k=1;
		for(i=1;i<=n;i++) scanf("%d",&a[i]);
	    for(i=1;i<=n;i++)
	    {
	    	s=s*3;
	    	if(a[i]%2==0) k=k*2;
		}
		s=s-k;
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <fstream>
#include <vector>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <string>
#include <set>
#include <map>
using namespace std;
typedef long long ll;

// #define DEBUG

class Point;

class Point
{
    double x;
    double y;

public:
    void printpoint();
    double norm();
    friend Point operator+(Point a, Point b);
    friend double operator*(Point a, Point b);
    friend Point operator*(double a, Point b);
    friend Point operator*(Point a, double b);
    friend Point operator/(Point a, double b);
    friend Point operator-(Point a, Point b);
    double dot(Point b);
    Point(double a, double b)
    {
        x = a;
        y = b;
    }
    int get_x() { return x; }
    int get_y() { return y; }
};

void Point::printpoint()
{
    printf( "%.8f  %.8f\n", x, y);
}

double Point::norm()
{
    return sqrt(x * x + y * y);
}

Point operator+(Point a, Point b)
{
    return Point(a.x + b.x, a.y + b.y);
}

double operator*(Point a, Point b)
{
    return double(a.y * b.x - a.x * b.y);
}
Point operator*(double a, Point b)
{
    return Point(a * b.get_x(), a * b.get_y());
}
Point operator*(Point a, double b)
{
    return Point(a.get_x() * b, a.get_y() * b);
}
Point operator/(Point a, double b)
{
    return Point(a.get_x() / b, a.get_y() / b);
}
Point operator-(Point a, Point b)
{
    return Point(a.x - b.x, a.y - b.y);
}

double Point::dot(Point b)
{
    return x * b.x + y * b.y;
}

void printarray(int n, int a[])
{
    for (int i = 1; i < n + 1; i++)
    {
        cout << a[i];
        if (i != n)
            cout << " ";
    }
    cout << endl;
}

int main()
{

#ifdef DEBUG
    cout << "DEBUG MODE" << endl;
    ifstream in("input.txt"); //for debug
    cin.rdbuf(in.rdbuf());    //for debug
#endif

    double a, b, c, d, e, f, q;
    cin >> a >> b >> c >> d;
    Point p1(a, b);
    Point p2(c, d);
    Point v1 = p2 - p1;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        cin >> e >> f;
        Point p3(e, f);
        Point v2 = p3 - p1;
        Point v4 = v1 * (v1.dot(v2)/(v1.norm()*v1.norm())) + p1;
        v4.printpoint();

    }
    return 0;
}

// getline(cin,s);
// a = strtok(s, ",");  ","で分解
// for (int i = 0; i < n; i++)


Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep1(i, n) for(int i = 1; i < n+1; i++)
#define sort(A) sort(A.begin(),A.end())
#define reverse(A) reverse(A.begin(),A.end());
typedef long long ll;

int main(){
  int n,k;
  cin >> n >> k;
  ll ans = 0;
  rep1(b,n){
    if(b <= k) continue;
    ans += n/b*(b-k);
    if(k == 0) ans += n%b;
    else ans += max(0,n%b-k+1);
  }
  cout << ans << endl;
}

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

int main(){
	int n,d;
	cin >> n >> d;
	int count  = 0;
	while(n--){
		ll x,y;
		cin >> x >> y;
		x = x*x;
		y = y*y;
		ll r = x+y;
		ll de = d;
		de = de*d;
		if(r <= de)count++;
	}
	cout << count << endl;

	return 0;
}


Measured memory_bytes: 3636