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

#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define eb emplace_back

using ll = long long;
using vll = vector<ll>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using P = pair<int, int>;

ll gcd(ll x, ll y){
    return y ? gcd(y, x%y) : x; 
}

vector<pair<ll, int>> factorize(ll n){
    vector<pair<ll, int>> ans;
    if(n == 1) return ans;
    for(ll i = 2; i*i <= n; i++){
        int cnt = 0;
        while(n%i == 0){
            cnt++;
            n /= i;
        }
        if(cnt) ans.eb(i, cnt);
    }
    if(n != 1) ans.eb(n, 1);
    return ans;
}

void Main(){
    int n; cin >> n;
    vi a(n); 
    ll g;
    vector<vector<pair<ll, int>>> f(n);
    rep(i, n) {
        cin >> a[i];
        if(i == 0) g = a[i];
        else g = gcd(g, a[i]);
        f[i] = factorize(a[i]);
    }
    if(g != 1) {
        cout << "not coprime" << endl;
        return;
    }
    map<int, int> seen;
    rep(i, n){
        for(auto [p, e] : f[i]){
            if(seen[p] == 1){
                cout << "setwise coprime" << endl;
                return;
            }else{
                seen[p] = 1;
            }
        }
    }    
    cout << "pairwise coprime" << endl;
    return;
}

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

Measured memory_bytes: 164740
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int D = sc.nextInt();
		int count = sc.nextInt();
		for (int i=0;i<N;i++) {
			int temp = sc.nextInt();
			for (int j=1;j<=D;j+=temp) {
				count ++;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 36124
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define all(a) a.begin(), a.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;

const int mx = 100000;
vector<int> graph[mx];
int ver[mx], dis[mx], col[mx];
int dp[mx][11];

void splatter(int v, int d, int c){
    if(dp[v][d] != 0)return;
    dp[v][d] = c;
    if(d == 0)return;
    splatter(v, d - 1, c);
    for(int u : graph[v]){
        splatter(u, d - 1, c);
    }
}

int main(){

    int N, M;
    cin >> N >> M;
    rep(i, M){
        int a, b;
        cin >> a >> b;
        a--; b--;
        graph[a].push_back(b);
        graph[b].push_back(a);
    }

    int Q;
    cin >> Q;
    rep(i, Q){
        cin >> ver[i] >> dis[i] >> col[i];
        ver[i]--;
    }

    for(int i = Q - 1; i >= 0; i--){
        splatter(ver[i], dis[i], col[i]);
    }

    rep(i, N){
        cout << dp[i][0] << endl;
    }
    
}

Measured memory_bytes: 12024
#include <map>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <stdio.h>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <iostream>
#include <queue>
#include <set>

#define ll long long
#define sf(a) scanf("%lld",&a)
#define pf(b) printf("%lld",b)
#define sp printf(" ")
#define nw printf("\n")
#define mp make_pair
#define pi pair<ll,ll>
#define f first
#define s second
#define pb push_back
#define sor(v) sort(v.begin(),v.end())
#define rev(v) reverse(v.begin(),v.end())
#define fast ios_base::sync_with_stdio(false)
using namespace std;

ll num(ll x,ll y,ll d)
{
   return (y/d)-((x-1)/d);
}
int main()
{
   ll a,b,c,d;
   cin>>a>>b>>c>>d;
   ll t=b-a+1;
   ll v=0;
   v+=num(a,b,c);
   v+=num(a,b,d);
   v-=num(a,b,(c*d)/__gcd(c,d));
   ll ans=t-v;
   pf(ans);
}

Measured memory_bytes: 3640
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int c = scan.nextInt();
		int b = scan.nextInt();
		int d = scan.nextInt();
		int left = (a>=b)?a:b;
		int right = (c<=d)?c:d;
		int inter = (right - left >= 0)?right - left:0;
		System.out.println(inter);
	}
}

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

int main(){
   int n; cin >> n; int h=0; int a;
   vector<float> v;
   while(h<n){
     cin >> a;
       v.push_back(a);
     h++;
   }
float ans;
sort(v.begin(),v.end());
 
  ans = (v[0]+v[1])/2;
   for(int i=2; i<n; i++){
       ans = (v[i]+ans)/2;
   }

cout << ans << endl;
return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int num,s[12],p[12],check[10000],i,j,count;
    while (1) {
        scanf("%d",&num);
        if (num==0) break;
        count=0;
        for (i=0; i<num; i++) scanf("%d",&s[i]);
        for (i=0; ; i++) {
            for (j=1; j<=12; j++) check[j]=0;
            for (j=0; j<num; j++) check[s[j]]++;
            for (j=0; j<num; j++) p[j]=check[s[j]];
            for (j=0; j<num; j++) {
                if (s[j]!=p[j]) break;
            }
            if (j==num) {
                break;
            } else {
                for (j=0; j<num; j++) s[j]=p[j];
            }
        }
        printf("%d\n",i);
        for (i=0; i<num; i++) {
        	if (i) printf(" ");
        	printf("%d",s[i]);
        }
        printf("\n");
    }
    return 0;
}

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

int main()
{
	int a500,b100,c50,x;
	int sum, ans=0;

	cin >> a500 >> b100 >> c50 >> x;

	for(int i=0;i<=a500;i++)
	{
		for(int j=0;j<=b100;j++)
		{
			for(int k=0;k<=c50;k++)
			{
				sum = 500 * i + 100 * j + 50 * k;
				if(sum == x)
				{
					ans++;
				}
			}

		}

	}

	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back

int main(){
    int A,B,M;
    cin >> A >> B >> M;
    vector<i64> a(A), b(B);
    vector<i64> x(M), y(M), c(M);
    rep(i, A) cin >> a[i];
    rep(i, B) cin >> b[i];
    rep(i, M) cin >> x[i] >> y[i] >> c[i];

    i64 ans = *min_element(all(a)) + *min_element(all(b));
    for(int i = 0; i < M; i++){
        ans = min(ans, a[x[i]-1] + b[y[i]-1] - c[i]);
    }

    cout << ans << endl;
}


Measured memory_bytes: 4224
#include <cstdio>

using namespace std;

#define SIEVE_UPPER     100000

int primes[SIEVE_UPPER + 5];
bool pflag[SIEVE_UPPER + 5];
int p;

void sieve() {
    p = 0;
    for (int i = 2; i <= SIEVE_UPPER; ++i) {
        if (!pflag[i])
            primes[p++] = i;

        for (int j = 0; j < p && i * primes[j] <= SIEVE_UPPER; ++j) {
            pflag[i * primes[j]] = true;
            if (i % primes[j] == 0)
                break;
        }
    }
}

int ans[100005];

void solve() {
    sieve();

    pflag[1] = true;
    for (int i = 1; i <= 100000; ++i) {
        if ((i & 1) == 0)
            ans[i] = ans[i - 1];
        else {
            if (!pflag[i] && !pflag[(i + 1) / 2])
                ans[i] = ans[i - 1] + 1;
            else
                ans[i] = ans[i - 1];
        }
    }
}

int main(int argc, char* argv[]) {
    solve();

    int q;
    scanf("%d", &q);
    while (q--) {
        int left, right;
        scanf("%d%d", &left, &right);
        printf("%d\n", ans[right] - ans[left - 1]);
    }

    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
vector<ll> p,c;
ll D,G;
const ll INF = ll(1e18)+5;
ll ans;
vector<bool> used;

void dfs(int t){
    if(t == D){
        // for(int i=0;i<D;i++){
        //     cerr <<"i="<<i <<"used=" << used[i] << endl;
        // }
        // score計算 Gを満たせたらansの値と比較して....
        ll sum =0;
        ll temp =0;
        for(int i=0;i<D;i++){
            if(used[i]){
                sum += ((i+1)*p[i] * 100 + c[i]);
                temp += p[i];
            }
            
        }
        // cerr <<"sum=" << sum <<"temp=" << temp << endl;
        if(sum>=G){
            ans = min(ans,temp);
            return;
        }
        for(int i=D-1;i>=0;--i){
            if(used[i]){
                continue;
            }
            for(int j=0;j<p[i]-1;j++){
                sum += (i+1)*100;
                temp++;
                if(sum>=G){
                    // cerr <<"temp=" << temp << endl;
                    ans = min(ans,temp);
                    return;
                }
            }
        }
        return;
    }
    
    dfs(t+1);
    used[t] = true;
    dfs(t+1);
    used[t] = false;
}

int main() {
    ans = INF;
    cin >> D >>G;
    used.resize(D,false);
    for(int i=0;i<D;i++){
        ll a,b;
        cin >> a >>b;
        p.push_back(a);
        c.push_back(b);
    }
    dfs(0);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.InputMismatchException;
import java.io.IOException;
import java.io.InputStream;

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

    static class TaskA {
        public void solve(int testNumber, FastScanner in, PrintWriter out) {
            int r1 = in.nextInt() * in.nextInt();
            int r2 = in.nextInt() * in.nextInt();
            out.println(Math.max(r1, r2));
        }

    }

    static class FastScanner {
        private InputStream in;
        private byte[] buffer = new byte[1024];
        private int bufPointer;
        private int bufLength;

        public FastScanner(InputStream in) {
            this.in = in;
        }

        private int readByte() {
            if (bufPointer >= bufLength) {
                if (bufLength == -1)
                    throw new InputMismatchException();

                bufPointer = 0;
                try {
                    bufLength = in.read(buffer);
                } catch (IOException e) {
                    throw new InputMismatchException();
                }

                if (bufLength <= 0)
                    return -1;
            }
            return buffer[bufPointer++];
        }

        private static boolean isSpaceChar(int c) {
            return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
        }

        public long nextLong() {
            long n = 0;

            int b = readByte();
            while (isSpaceChar(b))
                b = readByte();

            boolean minus = (b == '-');
            if (minus)
                b = readByte();

            while (b >= '0' && b <= '9') {
                n *= 10;
                n += b - '0';
                b = readByte();
            }

            if (!isSpaceChar(b))
                throw new NumberFormatException();

            return minus ? -n : n;
        }

        public int nextInt() {
            long n = nextLong();

            if (n < Integer.MIN_VALUE || n > Integer.MAX_VALUE)
                throw new NumberFormatException();

            return (int) n;
        }

    }
}



Measured memory_bytes: 21332
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <unordered_map>
#include <algorithm>
#include <functional>
#include <numeric>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <cassert>
#define bogo_sort std::sort
#define bozo_sort std::stable_sort
#define alles(obj) obj.begin(), obj.end()
#define elif else if
#define unless(flg) if(!(flg))
#define elless(flg) else if(!(flg))
#define echo std::cout <<
#define read std::cin >>
#define endl std::endl
#define fin << '\n'
#define bash push_back
#define makePair std::make_pair
#define _ << ' ' <<
// type-define
#define Stack std::stack
#define Queue std::queue
#define Set std::set
#define PQueue std::priority_queue
#define Vector std::vector
#define Pair std::pair
#define Map std::map
#define HashMap std::unordered_map
#define Greater std::greater
using String = std::string;
using llong = long long;
using boolean = bool;
using Pii = Pair<int, int>;
using Vi = Vector<int>;
using Vii = Vector<Pii>;
// utils
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr llong LINF = 0x3f3f3f3f3f3f3f3fLL;

namespace {
    template<class A, class B> A power ( llong x, llong n, llong mod ) {
        llong ans = 1;
        while ( n > 0 ) {
            if ( n & 1 ) ans = ( ans * x ) % mod;
            x = ( x * x ) % mod;
            n >>= 1;
        }
        return ans;
    }
    template<class A, class B> A power ( A x, B n ) { return power( x, n, 1000000007 ); }
    template<class A> A gcd ( A x, A y ) { return x % y ? gcd( y, x % y ) : y; }
    template<class A, class B> A lcm ( A x, B y ) { return ( x / gcd(x, y) * y ); }
    template<class A> inline A abs ( A n ) { return ( n < 0 ) ? -n : n; }
    template<class A, class B> inline bool chmax ( A &a, const B &b ) { return b > a ? a = b, true : false; }
    template<class A, class B> inline bool chmin ( A &a, const B &b ) { return b < a ? a = b, true : false; }
    boolean isMovable ( int x, int y, int w, int h ) {
        return ( x >= 0 && y >= 0 && x < w && y < h );
    }
}

namespace Rlyeh {

    Vi vi;

    signed call_of_Cthulhu( signed datum ) {

        int n;
        read n;
        for ( int i = 0; i < n; i++ ) {
            int a;
            read a;
            vi.bash(a);
        }

        bozo_sort(alles(vi));
        int s = 0;
        for ( int i = 0; i < n-1; i++ ) {
            s += vi[i];
        }
        if ( s <= vi[n-1] ) {
            echo "No" fin;
        }
        else echo "Yes" fin;

        return 0;
    }
}
signed main(){std::cin.tie(0); std::ios::sync_with_stdio(false); int main_result = Rlyeh::call_of_Cthulhu(114514); return 0;}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define mod 998244353
#define fi first
#define se second
#define pii pair<int,int>
#define int long long
#define endl '\n'
#define pll pair<long long,long long>
#define LONGLONG_MAX 100000000000000
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long power(long long a,long long b){
    long long ans=1;
    while(b>0){
        if(b&1){ans=(ans*a)%mod;}
                a=(a*a)%mod;
                b>>=1;
        }
    return ans;
        
}
double dp[303][303][303];
bool b[303][303][303];
double fun(int i,int j,int k,int n){
    if(i<0||j<0||k<0)return 0;
    if(i==0&&j==0&&k==0)return 0;
    if(b[i][j][k])return dp[i][j][k];
    double ans=n;
    b[i][j][k]=true;
    ans+=(i)*fun(i-1,j+1,k,n);
    ans+=j*fun(i,j-1,k+1,n);
    ans+=k*fun(i,j,k-1,n);
    ans/=(i+j+k);
    return dp[i][j][k]=ans;
}
int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;
    cin>>n;
    memset(b,false,sizeof(b));
    int a[3]={0};
    for(int i=0;i<n;i++){
        int x;
        cin>>x;
        x--;
        a[x]++;
    }
    cout<<fixed<<setprecision(12)<<fun(a[2],a[1],a[0],n);
    return 0;
}

Measured memory_bytes: 243968
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    cout << fixed << setprecision(10);
    double n,k;
    cin >> n >> k;
    double ans = 0;
    for(int i = 1;i <= (int)n; i++){
        int now = i;
        int cnt = 0;
        while(now < k){
            cnt++;
            now *= 2;
        }
        ans += 1/n*pow(0.5,cnt);
    }
    cout << ans << endl;
    return 0;
}

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

int main() {

  int y, m, d;
  int yd[5] = { 1868, 1912, 1926, 1989, 99999 };
  int md[5] = {    9,    7,   12,    1,     0 };
  int dd[5] = {    8,   30,   25,    8,     0 };
  string n[4] = { "meiji", "taisho", "showa", "heisei" };

  while( cin >> y >> m >> d ) {

    for ( int i = 0; i < 5; i++ ) {

      if ( y < yd[i] || ( y == yd[i] && ( m < md[i] || ( m == md[i] && d < dd[i] ) ) ) ) {
	if ( i == 0 ) {
	  cout << "pre-meiji" << endl;
	  break;
	}else {
	  cout << n[i-1] << " " << y - yd[i-1] + 1 << " " << m << " " << d << endl;
	  break;
	}
      }

    }

  }

  return 0;

}

Measured memory_bytes: 1204
# 169a
# A×Bを求めてください

# 1.入力をプログラムで扱えるように受け取ること
a, b = map(int, input().split())
# print(a , b)

# 2.受け取った入力値を使って、適切に処理(計算)すること
answer = a * b

# 3.計算した結果を出力すること 
print(answer)



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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int h,w;
    while(cin>>h>>w, h!=0){
        rep(i,h){
            rep(j,w){
                if (i==0||i==h-1||j==0||j==w-1) cout<<"#";
                else cout<<".";
            }
            cout<<"\n";
        }
        cout<<"\n";
    }
    return 0;
}



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

int A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W;
double X, Y, Z;

int run(){
    
    int i, j, k, l, m, n;
    char *S;
    
    scanf("%d", &N);
    S = (char *)malloc(sizeof(char)*(N+3));
    scanf("%d", &A);
    scanf("%d", &B);
    scanf("%d", &C);
    scanf("%d", &D);
    scanf("%s", S);
    
    A--;
    B--;
    C--;
    D--;
    
    S[A] = 'A';
    S[B] = 'B';
    
    S[N] = '#';
    S[N+1] = '#';
    S[N+2] = '\0';
    // printf(":: %s", S);
    
    if(C < D){
        for(i = A; i < C; i++){
            if(S[i+1]!='#') continue;
            if(S[i+1]=='#'){
                i++;
                if(S[i+1]=='#') return 1;
            }
        }
        if(i!=C) return 11;
        for(i = B; i < D; i++){
            if(S[i+1]!='#') continue;
            if(S[i+1]=='#'){
                i++;
                if(S[i+1]=='#') return 2;
            }
        }
        if(i!=D) return 12;
        return 0;
    }else{
        for(i = B; i < D; i++){
            if(S[i+1]!='#') continue;
            if(S[i+1]=='#'){
                i++;
                if(S[i+1]=='#') return 3;
            }
        }
        if(i!=D) return 13;
        int alpha = 1;
        int beta = 0;
        for(i = A; i < C; i++){
            if(S[i+1]!='#'){
                alpha++;
                if(alpha > 2) if(i < D+1)  if(B-1 < i) beta = 1;
                continue;
            }
            if(S[i+1]=='#'){
                alpha = 0;
                i++;
                if(S[i+1]=='#') return 4;
                alpha++;
            }
        }
        if(i!=C) return 14;
        if(beta==0){
            if((S[A+1]=='B') && (S[A+2]=='.')) return 0;
            return 5;
        }
        return 0;
    }
}

int main(){
    int ret = run();
    if(ret==0) printf("Yes");
    else printf("No");
    
    // printf("(%d)\n", ret);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;
typedef long double lb;
typedef pair<int,int> P;
const int MOD = 1000000007;
const ll INF = 1e16;
const double EPS = 1e-10;
const double PI = 3.141592653589793;
template<class T> inline bool chmin(T& a, T b){if(a>b){a = b;return 1;}return 0;}
template<class T> inline bool chmax(T& a, T b){if(a<b){a = b;return 1;}return 0;}
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 
#define int long long
#define double long double

////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////

int n,a[110000];int x[3],ans;
signed main(){
  cin>>n;rep(i,n)cin>>a[i];
  x[0] = x[1] = x[2] = 0;ans = 1;
  rep(i,n){
    int cnt = 0;
    rep(j,3){
      if(x[j] == a[i]){
        cnt++;
        if(cnt == 1){
          x[j]++;
        }else if(cnt == 0){
          cout << 0 << endl;
          return 0;
        }
      }
    }
    ans = ans * cnt % MOD;
  }
  cout << ans << endl;
}


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

int main() {
  int n;
  cin >> n;
  vector<int> x(n + 1, 0);
  for (int i = 1; i <= n; i++) {
    for (int j = i; j <= n; j += i) {
      x[j]++;
    }
  }
  ll ans = 0;
  for (ll i = 1; i <= n; i++) {
    ans += i * x[i];
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 42292
#include <iostream>
#include <array>

#define FOR(i, a, b) for(int (i) = (a); (i) < (b); ++(i))
#define REP(i, n) FOR(i, 0, n)

using lli = long long int;

template <int N, long long int mod>
struct CombinationMod{
private:
    using lli = long long int;
public:
    lli Power[N+1], Inverse[N+1], powInverse[N+1];
    // std::array<lli, N+1> Power{};
    // std::array<lli, N+1> Inverse{};
    // std::array<lli, N+1> powInverse{};

    constexpr CombinationMod(){
        Power[0] = 1; Inverse[0] = 1; powInverse[0] = 1;
        for(int x = 1; x <= N; ++x){
            Power[x] = (Power[x-1] * x) % mod;
            Inverse[x] = inverse(x);
            powInverse[x] = (powInverse[x-1] * Inverse[x]) % mod;
        }
    }
    constexpr void swap(lli &a, lli &b) const {
        a ^= b; b ^= a; a ^= b;
    }
    constexpr lli inverse(lli a) const noexcept{
        lli b = mod, u = 1, v = 0;
        while (b != 0) { 
            lli t = a / b; a -= t * b; swap(a, b);
            u -= t * v; swap(u, v);
        }
        u %= mod; if (u < 0) u += mod;
        return u;
    }
    // nCkを求める関数 : n < k の入力に注意せよ
    inline lli combination(int n, int k) const noexcept{
        if(n < k) return 0;
        return ((Power[n] * powInverse[k] % mod) * powInverse[n-k]) % mod;
    }
};

constexpr int mod = 1e9 + 7;
constexpr int MAX_SIZE = 2000;
using theComb = CombinationMod<MAX_SIZE, mod>;
constexpr theComb Com;

int main(void){
    int n, k; scanf("%d%d", &n, &k);
    REP(i, k){
        lli s = Com.combination(k-1, i);
        lli t = Com.combination(n-k+1, i+1);
        printf("%lld\n", (s * t) % mod);
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;

int main() {
	int N, K;
	cin >> N >> K;
	if(K!=1)cout << (N - K);
	else cout << 0;
}/*
	int T, N, now = 0, ans = 0;
	bool flag = false;
	cin >> T >> N;
	vector<int>t(N);
	for (int i = 0; i < N; i++)cin >> t[i];
	sort(t.begin(), t.end());
	int s = 0;
	while (s!=N-1) {
		if (now >= t[s])s++;
		else flag = true;
		if (flag) {
			now = t[s++]+T;
			ans += T;
			flag = false;
		}
	}
	cout << ans + T << endl;*/

Measured memory_bytes: 256
import sys
N=int(input())
S=list(input())
mod=10**9+7
data=[0]*2*N
if S[0]=="W":
    print(0)
    sys.exit()
data[0]=-1
for i in range(1,2*N):
    if S[i]==S[i-1]:
        data[i]=-data[i-1]
    else:
        data[i]=data[i-1]
if data[-1]==-1:
    print(0)
    sys.exit()
lst=[0]*2*N
lst[-1]=data[-1]
for i in range(2*N-2,-1,-1):
    lst[i]=lst[i+1]+data[i]
ans=1
for i in range(2*N-1,-1,-1):
    if data[i]==-1:
        ans=ans*(lst[i]+1)%mod
count=0
for i in range(2*N):
    if data[i]==1:
        count+=1
if count!=N:
    print(0)
    sys.exit()
for i in range(1,N+1):
    ans=ans*i%mod
print(ans)

Measured memory_bytes: 63216
N = int(input())
F, P = [], []
for _ in range(N):
    F.append(list(map(int, input().split())))
for _ in range(N):
    P.append(list(map(int, input().split())))

ans = float('-inf')
for i in range(1, 2**10):
    flags = [0] * 10
    for i, c in enumerate(bin(i)[2:][::-1]):
        if c == "1":
            flags[i] = 1

    res = 0
    for f, p in zip(F, P):
        cnt = 0
        for x, y in zip(f, flags):
            if x & y:
                cnt += 1
        res += p[cnt]
    ans = max(ans, res)
print(ans)

Measured memory_bytes: 3064
#include <stdio.h>
int main()
{
    int arr[3][3], row, col, n, i, b, j=0;
    for(row=0; row<3; row++){
        scanf("%d %d %d", &arr[row][0], &arr[row][1], &arr[row][2]);
    }
    scanf("%d", &n);
    int r0=0, r2=0, r1=0, c0=0, c2=0, c1=0, d1=0, d2=0;
    for(i=0; i<n; i++){
        scanf("%d", &b);
        for(row=0; row<3; row++){
            for(col=0; col<3; col++){
                if(arr[row][col]==b){
                    if(row==0) r0++; 
                    else if(row==1) r1++;
                    else if(row==2) r2++;
                    if(col==0) c0++;
                    else if(col==1) c1++;
                    else if(col==2) c2++;
                    if(row==col) d1++;
                    if((row==2 && col == 0) || (row==0 && col==2) || (row==col)) d2++;
                }
                if(r0==3 || r2==3 || r1==3 || c0==3 || c2==3 || c1==3 || d1==3 || d2==3){
                    printf("Yes");
                    return 0;
                }
            }
        }
    }
    printf("No");
    return 0;
}

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

using namespace std;


int main()
{
	int n;
  	cin >> n;
  	if(n%10 == 2 or n%10== 4 or n%10==5 or n%10==7 or n%10==9){
    cout<<"hon";
    }
  	else if(n%10 == 0 or n%10== 1 or n%10== 6 or n%10== 8){
    cout<<"pon";
    }
  	else{
    cout<<"bon";
    }
	return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<utility>
#include<set>
#include<stack>
#include<list>
#include<deque>
#include<bitset>
#include<iomanip>
#include<cstring>
#include<sstream>
#include<cstdio>
#include<cstdlib>
#include<climits>
#include<cmath>
#include<cctype>


#define pb push_back
#define mp make_pair
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define ren(i,a,b) for(int i=a;i>=b;i--)
#define ff first
#define ss second
#define pll pair<long long int,long long int>
#define pii pair<int,int>
#define vll vector<long long int>
#define vii vector<int>
#define gi(n) scanf("%d",&n)
#define gll(n) scanf("%lld",&n)
#define gstr(n) scanf("%s",n)
#define gl(n) cin >> n
#define oi(n) printf("%d",n)
#define oll(n) printf("%lld",n)
#define ostr(n) printf("%s",n)
#define ol(n) cout << n
#define os cout<<" "
#define on cout<<"\n"
#define o2(a,b) cout<<a<<" "<<b
#define all(n) n.begin(),n.end()
#define present(s,x) (s.find(x) != s.end())
#define cpresent(s,x) (find(all(s),x) != s.end())
#define tr(container, it) for(__typeof(container.begin()) it = container.begin(); it != container.end(); it++)
using namespace std;

typedef unsigned long long int ull;
typedef long long int ll;
typedef vector<vector<ll> > mat;

int main()
{ios_base::sync_with_stdio(false);
int n;
string s,t;
cin>>n>>s>>t;
if(s==t)
{
	ol(n);
	return 0;
}
ren(i,n-1,0)
{
	string ans=s+t.substr(i,n-i);
	if(ans.substr(ans.length()-n,n)==t)
	{
		ol(ans.length());
		return 0;
	}
}
return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

struct UnionFind{
    vector<ll> par;
    vector<ll> siz;
    UnionFind(ll N): par(N),siz(N,1LL){
        rep(i,N)par[i]=i;
    }
    void init(ll N){
        par.resize(N);
        siz.assign(N,1LL);
        rep(i,N)par[i]=i;
    }

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

    ll size(ll x){
        return siz[root(x)];
    }
    bool unite(ll x,ll y){
        ll rx = root(x);
        ll ry = root(y);
        if(rx==ry) return false;
        if(siz[rx]<siz[ry])swap(rx,ry);
        siz[rx]+=siz[ry];
        par[ry] = rx;
        return true;
    }
    bool same(ll x,ll y){
        ll rx = root(x);
        ll ry = root(y);
        return rx==ry;
    }
};


int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n,m;
cin>>n>>m;
int k,l;
UnionFind u(n+m);
rep(i,n){
    cin>>k;
    rep(j,k){
        cin>>l;
        u.unite(i,l+n-1);
    }
}
bool ok=true;

reps(j,n,1){
    if(!u.same(0,j)){
        ok=false;
        break;
    }
}
if(ok)cout<<"YES"<<endl;
else cout<<"NO"<<endl;
//system("pause");
return 0;
}

Measured memory_bytes: 3456
#include <vector>
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <numeric>
using namespace std;

int main(){
    int a,b,c=1000;
    cin >> a;
    if(a==1){
        cout << 1;
        return 0;
    }
    if(a==2){
        cout << 2;
        return 0;
    }
    if(a==3){
        cout << 3;
        return 0;
    }
    for(int i=2;;i++){
        b=1;
        for(int j=1;;j++){
            b*=i;
            if(b>a&&j>=3){
                c=min(a-(b/i),c);
                break;
            }else if(b>a&&j<3){
                break;
            }
        }
        if(i>a){
            break;
        }
    }
    cout << a-c;
}

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

using namespace std;
typedef long double lld;
const int maxn = 1e6 + 5;
int a[maxn], dp[maxn];
int main() {
//    freopen("in.in", "r", stdin);
    int n, k;
    cin >> n >> k;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    for (int i = 1; i <= k; i++) {
        for (int j = 1; j <= n; j++) {
            if (i >= a[j] && dp[i - a[j]] == 0) {
                dp[i] = 1;
            }
        }
    }
    if (dp[k]) {
        cout << "First" << endl;
    } else {
        cout << "Second" << endl;
    }
    return 0;
}

Measured memory_bytes: 2688
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<map>
#include<math.h>
#include<queue>
#include<deque>
#include<stack>
#include<cstdio>
#include<utility>
#include<set>
#include<list>
#include<cmath>
#include<stdio.h>
#include<string.h>
#include<iomanip>
#include<cstdio>
#include<cstdlib>
#include<cstring>
using namespace std;
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define REP(i, n) FOR(i, 0, n - 1)
#define NREP(i, n) FOR(i, 1, n)
using ll = long long;
using pii = pair<int, int>;
using piii = pair<pii, pii>;
const ll dx[4] = { 0, -1, 1, 0 };
const ll dy[4] = { -1, 0, 0, 1 };
const int INF = 1e9 + 7;
int gcd(int x, int y) {
	if (x < y)swap(x, y);
	if (y == 0)return x;
	return gcd(y, x%y);
}
void mul(ll a, ll b) {
	a = a * b % INF;
}
///////////////////////////////////////


int main() {
	int N, M;
	string s[101], t[101];
	cin >> N;
	for (int i = 0; i < N; ++i)cin >> s[i];
	cin >> M;
	for (int i = 0; i < M; ++i)cin >> t[i];
	map<string, int>ma;
	for (int i = 0; i < N; ++i) {
		ma[s[i]]++;
	}
	for (int i = 0; i < M; ++i) {
		ma[t[i]]--;
	}
	int ans = 0;
	for (auto itr = ma.begin(); itr != ma.end();++itr) {
		ans = max(ans, itr->second);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int a,b,c,k;
  cin >> a >> b>> c >> k;
  if(a+b <= k){
    cout << a + (k-(a+b))*(-1) << endl;
    return 0;
  }else{
    cout << k << endl;
    return 0;
  }
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#include <math.h>

int main() {

	long long N, K;
	int A[200100];
	int list_place[200100];
	int list_is_visited[200100];
	for (int i = 0; i < 200100; i++) {
		list_is_visited[i] = 0;
	}
	int ans, loop, start_loop_time;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	int place = 1;
	list_place[0] = 1;
	list_is_visited[1] = 1;

	for (int i = 0; i < N+2; i++) {
		place = A[place-1];
		list_place[i + 1] = place;

		if (list_is_visited[place] != 0) {
			loop =  (i + 2) - list_is_visited[place];
			start_loop_time = list_is_visited[place];
			break;
		}
		else {
			list_is_visited[place] = i + 2;
		}
	}

	if (K < start_loop_time) {
		ans = list_place[K];
	}
	else {
		ans = list_place[(K -start_loop_time + 1) % loop + start_loop_time - 1];
	}

	cout << ans<<endl;

	cin >> N;

	return 0;


}

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

using namespace std;

int main()
{
   string s1,s2,g;
   int b1,b2;
   cin>>s1>>s2>>b1>>b2>>g;
   if(g==s1)cout<<(b1-1)<<" "<<b2<<endl;
   else cout<<b1<<" "<<(b2-1)<<endl;
   return 0;

}


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

int d, t, s;

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> d >> t >> s;
    if (t*s >= d) cout << "Yes\n";
    else cout << "No\n";
    return 0;
}


Measured memory_bytes: 3644
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll h,s=0,sum=1;
	cin>>h;
	while(h>=2){
        h/=2;
        s++;
	}
	for(int i=1;i<=s;i++){
        sum=sum*2+1;
	}
	cout<<sum;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	char str[101];
	int a[7], i;
	for(i = 0; i < 6; ++i) {
		scanf("%d", &a[i]);
	}
	scanf("%s", str);
	int bottom = a[5], top = a[0], sideA = a[1], sideB = a[2], sideC = a[4], sideD = a[3], sth;
	for(i = 0; str[i] != '\0'; ++i) {
		if(str[i] == 'N') {
			sth = top;
			top = sideA;
			sideA = bottom;
			bottom = sideC;
			sideC = sth;
		}
		if(str[i] == 'E') {
			sth = sideB;
			sideB = top;
			top = sideD;
			sideD = bottom;
			bottom = sth;
		}
		if(str[i] == 'S') {
			sth = bottom;
			bottom = sideA;
			sideA = top;
			top = sideC;
			sideC = sth;
		}
		if(str[i] == 'W') {
			sth = sideD;
			sideD = top;
			top = sideB;
			sideB = bottom;
			bottom = sth;
		}
	}
	printf("%d\n", top);
	return 0;
}

	

	


Measured memory_bytes: 2112
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<set>
#include<vector>
#include<ctime>
#define ll long long
#define pr(x) cerr<<#x<<"="<<x<<endl
#define inf 100000000000
#define N 510000
#define md 1000000007
using namespace std;
ll ex[N],cnt,size,l[N],r[N],n,m,tmp,i,dp[N],q[N],head,tail,j,sum;
struct node 
{
	ll v,x;
}a[N];
bool cmp(node x,node y)
{
	return x.x<y.x;
}
void init()
{
	sort(ex+1,ex+1+cnt);
	size=unique(ex+1,ex+1+cnt)-ex-1;
	sort(ex+1,ex+1+size);
	for (ll i=1;i<=n;i++) 
	l[i]=upper_bound(ex+1,ex+1+size,l[i])-ex-1,r[i]=upper_bound(ex+1,ex+1+size,r[i])-ex-1;
}
int main()
{
	scanf("%lld",&n);
	for (i=1;i<=n;i++)
	{
		scanf("%lld %lld",&a[i].x,&a[i].v);
	}
	sort(a+1,a+1+n,cmp);
	for (i=1;i<=n;i++) tmp=max(tmp,a[i].v),r[i]=tmp;
	tmp=inf;for (i=n;i>=1;i--) tmp=min(tmp,a[i].v),l[i]=tmp;
	for (i=1;i<=n;i++) ex[++cnt]=a[i].v;
	init();
	//for (i=1;i<=n;i++) printf("%lld %lld\n",l[i],r[i]);
	dp[0]=1;
	n++;l[n]=r[n]=n;
	q[++tail]=0;sum=1;
	for (i=1;i<=n;i++) 
	{
		while (head!=tail&&r[q[head+1]]<l[i]-1) sum=(sum-dp[q[head+1]]+md)%md,head++;
		dp[i]=sum;
		sum=(sum+dp[i])%md;
		q[++tail]=i;
	}
	printf("%lld\n",dp[n]%md);
	return 0;
}

Measured memory_bytes: 24832
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <iomanip>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define repr(e,x) for(auto& e:x)
using namespace std;
typedef long long ll;

int N;
int D[51];
int T[24];

int main(){
    cin>>N;
    rep(i,N) cin>>D[i];
    D[N]=0;
    sort(D,D+N+1);

    rep(i,N+1){
        if(i&1){
            T[(24-D[i])%24]++;
        }else{
            T[D[i]]++;
        }
    }

    int ans=1001001;
    int sum=1001001;
    rep(i,25){
        if(T[i%24]==1){
            ans=min(ans,sum);
            sum=1;
        }else if(T[i%24]==0){
            sum++;
        }else{
            ans=0;
            break;
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
# import bisect
# from collections import Counter, deque
# import copy
# from heapq import heappush, heappop, heapify
# from fractions import gcd
# import itertools
# from operator import attrgetter, itemgetter
# import math

import sys

# import numpy as np

ipti = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, a, b = list(map(int,ipti().split()))

    if (a - b) % 2 == 1:
        if (a - 1) < (n - b):
            print(a + (b - a - 1) // 2)
        else:
            a, b = n - b + 1, n - a + 1
            print(a + (b - a - 1) // 2)
    else:
        print((b - a)//2)


if __name__ == '__main__':
    main()

Measured memory_bytes: 38384
//g++  7.4.0

#include <iostream>
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXX 1e12
#define MAXN 100005
vector<ll> adj[MAXN];
ll dp[MAXN];
ll vis[MAXN];
ll ans = 0;

void DFS(ll s)
{
    vis[s] = 1;
    for(auto it: adj[s])
    {
        ll v = it;
        if(!vis[v])
            DFS(v);
        
        dp[s] = max(dp[s],dp[v] + 1);
        ans = max(ans,dp[s]);
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll N,M; cin>>N>>M;
    for(ll i=0;i<M;++i)
    {
        ll u,v; cin>>u>>v;
        adj[u].push_back(v);
    }
    
    for(ll i=1;i<=N;++i)
    {
        if(!vis[i])
            DFS(i);
    }
    
    cout<<ans<<endl;
}

Measured memory_bytes: 13220
#![allow(unused_imports)]
#![allow(clippy::many_single_char_names)]

// language: Rust(1.42.0)
// check available crates on AtCoder at "https://atcoder.jp/contests/language-test-202001"
// My Library Repo' is at "https://github.com/Loptall/prcn_lib"

/*
    6月で水色になるぞ〜!!!
*/

// from std...
use std::cmp::{
    max, min,
    Ordering::{Equal, Greater, Less},
    Reverse,
};
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
use std::mem::swap;
use std::ops::*;
use std::process::exit;
use std::{f32, f64, i128, i16, i32, i64, i8, isize, u128, u16, u32, u64, u8, usize};

// Dep' crates are...
use itertools::*;
use itertools_num::*;
use lazy_static::lazy_static;
use maplit::{btreemap, btreeset, hashmap, hashset};
use num_bigint::{BigInt, BigUint};
use num_complex::Complex;
use num_integer::{binomial, gcd, lcm, Integer};
use num_rational::Rational;
use num_traits::{clamp, one, pow, zero, One, Pow, Zero};
use permutohedron::Heap;
use petgraph::unionfind::UnionFind;
use proconio::{fastout, input, is_stdin_empty, marker::*};
use rand::random;

pub const MOD: usize = 1000000007;
pub const MAX: usize = 1usize << 63usize;
pub const MIN: i64 = i64::MIN;
pub const PI: f64 = f64::consts::PI;
pub const A: u8 = 'A' as u8;

// code...
// #[fastout]
fn main() {
    input! {
        s: Chars,
        t: Chars
    }

    let mut ans = 0usize;
    for i in 0..s.len() {
        if s[i] != t[i] {
            ans += 1;
        }
    }
    println!("{}", ans)
}


Measured memory_bytes: 3932
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())

struct UnionFind {
    UnionFind() {}
    UnionFind(int n) {
        resize(n);
    }
    
    void resize(int n) {
        par.resize(n, -1);
    }
    
    int root(int x) {
        if (par[x] < 0) return x;
        return par[x] = root(par[x]);
    }
    
    bool merge(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return false;
        if (par[rx] > par[ry]) swap(rx, ry);
        par[rx] += par[ry];
        par[ry] = rx;
        return true;
    }
    
    bool is_same(int x, int y) {
        return (root(x) == root(y));
    }
    
    int size(int x) {
        return -par[root(x)];
    }
    
private:
    vector<int> par;
};

template<class T>
struct MinimumSpanningTree {
    MinimumSpanningTree() {}
    MinimumSpanningTree(int n) {
        vertex_count = n;
    }
    
    void resize(int n) {
        vertex_count = n;
    }
    
    void add_edge(int from, int to, T cost) {
        edges.emplace_back((Edge){from, to, cost});
    }
    
    T get_total_cost() {
        sort(edges.begin(), edges.end(), [&](const Edge &a, const Edge &b) {
            return a.cost < b.cost;
        });
        UnionFind uf(vertex_count);
        T ans = 0;
        for (int i = 0, lc = (int)edges.size(); i < lc; i++) {
            if (uf.is_same(edges[i].from, edges[i].to)) continue;
            uf.merge(edges[i].from, edges[i].to);
            ans = ans + edges[i].cost;
        }
        return ans;
    }
    
private:
    struct Edge {
        int from, to;
        T cost;
    };
    
    int vertex_count = 0;
    vector<Edge> edges;
};

struct City {
    ll id, x, y;
};

ll get_distance(const City &a, const City &b) {
    return min(abs(a.x - b.x), abs(a.y - b.y));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll n;
    cin >> n;
    vector<City> city(n);
    rep(i, n) {
        cin >> city[i].x >> city[i].y;
        city[i].id = i;
    }
    MinimumSpanningTree<ll> mst(n);
    sort(all(city), [](const City &a, const City &b){ return a.x < b.x; });
    rep(i, n - 1) {
        ll cost = get_distance(city[i], city[i + 1]);
        mst.add_edge(city[i].id, city[i + 1].id, cost);
    }
    sort(all(city), [](const City &a, const City &b){ return a.y < b.y; });
    rep(i, n - 1) {
        ll cost = get_distance(city[i], city[i + 1]);
        mst.add_edge(city[i].id, city[i + 1].id, cost);
    }
    ll ans = mst.get_total_cost();
    cout << ans << endl;
    return 0;
}


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

typedef long long ll;
typedef int64_t i6;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rep2(i, n) for (ll i = 1; i <= n; ++i)
#define ALL(v) (v).begin(), (v).end()
#define Sort(x) sort(ALL(x))
#define Sort_rev(x) Sort(x);reverse(ALL(x))

template<typename V,typename T>
T find_num(V v, T num) {
    if ( find(ALL(v), num) == v.end() ) {
        return false;
    } else {
        return true;
    }
}

// π M_PI
// deg = rad*180/M_PI

int main() {
    ll n, m, k;
    cin >> n >> m >> k;
    cout << k << " " << n << " " << m << endl;
    return 0;
}


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

int main() {
  string c;
  cin >> c;
  if(c =="a" || c == "e" || c == "i" || c == "o" || c == "u"){
    cout << "vowel" << endl;
  }
  else{
    cout << "consonant" << endl;
  }
}


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

namespace ConsoleApp15
{
    class Class286
    {
        static void Main()
        {
            var NM = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int N = NM[0], M = NM[1];

            bool[] c = new bool[N];
            c[0] = true;
            int[] count = Enumerable.Repeat(1, N).ToArray();
            
            for(int i = 0; i < M; i++)
            {
                var xy = Console.ReadLine().Split().Select(z => int.Parse(z) - 1).ToArray();
                int x = xy[0], y = xy[1];
                if (count[x] > 0)
                {
                    count[y]++;
                    count[x]--;
                    c[y] |= c[x];
                    if (count[x] == 0) c[x] = false;
                }
                
            }
            Console.WriteLine(c.Count(z=>z==true));
        }
    }
}


Measured memory_bytes: 17996
#include <bits/stdc++.h>
#define INF (1<<30)
#define MOD 1000000007
#define l_ength size
#define BLACK 1
#define WHITE 0
using ll = long long;
using namespace std;

int main(){
	
	int H, W;
	cin >> H >> W;
	
	int gridmap[H][W];
	
	for( int i = 0; i < H; ++i ){
	
		string temp;
		cin >> temp;
		
		for( int j = 0; j < W; ++j ){
			gridmap[i][j] = ( temp[j] == '#' ) ? BLACK : WHITE;
		}
	
	}
	
	array<pair<int, int>, 4> dxy = {make_pair(1, 0), make_pair(-1, 0), make_pair(0, 1), make_pair(0, -1)};
	
	for( int i = 0; i < H; ++i ){
		for( int j = 0; j < W; ++j ){

			if( gridmap[i][j] == BLACK){
				
				bool flag = false;
			
				for( auto d : dxy ){
					
					int dx = j + d.first;
					int dy = i + d.second;
					
					if( dx >= 0 && dx < W && dy >= 0 && dy < H && ( gridmap[dy][dx] == BLACK ) ){
						flag = true;
					}
					
				}
			
				if( !flag ){
					cout << "No" << endl;
					return 0;
				}
				
			}
			
		}
	}
	
	cout << "Yes" << endl;
	return 0;
	
}

Measured memory_bytes: 256
from bisect import bisect_left

N = int(input())
Lli = list(map(int,input().split()))

Lli.sort()

res = 0

for i in range(N-2):
  for j in range(i+1,N-1):
    ab = Lli[i]+Lli[j]
    res += bisect_left(Lli,ab)-j-1
    
print(res)

Measured memory_bytes: 74440
#include <stdio.h>
#include <assert.h>
#include <fstream>
#include <iostream>
#include <algorithm>
#include <array>
#include <vector>
#include <queue>
#include <set>
#include <cmath>
#include <unordered_map>
//#include <unordered_set>
//#include <boost/container/static_vector.hpp>
//#include <boost/unordered_set.hpp>
//#include <boost/unordered_map.hpp>
//#include <unistd.h>

//#include <cv.h>
//#include <highgui.h>
#include <stdlib.h>
#include <time.h>

#include <string>

const int MAX_N = 350;
int N;

std::string S[MAX_N];
bool is_good[MAX_N][MAX_N];

bool calc_is_good(int i, int j) {
    for (int k = 0; k < N; k++) {
        if (S[(i + k) % N][j] != S[i][(j + k) % N]) {
            return false;
        }
    }
    return true;
}

int main(int argc, char **argv) {
    std::cin >> N;

    for (int i = 0; i < N; i++) {
        std::cin >> S[i];
    }

    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            is_good[i][j] = calc_is_good(i, j);
        }
    }

    int ret = 0;
    for (int i = 0; i < N; i++) {
        bool is_all_good = true;
        for (int k = 0; k < N; k++) {
            if (!is_good[k][(i + k) % N]) {
                is_all_good = false;
                break;
            }
        }
        if (is_all_good) {
            ret += N;
        }
    }

    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(inti=a;i<=b;i++)

typedef long long int ll;
typedef vector<int>vi;
typedef pair<int,int>pi;



int main()
{
ll a,b,k;
cin>>a>>b>>k;

cout<<max(0LL,a-k)<<" "<<max(b-(max(0LL,k-a)),0LL)<<endl;
 return 0;
}


Measured memory_bytes: 3640