akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cmath>

const double PI = 3.14159265358979323846;
//using namespace boost::multiprecision;
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 1e15;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

std::istream &operator>>(std::istream &in, set<int> &o) {
    ll a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ifstream myfile("C:\\Users\\riku\\Downloads\\0_00.txt");
//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
const int mod = 1000000007;
//const ll mod = 1e10;
typedef priority_queue<long long, vector<long long>, greater<long long> > PQ_ASK;

int main() {
    ll n, k;
    cin >> n >> k;

    ll ans = 0;
    for (ll b = 1; b <= n; b++) {
        ll p = n / b;
        ll r = n % b;
        ll ac = p * max(0ll, b - k);
        ac += max(0ll, r - k + 1);
        if (0 % b >= k) ac--;
        ans += ac;


    }

    cout << ans << endl;
}


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

int main()
{
	deque<int> vary;

	int p;
	cin >> p;
	while (p--)
	{
		int m, n;
		cin >> m >> n;
		if (m == 0)//shuru
		{
			long long int x;
			cin >> x;
			if (n == 0)vary.push_front(x);
			else vary.push_back(x);
		}
		if (m == 1)//dayin
		{
			cout << vary[n] << endl;
		}
		if (m == 2)//shuchu
		{
			if (n == 1)vary.pop_back();
			else vary.pop_front();
		}
	}
	return 0;
}


Measured memory_bytes: 4676
def examA():
    S = SI()
    if S in alphabet:
        ans = "a"
    else:
        ans = "A"
    print(ans)
    return

def examB():
    ans = 0
    print(ans)
    return

def examC():
    ans = 0
    print(ans)
    return

def examD():
    ans = 0
    print(ans)
    return

def examE():
    ans = 0
    print(ans)
    return

def examF():
    ans = 0
    print(ans)
    return

from decimal import getcontext,Decimal as dec
import sys,bisect,itertools,heapq,math,random
from copy import deepcopy
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
def I(): return int(input())
def LI(): return list(map(int,sys.stdin.readline().split()))
def DI(): return dec(input())
def LDI(): return list(map(dec,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def SI(): return sys.stdin.readline().strip()
global mod,mod2,inf,alphabet,_ep
mod = 10**9 + 7
mod2 = 998244353
inf = 10**18
_ep = dec("0.000000000001")
alphabet = [chr(ord('a') + i) for i in range(26)]
alphabet_convert = {chr(ord('a') + i): i for i in range(26)}

getcontext().prec = 28

sys.setrecursionlimit(10**7)

if __name__ == '__main__':
    examA()

"""
142
12 9 1445 0 1
asd dfg hj o o
aidn
"""

Measured memory_bytes: 77072
#include <stdio.h>

int main() {
  int i, a;
  int f[45];

  
  f[0] = f[1] = 1;
  for(i = 2; i < 45; ++i) {
    f[i] = f[i-1] + f[i-2];
  }
  
  scanf("%d", &a);
  printf("%d\n", f[a]);

  
  return 0;
}



Measured memory_bytes: 2112
/*
 * main.c
 *
 *  Created on: 2020/07/27
 *      Author: 113896
 */
#include <stdio.h>

int main() {

	int a, b;
	scanf("%d%d", &a, &b);
	printf("%d %d\n", a*b, 2*a+2*b);

	return 0;
}




Measured memory_bytes: 2052
#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<(n);++i)
#define REPr(i, n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m, n) for(int i = (n);i >=(m);--i)
#define PB push_back
#define MP make_pair
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x, S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x, y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
using namespace std;
typedef pair<int, int> PII;
typedef pair<long long, long long> PLL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1e9+7;

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

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

template<class T>
inline bool chmax(T &a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
///////////////////////////////////////////////
/*🍈( '-'  🍈*/
int main(){
	static char grid[2005][2005] = {};
	static ll U[2005][2005] = {};
	static ll D[2005][2005] = {};
	static ll L[2005][2005] = {};
	static ll R[2005][2005] = {};

	int H,W;
	cin >> H >> W;
	FORq(h,1,H){
		FORq(w,1,W){
			cin >> grid[h][w];
		}
	}

	FORq(h,1,H){
		FORq(w,1,W){
			if (grid[h][w] != '.') continue;
			if (grid[h-1][w] == '.'){
				U[h][w] = U[h-1][w] + 1;
			}
		}
	}

	FORqr(h,1,H){
		FORq(w,1,W){
			if (grid[h][w] != '.') continue;
			if (grid[h+1][w] == '.'){
				D[h][w] = D[h+1][w] + 1;
			}
		}
	}

	FORq(w,1,W){
		FORq(h,1,H){
			if (grid[h][w] != '.') continue;
			if (grid[h][w-1] == '.'){
				L[h][w] = L[h][w-1] + 1;
			}
		}
	}

	FORqr(w,1,W){
		FORq(h,1,H){
			if (grid[h][w] != '.') continue;
			if (grid[h][w+1] == '.'){
				R[h][w] = R[h][w+1] + 1;
			}
		}
	}

	ll ans = 0;

	FORq(h,1,H){
		FORq(w,1,W){
			chmax(ans,U[h][w]+D[h][w]+R[h][w]+L[h][w]+1);
		}
	}
	

	cout << ans << "\n";

}

Measured memory_bytes: 129792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;
// vector<vector<int>> data(3, vector<int>(4));

void solve(string S){
	ll res = 0;
	rep(i, S.length()/2) {
		if (S[i] != S[S.length()-1-i]) res++;
	}
	cout << res << endl;
}

int main(){	
	string S;
	cin >> S;
	solve(S);
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define INF (1<<30)
using ll = long long;
using namespace std;
 
int main(){
	string S;
	cin >> S;
	int ans;
	for( char s : S ){
		if( s == '+' ){
			ans++;
		} else {
			ans--;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define N 100010
using namespace std;
int a[N];
void read(int &x)
{
	char c = getchar();
	x = 0;
	while(c < '0' || c > '9')
		c = getchar();
	while(c >= '0' && c <= '9')
	{
		x = x * 10 + (c - '0');
		c = getchar();
	}
}
void siktdown(int a[],int k,int n)
{
	int l,v = a[k];
	while((l = 2 * k + 1) < n)
	{
		if(l < n - 1 && a[l + 1] > a[l])
			l ++;
		if(a[l] > v)
		{
			a[k] = a[l];
			k = l;
		}
		else
			break;
	}
	a[k] = v;
}
void my_sort(int a[],int n)
{
	for(int i = (n - 2) / 2;i >= 0;i --)
	{
		siktdown(a,i,n);
	}
}
int main()
{
	int n,m;
	cin >> n >> m;
	for(int i = 0;i < n;i ++)
	{
		read(a[i]);
	}
	my_sort(a,n);
	while(m > 0 && a[0] > 0)
	{
		m --;
		a[0] /= 2;
		siktdown(a,0,n);
	}
	long long sum = 0;
	for(int i = 0;i < n ;i ++)
	{
		sum += a[i];
	}
	cout << sum << endl;
	return 0;
}

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

#define int long long
#define counter(m)     for(int i=0;i<m;i++)
#define gcd            __gcd
#define endl           "\n"
#define pb             emplace_back
#define setbits(x)     __builtin_popcountll(x)
#define zrobits(x)     __builtin_ctzll(x)
#define mod            1000000007
#define mod2           998244353
#define maxe           *max_element
#define mine           *min_element
#define inf            1e18
#define deci(x, y)      fixed<<setprecision(y)<<x
#define w(t)           int t; cin>>t; while(t--)
#define nitin          ios_base::sync_with_stdio(false); cin.tie(NULL)
#define PI             3.141592653589793238
using namespace std;
bool cmp(pair<int,int>&a,pair<int,int>&b)
{
    return a.first+a.second<b.first+b.second;
}
bool cmpa(pair<int,int>&a,pair<int,int>&b)
{
    return a.first<b.first;
}bool cmpb(pair<int,int>&a,pair<int,int>&b)
{
    return a.second<b.second;
}
int32_t main() {
    nitin;
    int n;
    cin>>n;
    vector<pair<int,int>>v;
    vector<pair<int,int>>a;
    vector<pair<int,int>>b;
    vector<pair<int,int>>c;
    for(int i=0;i<n;i++)
    {
        int a,b;
        cin>>a>>b;
        v.push_back({a,b});
    }
    a=v;
    b=v;
    c=v;
    for(auto &m:c)
    {
        m.second=1e9-m.second;
    }
    sort(v.begin(),v.end(),cmp);
    sort(a.begin(),a.end(),cmpa);
    sort(b.begin(),b.end(),cmpb);
    sort(c.begin(),c.end(),cmp);
    int ans1=abs(v[0].first-v[v.size()-1].first)+abs(v[v.size()-1].second-v[0].second);
    int ans2=abs(a[0].first-a[a.size()-1].first)+abs(a[a.size()-1].second-a[0].second);
    int ans3=abs(b[0].first-b[b.size()-1].first)+abs(b[b.size()-1].second-b[0].second);
    int ans4=abs(c[0].first-c[c.size()-1].first)+abs(c[c.size()-1].second-c[0].second);
    cout<<max(max(ans1,ans2),max(ans3,ans4))<<endl;
    return 0;
}


Measured memory_bytes: 15836
from math import ceil

n = int(input())
a = list(map(int, input().split()))

m = 10 ** 6
n_map = {}
v_a = []
for i in a:
    if i not in n_map:
        n_map[i] = 1
    else:
        n_map[i] += 1
v_a = [(k,v) for k, v in n_map.items()]

v_a.sort(key=lambda x: x[0])
res = 0
nn_map = {}
for i, v in v_a:
    if i in nn_map:
        continue
    for j in range(1, ceil(m / i) + 1):
        nn_map[i * j] = True
    if v == 1:
        res += 1
print(res)

Measured memory_bytes: 175400
n, k = map(int, input().split())
a = list(map(int, input().split()))

digit_n = 0
kk = k
while kk > 0:
    kk >>= 1
    digit_n += 1

count = [0] * digit_n
mask = ~((1 << digit_n) - 1)

ans = 0
for i in range(n):
    ans += a[i] & mask
    for j in range(digit_n):
        if (a[i] >> j) & 1:
            count[j] += 1 

dp = [[0] * (digit_n + 1) for _ in range(2)]

for i in range(1, digit_n + 1):
    j = digit_n - i
    bit = (k >> j) & 1
    dp[0][i] = (dp[0][i-1] << 1) + (n - count[j] if bit else count[j])
    if dp[1][i-1]:
        dp[1][i] = (dp[1][i-1] << 1) + max(n - count[j], count[j])
    if bit == 1:
        dp[1][i] = max(dp[1][i], (dp[0][i-1] << 1) + count[j])
ans += max(dp[0][-1], dp[1][-1])
print(ans)

Measured memory_bytes: 87232
#include <iostream>
#include <string>
#include <algorithm>

int main(){

	int n,x;
	int i,j,k,l;

	while(std::cin >> n){
		x = 0;
		for(i=0;i<10;i++){
		for(j=0;j<10;j++){
		for(k=0;k<10;k++){
		for(l=0;l<10;l++){
			if(n == i + j + k + l){
				x++;
			}
		}
		}
		}
		}
		std::cout << x << std::endl;
	}
}

Measured memory_bytes: 1160
/// --- In the name of ALLAH --- ///


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


typedef long long              ll;
typedef vector<int>            vi;
typedef vector<ll>             vl;
typedef vector<vi>             vvi;
typedef vector<vl>             vvl;
typedef pair<int,int>          pii;
typedef pair<double, double>   pdd;
typedef pair<ll, ll>           pll;
typedef vector<pii>            vii;
typedef vector<pll>            vll;
typedef double                 dl;

#define endl                   '\n'
#define PB                     push_back
#define F                      first
#define S                      second
#define all(a)                 (a).begin(),(a).end()
#define rall(a)                (a).rbegin(),(a).rend()
#define sz(x)                  (ll)x.size()
#define wt                     ll t; cin>>t; while(t--)
#define input(a,n)             for(int i=0;i<n;i++) cin>>a[i];

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;


#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))
#define mod 10000007
#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu () {            cerr << endl;}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest) {cerr << arg << ' ';faltu(rest...);}

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


const ll mx=1e9;









int main()
{
    optimize();

   int n,m,i,t,j,p=0;
   cin>>n>>m>>t;
   i=t/n;
   j=i*m;
   cout<<j<<endl;




    return 0;
}









































Measured memory_bytes: 3656
//#define _GLIBCXX_DEBUG

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (ll)(m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T1, typename T2>bool chmin(T1 &a,T2 b){if(a>b){a=b;return true;}else return false;}
template<typename T1, typename T2>bool chmax(T1 &a,T2 b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++){cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++){for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>vector<vector<T>>vec(ll x, ll y, T w){vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,-1,0,0,1,1,-1,-1};vector<ll>dy={0,0,1,-1,1,-1,1,-1};
template<typename T>vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<typename T1, typename T2>ostream &operator<<(ostream &os, const pair<T1, T2>&p){return os << p.first << " " << p.second;}
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v){for(auto &z:v)os << z << " ";cout<<"|"; return os;}
//mt19937 mt(chrono::steady_clock::now().time_since_epoch().count());
struct UnionFind {
  vector<ll> data;
  ll num;
  UnionFind(ll size) : data(size, -1) ,num(size){ }
  bool unite(ll x, ll y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
	  num--;
    }
    return x != y;
  }
  bool find(ll x, ll y) {
    return root(x) == root(y);
  }
  ll root(ll x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  ll size(ll x) {
    return -data[root(x)];
  }
};
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  UnionFind uf(n);
  rep(i,0,m){
    ll x,y;cin>>x>>y;x--;y--;
    uf.unite(x,y);
  }
  cout<<uf.num-1<<endl;
  return 0;
}

Measured memory_bytes: 3964
n = int(input())
mon_life = [i for i in map(int,input().split())]

while True :
    if len(mon_life) == 1 :
        break
    else : 
        min_val = min(mon_life)
        mon_life = [i % min_val for i in mon_life if i % min_val != 0 ]
        mon_life.append(min_val)

print(mon_life[0])

Measured memory_bytes: 14252
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        Long n = sc.nextLong();
        sc.close();
        Long pow = 1L;

        for(Long i = 1L; i <= n; i++){
            pow = i * pow % 1000000007L;
        }

        System.out.println(pow);
    }

}



Measured memory_bytes: 25172
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<queue>
using namespace std;
typedef long long ll;
const int maxn=1e5+10;
int n,m,a[maxn];
ll ans;
priority_queue<int,vector<int>,greater<int> >q;
int main()
{
	scanf("%d%d",&n,&m);
	for(int i=0;i<m;++i)scanf("%d",&a[i]);
	sort(a,a+m);
	for(int i=1;i<m;++i)
	q.push(a[i]-a[i-1]);
	for(int i=0;i<m-n;++i)
	{
		int tmp=q.top();q.pop();
		ans+=tmp;
	}
	printf("%lld\n",ans);
	return 0;
} 

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

int main(void)
{
  ios_base::sync_with_stdio(false);
  cin.tie(0); cout.tie(0);

  ll N; cin >> N;
  int *A = new int[N];
  A[0] = 0;
  for (int i = 1; i < N; i++) {
    cin >> A[i];
  }

  int *n = new int[N];
  for (int i = 0; i < N; i++) {
    n[i] = 0;
  }
  for (int i = 0; i < N; i++) {
    n[A[i]]++;
  }

  for (int i = 0; i < N; i++) {
    int ans = (i == N - 1)? 0: n[i + 1];
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 5220
/* Copyright 2016 AcrossTheSky */
#include <iostream>
#include <cstdio>
#include <utility>
#include <cassert>
#include <map>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <set>
#include <cstring>
#include <cstdlib>
#include <cctype>
#include <sstream>
#include <fstream>
#include <string>
#include <cmath>
#include <algorithm>
#define REP(i, a, b) for (int i = (a); i <= (b); ++i)
#define PER(i, a, b) for (int i = (a); i >= (b); --i)
#define RVC(i, c) fot (int i = 0; i < (c).size(); ++i)
#define RED(k, u) for (int k = head[(u)]; k; k = edge[k].next)
#define SQR(k) (k) * (k)
#define lowbit(x) ((x) & (-(x)))
#define CL(x, v) memset(x, v, sizeof x)
#define MP std::make_pair
#define PB push_back
#define FR first
#define SC second
#define rank rankk
#define next nextt
#define link linkk
#define index indexx
#define abs(x) ((x) > 0 ? (x) : (-(x)))
using namespace std;
typedef long long LL; typedef pair<int, int> PII;

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

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

template<class T> inline
void read(T *a) {
    char c;
    while (isspace(c = getchar())) {}
    bool flag = 0;
    if (c == '-') flag = 1, *a = 0;
    else
        *a = c - 48;
    while (isdigit(c = getchar())) *a = *a * 10 + c - 48;
    if (flag) *a = -*a;
}

const int mo = 1000000007;
template<class T>
T pow(T a, T b, int c = mo) {
    T res = 1;
    for (T i = 1; i <= b; i <<= 1, a = 1LL * a * a % c) if (b & i) res = 1LL * res * a % c;
    return res;
}
/*======================= TEMPLATE =======================*/
const int N = 210000;
int f[N], g[N];
map<PII, int> S;
int n, m1, m2;
set<int> S1[N], S2[N];
int get(int *g, int u) {
    if (u == g[u]) return u;
    return g[u] = get(g, g[u]);
}
int calc(int i, int j) {
    int ans = 0;
    if (S1[i].size() < S2[j].size()) {
        for (set<int>::iterator it = S1[i].begin(); it != S1[i].end(); ++it)
            if (S2[j].find(*it) != S2[j].end()) ++ans;
    }
    else {
        for (set<int>::iterator it = S2[j].begin(); it != S2[j].end(); ++it)
            if (S1[i].find(*it) != S1[i].end()) ++ans;
    }
    return ans;
}
void join(int *g, int u, int v) {
    g[get(g, u)] = get(g, v);
}
int main() {
    cin >> n >> m1 >> m2;
    REP(i, 1, n) f[i] = g[i] = i;
    while (m1--) {
        int x, y;
        read(&x); read(&y);
        join(f, x, y);
    }
    while (m2--) {
        int x, y;
        read(&x); read(&y);
        join(g, x, y);
    }
    REP(i, 1, n) S1[get(f, i)].insert(i);
    REP(i, 1, n) S2[get(g, i)].insert(i);
    REP(i, 1, n) {
        int x = get(f, i), y = get(g, i);
        int ans = 0;
        if (S.find(MP(x, y)) != S.end())  ans = S[MP(x, y)];
        else {
            S[MP(x, y)] = ans = calc(x, y);
        }
        printf("%d ", ans);
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 51200
#include <bits/stdc++.h>
#define rep(i,n) for (int (i) = 0; (i) < (n); i++)
#define ll long long
using namespace std;
int main() {
  ll a,b,k; cin >> a >> b >> k;
  vector<ll>A(0);
  rep(i,max(a,b)+1){
    if(i == 0){
      continue;
    }
    if(a%i == 0 && b%i == 0){
      A.push_back(i); 
    }
  }
  sort(A.begin(),A.end(),greater<ll>());
  cout << A[k-1];
}

Measured memory_bytes: 3484
N,P = [int(i) for i in input().split()]
A = [int(i)%2 for i in input().split()]

k = A.count(1)
l = A.count(0)

if P == 0:
    if k == 0:
        print(2**l)
        exit()
    ans = 1
    ans = 2**(k-1+l)
else:
    if k == 0:
        print(0)
        exit()
    else:
        ans = 1
        ans = 2**(k-1+l)

print(ans)


Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.StringTokenizer;

public class Main {
	
	public static void main(String[] args) throws IOException {
		MyScanner sc = new MyScanner();
		PrintWriter out = new PrintWriter(System.out);
		int N = sc.nextInt();
		int K = sc.nextInt() - 1;
		int[] a = new int[N];
		int[] b = new int[N];
		for (int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt() - 1;
		}
		for (int i = 0; i < b.length; i++) {
			b[i] = sc.nextInt() - 1;
		}
		int mod = K % 6;
		int[] mid = null;
		switch (mod) {
			case 0:
				mid = a;
				break;
			case 1:
				mid = b;
				break;
			case 2:
				mid = compose(b, inv(a));
				break;
			case 3:
				mid = inv(a);
				break;
			case 4:
				mid = inv(b);
				break;
			case 5:
				mid = compose(inv(b), a);
				break;
		}
		int[] left;
		if (K < 3) {
			left = id(N);
		} else {
			int total = 1 + ((K - 3) / 3) * 2;
			if (K % 3 != 0) total++;
			int[] base = compose(b, compose(inv(a), compose(inv(b), a)));
			left = eleva(base, total / 4);
			if (total % 4 >= 1) {
				left = compose(left, b);
			}
			if (total % 4 >= 2) {
				left = compose(left, inv(a));
			}
			if (total % 4 >= 3) {
				left = compose(left, inv(b));
			}
		}
		int[] ret = compose(left, compose(mid, inv(left)));
		for (int i = 0; i < ret.length; i++) {
			if (i > 0) out.print(" ");
			out.print(ret[i] + 1);
		}
		out.println();
		out.flush();
	}
	
	static int[] inv(int[] a) {
		int[] ret = new int[a.length];
		for (int i = 0; i < ret.length; i++) {
			ret[a[i]] = i;
		}
		return ret;
	}
	
	static int[] compose(int[] a, int[] b) {
		int[] ret = new int[a.length];
		for (int i = 0; i < ret.length; i++) {
			ret[i] = a[b[i]];
		}
		return ret;
	}
	
	static int[] id(int n) {
		int[] ret = new int[n];
		for (int i = 0; i < ret.length; i++) {
			ret[i] = i;
		}
		return ret;
	}
	
	static int[] eleva(int[] a, int e) {
		if (e == 0) return id(a.length);
		int[] tmp = eleva(a, e / 2);
		tmp = compose(tmp, tmp);
		if (e % 2 == 1) {
			tmp = compose(tmp, a);
		}
		return tmp;
	}
	
	static class MyScanner {
		private BufferedReader br;
		private StringTokenizer tokenizer;
		
		public MyScanner() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		
		public String next() {
			while (tokenizer == null || !tokenizer.hasMoreTokens()) {
				try {
					tokenizer = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					throw new RuntimeException(e);
				}
			}
			return tokenizer.nextToken();
		}
		
		public int nextInt() {
			return Integer.parseInt(next());
		}
		
		public long nextLong() {
			return Long.parseLong(next());
		}
	}
}


Measured memory_bytes: 49780
#include <stdio.h>
#include <iostream>
#include <string>
int main(void)
{
	char s[20];
	std::cin >> s;
	if (s[5] == ',')
	{
		s[5] = ' ';
	}
	if (s[13] == ',')
	{
		s[13] = ' ';
	}
	std::cout << s;
	return 0;
}
	

		
	

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fast {ios_base::sync_with_stdio(false);cin.tie(NULL);}
#define pb push_back
#define N 900000
#define ar array
typedef long long int ll;
using namespace std;
int main(void){
	fast;
	ll n;
	cin>>n;
	ll a=n*n;
	ll b=n*n*n;
	ll sum=n+a+b;
	cout<<sum;
	
}


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

int main() {
  int input, b, c, d, ans;
  cin >> input;
  b = input/100;
  c = input/10 - b*10;
  d = input - b*100 - c*10;
  ans = b+c+d;
  cout << ans << endl;
}

Measured memory_bytes: 256
n = list(map(int, input()))
ans = 0
x = 100
for i in range(len(n)):
    if i == 1:
        x = 10
    if i == 2:
        x = 1
    if n[i] == 9:
        ans += x * 1
    elif n[i] == 1:
        ans += x * 9
else:
    print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define mp(a,b) make_pair(a,b)
#define ff first
#define setp(a) setprecision(a)<<fixed
#define ss second
#define fori(v) for(int i=0; i<v; i++)
#define forj(v) for(int j=0; j<v; j++)
#define fork(v) for(int k=0; k<v; k++)
#define forl(v) for(int l=0; l<v; l++)
#define fort(v) for(int t=0; t<v; t++)
#define forz(v) for(int z=0; z<v; z++)
#define forx(v) for(int x=0; x<v; x++)
#define ll long long
#define lll __int128
#define MAX (int)(4*pow(10,3) + 100)
#define pb(a) push_back(a)
#define ch (int)(4*pow(10,4) + 100)
#define ld long double
// #define cout out
// #define cin in
ll inf = pow(10,18);
ll modulo = pow(10,9)+7 ;
double eps = 1e-9;
ifstream in;
ofstream out;




void deal(){
	ll n, m, v, p;
	cin>>n>>m>>v>>p;
	v = v-(p-1)-1;
	ll ans = p-1;
	vector<ll> arr(n);
	fori(n){
		cin>>arr[i];
	}
	sort(arr.rbegin(), arr.rend());
	{
		vector<ll> arr2;
		for(ll i = p-1; i<arr.size(); i++){
			arr2.pb(arr[i]);
		}
		arr = arr2;
	}
	
	
	n = arr.size();
	
/*	fori(n){
		cout<<arr[i]<<' ';
	}
	cout<<endl;
*/	
	ll lo = 0, hi = n-1;
	// last one that satisfies
	while(lo < hi){
		ll mid = (lo+hi)/2+1;
		ll ed = arr[mid] + m;
		ll s = 0;
		fori(n){
			if(i == mid){
				continue;
			}
			s+=min(m, ed-arr[i]);
		}
		if(v<=0){
			s = m;
		}
		else{
			s /= v;
		}
		if(s >= m && ed>=arr[0]){
			// we good
			lo = mid;
		}
		else{
			hi = mid-1;
		}
		
	}
	
	ans += lo+1;
	
	cout<<ans;
	
	
}


int main(){
	cin.tie(0);
	ios_base::sync_with_stdio(0);
	deal();
}



/* 
6 8 
1 2
2 3
3 4
4 1
2 5
3 5
1 6
4 6
*/

Measured memory_bytes: 2168
import java.io.IOException;
import java.io.InputStream;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner fs = new FastScanner();
        int N = fs.nextInt();
        String s = fs.next();
        int ans = 0;

        for (int i = 0; i < 1000; ++i) {
            String t;
            String tmp = Integer.toString(i);
            if (tmp.length() == 1) {
                t = "00" + tmp;
            }
            else if (tmp.length() == 2) {
                t = "0" + tmp;
            }
            else {
                t = tmp;
            }

            int ti = 0;
            for (int j = 0; j < N; ++j) {
                if (s.charAt(j) == t.charAt(ti)) {
                    ++ti;
                    if (ti == 3) {
                        break;
                    }
                }
            }
            if (ti == 3) {
                ++ans;
            }
        }

        System.out.println(ans);
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}

    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }

    public double nextDouble() { return Double.parseDouble(next());}
}




Measured memory_bytes: 37240
n, quantum = list(map(int, input().split()))
queue = []
sumOfTime = 0

for _ in range(n):
    name, time = input().split()
    queue.append([name, int(time)])

while len(queue) > 0:
    name, time = queue.pop(0)
    if time > quantum:
        sumOfTime += quantum
        queue.append([name, time - quantum])
    else:
        sumOfTime += time
        print(name, sumOfTime)



Measured memory_bytes: 13016
#include<stdio.h>
int main()
{
    int a;
    int b,c;
    int k;
    scanf("%d",&a);
    while(a!=0){
            if(a==0)
         
                break;
                k=0;
                a=1000-a;
             
        for(b=0;a!=0;b++){
         
 
 
         if(a>=500){
            k+=1;
            a=a-500;
        }
        else if(a>=100&&a<500){
            k+=1;
            a=a-100;
        }
        else if(a>=50&&a<100){
            k+=1;
        a=a-50;
        }
        else if(a>=10&&a<50){
            k+=1;
            a=a-10;
        }
        else if(a>=5&&a<10){
            k+=1;
            a=a-5;
        }
        else if(a>=1&&a<5){
            k+=1;
            a=a-1;
        }
        }
         
         
         
        printf("%d\n",k);
        scanf("%d",&a);
    }
    return 0;
}

Measured memory_bytes: 2564
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}

ll dfs(ll n,ll x,bool s,bool f,bool t){
    if(x>n) return 0;
    return dfs(n,x*10+7,1,f,t)+dfs(n,x*10+5,s,1,t)+dfs(n,x*10+3,s,f,1)+(s&f&t);
}

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

Measured memory_bytes: 256
# coding: utf-8
# Your code here!

s = input()


a=int(s[0:2])
b=int(s[2:])


aY=0
bY=0
aM=0
bM=0
if 1 <= a <= 12:
    aM=1
if 1 <= b <= 12:
    bM=1

if a==0:
#    print(a,b,"a0")
    if bM==1:
        print("YYMM")
    else:
        print("NA")
elif b==0:
#    print(a,b,"b0")
    if aM==1:
        print("MMYY")
    else:
        print("NA")
else:
    if aM == 1 and bM==1:
       print("AMBIGUOUS")
    elif aM == 1:
       print("MMYY")
    elif bM == 1:
       print("YYMM")
    else:
        print("NA")


Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long ll;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

const int ALP='z'-'a'+1,MAX_N=1e5;
int N,cnt[ALP];
string S;
const ll MOD=1e9+7;
int main(){
	cin>>N>>S;
	REP(i,N){
		cnt[S[i]-'a']++;
	}
	ll ans=1;
	REP(i,ALP){
		ans*=cnt[i]+1;
		ans%=MOD;
	}
	cout<<ans-1<<endl;
}

Measured memory_bytes: 512
//fold
#ifndef KHALIL
#include <bits/stdc++.h>
#else
#include "header.h"
#endif
#define endl '\n'
#define mp make_pair
#define tostr(x) static_cast<ostringstream&>((ostringstream()<<dec<<x)).str()
#define rep(i,begin,end) for(auto i = begin;i < end;i++)
#define repr(i,begin,end) for(auto i = begin-1;i >= end;i--)
#define pb push_back
#define sz(a) ((int)(a).size())
#define fi first
#define se second
#define abs(a) ((a) < (0) ? (-1)*(a) : (a))
#define SQ(a) ((a)*(a))
#define eqd(a,b) (abs(a-b)<1e-9)
#define X real()
#define Y imag()
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename t> t in(t q){cin >> q;return q;}
template <typename T> ostream& operator<<(ostream& os, const vector<T>& v){os << "[";for (int i = 0; i < sz(v); ++i) { os << v[i]; if (i != sz(v) - 1) os << ",";}os << "]";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const map<T, S>& v){for (auto it : v)os << "(" << it.first << ":" << it.second << ")";return os;}
template <typename T, typename S>ostream& operator<<(ostream& os, const pair<T, S>& v){os << "(" << v.first << "," << v.second << ")";return os;}
const long double PI = acosl(-1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
mt19937_64 rng64(chrono::steady_clock::now().time_since_epoch().count());
inline int rand(int l,int r){return uniform_int_distribution<int>(l, r)(rng);}
inline ll rand(ll l,ll r){return uniform_int_distribution<ll>(l, r)(rng64);}
//endfold
#define  N  (100'005)
#define MOD (1'000'000'007ll)
#define OO (1'050'000'000)
#define OOL (1'100'000'000'000'000'000ll)



//global
vector<pair<int,int>> s;
int n,k;
vector<int> adj[N];
int ans = 0;
int d[N];
int bef[N];
vector<int> st;
bool vis[N];

void dfs(int u,int cd){
	st.push_back(u);
	bef[u] = (sz(st) >= k?st[sz(st)-k]:1);
	d[u] = cd;
	for(int v:adj[u]){
		dfs(v,cd+1);
	}
	st.pop_back();
}

void dfsdelete(int u){
	if(vis[u]) return;
	vis[u] = true;
	for(int v:adj[u]){
		dfsdelete(v);
	}
}

int main(){
	//fold
	ios::sync_with_stdio(0);
	cin.tie(0); cout.tie(0);
	cout << setprecision(10);
	//endfold
	cin >> n >> k;
	rep(i,0,n){
		int u = i+1,v;
		cin >> v;
		swap(u,v);
		if(u == v) continue;
		if(v == 1){
			ans++;
			continue;
		}
		adj[u].push_back(v); 
	}
	dfs(1,0);
	rep(i,1,n+1){
		if(d[i] > k) s.push_back({-d[i],i});
	}
	sort(s.begin(), s.end());
	rep(i,0,sz(s)){
		if(!vis[s[i].second]){
			ans++;
			dfsdelete(bef[s[i].second]);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 12792
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    ll n, s;
    scanf("%lld%lld", &n, &s);

    if(n<s) {
        printf("-1\n"); return 0;
    }
    if(n==s) {
        printf("%lld\n", n+1); return 0;
    }
    ll a=n-s;

    int i;
    vector<ll> v;
    for(i=1; i<sqrt((double)a)+0.1; i++) {
        if(a%i==0) {
            v.push_back(i);
            if(i!=a/i) v.push_back(a/i);
        }
    }
    sort(v.begin(), v.end());

    for(i=0; i<(int)v.size(); i++) {
        ll p = v[i]+1;
        ll curr=n;
        ll cnt=0;
        while(curr) {
            cnt += (curr%p);
            curr /= p;
        }
        if(cnt==s) {
            printf("%lld\n", p); return 0;
        }       
    }
    printf("-1\n");

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(){
int a[10000], min, max, n, i;
long long sum = 0;scanf("%d", &n);
for(i = 0; i < n; i++){
scanf("%d", &a[i]);
sum += a[i];}
max = min = a[0];
for(i = 1; i < n; i++){
if(a[i] > max)max = a[i];if(a[i] < min)min = a[i];}
printf("%d %d %lld\n", min, max, sum);
return 0;
}


Measured memory_bytes: 2136
N, W = map(int, input().split())
wv = [[int(i) for i in input().split()] for _ in range(N)]

dp = [[0] * (W + 1) for _ in range(N + 1)]
for i in range(N) :
    for j in range(W+1) :
        if j >= wv[i][0] :
            dp[i+1][j] = max(dp[i][j-wv[i][0]] + wv[i][1], dp[i][j])
        else :
            dp[i+1][j] = dp[i][j]
print(dp[N][W])

Measured memory_bytes: 120044
#include <iostream>

using namespace std;

int main() {
	int res = 0;
	for(int i = 0; i < 5; i++) {
		int tmp; cin >> tmp;
		if(tmp >= 40) {
			res += tmp;
		}
		else {
			res += 40;
		}
	}
	cout << res / 5 << endl;

	return 0;
}

Measured memory_bytes: 1160
#include <set>
#include <queue>
#include <cmath>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <cstring>
#include <iostream>
#include <algorithm>
#define debug(x) cerr<<#x<<'='<<x<<endl
#define set0(x) memset(x,0,sizeof(x))
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pii;
template<typename T> void read(T &x){
	x = 0;char ch = getchar();ll f = 1;
	while(!isdigit(ch)){if(ch == '-')f*=-1;ch=getchar();}
	while(isdigit(ch)){x = x*10+ch-48;ch=getchar();}x*=f;
}

int mod = 998244353;
inline int mul(int x,int y){return 1ll*x*y%mod;}
int add(int x,int y){return x+y>=mod?x+y-mod:x+y;}
int sub(int x,int y){return x-y<0?x-y+mod:x-y;}
int sq(int x){return 1ll*x*x%mod;}
int pow(int a,int b){return b == 0 ? 1 : ( b&1 ? mul(a,sq(pow(a,b/2))) : sq(pow(a,b/2)));}

int n,a[1000010] = {0},w[1000010] = {0};
const int N = 1000000;
int main() {
	read(n);
	for(int i=0;i<n;i++){
		int cu;
		read(cu);
		a[cu]++;
	}
	int rans = 0;
	for(int i=1;i<=N;i++){
		w[i]=add(w[i],pow(i,mod-2));
		int ans = 0;
		int cu = 0;
		for(int j=i;j<=N;j+=i){
			if(j!=i)w[j] = sub(w[j],w[i]);
			for(int k=0;k<a[j];k++){
				ans = add(ans,mul(cu,j));
				cu = add(cu,j);
			}
		}
		rans = add(rans,mul(ans,w[i]));
	}
	cout<<rans<<endl;
	return 0;
}


Measured memory_bytes: 8064
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
using namespace std;
 
 
int main() {
  int N;
  vector<long int> A;
  cin >> N;
  A.resize(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  sort(A.begin(),A.end());
  long int l=0;
  for(int i=0;i<N;i++){
    l=l+A[i];
  } 
  int count=1;
  for(int i=0;i<N;i++){
    l=l-A[N-1-i];
    if(2*l<A[(N-1)-i]){
      break;
    }
    else{
      count=count+1;
    }
  }
  cout << count  <<endl;
  
  return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e9 + 7;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second

int n, m, a, d;
bool table[100][100];
int ans;

void solve(int now, int cnt){
	//cout << "!" << now << endl;
	if (cnt == d){
		//cout << endl;
		if (now == a){
			//cout << "!!" << endl;
			ans = 0;
		}
		return;
	}
	bool f = 1;
	if (now > 0 && table[cnt][now - 1]){
		solve(now - 1, cnt + 1);
		f = 0;
	}
	if (now < n - 1 && table[cnt][now]){
		solve(now + 1, cnt + 1);
		f = 0;
	}
	if(f)solve(now, cnt + 1);
}

int main(){
	while (cin >> n&&n){
		ans = 1;
		cin >> m >> a >> d;
		m--; a--;
		REP(i, d){
			string s;
			cin >> s;
			REP(j, s.size())table[i][j] = s[j] - '0';
		}
		//REP(i, d){
		//	REP(j, n - 1){
		//		cout << table[i][j];
		//	}
		//	cout << endl;
		//}
		solve(m, 0);
		if (!ans){
			cout << ans << endl;
			continue;
		}
		bool f = 0;
		REP(i, d){
			REP(j, n - 1){
				if (table[i][j] == 0){
					if (j > 0 && table[i][j - 1])continue;
					if (j < n - 2 && table[i][j + 1])continue;
					table[i][j] = 1;
					solve(m, 0);
					if (!ans){
						cout << i + 1 << " " << j + 1 << endl;
						f = 1;
					}
					table[i][j] = 0;
				}
				if (f)break;
			}
			if (f)break;
		}
		if (!f)cout << ans << endl;
	}

}

Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<(b);++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(),x.end()
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> freq(26);
    string s;
    cin >> s;
    rep(i,0,n) ++freq[s[i]-'a'];
    ll tot = 1;
    const ll MOD = 1e9+7;
    rep(i,0,26) {
        tot = (tot*(freq[i]+1))%MOD;
    }
    tot=(tot+MOD-1)%MOD;
    cout<<tot<<"\n";
}


Measured memory_bytes: 512
n = int(input())
t = [int(i) for i in input().split()]
s = sum(t)
m = int(input())
ans = []
for _ in range(m):
    p,x = map(int,input().split())
    p -= 1
    ans.append(s-t[p]+x)
print("\n".join(map(str,ans)))

Measured memory_bytes: 3064
S = list(input())
#S = list("dream" * 20000)
string = [list("dream") ,  list("dreamer") , list("erase") ,list("eraser")]
for i in range(4):
    string[i] = string[i][::-1]
#print(string)
S = S[::-1]
#print(S[0:5])
idx = 0
#print(S[idx:5])
while idx != len(S):
    if S[idx:idx + 5] == string[0]:
        idx += 5
    elif S[idx:idx + 7] == string[1]:
        idx += 7
    elif S[idx:idx + 5] == string[2]:
        idx += 5
    elif S[idx:idx + 6] == string[3]:
        idx += 6
    else:
        print("NO")
        exit()
print("YES")

Measured memory_bytes: 50544
#define _CRT_SECURE_NO_WARNINGS
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//#define int ll
//#define endl "\n"
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
template<class T> ostream & operator<<(ostream & os, vector<T> const &);
template<int n, class...T> typename enable_if<(n>=sizeof...(T))>::type _ot(ostream &, tuple<T...> const &){}
template<int n, class...T> typename enable_if<(n< sizeof...(T))>::type _ot(ostream & os, tuple<T...> const & t){ os << (n==0?"":" ") << get<n>(t); _ot<n+1>(os, t); }
template<class...T> ostream & operator<<(ostream & os, tuple<T...> const & t){ _ot<0>(os, t); return os; }
template<class T, class U> ostream & operator<<(ostream & os, pair<T,U> const & p){ return os << "(" << p.first << ", " << p.second << ") "; }
template<class T> ostream & operator<<(ostream & os, vector<T> const & v){ rep(i,v.size()) os << v[i] << (i+1==(int)v.size()?"":" "); return os; }
template<class T> inline bool chmax(T & x, T const & y){ return x<y ? x=y,true : false; }
template<class T> inline bool chmin(T & x, T const & y){ return x>y ? x=y,true : false; }
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<mt(__VA_ARGS__)<<" ["<<__LINE__<<"]"<<endl)
#else
#define dump(...)
#endif
// ll const mod = 1000000007;
// ll const inf = 1LL<<60;

int solve(ll s, ll d){
    if(s <= 0 && d >= 0) return __builtin_popcount(-s) + __builtin_popcount(d);
    else if(s >= 0 && d >= 0){
        int j = 0;
        int ans = 0;
        while(s < d){
            if((s>>j&1) && (d>>j&1)){
                s += 1LL<<j;
                d -= 1LL<<j;
                ans += 2;
            } else if((s>>j&1) ^ (d>>j&1)){
                s += 1LL<<j;
                ans ++;
            }
            j++;
        }
        return ans;
    } else return solve(-d,-s);
}

signed main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    int N;
    cin >> N;
    rep(i,N){
        ll s,d;
        cin >> s >> d;
        cout << solve(s,d) << endl;
    }
}

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

int distance(int start, int destination, std::vector<std::vector<int>> &v){
  int n = v.size();
  std::vector<int> d(n);
  int node = start;
  std::vector<bool> finished(n, false);
  std::vector<bool> candidate(n, false);
  std::stack<int> s;
  s.push(node);
  candidate[node] = true;
  d[node] = 0;
  
  while(!s.empty()){
    node = s.top();
    s.pop();
    finished[node] = true;
    candidate[node] = false;
    
    if(node == destination){
      break;
    }
    
    int num_of_children = v[node].size();
    for(int child = 0; child < num_of_children; child++){
      if(finished[v[node][child]]){
        continue;
      }
      if(candidate[v[node][child]]){
        continue;
      }
      s.push(v[node][child]);
      candidate[v[node][child]] = true;
      d[v[node][child]] = d[node] + 1;
    }
  }
  
  return d[destination];
}

std::vector<int> sphere(int start, int depth, std::vector<std::vector<int>> &v){
  int n = v.size();
  std::vector<int> d(n);
  std::vector<int> sphr;
  int node = start;
  std::vector<bool> finished(n, false);
  std::vector<bool> candidate(n, false);
  std::stack<int> s;
  s.push(node);
  candidate[node] = true;
  d[node] = 0;
  
  while(!s.empty()){
    node = s.top();
    s.pop();
    finished[node] = true;
    candidate[node] = false;
    
    if(d[node] == depth){
      sphr.push_back(node);
      continue;
    }
    
    int num_of_children = v[node].size();
    for(int child = 0; child < num_of_children; child++){
      if(finished[v[node][child]]){
        continue;
      }
      if(candidate[v[node][child]]){
        continue;
      }
      s.push(v[node][child]);
      candidate[v[node][child]] = true;
      d[v[node][child]] = d[node] + 1;
    }
  }
  
  return sphr;
}

int count(int start, std::vector<int> &gap, std::vector<std::vector<int>> &v){
  int n = v.size();
  int node = start;
  std::vector<bool> finished(n, false);
  for(int i : gap){
    finished[i] = true;
  }
  std::vector<bool> candidate(n, false);
  std::stack<int> s;
  s.push(node);
  candidate[node] = true;
  
  while(!s.empty()){
    node = s.top();
    s.pop();
    finished[node] = true;
    candidate[node] = false;
    
    
    int num_of_children = v[node].size();    
    for(int child = 0; child < num_of_children; child++){
      if(finished[v[node][child]]){
        continue;
      }
      if(candidate[v[node][child]]){
        continue;
      }
      s.push(v[node][child]);
      candidate[v[node][child]] = true;
    }
  }
  
  int count = 0;
  for(int i = 0; i < n; i++){
    if(finished[i]) count++;
  }
  count -= gap.size();
  
  return count;
}

int main(){
  int n;
  std::cin >> n;
  std::vector<std::vector<int>> v(n);
  int a, b;
  for(int i = 0; i < n - 1; i++){
    std::cin >> a >> b;
    v[a - 1].push_back(b - 1);
    v[b - 1].push_back(a - 1);
  }
  
  int d = distance(0, n - 1, v);
  std::vector<int> gap = sphere(0, d / 2, v);
  int white = count(n - 1, gap, v);
  if(white >= n - white){
    std::cout << "Snuke" << '\n';
  }else{
    std::cout << "Fennec" << '\n';
  }
  
  return 0;
}



Measured memory_bytes: 6144