akhauriyash/Code-Regression huggingface dataset:
//tree DP
//ABC036-D
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<stdbool.h>
#include<time.h>
#define inf 1072114514
#define llinf 4154118101919364364
#define mod 1000000007
#define pi 3.1415926535897932384

int max(int a,int b){if(a>b){return a;}return b;}
int min(int a,int b){if(a<b){return a;}return b;}
int zt(int a,int b){return max(a,b)-min(a,b);}

typedef struct{
int val;
int node;
}sd;

int sdsortfnc(const void *a,const void *b){
if(((sd*)a)->val < ((sd*)b)->val){return -1;}
if(((sd*)a)->val > ((sd*)b)->val){return 1;}
return 0;
}

typedef struct{
    long long st;
    long long fi;
    long long kr;
}rs;

typedef struct{
    long long st;
    long long kz;
}mkj;

int sortfnc(const void *a,const void *b){
if(((rs*)a)->st == ((rs*)b)->st){return 0;}
if(((rs*)a)->st < ((rs*)b)->st){return -1;}
return 1;
}

void makemkj(rs g[],mkj x[],long long n){
    long long i,ms=0,nst=g[0].st;
    for(i=1;i<n;i++){
        if(g[i].st!=g[i-1].st){
            x[nst].kz=i-ms;
            x[nst].st=ms;
            nst=g[i].st;ms=i;
        }
    }
    x[nst].kz=n-ms;
    x[nst].st=ms;
}

long long dist[524288],par[524288];
void dfs(long long t,long long l,long long bp,rs g[],mkj x[]){
  long long i;
  if(dist[t]<=l){return;}
  dist[t]=l;
  par[t]=bp;
  for(i=x[t].st;i<x[t].st+x[t].kz;i++){
    dfs(g[i].fi,l+1,t,g,x);
  }
}

int main(void){
    long long i,j,n,m,k,a,b,c,h,w,r,l,t;
    long long cnt[524288]={0};
    long long res=0;
    rs g[524288];
    mkj x[524288];
    sd dat[524288];
    scanf("%lld%lld",&n,&k);
    for(i=0;i<(n-1);i++){
      scanf("%lld%lld",&a,&b);
      cnt[a]++;
      cnt[b]++;
      g[2*i].st=a;
      g[2*i].fi=b;
      g[2*i].kr=1;
      g[2*i+1].st=b;
      g[2*i+1].fi=a;
      g[2*i+1].kr=1;
    }
    qsort(g,2*(n-1),sizeof(g[0]),sortfnc);
    makemkj(g,x,2*(n-1));
    for(i=0;i<=n;i++){
      dist[i]=inf;
    }
    dfs(1,0,-1,g,x);
    for(i=0;i<n;i++){
      dat[i].node=i+1;
      dat[i].val=dist[i+1];
    }
    qsort(dat,n,sizeof(dat[0]),sdsortfnc);
    r=k;
    for(i=0;i<n;i++){
      w=dat[i].node;
      if(i==0){c=cnt[w];t=k-1;}
      else{c=cnt[w]-1;t=k-2;}
      //printf("%lld %lld %lld\n",w,c,k);
      for(j=0;j<c;j++){
        r*=(t-j);
        r%=mod;
      }
    }
    printf("%lld\n",r);
    return 0;
}


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

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

  int n;cin>>n;
  int res=0;
  while(n--){
    int l,r;cin>>l>>r;
    res+=(r-l+1);
  }
  cout<<res<<endl;

  return 0;
}


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

int main(){
    int a,b,c,x; cin>>a>>b>>c>>x;

    int ans=0;

    for(int i=0; i<=a; i++){
        for(int j=0; j<=b; j++){
            for(int k=0; k<=c; k++){
                if(500*i + 100*j + 50*k == x){
                    ans++;
                }
            }
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3604
#pragma region include
#include <iostream>
#include <iomanip>
#include <stdio.h>

#include <sstream>
#include <algorithm>
#include <iterator>
#include <cmath>
#include <complex>

#include <string>
#include <cstring>
#include <vector>
#include <tuple>
#include <bitset>

#include <queue>
#include <set>
#include <map>
#include <stack>
#include <list>

#include <fstream>
#include <random>
//#include <time.h>
#include <ctime>
#pragma endregion //#include
/////////
#define REP(i, x, n) for(int i = x; i < n; ++i)
#define rep(i,n) REP(i,0,n)
#define ALL(X) X.begin(), X.end()
/////////
#pragma region typedef
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef std::pair<LL,LL> PLL;//
typedef std::pair<int,int> PII;//
#pragma endregion //typedef
////定数
const int INF = (int)1e9;
const LL MOD = (LL)1e9+7;
const LL LINF = (LL)4e18+20;
const LD PI = acos(-1.0);
const double EPS = 1e-9;
/////////
using namespace::std;
/////////
#pragma region Math
#pragma region
template<class T>
inline T gcd(T a, T b){return b ? gcd(b, a % b) : a;}
#pragma endregion // 最大公約数 gcd
#pragma region
template<class T>
inline T lcm(T a, T b){return a / gcd(a, b) * b;}
#pragma endregion // 最小公倍数 lcm
#pragma region
LL powMod(LL num,LL n,LL mod=(LL)MOD){//(num**n)%mod
	num %= mod;//
	if( n == 0 ){
		return (LL)1;
	}
	LL mul = num;
	LL ans = (LL)1;
	while(n){
		if( n&1 ){
			ans = (ans*mul)%mod;
		}
		mul = (mul*mul)%mod;
		n >>= 1;
	}
	return ans;
}
LL mod_inverse(LL num,LL mod=MOD){
	return powMod(num,MOD-2,MOD);
}
#pragma endregion //繰り返し二乗法 powMod
#pragma region
template<class T>
vector<T> getDivisor(T n){
	vector<T> v;
	for(int i=1;i*i<=n;++i){
		if( n%i == 0 ){
			v.push_back(i);
			if( i != n/i ){//平方数で重複して数えないように
				v.push_back(n/i);
			}
		}
	}
	sort(v.begin(), v.end());
	return v;
}
#pragma endregion //約数列挙 getDivisor(n):O(√n)
#pragma endregion //math
//Utility:便利な奴
#pragma region
template<class T>
void UNIQUE(vector<T>& vec){
	sort(vec.begin(),vec.end());
	vec.erase(unique(vec.begin(),vec.end()),vec.end() );
}
#pragma endregion // sort erase unique

void solve(){
	int N;
	cin >> N;
	vector<int> D(N);
	for(int i=0;i<N;++i){
		cin >> D[i];
	}
	UNIQUE( D );
	cout << D.size() << endl;
}

#pragma region main
signed main(void){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	std::cout << std::fixed;//小数を10進数表示
	cout << setprecision(16);//小数点以下の桁数を指定//coutとcerrで別	

	solve();
}
#pragma endregion //main()

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl 

void Suhaib_Sawalha (){

    vector <string> v = {"SUN", "MON", "TUE", "WED", "THU", "FRI", "SAT"};
    string s;
    cin >> s;
    cout << v.end() - find(v.begin(),v.end(),s);

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}

Measured memory_bytes: 3612
#include <stdio.h>
int main (){

  int A[100],ans=0,a,b,i,j,flag=1;

  scanf("%d",&a);
  for(i=0;i<a;i++) scanf("%d",&A[i]);

  while(flag){
      flag=0;
      for(j=a-1;j>0;j--){
          if(A[j]<A[j-1]){
            b=A[j];
            A[j]=A[j-1];
            A[j-1]=b;
            flag=1;
            ans++;
          }
       }
  }
  for(i=0;i<a;i++){
    printf("%d",A[i]);
    if(i<a-1) printf(" ");
    else printf("\n");
  }

  printf("%d\n",ans);
  return 0;
}




Measured memory_bytes: 2692
// C - Lining Up

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
const ll MOD = 1e9 + 7;

int A[100000];

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

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

	sort(A, A+N);

	ll ans = 1;
	if (N % 2 == 0) {
		for (int i=0; i<N; i++) {
			if (i % 2 == 0) {
				if (A[i] != A[i+1]) {
					ans = 0;
					break;
				}

				ans = ans * 2 % MOD;
			}
		}
	} else {
		for (int i=0; i<N; i++) {
			if (i % 2 == 1) {
				if (A[i] != A[i+1]) {
					ans = 0;
					break;
				}

				ans = ans * 2 % MOD;
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
import sys
import re
import queue
from math import ceil, floor, sqrt, pi, factorial, gcd
from copy import deepcopy
from collections import Counter, deque
from heapq import heapify, heappop, heappush
from itertools import accumulate, product, combinations, combinations_with_replacement
from bisect import bisect, bisect_left, bisect_right
from functools import reduce
from decimal import Decimal, getcontext
# input = sys.stdin.readline
def i_input(): return int(input())
def i_map(): return map(int, input().split())
def i_list(): return list(i_map())
def i_row(N): return [i_input() for _ in range(N)]
def i_row_list(N): return [i_list() for _ in range(N)]
def s_input(): return input()
def s_map(): return input().split()
def s_list(): return list(s_map())
def s_row(N): return [s_input for _ in range(N)]
def s_row_str(N): return [s_list() for _ in range(N)]
def s_row_list(N): return [list(s_input()) for _ in range(N)]
def lcm(a, b): return a * b // gcd(a, b)
sys.setrecursionlimit(10 ** 6)
INF = float('inf')
MOD = 10 ** 9 + 7
num_list = []
str_list = []

def main():
    H, W = i_map()
    Ch, Cw = i_map()
    Dh, Dw = i_map()
    Ch,Cw = Ch-1,Cw-1
    Dh,Dw = Dh-1,Dw-1
    maze = [input() for _ in range(H)]

    INF = 10 ** 12
    path = [[INF] * W for _ in range(H)]  # path: 各マスへの移動コスト

    # walk:移動A, warp:移動B
    walk = [(0, 1), (0, -1), (-1, 0), (1, 0)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + walk]

    q = deque()
    path[Ch][Cw] = 0
    q.append((Ch, Cw, 0))

    while(q):
        ux,uy,s = q.popleft()
        for dx,dy in walk:
            nx = ux + dx
            ny = uy + dy
            if(0<=nx<H and 0<=ny<W and maze[nx][ny]=='.' and path[nx][ny] > s):
                path[nx][ny] = s
                q.appendleft((nx,ny,s))
        for dx,dy in warp:
            nx = ux + dx
            ny = uy + dy
            if(0<=nx<H and 0<=ny<W and maze[nx][ny]=='.' and path[nx][ny] > s+1):
                path[nx][ny] = s+1
                q.append((nx,ny,s+1))

    ans = path[Dh][Dw] if path[Dh][Dw] < INF else '-1'
    print(ans)


if __name__ == '__main__':
	main()

Measured memory_bytes: 103288
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int , int> P;
typedef pair<ll, ll> PL;
const int INT_INF = 2147483646;
const ll LL_INF = 9223372036854775807;

bool SecondCompare(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second<b.second;
}
 
bool SecondCompareDes(const pair<int,int> &a,const pair<int,int> &b)
{
       return a.second>b.second;
}
 
int n,m,xx,yy;
int x[100], y[100];

int main(){
    cin >> n >> m >> xx >> yy;
    for(int i = 0; i < n; i++){ cin >> x[i];}
    for(int i = 0; i < m; i++) { cin >> y[i];}

    sort(x,x+n);
    sort(y,y+m);

    if(x[n-1] >= y[0]){
        cout << "War\n";
        return 0;
    }

    if(x[n-1] >= yy){
        cout << "War\n";
        return 0;
    }
    if(y[0] <= xx){
        cout << "War\n";
        return 0; 
    }

    cout << "No War\n";
}

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

int main() {
  long long n;
  std::cin >> n;
  long long max_factor = 1;
  for (long long i = 1; i * i <= n; i++)
    if (n % i == 0) max_factor = i;
  long long rest = n / max_factor;
  std::cout << 1 + std::floor(std::log10(rest)) << std::endl;
}


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

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()

#define SI(n) scanf("%d",&n)
#define PI(n) printf("%d\n",n)
#define SL(n) scanf("%lld",&n)
#define PL(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE
#ifdef TRACE
#define TR(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define TR(...)
#endif
//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);
typedef long long int 	LL;
typedef long double 	LD;
typedef pair<int,int>   II;
typedef vector<int>     VI;
const int MOD = 1e9 + 7;
const int N = 100011;


int main() {
    int n;
    SI(n);
    VI A(n), B(n), C(n);
    vector<LL> preB(n);
    for(int i = 0; i < n; ++i)
        SI(A[i]);
    for(int i = 0; i < n; ++i)
        SI(B[i]);
    for(int i = 0; i < n; ++i)
        SI(C[i]);
    sort(ALL(A));
    sort(ALL(B));
    
    for(int i = 0; i < n; ++i) {
        int x = B[i];
        int t = lower_bound(ALL(A), x) - A.begin();
        preB[i] = t;
    }
    for(int i = 1; i < n; ++i)
        preB[i] += preB[i-1];

    LL ans = 0;
    for(int i = 0; i < n; ++i) {
        int x = C[i];
        LL b = lower_bound(ALL(B), x) - B.begin();
        b--;
        if(b >= 0)
            ans += preB[b];
    }
    PL(ans);
    return 0;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    string t;
    cin>>s>>t;
    int ans=0;
    int n=s.length();
    for(int i=0;i<n;i++)
    {
        if(s[i]!=t[i])
        {
            ++ans;
        }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3820
#include<bits/stdc++.h>
using namespace std;
using uint = unsigned int;
using ll = long long;
using ull = unsigned long long;

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

int main() {
	int A, B;
	cin >> A >> B;
	cout << A * B << endl;
	return 0;
}

Measured memory_bytes: 3604
require 'prime'
N = gets.to_i
a_list = gets.split.map(&:to_i)

forward_gcd_list = []
prev_gcd = nil
a_list.each do |a|
  gcd = if prev_gcd == nil
    a
  else
    prev_gcd.gcd(a)
  end
  forward_gcd_list.push(gcd)
  prev_gcd = gcd
end
backward_gcd_list = []
prev_gcd = nil
a_list.reverse.each do |a|
  gcd = if prev_gcd == nil
    a
  else
    prev_gcd.gcd(a)
  end
  backward_gcd_list.unshift(gcd)
  prev_gcd = gcd
end

ans = -1
(0...N).each do |i|
  front_gcd = i >= 1 ? forward_gcd_list[i - 1] : nil
  back_gcd = i < N - 1 ? backward_gcd_list[i + 1] : nil
  if front_gcd == nil
    ans = back_gcd if back_gcd > ans
  elsif back_gcd == nil
    ans = front_gcd if front_gcd > ans
  else
    gcd = front_gcd.gcd(back_gcd)
    ans = gcd if gcd > ans
  end
end
puts ans


Measured memory_bytes: 11688
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;
using pll=pair<ll,ll>;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define MOD 1000000007

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; }

int main() {
	int N;
	ll H;
	cin >> N >> H;
	vector<pll> A(N);
	rep(i,N) cin >> A[i].se >> A[i].fi;
	ll d = 0;
	ll maxi = -1, idx = -1;
	rep(i,N) {
		if(maxi < A[i].se) {
			maxi = A[i].se;
		}
	}
	sort(A.begin(), A.end(), greater<>());
	rep(i,N) {
		if(A[i].se == maxi) idx = i;
	}
	int cnt=0;
	//cout << maxi << endl;
	rep(j,N) {
		if(A[j].fi > maxi /*&& j != idx*/) {
			H -= A[j].fi;
			cnt++;
			if(H <= 0) break;
		}
	}
	if(H > 0) {
		/*if(A[idx].fi > A[idx].se) {
			H -= A[idx].fi;
			cnt++;
		}*/
		//if(H > 0) {
			if(H % A[idx].se != 0) cnt++;
			cnt += H / A[idx].se;
		//}
	}
	cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 4844
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("sse2")

#include<bits/stdc++.h>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

#define int         long long
#define ll          long long
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define mp          make_pair
#define all(a)      (a).begin(),(a).end()
#define FF           first
#define SS           second
#define sz(x)       (int)x.size()
#define endl        '\n'
//#define hell          1000000007
#define rep(i,a,b)  for(int i=a;i<b;i++)
// mp::cpp_int
#define pp pair<pii,pii>
const int hell =1000000007;



int power(int a,int b)
{
  if(b==0)return 1;
  if(b==1)return a;
  int t=power(a,b/2);
  t%=hell;
  t*=t;
  t%=hell;
  if(b%2)return (t*a)%hell;
  else
     return t;
}

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

int digitsum(int x)
{
  while(x>9)
    {  int ans=0;
       while(x!=0)
       {
        ans+=x%10;
        x/=10;
       }
       x=ans;
    }
    return x;
}

int pw(int a,int b)
{
  int x=a;
  rep(i,1,b){a=a*x;}
  return a;
}

int solve( ){

int n,k;
cin>>n>>k;
if(n>=k)cout<<n-k+1;
else cout<<0;
 

return 0;
}

signed main()
{  int t=1;
 ios::sync_with_stdio(false);
   cin.tie(0);
   cout.tie(0);
   cin.exceptions(cin.failbit);

  

  clock_t time_req;

    // Without using pow function
    time_req = clock();
    
//cin>>t;

    int k=1;
   while(t--)
     {
       //cout<<"case #"<<k<<":"<<" ";k++;
      solve();
     }

         time_req = clock() - time_req;
 // cout << "Processor time taken is "
   // << (double)time_req/CLOCKS_PER_SEC << " seconds" << endl;


    return 0;
}

Measured memory_bytes: 256
// luogu-judger-enable-o2
#include <bits/stdc++.h>
using namespace std;
long long n,a[100002],o;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i];
	}
	sort(a+1,a+n+1);
	int j=1;
	for(int i=2;i<=n;i++){
		if(a[i]==a[i-1])j=(j+1)%2;
		else o+=j,j=1;
	}
	if(j%2)o++;
	cout<<o<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
using namespace std;

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

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main(){
    int n;
    string s, t;
    cin >> n >> s >> t;

    REP(i,n){
        bool f = 1;
        REP(j,n-i){
            if (s[j+i] != t[j]) f = 0;
        }
        if (f){
            cout << n+i << endl;
            return 0;
        }
    }

    cout << 2*n << endl;

    return 0;
}

Measured memory_bytes: 384
# ABC 061: B – Counting Roads
n, m = [int(s) for s in input().split()]

a = []
b = []

for _ in range(m):
    tmp = [int(s) for s in input().split()]
    a.append(tmp[0])
    b.append(tmp[1])

for i in range(1, n + 1):
    print(a.count(i) + b.count(i))

Measured memory_bytes: 3060
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    for (i in 1..n) {
        val (x1, y1, x2, y2) = Array(4, { sc.nextDouble() })
        val (x3, y3, x4, y4) = Array(4, { sc.nextDouble() })
        val dx1 = x2-x1
        val dx2 = x4-x3
        val dy1 = y2-y1
        val dy2 = y4-y3
        if (Math.abs(dx1*dy2-dx2*dy1) < 1e-10) println("YES")
        else println("NO")
    }
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) (((n) * ((n) + 1)) / 2)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
constexpr int MOD = 1e9 + 7;
//} END

signed main(void) {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int n;
  cin >> n;
  vector<int> a(n);
  arep(i, a) cin >> i;
  sort(all(a));
  int q;
  cin >> q;
  int ans = 0;
  rep(i, 0, q) {
    int s;
    cin >> s;
    if (upper_bound(all(a), s) - lower_bound(all(a), s) != 0) ++ans;
  }

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


Measured memory_bytes: 3532
while True:
    try:
        w = float(input())
    except:
        break
    if w<=48.00:
        print('light fly')
    if 48.00<w<=51.00:
        print('fly')
    if 51.00<w<=54.00:
        print('bantam')
    if 54.00<w<=57.00:
        print('feather')
    if 57.00<w<=60.00:
        print('light')
    if 60.00<w<=64.00:
        print('light welter')
    if 64.00<w<=69.00:
        print('welter')
    if 69.00<w<=75.00:
        print('light middle')
    if 75.00<w<=81.00:
        print('middle')
    if 81.00<w<=91.00:
        print('light heavy')
    if 91.00<w:
        print('heavy')


Measured memory_bytes: 5568
s=input().split()
a=int(s[0])
b=int(s[2])
c=s[1]
while (c!='?'):
    if(c=='+'):print(a+b)
    elif(c=='-'):print(a-b)
    elif(c=='*'):print(a*b)    
    elif(c=='/'):print(int(a/b))
    s=input().split()
    a=int(s[0])
    b=int(s[2])
    c=s[1]

Measured memory_bytes: 7576
# define _CRT_SECURE_NO_WARNINGS 1
# define _USE_MATH_DEFINES
# include <iostream>
# include <numeric>
# include <string>
# include <bitset>
# include <vector>
# include <algorithm>
# include <cstdlib>
# include <cstdio>
# include <cstring>
# include <cstdlib>
# include <iomanip>
# include <queue>
# include <sstream>
# include <unordered_set>
# include <unordered_map>
# include <climits>
# include <complex>
# include <cmath>
# include <list>
# include <functional>
# include <string>
# include <ctime>
# include <set>
# include <forward_list>
# include <map>
# include <stack>
using namespace std;
# define INF ((int)(1<<25))
# define REP(i,n) for(int i=0;i<(int)n;i++)
# define FOR(i,n) REP(i,n)
# define FORI(i,k,n) for(int i=k;i<(int)n;i++)
# define TORAD 2.0*M_PI/360.0
# define INT(x) int x;cin>>x;
# define STR(x) string x;cin>>x;
# define ALL(x) begin(x),end(x)
# define RALL(x) (x).rbegin(),(x).rend()
# define DEBUG(x) cout<<#x<<":"<<x<<endl;
# define EPS 1e-12
#ifdef _MSC_VER
#include <intrin.h>
#define __builtin_popcount __popcnt
#endif
typedef long long lint;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<int> vi;
typedef vector<lint> vl;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef pair<int, pii> piii;
const int dx[4] = { 0,1,0,-1 }, dy[4] = { -1,0,1,0 };
const int M = 1000000007;
template<class T> void debug(T a) { for (auto i : a)cout << i << endl; }

int N, W;
int memo[200][10001];
vi a;
int t,z;
int dp(int now, int w)
{
	if (now == a.size()&&w==0)return 1;
	if (now == a.size())return 0;
	if (w < 0)return 0;
	if (memo[now][w] != -1)return memo[now][w];
	int ans = 0;
	ans += dp(now + 1, w - a[now]);
	if (a[now]>z)ans += dp(now + 1, w);
	ans %= M;
	return memo[now][w] = ans;
}

int main()
{
	cin >> N >> W;
	FOR(i, N)
	{
		INT(x); a.push_back(x);
	}
	sort(ALL(a));
	int ans = 0;
	for (t = 0; t <= W; t++)
	{
		z = W - t;
		memset(memo, -1, sizeof memo);
		ans = (ans + dp(0, t))%M;
	}
	cout << ans << endl;
}

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

int main(){
    string contest;
    cin >> contest;
    if(contest == "ABC")
        cout << "ARC" << endl;
    else
        cout << "ABC" << endl;
    return 0;
}


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

using namespace std;

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


// void recurse(int i)
// {
//     //  ith recurse(i) gives the no of robots possible by taking in the ith robo



// }

bool sortcol( const vector<int>& v1, 
               const vector<int>& v2 ) { 
 return v1[1] < v2[1]; 
} 

int main()
{
	int N;
    cin >> N;
    
    vector<vector<int> >robots(N, vector<int>(2));

    // Take input
    repr(i, N) cin >> robots[i][0] >> robots[i][1];

    // repr(i, N) cout << robots[i][0] << robots[i][1];
    
    // Lets update the vector robots inplace
    repr(i, N) 
    {
        int l = robots[i][0] - robots[i][1];
        int r = robots[i][0] + robots[i][1];

        // Update vals
        robots[i][0] = l;
        robots[i][1] = r;
    }

    // Now sort the robots vector based on r coors
    sort(robots.begin(), robots.end(), sortcol);
    // repr(i, N) cout << robots[i][0] << robots[i][1];

    set<vector<int> >to_return;
    // aDD THE first robot
    to_return.emplace(robots[0]);


    // Loop over the robot
    for(int i = 1; i < robots.size(); i++)
    {
        auto it = to_return.rbegin();

        int val = (*it)[1];
        // cout << val << endl;
        if(robots[i][0] >= val)
        {
            to_return.emplace(robots[i]);
        }

    }

    cout << to_return.size() << endl;
	return 0;
}


Measured memory_bytes: 15104
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <iostream>
#include <bitset>
using namespace std;
#define N 100005
#define ll long long
#define mod 1000000007
char c[N];
int sum[128],n;
int main()
{	
	scanf("%d%s",&n,c+1);
	for(int i=1;i<=n;i++)sum[c[i]-'a']++;
	int ans=1;
	for(int i=0;i<26;i++)ans=(ll)ans*(sum[i]+1)%mod;
	printf("%d\n",(ans+mod-1)%mod);
	return 0;
}

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

#define ll long long
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false); cin.tie(NULL);
#define M 1000000007

void solve()
{
	ll n,w;
	cin>>n>>w;
	vector<pair<ll,ll>> v;
	v.push_back({-1,-1});
	for(ll i=0;i<n;i++) 
	{
		ll x,y;
		cin>>x>>y;
		v.push_back({x,y});
	}
	sort(v.begin(),v.end());
	ll dp[n+1][w+1];
	memset(dp,0,sizeof(dp));
	for(ll i=1;i<=n;i++)
	{
		for(ll j=1;j<=w;j++)
		{
			if(j<v[i].first) dp[i][j]=dp[i-1][j];
			else dp[i][j]=max(dp[i-1][j],v[i].second+dp[i-1][j-v[i].first]);
			//cout<<dp[i][j]<<" ";
		}
		//cout<<endl;
	}
	cout<<dp[n][w];
}

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

Measured memory_bytes: 79232
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from functools import lru_cache
import bisect


class Scanner():
    def int():
        return int(sys.stdin.readline().rstrip())

    def string():
        return sys.stdin.readline().rstrip()

    def map_int():
        return [int(x) for x in Scanner.string().split()]

    def string_list(n):
        return [input() for i in range(n)]

    def int_list_list(n):
        return [Scanner.mapInt() for i in range(n)]

    def int_cols_list(n):
        return [int(input()) for i in range(n)]


class Math():
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    def roundUp(a, b):
        return -(-a // b)

    def toUpperMultiple(a, x):
        return Math.roundUp(a, x) * x

    def toLowerMultiple(a, x):
        return (a // x) * x

    def nearPow2(n):
        if n <= 0:
            return 0
        if n & (n - 1) == 0:
            return n
        ret = 1
        while(n > 0):
            ret <<= 1
            n >>= 1
        return ret

    def isPrime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True


MOD = int(1e09) + 7


def main():
    # sys.stdin = open("sample.txt")
    N = Scanner.int()
    A = Scanner.map_int()
    M = Counter(A)
    ans = 0
    for k, v in M.items():
        if k == v:
            continue
        if k < v:
            ans += v-k
        else:
            ans += v
    print(ans)
    return


if __name__ == "__main__":
    main()


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

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test() int t;cin>>t;for(int test=1;test<=t;test++)
#define pb push_back
#define nl cout<<"\n"
#define F first
#define S second
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const ll MOD = 1000000007;
ll mod( ll n, ll m=MOD ){ n%=m,n+=m,n%=m;return n; }

const int MAXN = 1e5+5;
const int LOGN = 21;
const ll INF = 1e14;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

template<class T1, class T2, class T3> void add( T1 &x, T2 y, T3 m = MOD )
{
    x += y;
    if( x >= m )
        x -= m;
}

template<class T1, class T2, class T3> void sub( T1 &x, T2 y, T3 m = MOD )
{
    x -= y;
    if( x < 0 )
        x += m;
}

int main() 
{
    fastio();

    ll x,y,a,b,c;
    cin>>x>>y>>a>>b>>c;
    vector<ll>p(a), q(b), r(c);
    for(int i=0;i<a;i++)
        cin>>p[i];
    for(int i=0;i<b;i++)
        cin>>q[i];
    for(int i=0;i<c;i++)
        cin>>r[i];

    sort(p.rbegin(),p.rend());
    sort(q.rbegin(),q.rend());
    sort(r.rbegin(),r.rend());

    int i = 0, j = 0, k = 0, red = 0, green = 0, ambiguous = 0;
    ll ans = 0;
    while( red < x || green < y )
    {
        ll red_apple = ( ( i < a && red < x ) ? p[i] : 0 );
        ll green_apple = ( ( j < b && green < y ) ? q[j] : 0 );
        ll other = ( k < c ? r[k] : 0 );

        // cout<<red<<" "<<green<<" "<<ambiguous,nl;
        // cout<<red_apple<<" "<<green_apple<<" "<<other,nl;nl;
        if( red + green + ambiguous >= x + y )
            break;

        if( red < x && red_apple >= green_apple && red_apple >= other )
        {
            ans += red_apple;
            i++;
            red++;
        }
        else if( green < y && green_apple >= red_apple && green_apple >= other )
        {
            ans += green_apple;
            j++;
            green++;
        }
        else if( red + green + ambiguous < x + y )
        {
            ans += other;
            k++;
            ambiguous++;
        }
    }
    cout<<ans,nl;

    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}


Measured memory_bytes: 2560
n = int(input())

for i in range(1, n+1):
    if i % 3 == 0:
        print(' ' + str(i), end='')
    else:
        x = i
        while x:
          if x % 10 == 3:
            print(" {}".format(i), end = "")
            break
          x //= 10
print()


Measured memory_bytes: 5876
//agc019_b.cpp
//Sat Jan  4 11:34:01 2020

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

int main(){
	string s;
	cin >> s;

	map<char, ll> mp;

	for (int i=0;i<s.length();i++){
		auto itr = mp.find(s[i]);
		if (itr != mp.end()){
			mp[s[i]]++;
		}else {
			mp[s[i]] = 1;
		}
	}

	ll ans = 0;
	for (auto itr = mp.begin();itr!=mp.end();itr++){
		ans+=(itr->second)*(itr->second-1)/2;
	}

	ll all = s.length()*(s.length()-1)/2+1;

	cout << all-ans<< endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 640
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools
from collections import deque

sys.setrecursionlimit(10**7)
inf = 10**20
mod = 10**9 + 7

DR = [1, -1, 0, 0]
DC = [0, 0, 1, -1]

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def solve(x):
    rot = x // (6 + 5)
    res = x % (6 + 5)
    ans = 2 * rot
    # rot:evenなら、つぎに当たるのは6
    if 0 < res <= 6:
        ans += 1
    if 6 < res:
        ans += 2
    return ans

def main():
    x = I()
    ans = solve(x)
    print(ans)
main()



Measured memory_bytes: 5460
"""
author : halo2halo
date : 30, Jan, 2020
"""

import sys

# import itertools
# import numpy as np

read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(10 ** 7)

H, W = map(int, readline().split())
a = read().decode('utf8').split()
print('#' * (W + 2))
for i in range(H):
    print('#' + a[i] + '#')
print('#' * (W + 2))


Measured memory_bytes: 3060
#include <iostream>
#include <fstream>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
using namespace std;

#define EPS 1e-9
#define INF MOD
#define MOD 1000000007LL
#define fir first
#define iss istringstream
#define sst stringstream
#define ite iterator
#define ll long long
#define mp make_pair
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<n;i++)
#define pi pair<int,int>
#define pb push_back
#define sec second
#define sh(i) (1LL<<i)
#define sz size()
#define vi vector<int>
#define vc vector
#define vl vector<ll>
#define vs vector<string>

int a[129];
char c;

int main(){
	while(cin>>c)a[c]++;
	cout<<min(a['K'],min(a['U'],min(a['P'],a['C'])))<<endl;
}

Measured memory_bytes: 0
import java.util.*;

public class Main {
  public static boolean check(int num) {
    int i;
    for(i = 1; i * i <= num; i++) {
      if(i * i == num) return true;
    }
    return false;
  }

  public static void main(String[] args) {
    int i, j, k, number_n, number_d, temp, count = 0;
    Scanner sc = new Scanner(System.in);
    number_n = Integer.parseInt(sc.next());
    number_d = Integer.parseInt(sc.next());
    int[][] point = new int[number_n][number_d];
    for(i = 0; i < number_n; i++) {
      for(j = 0; j < number_d; j++) {
        point[i][j] = Integer.parseInt(sc.next());
      }
    }
    for(i = 0; i < number_n; i++) {
      for(j = i + 1; j < number_n; j++) {
        temp = 0;
        for(k = 0; k < number_d; k++) {
          temp += (point[i][k] - point[j][k]) * (point[i][k] - point[j][k]);
        }
        if(check(temp)) count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 25172
function main(input) {
  input=input.trim();
  const a = parseInt(input.split(" ")[0], 10);
  const b = parseInt(input.split(" ")[1], 10);
  if(a%3!=0&&b%3!=0&&(a+b)%3!=0){
    console.log("Impossible");
  }else{
    console.log("Possible");
  }
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << endl
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1e6;
int n;
vector<pair<char, int>> L(MAX / 2 + 2), R(MAX / 2 + 2);
inline void merge(vector<pair<char, int>> &a, int left, int mid, int right) {
	int n1 = mid - left;
	int n2 = right - mid;
	rep(i, 0, n1) L[i] = a[left + i];
	rep(i, 0, n2) R[i] = a[mid + i];
	L[n1] = R[n2] = mp('Z', 1e9);
	int i = 0, j = 0;
	rep(k, left, right) {
		if(L[i].second <= R[j].second) {
			a[k] = L[i];
			++i;
		} else {
			a[k] = R[j];
			++j;
		}
	}
}
inline void mergeSort(vector<pair<char, int>> &a, int left, int right) {
	if(left + 1 < right) {
		int mid = (left + right) / 2;
		mergeSort(a, left, mid);
		mergeSort(a, mid, right);
		merge(a, left, mid, right);
	}
}
inline int partition(vector<pair<char, int>> &a, int p, int r) {
	int x = a[r].second;
	int i = p - 1;
	rep(j, p, r) {
		if(a[j].second <= x) {
			swap(a[++i], a[j]);
		}
	}
	swap(a[++i], a[r]);
	return i;
}
inline void quickSort(vector<pair<char, int>> &a, int p, int r) {
	if(p < r) {
		int q = partition(a, p, r);
		quickSort(a, p, q - 1);
		quickSort(a, q + 1, r);
	}
}
int main() {
	cin >> n;
	vector<pair<char, int>> v, mv; v.reserve(100001);
	char s;
	int x;
	rep(i, 0, n) {
		cin >> s >> x;
		v.eb(mp(s, x));
	}
	mv.assign(all(v));
	quickSort(v, 0, n - 1);
	mergeSort(mv, 0, n);
	P(v == mv ? "Stable" : "Not stable");
	rep(i, 0, n) {
		cout << v[i].first << ' ' << v[i].second << endl;
	}
	return 0;
}

Measured memory_bytes: 12240
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int h, w;
  cin >> h >> w;
  char a[h][w];
  rep (i, h) {
    rep (j, w) {
      cin >> a[i][j];
    }
  }
  rep (i, h + 2) {
    rep (j, w + 2) {
      if (i == 0 || i == h + 1 || j == 0 || j == w + 1) cout << "#";
      else cout << a[i - 1][j - 1];
    }
    cout << endl;
  }
  return 0;
}

Measured memory_bytes: 256
n,*l=map(int,open(0).read().split())
l.sort()
i=0
ans=[]
while l[i]<0:
  i+=1
  if i==n:
    break
minus=l[:i]
plus=l[i:]
if minus and plus:
  x=minus[0]
  for y in plus[:-1]:
    ans.append((x,y))
    x-=y
  minus[0]=x
  x=plus[-1]
  for y in minus:
    ans.append((x,y))
    x-=y
elif minus:
  x=minus[-1]
  for y in minus[:-1]:
    ans.append((x,y))
    x-=y
else:
  x=plus[0]
  for y in plus[1:-1]:
    ans.append((x,y))
    x-=y
  ans.append((plus[-1],x))
  x=plus[-1]-x
print(x)
for i,j in ans:
  print(i,j)

Measured memory_bytes: 20836
#include <iostream>
#include <string>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <cmath>
#include <time.h>
#include <stdio.h>
#define int long long
using namespace std;
int gcd(int x, int y) {
	if (y == 0)return x;
	return gcd(y, x%y);
}
int lcm(int x, int y) {
	return x / gcd(x, y)*y;
}
int mypow(int x, int y) {
	if (y == 0)return 1;
	if (y % 2)return mypow(x, y - 1)*x;
	else return mypow(x, y / 2)*mypow(x, y / 2);
}

/*ライブラリゾーン！！！！！！！！！！！！！！！*/
int n, p, dp[55][2], a[55];
signed main(){
	cin >> n >> p;
	dp[0][0] = 1;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < 2; j++) {
			if (a[i] % 2)dp[i][j] = dp[i - 1][0] + dp[i - 1][1];
			else dp[i][j] = dp[i - 1][j] + dp[i - 1][j];
		}
	}
	cout << dp[n][p] << endl;
	system("PAUSE");
	return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
 
int main(){
	string S;
	cin >> S;
	if (S == "SUN"){
		cout << 7;
	}
	else if (S == "MON"){
		cout << 6;
	}
	else if (S == "TUE"){
		cout << 5;
	}
	else if (S == "WED"){
		cout << 4;
	}
	else if (S == "THU"){
		cout << 3;
	}
	else if (S == "FRI"){
		cout << 2;
	}
	else if (S == "SAT"){
		cout << 1;
	}
	
	
}

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

using namespace std;

int main()
{
	int N,T;
	cin >> N >>T;
	map<int,int> way_list;
	
	for(size_t i = 0; i < N; i++)
	{
		int c,t;
		cin >> c >> t;
		
		if (t <= T) {
			way_list[c]=t;
		}
		
	}
	
	if (way_list.empty()) {
		cout << "TLE" << endl;
	}else{
		cout << way_list.begin()->first << endl;
	}
	 
	return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main
{
	public static void main(String[] args) throws NumberFormatException, IOException{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int hight[];
		hight = new int[10];
		for(int i = 0; i < 10; i++){
			hight[i] = Integer.parseInt(br.readLine());
		}
		Arrays.sort(hight);
		for(int i = 0; i < 3; i++){
			System.out.println(hight[9 - i]);
		}
	}
}

Measured memory_bytes: 24224
#!/usr/bin/env python
from fractions import gcd
def main():
    N = int(input())
    ans = len(str(N))
    for i in range(len(str(N)) // 2 + 1):
            for j in reversed(range(10**i, 10**(i+1))):
                if N % j == 0:
                    tmp = max(len(str(j)), len(str(N // j)))
                    if ans > tmp:
                        ans = tmp
                    break
    print(ans)

if __name__ == '__main__':
    main()

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

int main() {
  	int n, m; cin >> n >> m;
  	vector<vector<int>> G(n);
  	vector<int> dp(n,0), in(n,0);
    rep(i,m){
        int x, y; cin >> x >> y; x--; y--;
        G[x].push_back(y);
        in[y]++;
    }

    queue<int> que;
    rep(i,n) if(in[i] == 0) que.push(i);
    while(!que.empty()) {
        int v = que.front(); que.pop();
        for(int nv : G[v]){
      		dp[nv] = max(dp[nv], dp[v]+1);
            if(--in[nv] == 0) que.push(nv);
        }
    }

    int ans = 0;
    rep(i,n) ans = max(ans, dp[i]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9500
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <set>
#include <unordered_map>
using namespace std;

int main()
{
	long long a, b, x;
    cin >> a >> b >> x;
	if (a != 0) {
		cout << b / x - (a - 1) / x << endl;
	}
	else {
		cout << b / x + 1 << endl;
	}
}

Measured memory_bytes: 256
def main():
    n, m = map(int, input().split())
    like_count = [0 for _ in range(m + 1)]

    # time O(NM)
    for _ in range(n):
        tmp = list(map(int, input().split()))
        like_list = tmp[1:]
        for like in like_list:
            like_count[like] += 1

    # time O(M)
    count = 0
    for value in like_count:
        if value == n:
            count += 1

    print(count)


main()


Measured memory_bytes: 3060
#include <stdio.h>

int selectionSort(int A[],int N)
{
  int i,j,minj,a,b,count=0; 

  for(i=0;i<=N-1;i++){
    minj=i;
    for(j=i;j<=N-1;j++){
      if(A[j]<A[minj]){
	minj=j;
      }
    }
    if(A[i]>A[minj]) count++;
    a=A[i];
    b=A[minj];
    A[i]=b;
    A[minj]=a;
  }
  return count;
}


int main(){
  int i,j,N,count;
   scanf("%d",&N);
 
  int A[N];
  for(i=0; i<N ;i++){
    scanf("%d",&A[i]);
  }

  count=selectionSort(A,N);

  for(j=0;j<N;j++){
    if(j>0) printf(" ");
    printf("%d",A[j]);
  }
  printf("\n");
  printf("%d\n",count);

  
  return 0;
}



Measured memory_bytes: 2104
// 2020-07-11 21:09:47
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = long long;
using ld = long double;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

ll rec(ll a) {
  if(a == 0) return 0;
  return 1 + rec(a % __builtin_popcount(a));
}
void answer() {
  ll n; string x;
  cin >> n >> x;
  ll orig = 0;
  rep(i, n) if(x[i] == '1') orig++;
  map<ll, ll> mp[2];
  ll tot[2];
  string rx = x;
  reverse(ALL(rx));
  rep(k, 2) {
    ll mod = orig;
    if(k == 0) mod--;
    else mod++;
    if(mod <= 0) continue;
    tot[k] = 0;
    ll cur = 1 % mod;
    rep(i, n) {
      if(i) cur = (2 * cur) % mod;
      mp[k][i] = cur;
      if(rx[i] == '1') {
        tot[k] += mp[k][i];
        tot[k] %= mod;
      }
    }
  }
  vector<ll> res;
  rep(xi, n) {
    int i = n - xi - 1;
    int d = x[xi] - '0';
    if(d == 0) {
      ll mod = orig + 1;
      ll st = (tot[1] + mp[1][i]) % mod;
      res.emplace_back(rec(st) + 1);
    } else {
      ll mod = orig - 1;
      if(mod == 0) {
        res.emplace_back(0);
        continue;
      }
      ll st = (mod + tot[0] - mp[0][i]) % mod;
      if(st == 0) {
        res.emplace_back(1);
        continue;
      }
      res.emplace_back(rec(st) + 1);
    }
  }
  for(const auto& a : res) cout << a << '\n';
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}


Measured memory_bytes: 30716
n, q = [int(_) for _ in input().split()]
w = {}
add = {}
seen = {}
ans_d = {}
for i in range(1, n + 1):
    w[i] = []
    seen[i] = 0
    add[i] = 0
    ans_d[i] = 0
for i in range(n - 1):
    a, b = [int(_) for _ in input().split()]
    w[a].append(b)
    w[b].append(a)
for i in range(q):
    p, x = [int(_) for _ in input().split()]
    add[p] += x

que = [1]
ans_d[1] = add[1]
seen[1] = 1
while len(que) != 0:
    v = que.pop()
    for node in w[v]:
        if seen[node] == 0:
            ans_d[node] = ans_d[v] + add[node]
            que.append(node)
            seen[node] = 1

ans_l = []
for i in range(1, n + 1):
    ans_l.append(str(ans_d[i]))
print(' '.join(ans_l))

Measured memory_bytes: 126620
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;
const int MOD = INF+7;
const ll LINF = 1e18;
#define rep(i,N) for(int (i)=0;(i)<(N);++(i))
#define rrep(i,N) for(int (i)=(N-1);(i)>0;--i)
#define FOR(i,j,N) for(int (i)=(j);(i)<(N);++(i))
#define put(n) cout<<(n)<<endl;
#define all(v) v.begin(),v.end()
#define MP make_pair
#define pb(n) push_back(n)


int main(){
    int D;
    cin >> D;
    if(D == 25) cout <<"Christmas" << endl;
    if(D == 24) cout <<"Christmas Eve" << endl;
    if(D == 23) cout << "Christmas Eve Eve"<< endl;
    if(D == 22) cout << "Christmas Eve Eve Eve"<< endl;
}

Measured memory_bytes: 256
import copy

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

S=[]
X=[]
for i in range(N):
	if i==0:
		S.append(A[i])
		X.append(A[i])
	else:
		S.append(S[i-1]+A[i])
		X.append(X[i-1]^A[i])


ans=0


for i in range(N):
	ok=copy.deepcopy(i)
	ng=N

	while ng!=ok+1:
		m=(ok+ng)/2
		if i==0:
			if S[m]==X[m]:
				ok=m
			else:
				ng=m
		else:
			if S[m]-S[i-1]==X[m]^X[i-1]:
				ok=m
			else:
				ng=m
	ans+=(ok-i)+1

print ans


Measured memory_bytes: 71048