akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
  int dice[7][101];
  int k,l,n=0;
  char roll[101];
  for(k=1;k<=6;k++){
    scanf("%d",&dice[k][0]);
  }
  scanf("\n");
  for(k=1;k<=100;k++){
    scanf("%c",&roll[k]);
    if(roll[k]=='\n') break;
    n++;
  }
  for(k=1;k<=n;k++){
    if(roll[k]=='S'){
      dice[2][k]=dice[1][k-1];
      dice[6][k]=dice[2][k-1];
      dice[5][k]=dice[6][k-1];
      dice[1][k]=dice[5][k-1];
      dice[3][k]=dice[3][k-1];
      dice[4][k]=dice[4][k-1];
    }else if(roll[k]=='N'){
      dice[5][k]=dice[1][k-1];
      dice[1][k]=dice[2][k-1];
      dice[2][k]=dice[6][k-1];
      dice[6][k]=dice[5][k-1];
      dice[3][k]=dice[3][k-1];
      dice[4][k]=dice[4][k-1];
    }else if(roll[k]=='W'){
      dice[4][k]=dice[1][k-1];
      dice[1][k]=dice[3][k-1];
      dice[3][k]=dice[6][k-1];
      dice[6][k]=dice[4][k-1];
      dice[2][k]=dice[2][k-1];
      dice[5][k]=dice[5][k-1];
    }else if(roll[k]=='E'){
      dice[1][k]=dice[4][k-1];
      dice[3][k]=dice[1][k-1];
      dice[6][k]=dice[3][k-1];
      dice[4][k]=dice[6][k-1];
      dice[5][k]=dice[5][k-1];
      dice[2][k]=dice[2][k-1];
    }
  }
  printf("%d\n",dice[1][n]);
  return 0;
}

Measured memory_bytes: 600
#include<iostream>

using namespace std;

int main(){

  int t;

  cin >> t;

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

      int n;
      cin >> n;
      int data[n];

      int mup = 0, mdn = 0;
 

      for(int j = 0; j < n; j++){
	cin >> data[j];
	int pre;
	if(j != 0){
	  pre = data[j-1]-data[j];
	  
	  if(pre < 0){
	    pre *= -1;
	    if(pre > mup) mup = pre;
	  }else{
	    if(pre > mdn) mdn = pre;
	  }
	}
      }

      cout << mup << " " << mdn << endl;
    }
  return 0; 
}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    int n,state = 0,cnt = 0,v;
    vector<int> a;
    cin >> n;
    for(int i = 0;i < n;i++){
        cin >> v;
        a.push_back(v);
    }
    while(state != 1){
        state = a[state]-1;
        cnt++;
        if(cnt > n){
           cnt = -1;
           break;
       }
    }
    cout << cnt << endl;
    return 0;
}

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

typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) std::cout << x << '\n'
#define all(a) a.begin(), a.end()
#define pb push_back
#define sz(x) ((int)(x).size())
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { ll g = gcd(a, b); return a / g * b; }
const int dx[4] = { 1, 0, -1,  0 };
const int dy[4] = { 0, 1,  0, -1 };
const int INF = (int)1e9;
const ll  inf = (ll)1e18;
const int mod = 1000000007;
const int MAX_N = 100010;

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(10);
	/*------------------------------*/

	ll n, p;
	cin >> n >> p;
	vl a(n);
	ll odd = 0, even = 0;
	rep(i, n) {
		cin >> a[i];
		if (a[i] % 2 == 0) {
			even++;
		}
		else {
			odd++;
		}
	}

	if (p == 0) {
		if (odd == 0) {
			out((ll)pow(2, n));
		}
		else {
			out((ll)pow(2, n - 1));
		}
	}
	else {
		if (odd > 0) {
			out((ll)pow(2, n - 1));
		}
		else {
			out(0);
		}
	}

	return 0;
}

Measured memory_bytes: 512
a = int(input())
b = int(input())
c = int(input())
x = int(input())


def binary_search(x, c_nums):
    l = 0
    r = c
    while l + 1 != r and c != 0:
        m = (l + r) // 2
        if c_nums[m] == x:
            return 1
        elif c_nums[m] < x:
            l = m
        elif c_nums[m] > x:
            r = m
        m = (l + r) // 2
    if x == c_nums[l] or x == c_nums[r]:
        return 1
    else:
        return 0


c_nums = [50 * i for i in range(c + 1)]
res = 0
for i in range(a + 1):
    for j in range(b + 1):
        tmp = x - 500 * i - 100 * j
        res += binary_search(tmp, c_nums)

print(res)


Measured memory_bytes: 9212
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <list>
#include <utility>
#include <tuple>
#include <cstdio>
#include <set>
#include <queue>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#include <cmath>
#define _GLIBCXX_DEBUG
using namespace std;
const long long INF = 1LL << 60;
typedef long long ll;
int main() {
    ll A,B,C;
    cin >> A >> B >> C;
    ll a,b,c;
    a = A;
    b = B;
    c = C;
    ll cnt = 0;
    while( a%2==0 && b%2==0 && c%2==0){
        cnt++;
        ll na,nb,nc;
        na = (b + c)/2 ;
        nb = (a + c)/2 ;
        nc = (a + b)/2 ;
        if( (na%2==0 && nb%2==0 && nc%2==0)&&((na==nb)&&(nb==nc))){
            cnt = -1;
            break;
        }
        a = na;
        b = nb;
        c = nc;
    }
    cout << cnt <<endl;
    
}


Measured memory_bytes: 3600
#include <iostream>
#include <cstdio>
#include <cstring>
using namespace std;
const int mod=1e9+7;
int n,m,f[3005][3005];
int add(int a,int b){return a+b>=mod?a+b-mod:a+b;}
int main(){
	scanf("%d%d",&n,&m);
	for(int i=0;i<=n;i++) f[0][i]=1;
	for(int i=0;i<m;i++){
		for(int p=0;p<=n;p++)if(f[i][p]){
			if(p){
				f[i+1][p]=add(f[i+1][p],f[i][p]);
				f[i+1][p-1]=add(f[i+1][p-1],f[i][p]);
			}
			if(p<n){
				f[i+1][p]=add(f[i+1][p],f[i][p]);
				f[i+1][p+1]=add(f[i+1][p+1],f[i][p]);
			}
		}
	}
	int ans=0;
	for(int i=0;i<=n;i++) ans=add(ans,f[m][i]);
	memset(f,0,sizeof(f));
	for(int i=0;i<n;i++) f[0][i]=1;
	for(int i=0;i<m;i++){	
		for(int p=0;p<n;p++)if(f[i][p]){
			if(p){
				f[i+1][p]=add(f[i+1][p],f[i][p]);
				f[i+1][p-1]=add(f[i+1][p-1],f[i][p]);
			}
			if(p<n-1){
				f[i+1][p]=add(f[i+1][p],f[i][p]);
				f[i+1][p+1]=add(f[i+1][p+1],f[i][p]);
			}
		}
	}
	for(int i=0;i<n;i++) ans=add(ans,mod-f[m][i]);
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 35456
S = input()
N = len(S)
chl = [0] * N

peo = 0
for i in range(0, N, 1):
  if(S[i] == "R"):
    peo += 1
  else:
    chl[i-1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0

peo = 0
for i in reversed(range(0, N, 1)):
  if(S[i] == "L"):
    peo += 1
  else:
    chl[i+1] += (peo+1)//2
    chl[i] += peo//2
    peo = 0
    
print(" ".join(map(str, chl)))

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


int main() {
    int N, M, K;
    std::cin >> N >> M >> K;

    std::vector<long long int> A(N + 1, 0), B(M + 1, 0);
    for (int i = 1; i <= N; i++) {
        std::cin >> A[i];
        A[i] += A[i - 1];
    }
    for (int j = 1; j <= M; j++) {
        std::cin >> B[j];
        B[j] += B[j - 1];
    }


    int i_a = 0;
    for (; i_a <= N; i_a++) {
        if (A[i_a] > K) {
            break;
        }
    }
    i_a = std::min(i_a, N);

    int i_b = 0;
    int max_count = 0;
    for (; i_a >= 0; i_a--) {
        int val = K - A[i_a];
        for (; i_b <= M; i_b++) {
            if (B[i_b] > val) {
                break;
            }
        }
        max_count = std::max(i_a + i_b - 1, max_count);
    }

    std::cout << max_count << std::endl;
}


Measured memory_bytes: 6424
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cctype>
using namespace std;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
}
const int N = 1e5+5;
struct Edge
{
    int next, to;
    Edge(int next = 0, int to = 0):next(next), to(to) {};
}edge[N<<1];
int tot, head[N];
void _add(int x, int y) { edge[++tot] = Edge(head[x], y), head[x] = tot; }
void add(int x, int y) { _add(x, y), _add(y, x); } 
int n;
int dp(int x, int fa)
{
    int ret = 0;
    for(int i = head[x]; i; i = edge[i].next)
    {
        int y = edge[i].to; if(y == fa) continue;
        ret ^= dp(y, x)+1;
    }
    return ret;
}
int main()
{
    n = read();
    for(int i = 1; i < n; ++i)
    {
        int x = read(), y = read();
        add(x, y);
    }
    puts(dp(1, 0)?"Alice":"Bob");
    return 0;
}

Measured memory_bytes: 6784
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <string>
#include <tuple>

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

int main()
{
  int d;
  cin >> d;
  cout << "Christmas";
  for (int i = 0; i < 25 - d; ++i)
    cout << " Eve";
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
l=[]
count=0
m=[]
for i in range(5):
    #l.append(int(input()))
    a=int(input())
    l.append(a)

    count+=int(a/10)*10
    if a%10!=0:
        m.append(a%10)
        count+=10
if len(m)==0:
    flag=False
else:
    flag=True


if flag==True:
    mini=min(m)
    a=[] 
    for i in l:
        if mini==i%10:
            a.append(i)

    if len(a)==0:
        print(count)
    else:
        last=min(a)
        b=10-mini
        count-=b
        print(count)
else:
    print(sum(l))




Measured memory_bytes: 3064
# ABC127 C - Prison
si = lambda: input()
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))
n,m=nm()
l,r=0,10000000

for i in range(m):
    cl,cr=nm()
    l=max(cl,l)
    r=min(cr,r)

if r-l>=0:
    print(r-l+1)
elif r-l<0:
    print(0)



Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>

typedef long long ll;

using namespace std;

int main(int argc, const char * argv[]) {
  ll N;
  ll M = 0;
  ll i,j,k;
  ll sum;
  cin >> N;
  vector<ll> A(N+1);
  vector<ll> B(N+1);
  for(i=1;i<=N;i++){
    cin >> A[i];
    //if(i+1>N/2){
    //  B[i] = A[i];
    //}
    //cout << i << "," << B[i] << endl;
  }
  
  for(i=N;i>0;i--){
    sum = 0;
    j = 2;
    while(1){
      if(i*j>N) break;
      sum += B[i*j];
      j++;
    }
    B[i] = (sum + A[i])%2;
    M += B[i];
  }
  cout << M << endl;
  for(i=1;i<=N;i++){
    if(B[i]){
      cout << i << ' ';
    }
  }
  return 0;
}

Measured memory_bytes: 3968
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define INF 1LL << 60;
#define LLINF 1e12
#define PI 3.14159265359
int dy[] = {1, 0, -1, 0};
int dx[] = {0, 1, 0, -1};
int ny, nx;
typedef long long ll;
using namespace std;

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

ll lcm(ll m, ll n)
{
    if ((0 == m) || (0 == n))
        return 0;
    return ((m / gcd(m, n)) * n);
}

ll llpow(ll x, ll y)
{
    ll ans = 1;
    REP(i, y)
    ans *= x;
    return ans;
}

ll llmin(ll x, ll y) { return x < y ? x : y; }
ll llmax(ll x, ll y) { return x > y ? x : y; }

template <typename Container>
bool exist_in(const Container &c, const typename Container::value_type &v)
{
    return (c.end() != std::find(c.begin(), c.end(), v));
}

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

//std::cout << std::defaultfloat << std::setprecision(10);
////////////////////////////////////////
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);

    int x,y,z; cin >> x >> y >> z;

    cout << z << " " << x  << " " << y;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main() {
	string date[111];
	int a, b;
	int x, y,loop;
	int date2[111][111];
	while (1) {
		loop = 0;
		for (int i = 0; i <= 101; i++) {
			for (int z = 0; z <= 101; z++) {
				date2[i][z] = 0;
			}
		}
		cin >> a >> b;
		if (a == 0 && b == 0) {
			goto end;
		}
		for (int i = 0; i < a; i++) {
			cin >> date[i];
		}
		x = 0;
		y = 0;
		while (1) {
			if (date[y][x] == '>') {
				if (date2[y][x] == 1) {
					goto b;
				}
				date2[y][x] = 1;
				x = x + 1;
			}
			if (date[y][x] == '<') {
				if (date2[y][x] == 1) {
					goto b;
				}
				date2[y][x] = 1;
				x = x - 1;
			}
			if (date[y][x] == 'v') {
				if (date2[y][x] == 1) {
					goto b;
				}
				date2[y][x] = 1;
				y = y + 1;
			}
			if (date[y][x] == '^') {
				if (date2[y][x] == 1) {
					goto b;
				}
				date2[y][x] = 1;
				y = y - 1;
			}
			if (date[y][x] == '.') {
				goto a;
			}
		}
		b:;
		loop = 1;
		a:;
		if (loop == 1) {
			cout << "LOOP" << endl;
		}
		else {
			cout << x << " " << y << endl;
		}
	}
end:;
}


Measured memory_bytes: 3200
# スペース区切りの整数の入力
N,K= map(int, input().split())
''' a1=abs(N)
a2=abs(N-K)
da=a1-a2
N=a2 '''
''' while da>=0:
    a1=abs(N)
    a2=abs(N-K)
    da=a1-a2
    N=a2 '''
ansN=N//K
ans=min(N-ansN*K,-N+(ansN+1)*K)

print(ans)

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
const int inf = 1e9;

bool issame(string &a, string &b){
	for(int i=0; i<(int)a.length(); i++){
		if(a[i]!='x' && b[i]!='x' && a[i]!=b[i]){
			return false;
		}
	}
	return true;
}

int solve(string &str, vector<string> &s, map<string, int> &mincost){
	if(mincost.count(str) != 0){
		return mincost[str];
	}
	int n = s.size();
	int count = 0;
	for(int i=0; i<n; i++){
		if(issame(s[i], str)) count++;
	}
	if(count <= 1){
		mincost[str] = 0;
		return 0;
	}
	
	int m = str.length();
	int res = inf;
	for(int i=0; i<m; i++){
		if(str[i] == 'x'){
			string tmpstr[2] = {str, str};
			tmpstr[0][i] = '0';
			tmpstr[1][i] = '1';
			res = min(res, max(solve(tmpstr[0], s, mincost), solve(tmpstr[1], s, mincost)) +1);
		}
	}
	mincost[str] = res;
	return res;
}

int main(){
	while(1){
		int m,n;
		cin >> m >> n;
		if(m==0) break;
		
		vector<string> s(n);
		for(int i=0; i<n; i++) cin >> s[i];
		map<string, int> mincost;
		string ini = string(m, 'x');
		cout << solve(ini, s, mincost) << endl;
	}
	return 0;
}


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

int main() {
  int n,a,b;
  string s;
  cin>>n>>a>>b>>s;
  int cnt_ab=0,cnt_b=0;
  REP(i,n){
    if(s[i]=='a'){
      if(cnt_ab<a+b){
        cnt_ab++;
        cout<<"Yes"<<endl;
      } else {
        cout<<"No"<<endl;
      }
    } else if(s[i]=='b'){
      if(cnt_ab<a+b&&cnt_b<b){
        cnt_ab++;
        cnt_b++;
        cout<<"Yes"<<endl;
      } else {
        cout<<"No"<<endl;
      }
    } else {
      cout<<"No"<<endl;
    }      
  }
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
#define REP(x,y,z) for(int x=y;x<=z;x++)
#define FORD(x,y,z) for(int x=y;x>=z;x--)
#define MSET(x,y) memset(x,y,sizeof(x))
#define FOR(x,y) for(__typeof(y.begin()) x=y.begin();x!=y.end();x++)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 
void RI(){}
template<typename... T>
void RI( int& head, T&... tail ) {
  scanf("%d",&head);
  RI(tail...);
}
using namespace std;
typedef long long LL;
int main()
{  
	int r;
	scanf("%d", &r);
	printf("%d\n", r*r);
  return 0;
}


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

const int inf = 1e9;
const ll linf = 1e18;

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

    int n; cin >> n;
    string s, t; cin >> s >> t;
    
    string ans;
    for (int i = 0; i < s.length(); i++) {
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }

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

Measured memory_bytes: 256
A,B,H,M = gets.chomp.split.map(&:to_i)

AC = (30 * H) + (M * 0.5)
BC = M * 6
abc = (AC - BC).abs

if abc >= 180
  s = 360 - abc
  abc = s
end

puts Math.sqrt((A * A) + (B * B) - (2 * A * B * Math.cos(abc / 180.0 * Math::PI)))

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

int main() {
	string N;
	cin >> N;
	
	int dp[2][10][8];
	memset(dp, 0, sizeof(dp));

	int tmp = N[0] - '0', ans = 0;
	if (tmp > 3) {
		dp[0][0][1] = 1;
		if (tmp > 5) {
			dp[0][0][2] = 1;
			if (tmp > 7) dp[0][0][4] = 1;
			else if (tmp == 7) dp[1][0][4] = 1;
		} else if (tmp == 5) dp[1][0][2] = 1;
	} else if (tmp == 3) dp[1][0][1] = 1;
	
	for (int i = 1;i < N.size();++ i) { // 桁数を求めたいのに固定したとき
		tmp = N[i] - '0';
		for (int j = 0;j < 8;++ j) {
			for (int k = 1;k < 8;k <<= 1) dp[0][i][j | k] += dp[0][i - 1][j];
			if (tmp > 3) {
				dp[0][i][j | 1] += dp[1][i - 1][j];
				if (tmp > 5) {
					dp[0][i][j | 2] += dp[1][i - 1][j];
					if (tmp > 7) dp[0][i][j | 4] += dp[1][i - 1][j];
					else if (tmp == 7) dp[1][i][j | 4] += dp[1][i - 1][j];
				} else if (tmp == 5) dp[1][i][j | 2] += dp[1][i - 1][j];
			} else if (tmp == 3) dp[1][i][j | 1] += dp[1][i - 1][j];
		}
	}
	ans = dp[0][N.size() - 1][7] + dp[1][N.size() - 1][7];
	
	memset(dp, 0, sizeof(dp));
	dp[0][1][1] = dp[0][1][2] = dp[0][1][4] = 1;
	for (int i = 2;i < N.size();++ i) { // Nより小さい桁数の場合全て
		for (int j = 0;j < 8;++ j) for (int k = 1;k < 8;k <<= 1) dp[0][i][j | k] += dp[0][i - 1][j];
		ans += dp[0][i][7];
	}
	cout << ans;
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

dpすると解ける
*/

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

int main(){

  string s;
  cin >> s;
  int count=0;
  if(s[0]=='+') count++;
  else count--;
  if(s[1]=='+') count++;
  else count--;
  if(s[2]=='+') count++;
  else count--;
  if(s[3]=='+') count++;
  else count--;
  cout << count << endl;
}

Measured memory_bytes: 256
from collections import Counter
from bisect import bisect_left
from itertools import accumulate

N = int(input())
A = list(map(int, input().split()))
a = list(Counter(A).values())
a.sort()
b = list(accumulate(a + [0]))
s = sum(a)
length = len(a)

for i in range(1, N + 1):
    if i == 1:
        print(s)
    elif len(a) < i:
        print(0)
    else:
        n = s // i
        for j in reversed(range(1, n + 1)):
            t = bisect_left(a, j)
            if j * i <= b[t - 1] + (length - t) * j:
                print(j)
                break

Measured memory_bytes: 39248
#include <bits/stdc++.h>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

int main(){

	int r, d, x;

	cin>> r >> d >> x;

	for(int i=0;i<10;i++){
		x=r*x-d;
		cout<< x << endl;
	}



}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


class CmbMod:
    def __init__(self, n, p):
        """
        二項係数nCr(n個の区別できるものからr個のものを選ぶ組み合わせの数)をpで割った余りを求める
        """
        self.n = n
        self.p = p
        self.fact = [1, 1]
        self.factinv = [1, 1]
        self.inv = [0, 1]

    def cmb_mod(self, n, r):
        """
        二項係数nCr(mod p)をO(r)にて計算。nが大きいがrは小さい時に使用。
        """
        numer, denom = 1, 1
        for i in range(r):
            numer = (numer * (n - i)) % self.p
            denom = (denom * (i + 1)) % self.p
        return (numer * pow(denom, self.p - 2, self.p)) % self.p

    def prep(self):
        """
        二項係数nCr(mod p)をO(1)で求める為の前処理をO(N)にて実行。
        """
        for i in range(2, self.n + 1):
            self.fact.append((self.fact[-1] * i) % self.p)
            self.inv.append((-self.inv[self.p % i] * (self.p // i)) % self.p)
            self.factinv.append((self.factinv[-1] * self.inv[-1]) % self.p)

    def cmb_mod_with_prep(self, n, r):
        """
        二項係数nCr(mod p)をO(1)で求める。事前にprepを実行する事。
        """
        if (r < 0) or (n < r):
            return 0
        r = min(r, n - r)
        return self.fact[n] * self.factinv[r] * self.factinv[n - r] % self.p


def resolve():
    n, k = map(int, input().split())
    k = min(k, n - 1)
    cb = CmbMod(n + 1, mod)
    cb.prep()
    res = 0
    for i in range(k + 1):
        res += (cb.cmb_mod_with_prep(n, i) * cb.cmb_mod_with_prep(n - 1, i)) % mod
        res %= mod
    print(res)


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 32908
using System;

namespace AtCoder
{
    internal static class Program
    {
        private static void Main()
        {
            int[] nbrs = Array.ConvertAll(Console.ReadLine().Split(), int.Parse);
            int res = 0;

            if (nbrs[0] == nbrs[1] && nbrs[0] == nbrs[2])
                if (nbrs[0] % 2 == 0)
                    res = -1;
                else
                    res = 0;
            else
            {
                while (nbrs[0] % 2 == 0 && nbrs[1] % 2 == 0 && nbrs[2] % 2 == 0)
                {
                    int[] tmpNbrs = new int[3];
                    for (int i = 0; i < nbrs.Length; i++)
                    {
                        tmpNbrs[i] = (nbrs[(i + 1) % 3] + nbrs[(i + 2) % 3]) / 2;
                    }
                    for (int i = 0; i < nbrs.Length; i++)
                    {
                        nbrs[i] = tmpNbrs[i];
                    }

                    res++;
                }
            }

            Console.WriteLine(res);
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <iomanip>
#include <cmath>
#include <cstdlib>
using namespace std;

int main() {
  int T, D;

  while (cin >> T >> D) {
    int ta, tb; cin >> ta >> tb;
    int da, db; cin >> da >> db;
    double ans = 999999999;

    for (int i = 0; i * da <= D; i++) {
      int va = i * da;
      for (int j = 0; va + j * db <= D; j++) {
        int vb = j * db;
        double t = (double)(ta * va + tb * vb) / (va + vb);
        ans = min(ans, fabs(t - T));
      }
    }
    cout << fixed << setprecision(10) << ans << endl;
  }
}

Measured memory_bytes: 1236
N,W = map(int,raw_input().split())
dp = [0]*(W+1)
for loop in range(N):
    v,w = map(int,raw_input().split())
    for i in range(W-w,0,-1):
        if dp[i]:
            dp[i+w] = max(dp[i+w],dp[i]+v)
    dp[w] = max(dp[w],v)
print max(dp)

Measured memory_bytes: 4728
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define fs first
#define sc second
#define pb push_back
#define sz size()

using namespace std;
typedef double D;
typedef complex<D> P;
typedef pair<P,P> L;

const D EPS = 1e-8;
const D PI = acos(-1);

inline pair<P,P> norm(const P &p){return make_pair(p*P(0,1),p*P(0,-1));}
inline D dot(const P &x, const P &y){return real(conj(x)*y);}
inline D cross(const P &x, const P &y){return imag(conj(x)*y);}

int ccw(const P &a,P b,P c){
  b -= a;c -= a;
  if (cross(b,c)>EPS) return 1;
  if (cross(b,c)<-EPS) return -1;
  if (dot(b, c)<-EPS) return 2;
  if (abs(b)<abs(c)) return -2;
  return 0;
}

inline P line_cp(const L &a, const L &b){
  return a.fs+(a.sc-a.fs)*cross(b.sc-b.fs,b.fs-a.fs)/cross(b.sc-b.fs,a.sc-a.fs);
}

inline bool is_cp(const L &a, const L &b){
  return (ccw(a.fs,a.sc,b.fs)*ccw(a.fs,a.sc,b.sc)<=0)
    && (ccw(b.fs,b.sc,a.fs)*ccw(b.fs,b.sc,a.sc)<=0);
}

inline P symmetry_line(const L &l, const P &p){
  if(abs(ccw(l.fs,l.sc,p)) != 1)return p;
  return line_cp(l, L(p,p + norm(l.fs-l.sc).fs))*2.0 - p;
}

struct state{
  P goal;
  vector<L> mirrors;
  state(P p, vector<L> m):goal(p),mirrors(m){}

  inline state symmetry(int x){
    vector<L> sym(mirrors.sz);
    rep(i,mirrors.sz){
      if(i == x)sym[i] = mirrors[i];
      else sym[i] = L(symmetry_line(mirrors[x],mirrors[i].fs),
		      symmetry_line(mirrors[x],mirrors[i].sc));
    }
    return state(symmetry_line(mirrors[x],goal), sym);
  }
};

const int max_depth = 6;
int n;
int tx,ty,lx,ly;

D rec(int depth, vector<int> &order, vector<state> &mir){
  if(depth == max_depth)return 1e8;
    D res = 1e8;

  bool f = true;
  P start = P(lx,ly);
  L route = L(start, mir.back().goal);
  rep(i,depth+1){
    state cur = mir[i];
    int axis = i==depth?-1:order[i], prev = !i?-1:order[i-1];
    if(axis>=0 && !is_cp(route, cur.mirrors[axis])){ f = false; break; }

    P cp = axis>=0?line_cp(route, cur.mirrors[axis]):mir.back().goal;
    L seg = L(start, cp);
    rep(j,n){
      if(axis!=j && prev!=j && is_cp(seg, cur.mirrors[j])){ f = false; break; }
    }
    if(!f)break;
    start = cp; route.fs = start;
  }
  if(f)res = abs(P(lx,ly) - mir.back().goal);

  rep(i,n){
    if(depth && order[depth-1] == i)continue;
    order.pb(i);
    mir.pb(mir.back().symmetry(i));
    res = min(res, rec(depth+1, order, mir) );
    mir.pop_back();
    order.pop_back();
  }

  return res;
}

int main(){
  while(scanf("%d",&n), n){
    vector<L> vl(n);
    rep(i,n){
      int px, py, qx, qy;
      scanf("%d%d%d%d",&px,&py,&qx,&qy);
      vl[i] = L(P(px,py), P(qx,qy));
    }
    scanf("%d%d%d%d",&tx,&ty,&lx,&ly);
    
    vector<state> vs;
    vs.push_back( state(P(tx,ty), vl) );
    vector<int> vi;
    printf("%.4lf\n",rec(0,vi,vs));
  }
}

Measured memory_bytes: 1272
N = int(input())
b_list = list(map(int,input().split()))
answer_list = []
check = 0

for i in range(N):
    if b_list[i] > i+1:
        print(-1)
        check = 1
        break

if check == 0:
    for i in range(N):     
        for j in range(N-i, 0, -1):
            
            if b_list[j-1] == j:
                answer_list.append(b_list[j-1])
                b_list.pop(j-1)
                
                break

    answer_list.reverse()


    for i in range(N):
        print(answer_list[i])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define div1 1000000007
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef long double ld;
// a>b -> a==b;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
// a<b -> a==b;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

int main(void)
{
    ll N;

    cin >> N;

    if(N%1000==0) cout << 0 << endl;
    else cout << 1000*(N/1000+1)-N << endl;

    return 0;
}

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

inline i64 lucas(int n)
{
    vector<i64> arr(n);
    arr.at(0) = 2;
    arr.at(1) = 1;
    for (int i = 2; i < n; i++) {
        arr.at(i) = arr.at(i - 1) + arr.at(i - 2);
    }
    return arr.at(n - 1);
}

int main()
{
    int N;
    cin >> N;
    cout << lucas(N + 1) << endl;
}


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

const int BLACK=0;
const int WHITE=1;
const int NOTHING=2;

using namespace std;

int main(){
	int N;
	cin>>N;
    vector <int>a(N-1);
	vector <int>b(N-1);
    for(int i=0 ; i<N-1 ; i++){
        cin>>a[i];
    	cin>>b[i];
    	a[i]-=1;
    	b[i]-=1;
    }
	queue <int> que;
	vector <vector <int>> neighbor(N);
	vector <int> neighbor_state(N,NOTHING);
	int temp,address,black=0,white=0;
	
	//隣接関係を作る
	for(int i=0 ; i<N-1 ; i++){
		neighbor[a[i]].push_back(b[i]);
		neighbor[b[i]].push_back(a[i]);
	}
	que.push(0);
	que.push(N-1);
	neighbor_state[0]=BLACK;
	neighbor_state[N-1]=WHITE;
	while(1){
		if(que.empty())break;
		temp=que.front();
		que.pop();
		for(int i=0 ; i<neighbor[temp].size() ; i++){
			if(neighbor_state[temp]==BLACK){
				if(neighbor_state[neighbor[temp][i]]==NOTHING){
					neighbor_state[neighbor[temp][i]]=BLACK;
					que.push(neighbor[temp][i]);
				}
			}
			if(neighbor_state[temp]==WHITE){
				if(neighbor_state[neighbor[temp][i]]==NOTHING){
					neighbor_state[neighbor[temp][i]]=WHITE;
					que.push(neighbor[temp][i]);
				}
			}
		}
	}
	for(int i=0 ; i<neighbor_state.size() ; i++){
		if(neighbor_state[i]==BLACK)black+=1;
		else white+=1;
	}
	if(white>=black)cout<<"Snuke\n";
	else cout<<"Fennec\n";
	return 0;
}


Measured memory_bytes: 6912
//K個のケーキ

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define irep(i,a) for(auto i = a.begin(); i != a.end(); ++i)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int k,t;cin>>k>>t;
    vecrep(t,a,int);
    sort(range(a),greater<int>());
    if(a[0]*2>k)cout<<a[0]*2-k-1<<nnn;
    else cout<<0<<nnn;
    return 0;
}

Measured memory_bytes: 3592
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define REPS(i, _s, n) for(int i = _s, i##_len = (n); i < i##_len; ++i)
#define ALL(x) (x).begin(), (x).end()
using namespace std;

#define repi(itr, ds) for(auto itr = ds.begin(); itr != ds.end(); itr++)
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
  for(T &x : vec) is >> x;
  return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
  os << "(" << pair_var.first << ", " << pair_var.second << ")";
  return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
  os << "{";
  for(int i = 0; i < vec.size(); i++) {
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  }
  os << "}\n   ";
  return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
  os << "{";
  repi(itr, map_var) {
    os << *itr;
    itr++;
    if(itr != map_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
  os << "{";
  repi(itr, set_var) {
    os << *itr;
    itr++;
    if(itr != set_var.end()) os << ", ";
    itr--;
  }
  os << "}";
  return os;
}

#define DUMPOUT cerr

void dump_func() { DUMPOUT << endl; }
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
  DUMPOUT << head;
  if(sizeof...(Tail) > 0) {
    DUMPOUT << ", ";
  }
  dump_func(std::move(tail)...);
}
#ifdef DEBUG_
#define DEB
#define dump(...)                                                             \
  DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                             \
          << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]" << endl \
          << "    ",                                                          \
      dump_func(__VA_ARGS__)
#else
#define DEB if(false)
#define dump(...)
#endif

typedef long long int ll;

int main() {
  ll N;
  cin >> N;
  ll s = ceil(sqrt(N));
  while(s >= 1) {
    if(N % s == 0) {
      ll r = N / s;
      cout << r + s - 2 << endl;
      return 0;
    }
    s--;
  }
}


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

// Macros and Constants
#define ll long long
const ll mod=1000000007LL;

int main(int argc, char const *argv[])
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    //     ifstream cin("practice/input.txt");
    //     ofstream cout("practice/output.txt");
    // #endif
    
    string s;
    cin >> s;
    int af = 0;
    for (int i = 0; i < s.length(); i++) {
        char c = s[i];
        if (c == 'A') af++;
    }
    if ((af != 0) && (af != s.length())) {
        cout << "Yes";
    } else {
        cout << "No";
    }

    return 0;
}

Measured memory_bytes: 256
from collections import Counter
N = int(input())
def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return a
ans = 0
primes = prime_factorize(N)
pc = Counter(primes)
for v in pc.values():
    now = 1
    while now*(now+1)//2 <= v:
        now += 1
    ans += now-1
print(ans)



Measured memory_bytes: 9440
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <cstring>
#include <map>

#define rep(i, N) for (int i = 0; i < (int)N; i++)
using namespace std;
typedef long long ll;
const ll LLINF = 9223372036854775807;
const int MOD = 1000000007;

vector<int> x;
vector<vector<vector<ll>>> dp(51, vector<vector<ll>>(51,vector<ll>(2501, -1)));

ll dfs(int n, int k, int s) {
  if (dp[n][k][s]!=-1) return dp[n][k][s];
  if (k==0) {
    if (s==0) return dp[n][k][s] = 1;
    else return dp[n][k][s] = 0;
  }
  if (n<k) return dp[n][k][s]=0;
  ll result = 0;
  result += dfs(n-1, k, s);
  if (x[n-1]<=s) result += dfs(n-1, k-1, s-x[n-1]);
  return dp[n][k][s] = result;
}

int main() {
  int N, A; cin >> N >> A;
  rep(i,N) {int tmp; cin >> tmp; x.push_back(tmp);}

  ll result = 0;
  for (int i=1; i<=N; i++) result+= dfs(N,i,A*i);
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 52224
#include <algorithm>
#include <functional>
#include <iostream>
#include <list>
#include <queue>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

// rep(i, 100) { cout << i << endl; } => 0 1 2 ... 99
#define rep(i, n) for(int i = 0, i##_len = (n); i < (int)n; i++)

// std::sort(all(v));
#define all(x) (x).begin(), (x).end()

// long long int
using ll = long long;

// utility to cast return value of size function to int
#define SZ(x) ((int)(x).size())

// VS defines "_DEBUG" macro when debug configuration.
#if _DEBUG
#define dump(x) cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define dump(x)
#define debug(x)
#endif

// update max
template<class T>bool chmax(T & prov, const T & cur)
{
	if (cur > prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

// update min
template<class T>bool chmin(T & prov, const T & cur)
{
	if (cur < prov)
	{
		prov = cur;
		return true;
	}
	return false;
}

int main()
{
	ll N, M;
	cin >> N >> M;
	vector<ll> A(N);
	priority_queue<ll> hoge;
	for (auto && a : A)
	{
		cin >> a;
		hoge.push(a);
	}

	for (ll i = 0; i < M; i++)
	{
		ll p = hoge.top() / 2;
		hoge.pop();
		hoge.push(p);
	}

	ll ans = 0;
	while(!hoge.empty())
	{
		ans += hoge.top();
		hoge.pop();
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 2296
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<n;i++)
#define INF 1000000000
#define mod 1000000007
typedef long long ll;
const ll LINF = 1001002003004005006ll;
int dx[]={1,0,-1,0};
int dy[]={0,1,0,-1};
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
//0と1を決めたら2が決まって3が決まって...
//01をSS,SW,WS,WW全部試してnとぐるっとやって矛盾が無ければいいのでは

main(){
    int n;
    string saying;
    cin>>n;
    cin>>saying;

    string YATTE_TRY[4]={"SS","SW","WS","WW"};

    for(int YT=0;YT<4;YT++){
        string ans=YATTE_TRY[YT];
        for(int i=2;i<n;i++){
            if(saying[i-1]=='o'){
                if(ans[i-1]=='S'){
                    //羊がoという
                    if(ans[i-2]=='S')   ans+="S";
                    else                ans+="W";
                }
                else{
                    //狼がoという
                    if(ans[i-2]=='S')   ans+="W";
                    else                ans+="S";
                }
            }
            else{
                if(ans[i-1]=='S'){
                    //羊がxという
                    if(ans[i-2]=='S')   ans+="W";
                    else                ans+="S";
                }
                else{
                    //狼がxという
                    if(ans[i-2]=='S')   ans+="S";
                    else                ans+="W";
                }
            }
        }
        //0とn-1がくっつく部分で矛盾がないか
        bool f1=false,f2=false;
        if(ans[n-1]=='S'){
            if(saying[n-1]=='o'){
                if(ans[n-2]==ans[0]){
                    f1=true;
                }
            }
            else{
                if(ans[n-2]!=ans[0]){
                    f1=true;
                }
            }
        }
        else{
            if(saying[n-1]=='o'){
                if(ans[n-2]!=ans[0]){
                    f1=true;
                }
            }
            else{
                if(ans[n-2]==ans[0]){
                    f1=true;
                }
            }
        }
        //f1で最後の動物の言い分が正しいか判定
        //f2で0の動物の言い分が正しいか判定
        if(ans[0]=='S'){
            if(saying[0]=='o'){
                if(ans[1]==ans[n-1]){
                    f2=true;
                }
            }
            else{
                if(ans[1]!=ans[n-1]){
                    f2=true;
                }
            }
        }
        else{
            if(saying[0]=='x'){
                if(ans[1]==ans[n-1]){
                    f2=true;
                }
            }
            else{
                if(ans[1]!=ans[n-1]){
                    f2=true;
                }
            }
        }
        if(f1&&f2){cout<<ans<<endl;return 0;}
    }
    cout<<-1<<endl;
    return 0;
}

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

typedef long long ll;

int N, M;
int a[1050];
int b[1050];
int c[1050][15];

void input() {
	cin >> N >> M;
	for (int i = 0; i < M; i++) {
		cin >> a[i] >> b[i];
		for (int j = 0; j < b[i]; j++) {
			cin >> c[i][j];
		}
	}
}

void min(int& a, int b) {
	if (a > b)a = b;
}

int main() {
	input();
	int INF = 1e9;
	vector <int> dp(5000, INF);
	dp[0] = 0;

	for (int j = 0; j < M; j++) {
		int now = 0;
		for (int k = 0; k < b[j]; k++) {
			now |= (1 << (c[j][k] - 1));
		}
		for (int i = 0; i < (1 << N); i++) {
			min(dp[i | now], dp[i] + a[j]);
		}
	}

	if (dp[(1 << N) - 1] == INF)dp[(1 << N) - 1] = -1;
	cout << dp[(1 << N) - 1] << endl;

	return 0;
}

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

int main()
{
    long long int n;
    cin >> n;
    if(n % 2)
        cout << 0;
    else
    {
        long long ans = n/10;
        long long temp = 10;
        while(temp <= n/5)
        {
            temp = temp * 5;
            ans += n/temp;
        }
        cout << ans;
    }
	return 0;
}


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






#define pf                  printf
#define sf(a)               scanf("%d",&a)
#define sfl(a)              scanf("%lld",&a)
#define sff(a,b)            scanf("%d %d",&a,&b)
#define sffl(a,b)           scanf("%lld %lld",&a,&b)
#define sfff(a,b,c)         scanf("%d %d %d",&a,&b,&c)
#define sfffl(a,b,c)        scanf("%lld %lld %lld",&a,&b,&c)
#define sffff(a,b,c,d)      scanf("%d %d %d %d",&a,&b,&c,&d)
#define sffffl(a,b,c,d)     scanf("%lld %lld %lld %lld",&a,&b,&c,&d)
#define sfffff(a,b,c,d,e)   scanf("%d %d %d %d %d",&a,&b,&c,&d,&e)
#define sfffffl(a,b,c,d,e)  scanf("%lld %lld %lld %lld %lld",&a,&b,&c,&d,&e)
#define sfc(a)              scanf("%c",&a)
#define pii                 pair<int,int>
#define ms(a,b)             memset(a,b,sizeof(a))
#define pb(a)               push_back(a)
#define pbp(a,b)            push_back({a,b})
#define db                  double
#define ft                  float
#define ll                  long long
#define ull                 unsigned long long
#define pii                 pair<int,int>
#define ff                  first
#define ss                  second
#define sz(x)               x.size()
#define all(x)              x.begin(),x.end()
#define CIN                 ios_base::sync_with_stdio(0); cin.tie(0)
#define max3(a, b, c)       max(a, b) > max(b, c) ? max(a, b) : max(b, c)
#define min3(a, b, c)       min(a, b) < min(b, c) ? min(a, b) : min(b, c)
#define for0(i,n)           for(int i=0;i<n;i++)
#define for1(i,n)           for(int i=1;i<=n;i++)
#define forrev(i,n)         for(int i=n-1; i>=0; i--)
#define forab(i,a,b)        for(int i=a;i<=b;i++)
#define forba(i,b,a)        for(int i=b;i>=a;i--)
#define stlloop(x)          for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define gcd(a, b)           __gcd(a, b)
#define lcm(a, b)           ((a)*((b)/gcd(a,b)))
#define case1(z)            cout<<"Case "<<z<<": "
#define case2(z)            printf("Case %d: ",z)
#define PI                  acos(-1) //3.14159265358979323846264338328
#define valid(tx,ty)        tx>=0 && tx<row && ty>=0 && ty<col
#define intlim              2147483648
#define N                   100005
#define inf                 100000008
#define mod                 1000000007

/*------------------------------Graph Moves----------------------------*/
//const int fx[]={+1,-1,+0,+0};
//const int fy[]={+0,+0,+1,-1};
//const int fx[]={+0,+0,+1,-1,-1,+1,-1,+1};   // Kings Move
//const int fy[]={-1,+1,+0,+0,+1,+1,-1,-1};  // Kings Move
//const int fx[]={-2, -2, -1, -1,  1,  1,  2,  2};  // Knights Move
//const int fy[]={-1,  1, -2,  2, -2,  2, -1,  1}; // Knights Move
/*---------------------------------------------------------------------*/
ll a[N];
int main()
{
    ll k=0,n,b,c=0;
    cin>>n;
    for0(i,n)
    {
        cin>>a[i];
        if(a[i]%2==0 && (a[i]%3==0 || a[i]%5==0))
            k++;
        if(a[i]%2==0)
            c++;
    }


        if(k==c)
            cout<<"APPROVED"<<endl;
        else
            cout<<"DENIED"<<endl;
    return 0;
}
































Measured memory_bytes: 256
#include "bits/stdc++.h" // {{{
using namespace std; typedef long long ll; typedef pair<int,int> pii;
#define val         const auto
#define eb          emplace_back
#define emp         emplace
#define fi          first
#define se          second
#define outl(x)     cout << (x) << '\n'
#define rep(i,n)    for(int i=0; i < (int)(n); ++i)
#define repr(i,h,l) for(int i=(h); i >= (int)(l); --i)
#define reps(i,s,t) for(int i=(s); i <= (int)(t); ++i)
#define ALL(x)      begin(x), end(x)
#define UNQ(x)      (x).erase(std::unique(ALL(x)), end(x))
#define TMPLT(T,U)  template<class T, class U>
#define ten(p)      ((long long)(1e##p))
#define FILL(a,v)   memset((a), (v), sizeof(a))
#define YDK(f,a,b)  ((f)? (a):(b))
#ifdef  DEBUG
#define debug(...)  fprintf(stderr, __VA_ARGS__)
#define show(x)     clog << #x << " \t\t= " << (x) << '\n'
#define show2(x,y)  clog << '(' << #x << ',' << #y << ")\t\t= " << '(' << (x) << "\t, " << (y) << ")\n"
#define LN()        fputs("\n--------------------------------\n", stderr)
struct NullPointer{};
#else
#define debug(...)
#define show(x)
#define show2(x,y)
#define LN()
struct NullPointer{ NullPointer(){cin.tie(0);ios::sync_with_stdio(false);} };
#endif
#define def(op) inline bool operator op (const T &that) const { return comp(that) op 0; }
template<class T> struct Ordered
{ virtual int comp(const T &that) const = 0; def(==); def(!=); def(<); def(<=); def(>); def(>=); };
#undef def
namespace {
  constexpr int INF = 0x3f3f3f3f; constexpr ll LINF = 0x3f3f3f3f3f3f3f3fLL; ostringstream _oss;
  TMPLT(T,U) inline constexpr common_type_t<T,U> gcd(T x, U y)
  { return (x<y)? gcd(y,x) : (y <= 0)? x : gcd(y, x % y); }
  TMPLT(T,U) inline bool chmax(T &a, const U &b){return b>a ? a=b,1 : 0;}
  TMPLT(T,U) inline bool chmin(T &a, const U &b){return b<a ? a=b,1 : 0;}
  TMPLT(T,U) inline constexpr ll lcm(T x, U y) { return (ll)x/gcd(x,y) * y; }
  template<class T>   string toString(const T &x){ _oss.str(""); _oss << x; return _oss.str(); }
  template<class Itr> string mkString(Itr begin, Itr end, const char *sp = " ") {
    _oss.str(""); for(Itr i=begin; i != end; ++i) { if(i != begin)_oss << sp; _oss << *i; }
    return _oss.str();
  }
  // }}}

constexpr int MX = ten(5) + 10;

void Xx_main_xX(const vector<char*> &args)
{
  int N;
  map<int, int> cnt;

  cin >> N;
  rep(i, N) {
    int a; cin >> a;
    cnt[a]++;
  }


  int ans = 0;
  for (val &e : cnt) {
    if (e.se % 2 == 1) ++ans;
  }

  outl(ans);
}

} // {{{
signed main(signed argc, char *argv[]) {
  NullPointer Exception;
  cout << fixed << setprecision(9); Xx_main_xX(vector<char*>(argv, argv+argc)); return 0;
} // }}}



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

using namespace std;

int main()
{
    int n,m;

    while(cin>>n>>m)
    {
        vector<int> v(n+1),w(n+1),num(n+1);
        vector<int> dp(m+1);
        for(int i=1;i<=n;i++)
        {
            cin>>v[i]>>w[i]>>num[i];
        }
        for(int i=1;i<=n;i++)
        {
            int tmp=num[i];
            for(int k=1;tmp>0;k<<=1)
            {
                int mul=min(tmp,k);
                for(int j=m;j>=mul*w[i];j--)
                {
                    dp[j]=max(dp[j],dp[j-mul*w[i]]+mul*v[i]);
                }
                tmp-=mul;
            }
        }
        cout<<dp[m]<<endl;
    }

    return 0;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
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; }
//(a+b-1)/b
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;

class UnionFind
{
private:
    vector<ll> p;
    vector<ll> rank;
public:
    UnionFind(ll n){
        p.resize(n,-1);
        rank.resize(n,1);
    }
    ll find(ll x){
        if(p[x]<0)return x;
        return p[x]=find(p[x]);
    }
    void unite(ll x,ll y){
        x=find(x);
        y=find(y);
		if(x==y)return;
        if(rank[x]>rank[y])swap(x,y);
        if(rank[x]==rank[y])rank[y]++;
        p[y]+=p[x];
        p[x]=y;
    }
    ll size(ll x){
        return -p[find(x)];
    }
};



signed main(){
	ll n, m, k; cin >> n >> m >> k;
	vl fr(n);
	UnionFind uf(n);
	rep(i,0,m){
		ll a,b; cin >> a >> b;
		--a; --b;
		fr[a]++;
		fr[b]++;
		uf.unite(a,b);
	}
	vl to[n];
	rep(i,0,k){
		ll a,b; cin >> a >> b;
		--a; --b;
		to[a].push_back(b);
		to[b].push_back(a);
	}
	rep(i,0,n){
		ll ans=uf.size(i)-fr[i]-1;
		for(ll c:to[i]){
			if(uf.find(c)==uf.find(i))--ans;
		}
		cout<<ans<<" ";
	}
	cout<<endl;
	

	return 0;
}

Measured memory_bytes: 11364
#define loop(i,j,k) for(long long i = j;i < k;i++)

#include <iostream>
#include <algorithm>
#include <vector>
#include <utility>
#include <string>
#include <list>
#include <stack>
#include <set>
#include <map>

using namespace std;

typedef long long int int64;

char dict[2][256];

int main(int argc,char** argv) {
    string s[2];
    cin >> s[0] >> s[1];
    loop(i,0,2) {
        char cur = 'A';
        loop(j,0,s[i].length()) {
            if(dict[i][s[i][j]] == 0) {
                dict[i][s[i][j]] = cur;
                cur++;
            }
        }
        loop(j,0,s[i].length()) {
            s[i][j] = dict[i][s[i][j]];
        }
    }
    if(s[0] == s[1]) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 776
n = int(input())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
c = list(map(int,input().split()))
a = sorted(a)
b = sorted(b)
c = sorted(c)
count = 0
import bisect
for i in range(n):
    A = bisect.bisect_right(a,b[i]-1)
    C = bisect.bisect_left(c,b[i]+1)
    count += A*(n-C)
print(count)

Measured memory_bytes: 23328
#include <iostream>

using namespace std;

int main(int argc, char const *argv[])
{
    int N;
    string S;
    cin >> N;
    cin >> S;

    int white_stone_num_in_right = 0;
    int black_stone_num_in_left = 0;
    for (int i = 0; i < N; i++)
    {
        if (S[i] == '.')
        {
            white_stone_num_in_right++;
        }
    }

    //cout << white_stone_num_in_right; // これが全部黒のときの取り替える数
    int answer = white_stone_num_in_right;

    for (int i = 0; i < N; i++)
    {
        if (S[i] == '#')
        {
            black_stone_num_in_left++;
        }
        else
        {
            white_stone_num_in_right--;
        }

        if (answer > (black_stone_num_in_left + white_stone_num_in_right))
        {
            answer = black_stone_num_in_left + white_stone_num_in_right;
        }
    }

    cout << answer;

    return 0;
}


Measured memory_bytes: 640