akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define rep(i, s, n) for (int i = s; i < (int)(n); i++)
typedef long long int ll;
using namespace std;
//分割数
int n, m;
ll dp[2010][2010]; //jのi分割の総数
ll cnt[2010];
const int M = 1000000007;
void solve()
{
    dp[0][0] = 1;
    for (int i = 1; i <= 2000; i++)
    {
        for (int j = 0; j <= 2000; j++)
        {
            if (j - i >= 0)
                dp[i][j] = (dp[i - 1][j] + dp[i][j - i]) % M;
            else
            {
                dp[i][j] = dp[i - 1][j];
            }
        }
    }
    // cout << dp[m][n] << endl;
}

ll f[2010], rf[2010];
ll inv(ll x)
{
    ll res = 1;
    ll k = M - 2;
    ll y = x;
    while (k)
    {
        if (k & 1)
            res = (res * y) % M;
        y = (y * y) % M;
        k /= 2;
    }
    return res;
}
void init()
{
    f[0] = 1;
    rep(i, 1, 2010) f[i] = (f[i - 1] * i) % M;
    rep(i, 0, 2010) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k)
{
    ll a = f[n];      // = n!
    ll b = rf[n - k]; // = (n-k)!
    ll c = rf[k];     // = k!

    ll bc = (b * c) % M;

    return (a * bc) % M;
}

int main()
{
    init();
    int k;
    cin >> n >> k;
    m = n;
    solve();
    ll s = cnt[0];
    for (int i = 1; i <= k; i++)
    {
        if (n - k + 1 < i)
            cout << 0 << endl;
        else
            cout << (C(k - 1, i - 1) * C(n - k + 1, i)) % M << endl;
    }
}

Measured memory_bytes: 31744
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int a[225816],b[225816];
vector<int> v,u;

int main(void){
	int n,i,m;
	cin >> n;
	for(i=0; i<20; ++i){
		if(n==(1<<i)){
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	for(i=1; i<4; ++i){
		v.push_back(i);
	}
	for(i=1; i<4; ++i){
		v.push_back(i+n);
	}
	for(i=4; i+3<=n; i+=4){
		v.push_back(i);
		v.push_back(i+1);
		v.push_back(i+2);
		v.push_back(i+3);
		v.push_back(i+n);
		v.push_back(i+n+1);
		v.push_back(i+n+2);
		v.push_back(i+n+3);

	}
	m = (n/4)*4;
	if(0 < n%4 && n%4 < 3){
		cout << n+m << " " << n+m+1 << endl;
		cout << n+m+1 << " " << 1 << endl;
		cout << 1 << " " << m << endl;
		cout << m << " " << m+1 << endl;
		if(n%4 == 2){
			cout << n+m+1 << " " << n+m+2 << endl;
			cout << m+2 << " " << 2 << endl;
		}
	}else if(n%4==0){
		cout << ((m-4)^m) << " " << (m-4) << endl;
		cout << ((m-4)^m) << " " << n << endl;
		cout << (m-4) << " " << n+n << endl;

	}
	for(i=(v.l_ength()-1); i>0; --i){
		if(n%4==0 && v[i]==(m-4)){
			continue;	
		}
		cout << v[i] << " " << v[i-1] << endl;
	}
	return 0;
}


Measured memory_bytes: 3700
/*
  Lower bound: first element that is greater-or-equal.
  int i=lower_bound(a,a+n,x)-a;
  Upper bound: first element that is strictly greater.
  #include<boost/multiprecision/cpp_int.hpp>
  namespace mp=boost::multiprecision;
  mp::cpp_int u=1; for(unsigned i=1;i<=n;i++) u*=i;
*/
#pragma GCC optimize("O3")  
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*b)/gcd(a,b)
#define mem(z,i) memset(z,i,sizeof(z))
#define eps 1e-7
#define I (int)
const int mod=(int)1e9+7;
const long long INF = 1000000000000000000LL;
const int WASTE=(int)2e5;
int power(int a,int b,int m=mod){
	if(b == 0) return 1;
	if(b == 1) return a;
	int x = power(a,b/2,m)%m;
	x = (x*x)%m;
	if(b%2) return (x*a)%m;
	return x;
}
//#define int long long
const int N=1e5+5;
bool prime[N];
void seive(){
	for(int x=2;x<N;x++){
		if(!prime[x]){
			for(int y=x*2;y<N;y+=x)
				prime[y]=1;
		}
	}
}
signed main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    mem(prime,0);
    seive();
    int a[N];
    a[1]=0;
    for(int x=2;x<N;x++){
    	a[x]=a[x-1];
    	if(x%2){
    		if(!prime[x]&&!prime[(x+1)/2])
    			a[x]++;
    	}
    }
    int q;
    cin>>q;
    while(q--){
    	int x,y;
    	cin>>x>>y;
    	int ans=a[y]-a[x-1];
    	cout<<ans<<endl;
    }
    return 0;	
}

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

int main() {
  int a, b, c;
  cin >> a >> b >> c;
  cout << max(c-a+b,0) << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
 public static void main(String[] args){
   Scanner sc = new Scanner(System.in);
   int n = sc.nextInt();
   String s = sc.next();
   int cntR=0,cntB=0;
   for(int i=0; i<n; ++i) {
     if(s.charAt(i) == 'R') ++cntR;
     else ++cntB;
   }
   if(cntR > cntB)
     System.out.println("Yes");
   else
     System.out.println("No");
 }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define fi first
#define se second
using namespace std;
int main()
{
    int n;
    cin>>n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin>>a[i];
    int ans=0,now=1,len=0;
    while(now<n)
    {
        len=0;
        while(now<n && a[now]<=a[now-1])
            len++,now++;
        ans=max(ans,len);
        now++;
    }
    cout<<ans;
    return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>
#include<set>
 
using namespace std;
 
#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define P(p) cout<<(p)<<endl;
#define p(p) cout<<(p)<<" ";
#define pb push_back
#define mp make_pair
#define INF 1<<25

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

int dy[8]={1,1,1,0,0,-1,-1,-1};
int dx[8]={-1,0,1,-1,1,-1,0,1};
struct S{
	int a,b,c;
};
bool asc(const S& left,const S& right){
	return left.c > right.c;
}
int n,m,l,r;
int a[301][301];
void input(){
	cin>>n>>m;
	rep(i,n){
		rep(j,m){
			cin>>a[i][j];
		}
	}
}

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	input();
	vi ban(301,0);
	int ans=INF;
	rep(i,m){
		vi cnt(301,0);
		rep(j,n){
			rep(k,m){
				if(ban[a[j][k]]!=1){
					cnt[a[j][k]]++;
					break;
				}
			}
		}
		int num=max_element(ALL(cnt))-cnt.begin();
	//	p(num)P(cnt[num]);
		if(cnt[num]<ans){
			ans=cnt[num];
		}
		ban[num]=1;
	}
	P(ans);
	return 0;
}



Measured memory_bytes: 640
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    p,q,r = LI()
    print(p+q+r-max(p,q,r))
    return

#B
def B():
    n = I()
    w = LI()
    ans = float("inf")
    for i in range(n):
        m = sum(w[:i])
        l = sum(w[i:])
        ans = min(ans,abs(m-l))
    print(ans)
    return

#C
def C():
    n,m = LI()
    f = defaultdict(lambda : 1)
    for i in range(m):
        a = I()
        f[a] = 0
    dp = defaultdict(int)
    dp[0] = 1
    for i in range(1,n+1):
        if f[i]:
            dp[i] = dp[i-1]+dp[i-2]
            dp[i] %= mod
    print(dp[n])
    return

#D
def D():
    h,w = LI()
    s = SR(h)

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#Solve
if __name__ == "__main__":
    C()


Measured memory_bytes: 61400
#include <iostream>

using namespace std;

const long long MOD = 1000000007;

long long dp[100010];
bool am[100010];

int main() {
	long long n, m;
	long long a; //一時保存用
	cin >> n >> m;
	for (int i = 0; i < m; ++i) {
		cin >> a;
		am[a] = true;
	}
	
	if (!am[1]) dp[1] = 1;
	if (!am[2]) dp[2] = 1;
	for (int i = 1; i < n; ++i) {
		if (!am[i + 1]) {
			dp[i + 1] += dp[i];
			dp[i + 1] %= MOD;
		}
		if (!am[i + 2]) {
			dp[i + 2] += dp[i];
			dp[i + 2] %= MOD;
		}
	}
	cout << dp[n] % MOD << endl;
	return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;

int main(int argc, char *argv[]) { ios::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);

  ll n;
  cin>>n;
  ll ans=0;
  int cnt=1;
  if(n%2==1){
    cout<<0<<endl;
    return 0;
  }
  while(1){
    ll div=pow(5,cnt)*2;
    if(div>n)break;
    ans += n/div;
    cnt++;
  }
  cout<<ans<<endl;

  
  return 0;
}


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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;


using namespace std;

#if DEBUG && !ONLINE_JUDGE
    #include "debug.h"
#else
    #define debug(...)
#endif

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<vector<int> > vvi;
typedef vector<vector<ii> > vvii;

#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define fill(a,x) memset(a,x,sizeof(a))
#define ff first
#define ss second
#define trav(a, x) for(auto& a : x) 
#define FOR(i,a,b) for(int i = a; i<=b; ++i)
#define NFOR(i,a,b) for(int i = a; i>=b; --i)
#define PI 3.1415926535897932384626433832795
const ll INF = 1e18;
const int mod = 1e9 + 7;
const int N = 1e5;
ll gcd(ll a,ll b){if (a==0) return b;return gcd(b%a,a);}
ll lcm(ll a,ll b){return a*(b/gcd(a,b));}
ll Abs(ll a){if(a>0)return a;return -a;}
ll Ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
double Abs(double a){if(a>0)return a;return -a;}

//*X.find_by_order(2) element at index=2
//X.order_of_key(1) how many elements strictly less than 1

#define ordered_set tree<int, null_type,less_equal<int>, rb_tree_tag,tree_order_statistics_node_update> 

inline int pow_(ll x, ll y,ll p){
  int r = 1; while(y){if(y & 1) r = r * x % p; y >>= 1; x = x * x % p;} return r;
}
inline int inv_(int x){return pow_(x, mod - 2, mod);}
inline int add(int a, int b){a += b; if(a >= mod) a -= mod; return a;}
inline int mul(int a, int b){return a * 1LL * b % mod;}
inline int sub(int a, int b){a -= b; if(a < 0) a += mod; return a;}

int main()
{
    #ifdef LOCAL_TEST
    freopen("in.txt","r",stdin);
    //freopen("out.txt", "w", stdout);
    #else
    ios_base::sync_with_stdio(false);cin.tie(NULL);
    #endif
    int n,m,c;
    cin>>n>>m>>c;
    int b[25]= {0};
    for(int i=1;i<=m;i++)cin>>b[i];
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        ll sum = 0;
        for(int j=1;j<=m;j++)
        {
            int t;
            cin>>t;
            sum += t * b[j];
        }

        sum += c;

        if(sum > 0)
        {
            ans++;
        }  
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <functional>
#include <ctime>
#include <cmath>
#include <limits>
#include <numeric>
#include <type_traits>
#include <iomanip>
#include <float.h>
#include <math.h>
using namespace std;
using ll = long long;

unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

ll ll_gcd(ll a, ll b) {
    if (a < b) return ll_gcd(b, a);
    ll r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

class UnionFind {
public:
    vector <ll> par;
    vector <ll> siz;
    UnionFind(ll sz_) : par(sz_), siz(sz_, 1LL) {
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    void init(ll sz_) {
        par.resize(sz_);
        siz.assign(sz_, 1LL);
        for (ll i = 0; i < sz_; ++i) par[i] = i;
    }
    ll root(ll x) {
        while (par[x] != x) {
            x = par[x] = par[par[x]];
        }
        return x;
    }
    bool merge(ll x, ll y) {
        x = root(x);
        y = root(y);
        if (x == y) return false;
        if (siz[x] < siz[y]) swap(x, y);
        siz[x] += siz[y];
        par[y] = x;
        return true;
    }

    bool issame(ll x, ll y) {
        return root(x) == root(y);
    }

    ll size(ll x) {
        return siz[root(x)];
    }
};

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

long long modinv(long long a, long long mod) {
    return modpow(a, mod - 2, mod);
}

int main() {
    ll aa, b;
    cin >> aa >> b;
    ll ans = 0;
    for (int i = aa; i < b+1; i++) {
        ll a = i;
        ll m = a % 10;
        a /= 10;
        ll mm = a % 10;
        a /= 10;
        ll mmm = a % 10;
        a /= 10;
        ll mmmm = a % 10;
        a /= 10;
        ll mmmmm = a;
        if (m == mmmmm && mm == mmmm)ans++;
    }
    cout << ans << endl;
}

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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using vec_b = vector<bool>;
using vec_str = vector<string>;

#define INF (1LL << 60)
#define MOD 1000000007

#define REP(i,m,n) for(ll (i)=(m),i##_len=(n);(i)<(i##_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define _PR(x) cout << (x) << endl
#define _PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define pb push_back
#define mp make_pair

const double PI=3.14159265358979323846;

int main()
{
    ll A, B, H, M;
    cin >> A >> B >> H >> M;
    double d = 0;

    double angH = H / 6.0 * PI + M / 360.0 * PI;
    double angM = M / 30.0 * PI;
    double hx = -sin(angH) * A;
    double hy = cos(angH) * A;
    double mx = -sin(angM) * B;
    double my = cos(angM) * B;
    double dx = hx - mx;
    double dy = hy - my;
    cout << setprecision(12) << sqrt(dx*dx+dy*dy) << endl;

    return 0;
}

/*



*/

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

string a;

int f(int p, string q) {
	int i;
	if (p + q.size() > a.size()) return -1;
	for (i = 0; i < q.size(); i++) {
		if (a[p + i] != q[i]) return 0;
	}
	return 1;
}

int main()
{
	int i;
	cin >> a;
	for (i = 0; i < a.size();) {
		if (f(i, "dream") == 1) {
			i += 5;
			if (f(i, "er") == 1 && f(i + 2, "a") != 1) i += 2;
		} else if (f(i, "eraser") == 1) {
			i += 6;
		} else if (f(i, "erase") == 1) {
			i += 5;
		} else {
			puts("NO"); return 0;
		}
	}
    cout << "YES";
    return 0;
}

Measured memory_bytes: 512
N,K=map(int,input().split())
MOD=10**9+7
max_n=2000
fac=[1]*(max_n+1)
inv=[1]*(max_n+1)
ifac=[1]*(max_n+1)
for n in range(2,max_n+1):
    fac[n]=(fac[n-1]*n)%MOD
    inv[n]=MOD-inv[MOD%n]*(MOD//n)%MOD
    ifac[n]=(ifac[n-1]*inv[n])%MOD
def comb(n,k):
    if n<k:
        return 0
    if n<0 or k<0:
        return 0
    return (fac[n]*ifac[k]*ifac[n-k])%MOD
for i in range(1,1+K):
    if N-K<i-1:
        print(0)
        continue
    b=max(comb(K-1,i-1),1)
    r=max(comb(N-K+1,i),1)
    print((b*r)%MOD)

Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
#include <vector>
#include <numeric>
#include <map>
#include <cmath>
#include <iomanip>
using ll =long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;

int main(){
    int a, b;
    cin >> a >> b;
    if(a*b %2 ==0){
        cout << "Even" << endl;
    }
    else{
        cout << "Odd" << endl;
    }
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<list>
#include<map>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<vector>
#include<algorithm>
#include<memory.h>
using namespace std;
long long n,m,a[200005],b[200005],c[200005],d[200005];
int main(){
	cin>>n>>m;
	for(int i=1;i<=m;i++){
		cin>>a[i]>>b[i];
		if(a[i]==1)c[b[i]]=1;
		if(b[i]==n)d[a[i]]=1;
	}
	for(int i=1;i<=n;i++){
		if(c[i]==1&&d[i]==1){
			cout<<"POSSIBLE";
			return 0;
		}
	}
	cout<<"IMPOSSIBLE";
	return 0;
}


Measured memory_bytes: 6528
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main() {
  int x, y, z, k;
  cin >> x >> y >> z >> k;
  
  vector<long long> a, b, c;
  for (int i = 0; i < x; i++) {
    long long t;
    cin >> t;
    a.push_back(t);
  }
  
  for (int i = 0; i < y; i++) {
    long long t;
    cin >> t;
    b.push_back(t);
  }
  
  for (int i = 0; i < z; i++) {
    long long t;
    cin >> t;
    c.push_back(t);
  }  

  sort(a.begin(), a.end(), greater<long long>());
  sort(b.begin(), b.end(), greater<long long>());
  sort(c.begin(), c.end(), greater<long long>());

  vector<long long> ab;
  for (int i = 0; i < min(int(a.size()), k); i++) {
    for (int j = 0; j < min(int(b.size()), k); j++) {
      ab.push_back(a[i] + b[j]);
    }
  }
  sort(ab.begin(), ab.end(), greater<long long>());  

  vector<long long> abc;
  for (int i = 0; i < min(int(ab.size()), k); i++) {
    for (int j = 0; j < min(int(c.size()), k); j++) {
      abc.push_back(ab[i] + c[j]);
    }
  }
  
  sort(abc.begin(), abc.end(), greater<long long>());
  for (int i = 0; i < k; i++) {
    cout << abc[i] << '\n';
  }
  
  return 0;
}


Measured memory_bytes: 43300
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#define max(a, b)	(((a) > (b)) ? (a) : (b))		/* ２個の値の最大値 */
#define min(a, b)	(((a) < (b)) ? (a) : (b))		/* ２個の値の最小値 */
#define ENTER		printf("\n")					/* 改行プリント */
int DBG = 1;										/* デバッグプリント 提出時は0 */
/* main *************************************************************/
int main()
{
	int		a,b,c,i,j,k,n,m,x,y,ans = 0;
	char	str[256];
	
	scanf("%d %d", &a, &b);
	scanf("%d %d", &c, &i);

	if (a==c) printf("0\n");
	else printf("1\n");


	return 0;
}


Measured memory_bytes: 128
import           Control.Monad
import           Control.Monad.ST
import qualified Data.Array                    as A
import qualified Data.Array.ST                 as ST
import qualified Data.Array.Unboxed            as AU
import qualified Data.ByteString.Char8         as BS
import           Data.Char
import qualified Data.Foldable                 as DF
import           Data.Int
import qualified Data.IntMap                   as IM
import           Data.List
import qualified Data.Map                      as M
import           Data.Maybe
import           Data.Ord
import qualified Data.Set                      as S
import qualified Data.Sequence                 as SQ
import           Data.Time
import qualified Data.Vector                   as V
import qualified Data.Vector.Mutable           as VM
import qualified Data.Vector.Unboxed           as VU
import qualified Data.Vector.Unboxed.Mutable   as VUM

readInt = map (fst . fromJust . BS.readInt) . BS.words <$> BS.getLine
readInts n = replicateM n readInt
readString = map BS.unpack . BS.words <$> BS.getLine
readStrings n = replicateM n <$> readString
toPair [x, y] = (x, y)

main = do
  [a, b, c, x, y] <- readInt
  print $ solve a b c x y

solve a b c x y = minimum cs
 where
  c' = 2 * c
  cs = map (\ccc -> f a b x y ccc) $ map (\n -> (n, c' * n)) [0 .. max x y]

f a b x y (c, acc) | c >= x && c >= y = acc
                   | c >= x && c < y  = acc + b * (y - c)
                   | c < x && c >= y  = acc + a * (x - c)
                   | otherwise        = acc + a * (x - c) + b * (y - c)


Measured memory_bytes: 892
import itertools

n = int(input())

l = []

for _ in range(n):

    l.append(list(map(int, input().split())))

aaaa = list(itertools.permutations(l , n))


distance = 0
for aa in aaaa:

    for i in range(len(aa)):
        if i != n-1:
            xi = (aa[i][0])
            yi = (aa[i][1])
            xj = (aa[i + 1][0])
            yj = (aa[i + 1][1])

            distance += ( (xi - xj) ** 2 + (yi - yj) ** 2 ) ** 0.5


pattern = len(aaaa)

ans = distance / pattern

print(ans)

Measured memory_bytes: 8052
#3 
N = int(input())
answer = [0]*N
for k in range(1, int(N**(1/2))):
    for l in range(1, int(N**(1/2))):
        for m in range(1, int(N**(1/2))):
            v = k**2 + l**2 + m**2 + k*l + l*m + m*k
            if v-1 < N:
                answer[v-1] += 1
for i in range(N):
    print(answer[i])

Measured memory_bytes: 9428
using namespace std;
#include<bits/stdc++.h>
#define BEGIN ios_base::sync_with_stdio(0);cin.tie(0);
#define END return EXIT_SUCCESS;
#define FOR(I,A,B) for((I)=(A);(I)<(B);(I)++)
#define REP(I,N) FOR((I),0,(N))
#define UP(I,A,B) for((I)=(A);(I)<=(B);(I)++)
#define DW(I,A,B) for((I)=(A);(I)>=(B);(I)--)
#define IN(P) cin>>(P)
#define IN2(P1,P2) cin>>(P1)>>(P2)
#define IN3(P1,P2,P3) cin>>(P1)>>(P2)>>(P3)
#define INS(I,N,V) REP((I),(N)) cin>>(V[I])
#define INS2(I,N,V1,V2) REP((I),(N)) cin>>(V1[I])>>(V2[I]);
#define INS3(I,N,V1,V2,V3) REP((I),(N)) cin>>(V1[I])>>(V2[I])>>(V3[I]);
#define OUT(P) cout<<(P)<<endl
#define OUT2(P1,P2) cout<<(P1)<<" "<<(P2)<<endl
#define OUT3(P1,P2,P3) cout<<(P1)<<" "<<(P2)<<" "<<(P3)<<endl
#define OUTS(I,N,V) REP((I),(N)) cout<<(V[i])<<endl
#define ALL(C) (C).begin(),(C).end()
#define RALL(C) (C).rbegin(),(C).rend()
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}

int W,a,b;
inline void solve(){
  IN3(W,a,b);
  if(a<b)OUT(max(0,b-W-a));
  else if(b+W<a)OUT(max(0,a-W-b));
  else OUT(0);
}

int main(int argc,char**argv){
  BEGIN
  solve();
  END
}


Measured memory_bytes: 256
import java.util.*;


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

        Scanner sc = new Scanner(System.in);
        int num1 = sc.nextInt();
        String symbol = sc.next();
 		int num2 = sc.nextInt();
   		int answer = 0;
      	if (symbol.equals("+")){
      		answer = num1 + num2;
        }else if (symbol.equals("-")){
        	answer = num1 - num2;
        }
      	sc.close();
        System.out.println(answer);
        
    }
}

Measured memory_bytes: 23892
#include "bits/stdc++.h"
using namespace std;
typedef long long li;

li memo[200005];
li f(const li x) {
    if (x == 0) {
        return 0;
    } else {
        if (memo[x]) {
            return memo[x];
        }
        li pp = __builtin_popcountll(x);
        return memo[x] = f(x % pp) + 1;
    }
}

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

    li n;
    cin >> n;
    string s;
    cin >> s;

    li popcount = 0;
    for (int i = 0; i < n; ++i) {
        if (s[i] == '1') {
            popcount++;
        }
    }

    const li up_mod = popcount + 1;
    li up_rem = 0;
    vector<li> up_rems(n);
    {
        li cur = 1;
        for (int i = n - 1; i >= 0; --i) {
            up_rems[i] = cur;
            if (s[i] == '1') {
                up_rem += cur;
            }
            cur *= 2;
            cur %= up_mod;
        }
    }

    const li lo_mod = popcount - 1;
    li lo_rem = 0;
    vector<li> lo_rems(n);
    {
        li cur = 1;
        for (int i = n - 1; i >= 0; --i) {
            lo_rems[i] = cur;
            if (lo_mod == 0) {
                continue;
            }
            if (s[i] == '1') {
                lo_rem += cur;
            }
            cur *= 2;
            cur %= lo_mod;
        }
    }

    vector<li> ans(n);
    for (int i = n - 1; i >= 0; --i) {
        if (s[i] == '1') {
            if (lo_mod == 0) {
                ans[i] = 0;
                continue;
            }
            li rem = lo_rem + (lo_mod - lo_rems[i]);
            rem %= lo_mod;
            ans[i] = f(rem) + 1;
        } else {
            li rem = up_rem + up_rems[i];
            rem %= up_mod;
            ans[i] = f(rem) + 1;
        }
    }

    for (int i = 0; i < n; ++i) {
        cout << ans[i] << '\n';
    }
    return 0;
}

Measured memory_bytes: 8988
#include<iostream>
#include<string>
#include<array>

int main(void) {
	std::array<std::string, 100>arr = {};
	int N;
	int sameword = 0;
	int samechar = 0;
	std::cin >> N;

	for (int i = 0; i < N; i++)
	{
		std::cin >> arr[i];
	}
	//同じモノがあるか判定
	for (int i = 0; i < N; i++)
	{
		for (int j = 0; j < N; j++)
		{
			if (i != j)
			{
				if (arr[i] == arr[j])
				{
					sameword = 1;
				}
			}
		}
	}

	//語尾と語頭が一緒か
	for (int i = 0; i < N - 1; i++)
	{
		if (arr[i].back() != arr[i + 1].front())
		{
			samechar = 1;
		}
	}

	//結果を出力
	if (samechar == 1 || sameword == 1)
	{
		std::cout << "No" << std::endl;
	}

	else if (samechar == 0 && sameword == 0)
	{
		std::cout << "Yes" << std::endl;
	}

}

Measured memory_bytes: 256
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

struct UnionFind {
    parent_or_size: Vec<isize>,
}

impl UnionFind {
    fn new(size: usize) -> UnionFind {
        UnionFind { parent_or_size: vec![-1; size] }
    }

    fn find(&self, index: usize) -> usize {
        let mut index = index;
        while self.parent_or_size[index] >= 0 {
            index = self.parent_or_size[index] as usize;
        }
        index
    }

    fn same(&self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }

    fn unite(&mut self, index0: usize, index1: usize) -> bool {
        let a = self.find(index0);
        let b = self.find(index1);
        if a == b {
            false
        } else {
            if self.parent_or_size[a] < self.parent_or_size[b] {
                self.parent_or_size[a] += self.parent_or_size[b];
                self.parent_or_size[b] = a as isize;
            } else {
                self.parent_or_size[b] += self.parent_or_size[a];
                self.parent_or_size[a] = b as isize;
            }
            true
        }
    }
}


fn main() {
    let nm: Vec<usize> = read_vec();
    let (n, m) = (nm[0], nm[1]);
    let mut p: Vec<usize> = read_vec();
    let mut uft = UnionFind::new(n + 1);
    for _i in 0..m {
        let xy = read_vec::<usize>();
        let (x, y) = (xy[0] - 1, xy[1] - 1);
        uft.unite(x, y);
    }

    let mut ans:i32 = 0;
    for i in 0..p.len() {
        p[i] -= 1;
    }
    for i in 0..p.len() {
        if uft.same(p[i], i) {
            ans += 1;
        }
    }
    println!("{:?}", ans);
}


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

typedef long long ll;
#define pa pair<int, int> 
#define pal pair<long long, long long>
#define pad pair<double, double>
#define pb push_back
#define mp make_pair
#define VIN(v) for(int64_t i=0;i<(v).size();i++){cin >> (v).at(i);}

typedef vector<bool> bvec;
typedef vector<int> ivec;
typedef vector<long long> lvec;
typedef vector<double> dvec;
typedef vector<pa> pvec;

typedef vector< vector<bool> > bmat;
typedef vector< vector<int> > imat;
typedef vector<string> svec;
typedef vector< vector<string> > smat;
const ll infll = (1LL << 60) - 1;
const int inf = (1 << 30) - 1;

ll gcd(ll x, ll y){
    ll r = x%y;
    if(r == 0) return y;
    else return gcd(y, r);
} 

ll lcm(ll x, ll y){
    ll g = gcd(x,y);
    return x*y/g;
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, l=1, cnt=0;
    cin >> n;
    for (size_t i = 0; i < n; i++)
    {
        int a;
        cin >> a;
        if(a==l) l++;
        else cnt++;
    }
    if(cnt==n) cnt=-1;
    cout << cnt << endl;
    
    
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */

import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		// your code goes here
		Scanner sc = new Scanner(System.in);
	    long n = sc.nextLong();
	    int level = 0;
	    while(n > 0){
	    	++level;
	    	n/=2;
	    }
	    long ans = (1L<<level)-1;
		 System.out.print(ans);
		
	}
}

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

#define NIL NULL
struct node{
  int key;
  struct node *p;
  struct node *l;
  struct node *r;
};

typedef struct node *Node;

Node ro;

void delete1(Node k){
	Node a=k->p;
  if(k->r==NIL && k->l==NIL){
  	if(a->l==k)a->l = NIL;
  	else a->r = NIL;
	free(k);
  }else if(k->r==NIL){
  	if(a->l==k){
    	a->l = k->l;
    	k->l->p=a;
  	}else{
		a->r = k->l;
    	k->l->p=a;
	}
	k=NIL;
	free(k);
  }else if(k->l==NIL){
   	if(a->l==k){
    	a->l = k->r;
    	k->r->p=a;
  	}else{
		a->r = k->r;
    	k->r->p=a;
	}
	free(k);
  }else{
   if(k->r!=NIL){
     	a=k->r; 
	  	while(a->l!=NIL)a=a->l;
		k->key=a->key;
		delete1(a);
	  }else{
	  	a=k->p; 
	  	while(a!=NIL && k==a->r){
			k=a;
			a=a->p;
		}
		k->key=a->key;
		delete1(a);
	  }
  }
}

void delete(int k){
  Node x = ro;

  while(x != NIL && x->key!=k){
    if(k < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
  
  if(x== NIL){
  }else{
    delete1(x);
  }
}
Node find(int k,Node node){
  if(node == NIL){
    return node;
  }

  if(node->key == k){
    return node;
  }
  if(node->key > k){
    return find(k , node->l);
  }else{
    return find(k , node->r);
  }
}
void insert(int k){
  Node y = NIL;
  Node x = ro;
  Node z;
  
  z = malloc(sizeof(struct node));
  z->key = k;
  z->l = NIL;
  z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key){
      x = x->l;
    }else{
      x = x->r;
    }
  }
  
  z->p = y;
  if(y == NIL){
    ro = z;
  }else{
  	if(z->key < y->key){
    	y->l = z;
  	}else{
    	y->r = z;
  	}
  }
}

void inorder(Node u){
  if(u == NIL)return;
  inorder(u->l);
  printf(" %d",u->key);
  inorder(u->r);
}

void preorder(Node u){
  if(u == NIL)return;
  printf(" %d",u->key);
  preorder(u->l);
  preorder(u->r);
}

int main(){
  int n,i,j,z,k;
  char s[10];
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%s",s);
    if(s[0] == 'i'){
      scanf("%d",&z);
      insert(z);
    }else if(s[0]=='f'){
      scanf("%d",&k);
      if(find(k,ro)!=NIL){
		printf("yes\n");
      }else{
		printf("no\n");
      }
    }else if(s[0]=='d'){
      scanf("%d",&k);
      delete(k);
    }else if(s[0]=='p'){
      inorder(ro);
  	  printf("\n");
      preorder(ro);
      printf("\n");
    }
  }
  free(ro);
  return 0;
}


Measured memory_bytes: 20556
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>

int main()
{
    int N, M;

    std::cin >> N >> M;

    // std::vector<int> A(N), B(N);
    std::vector<std::pair<int, int> > A(N);

    for (int i = 0; i < N; ++i) {
        std::cin >> A.at(i).first >> A.at(i).second;
    }

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

    int store = 0;
    long price = 0;
    for (int i = 0; i < M; ++i) {
        price += A.at(store).first;
        --A.at(store).second;
        if (A.at(store).second == 0) {
            ++store;
        }
    }

    std::cout << price << std::endl;
}

Measured memory_bytes: 1024
/*
このコード、と～おれ!
Be accepted!
∧＿∧　
（｡･ω･｡)つ━☆・*。
⊂　　 ノ 　　　・゜+.
　しーＪ　　　°。+ *´¨)
 　　　　　　　　　.· ´¸.·*´¨) ¸.·*¨)
		  　　　　　　　　　　(¸.·´ (¸.·'* ☆
					*/

#pragma GCC optimize("Ofast")
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define rep1(i, n) for(int i = 1; i <= (n); ++i)
#define repr(i, n) for(int i = n; i >= 0; --i)
#define reprm(i, n) for(int i = n - 1; i >= 0; --i)
#define printynl(a) printf(a ? "yes\n" : "no\n")
#define printyn(a) printf(a ? "Yes\n" : "No\n")
#define printYN(a) printf(a ? "YES\n" : "NO\n")
#define printfin(a) printf(a ? "possible\n" : "inposible\n")
#define all(x) (x).begin(), (x).end()
using ll = long long;

const int INF = 2147483647;
//const ll LINF = ll();今度書く

//マクロとかここまで

#include <stdio.h>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <iostream>

using namespace std;

int main() {
	
	int n;
	scanf("%d", &n);
	vector<pair<pair<string, int>, int>> a(n);
	rep(i, n) {
		cin >> a[i].first.first >> a[i].first.second;
		a[i].second = i + 1;
		a[i].first.second *= -1;
	}
	sort(all(a));
	rep(i, n)printf("%d\n", a[i].second);

	return 0;
}


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

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

	string s, t;
	cin >> s >> t;
	int len1 = s.length(), len2 = t.length();
	vector<vector<int>> dp(len1 + 1, vector<int> (len2 + 1, 0));
	for (int i = 0; i <= len1; i++)
	{
		for (int j = 0; j <= len2; j++)
		{
			if (i == 0 || j == 0)
				continue;
			if (s[i - 1] == t[j - 1])
			{
				dp[i][j] = dp[i - 1][j - 1] + 1;
			}
			else
			{
				dp[i][j] = max(dp[i - 1][j], dp[i][j - 1]);
			}
		}
	}
	string answer;
	int p = len1, q = len2;
	while (p > 0 && q > 0)
	{
		if (s[p - 1] == t[q - 1])
		{
			answer += s[p - 1];
			p--;
			q--;
		}
		else if (dp[p - 1][q] > dp[p][q - 1])
		{
			p--;
		}
		else
		{
			q--;
		}
	}
	reverse(answer.begin(), answer.end());
	cout << answer;

	return 0;
}

Measured memory_bytes: 38564
import sys
input = sys.stdin.readline
N = int(input())
import sys
import itertools

def solve(N: int):
    LEN = len(str(N))
    if LEN <= 2:
        a = 0
        return a

    answer = 0
    for i in range(3,LEN+1):
        for j in list(itertools.product(['3','5','7'], repeat=i)):

            if j.count('3') >= 1 and j.count('5')>=1 and j.count('7') >=1 and int(''.join(j))<=N:
                answer +=1
    return answer
ans = solve(N)
print(ans)

Measured memory_bytes: 6260
using System;
using System.Linq;

namespace AtCoderPractice0704
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());
            int[] V = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();
            int[] C = Console.ReadLine().Split(' ').Select(a => int.Parse(a)).ToArray();

            //V[i]-C[i]>0のものを全て選べば良い
            int ans = 0;
            for(var i =0; i<N; i++)
            {
                if (V[i] > C[i])
                {
                    ans += (V[i] - C[i]);
                }
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;


// ローリングハッシュ
// 二分探索で LCP を求める機能つき
struct RollingHash {
    static const int base1 = 1007, base2 = 2009;
    static const int mod1 = 1000000007, mod2 = 1000000009;
    vector<long long> hash1, hash2, power1, power2;

    // construct
    RollingHash(const string &S) {
        int n = (int)S.size();
        hash1.assign(n+1, 0);
        hash2.assign(n+1, 0);
        power1.assign(n+1, 1);
        power2.assign(n+1, 1);
        for (int i = 0; i < n; ++i) {
            hash1[i+1] = (hash1[i] * base1 + S[i]) % mod1;
            hash2[i+1] = (hash2[i] * base2 + S[i]) % mod2;
            power1[i+1] = (power1[i] * base1) % mod1;
            power2[i+1] = (power2[i] * base2) % mod2;
        }
    }
    
    // get hash of S[left:right]
    inline pair<long long, long long> get(int l, int r) const {
        long long res1 = hash1[r] - hash1[l] * power1[r-l] % mod1;
        if (res1 < 0) res1 += mod1;
        long long res2 = hash2[r] - hash2[l] * power2[r-l] % mod2;
        if (res2 < 0) res2 += mod2;
        return {res1, res2};
    }

    // get lcp of S[a:] and T[b:]
    inline int getLCP(int a, int b) const {
        int len = min((int)hash1.size()-a, (int)hash1.size()-b);
        int low = -1, high = len;
        while (high - low > 1) {
            int mid = (low + high) / 2;
            if (get(a, a+mid) != get(b, b+mid)) high = mid;
            else low = mid;
        }
        return low;
    }
};


int main() { 
    int N;
    string S;
    cin >> N >> S;

    // ロリハ
    RollingHash rh(S);

    // 求める
    int res = 0;
    for (int i = 0; i < N; ++i) {
        for (int j = i+1; j < N; ++j) {
            int lcp = rh.getLCP(i, j);
            lcp = min(lcp, j-i);
            res = max(res, lcp);
        }
    }   
        
    cout << res << endl;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll n,m,ans;
map<int,int> x;
int main(){
	cin >> n >> m;
	ll a[n];
	x[0]=1;
	cin >> a[0];
	for(int i=1;i<n;i++){
		cin >> a[i];
		a[i]+=a[i-1];
	}
	for(int i=0;i<n;i++){
		ans+=x[a[i]%m];
		x[a[i]%m]++;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3968
import Data.List (sortBy)
import Data.Function (on)

div'::Int->Int->Double
div' = (/) `on` fromIntegral

sortDesc::[Int]->[Int]
sortDesc = sortBy $ flip compare

main = do
  [n,m] <- map read . words <$> getLine
  an <- map read . words <$> getLine
  let bn = sortDesc an
  let threshold = div' (sum an) (4*m)
  putStrLn $ if all (\p -> threshold <= fromIntegral(p)) (take m bn) then "Yes" else "No"

Measured memory_bytes: 1020
using System;
using System.Numerics;
using System.Linq;
using static System.Math;

class Program 
{
  static void Main(string[] args) {
    string[] input = Console.ReadLine().Split(' ');
    int a = int.Parse(input[0]);
    int b = int.Parse(input[1]);
    int c = int.Parse(input[2]);

    int t = a - b;
    Console.WriteLine(Max(0, c - t));
  }
}

Measured memory_bytes: 13140
def draw
   mp=gets.split(' ').map(&:to_i)
   if mp[0]==0 && mp[1]==0 then return -1 end
   for y in 1..mp[0] do
      for x in 1..mp[1] do
         print "#"
      end
      print "\n"
   end
   print "\n"
   return 0
end

ret=draw
until ret==-1 do
    ret=draw
end

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-9;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int ans[125252];

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n, m, a, b;
  cin>>n>>m;
  vi g[125252];
  REP(i, m){
    cin>>a>>b;
    --a;--b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  REP(i, n){
    ans[i]=-1;
  }
  queue<pii> que;
  que.emplace(0, 0);
  ans[0]=0;
  while(que.size()){
    auto [x, y]=que.front();que.pop();
    for(auto t : g[y]){
      if(ans[t]==-1){
        ans[t]=y;
        que.emplace(x+1, t);
      }
    }
  }
  cout<<"Yes"<<'\n';
  FOR(i, 1, n){
    cout<<ans[i]+1<<'\n';
  }
  return 0;
}


Measured memory_bytes: 11296
#include <iostream>
#include <vector>
#include <string>
#include <cstdio>
#include <map>
#include <algorithm>
using namespace std;

int main(){
  
  int n;
  while(cin >> n, n){
    char c;
    vector <string> v;
    map<string, int> d;
    for(int i = 0; i < n; i++){
      bool first = false;
      while(true){
	string s;
	if(first && getchar() == '\n') break;
	first = true;
	cin >> s;
	if(!d[s]) v.push_back(s);
	d[s]--;
      }
    }

    cin >> c;
    vector <pair<int, string> > ans;
    for(int i = 0; i < v.size(); i++){
      if(v[i][0] == c)
	ans.push_back(make_pair(d[v[i]], v[i]));
    }
    sort(ans.begin(), ans.end());
    
    if(!ans.size()) cout << "NA" << endl;
    for(int i = 0; i < ans.size() && i < 5; i++)
      printf("%s%c", ans[i].second.c_str(), (i == ans.size()-1 || i == 4 ? '\n' : ' '));
  }

}

Measured memory_bytes: 1260
#include <algorithm>

#include <stdio.h>

int main(int argc, char** argv)
{
  int w, n;

  fscanf(stdin, "%d", &w);
  
  int ind[30] = { 1,  2,  3,  4,  5,  6,  7,  8,  9, 10,
		 11, 12, 13, 14, 15, 16, 17, 18, 19, 20,
		 21, 22, 23, 24, 25, 26, 27, 28, 29, 30
  };

  fscanf(stdin, "%d", &n);
  
  for (int i = 0; i < n; i ++) {
    int a, b;

    fscanf(stdin, "%d,%d", &a, &b);
    
    std::swap(ind[a - 1], ind[b - 1]);
  }
  
  for (int i = 0; i < w; i ++)
    fprintf(stdout, "%d\n", ind[i]);
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>

using namespace std;



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

	int n, i, j, k, total, m, p, x;
	cin >> n;
	vector<int> t(n + 1);
	total = 0;
	for (i = 1; i <= n; i++) {
		cin >> t[i];
		total += t[i];
	}

	cin >> m;
	vector<int> ans(m);
	for (i = 0; i < m; i++) {
		cin >> p >> x;
		ans[i] = total - t[p] + x;
	}

	for (auto p : ans) cout << p << "\n";

	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

struct UnionFind {
    vector<int> d;
    UnionFind(int n): d(n,-1) {}
    int root(int x) {
        if (d[x] < 0) return x;
        return d[x] = root(d[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (d[x] > d[y]) swap(x,y);
        d[x] += d[y];
        d[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y);}
    int size(int x) { return -d[root(x)];}
};

int main(){
    int n,m;cin >> n >> m;
    vector<P> p(m);
    rep(i,m){
        int a,b;cin >> a >> b;
        --a;--b;
        p[i] = {a,b};
    }
    reverse(p.begin(),p.end());
    ll all = (ll)(n-1) * n /2;
    UnionFind uf(n);
    vl ans(m);
    ans[0] = all;
    rep(i,m-1){
        if(!uf.same(p[i].first, p[i].second)) ans[i+1] = ans[i] - (ll)uf.size(p[i].first) * uf.size(p[i].second);
        else ans[i+1] = ans[i];
        uf.unite(p[i].first, p[i].second);
    }
    reverse(ans.begin(),ans.end());
    rep(i,m) cout << ans[i] << endl;
}

Measured memory_bytes: 3328
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<map>
#include<queue>
#include<stack>
#include<deque>
#include<fstream>
#include<string>
#include<sstream>
#include<iomanip>
#include<numeric>
#include<cctype>
#include<random>

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
typedef long long int I;

int keta(int a){
    int count=0;
    while(a!=0){
        a/=10;
        count++;
    }
    return count;
}


int main(){
    string x,ans;
    cin>>x;

    for(int i=0;i<x.size();i++){
        ans+='x';
    }

    cout<<ans<<endl;

    return 0;
} //カモンAC

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

using Graph = vector<int>;
int main() {
    int n, m;
    cin >> n >> m;
    vector<Graph>g(n);
    vector<int> color(n, -1);
    for (int i=0; i < m; i++) {
        int s, t;
        cin >> s >> t;
        g[s].emplace_back(t);
        g[t].emplace_back(s);
    }

    int num = 0;
    for (int i=0; i<n; i++) {
        num++;
        queue<int> que;
        if (color[i] != -1) {
            continue;
        }

        que.push(i);
        while(!que.empty()) {
            int s = que.front();
            que.pop();
            Graph G = g[s];
            for (int j=0; j<G.size(); j++) {
                int n = G[j];
                if (color[n] != -1) {
                    continue;
                }

                color[n] = num;
                que.push(n);
            }
        }
    }

    int q;
    cin >> q;
    for (int i=0; i < q; i++) {
        int s, t;
        cin >> s >> t;


        if (color[s] == color[t] && color[s] != -1) {
            cout << "yes" << endl;
        } else {
            cout << "no" << endl;
        }
    }
    return 0;
}



Measured memory_bytes: 8548
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<map>
using namespace std;


int main(void) {

  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0; i<n; i++) cin >> p[i];

  int cnt = 0;
  for(int i=0; i<n-1; i++){
    if( p[i] == i+1 ){
      swap(p[i], p[i+1]);
      cnt++;
    }
  }
  if( p[n-1] == n ){
    swap(p[n-1], p[n-2]);
    cnt++;
  }

  for(int i=0; i<n; i++) cerr << p[i] << " ";
  cerr << endl;

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 640
import math

n=int(input())
M=[]
for i in range(n):
    x,y=map(int,input().split())
    M.append([x,y])

D=[]
for i in range(n-1):
    for j in range(i+1,n):
        D.append(math.sqrt((M[i][0]-M[j][0])**2+(M[i][1]-M[j][1])**2))

print(sum(D)*2/n)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main(void){
	char str[1001];
	char movable[9][5] = {"BD","ACE","BF","AEG","BDFH","CEI","DH","EGI","FH"};

	while(scanf("%s",str) != EOF){
		int now = str[0] - 'A';
		int i, j;
		for(i = 1;i < strlen(str);i++){
			for(j = 0;j < strlen(movable[now]);j++){
				if(str[i] == movable[now][j]){
					break;
				}
			}
			if(j == strlen(movable[now])){ // ?§??????§???????????¨???
				break;
			}else{
				now = movable[now][j] - 'A';
			}
		}
		if(i == strlen(str)){
			printf("%s\n",str);
		}
	}
		
	return 0;
}

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

int main(){
    int k, x;
    cin >> k >> x;
    for(int i = (-1)*(k-1);i < k;i++){
        if(x+i >= 1000000*(-1) && x+i <= 1000000) cout << x+i << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256