akhauriyash/Code-Regression huggingface dataset:
# 4進数

N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]
INF = float('inf')

ans = INF
for ptn in range(1 << (2 * N)):
    abc = [0 for _ in range(4)]

    v = [None for _ in range(N)]
    # lの各idxをどの竹用に割り当てるか, ABC無 = 0123

    cnt = 0
    for j in range(N):
        v[j] = (ptn >> (2 * j)) & 3
        abc[v[j]] += l[j]
        if 0 <= v[j] < 3:
            cnt += 1

    if 0 in abc[:3]: continue
    ans = min(ans, sum(abs(x - t) for x, t in zip(abc[:3], [A, B, C])) + (cnt - 3) * 10)
print(ans)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod = 1000000000+7;
int A[2010];
int main(){
    int n,k;scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++) scanf("%d",&A[i]);
    int ans=0;
    for(int i=1;i<=n;i++){
        int tot=0;
        for(int j=1;j<i;j++) if(A[j]>A[i]) tot++;
        (ans+=1ll*tot*k%mod)%=mod;
        for(int j=i+1;j<=n;j++) if(A[j]>A[i]) tot++;
        (ans+=1ll*tot*((1ll*k*k-k)/2%mod)%mod)%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


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

struct UnionFind{
    vector<int> par;

    UnionFind(int n) : par(n,-1) { }
    void init(int n) { par.assign(n,-1); }

    int root(int x){
        if(par[x]<0) return x;
        else return par[x]=root(par[x]);
    }

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

    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y) return false;
        if(par[x]>par[y]) swap(x,y);
        par[x]+=par[y];
        par[y]=x;
        return true;
    }

    int size(int x){
        return -par[root(x)];
    }
};

int main(){
    int n,m;
    cin>>n>>m;
    int p[n];
    rep(i,n){
        cin>>p[i];
        p[i]--;
    }
    UnionFind uf(n);
    rep(i,m){
        int x,y;
        cin>>x>>y;
        x--,y--;
        uf.merge(x,y);
    }
    int ans=0;
    rep(i,n){
        if(p[i]==i) ans++;
        else{
            if(uf.issame(p[i],i)) ans++;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#include<iostream>
using namespace std;
int n;
int a[20];
int x[20][20],y[20][20];
int count(int i){
	if(i==0) return 0;
	return count(i>>1)+(i&1);
}
int main(){
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
		for(int j=0;j<a[i];j++){
			cin>>x[i][j]>>y[i][j];
			x[i][j]--;
		}
	}
	int ans=0;
	for(int i=0;i<(1<<n);i++){
		int k=1;
		for(int j=0;j<n;j++){
			if(!(i>>j&1)) continue;
			for(int l=0;l<a[j];l++){
				if(((i>>(x[j][l])&1)^y[j][l])) k=0;
			}
		}
		if(k) ans=max(ans,count(i));
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
using namespace std;


int main(){
  int N,M,X;
  int a;
  int list[101];
  int cst0 = 0;
  int cstN = 0;

memset(list,0,sizeof(list));
std::cin >> N>>M>>X;
for (int i = 0; i<M;i++){
  std::cin >> a;
  list[a] = 1;
}
for (int i = X;i<N;i++ ){
  cstN = cstN + list[i];
}
for (int i = X; 0<i ;i-- ){
  cst0 = cst0 + list[i];
}
std::cout << min(cst0,cstN) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<string.h>
#include<algorithm>
#include<math.h>
#include<map>
#include<vector>
using namespace std;
int n,m,k,rw=1000000007;
int yq[30][30],nx[(1<<20)+5][25],dp[2][21][(1<<20)+5];
int main()
{
	scanf("%d%d%d",&n,&m,&k);--n;
	for(int i=1;i<=m;i++)
		for(int j=0;j<n;j++)
			yq[i][j]=-1;
	for(int i=1,a,b,c;i<=k;i++)
	{
		scanf("%d%d%d",&a,&b,&c);
		yq[a][b-1]=c;
	}
	for(int i=0;i<(1<<n);i++)
	{
		int la=-1;
		for(int j=n-1;j>=0;j--)
		{
			if((i&(1<<j)))la=j;
			nx[i][j]=la;
		}
        //for(int j=0;j<n;j++)cout<<nx[i][j];
	}
	dp[0][n][0]=1;
	int now=1;
	for(int i=1;i<=m;i++)
	{
		for(int s=0;s<(1<<n);s++)
			dp[now][0][s]=dp[now^1][n][s];
		for(int j=0;j<=n;j++)
			for(int s=0;s<(1<<n);s++)
				dp[now^1][j][s]=0;
		for(int j=0;j<n;j++)
		{
			for(int s=0;s<(1<<n);s++)
			{
				if(dp[now][j][s])
				{
					for(int k=0;k<=1;k++)
					{
						if(yq[i][j]!=-1&&yq[i][j]!=k)continue;
						int t=((s>>j)&1);
						if(k==0&&t==1)continue;
						if(k==t)(dp[now][j+1][s]+=dp[now][j][s])%=rw;
						if(k==1&&t==0)
						{
							int la=nx[s][j];
							if(la==-1)(dp[now][j+1][s|(1<<j)]+=dp[now][j][s])%=rw;
							else (dp[now][j+1][(s|(1<<j))^(1<<la)]+=dp[now][j][s])%=rw;
						}
					}
				}
			}
		}
		now^=1;
	}
	int ans=0;
	for(int s=0;s<(1<<n);s++)
	{
		(ans+=dp[now^1][n][s])%=rw;
	}
	printf("%d\n",(ans+rw)%rw);
}

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

using namespace std;

#define LOG(...) fprintf(stderr, __VA_ARGS__)
//#define LOG(...)
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); ++i)
#define RFOR(i, a, b) for (int i = (int)(b - 1); i >= (int)(a); --i)
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define RREP(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort(ALL(c))
#define RSORT(c) sort(RALL(c))
#define SZ(a) ((int)(a).size())
#define BIT(x, i) (((x) >> (i)) & 1)
#define SQ(x) ((x) * (x))

typedef long long ll;
typedef unsigned long long ull;
typedef vector<bool> vb;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vb> vvb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main() {
    int N;
    while (cin >> N, N) {
        vs S(N);
        REP(i, N) cin >> S[i];
        int mi = 100;
        FOR(k, 1, 51) {
            set<string> code;
            REP(i, N) {
                stringstream ss;
                ss << S[i][0];
                REP(j, S[i].length()-1) {
                    switch (S[i][j]) {
                    case 'a':
                    case 'i':
                    case 'u':
                    case 'e':
                    case 'o':
                        ss << S[i][j+1];
                        break;
                    }
                }
                string s = ss.str();
                if ((int)s.length() < k) {
                    code.insert(s);
                } else {
                    code.insert(s.substr(0, k));
                }
            }
            if (SZ(code) == N) {
                mi = k;
                break;
            }
        }
        cout << (mi != 100 ? mi : -1) << endl;
    }
}

Measured memory_bytes: 3180
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<int> v1;
  string a;
  cin >> a;
  for(int k = 0; k < 4; k++){
      int b;
      b = a.at(k) - '0';
      v1.push_back(b);
  }
  vector<char> v2(3);
  for(int i = 0; i < (1 << 3); i++){
      int p = v1.at(0);
      for(int t = 0; t < 3; t++){
          if(i & (1 << t)){
             p += v1.at(t+1);
             v2[t] = '+';
          }else{
             p -= v1.at(t+1);
             v2[t] = '-';
          }
     } 
     if(p == 7) goto end;
  }
  end:
    cout << v1.at(0) << v2.at(0) << v1.at(1) << v2.at(1) << v1.at(2) << v2.at(2) << v1.at(3) << "=7" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#define MAX 100000

using namespace std;

typedef long long llong;

int n,k;
llong T[MAX];

int check(llong p){
	int i = 0;
	for( int j = 0; j < k; j++ ){
		llong s = 0;
		while( s+T[i] <= p ){
			s += T[i];
			i++;
			if ( i == n ) return n;
		}
	}
	return i;
}

int solve(){
	llong left = 0;
	llong right = 100000*10000;
	llong mid;
	while( right - left > 1 ){
		mid = (left+right)/2;
		int v = check(mid);
		if( v >= n ) right = mid;
		else left = mid;
	}
	return right;
}

main(){
	cin >> n >> k;
	for( int i = 0; i < n; i++ ) cin >> T[i];
	llong ans = solve();
	cout << ans << endl;
}


Measured memory_bytes: 3876
from collections import defaultdict

n, k = map(int, input().split())

s = set()
d = defaultdict(int)
for _ in range(n):
    a, b = map(int, input().split())
    d[a] += b
    s.add(a)

s = sorted(list(s))
# print(s)
# print(d)
s += [0]
cnt = 0
ret = None
for i in s:
    cnt += d[i]
    if cnt >= k:
        # print(i, cnt)
        ret = i
        break
print(ret)


Measured memory_bytes: 13484
#include <bits/stdc++.h>
using namespace std;
const int MOD = (int)1e9 + 7;
const int INF = 100100100;
const double PI = 3.14159265358979323846;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)

int main() {
  int n, x[10] = {0}, y[10] = {0};
  cin >> n;
  REP(i, n) cin >> x[i] >> y[i];
  vector<int> v(n);
  REP(i, n) v[i] = i;
  double routeSum = 0.0;
  do {
    FOR(i, 0, n - 1) {
      double xx = (double)(x[v[i]] - x[v[i + 1]]) * (x[v[i]] - x[v[i + 1]]);
      double yy = (double)(y[v[i]] - y[v[i + 1]]) * (y[v[i]] - y[v[i + 1]]);
      routeSum += sqrt(xx + yy);
    }
  } while (next_permutation(v.begin(), v.end()));
  double fn = 1.0;
  REP(i, n) fn *= i + 1;
  double ans = routeSum / fn;
  cout << fixed << setprecision(6) << ans << endl;
  return 0;
}

Measured memory_bytes: 256
N, M = map(int, input().split())
S, C = [], []
for i in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)
F = False
for i in range(10**(N)):
    t = str(i)
    flag = True
    if len(t) != N:
        continue
    for j in range(M):
        if t[S[j]-1] != str(C[j]):
            flag = False
    if flag:
        print(i)
        F = True
        break
if not F:
    print(-1)

Measured memory_bytes: 40688
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

using namespace std;
typedef long long lint;

const int MOD = 1000000007, INF = 1111111111;
const double EPS = 1e-9;

template <class T>
class CuSum {
private:
	vector<T> cusum;
	void init(vector<T> &vec) { for (int i = 0; i < (int)(vec.size()); i++) cusum[i + 1] = cusum[i] + vec[i]; }

public:
	CuSum(vector<T> &vec) : cusum(vec.size() + 1) { init(vec); }
	T query(int l, int r /*[l, r) */) { return cusum[r] - cusum[l]; }
};

int main() {

	cin.tie(0);

	int N;
	string S;
	cin >> N >> S;

	vector<int> b(N);
	
	for (int i = 0; i < N; i++) {

		if (S[i] == '.') b[i] = 0;
		else b[i] = 1;
	}

	CuSum<int> cul(b);
	int ans = INF, changes;
	for (int i = 0; i < N; i++) {

		changes = cul.query(0, i) + (N - 1 - i - cul.query(i + 1, N));
		ans = min(ans, changes);
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 2180
#include <iostream>

using namespace std;
int main(int argc, const char * argv[]) {
    // 整数の入力
    int N;
    cin >> N;

    // 文字列の入力
    string s, t;
    cin >> s >> t;
    int res, i;
    
    if(s == t) res = N;
    else {
        for(i=1; i<=N; i++) {
            if(s.substr(i) == t.substr(0, N-i)) break;
        }
        res = N + i;
    }
    
    // 出力
    cout << res << endl;
    return 0;
}


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

int main(){
  int n, a ,b;
  cin >> n >> a >> b;
  
  int range = b - a;
  string ans;
  if (range % 2 == 0)
    ans = "Alice";
  else
    ans = "Borys";
  
  cout << ans << endl;
  
  return 0;
}

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

const int MAX = 5000000;
const int MOD = 1000000007;

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

// テーブルを作る前処理
void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (int i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

// 二項係数計算
long long COM(int n, int k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  int X,Y;
  cin>>X>>Y;
  int x,y;
  if((2*X-Y)%3!=0||(2*Y-X)%3!=0){
    cout<<0<<endl;
    return 0;
  }
  x=(2*X-Y)/3; y=(2*Y-X)/3;
  COMinit();
  cout << COM(x+y, x) << endl;
  return 0;
}





Measured memory_bytes: 117376
n,a,b = map(int, input().split())

mod = 10**9+7

total = pow(2,n,mod)
total += mod*3

# c[i] = x**(mod-2) % mod
c = [pow(x,mod-2,mod) for x in range(2*10**5+1)]

nCa = 1
for i in range(1,a+1):
    nCa *= n-i+1
    nCa *= c[i]
    nCa %= mod

nCb = 1
for i in range(1,b+1):
    nCb *= n-i+1
    nCb *= c[i]
    nCb %= mod


print((total - 1 - nCa - nCb) % mod)

Measured memory_bytes: 52464
#include<bits/stdc++.h>
using namespace std;
#define FASTIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pil pair<int,ll>
#define pli pair<ll,int>
#define mod 1000000007
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
int main(){
FASTIO  
ll k;
cin>>k;
ll ans=0;
for(ll i=1;i<=k;i++){
  for(ll j=1;j<=k;j++){
     for(ll p=1;p<=k;p++){
        ans+=(ll)(__gcd(i,__gcd(j,p)));
     }
  }
}
cout<<ans;
return 0;
}


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

int main() {
    int n, a, b;
    cin >> n >> a >> b;
    vector<int> p(n), pos(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
        p[i]--;
        pos[p[i]] = 2 * i + 1;
    }
    constexpr int64_t kInf = 1'000'000'000'000'000'000;
    vector<vector<int64_t>> dp(n, vector<int64_t>(n + n + 1, kInf));
    for (int i = 0; i < n + n; ++i) {
        if (i < pos[0]) dp[0][i] = b;
        else if (i == pos[0]) dp[0][i] = 0;
        else dp[0][i] = a;
    }
    for (int i = 1; i < n; ++i) {
        int64_t prv = kInf;
        for (int j = 0; j < n + n + 1; ++j) {
            prv = min(prv, dp[i - 1][j]);
            if (j % 2 == 1 && j != pos[i]) continue;
            int cost = j == pos[i] ? 0 : j < pos[i] ? b : a;
            dp[i][j] = prv + cost;
        }
    }
    cout << *min_element(dp[n - 1].begin(), dp[n - 1].end()) << "\n";
    return 0;
}


Measured memory_bytes: 391168
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
using namespace std;

int main() {

    int N, Q;
    cin >> N>>Q;
    vector<char> S(N+1);
    vector<int>l(Q), r(Q);
    for (int i = 0; i < N; i++) {
        cin >> S[i];
    }
    for (int i = 0; i < Q; i++) {
        cin >> l[i] >> r[i];
    }

    vector<int>ans(N,0);
    for (int i = 0; i < N; i++) {
        if (i > 0)ans[i] += ans[i - 1];
        if (S[i] == 'A'&&S[i + 1] == 'C')ans[i + 1]++;
    }

    for (int i = 0; i < Q; i++) {
        cout << ans[r[i]-1] - ans[l[i]-1] << "\n";
    }


    return 0;
}

Measured memory_bytes: 2048
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define int long long
#define mkp make_pair
#define pb push_back
#define ff first
#define ss second
#define debug1(a) cout<<a<<endl;
#define debug2(a,b) cout<<a<<' '<<b<<endl;
#define debug3(a,b,c) cout<<a<' '<<b<<' '<<c<<endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define repre(i,a,b)for(int i=a;i<=b;i++)
#define clr1(arr) memset(arr,-1,sizeof(arr));
#define clr0(arr) memset(arr,0,sizeof(arr));
#define pi pair<int,int>
#define pii pair<int,pi>
#define aint(v) v.begin(),v.end()
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace __gnu_pbds;
using namespace std;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> orderedSet;
typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> orderedMSet;
struct custom_hash {
static uint64_t splitmix64(uint64_t x) {
        // http://xorshift.di.unimi.it/splitmix64.c
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};
#define ump gp_hash_table<int,int,custom_hash>
//*p.find_by_order(index) return value at index
//p.order_of_key(key) return index
/*int **dp,in main function,int row,col;dp=new int*[n];rep(i,n)dp[i]=new int[m]*/
//**** Maths Section*******/
int power(int x,int y);
bool isPrime(int n);
int modInv(int a,int b);
int gcdExtended(int a,int b,int *x,int* y);
int mpower(int a,int b,int p);
/***************************/
int32_t main()
{
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  fastio
  string a,b;
  cin>>a;
  cin>>b;
  cout<<b<<a<<endl;
  return 0;
}

int modInv(int a, int m)
{
int x, y;
int g = gcdExtended(a, m, &x, &y);
int res = (x%m + m) % m;
return res;
}

int gcdExtended(int a, int b, int *x, int *y)
{
if (a == 0){
    *x = 0, *y = 1;
    return b;
  }
  int x1, y1;
  int gcd = gcdExtended(b%a, a, &x1, &y1);
  *x = y1 - (b/a) * x1;
  *y = x1;
  return gcd;
}

int mpower(int x, int y, int p)
{
int res = 1;
x = x % p;
while(y > 0){
    if(y & 1) res = (res*x) % p;
      y = y>>1;
      x = (x*x) % p;
    }
    return res;
}
int power(int x, int y)
{
int res = 1;
while (y > 0){
    if (y & 1) res = res*x;
      y = y>>1;
      x = x*x;
    }
    return res;
}

bool isPrime(int n)
{
if (n <= 1)  return false;
  if (n <= 3)  return true;
    if (n%2 == 0 || n%3 == 0) return false;
      int p=sqrt(n);
      for(int i=5;i<=p;i=i+6)
        if (n%i == 0 || n%(i+2) == 0)
          return false;
      return true;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
const int MOD = 1e9+7;
const int MOOD = 998244353;
#define PI 3.14159265359
typedef long long ll;
using namespace std;

int f[200010];
int amari[200010][2];

int main(){
	int n, popcount = 0;
	string s;
	cin >> n >> s;
	for (int i = 0; i < s.length(); i++){
		if (s[i] == '1') popcount++;
	}
	for (int i = 1; i <= 200000; i++){
		int coun = 0;
		for (int j = 0; j <= 18; j++){
			if (i & (1LL << j)) coun++;
		}
		f[i] = f[(i%coun)] + 1;
	}

	if (popcount != 1){
		amari[0][0] = 1%(popcount-1);
	}
	amari[0][1] = 1%(popcount+1);

	for (int i = 1; i < n; i++){
		if (popcount != 1){
			amari[i][0] = (amari[i-1][0]*2)%(popcount-1);
		}
		amari[i][1] = (amari[i-1][1]*2)%(popcount+1);
	}
	int defamari0 = 0;
	int defamari1 = 0;

	for (int i = 0; i < n; i++){
		if (s[i] == '1'){
			defamari0 += amari[s.length()-1-i][0];
			defamari1 += amari[s.length()-1-i][1];
			if (popcount != 1){
				defamari0 %= (popcount-1);
			}
			defamari1 %= (popcount+1);
		}
	}
	for (int i = 0; i < s.length(); i++){
		if (s[i] == '0'){
			int newamari = defamari1 + amari[s.length()-1-i][1];
			newamari %= (popcount+1);
			cout << f[newamari]+1 << endl;
		}else if (s[i] == '1' && popcount != 1){
			int newamari = defamari0 - amari[s.length()-1-i][0];
			newamari %= (popcount+1);
			if (newamari < 0) newamari += (popcount-1);
			cout << f[newamari]+1 << endl;
		}else{
			cout << 0 << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 6072
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    int n, i;
    int s[1000];
    double m, sum;
    double siguma;
     
    for(; ; ) {
        scanf("%d", &n);
        if(n==0) break;
        else {
            m=0; sum=0;
            for(i=0; i<n; i++) {
                scanf("%d", &s[i]);
                m+=s[i];
            }
            m=(double)m/n;
             
            for(i=0; i<n; i++)
                sum+=pow(s[i]-m, 2);
            sum/=n;
            siguma=sqrt(sum);
            printf("%f\n", siguma);
        }
    }
     
    return 0;
}


Measured memory_bytes: 2036
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>

using namespace std;

inline int read()
{
   int x=0,f=1;char ch=getchar();
   while (!isdigit(ch)){if (ch=='-') f=-1;ch=getchar();}
   while (isdigit(ch)){x=(x<<1)+(x<<3)+ch-'0';ch=getchar();}
   return x*f;
}

const int maxn = 1010;

struct Node
{
	int a,b;
};

Node a[maxn];
int n,m;

int main()
{
  n=read();m=read();
  int ans=1e9;
  for (int i=1;i<=n;i++) a[i].a=read(),a[i].b=read();
  for (int i=1;i<=n;i++)
  {
  	if (a[i].b<=m) ans=min(ans,a[i].a);
  }
  if (ans==1e9) cout<<"TLE";
  else cout<<ans;
  return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N, A, B=map(int, input().split())

if (B-A) % 2 == 0:
    C=(B-A)//2
else:
    if A-1 > N-B:
        C1=N-B
        C2=(N-A-C1) // 2
        C= C1 + C2 + 1
    else:
        C1=A-1
        C2=(B-1-C1) // 2
        C= C1 + C2 + 1

print(C)

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

#define FOR(i, a, b) for(int i = (a); i < (b); ++i)
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPr(i, n) for(int i = (n)-1; i >= 0; --i)
#define FORq(i, m, n) for(int i = (m); i <= (n); ++i)
#define FORqr(i, m, n) for(int i = (n); i >= (m); --i)
#define MP make_pair
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x, 0, sizeof(x))
#define FILL(x, y) memset(x, y, sizeof(x))
#define MM(x) memset(x, -1, sizeof(x))
#define ALL(x) (x).begin(), (x).end()
#define DB(x) cerr << #x << " = " << x << endl
#define DB2(x, y)                                                              \
    cerr << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")\n";
#define DEBUG                                                                  \
    int x12345;                                                                \
    cin >> x12345;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
const long long MOD = 1e9 + 7;
///////////////////////////////////////////////
// for template
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}
///////////////////////////////////////////////
/// 🍈( '-' 🍈 |AC|
int main() {
    int N;
    ll D;
    int ans = 0;
    cin >> N >> D;
    REP(i,N){
        ll X,Y; cin >> X >> Y;
        if (X * X + Y * Y <= D * D){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define INF (int)1e9
#define EPS 1e-9
#define PI 3.1415926535897932384626433832795
#define MOD 1000000007
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef double ld;

int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int a,b,c,d ,e;
	cin >> a >> b >> c >> d >> e;
	if(a == 0)cout << 1 << "\n";
	else if(b == 0)cout << 2 << "\n";
	else if(c == 0)cout << 3 << "\n";
	else if(d == 0)cout << 4 << "\n";
	else if(e == 0)cout << 5 << "\n";
	return 0;
}


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

float OptimalBSTree(vector<float> p, vector<float> q){
	int n = p.size();

	vector< vector<float> > psum(n, vector<float>(n, 0));
	for (int i = 0; i < n; i++){
		for (int j = 0; j < n - i; j++){
			if (i == 0){
				psum[j][j] = p[j];
			}
			else{
				psum[j][j + i] = psum[j][j + i - 1] + p[j + i];
			}
		}
	}
	vector< vector<float> > qsum(n + 1, vector<float>(n + 1, 0));
	for (int i = 0; i < n + 1; i++){
		for (int j = 0; j < n + 1 - i; j++){
			if (i == 0){
				qsum[j][j] = q[j];
			}
			else{
				qsum[j][j + i] = qsum[j][j + i - 1] + q[j + i];
			}
		}
	}

	float et;
	vector< vector<float> > table(n + 1, vector<float>(n + 1, 0));
	for (int i = 0; i < n + 1; i++){
		for (int j = 0; j < n + 1 - i; j++){
			if (i == 0){
				table[j][j] = q[j];
			}
			else{
				float min;
				for (int k = 0; k < i; k++){
					et = table[j][j + k] + table[j + k + 1][j + i] + psum[j][i + j - 1] + qsum[j][i + j];
					if (k == 0 || et < min) min = et;
				}
				table[j][j + i] = min;
			}
		}
	}
	return table[0][n];
}

int main(){
	int n;
	scanf("%d", &n);
	vector<float> p(n), q(n + 1);
	for (int i = 0; i < n; i++){
		scanf("%f", &p[i]);
	}
	for (int i = 0; i < n + 1; i++){
		scanf("%f", &q[i]);
	}
	printf("%f\n", OptimalBSTree(p, q));

	return 0;
}


Measured memory_bytes: 5848
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n, m;
  cin >> n >> m;
  vector<int> a(m), b(m);
  for (int i=0;i<m;i++){
    cin >> a[i] >> b[i];
  }
  for (int i=1;i<n+1;i++){
    int count =0;
    for (int j=0;j<m;j++){
      if (a[j]==i){
        count++;
      }
      if (b[j]==i){
        count++;
      }
    }
    cout << count << endl;
  }
}

Measured memory_bytes: 256
#include <cmath>
#include <iostream>

using namespace std;

int main(void)
{
  int a,b,c;
  string b_str;
  
  cin >> a;
  cin >> b;
  
  b_str = to_string(b);
  c = a*pow(10,b_str.length())+b;
  
  for (int i=1; i<c;i++)
  {
    if (i*i==c)
    {
      cout << "Yes";
      break;
    }
    else if (i*i>c)
    {
      cout << "No";
      break;
    }
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define ii pair<int,int>
#define MAX 1000000007
using namespace std;

int main(void){
	int n,x;
	cin>>n>>x;;
	int l;
	int cur=0,cnt=1;
	rep(i,n){
		cin>>l;
		if(cur+l>x)break;
		cur+=l;
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


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

typedef long long ll;
typedef pair<int,int> pii;

long long MOD = 1000000000 + 7;

int main(){
  cout << setprecision(10);
  ll N,M; cin >> N >> M;
  ll ans = 0;

  if(M >= N * 2){
    ans += N;
    M -= N * 2;
    ans += M / 4;
  } else { 
    ans += M / 2;
  }
  cout << ans << endl;

}


Measured memory_bytes: 3540
a, v1 = map(int, input().split())
b, v2 = map(int, input().split())
t = int(input())
l = abs(a-b)
delta_v = v1-v2
if delta_v <= 0:
  print("NO")
  exit()

if delta_v * t >= l:
  print("YES")
else:
  print("NO")

Measured memory_bytes: 9184
# encoding: utf-8
N, A = map(int, input().split())
x = list(map(int, input().split()))
MAX_X = 50

x.sort()

memo = [None] * (N * N * MAX_X * N)

def get(pos, tmp, cnt):
    # print("#", pos, tmp, cnt)
    # end
    if pos == N:
        if cnt > 0 and cnt * A == tmp:
            # print("##", pos, tmp, cnt, "end\tret=", 1)
            return 1
        else: return 0
    # read memo
    idx_memo = pos * (N * N * MAX_X) + cnt * (N * MAX_X) + tmp
    if memo[idx_memo] != None:
        # print("##", pos, tmp, cnt, "memo\tret=", memo[idx_memo])
        return memo[idx_memo]
    # for cnt_sub in range(1, cnt):
    #     if tmp % cnt > 0: break
    #     tmp_sub = (tmp // cnt) * cnt_sub
    #     idx_memo = pos * (N * N * MAX_X) + cnt_sub * (N * MAX_X) + tmp_sub
    #     if memo[idx_memo] != None:
    #         # print("##", pos, tmp, cnt, "sub\tret=", memo[idx_memo])
    #         return memo[idx_memo]
    # process
    ret = 0
    ret += get(pos + 1, tmp + x[pos], cnt + 1) # take
    ret += get(pos + 1, tmp, cnt) # pass
    # write memo
    idx_memo = pos * (N * N * MAX_X) + cnt * (N * MAX_X) + tmp
    if memo[idx_memo] == None: memo[idx_memo] = ret
    # for cnt_sub in range(1, cnt):
    #     if tmp % cnt > 0: break
    #     tmp_sub = (tmp // cnt) * cnt_sub
    #     idx_memo = pos * (N * N * MAX_X) + cnt_sub * (N * MAX_X) + tmp_sub
    #     if memo[idx_memo] == None: memo[idx_memo] = ret
    return ret

print(get(0, 0, 0))
    

Measured memory_bytes: 55284
package main

import (
	"bufio"
	"fmt"
	"os"
)

var bw = bufio.NewWriter(os.Stdout)

func isOdd(n int) bool { return n%2 != 0 }

func printf(format string, a ...interface{}) { fmt.Fprintf(bw, format, a...) }

func main() {
	defer bw.Flush()
	var s string
	fmt.Scan(&s)
	n := len(s)
	ans := make([]int, n)
	ctR := 0
	for i := 0; i < n; i++ {
		if s[i] == 'R' {
			ctR++
		} else {
			ans[i-1] += (ctR + 1) / 2
			ans[i] += ctR / 2
			ctR = 0
		}
	}
	ctL := 0
	for i := n - 1; i >= 0; i-- {
		if s[i] == 'L' {
			ctL++
		} else {
			ans[i] += ctL / 2
			ans[i+1] += (ctL + 1) / 2
			ctL = 0
		}
	}
	for _, v := range ans {
		printf("%v ", v)
	}
}


Measured memory_bytes: 3200
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <string>
#include <set>
#include <vector>
#include <map>
#include <utility>
#include <queue>
#include <deque>
#include <stack>
#define io ios::sync_with_stdio(false)
using namespace std;
typedef long long ll;
const int maxn=1e3+10;
int sum[maxn][maxn],f[maxn][maxn];
void solve(){
    int sum,t,s;
    cin>>sum>>t>>s;
    if(sum>t*s)cout<<"No";
    else cout<<"Yes";
}
int main(){
    io;
    //int T;cin>>T;
    //while(T--)
        solve();
}


Measured memory_bytes: 3036
import java.util.*;

public class Main{
  
	public static void main(String[] args) {
			Scanner sc = new Scanner(System.in);
			int a = sc.nextInt();
			int n = a;
			int[] array = new int[8]; 
			int b = 10;
			int sum = 0;
			for(int i = 0; i < 8; i++) {
				array[i] = a % b;
				a -= array[i];
				sum += array[i] / (b / 10);
				b *= 10;
			}
			if(n % sum == 0) {
				System.out.println("Yes");
			}else {
				System.out.println("No");
			}
		
		}
	}

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

int main() {
    string S;
    string S2;
    int judge = 0;
    int N;
    string str1;
    string str2;
    string str3;
    string str4;

    cin >> S;

    N = S.size();
    S2 = S;
    reverse(S2.begin(),S2.end());

    for (int i = 0 ; i < N ; i++ ){
        if ( S.at(i) != S2.at(i)){
            judge += 1;
        }
    }        
    //条件2判定
    for (int i = 0; i < (N-1) / 2 ; i++) {
        str1 += S.at(i);
    }

    str2 = str1;
    reverse (str2.begin(),str2.end());


    for (int i = 0 ; i < str1.size() ; i++ ){
        if ( str1.at(i) != str2.at(i)){
            judge += 1;
        }
    }

    //条件3判定

    for (int i = ( N + 3 ) / 2 - 1; i< N ; i++) {
        str3 += S.at(i);
    }
    str4 = str3;
    reverse (str4.begin(),str4.end());    

    for (int i = 0 ; i < str3.size() ; i++ ){
        if ( str3.at(i) != str4.at(i)){
            judge += 1;
        }
    }

    if (judge == 0){
        cout << "Yes" << endl;
    }
    else 
        cout << "No" << endl;


}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(void)
{
    int N;
    cin >> N;
    vector<std::pair<int, bool> > v(N);
    for(auto& e : v)
    {
        int ai;
        cin >> ai;
        e = make_pair(ai, false);
    }

    int next = 0;
    int ans = 0;
    while(1)
    {
        if(v[next].second)
        {
            ans = -1;
            break;
        }
        if(1 == next)
            break;
        v[next].second = true;
        next = v[next].first - 1;
        ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
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; }
const int INF=1001001001;

int main() {
  int N;
  cin>>N;
  vector<int>a(N);
  for(int i=0;i<N;i++){
    cin>>a[i];
  }
  int next=1,ans=0;
  for(int i=0;i<N;i++){
    if(a[i]==next){next++;}
    else{ans++;}
  }
  if(ans==N){ans=-1;}
  cout<<ans<<endl;
  return 0;}

Measured memory_bytes: 1024
/* ＵＴＦ－８ */
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>
#include <limits>

#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>

#define USE_COLORED 1

#ifdef USE_COLORED
static const char stdout_pre[]  = "\033[1m"; // bold black
static const char stderr_pre[]  = "\033[31;1m"; // bold red
static const char stdxxx_post[] = "\033[m";

// 当然ながら GCC(g++)/libstdc++ 依存
#include <ext/stdio_filebuf.h>
using stdio_filebuf = __gnu_cxx::stdio_filebuf<char>;
class colored_stdio_filebuf : public stdio_filebuf {
private:
	const char* const pre_;
	const char* const post_;

public:
	colored_stdio_filebuf(FILE* fp, const char* pre, const char* post) : stdio_filebuf(fp, std::ios_base::out), pre_(pre), post_(post)
	{
	}

protected:
	std::streamsize xsputn(const char* s, std::streamsize count) override
	{
		stdio_filebuf::xsputn(pre_, strlen(pre_));
		auto ret = stdio_filebuf::xsputn(s, count);
		stdio_filebuf::xsputn(post_, strlen(post_));
		return ret;
	}
};
#endif

int main()
{
#ifdef USE_COLORED
	if (getenv("DEBUG")) {
		std::cout.rdbuf(new colored_stdio_filebuf(stdout, stdout_pre, stdxxx_post));
		std::cerr.rdbuf(new colored_stdio_filebuf(stderr, stderr_pre, stdxxx_post));
	} else
#endif
	{
		int fd = open("/dev/null", O_WRONLY);
		dup2(fd, 2);
		close(fd);
	}
	std::string S;
	std::cin >> S;
	bool fumiyasui = true;
	for (int i = 0; i < S.size(); i += 2)
	{
		if (S[i] == 'L')
			fumiyasui = false;
	}
	for (int i = 1; i < S.size(); i += 2)
	{
		if (S[i] == 'R')
			fumiyasui = false;
	}
	if (fumiyasui)
		std::cout << "Yes\n";
	else
		std::cout << "No\n";
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int k, C[10], C2[10], ans, is;
char map[10][10];
void dfs(int cur){
	if(cur == 8){
		for(int i = 0; i < 8; i++){
			for(int j = 0; j < 8; j++)cout<<map[i][j];
			cout<<"\n";
		}
		is = 1;
	}
	else for(int i = 0; i < 8; i++){
		bool ok = true;
		for(int j = 0; j < cur; j++)
			if(C[j]==i || cur-i==j-C[j] || cur+i==j+C[j])
				{ok = false; break;}
		if(C2[cur]!=0 && C2[cur] != i)ok = false;
		if(ok && !is){
			map[cur][i] = 'Q';
			C[cur] = i;
			dfs(cur+1);
			map[cur][i] = '.';
		}
	}
}
int main(){
	for(int i = 0; i < 8; i++)
		for(int j = 0; j < 8; j++)
			map[i][j] = '.';
	cin>>k;
	for(int i = 0; i < k; i++){
		int a, b;
		cin>>a>>b;
		C2[a] = b;
		map[a][b] = 'Q';
	}
	dfs(0);
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;i<=(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

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

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

void solve_abc_b() {
	ll n, x, a, b, c, k;
	ll ans = 0;
	//float ans = 0;

	cin >> a >> b >> c >> k;

	if (a >= k) {
		ans = k;
	}
	else {
		ans = a;
		k -= a;
		if (b >= k) {
			
		}
		else {
			k -= b;
			if (c >= k) {
				ans -= k;
			}
			else {
				ans -= c;
			}
		}
	}
	cout << ans << "\n";
}

int main(void) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed;
	//cout << setprecision(7);

	solve_abc_b();

	return 0;
}

Measured memory_bytes: 3652
#include <algorithm>
#include <map>
#include <iostream>
#include <string>
#include <set>
#include <queue>
#include <cmath>
#include <iterator>
#include <array>
typedef long long int ll;
using namespace std;
#define maxN 200005
#define mod 1000000007

string s;
map<ll,ll>mm;
ll ans=0;

void solve() {
	mm[0]=1;
	ll ten=1,st=0;
	ans=0;
	for(int i=s.length()-1; i>=0; i--) {
		st=(st+(s[i]-'0')*ten)%2019;
		ten*=10;
		ten%=2019;
		mm[st]++;
	}
	for(auto i:mm) {
		ans+=i.second*(i.second-1)/2;
	}
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>s;
	solve();
	cout<<ans<<endl;
}

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
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; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int r;
    cin >> r;
    cout << 3 * r * r << endl;
}

Measured memory_bytes: 3560
#include <cstdio>

int N,M;
int dpA[6008][3008];
int dpAsum[6008];
int dpB[6008][3008];
int dpBsum[6008];
int dpC[6008][3008];
int dpCsum[6008];
int MOD=1000000007;
int main() {
	scanf("%d%d",&N,&M);
	dpA[0][0]=1;
	for(int i=0;i<=M*2;i++) {
		//go back
		if(i%2) {
			for(int j=0;j<=N;j++) {
				if(j<N) dpA[i+1][j]+=dpA[i][j];
				if(j) dpA[i+1][j-1]+=dpA[i][j];
				dpA[i+1][j]%=MOD;
				if(j) dpA[i+1][j-1]%=MOD;
			}
		} else {
			for(int j=0;j<=N-1;j++) {
				dpA[i+1][j]+=dpA[i][j];
				dpA[i+1][j+1]+=dpA[i][j];
				dpA[i+1][j]%=MOD;
				dpA[i+1][j+1]%=MOD;
			}
		}
		dpA[i+1][0]=0;
	}
	for(int i=0;i<=M*2;i++) for(int j=0;j<=N;j++) {
		dpAsum[i]+=dpA[i][j];
		dpAsum[i]%=MOD;
	}
	dpB[0][0]=1;
	for(int i=0;i<=M*2;i++) {
		//go ahead
		if(i%2) {
			for(int j=0;j<=N-1;j++) {
				dpB[i+1][j]+=dpB[i][j];
				dpB[i+1][j+1]+=dpB[i][j];
				dpB[i+1][j]%=MOD;
				dpB[i+1][j+1]%=MOD;
			}
		} else {
			for(int j=0;j<=N;j++) {
				if(j<N) dpB[i+1][j]+=dpB[i][j];
				if(j) dpB[i+1][j-1]+=dpB[i][j];
				dpB[i+1][j]%=MOD;
				if(j) dpB[i+1][j-1]%=MOD;
			}
		}
	}
	for(int i=0;i<=M*2;i++) for(int j=0;j<=N;j++) {
		dpBsum[i]+=dpB[i][j];
		dpBsum[i]%=MOD;
	}
	dpC[0][0]=1;
	for(int i=0;i<=M*2;i++) {
		//go ahead
		if(i%2) {
			for(int j=0;j<=N;j++) {
				if(j<N) dpC[i+1][j]+=dpC[i][j];
				if(j) dpC[i+1][j-1]+=dpC[i][j];
				dpC[i+1][j]%=MOD;
				if(j) dpC[i+1][j-1]%=MOD;
			}
		} else {
			for(int j=0;j<=N-1;j++) {
				dpC[i+1][j]+=dpC[i][j];
				dpC[i+1][j+1]+=dpC[i][j];
				dpC[i+1][j]%=MOD;
				dpC[i+1][j+1]%=MOD;
			}
		}
	}
	for(int i=0;i<=M*2;i++) for(int j=0;j<=N;j++) {
		dpCsum[i]+=dpC[i][j];
		dpCsum[i]%=MOD;
	}
	long long sol=dpBsum[M*2];
	for(int j=1;j<=M*2;j+=2) {
		long long ksol=dpAsum[j];
		ksol*=dpCsum[M*2-j];
		sol+=ksol;
		sol%=MOD;
	}
	printf("%lld\n",sol);
	//for(int i=0;i<=M*2;i++) {printf("%d %d %d\n",i,dpAsum[i],dpBsum[i]);}
	return 0;
}


Measured memory_bytes: 211968
ryou = [0]*4
for i in range(4):
    ryou[i] = [0]*3
for i in range(4):
    for j in range(3):
        ryou[i][j] = [0]*10
sep = '#' * 20

n = int(input())
for i in range(n):
    b, f, r, v = [int(x) for x in input().split()]
    ryou[b-1][f-1][r-1] += v

for i in range(4):
    for j in range(3):
        s = ' '
        s += ' '.join(map(str,ryou[i][j]))
        print(s)
    if not i == 3:
        print(sep)

Measured memory_bytes: 7772
#include <stdio.h>
#include <math.h>
main(){
  int a,b;

  while(1){
    scanf("%d%d", &a, &b);
    if(a==0 && b==0) break;

    printf("%.6f\n", 2.0*(double)(a)*sqrt(0.5*0.5*a*a+b*b)+(double)(a*a));
  }
  return 0;
}

Measured memory_bytes: 0
// B - Common Raccoon vs Monster
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int H,N;

int in(){int x;cin>>x;return x;}

int main(){
	cin>>H>>N;
	int s = 0; rp(i,0,N) s += in();
	cout<< (s>=H? "Yes":"No") <<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,d,f;
ll gcd(ll a,ll b){
    return b?gcd(b,a%b):a;
}
ll fun(ll x,ll y){
    return x/c+x/d-x/y;
}
int main(){
    cin>>a>>b>>c>>d;
    f=gcd(c,d);
    ll p=c*d/f;
    cout<<b-a+1-(fun(b,p)-fun(a-1,p))<<endl;
}


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


using ll = long long;
const int MaxN = 51;
const int MaxM = 20;
int n, m;
bool adj[MaxN][MaxN];
map<pair<int, int>, int> edge;
int u[MaxM], v[MaxM];
bool used[MaxN];
int path[MaxN];


bool dfs(int k, int nc, int nd)
{
    for (int x = 1; x <= n; x++) {
        if (used[x] || !adj[nc][x]) continue;
        used[x] = true;
        path[k] = x;
        if (x == nd) return true;
        if (dfs(k + 1, x, nd)) return true;
        used[x] = false;
    }
    return false;
}


void solve()
{
    ll mask[MaxM] = {0};
    for (int i = 0; i < m; i++) {
        for (int j = 1; j <= n; j++) used[j] = false;
        used[u[i]] = true;
        path[0] = u[i];
        dfs(1, u[i], v[i]);
        for (int j = 0; j < n - 1; j++) {
            mask[i] |= 1LL << edge[make_pair(path[j], path[j + 1])];
            if (path[j + 1] == v[i]) break;
        }
    }

    ll ans = 0;
    int xmax = 1 << m;
    for (int x = 0; x < xmax; x++) {
        ll mk = 0;
        int sgn = 1, t = x, idx = 0;
        while (t) {
            if (t & 1) {
                sgn = -sgn;
                mk |= mask[idx];
            }
            t >>= 1;
            idx++;
        }
        ans += (1LL << (n - 1 - __builtin_popcountll(mk))) * sgn;
    }
    cout << ans << endl;
}


int main()
{
    cin >> n;
    int ai, bi;
    for (int i = 0; i < n - 1; i++) {
        cin >> ai >> bi;
        adj[ai][bi] = adj[bi][ai] = true;
        edge[make_pair(ai, bi)] = edge[make_pair(bi, ai)] = i;
    }
    cin >> m;
    for (int i = 0; i < m; i++) cin >> u[i] >> v[i];
    solve();
    return 0;
}


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

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

const int MOD=1e9+7;
const int INF=1<<30;
const int MAX=1e5;

int n;

template<class T>
inline void xmin(T &a, T b){a=(a<b)?a:b;}
template<class T>
inline void xmax(T &a, T b){a=(a>b)?a:b;}



void solve(){
    string s;
    cin>>s;
    if(s=="Sunny"){
        cout<<"Cloudy"<<endl;
    }
    if(s=="Cloudy"){
        cout<<"Rainy"<<endl;
    }
    if(s=="Rainy"){
        cout<<"Sunny"<<endl;
    }
}

signed main(){
    solve();
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
#define show(obj) {for(auto x:obj)cout<<x<<' ';cout<<endl;}
#define line "----------"
typedef long long ll;
typedef pair<int,int> P;
typedef pair<ll,ll> LP;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

ll N, K;
vector<ll> A(200200);
map<ll, int> exist;

ll calc_under(ll num, ll a){
	ll res = INF;
	ll need = INF;

	if(a > 0){
		if(num >= 0){
			need = num / a + (num % a != 0);
		}else{
			need = num / a;
		}
		auto it = lower_bound(all(A), need);
		res = it - A.begin();
		if(a < need)--res;
	}else if(a == 0){
		if(0 < num)res = N-1;
		else res =  0;
	}else{
		if(num >= 0){
			need = num / a - (num % a != 0);
		}else{
			need = num / a;
		}
		auto it = upper_bound(all(A), need);
		res = A.end() - it;
		if(a > need)--res;
	}

	//if(num == 1){
	//	printf("[a = %lld, need = %lld, res = %lld]\n", a, need, res);
	//}
	return res;
}

bool isOK(ll num){
	ll under = 0;
	ll same = 0;
	rep(i,N){
		under += calc_under(num, A[i]);
		if(A[i] != 0){
			if(num % A[i] == 0){
				same += exist[num / A[i]];
				if(A[i] == num / A[i])--same;
			}	
		}else{
			if(num == 0)same += N-1;
		}
	}
	under /= 2;
	same /= 2;
	//if(num == 1){
	//	printf("[num = %lld, under = %lld, same = %lld]\n", num, under, same);
	//}
	if(under >= K)return true;
	else{
		if(under + same >= K)return true;
		else return false;
	}
}

ll binary_search(){
	ll ng = -1e18 - 7;
	ll ok = 1e18 + 7;
	while(abs(ok-ng) > 1){
		ll mid = (ok + ng)/2;
		bool b = isOK(mid);
		//printf("[num = %lld -> %d]\n", mid, b);
		if(b)ok = mid;
		else ng = mid;
	}
	return ok;
}

int main(){
	cin >> N >> K;
	A.resize(N);
	rep(i,N){
		cin >> A[i];
		exist[A[i]] ++;
	}
	sort(all(A));
	cout << binary_search() << endl;
	return 0;
}


Measured memory_bytes: 16172
def combination(n,r,mod=10**9+7):
    n1 = n+1
    r = min(r,n-r)
    numer = denom = 1
    for i in range(1,r+1):
        numer = numer * (n1-i) % mod
        denom = denom * i % mod
    return numer * pow(denom,mod-2,mod) % mod

def power_func(a,n,p):
    bi=str(format(n,"b"))#2進表現に
    res=1
    for i in range(len(bi)):
        res=(res*res) %p
        if bi[i]=="1":
            res=(res*a) %p
    return res

mod = int(1e9+7)
n,a,b= map(int,input().split())

S = (power_func(2,n,mod) - 1)%mod
A = combination(n,a)
B = combination(n,b)
ans = (S-A-B)%mod

print(ans)

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

int main() {
	int N;
	cin >> N;
	vector<string> S(N);
	for (int i = 0; i < N; i++) cin >> S[i];
	sort(S.begin(), S.end());
	S.erase(unique(S.begin(), S.end()), S.end());
	cout << S.size() << endl;
}

Measured memory_bytes: 9524
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <stack>
#include <random>
#include <bitset>
#include <string>
#include <vector>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <algorithm>
#include <functional>
#include <unordered_map>

using namespace std;

int n, l;
set<int> w;

int main()
{
#if _DEBUG
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#else
	//freopen("capital.in", "r", stdin);
	//freopen("capital.out", "w", stdout);
#endif
	ios::sync_with_stdio(0);
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> l;
		if (w.count(l))
			w.erase(l);
		else
			w.insert(l);
	}
	cout << w.size();
	return 0;
}

Measured memory_bytes: 4992
import math

n = int(input())
ans = 0
l = [tuple(map(int, input().split())) for _ in range(n)]
for i in range(1001):
  th = 2*i*math.pi/1000
  thx = math.cos(th)
  thy = math.sin(th)
  cx,cy = 0,0
  for dx,dy in l:
    if thx*dx+thy*dy > 0:
      cx += dx
      cy += dy
  ans = max(ans,cx**2+cy**2)
print(ans**.5)


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

#define MAX 200000
#define SENTINEL 2000000000
typedef long long llong;

int L[MAX / 2 + 2], R[MAX / 2 + 2];

llong merge(int A[], int n, int left, int mid, int right) {
	int i, j, k;
	llong cnt = 0;
	int n1 = mid - left;
	int n2 = right - mid;
	for (i = 0; i < n1; i++) L[i] = A[left + i];
	for (i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	i = j = 0;
	for (k = left; k < right; k++) {
		if (L[i] <= R[j]) {
			A[k] = L[i++];
		}
		else {
			A[k] = R[j++];
			cnt += n1 - i;
		}
	}

	return cnt;
}

llong mergeSort(int A[], int n, int left, int right) {
	int mid;
	llong v1, v2, v3;
	if (left + 1 < right) {
		mid = (left + right) / 2;
		v1 = mergeSort(A, n, left, mid);
		v2 = mergeSort(A, n, mid, right);
		v3 = merge(A, n, left, mid, right);
		return v1 + v2 + v3;
	}
	else {
		return 0;
	}
}

int main() {
	int A[MAX], n, i;

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

	llong ans = mergeSort(A, n, 0, n);
	cout << ans << endl;

	return 0;
}


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

int main(){
    int h, w, ni, nj, mine;
    const int   dx[8] = {-1, 0, 1, -1, 1, -1, 0, 1},
                dy[8] = {-1, -1, -1, 0, 0, 1, 1, 1}; //選択コマの周囲８コマを調べるための既定値
    string board[50];

    cin >> h >> w;

    for(int i = 0; i < h; i++) cin >> board[i];

    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            //ここでは座標[i][j]のコマに着目
            if(board[i][j] == '#') continue;
            mine = 0; //mineの初期化
            for(int n = 0; n < 8; n++){
                ni = i + dy[n];
                nj = j + dx[n]; //新しい座標を代入

                if(ni < 0 || h <= ni) continue;
                if(w <= nj|| nj < 0) continue; //周囲コマを探索中範囲外参照をしそうな場合を排除

                if(board[ni][nj] == '#') mine++;
            }
            board[i][j] = mine + '0';
        }
    }

    for(int i = 0; i < h; i++) cout << board[i] << endl;
}

Measured memory_bytes: 256