akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main() {
    long long n, a, b;
    cin >> n >> a >> b;
    if(a == 0) cout << 0 << endl;
    else if(n < a+b){
        if(n < a) cout << n << endl;
        else cout << a << endl;
    }
    else {
        if(n%(a+b) < a)cout << a*(n/(a+b)) + n%(a+b) << endl;
        else cout << a*(n/(a+b)) + a << endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int m = scanner.nextInt();
			int[] a = new int[n], b = new int[n];
			int[] c = new int[m], d = new int[m];
			IntStream.range(0, n).forEach(i -> {
				a[i] = scanner.nextInt();
				b[i] = scanner.nextInt();
			});
			IntStream.range(0, m).forEach(i -> {
				c[i] = scanner.nextInt();
				d[i] = scanner.nextInt();
			});
			IntStream.range(0, n).map(i -> {
				int min = Integer.MAX_VALUE;
				int minIndex = -1;
				for (int j = 0; j < m; j++) {
					int distance = Math.abs(a[i] - c[j]) + Math.abs(b[i] - d[j]);
					if (distance < min) {
						min = distance;
						minIndex = j;
					}
				}
				return minIndex + 1;
			}).forEach(System.out::println);
		}
	}
}


Measured memory_bytes: 27092
import sys
sys.setrecursionlimit(10**6)


def main(input, print):
    n = int(input())
    ans = 0
    for a in range(1, n):
        for b in range(1, n):
            if a*b >= n:
                break
            ans += 1
    print(ans)


if __name__ == '__main__':
    main(sys.stdin.readline, print)


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

#define lson rt << 1
#define rson rt << 1 | 1
#define mid ((l + r) >> 1)
#define Lson l, mid, lson
#define Rson mid + 1, r, rson
const int MAXN = 1e6 + 20;
using pa = pair<int, int>;
using ll = long long;

const int MOD = 1e9 + 7;
ll ksm(ll a, ll b) {
    ll ret = 1;
    while (b) {
        if (b & 1) {
            ret = ret * a % MOD;
        }
        b /= 2;
        a = a * a % MOD;
    }
    return ret;
}
ll fac[MAXN], inv[MAXN];
int C(int n, int m) {
    return 1ll * fac[n] * inv[m] % MOD * inv[n - m] % MOD;
}
void init() {
    fac[0] = inv[0] = inv[1] = 1;
    for (int i = 1; i < MAXN; i++) 
        fac[i] = 1ll * fac[i - 1] * i % MOD;
    for (int i = 2; i < MAXN; i++) 
        inv[i] = 1ll * (MOD - MOD / i) * inv[MOD % i] % MOD;
    for (int i = 1; i < MAXN; i++) 
        inv[i] = 1ll * inv[i - 1] * inv[i] % MOD;
}
int main() {
    init();
    ll n;
    cin >> n;
    ll all = ksm(10, n);
    all -= ksm(8, n);
    all += MOD;
    all %= MOD;
    ll r = 0;
    for (int i = 1; i <= n; i++) {
        r += C(n, i) * ksm(8, n - i) % MOD;
        r %= MOD;
    }
    r *= 2;
    r %= MOD;
    all -= r;
    all += MOD;
    all %= MOD;
    cout << all << endl;
}



Measured memory_bytes: 19256
#include <cstdio>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long int lli;

lli seg[400005]={};
int N=1;
void init(int p){
	while(N<p)N*=2;
}

lli rec(int l,int r,int a,int b,int no){
	if(b<=l || r<=a)return 0;
	if(a<=l && r<=b)return seg[no];
	return max( 
		rec(l,(l+r)/2,a,b,no*2),
		rec((l+r)/2,r,a,b,no*2+1));
}
		
void upd(int p,lli to){
	p+=N;
	while(p){
		seg[p]=max(seg[p],to);
		p/=2;
	}
}
lli n;
lli dat[100005];
int main(void){
	scanf("%lld",&n);
	rep(i,n)scanf("%lld",&(dat[i]));
	
	init(n+3);
	rep(i,n){
		lli cam=rec(0,N,1,dat[i],1);
		upd(dat[i],cam+dat[i]);
	}
	printf("%lld\n",n*(n+1)/2-rec(0,N,1,n+1,1));
	return 0;
}

Measured memory_bytes: 3392
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

int n;
int a[101], aa[101];
bool flag = false;

int main()
{
	cin >> n;
	for (int i = 1; i <= n; ++ i)
	{
		cin >> a[i];
		aa[i] = a[i];
	}
	for (int i = 1; i <= n; ++ i)
	{
		if (a[i] != i)
		{
			if (flag)
			{
				cout << "NO";
				flag = false;
				break;
			}
			else
			{
				flag = true;
				if (a[a[i]] != i)
				{
					cout << "NO";
					flag = false;
					break;
				}
				else
				{
					swap(a[i], a[a[i]]);
				}
			}
		}
	}

	sort(aa + 1, aa + 1 + n);
	flag = true;
	for (int i = 1; i <= n; ++ i)
	{
		if (a[i] != aa[i]) flag = false;
	}

	if (flag) cout << "YES";
	return 0;
}

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

int main(){
	int n;
	while(cin >> n,n){
		int a,cnt[7] = {};
		for(int i = 0;i < n;i++){
			cin >> a;
			cnt[min(a / 10,6)]++;
		}
		for(int i = 0;i < 7;i++) cout << cnt[i] << endl;
	}
	return 0;
}

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

int main() {
    int A,B,X;
    string result;
    cin >> A >> B >>X;
    if(A <= X && X <= A+B){
        result = "YES";
    }else{
        result = "NO";
    }

    cout << result << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define PF push_front
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double
#define pii pair<int,int>
#define pll pair<LL,LL>
#define vi vector<int>
#define vl vector<LL>
#define vii vector<vi>
#define vll vector<vl>

const double pi = 3.14159265358979323846264;
const int mod=1000000007;

int main(){
	string s,t,u;
    cin>>s>>t;
    int a,b;
    cin>>a>>b>>u;
    if(s==u){
        a--;
    }else{
        b--;
    }
    cout<<a<<" "<<b;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, z, n) for(int i = z; i < n; i++)
#define all(v) v.begin(), v.end()
typedef long long ll;
const int INF = 1<<29;
//const int MODINF = 1000000007;
using namespace std;

int main(){
    int H, W, K;
    cin >> H >> W >> K;
    vector<vector<char>> S(H,vector<char>(W));
    rep(i, 0, H){
        rep(j, 0, W){
            cin >> S.at(i).at(j);
        }
    }
    int line_f = H * W;
    for(int tmp = 0; tmp < (1 << (H - 1)); tmp++){
        if (pow(2, H) <= tmp) break;
        vector<bool> h(W, false);
        bitset<10> t(tmp);
        //cout << t << endl;
        int num = 0;
        rep (k, 0, 9){
            if(t.test(k)) num++;
        }
        int line = num;
        //cout << line << endl;
        
        vector<int> line_count(num + 1, 0);
        rep(j, 0, W){
            int address = 0;
            rep(i, 0, H){
                
                if(S.at(i).at(j) == '1'){
                    line_count.at(address)++;
                }
                if(line_count.at(address) > K){
                    line++;
                    //cout << "n " << endl;
                    rep(k, 0, num + 1) line_count.at(k) = 0;
                    if (j == 0){
                        //cout << "l " << j << endl;
                        line = INF;
                        goto SKIP;
                    }
                    else if (h.at(j - 1)){
                        //cout << "h " << j << endl;
                        line = INF;
                        goto SKIP;
                    }
                    h.at(j - 1) = true;
                    j--;
                    //cout << "j " << j << endl;
                    break;
                    
                }
                else{
                    //cout << "M " << endl;
                }
                if(t.test(i)) address++;
            }
        }
        SKIP:
        line_f = min(line, line_f);
        
        //cout << line << endl;
       
    }
    cout << line_f << endl;
}

Measured memory_bytes: 256
//#include <tourist>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = 1e9;
const ll LINF = ll(1e18);
const int MOD = 1000000007;
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define rep(i, n) for (int i = 0; i < n; i++)
#define ALL(v) v.begin(), v.end()
#define debug(v)          \
    cout << #v << ":";    \
    for (auto x : v)      \
    {                     \
        cout << x << ' '; \
    }                     \
    cout << endl;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
//cout<<fixed<<setprecision(15);有効数字15桁
//-std=c++14
//-std=gnu++17
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    string s;
    cin >> n >> s;
    int ans = 1;
    rep(i,n-1){
        if(s[i]!=s[i+1])ans++;
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 512
///I don't wanna read problem's statement anymore
using namespace std;
#include<bits/stdc++.h>
#define ll long long
#define read freopen("in.txt", "r", stdin)
#define write freopen("out.txt", "w", stdout)
#define sf scanf
#define pb push_back
#define pfr push_front
#define reap(i,n) for(int i=0; i<n; i++)
#define case_ printf("Case %d: ",i)
#define check printf("working\n")
#define pf printf
#define ato(v) for(auto k:v)
#define vi vector<int>
#define vll vector<ll>
#define vec_ch vector<char>
#define list_i list<int>
#define list_ll list<ll>
#define list_ch list<ch>
#define M 100005
#define ios ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);


ll d[M];
ll a[M];
ll solve(int n){
    if(n==1) return abs(a[1]-a[0]);
    if(n==2) return abs(a[2]-a[0]);
    if(d[n]!=-1) return d[n];
    else{
        d[n]=min(abs(a[n]-a[n-2])+solve(n-2), abs(a[n]-a[n-1])+solve(n-1));
        return d[n];
    }
}
int main(){
    ios
    //read;
    //write;
    int n;
    cin>>n;
    for(ll i=0; i<n; i++) cin>>a[i];
    memset(d,-1,sizeof(d));
    cout<<solve(n-1);
    return 0;
}


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

int main(void){
    int n;
    cin >> n;
    vector<ll> a(n);
    for (int i=0; i<n; i++) cin >> a[i];
    sort(a.begin(), a.end(), greater<int>());
    
    vector<ll> ans;
    for (int i=0; i<n-1; i++) {
        if (a[i] == a[i+1]) {
            ans.push_back(a[i]);
            i++;
        }
        if (ans.size() == 2) break;
    }
    cout << (ans.size() == 2 ? ans[0] * ans[1] : 0) << endl;
    return 0;
}

Measured memory_bytes: 3996
#include <bits/stdc++.h>
 
#define ull unsigned long long
#define ll long long
#define pb push_back
#define pii pair<int, int>
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
 
using namespace std;
 
const int INF = 1e9 + 7;

int freq[1000001] = {0};
int main(void)
{
	FAST
 	
	int n; cin >> n;
	
	vector<int> a(n);

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

	if(freq[1] == 1) cout << 1 << '\n';
	else if(freq[1] > 1) cout << 0 << '\n';
	else
	{
		int ans = n;
		for(int i : a)
		{
			if(freq[i] > 1) ans--;
			else
			{
				for(int j = 2; j*j <= i; j++)
				{
					if(i % j  == 0)
					{
						if(freq[j] > 0 || freq[i/j] > 0)
						{
							ans--;
							break;
						}
					}
				}
			}
		}
		cout << ans << '\n';
	}
	return 0;
}


Measured memory_bytes: 7960
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int N;
    cin >> N;
    vector<int> D(N, 0);
    for (int i = 0; i < N; i++)
    {
        cin >> D[i];
    }
    
    int M;
    cin >> M;
    vector<int> T(M, 0);
    for(int i = 0; i < M; i++){
        cin >> T[i];
    }
    
    if( M > N){
        cout << "NO" << endl;
        return 0;
    }
    sort(D.begin(), D.end());
    sort(T.begin(), T.end());

    int i_d = 0;
    bool success = true;
    for(int i = 0; i < M; i++){
        
        bool match = false;
        while(i_d < N){
            if(T[i] == D[i_d]){
                match = true;
                i_d++;
                break;
            }
            i_d++;
        }

        if(i_d == N && !match){
            success = false;
            break;
        }
    }

    if(success){
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}


Measured memory_bytes: 4848
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)
import bisect
import numpy as np
import math


A, B, H, M = map(int, input().split())

def get_len(a, b, deg):
    rad = deg * math.pi / 180
    return (a**2 + b**2 - 2*a*b*math.cos(rad))**0.5


deg_A = 0.5 * (M + H*60)
deg_B = M * 360 / 60

deg = abs(deg_A - deg_B)
print(get_len(A, B, deg))

Measured memory_bytes: 27204
//💭💡🎈fold
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<stack>
#include<deque>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<bitset>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#define pb push_back
#define mp make_pair
#define sz(x) ((int)(x).size())
#define frd(x) freopen("x","r",stdin)
#define fwt(x) freopen("x","w",stdout)
#define fo(i,a) for(int i=1;i<=(a.n);i++)
#define fup(i,x,y) for(int i=(x);i<=(y);i++)
#define fdn(i,x,y) for(int i=(x);i>=(y);i--)
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

template<int __>
struct ia
{
    int a[__],n;
    ia(int n=0):n(n) {}
    void rev(){reverse(a+1,a+n+1);}
    void hp(){make_heap(a+1,a+n+1);}
    int& operator[](int x){return a[x];}
    void sf(){fup(i,1,n)scanf("%d",a+i);}
    void mem(int x){memset(a,x,sizeof(a));}
    void sup(){sort(a+1,a+n+1,less<int>());}
    void sdn(){sort(a+1,a+n+1,greater<int>());}
    void uq(){this->sup(),n=unique(a+1,a+n+1)-a-1;}
    bool nexp(){return next_permutation(a+1,a+n+1);}
    int lb(int x){return lower_bound(a+1,a+n+1,x)-a;}
    int ub(int x){return upper_bound(a+1,a+n+1,x)-a;}
    void pf(){fup(i,1,n)printf("%d%c",a[i],i==n?'\n':' ');}
};

int abs(int x)
{
    return (x>=0)?x:-x;
}

int main()
{
    int n;
    scanf("%d",&n);
    int nx=0,ny=0,nt=0;
    fup(i,1,n)
    {
        int t,x,y;
        scanf("%d%d%d",&t,&x,&y);
        if((abs(nx-x)+abs(ny-y))%2!=(abs(nt-t)%2))
            return !printf("No\n");
        if(abs(nx-x)+abs(ny-y)>abs(nt-t))
            return !printf("No\n");
        nx=x,ny=y,nt=t;
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 256
//
// Created by Hideaki Imamura on 2019-07-09.
//

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

int main() {
    ll n, k;
    cin >> n >> k;

    ll res = 0;

    ll m = 0;
    for (ll i = 1; i <= n; ++i) {
        if (i % k == 0) ++m;
    }
    res += m * m * m;

    m = 0;
    if (k % 2 == 0) {
        for (ll i = 1; i <= n; ++i) {
            if (i % k == k / 2) ++m;
        }
    }
    res += m * m * m;

    cout << res << endl;

    return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <cstring>

using namespace std;

int n;
int m;
const int maxn = 2e5 + 5;
int a[maxn], b[maxn];
int vis[maxn];

int main(){
    cin >> n >> m;
    memset(vis, 0, sizeof(vis));
    for(int i = 1;i <= m;i++){
       scanf("%d%d", &a[i], &b[i]);
        if(a[i] == 1) 
            vis[b[i]]++;
        if(b[i] == n)
            vis[a[i]]++;
    }
    bool flag = false;
    for(int i = 2;i < n;i++){
        if(vis[i] >= 2){
            flag = true;
        }
    }
    if(flag)
        cout << "POSSIBLE" << endl;
    else
        cout << "IMPOSSIBLE" << endl;
    return 0;
}


Measured memory_bytes: 2560
#include <stdio.h>

int main()
{
    int time,h,m,s;
    
    scanf("%d",&time);
    
    h = time / 3600;
    m = (time - 3600 * h) / 60;
    s = (time - 3600 * h - 60 * m);
    printf("%d:%d:%d\n",h,m,s);
    return 0;
}


Measured memory_bytes: 2104
// Undone
#include <bits/stdc++.h>
#define int long long
#define double long double
#define INF 1e18
using namespace std;
signed main() {
  int X, A; cin >> X >> A;
  if (X < A) {
    cout << 0 << endl;
  } else {
    cout << 10 << endl;
  }
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define int long long int
#define pb push_back
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define vvi vector<vector<int>>
#define vi vector<int>
#define f first
#define s second
using namespace std;
const int mod = 1e9 + 7;
int logi(int n) {int p = 0; while (n / 2) {n = n / 2; p++;} return p;}
int poww(int x, int y) {int pro = 1; while (y) {if (y & 1)pro = ((pro % mod) * (x % mod) % mod); y = y >> 1; x = ((x % mod) * (x % mod) % mod);} return pro;}
int poww2(int x, int y) {int pro = 1; while (y) {if (y & 1)pro = pro * x; y = y >> 1; x = x * x;} return pro;}
bool isprime(int n) { if (n == 1) return false; for (int i = 2; i <= sqrt(n); i++) if (n % i == 0) return false; return true;}
vector<vector<int>> adj(2e5);
vi dist(2e5, INT_MAX);
/*

*/

int solve() {
	string s, t;
	cin >> s >> t;
	int ans = INT_MAX;
	for (int i = 0; i <= s.size() - t.size(); i++)
	{
		int k = 0, cnt = 0;
		for (int j = i; j < i + t.size(); j++)
		{
			if (s[j] != t[k])cnt++;
			k++;
		}
		ans = min(ans, cnt);
	}
	cout << ans;
	return 0;
}
int32_t main() {
	/*#ifndef ONLINE_JUDGE
	    //for getting input from input.txt
	    freopen("input.txt","r",stdin);
	    //for writing output to output.txt
	    freopen("output.txt","w",stdout);
	#endif*/
	fast;
	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}
	return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<string> s(n);
    vector<int> ans(4);

    rep(i,n) {
        cin >> s.at(i);
    }
    rep(i,n) {
        if (s.at(i) == "AC") {
            ans.at(0)++;
        } else if  (s.at(i) == "WA") {
            ans.at(1)++;
        } else if  (s.at(i) == "TLE") {
            ans.at(2)++;
        } else if  (s.at(i) == "RE") {
            ans.at(3)++;
        }
    }

    cout << "AC x " << ans.at(0) << endl;
    cout << "WA x " << ans.at(1) << endl;
    cout << "TLE x " << ans.at(2) << endl;
    cout << "RE x " << ans.at(3) << endl;

    return 0;
}

Measured memory_bytes: 6420
while True:
  H,W=map(int,input().split())
  if(W==0 and H==0):
    break
  for i in range(H):
    for j in range(W):
      if(i==0 or i==H-1):
        print("#",end="")
      elif(i!=0 and i!=H-1 and j==0 or j==W-1):
          print("#",end="")
      else:
          print(".",end="")
    print()
  print()


Measured memory_bytes: 7000
# -*- coding: utf-8 -*-
import numpy as np

n = int(input())

a = []
for i in range(n):
    a.append(int(input()))

a_s = sorted(a, reverse=True)
a_max = a_s[0]
a_max_2 = a_s[1]

for i in range(n):
    if a[i] != a_max:
        print(a_max)
    else:
        print(a_max_2)


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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int N;
  std::cin >> N;

  std::cout << (N + 1) / 2 << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <cmath>
#include <cstdint>
#include <deque>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <queue>

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

  int n;
  cin >> n;
  unordered_map<int, vector<pair<int, uint64_t>>> edges;
  for (int i = 1; i < n; i++) {
    int from, to, weight;
    cin >> from >> to >> weight;
    edges[from].emplace_back(make_pair(to, weight));
    edges[to].emplace_back(make_pair(from, weight));
  }
  int q, k;
  cin >> q >> k;

  vector<uint64_t> dist(n + 1);
  typedef pair<uint64_t, int> queue_entry;    // dist, vertex
  priority_queue<queue_entry,
                 std::vector<queue_entry>,
                 std::greater<queue_entry>> queue;
  queue.push(make_pair(0, k));  // starting point
  while (!queue.empty()) {
    auto entry = queue.top();
    queue.pop();
    uint64_t current_dist = entry.first;
    dist[entry.second] = current_dist;

    auto edge = edges.find(entry.second);
    for (auto& entry : edge->second) {
      if (dist[entry.first] == 0 && entry.first != k) {
        queue.push(make_pair(current_dist + entry.second, entry.first));
      }
    }
  }

  for (int i = 0; i < q; i++) {
    int x, y;
    cin >> x >> y;
    cout << dist[x] + dist[y] << "\n";
  }
}


Measured memory_bytes: 15888
//ABC121C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int n, m;
	cin >> n >> m;
	vector<pair<long long int,long long int>> p;
	long long int sigma = 0;
	for(int i=0;i<n;i++){
		int a, b;
		cin >> a >> b;
		p.emplace_back(a,b);
	}
	sort(p.begin(),p.end());
	while(m > 0){
		for(int i=0;i<n;i++){
			long long int num = min(p.at(i).second,m);
			sigma += p.at(i).first*num;
			m -= num;
		}
	}
	cout << sigma << endl;
	return 0;
}

Measured memory_bytes: 2420
#include <iostream>
using namespace std;
long long g(long long l){
    return ((long long)1 << (l+2)) - 3;
}
long long h(long long l){
    return ((long long)1 << (l+1)) - 1;
}
long long f(long long n, long long x){
    long long r = 0, y = x;
    if(x <= 1)return 0;
    if(x == 1)return 1;
    if(x >= g(n)-1)return h(n);
    if(x >= g(n-1)+2){
        r = 1;
        r += h(n-1);
        r += f(n-1, x-g(n-1)-2);
    }else if(x == g(n-1)+1){
        r = h(n-1);
    }else{
        r = f(n-1, x-1);
    }
    return r;
}
int main() {
    long long n, x;
    cin >> n >> x;
    cout << f(n, x) << endl;
	return 0;
}

Measured memory_bytes: 256
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let mut cnt = vec![0; N];
    for _ in 0..N-1 {
        let A: usize = sc.get::<usize>() - 1;
        cnt[A] += 1;
    }
    for i in cnt {
        println!("{}", i);
    }
}


Measured memory_bytes: 2760
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  long long n, x, d;
  cin >> n >> x >> d;
  if (d == 0) {
    cout << (x == 0LL ? 1 : n + 1) << '\n';
    return 0;
  }
  if (d < 0) d *= -1, x *= -1;
  auto calc_sum = [&] (long long x) -> long long {return x * (x + 1) / 2; };
  map<long long, vector<pair<long long, long long>>> mp;
  for (long long i = 0; i <= n; i++) {
    long long l = (x * i - (x * i % d + d) % d) / d + calc_sum(i - 1);
    long long r = (x * i - (x * i % d + d) % d) / d + calc_sum(n - 1) - calc_sum(n - i - 1);
    mp[(x * i % d + d) % d].emplace_back(l, r);
  }
  long long ans = 0;
  for (auto& m : mp) {
    sort(m.second.begin(), m.second.end());
    long long l = m.second[0].first, r = m.second[0].second;
    for (int i = 1; i < (int) m.second.size(); i++) {
      if (r < m.second[i].first) {
        ans += r - l + 1;
        l = m.second[i].first;
        r = m.second[i].second;
      } else {
        r = max(r, m.second[i].second);
      }
    }
    ans += r - l + 1;
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 22144
#include <iostream>
#include <algorithm>
#include <string>
using namespace std;
#define int long long
int a[114514], b[114514], h, w;
signed main() {
	cin >> h >> w;
	for (int i = 0; i < h; i++)cin >> a[i]; sort(a, a + h);
	for (int i = 0; i < w; i++)cin >> b[i]; sort(b, b + w);
	int p = 0, ans = 0, sum = 0;
	for (int i = 0; i < h; i++) {
		while (a[i] > b[p]) {
			sum += b[p];
			p++;
		}
		ans += sum + (w - p)*a[i];
	}
	cout << ans << endl;
}


Measured memory_bytes: 4660
#include <iostream>
#include <vector>
#include <queue>
#include<map>
#include<algorithm>
#define rep(i,n) for(int i = 0;i < n;i++)
#define req(i,n) for(int i = 1; i<=n;i++)
#define ALL(a) a.begin(),a.end()
using namespace std;
struct cake {
    int w, d, area, turn;
    cake(int w_,int d_,int turn_)
        :w(w_),d(d_),area(w_*d_),turn(turn_){}
    bool operator <(const cake& c) const{
        if (turn != c.turn) { return turn < c.turn; }
        return area < c.area;
    }
};
vector<cake> cakes;
int main() {
    int n, w,d;
    while (cin >> n >> w >> d, w) {
        int turn = 0, p, s; cakes.clear();
        cakes.push_back(cake(w, d, turn));
        rep(i, n) {
            cin >> p >> s; p--; turn++;
            cake piece = cakes[p];
            cakes.erase(cakes.begin() + p);
            int diff = s, k = 1;
            for (; diff > 0; k++) diff -= (k % 2) ? piece.w : piece.d;
            diff *= -1;
            if (k % 2) {
                int d1 = piece.d - diff, d2 = diff;
                cakes.push_back(cake(piece.w, d1, turn));
                cakes.push_back(cake(piece.w, d2, turn));
            }
            else {
                int w1 = piece.w - diff, w2 = diff;
                cakes.push_back(cake(w1, piece.d, turn));
                cakes.push_back(cake(w2, piece.d, turn));
            }sort(ALL(cakes));
        }vector<int> ans;
        rep(i, cakes.size()) ans.push_back(cakes[i].area);
        sort(ALL(ans));
        rep(i, ans.size()) {
            if (i) cout << " ";
            cout << ans[i];
        }cout << endl;
    }
}


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

#define int             long long int
#define ff              first
#define ss              second
#define pb              push_back

#define vi              vector <int>
#define pii             pair <int, int>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))

#define endl            "\n"
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl



template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int M = 1e18;

void solve()
{

	int n;
	cin >> n;
	int f = 1;
	int a[n];
	loop(i, 0, n)
	{
		cin >> a[i];
		if (a[i] == 0) f = 0;
	}
	if (f == 0)
	{
		cout << 0 << endl;
		return;
	}
	long double sum = a[0];
	loop(i, 1, n)
	{
		sum = sum * a[i];
		if ( sum > (long double)1e18 )
		{
			cout << -1 << endl;
			return ;
		}
	}
	//cout << sum << endl;
	cout << fixed << setprecision(0) << sum << endl;

	return;
}


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


	int t = 1;
	//cin >> t;
	while (t--) solve();

	return 0;
}


Measured memory_bytes: 4584
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define _DEBUG
#include "bits/stdc++.h"
#define CHOOSE(a) CHOOSE2 a
#define CHOOSE2(a0,a1,a2,a3,a4,x,...) x
#define debug_1(x1) cout<<#x1<<": "<<x1<<endl
#define debug_2(x1,x2) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<endl
#define debug_3(x1,x2,x3) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<endl
#define debug_4(x1,x2,x3,x4) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<endl
#define debug_5(x1,x2,x3,x4,x5) cout<<#x1<<": "<<x1<<", "#x2<<": "<<x2<<", "#x3<<": "<<x3<<", "#x4<<": "<<x4<<", "#x5<<": "<<x5<<endl
#ifdef _DEBUG
#define debug(...) CHOOSE((__VA_ARGS__,debug_5,debug_4,debug_3,debug_2,debug_1,~))(__VA_ARGS__)
#else
#define debug(...)
#endif
#define rep(index,num) for(int index=0;index<(int)num;index++)
#define rep1(index,num) for(int index=1;index<=(int)num;index++)
#define brep(index,num) for(int index=(int)num-1;index>=0;index--)
#define brep1(index,num) for(int index=(int)num;index>0;index--)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=(ll)1e+18+1;
int INF=1e+9+1;
int A[1000001];
int insu[1000001]={};
bool prime_factor_decomp(ll n) {
    ll m = n;
    for (ll i = 2; i * i <= n; i++) {
        if (m % i != 0) continue;
        int c = 0;
        while (m % i == 0) c++, m /= i;
        insu[i]++;
		if(insu[i]>=2) return 0;
        //e.push_back(c);
    }
    if (m > 1) {
        insu[m]++;
		if(insu[m]>=2) return 0;
        //e.push_back(1);
    }
	return 1;
    //return mp(p, e);
}
ll gcd(ll x,ll y){
	if(y==0) return x;
	return gcd(y,x%y);
}
int main(){
	int N;
	scan(N);
	rep(i,N) scan(A[i]);
	bool flag=1;
	rep(i,N){
		if(A[i]!=1){
			bool f=prime_factor_decomp(A[i]);
			if(f==0){
				flag=0;
				break;
			}
		}
	}
	if(flag){
		prin("pairwise coprime");
	}
	else{
		int g=0;
		rep(i,N) g=gcd(g,A[i]);
		if(g==1) prin("setwise coprime");
		else prin("not coprime");
	}
	return 0;
}


Measured memory_bytes: 7780
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var one = nextIntArray();
	var A = one[0];
	var B = one[1];
	var C = one[2];
	var D = one[3];
	var turn = true;
	while(A > 0 && C > 0){
		if(turn){
			C -= B;
			turn = false;
		}else{
			A -= D;
			turn = true;
		}
	}
	if(A <= 0){
		myout("No");
	}else{
		myout("Yes");
	}
}

Measured memory_bytes: 29636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int A,B;
    cin>>A>>B;

    if(A>B && A !=1 && B!=1)
        cout<<"Alice"<<endl;
    else if(A<B && A !=1 && B!=1)
        cout<<"Bob"<<endl;
    else if(A==B)
        cout<<"Draw"<<endl;
    else if(A ==1 && B!=1)
        cout<<"Alice"<<endl;
    else if(A!=1 && B==1)
        cout<<"Bob"<<endl;

    return 0;

}


Measured memory_bytes: 256
#include <iostream>

int Fib[45];

int main(){
  int n;
  std::cin >> n;
  Fib[0]=Fib[1]=1;

  for(int i=2; i<=n; i++){
    Fib[i] = Fib[i-1]+Fib[i-2];
  }
  std::cout << Fib[n] << std::endl;

  return 0;
}



Measured memory_bytes: 3128
#include<iostream>
 
using namespace std;
 
int main( void ){
    int n, r;
    cin >> n >> r;
    int ans = 0;
    if( n >= 10 ){
         ans = r;
    }else{
        int tmp = 100 * ( 10 - n );
        ans = r + tmp;
    }
    cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl; 
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

//超数学最高
/*
まずa1<=a2<=...<=anを仮定すると
an-a1>1ならNOを出していい
Var{a1,a2,..an}をa1~anの猫の色の種類数とすると
Var{a1,a2,...an}=xとする。
a1=Var{a2,...an}=if a1 is unique then x-1 else x
an=Var{a1,...a(n-1)}=if an is unique then x-1 else x
a1<=anより
(a1,an)=(x-1,x) or (x-1,x-1) or (x,x)以外ありえない
よって最大値と最小値の差が2以上ならそもそも構築不可能

ここで数列aの値がすべてxの時
x+1<n<2*x  ->No
n=x+1,n>=2*x  ->Yes
である。
n=x+1なら
{a1,...an}={1,2,3,...,x+1}と構築すればいいし
n=2*xなら
{a1,...an}={1,1,2,2,3,3,...x,x}と構築し、nがそれ以上なら
既出の色を追加すればいい。
逆にそれ以外の時は構築できないことは自明。

ここで数列aの値がx-1とxのとき
{a1,...an}={x-1,x-1,...x,x,...x}の時
わからんわクソ
*/

int main(){
    int n;
    cin>>n;
    vector<int> a(n);
    rep(i,n) cin>>a[i];
    sort(ALL(a));
    if(a[n-1]-a[0]>=2){
        cout<<"No"<<endl;
        return 0;
    }
    if(a[n-1]==a[0]){
        int x=a[0];
        if(x+1<n&&n<2*x){
            cout<<"No"<<endl;
        }
        else{
            cout<<"Yes"<<endl;
        }
        return 0;
    }
    else{
        int x=0;
        rep(i,n){
            if(a[0]==a[i]) x++;
        }
        int y=n-x;
        if(x==a[n-1]-1){
            cout<<"Yes"<<endl;
            return 0;
        }
        if(2*(a[n-1]-x)<=y&&x<a[n-1]){
            cout<<"Yes"<<endl;
            return 0;
        }
    }
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 640
from collections import deque
n, m = map(int, input().split())
fiend_memo = [[] for _ in range(n + 1)]
for _ in range(m):
    a, b = map(int, input().split())
    fiend_memo[a].append(b)
    fiend_memo[b].append(a)
#print(fiend_memo)
make_group = []
ans = 0
d = deque()
d.append(1)
seen = {}
# seen[1] = 1
for person in range(1, n + 1):
    cnt = 0
    if person not in seen.keys():
        d.append(person)
        seen[person] = 1
        cnt += 1
    while d:
        now_person = d.popleft()
        for next_person in fiend_memo[now_person]:
            if next_person not in seen.keys():
                d.append(next_person)
                seen[next_person] = 1
                cnt += 1
    ans = max(ans, cnt)
print(ans)

Measured memory_bytes: 128124
n,k = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]

if len(x) == 1:
    print(abs(x[0]))
else:
    ans = 10 ** 9
    for i in range(n-k+1):
        tmp = min(abs(x[i]), abs(x[i+k-1]))
        ans = min(ans,tmp+abs(x[i+k-1]-x[i]))
    print(ans)


Measured memory_bytes: 14568
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author EDGE
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskB solver = new TaskB();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskB {
        public void solve(int testNumber, FastReader in, PrintWriter out) {

            long a = in.nextLong(), b = in.nextLong(), k = in.nextLong();

            if (k >= a) {
                k = k - a;
                a = 0;
            } else {
                a = a - k;
                k = 0;
            }

            if (k != 0) {
                if (k >= b) {
                    b = 0;
                    k = k - b;
                } else {
                    b = b - k;
                }
            }

            out.println(a + " " + b);
        }

    }

    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        public long nextLong() {
            return Long.parseLong(next());
        }

    }
}



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

int main() {
    string s;
    cin >> s;
    cout << s[0] << s.size() - 2 << s[s.size() - 1] << endl;
    return 0;
}

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

int main() {
	int n,m,i,j,k,ans=0,cur;
	cin >> n;
	string s;
	cin >> s;
	ans=1;
	for(i=0; i<n-1; i++){
		if(s[i]!=s[i+1]){
			ans++;
		}
	}
	cout << ans;
}

Measured memory_bytes: 512
package main

import (
	"fmt"
)

func main() {
	var K int
	fmt.Scanf("%d", &K)
	x, epq := 1, 1
	for i := 0; i < K; i++ {
		fmt.Printf("%d\n", x)
		x += epq
		sx := 0
		for y := x; y != 0; y /= 10 {
			sx += y % 10
		}
		//fmt.Printf("%d, %d, %d\n", x, sx, x-epq*sx)
		if x > epq*sx {
			epq *= 10
			x -= x % epq
			for j := 1; j < epq; j *= 10 {
				x += 9 * j
			}
		}
	}
	return
}


Measured memory_bytes: 512
import java.io.*
import java.util.*

import kotlin.Comparable

fun solve(N: Int, M: Int, a: IntArray, b: IntArray){
    data class Range(val a: Int, val b: Int) : Comparable<Range> {
        override fun compareTo(other: Range) = this.b - other.b
    }
    val ranges = (0 until M).map{ Range(a[it], b[it])}.sortedBy{ it.b }
    val destroyed = TreeSet<Int>()
    for(range in ranges){
        destroyed.ceiling(range.a)?: destroyed.add(range.b - 1)
    }
    println(destroyed.size)
    return
}



fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    val M = sc.next().toInt()
    val a = IntArray(M)
    val b = IntArray(M)
    for (i in 0 until M) {
        a[i] = sc.next().toInt()
        b[i] = sc.next().toInt()
    }
    solve(N, M, a, b)
}



Measured memory_bytes: 57056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,mod=1e9+7;
ll n,k,ans[N];
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    n=3;
    scanf("%lld",&k);
    ll res=0;
    for(int i=k;i>=1;i--)
    {
        ans[i]=(ans[i]+qpow(k/i,n))%mod;
        res=(res+ans[i]*i)%mod;
        for(int j=1;j*j<=i;j++)
            if(i%j==0)
            {
                if(j!=i)
                    ans[j]=(ans[j]-ans[i])%mod;
                if(i/j!=j&&i/j!=i)
                    ans[i/j]=(ans[i/j]-ans[i])%mod;
            }
    }
    res=(res+mod)%mod;
    printf("%lld\n",res);
}


Measured memory_bytes: 3828
#include<bits/stdc++.h>
            #define ll long long
            #define f   first
            #define s   second
            #define pb          push_back
            #define mod        1000000007
            #define mod1       1000000009
            #define hell        998244353
            #define inf         1000000000000000000LL
            #define pi          3.14159265358979323
            //#define N           100005 
            const int N=1000005;
            using namespace std;
            ll n,k,sum,q,res,m,val,ans;
            ll x,y;
            double p;
            ll xx[]={1,0,-1,0};
            ll yy[]={0,1,0,-1};
            void solve()    
            {   
                cin>>n>>m;
                ll deg[n+1]={0};
                for(int i=0;i<m;i++)
                {
                    cin>>x>>y;
                    deg[x]++;
                    deg[y]++;
                }
                for(int i=1;i<=n;i++)
                    cout<<deg[i]<<"\n";

            }
            int main()  
            {   ios_base::sync_with_stdio(false);
                cin.tie(0);cout.tie(0);
                ll t=1;  
                //cin>>t;
                 for(ll i=1;i<=t;i++)
                    solve();
                

            }            

Measured memory_bytes: 3564
from itertools import product
N,M = list(map(int, input().split()))

A = [[0] * N for i in range(M)]

for i in range(M):
  L = list(map(int, input().split()))
  for a in L[1:]:
    A[i][a-1] = 1
    
P = list(map(int, input().split())) 

ans = 0
for X in list(product([0,1], repeat=N)):
  flg = True
  for i in range(M):
    work = 0
    for j in range(N):
      work += A[i][j] * X[j]
      
    if work % 2 == P[i]:
      continue
    else:
      flg = False
      break
  if flg:
    ans += 1
    
print(ans)


Measured memory_bytes: 3188
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n; std::cin >> n;
    std::vector<int> d(n);
    for (int i = 0; i < n; i++) std::cin >> d[i];
    std::sort(d.begin(), d.end());
    std::cout << d[n / 2] - d[n / 2 - 1] << std::endl;
    return 0;
}

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

const ll MAXN = 200000;
const ll INF = 1001001001;

ll N, M, ans=0, tmp=-1;
priority_queue<pair<ll,ll>, vector<pair<ll,ll>>, greater<pair<ll,ll>>> S;

signed main(){
    cin >> N >> M;
    for(int i=0;i<M;i++) {
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        S.push(make_pair(b,a));
    }
    while(!S.empty()) {
        pair<ll,ll> p = S.top();
        S.pop();
        if(tmp<=p.second) {
            tmp = p.first;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2420
// This file is a "Hello, world!" in C++ language by GCC for wandbox.
#include <iostream>
#include <cstdlib>
using namespace std ;

int main()
{
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    int x3 = x2 + (y1 - y2);
    int y3 = y2 + (x2 - x1);
    int x4 = x1 - (y2 - y1);
    int y4 = y1 + (x2 - x1);
    
    cout << x3 << " " << y3 << " " << x4 << " " << y4 << endl;   
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>*/
 
#define pll              pair <long long,long long>
#define pb               push_back
#define ll               long long
#define ff               first
#define ss               second
#define D(x)             cerr<<#x " = "<<(x)<<endl
#define vll              vector <ll>
#define IOS              ios_base::sync_with_stdio(0); cin.tie(NULL);
#define endl             '\n'   
using namespace std;
int main()
{
    IOS
     // freopen("input.txt","r",stdin);
     // freopen("output.txt","w",stdout);
     // freopen("error.txt","w",stderr);
      ll n,k;
      cin>>n>>k;
      multiset<ll>st;
      for(ll i=0;i<n;i++)
      {
         ll x;
         cin>>x;
         st.insert(x);
      }
      ll ans=0;
      for(ll i=0;i<k;i++)
      {
        ans+=*st.begin();
        st.erase(st.begin());
      }
      cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3704
#include<bits/stdc++.h>
using namespace std ;
signed main() {
  int n ; cin >> n ; int cnt = 0 ;
  for(register int i = 1 ; i <= n ; i ++)
    if(i & 1) cnt ++ ;
  double ans = cnt * 1.000 / n ;
  cout << fixed << setprecision(7) << ans << endl ;
  return 0 ;
}

Measured memory_bytes: 256