akhauriyash/Code-Regression huggingface dataset:
fun main(args : Array<String>) {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val aa = readLine()!!.split(" ").map { it.toInt() }
    val sum = aa.sum()

    var cnt = 0
    aa.forEach {
        if (it != 0 && it * 4 * m >= sum) cnt++
        if (cnt == m) {
            println("Yes")
            return
        }
    }

    println("No")
}


Measured memory_bytes: 37876
import numpy as np

# 日数
D = int(input())
# type毎の満足度の下がりやすさ
c = np.array(list(map(int, input().split())))
# [d,i]の満足度
s = np.array([list(map(int, input().split())) for _ in range(D)])

# type毎に最後に開催された日を管理
lastday = np.zeros(26)

# d日目の終わりで低下する満足度
def cost(c, d, lastday, choicei):
    total = 0
    for i in range(26):
        # 調べたいtypeの場合は差分=0にしてマイナス計算させない
        lday = d if choicei == i else lastday[i]
        total += c[i] * (d - lday)
    return total

for d in range(D):
    # その日の満足度リストをソートしてindexを取得    
    # sd_sort = np.argsort(s[d])
    # max_ans = -1
    # typei = -1
    
    sd = s[d]
    scores = np.empty(26)
    for i in range(26):
        score = sd[i] - cost(c, d+1, lastday, i)
        scores[i] = score
        # # print("type:{}, ans={}".format(i, ans))
        # if ans > max_ans:
        #     # print("更新:{}".format(i))
        #     typei = i
        #     max_ans = ans

    typei = scores.argmax()
    lastday[typei] = d+1 # 日付なので+1
    print(typei+1)


Measured memory_bytes: 27256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long LL;

#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define ALL(a)  (a).begin(),(a).end()
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)

#define dump(x)  cerr << #x << " = " << (x) << endl;

int main() {
  int N, K;
  cin >> N >> K;
  vector<int> h(N);
  REP(i, N) {
    cin >> h[i];
  }
  sort(ALL(h));

  vector<int> dis(N-K+1);
  REP(i, N-K+1) {
    int max, min;
    min = h[i];
    max = h[i+K-1];
    dis[i] = max - min;
  }
  int res = 1e9;
  REP(i, N-K+1) {
    if (dis[i] < res) res = dis[i];
  }
  cout << res << endl;

  return 0;
}

Measured memory_bytes: 1024
#include "bits/stdc++.h"
using namespace std;
 
int main(){
  long long int n;
  cin>>n;
  vector<long long int> r(n+2);
  r[0]=2;
  r[1]=1;
 
  for(int i=2;i<=n;i++)r[i]=r[i-1]+r[i-2];
 
  cout<<r[n]<<endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define LL long long
#define endl '\n'
using namespace std;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int member[4][3][10] = {};
    int n;
    cin >> n;
    REP(i, n)
    {
        int b, f, r, v;
        cin >> b >> f >> r >> v;
        b--;f--;r--;
        member[b][f][r] += v;
    }
    REP(i, 4)
    {
        REP(j, 3)
        {
            REP(k, 10)
            {
                if (k != 9 || k != 0)
                    cout << " ";
                cout << member[i][j][k];
            }
            cout << endl;
        }
        if (i <= 2) {
            REP(i, 20) {
                cout << "#";
            }
            cout << endl;
        }
    }
    return 0;
}


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

int main() {
  int A,B,C,D;
  cin >> A>> B>> C>> D;

  if (A+B==C+D) {
    cout <<"Balanced"<< endl;
  }else if(A+B<C+D){
    cout <<"Right"<< endl;
  }else{
    cout <<"Left"<< endl;
  }
}

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

using namespace std;

const int MAXN = 100005;

struct Edge
{
	int to, next;	
}e[MAXN << 1];
int head[MAXN], te = 1;

inline void addE(int u, int v)
{
	e[++te] = (Edge){v, head[u]}, head[u] = te;
}

struct State
{
	long long D;
	int id;	
}d[MAXN];

bool operator <(const State &a, const State &b)
{
	return a.D > b.D;
}

map<long long, int> mp;

int size[MAXN], depth[MAXN], fa[MAXN];

long long Dn = 0;

int n;

void dfs(int u, int p = 0)
{
	if (p != 0)
	{
		depth[u] = depth[p] + 1;
		fa[u] = p;
		Dn += depth[u];	
	}
	for (int j = head[u]; j != 0; j = e[j].next)
		if (e[j].to != p)
			dfs(e[j].to, u);
}

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%lld", &d[i].D);
		d[i].id = i, size[i] = 1;
		mp[d[i].D] = i;
	}
	sort(d + 1, d + n + 1);
	for (int i = 1; i < n; i++)
	{
		long long D = d[i].D - n + (size[d[i].id] << 1);
		if (mp[D] == 0)
		{
			printf("-1\n");
			exit(0);	
		}
		addE(d[i].id, mp[D]), addE(mp[D], d[i].id);
		size[mp[D]] += size[d[i].id];
	}
	dfs(d[n].id);
	if (Dn != d[n].D)
	{
		printf("-1\n");
		exit(0);	
	}
	for (int i = 1; i <= n; i++)
		if (fa[i] != 0)
			printf("%d %d\n", fa[i], i);
	return 0;	
}


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

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

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

const int MAX = 1e5 + 5;
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

    vector<string> S(N);
    vector<int> T(N);
    rep(i, N) cin >> S[i] >> T[i];
    
    string X;
    cin >> X;

    int ans = 0;
    bool flg = false;
    rep(i, N) {
        if (flg) ans += T[i];
        if (S[i] == X) flg = true;
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
A = []
for i in range(3):
    A.append(list(input().split()))
N = int(input())
B = []
for i in range(N):
    B.append(input())
B=set(B)
if set(A[0]) <= B or set(A[1]) <= B or set(A[2]) <= B or {A[0][0], A[1][0], A[2][0]} <= B or\
{A[0][1], A[1][1], A[2][1]} <= B or {A[0][2], A[1][2], A[2][2]} <= B \
or {A[0][0], A[1][1], A[2][2]} <= B or {A[0][2], A[1][1], A[2][0]} <= B:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38288
A, B = map(int, input().split())

AB_max = max(A,B)
A_k = A
B_k = B
number = 2
A_soinsu = dict()
B_soinsu = dict()
soinsu = dict()
while (A_k != 1 and B_k != 1) or number <= AB_max:
    check = 0
    A_count = 0
    if A_k % number == 0:
        check = 1
        if number not in A_soinsu:
            A_soinsu[number] = 1
        else:
            A_soinsu[number] += 1
        A_count = A_soinsu[number]
        A_k = A_k / number
    
    B_count = 0
    if B_k % number == 0:
        check = 1
        if number not in B_soinsu:
            B_soinsu[number] = 1
        else:
            B_soinsu[number] += 1
        B_count = B_soinsu[number]
        B_k = B_k / number
    
    count_max = max([A_count, B_count])
    if number not in soinsu:
        soinsu[number] = count_max
    else:
        if count_max > soinsu[number]:
            soinsu[number] = count_max
    if check == 0:
        number += 1

ans = 1
for k, v in soinsu.items():
    ans = ans * (k ** v)
print(ans)       

Measured memory_bytes: 15080
#include <iostream>
#include <string>
using namespace std;
#define REP(i,n) for (int i=0; i<n; i++)
#define REP1(i,n1,n2) for (int i=n1; i<n2; i++)

int sum(int x[]){
	int s=0;
	REP1(i,1,10) s += x[i];
	return s;
}

bool check(int x[], int j=1){
	if (sum(x)==0) return true;
	REP1(i,j,10){
		int y[10];
		REP(j,10) y[j]=x[j];
		if (y[i]>=3){
			y[i]-=3;
			if (check(y,i)) return true;
			y[i]+=3;
		}
		if (i<8 && y[i]>0 && y[i+1]>0 && y[i+2]>0){
			y[i]--;
			y[i+1]--;
			y[i+2]--;
			if (check(y,i)) return true;
		}
	}
	return false;
}

int main(void){
	while (true){
		int n[10];
		REP(i,10) n[i]=0;
		string line;
		getline(cin,line);
		if (cin.eof()) break;
		REP(i,line.size()) n[line[i]-'0']++;

		bool f = false;
		REP1(i,1,10){
			int n1[10];
			REP(i1,10) n1[i1]=n[i1];
			if (n1[i]>=4) continue;
			else n1[i]++;
			REP1(j,1,10)
				if (n1[j] >= 2){
					n1[j] -= 2;
					if (check(n1)){
						if (f) cout<<" ";
						else f = true;
						cout<<i;
						break;
					}
					n1[j] += 2;
				}
		}
		if (f) cout<<endl;
		else cout<<"0"<<endl;
	}
}

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

using namespace std;

typedef struct node_{
    int id;
    node_* left;
    node_* right;
}* node;

void printPreorder(node root){
    printf(" %d", root -> id);
    if(root -> left != NULL){
        printPreorder(root -> left);
    }
    if(root -> right != NULL){
        printPreorder(root -> right);
    }
}

void printInorder(node root){
    if(root -> left != NULL){
        printInorder(root -> left);
    }
    printf(" %d", root -> id);
    if(root -> right != NULL){
        printInorder(root -> right);
    }
}

void printTree(node root){
    if(root == NULL){
        printf("\n\n");
    }else{
        printInorder(root);
        printf("\n");
        printPreorder(root);
        printf("\n");
    }
}

void nodeInsert(node root, node nd){
    if(root -> id > nd -> id){
        if(root -> left == NULL){
            root -> left = nd;
        }else{
            nodeInsert(root -> left, nd);
        }
    }else{
        if(root -> right == NULL){
            root -> right = nd;
        }else{
            nodeInsert(root -> right, nd);
        }
    }
    
}

int main(){
    int n;
    scanf("%d", &n);
    char* option = new char[7];
    node root = NULL;
    for(int i = 0; i < n; i++){
        scanf("%s", option);
        if(strcmp(option, "insert") == 0){
                int id;
                scanf("%d", &id);
                node nd = new node_;
                nd -> id = id;
                nd -> left = NULL;
                nd -> right = NULL;
            if(root == NULL){
                root = nd;    
            }else{
                nodeInsert(root, nd);
            }
        }else{
            printTree(root);
        }
    }
    return 0;
}


Measured memory_bytes: 18772
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <sstream>
#include <set>
using namespace std;

int main()
{
  int n, m;
  cin >> n >> m;
  int Q;
  cin >> Q;

  int len = 0;
  vector<int> order(m, -1);
  vector<int> natural(m);
  vector<int> freq(m + 1);
  freq[0] = n;

  vector<int> ac(Q);
  for (int iter=0; iter<Q; iter++) {
    cin >> ac[Q-1-iter];
    ac[Q-1-iter] --;
  }

  for (int iter=0; iter<Q; iter++) {
    int a = ac[iter];
//    printf("%d %d\n", a, order[a]);

    if (order[a] == -1) {
      order[a] = len;
      natural[len] = a;
      freq[len] --;
      len ++;
      freq[len] ++;
      continue;
    }
    if (freq[order[a]] == 0) continue;
    freq[order[a]] --;
    freq[order[a]+1] ++;
  }

  for (int i=0; i<m; i++)
    if (order[i] == -1) {
      natural[len++] = i;
    }
  int first = 0;
  for (int i=0; i<=m; i++)
    if (freq[i]) {
      first = i;
      break;
    }
  for (int i=first; i+1<m; i++)
    if (natural[i] > natural[i+1]) {
      cout << "No" << endl;
      return 0;
    }

  cout << "Yes" << endl;
  return 0;
}


Measured memory_bytes: 1920
#include<iostream>
#include <string> 
#include <vector>  
#include<math.h>

#define INF 1000000000
using namespace::std;



long Lmax(long x, long y) {
	if (x > y)return x;
	return y;
}

int max(int x, int y) {
	if (x > y)return x;
	return y;
}

long Lmin(long x, long y) {
	if (x < y)return x;
	return y;
}


int min(int x, int y) {
	if (x < y)return x;
	return y;
}

int abs(int x) {
	if (x < 0) {
		return -x;
	}
	return x;
}

bool c;
int point,N;
int H,X,Y ,Z,T, R, G,A[2002],B[2000], M, K, W, t[101], v[101], ans, now;
string S,s;

int main() {
	cin >> S;
	if (S[1] == S[2] && S[2] == S[3] || S[0] == S[1] && S[1] == S[2]) {
		cout << "Yes" << endl;
		return 0;
	}

	cout << "No" << endl;
	return 0;
}




Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
    long n,m,l;
    long A[100][100];
    long B[100][100];
    long C[100][100];
    
    cin >> n >> m >> l;
    
    for(int i=0;i<100;i++){
        for(int j=0;j<100;j++){
            A[i][j]=0;
            B[i][j]=0;
            C[i][j]=0;
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            cin >> A[i][j];
        }
    }
    
    for(int i=0;i<m;i++){
        for(int j=0;j<l;j++){
            cin >> B[i][j];
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<m;j++){
            for(int k=0;k<l;k++){
            C[i][k]+=A[i][j]*B[j][k];
            }
        }
    }
    
    for(int i=0;i<n;i++){
        for(int j=0;j<l;j++){
            if(j == l-1){
                cout << C[i][j] << endl;
            }else{
                cout << C[i][j] << " ";
            }
        }
    }
}
  


Measured memory_bytes: 3324
a = list(input())
k = int(input())
abc = "abcdefghijklmnopqrstuvwxyz"
c = 0
for e,i in enumerate(a[:-1]):
    # print(26-abc.index(i))
    if k-26+abc.index(i)>=0 and i!='a':
        a[e] = 'a'
        k-=26-abc.index(i)
    # print(k)  
k+=abc.index(a[-1])
k%=26
a[-1] = abc[k]

print("".join(a))

Measured memory_bytes: 4792
/*  -*- coding: utf-8 -*-
 *
 * m.cc: M - Candies
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_K = 100000;
const int MOD = 1000000007;

/* typedef */

/* global variables */

int dp[2][MAX_K + 1];

/* subroutines */

inline void addmod(int &a, int b) { a = (a + b) % MOD; }

/* main */

int main() {
  int n, k;
  scanf("%d%d", &n, &k);

  dp[0][0] = 1;
  int cur = 0, nxt = 1;

  for (int i = 0; i < n; i++) {
    int ai;
    scanf("%d", &ai);

    memset(dp[nxt], 0, sizeof(dp[nxt]));

    for (int j = 0; j <= k; j++) {
      int &dj = dp[cur][j];
      if (dj) {
	addmod(dp[nxt][j], dj);
	if (j + ai < k) addmod(dp[nxt][j + ai + 1], MOD - dj);
      }
    }

    for (int j = 0; j < k; j++)
      addmod(dp[nxt][j + 1], dp[nxt][j]);

    cur ^= 1, nxt ^= 1;
  }

  printf("%d\n", dp[cur][k]);
  return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <map>
#include <string>
#include <queue>
#include <set>
#include <math.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<ll, P> Q;
const ll mod = 1000000007;
const ll INF = 1000000000000000;
ll bit[100010], num;
ll par[100010], sz[100010];
ll n, a;
multiset<ll> st;


struct edge { ll to, cost; };
ll V;
vector<edge> G[300010];
ll d[300010];

ll root(int x) { // �f�[�^x��������؂̍����ċA�œ���Froot(x) = {x�̖؂̍�}
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

void unite(int x, int y) { // x��y�̖؂𕹍�
	int rx = root(x); //x�̍���rx
	int ry = root(y); //y�̍���ry
	if (rx == ry) return; //x��y�̍�������(=�����؂ɂ���)���͂��̂܂�
	par[rx] = ry; //x��y�̍��������łȂ�(=�����؂ɂȂ�)���Fx�̍�rx��y�̍�ry�ɂ���
}

bool same(int x, int y) { // 2�̃f�[�^x, y��������؂������Ȃ�true��Ԃ�
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}

ll sum(ll i)
{
	ll s = 0;
	while (i > 0)
	{
		s += bit[i];
		i -= i & -i;
	}
	return s;
}

void add(ll i, ll x)
{
	while (i <= num)
	{
		bit[i] += x;
		i += i & -i;
	}
}

ll po(ll x, ll y)
{
	if (y == 0) return 1;
	if (y % 2)
	{
		return po(x, y - 1) * x % mod;
	}
	else
	{
		ll yyy = po(x, y / 2);
		return yyy * yyy % mod;
	}
}

ll pow_mod(ll x, ll y)
{
	ll res = 1;
	while (y > 0)
	{
		if (y % 2 == 1)
		{
			(res *= x) %= mod;
		}
		(x *= x) %= mod;
		y /= 2;
	}
	return res;
}

ll div(ll x)
{
	return po(x, mod - 2);
}

int main(void)
{
	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> a;
		if (i == 0)
		{
			st.insert(a);
		}
		else
		{
			auto itr = st.lower_bound(a);
			if (itr != st.begin())
			{
				itr--;
				st.erase(itr);
			}
			st.insert(a);
		}
	}

	cout << st.size() << endl;

	int www;
	cin >> www;
}


Measured memory_bytes: 13184
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)
#define repr(i,a,b) for(ll i=a;i>=ll(b);i--)
#define endl "\n"
#define ALL(x) x.begin(),x.end()
#define ALLR(x) x.rbegin(),x.rend()
using namespace std;

#define INF 1e9

ll n, k;
int main() {
	cin >> n >> k;
	vector<int> a(n);
	rep(i, 0 ,n){
		 int tmp; cin  >> tmp;
		 a[i] = tmp-1;
	}
	
	vector<bool> seen(n,false);
	int root = 0;
	while(1){
		if(seen[root]) break;
		seen[root] = true;
		root = a[root];
		k--;
		if(k <= 0) {
			cout << root+1 << endl;
			return 0;
		}
	}
		
	int roopCount = 1, now = a[root];
	while(1){
		if(root == now)break;
		now = a[now];
		roopCount++;
	}
	
	k += roopCount;
	k %= roopCount;
	
	int ans = root;
	rep(i, 0, k){
		ans = a[ans];
	}
	
	cout << ans + 1 << endl;
    return 0;
}


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

// types
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;

// macros
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

// constants
const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int mod = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};


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

  ll n;
  cin >> n;

  vector<vector<ll>> a(2, vector<ll>(n));
  vector<vector<ll>> dp(2, vector<ll>(n));
  REP(i, 2){
    REP(j, n)
      cin >> a[i][j];
  }

  dp[0][0] = a[0][0];
  dp[1][0] = dp[0][0] + a[1][0];
  REP1(j, n)
    dp[0][j] = dp[0][j-1] + a[0][j];

  REP1(j, n)
    dp[1][j] = a[1][j] + max(dp[1][j-1], dp[0][j]);
  
  cout << dp[1][n-1] << endl;
}


Measured memory_bytes: 384
import sys, math
import io, os
#data = io.BytesIO(os.read(0,os.fstat(0).st_size)).readline
from bisect import bisect_left as bl, bisect_right as br, insort
from heapq import heapify, heappush, heappop
from collections import defaultdict as dd, deque, Counter
#from itertools import permutations,combinations
def data(): return sys.stdin.readline().strip()
def mdata(): return list(map(int, data().split()))
def outl(var) : sys.stdout.write('\n'.join(map(str, var))+'\n')
def out(var) : sys.stdout.write(str(var)+'\n')
from decimal import Decimal
from fractions import Fraction
#sys.setrecursionlimit(100000)
INF = float('inf')
mod = int(1e9)+7


n=int(data())
l=mdata()
l.sort()
ans=0
for i in range(n):
    for j in range(i+1,n):
        for k in range(j+1,n):
            if l[i]!=l[j] and l[j]!=l[k] and l[i]+l[j]>l[k]:
                ans+=1
out(ans)

Measured memory_bytes: 73404
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians, atan, degrees
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from fractions import gcd
from bisect import bisect

def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def main():
	N = INT()
	A = LIST()

	upper_len = len("{:b}".format(max(A)))

	cnt = [defaultdict(int) for _ in range(upper_len)]
	for i in range(N):
		num = "{:b}".format(A[i]).zfill(upper_len)
		for j in range(len(num)):
			cnt[upper_len-j-1][num[j]] += 1

	ans = 0
	for i in range(upper_len):
		ans = (ans + (1<<i)*cnt[i]["0"]*cnt[i]["1"])%mod
	print(ans)

if __name__ == "__main__":
	main()


Measured memory_bytes: 121148
#define _USE_MATH_DEFINES
#include <iomanip>
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <tuple>
#include <climits>
#include <algorithm>
#include <cmath>
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<double> VD;
typedef vector<LL> VLL;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<vector<int>> VVI;
typedef vector<vector<long long>> VVLL;
typedef vector<vector<bool>> VVB;
typedef vector<vector<double>> VVD;

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

const int MOD = 1000000007;

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

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

void debug(VI &arr){
	int n=arr.size();
	rep(i,n){
		cout<<arr.at(i)<<endl;
	}
}

void debug(VVI &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout << board.at(i).at(j) << " ";
		}
		cout<<endl;
	}
}

void debug(VVLL &board){
	int h = board.size();
	int w = board.at(0).size();
	rep(i,h){
		rep(j,w){
			cout<<board.at(i).at(j)<<" ";
		}
		cout<<endl;
	}
}

void debug(VS &board){
	int h = board.size();
	rep(i,h){
		cout<<board.at(i)<<endl;
	}
	return;
}

LL gcd(LL a,LL b){
	return b==0?a:gcd(b,a%b);
}

LL lcm(LL a,LL b){
	return a*b/gcd(a,b);
}

int main(){
	//cout<<fixed;
	//cout<<setprecision(9)<<...
	string s,t;
	int a,b;
	cin>>s>>t>>a>>b;
	string u;
	cin >>u;
	if(u==s)a--;
	else b--;
	cout<<a<<" "<<b<<endl;
	return 0;
}


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

int main(){
	int n;
	double r=0.05;
	int y = 100000;
	cin >> n;

	for(int i=0;i<n;i++){
		y = ( 1 + r ) * y;
		if(y%1000 != 0){
			y = y - y%1000;
			y = y + 1000;
		}
	}
	cout << y << endl;

}

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll s,w;
    cin >> s >> w;
    if(w >= s){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }

    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
    int i, j, h, w;
    char c[110][110];
    scanf("%d %d", &h, &w);
    for(i = 0; i < h; i++){
        //scanf("%s", c[i]);
        // 上の1行の代わりにこっちで書いても良い
        getchar();
        for(j = 0; j < w; j++){
            scanf("%c", &c[i][j]);
        }
    }
    for(i = -1; i <= h; i++){
        for(j = -1; j <= w; j++){
            if(i == -1 || i == h || j == -1 || j == w){
                printf("#");
            }else{
                printf("%c", c[i][j]);
            }
        }
        printf("\n");
        getchar();
    }
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll mod=1e18+7;

ll N,X;
ll brg[55];
ll pat[55];
ll ans;

ll eat(ll level,ll x){

	if(level==1){
		if(x<=1){
			return 0;
		}
		if(x==2){
			ans++;
			return 0;
		}
		if(x==3){
			ans+=2;
			return 0;
		}
		if(x>=4){
			ans+=3;
			return 0;
		}
	}
	ll m=brg[level];
	ll b=(m+1)/2;
	if(x==m){
		ans+=(2*pat[level-1]+1);
		return 0;
	}
	if(x==m-1){
		ans+=(2*pat[level-1]+1);
		return 0;
	}
	if((x<m-1)&&(x>b)){
		ans+=(pat[level-1]+1);
		return eat(level-1,x-b);
	}
	if(x==b){
		ans+=(pat[level-1]+1);
		return 0;
	}
	if(x==b-1){
		ans+=pat[level-1];
		return 0;
	}
	if(x<b-1){
		return eat(level-1,x-1);
	}
	return 0;

}

int main(){ 

cin.tie(0);
ios::sync_with_stdio(false);

cin>>N>>X;

brg[0]=1;
for(int i=1; i<=N; i++){
	brg[i]=2*brg[i-1]+3;
}
pat[0]=1;
for(int i=1; i<=N; i++){
	pat[i]=2*pat[i-1]+1;
}

eat(N,X);

cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <cstring>
#include <queue>
#include <cassert>
using namespace std;
#define debug(x) std::cerr << #x << " = " << (x) << std::endl
typedef long long LL;
const int MAXN = 1e5+17;
const LL MOD = 1e9+7;
vector<pair<LL,LL> > G[MAXN];
map<pair<LL,LL >,LL > mp;
LL mincost[MAXN];		// 从集合X出发的边到每个顶点的最小权值
bool used[MAXN];		// 顶点i是否包含在集合X中
int V,m=0;					// 顶点数
// first 最短路径，second顶点编号
typedef pair<LL, LL> P;

LL prim()
{
	V = m;
	LL res = 0;
	for (int i = 0; i < V; ++i)
	{
		mincost[i] = 9999999999999;
	}
	memset(used, 0, V * sizeof(bool));
	mincost[0] = 0;
	priority_queue<P, vector<P>, greater<P> > que;
	que.push(P(0, 0));  
	while (!que.empty())
	{
		P p = que.top(); que.pop();
		LL v = p.second;  
		if (used[v] || p.first > mincost[v]) continue;
		used[v] = true;
		res += 1LL*mincost[v];
		for (int i = 0; i < G[v].size(); ++i)
		{
			LL to = G[v][i].first,cost = G[v][i].second;
			if (mincost[to] > cost)
			{
				mincost[to] = cost;
				que.push(P(mincost[to], to));
			}
		}
	}
	assert(res<(1LL<<32));
	return res;
}
int main(int argc ,char const *argv[])
{
    #ifdef noob
    freopen("Input.txt","r",stdin);freopen("Output.txt","w",stdout);
    #endif	
    int n;
    cin>>n;
    vector<pair<LL,LL > > x,y,all;
    for (int i = 0; i < n; ++i)
    {
    	LL a,b;
    	cin>>a>>b;
    	// if(mp[{a,b}]!=1)
    	// {
    		//mp[{a,b}]=1;
    		m++;
    		all.push_back({a,b});
    		x.push_back({a,i});
    		y.push_back({b,i});
    	//}
    }
    sort(x.begin(), x.end());
    sort(y.begin(), y.end());
    for (int i = 0; i < m; ++i)
    {
    	LL tx = all[i].first,ty = all[i].second;
    	pair<LL,LL > tp =  {tx,i};
    	vector<pair<LL,LL > > :: iterator itx1 = lower_bound(x.begin(), x.end(),tp);
    	if((itx1+1)!=x.end()&&(*(itx1+1)).first==tx) 
    	{
    		itx1++;
    	}
    	else if(itx1!=x.begin()) itx1--;
		LL cost = (tx-((*itx1).first)),v = ((*itx1).second);
    	G[i].push_back({v,cost});
    	G[v].push_back({i,cost});
    	itx1 = upper_bound(x.begin(), x.end(), tp);
    	if(itx1!=x.end())
    	{
    		cost = ((*itx1).first)-tx,v = ((*itx1).second);
    		G[i].push_back({v,cost});
    		G[v].push_back({i,cost});
    	}

    	tp =  {ty,i};
    	itx1 = lower_bound(y.begin(), y.end(), tp);
    	if((itx1+1)!=y.end()&&(((*(itx1+1)).first==ty))) 
    	{
    		itx1++;
    	}
    	else if(itx1!=y.begin()) itx1--;
		cost = ty-((*itx1).first),v = ((*itx1).second);
    	G[i].push_back({v,cost});
    	G[v].push_back({i,cost});
    	itx1 = upper_bound(y.begin(), y.end(), tp);
    	if(itx1!=y.end())
    	{
    		cost = ((*itx1).first)-ty,v = ((*itx1).second);
    		G[i].push_back({v,cost});
    		G[v].push_back({i,cost});
    	}
    }
    cout<<1LL*prim()<<endl;
    return 0;
}


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

const int maxn=50000+10;
int sum[maxn],num[maxn],N,W,R[maxn];

inline int len(int l,int r)
{
    if (l>=r) return 0;
    if (sum[r]-sum[l-1]+r-l>W) return -1;
    return (W-(sum[r]-sum[l-1])+(r-l-1))/(r-l);
}

bool solve(int can)
{
    int now=1,st,ed,l,r,maxs=0;
    memset(num,0,(N+2)*sizeof(int));
    num[1]=-1;
    l=2;
    for(int i=0;i<=maxs;i++)
    {
        now+=num[i];
        if (now<=0||len(i+1,R[i+1])>can) continue;
        if (l<i+2) l=i+2;
        while(len(i+1,l)>can) l++;
        r=R[i+1];
        num[l]++;
        num[r+1]--;
        if (r>maxs) maxs=r;
        if (sum[N]-sum[r]+N-r<=W) return 1;
    }
    return 0;
}

int main()
{
    while(scanf("%d%d",&W,&N)==2)
    {
        if (W==0&&N==0) break;
        sum[0]=0;
        for(int i=1;i<=N;i++) scanf("%d",&sum[i]),sum[i]+=sum[i-1];
        int st=1,ed=W/2+1;
        if (sum[N]+N-1<=W) ed=1;
        int j=N;
        for(int i=N-1;i>=1;i--)
        {
            while(sum[j]-sum[i-1]+j-i>W) j--;
            R[i]=j;
        }
        while(st<ed)
        {
            int mid=(st+ed)>>1;
            if (solve(mid)) ed=mid;
            else st=mid+1;
        }
        printf("%d\n",st);
    }
    return 0;
}
/*
11 4
4 2 1 3
5 7
1 1 1 2 2 1 2
11 7
3 1 3 1 3 3 4
100 3
30 30 39
30 3
2 5 3
0 0
*/

Measured memory_bytes: 1620
#include <iostream>
#include <vector>
#include <limits.h>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <bitset>
#include <cassert>
#include <random>
#include <functional>
#include <stack>
#include <iomanip>
using namespace std;

template<class T>
void in(vector<T>& V) {
	for (auto itr = V.begin(); itr != V.end(); itr++)cin >> *itr;
	return;
}

template<class T>
void out(vector<T>& V) {
	for (T& itr : V)cout << itr << endl;
	return;
}

vector<int> DP1, DP2;
int N;

int main() {
	string S;
	cin >> N >> S;
	DP1.resize(N + 2, 0);
	DP2.resize(N + 2, 0);
	for (int n = 1; n <= N; n++) {
		DP1[n] = DP1[n - 1] + (S[n - 1] == 'W' ? 1:0);
	}
	for (int n = N; n >= 1; n--) {
		DP2[n] = DP2[n + 1] + (S[n - 1] == 'E' ? 1 : 0);
	}
	int ans = INT_MAX;
	for (int n = 1; n <= N; n++) {
		int temp = 0;
		temp = DP1[n - 1] + DP2[n + 1];
		ans = min(ans, temp);
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<string> key(n);
  for(int i = 0; i < n; i++)cin >> key[i];

  int m;
  cin >> m;
  bool locked = true;
  bool change;
  string in;
  for(int i = 0; i < m; i++){
    change = false;
    cin >> in;
    for(int j = 0; j < n; j++){
      if(in == key[j]){
        locked = !locked;
        change = true;
        break;
      }
    }
    if(change){
      if(locked)cout << "Closed by " << in << endl;
      else cout << "Opened by " << in << endl;
    }else{
      cout << "Unknown " << in << endl;
    }
  }

}

Measured memory_bytes: 3160
#include <iostream>
#include <map>

using namespace std;

int main(void){
	int n;
	while(cin >> n && n){
		map<int,int> m;
		int a,b,w;
		for(int i=0;i<n;i++){
			cin >> w >> a >> b;
			m[a] += w;
			m[b] -= w;
		}
		map<int,int>::iterator it = m.begin();
		int tmp=0;
		bool ok = true;
		while(it != m.end()){
			tmp += (*it).second;
			if(tmp > 150){
				ok = false;
				break;
			}
			++it;
		}
		if(ok){
			cout << "OK" << endl;
		}else{
			cout << "NG" << endl;
		}
	}
}

Measured memory_bytes: 0
/// kazuki08
/*
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
*/
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
#define int long long
typedef long long ll;
typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update>ordered_set;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef vector<pi> vpi;
#define ar array
//#define inf 1000000000
#define mod 1000000007
#define dmp(x) cerr<<"line "<<__LINE__<<" "<<#x<<":"<<x<<endl
#define fs first
#define sc second
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define mt make_tuple
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
    return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
    o<<"{";
    for(const T& v:vc) o<<v<<",";
    o<<"}";
    return o;
}
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());



signed main(){
IOS;
//freopen("input.txt", "r", stdin);
//freopen("output.txt", "w", stdout);
  

  int n;
  ld d;
  cin >> n >> d;
  int ans = 0;
  for(int i=1;i<=n;i++){
    ld x,y;
    cin >> x >> y;
    if(sqrt(x*x+y*y)<=d)ans++;
  }
  cout << ans << endl;
  

return 0;
}
///....


Measured memory_bytes: 3832
package main

import "fmt"

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func divisors(n int) (r map[int]int) {
	r = make(map[int]int, 0)
	for i := 2; i*i <= n; i++ {
		for n%i == 0 {
			n /= i
			r[i]++
		}
	}
	if n > 1 {
		r[n]++
	}
	return r
}

func main() {
	var A, B int
	fmt.Scan(&A, &B)
	// fmt.Println("A", A, "B", B, "GCD", gcd(A, B), "divs(GCD)", divisors(gcd(A, B)))
	fmt.Println(len(divisors(gcd(A, B))) + 1)
}


Measured memory_bytes: 512
#include <iostream>
#include <float.h>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <iomanip>
#include <sstream>
#include <bitset>
#include <fstream>
#include <queue>
#include <set>
#include <stdlib.h>
#include <time.h>
#include <list>
#include <stack>
#include <queue>
#include <sstream>

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

//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
#define SORT(c) sort((c).begin(),(c).end())
#define vi(m,a) vector<int> m(a)
#define vti(m,a,i) vector<vector<int>> m(a,vector<int>(i))
#define ALL(it,a) for(auto it = a.begin(); it!=a.end(); it++)
#define Fe(it,a) for(auto &it : a)
#define all(a) begin(a),end(a)

using namespace std;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
#define WARU 1000000007;

int dx[] = { 1,0,-1,0 };
int dy[] = { 0,1,0,-1 };

int main() {
	ll n, m;
	ll k;
	cin >> n >> m >> k;
	bool flag = false;
	rep(i, n + 1)
		rep(l, m + 1) {
		if (n*l + m *i - 2 * i*l == k)
			flag = true;

	}
	if (flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;


}



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

typedef long long ll;

int ans;
int n;
int sTakahashi, sAoki;
int aoki[100000];
vector<int> t[100000];

void createAoki(int cur, int dist) {
  aoki[cur] = dist;
  for (int i = 0; i < t[cur].size(); i++) {
    int next = t[cur][i];
    if (aoki[next] == -1) {
      createAoki(next, dist + 1);
    }
  }
}

void solve(int cur, int pre, int dist) {
  if (aoki[cur] >= dist) {
    if (dist % 2 == aoki[cur] % 2) {
      ans = max(ans, dist);
    } else {
      ans = max(ans, dist - 1);
    }
  }
  if (aoki[cur] <= dist) {
    return;
  }
  if (t[cur].size() == 1) {
    int distPre = aoki[t[cur][0]];
    ans = max(ans, distPre);
  }
  ans = max(ans, dist);
  for (int i = 0; i < t[cur].size(); i++) {
    int next = t[cur][i];
    if (pre != next) {
      solve(next, cur, dist + 1);
    }
  }
}

int main() {
  while (cin >> n >> sTakahashi >> sAoki) {
    sTakahashi--;
    sAoki--;
    for (int i = 0; i < 100000; i++) {
      t[i].clear();
    }
    for (int i = 0; i < n - 1; i++) {
      int a, b;
      cin >> a >> b;
      a--;
      b--;
      t[a].push_back(b);
      t[b].push_back(a);
    }

    memset(aoki, -1, sizeof(aoki));
    createAoki(sAoki, 0);

    ans = 0;
    solve(sTakahashi, -1, 0);

    cout << ans << endl;
  }
}


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

char next_char(char c, int n) {
  for (int i = 0; i < n; i++) {
    if (c == 'z') { c = 'a'; }
    else { c += 1; }
  }
  return c;
}

int main() {
  char WORD[100000];
  int N;

  scanf("%s", WORD);
  scanf("%d", &N);

  int len = strlen(WORD);

  int n = N;

  for (int i = 0; i < len; i++) {
    if (WORD[i] == 'a') { continue; }

    int required_n = (122 - WORD[i] + 1);

    if (n >= required_n) {
      WORD[i] = 'a';
      n -= required_n;
    }
    else {
      continue;
    }
  }

  if (n >= 0) {
    WORD[len-1] = next_char(WORD[len-1], n);
  }

  printf("%s\n", WORD);

  return 0;
}



Measured memory_bytes: 384
#http://d.hatena.ne.jp/yatt/20130128/1359370204
def try_square_root_naive(n):
    m = int(n**.5)
    return m if abs(m*m - n) < 1e-6 else 0

a,b=[str(i) for i in input().split()]
c=a+b
d=int(c)
#print(d)
if try_square_root_naive(d)!=0:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>
#include <queue>
#include<string>
#include<cstring>
#include<complex>
#include<cmath>
#include <iomanip>
using namespace std;
#define rep(i, n)   for(int i = 0; i < (int)(n); i++)
#define rrp(i, n)   for(int i = ((int)(n)); i >=0; i--)
#define mpp(i,j,k)  make_pair((int)(i),make_pair((int)(j),(int)(k)))
typedef pair<int,pair<int,int > > ppp;
typedef pair<int,int> pp;
typedef vector<int> vi;
typedef vector<vi>  vvi;

const int N=15e4+1;
long double dp[N];
long double dp2[N];
vvi e(N,vi());
int p;

long double dfs(int v,int parent){
  rep(i,e[v].size()){
    int u=e[v][i];
    if(parent==u)continue;
    else{dp[v]+=dfs(u,v);}
  }
  if(e[v].size()>1){
      if(v==1)dp[v]/=e[v].size();
      else{
       dp[v]/=e[v].size()-1;}
      
  }
  if(!(e[v].size()==1&&e[v][0]==parent))dp[v]+=1.0;
return dp[v];}

void dfs2(int v,int parent){
  if(v>1)dp2[v]=dp2[parent];
  if(parent==1)p=e[parent].size();
  else{p=e[parent].size()-1;}
  
  if (p>1){
  dp2[v]+=(dp[parent]-(1.0+dp[v])/p)*p;
  dp2[v]/=e[parent].size()-1;
  }
  if(v>1)dp2[v]+=1.0;
  rep(i,e[v].size()){
    int u=e[v][i];
    if(parent==u)continue;
    else{dfs2(u,v);}
  }
} 

int main(){

int a,b,n;
cin>>n;
rep(i,n-1)cin>>a>>b,e[a].push_back(b),e[b].push_back(a);



dfs(1,0);
dfs2(1,0);
cout << fixed << setprecision(8);
cout<<dp[1]<<endl;
for(int i=2;i<=n;i++)cout<<(dp[i]*(e[i].size()-1)+dp2[i])/e[i].size()<<endl;
  return 0;
}


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

int main() {
  int count = 0;
  string num;
  cin >> num;
  for ( int i=0 ; i<3 ; i=i+1 ) {
    if ( num[i] == '1' ) {
      count = count + 1;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 256
N = int(input())


def GetDivider(num):
    cnt = 0
    for i in range(1, num+1):
        if num % i == 0:
            cnt += 1
    return cnt


ans = 0
for i in range(1, N+1):
    if GetDivider(i) == 8:
        if i % 2 != 0:
            ans += 1
print(ans)


Measured memory_bytes: 63564
#include <bits/stdc++.h>
using namespace std;
#define int long long 
#define all(v) (v).begin(),(v).end();
const int mod = 1e9+7;
const int N = 1e5+20;

int a[N];
int sum[N];
int n;
int ksm(int a,int b){
    int ans=1; a%=mod;
    for(;b;b>>=1,a=a*a%mod)
    {
        if(b&1)ans=ans*a%mod;
       // cout<<b<<" "<<ans<<" "<<a<<endl;
    }
    return ans;
}
 int inv(int x){
    return ksm(x,mod-2);
}
signed main(){

 //   cout<<inv(2)<<endl;
    ios::sync_with_stdio(0);
    cin>>n;
    int Fac=1;
    for(int i=1;i<n;i++)Fac=Fac*i%mod;
    for(int i=1;i<=n;i++)cin>>a[i],sum[i]=sum[i-1]+a[i],sum[i]%=mod;
    int ans=0;
   // cout<<sum[n]<<endl;

    for(int k=1;k<=n-2;k++){
        int r=(sum[n-1]-sum[k]);
        int l=sum[n-k-1];
      //  cout<<k<<" "<<inv(k)<<" "<<inv(k+1)<<endl;
        ans += inv(k)*inv(k+1)%mod*(r-l)%mod;
        ans %= mod;
    }
   // cout<<ans<<endl;
    for(int i=1;i<=n-1;i++){
         ans += inv(n-i)*(a[n]-a[i])%mod;
         ans %= mod;
    }
    ans=(ans*Fac%mod+mod)%mod;
    cout<<ans<<endl;
    


   
  //  getchar();getchar();

}


Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main() {
	int N, B;
	cin >> N >> B;
	if (N >= 13) {
		cout << B << endl;
	}
	else if (6 <= N && N <= 12) {
		cout << B / 2 << endl;
	}
	else {
		cout << B % 2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
while 1:
    try:
        c=map(int,raw_input().split())
        sumc=c[0]+c[1]
        cnt=0
        for i in xrange(1,11):
            if i in c:continue
            if sumc+i<=20:
                cnt+=1
        if cnt>=4:
            print('YES')
        else:
            print('NO')
    except:
        break

Measured memory_bytes: 6316
package main

import (
	"fmt"
)

func main() {
	var s string
	fmt.Scan(&s)

	for {
		s = s[:len(s)-1]
		if len(s)%2 == 0 && s[:len(s)/2] == s[len(s)/2:] {
			fmt.Println(len(s))
			return
		}
	}
}


Measured memory_bytes: 512
s = input()
n = True
for i in range(len(s)):
  if s[i] == 'L' and i % 2 == 0:
    n = False
    break
  elif s[i] == 'R' and i % 2 == 1:
    n = False
    break
if n:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3060
#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>
#include <string>
#include <map>
#ifdef __mr__
#include "prettyprint.hpp"
#endif

#include<vector>
#define endl                        ('\n')
using namespace __gnu_pbds;
using namespace std;
typedef vector<int> vi;
typedef vector<long long> vll;
typedef tree<
        int,
        null_type,
        less<int>,
        rb_tree_tag,
        tree_order_statistics_node_update>
        ordered_set;
int arr[26];
int nextint(){
    int z;
    scanf("%d",&z);
    return z;

}
long long nextlong(){
    long long z;
    scanf("%dll",&z);
    return z;

}
int main() {
    int n=nextint();
int i=nextint();
cout<<n-i+1<<endl;
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
using namespace std;

#define hi(x) ((x)>>16)
#define lo(x) ((x)&0xffff)

struct comp{
    bool operator()(const unsigned a, const unsigned b){return hi(a)*lo(a) < hi(b)*lo(b);}
};

int main(){
	int n,w,d;
	while(1){
		scanf("%d %d %d",&n,&w,&d);
		if(!n&&!w&&!d)return 0;
		
{
	vector<unsigned> v;
	v.push_back((w<<16)+d);
	while(n--){
		int p, s, state=0;
		scanf("%d %d", &p, &s);
		p--;
		s%=hi(v[p])+lo(v[p]);
		
		unsigned x=hi(v[p]), y=lo(v[p]), _x=0, _y=0;
		while(s--){
			switch(state){
				case 0:{
					_x++;
					if(_x==x)state=1;
					break;
				}
				case 1:{
					_y++;
					break;
				}
			}
		}
		unsigned x1, x2, y1, y2;
		switch(state){
			case 0:{
				x1=_x;x2=x-_x;
				y1=y2=y;
				break;
			}
			case 1:{
				x1=x2=x;
				y1=_y;y2=y-_y;
				break;
			}
		}
		
		v.erase(v.begin()+p);
		if(x1*y1>x2*y2){
			v.push_back((x2<<16)+y2);
			v.push_back((x1<<16)+y1);
		}else{
			v.push_back((x1<<16)+y1);
			v.push_back((x2<<16)+y2);
		}
	}
	
	sort(v.begin(), v.end(), comp());
	while(v.size()){
		printf("%d", hi(v[0])*lo(v[0]));
		v.erase(v.begin());
		if(v.size())printf(" ");
	}
	printf("\n");
}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <numeric>
#include <complex>
#define rep(i,n) for(int (i) = 0; (i) < (n); ++(i))
using namespace std;
typedef long long ll;

int main(){
    int n;
    cin >> n;
    vector<int> p(n);
    vector<int> q(n);
    rep(i,n) cin >> p[i];
    rep(i,n) cin >> q[i];
    vector<int> v(n);
    iota(v.begin(), v.end(), 1);
    int a = 0, b = 0;

    do{
        bool flag = true;
        rep(i,n){
            if(p[i] != v[i]){
                flag = false;
            }
        }
        if(flag) break;
        else ++a;
    }while(next_permutation(v.begin(), v.end()));


    iota(v.begin(), v.end(), 1);
    do{
        bool flag = true;
        rep(i,n){
            if(q[i] != v[i]){
                flag = false;
            }
        }
        if(flag) break;
        else ++b;
    }while(next_permutation(v.begin(), v.end()));

    cout << abs(a-b) << endl;

    return 0;
}


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

using namespace std;

int f(int x)
{
    int sol=0;
    while(x>0)
    {
        sol+=x%10;
        x/=10;
    }
    return sol;
}

int sum;
int bst=(1<<30);

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin>>sum;
    for(int a=1;a<=sum-a;a++)
    {
        int b=sum-a;
        if(b==0)
            continue;
        bst=min(bst,f(a)+f(b));
    }
    cout<<bst<<"\n";
    return 0;
}


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



Measured memory_bytes: 1804
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    ll n;
    cin >> n;
    string res = "";
    while(n > 0){
        n--;
        int temp = n % 26;
        res += ('a' + temp);
        n = n / 26;
    }
    reverse(res.begin(), res.end());
    cout << res << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //GCC5.4.1で配列の範囲外アクセスをエラーにする

//cmdで g++ test.cpp とするとコンパイルできる
//制限1秒なら10^6は余裕 10^7は多分間に合う 10^8はよほど単純でないと厳しい
// https://github.com/atcoder/live_library
// cppdbg: test.exeのterminalに標準入力を打てる

#define ALL(x) x.begin(),x.end()
#define get_tp(t,i) get<i>(t)
#define len(x) (ll)(x.size())
#define ub(a,x) (upper_bound(ALL(a),x)-a.begin())
#define lb(a,x) (lower_bound(ALL(a),x)-a.begin())
typedef long long ll; //long long
typedef pair<int,int> pii; //pair<int,int>
typedef pair<long long,long long> pllll; //pair<ll,ll>
typedef vector<int> vi; //vector<int>
typedef vector<vector<int>> vvi; //vector<vector<int>>
typedef vector<ll> vll; //vector<long long>
typedef vector<vector<ll>> vvll; //vector<vector<long long>>
typedef priority_queue<ll, vector<ll>, greater<ll> > gpq; //逆順priority_queue
typedef priority_queue<ll> pq;

//const int MOD=998244353;
const int MOD=1000000007; //10^9+7
const long double PI=3.1415926535897932;

int main(){
    string S;cin>>S;
    S[5]=' ';S[13]=' ';
    cout<<S<<endl;
}

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

using ll = long long;
using namespace std;

int main() {
    ll n, a, b, c, d;
    cin >>n>>a>>b>>c>>d;
    ll e = b-a;
    for (int i = 0; i <= n - 1; i++) {
        if (e <= (n - 1 - i) * d - i * c && e >= -i * d + (n - 1 - i) * c) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;

}


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

using Pair = System.Collections.Generic.KeyValuePair<int, int>;

class Program
{
	public Program() { }

	static void Main(string[] args)
	{
		new Program().prog();
	}

	Scanner cin;

	const int MOD = 1000000007;
	const int INF = int.MaxValue - 10;
	const long INFL = long.MaxValue - 10;
	const double EPS = 1e-8;
	const double PI = 3.1415926536;
	int[,] dir8;
	int[,] dir4;



	void prog()
	{
		cin = new Scanner();
		dir8 = new int[8, 2] { { -1, -1 }, { -1, 0 }, { -1, 1 }, { 0, -1 }, { 0, 1 }, { 1, -1 }, { 1, 0 }, { 1, 1 } };
		dir4 = new int[4, 2] { { -1, 0 }, { 0, -1 }, { 0, 1 }, { 1, 0 } };

		int H = cin.nextInt();
		int W = cin.nextInt();
		char[][] red = new char[H][];
		char[][] blue = new char[H][];

		for (int i = 0; i < H; i++)
		{
			string str = cin.next();
			red[i] = new char[W];
			blue[i] = new char[W];
			for (int j = 0; j < W; j++)
			{
				if (str[j] == '#')
				{
					red[i][j] = blue[i][j] = '#';
				}
				else
				{
					if (i % 2 == 0)
					{
						if (j != W - 1)
						{
							red[i][j] = '#';
							blue[i][j] = '.';
						}
						else
						{
							red[i][j] = '.';
							blue[i][j] = '#';
						}
					}
					else
					{
						if (j == 0)
						{
							red[i][j] = '#';
							blue[i][j] = '.';
						}
						else
						{
							red[i][j] = '.';
							blue[i][j] = '#';
						}
					}
				}
			}
		}
		for (int i = 0; i < H; i++)
		{
			Console.WriteLine(red[i]);
		}
		Console.WriteLine();
		for (int i = 0; i < H; i++)
		{
			Console.WriteLine(blue[i]);
		}
	}
}

class Scanner
{
	string[] s;
	int i;

	char[] cs = new char[] { ' ' };

	public Scanner()
	{
		s = new string[0];
		i = 0;
	}

	public string next()
	{
		if (i < s.Length) return s[i++];
		string st = Console.ReadLine();
		while (st == "") st = Console.ReadLine();
		s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
		i = 0;
		return next();
	}

	public int nextInt()
	{
		return int.Parse(next());
	}

	public long nextLong()
	{
		return long.Parse(next());
	}

	public double nextDouble()
	{
		return double.Parse(next());
	}
}

Measured memory_bytes: 6228