akhauriyash/Code-Regression huggingface dataset:
N,M=map(int,input().split())
A=[]
for i in range(M):
  a=[int(i)-1 for i in input().split()]
  A.append(a[1:])
P=[int(i) for i in input().split()]
ans=0
for i in range(1<<N):
  F=True
  #print(i)
  for a in range(M):
    r=0
    for s in A[a]:
      r+=(((1<<s)&(i))>>s)
    #print(i,r)
    if P[a]!=r%2:
      F=False
      break
  if F:
    ans+=1
print(ans)      

Measured memory_bytes: 39664
"use strict";
function Main(input) {
    let S = input.split("\n")[0].split(/\s/)[0] + 'X';
    let ans = 0, l = 0, p = -1, q = -1;
    for (let n = 0; n < S.length; n++) {
        switch (S.charAt(n)) {
        case 'A': 
        case 'C': 
        case 'T': 
        case 'G': 
            if (p < 0) p = n;
            l += 1; 
        break;
        default: 
            if (l > ans) {
                ans = l;
                q = p;
            }
            l = 0;
            p = -1;
        }
    }
    console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

int main(void) {
  bool cards[4][13];
  for (int i=0; i<4; i++) {
    for (int j=0; j<13; j++) {
      cards[i][j] = false;
    }
  }  
  int n;
  cin >> n;
  char design;
  int rank;
  while (n--) {
    cin >> design >> rank;
    switch (design) {
    case 'S':
      cards[0][rank-1] = true;
      break;
    case 'H':
      cards[1][rank-1] = true;
      break;
    case 'C':
      cards[2][rank-1] = true;
      break;
    case 'D':
      cards[3][rank-1] = true;
      break;
    default:
      break;
    }
  }
  char ans;
  for (int i=0; i<4; i++) {
    for (int j=0; j<13; j++) {
      if (cards[i][j]==false) {
        switch (i) {
        case 0:
          ans = 'S';
          break;
        case 1:
          ans = 'H';
          break;
        case 2:
          ans = 'C';
          break;
        case 3:
          ans = 'D';
          break;
        default:
          break;
        }
        cout << ans << " " << j+1 << endl;
      }
    }
  }
  return 0;
}

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;

using namespace std;

int main()
{

    int r=0;

    int m_r = 0;


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

        char c;

        cin >>c;

        if(c=='R'){
            r++;
        }
        else{


            m_r = max(r,m_r);

            r=0;
        }
    }


    m_r = max(r,m_r);


    cout << m_r << endl;

    return 0;
}

Measured memory_bytes: 3580
#include "bits/stdc++.h"
typedef long long ll;
using namespace std;

int main() {
    int n, x;
    cin >> n >> x;
    vector<int> m(n);
    for (int i = 0; i < n; ++i) cin >> m[i];

    int m_sum = 0;
    int m_min = INT_MAX;
    for (int i = 0; i < n; ++i) {
        m_sum += m[i];
        m_min = min(m_min, m[i]);
    }

    int remain = x - m_sum;
    int ans = n + remain / m_min;
    cout << ans;

    return 0;
}


Measured memory_bytes: 256
N = int(input())
a = [int(i) for i in input().split()]

total = 0
for i in range(N):
    total += a[i]
ave = total / N

small = abs(a[0] - ave)
place = 0
for i in range(1,N):
    if abs(a[i] - ave) < small:
        small = abs(a[i] - ave)
        place = i

print(place)


Measured memory_bytes: 3064
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int num,gen;
	scanf("%d%d",&num,&gen);
	vector<int>v;
	for(int i=0;i<num;i++)
	{
		int z;
		scanf("%d",&z);
		v.push_back(z);
	}
	ll maxi=0;
	int rr=-1;
	for(int i=0;i<num-1;i++)
	{
		if(maxi<v[i]+v[i+1])
		{
			maxi=v[i]+v[i+1];
			rr=i+1;
		}
	}
	if(maxi<gen)
	{
		printf("Impossible\n");
		return 0;
	}
	printf("Possible\n");
	for(int i=1;i<rr;i++)printf("%d\n",i);
	for(int i=num-1;i>=rr;i--)printf("%d\n",i);
}

Measured memory_bytes: 1272
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}


struct FastIO{
  FastIO(){
    cin.tie(0);
    ios::sync_with_stdio(0);
  }
}fastio_beet;

//INSERT ABOVE HERE
signed main(){
  Int n;
  cin>>n;
  string s;
  cin>>s;

  set<string> res,tmp;
  tmp.emplace("");
  for(char c:s){
    set<string> nxt;
    for(string t:tmp){
      if(t.size()==2u) res.emplace(t+c);
      else nxt.emplace(t+c);
      nxt.emplace(t);
    }
    tmp=nxt;
  }

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


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <cctype>
#include <functional>
#include <cmath>
using namespace std;
using ll = long long;

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

int main(){
    int n;
    cin >> n;
    int t,x,y;
    int tmp=0,tmpx=0,tmpy=0;
    rep(i,n){
        cin >> t >> x >> y;
        int d = abs(x-tmpx) + abs(y-tmpy);
        if(t-tmp>d){
            if((t-tmp-d)%2!=0){
                cout << "No" << endl;
                return 0;
            }
        }else if(t-tmp<d){
            cout << "No" << endl;
            return 0;
        }
        tmp = t;
        tmpx = x;
        tmpy = y;
    }
    cout << "Yes" << endl;
    return 0;
}

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

int main() {
  int N;
  cin>>N;
 vector<int>A(N);
  for(int i=0;i<N;i++){
  cin>>A.at(i);
  }
 sort(A.begin(),A.end());
 int S=0;
 for(int i=0;i<N;i++){
 S=S+A.at(i);
 }
  if(2*A.at(N-1)<S){
  cout<<"Yes"<<endl;
  }
  else{
  cout<<"No"<<endl;
  }
}

Measured memory_bytes: 256
N, X, Y = map(int, input().split())


distance = [0] * (N)
for i in range(1, N + 1):
  for j in range(i + 1, N + 1):
    d = j - i
    b = abs(j - Y) + 1 + abs(X - i)
    distance[min(b, d)] += 1
for i in distance[1:]:
  print(i)

Measured memory_bytes: 3444
//075 C - Bridge 2017/10/14

#include <bits/stdc++.h>
#define rep(i ,n) for(int i=0;i<(int)(n);++i)
using namespace std;
typedef long long int int64;
typedef unsigned long long uint64;

int n;
bool Graph[50][50]={false};
bool visited[50]={false};

void dfs( int a ){
    visited[a] = true;
    rep(i,n){
        if(!Graph[i][a] || !Graph[a][i]) continue;
        if(visited[i]) continue;
        dfs(i);
    }
}

int main(){
    int m; cin >> n >> m;
    int a[m] , b[m];
    rep(i , m){
        cin >> a[i] >> b[i];
        Graph[a[i]-1][b[i]-1] = true;
        Graph[b[i]-1][a[i]-1] = true;
    }
    int ans = 0;
    rep(i ,m){ //各辺が橋かどうか
        Graph[a[i]-1][b[i]-1] = false; //(a[i]-1,b[i]-1)が橋かどうか調べる
        Graph[b[i]-1][a[i]-1] = false;

        rep(j ,n) visited[j] = false;

        dfs(0);

        bool bridge = false;
    
        rep(j ,n) {
            if(!visited[j]) { bridge = true; break; }
        }
        if(bridge) ++ans;
        Graph[a[i]-1][b[i]-1] = true; //辺を元に戻して繰り返す
        Graph[b[i]-1][a[i]-1] = true;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<map>
#include<set>
#include<bitset>
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<chrono>
#include<stack>
#include<fstream>
#include<list>
#include<math.h>
#define REP(i,x,y) for(ll i=x;i<=y;i++)
#define SIZE(a) ll(a.size())
#define vll vector<ll> 
#define MEMSET(a, n, m) for(ll i=0;i<=n;i++) a[i] = m
#define BIT(n) (ll(1)<<n)
#define UNIQUE(v) v.erase(unique(v.begin(),v.end()),v.end()) 
#define UNIQUE_ARRAY(a,x) unique(a + 1, a + x + 1) - a - 1
#define SORT(a,n) sort(a+1,a+n+1)
#define SORT_O(a,n,order) sort(a+1,a+n+1,order)
#define PER(i,y,x) for(ll i=y;i>=x;i--)
typedef long long ll;
using namespace std;
double const PI = 3.1415926535;

struct edge
{
	long long to; long long cost;
	bool operator<(const edge& rhs) const {
		return cost > rhs.cost;
	}
};

ll const MAX = 2e5 + 5;
ll a[MAX], b[MAX];

int main(){
	ll flag = 1;
	ll n;
	cin >> n;
	REP(i, 1, n) {
		cin >> a[i] >> b[i];
		if (a[i] != b[i]) {
			flag = 0;
		}
	}
	if (flag) {
		cout << 0 << endl;
		return 0;
	}
	ll ans = 0;
	ll b_min = 1e18;
	REP(i, 1, n) {
		if (a[i] > b[i]) {
			b_min = min(b_min, b[i]);
		}
		ans += b[i];
	}
	cout << ans - b_min << endl;
}

Measured memory_bytes: 512
#include <iostream>

using namespace std;

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

	int num = N % 10;
	if (num == 3) {
		cout << "bon";
	}
	else if (num == 0 | num == 1 | num == 6 | num == 8) {
		cout << "pon";
	} else {
		cout << "hon";
	}
	return 0;
}

Measured memory_bytes: 3048
#include <bits/stdc++.h>
typedef long long ll;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP2(i, a, b) for(int i = a;i <= b;i++)
#define REPR(i, a, b) for(int i = a; i >= b; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define MOD 1000000007
#define PI 3.14159265358979323846
#define vi vector<int>
#define vll vector<ll>
#define vi2 vector<vector<int>>
#define eb emplace_back
#define fi first
#define se second
#define ALL(v) v.begin(), v.end()
#define sz(x) int(x.size())
using namespace std;
using P = pair<ll,ll>;
const int dx[]{0, 1, 0, -1, -1, -1, 1, 1}, dy[]{1, 0, -1, 0, -1, 1, -1, 1};
#define INT(name) int name;cin >> name;
#define VEC(type,name,n) vector<type> name(n);REP(i,n) cin >> name[i];

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()
{
  INT(N);
  VEC(ll,A,N);
  ll cnt = 0;
  REP(i,N){
    REP(j,i){
      REP(k,j){
        if(A[i]!=A[j]&&A[j]!=A[k]&&A[i]!=A[k]){
          if(A[i]+A[j]>A[k]&&A[j]+A[k]>A[i]&&A[k]+A[i]>A[j]){
            cnt++;
            // cout << i+1 << " " << j+1 <<" " << k+1 << endl;
          }
        }
      }
    }
  }

  cout << cnt << endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <fstream>
#include <sstream>
#include <iomanip>
#define ll long long

using namespace std;

long long MOD = 1000000007;

int main(){
    int x;
    cin >> x;
    if(x>=30){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}

Measured memory_bytes: 3628
#include <stdio.h>
int main(void){
    int n;
    char s[100+5];
    scanf("%d", &n);
    scanf("%s", s);
    int ans=0, x=0;
    for(int i=0; i<n; i++){
        if(s[i]=='I')x++;
        else x--;
        if(x>ans)ans=x;
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
#include <math.h>
#include <float.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = 0; i <= (n); i++)
using namespace std;
typedef long long ll;
 
const ll INF = 1LL<<62;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
// 多次元 vector 生成
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
  return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
const int MOD = 1000000007;

int main(){
    ll N,M; cin >> N >> M;

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

Measured memory_bytes: 3592
#include <iostream>
#include <sstream>

struct card
{
    char type;
    int rank;
    
    card() {}
};

int main()
{
    int count;
    std::string temp;
    std::getline(std::cin, temp, '\n');
    count = std::stoi(temp);
    
    card* cards = new card[count];
    
    for (int n = 0; n < count; ++n)
    {
        std::string line;
        std::getline(std::cin, line, '\n');
        
        std::string item;
        std::stringstream ss(line);
        bool tp = true;
        card c;
        while (std::getline(ss, item, ' '))
        {
            if (tp)
                c.type = item.at(0);
            else
                c.rank = std::stoi(item);
            tp = false;
        }
        
        cards[n] = c;
    }
    
    const char* table = new char[4]{'S', 'H', 'C', 'D'};
    
    for (int t = 0; t < 4; ++t)
    {
        for (int rank = 1; rank <= 13; ++rank)
        {
            char type = table[t];
            bool matched = false;
            
            for (int n = 0; n < count; ++n)
            {
                const card& data = cards[n];
                
                if (data.type == type && data.rank == rank)
                    matched = true;
            }
            
            if (!matched)
                std::cout << type << " " << rank << std::endl;
        }
    }
    
    delete[] cards;
    
    return 0;
}


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

#define x first
#define y second

using namespace std;

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> ii;
typedef pair<ll,ll> pll;

int dp[2][101][101][101];
int H,W;
string bd[100];
int ei,ej;
int cs[2][101][101];

int main() {
	cin >> H >> W;
	for (int i=0;i<H;i++) cin >> bd[i];
	for (int i=0;i<H;i++) for (int j=0;j<W;j++) {
		if (bd[i][j]=='E') {
		ei=i;
		ej=j;
		}
		else if (bd[i][j]=='o') {
			cs[0][i][j+1]++;
			cs[1][i+1][j]++;
		}
		cs[0][i][j+1]+=cs[0][i][j];
		cs[1][i+1][j]+=cs[1][i][j];
	}
	int p=0;
	for (int i=H;i>=0;i--,p=1-p) for (int j=H-i;j>=0;j--)
		for (int k=W;k>=0;k--) for (int l=W-k;l>=0;l--) {
			if (i+j==H || k+l==W) {
				dp[p][j][k][l]=0;
				continue;
			}
			
			int &r=dp[p][j][k][l];
			int t=0;
			if (ei+i+1<H-j) {
				int lb=max(k,ej-l),ub=min(W-l,ej+k+1);
				if (lb<ub) t+=cs[0][ei+i+1][ub]-cs[0][ei+i+1][lb];
			}
			t+=dp[1-p][j][k][l];
			r=t;

			t=0;
			if (ei-j-1>=i) {
				int lb=max(k,ej-l),ub=min(W-l,ej+k+1);
				if (lb<ub) t+=cs[0][ei-j-1][ub]-cs[0][ei-j-1][lb];
			}
			t+=dp[p][j+1][k][l];
			if (t>r) r=t;

			t=0;
			if (ej+k+1<W-l) {
				int lb=max(i,ei-j),ub=min(H-j,ei+i+1);
				if (lb<ub) t+=cs[1][ub][ej+k+1]-cs[1][lb][ej+k+1];
			}
			t+=dp[p][j][k+1][l];
			if (t>r) r=t;

			t=0;
			if (ej-l-1>=k) {
				int lb=max(i,ei-j),ub=min(H-j,ei+i+1);
				if (lb<ub) t+=cs[1][ub][ej-l-1]-cs[1][lb][ej-l-1];
			}
			t+=dp[p][j][k][l+1];
			if (t>r) r=t;

		}

	cout << dp[1-p][0][0][0] << endl;
}

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


int main() {

long N,M;
cin>>N>>M;
vector<int> d;

for(int i=1;i*i<=M;i++){
  if(M%i==0){
    d.push_back(i);
    if(i*i!=M) d.push_back(M/i);
  }
}

sort(d.begin(),d.end());


for(int i=0;i<d.size();i++){
  if(d[i]>=N){
    cout<<M/d[i]<<endl;
    return 0;
  }
}

}


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

#define FOR(i, a, b) for (int i = a; i < (int) b; i++) 
#define F0R(i, a) FOR (i, 0, a)
#define GO(to, a) for (auto to : a)

#define f first
#define s second
#define eb emplace_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<vi> vvi;
typedef vector<vpii> vvpii;

const int dr[] = {+1, -1, +0, +0, +1, -1, +1, -1};
const int dc[] = {+0, +0, +1, -1, +1, -1, -1, +1};

const int m[] = {+31, +29, +31, +30, +31, +30, +31, +31, +30, +31, +30, +31};

int main () {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int a, b;
	cin >> a >> b;
	cout << a / b + (a % b != 0) << '\n';
	return 0;
}

Measured memory_bytes: 256
#coding: euc-jp
class Main
  def self.main
    n, q = read1
    s = read2
    d = Array.new(n, 0)
    pos = 0
    (n - 1).times do |pos|
      d[pos + 1] = d[pos] + (s[pos, 2] == 'AC' ? 1 : 0)
    end
    q.times do
      l, r = read1
      puts d[r - 1] - d[l - 1]
    end
  end

  def self.read1
    gets.chomp.split.map(&:to_i)
  end
  def self.read2
    gets.chomp
  end
end

Main.main


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

int main() {
  string s;cin>>s;
  while (s.size()>0) {
    s.pop_back();
    int n=s.size();
    if (s.size()%2!=0) continue;
    bool flg=true;
    rep(i,n/2) if (s[i]!=s[i+n/2]) {
      flg=false;
      break;
    }
    if (flg) {
      cout << s.size();
      return 0;
    }
    
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rrep(i, n) for(int i = (n-1); i >= 0; i--)
using namespace std;
typedef long long ll;
const int MOD = 1000000007;
const ll INF = 1LL<<62;
const int IINF = 1000000000;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using Graph = vector<vector<int>>;

typedef pair<int, int> P;

int main(){
    string N; cin >> N;
    int K; cin >> K;
    int n = N.size();

    vector<vector<vector<ll>>> dp(n+1, vector<vector<ll>>(2, vector<ll>(105,0)));
    dp[0][0][0] = 1;

    rep(i,n){
        rep(j,5){
            rep(k,10){
                if (k != 0){
                    dp[i+1][1][j+1] += dp[i][1][j];
                }
                else{
                    dp[i+1][1][j] += dp[i][1][j];
                }
            }

            int num = N[i]-'0';

            rep(k,num){
                if (k != 0){
                    dp[i+1][1][j+1] += dp[i][0][j];
                }
                else{
                    dp[i+1][1][j] += dp[i][0][j];
                }
            }
            if (num != 0) dp[i+1][0][j+1] += dp[i][0][j];
            else dp[i+1][0][j] += dp[i][0][j];
        }
    }
    ll ans = 0;
    ans += dp[n][0][K];
    ans += dp[n][1][K];

    cout << ans << endl;

}

Measured memory_bytes: 3796
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC optimize ("-ffloat-store")  
#pragma GCC optimize ("-fno-defer-pop")
#define all(a) a.begin(),a.end()
#define ll long long int
#define ld long double
ll power(ll a,ll b,ll m){ if(b==0) return 1; if(b==1) return a%m; ll t=power(a,b/2,m)%m; t=(t*t)%m; if(b&1) t=((t%m)*(a%m))%m; return t;}
ll modInverse(ll a, ll m) { return power(a, m-2, m); }
#define ps push_back
#define fs first
#define sc second
#define N 3000005
#define endl "\n"
#define mod 1000000007
int main(){
	
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll i,j,k,l,n;
	cin>>n;
	k=0;
	ll ar[n+1];
	for(i=1;i<=n;i++){
		cin>>ar[i];
		k+=ar[i];
	}
		
	ll mn=1e18; l=0;
	for(i=1;i<n;i++){
		l+=ar[i];
		mn=min(mn,abs(k-2*l));
	}
	cout<<mn;
	return 0;
}


Measured memory_bytes: 256
n, k = map(int, input().split())
L = [0] * n
for i in range(k):
    d = int(input())
    tmp = list(map(int, input().split()))

    for j in range(len(tmp)):
        if L[tmp[j] - 1] == 0:
            L[tmp[j] - 1] = 1

print(L.count(0))

Measured memory_bytes: 9204
#include<bits/stdc++.h>
//cervello|Phoenix
using namespace std;
#define ll long long int
#define eb emplace_back
#define mk make_pair
#define all(x) x.begin(),x.end()
#define mod 1000000007

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  ll n; cin>>n;
  ll ans=0;
  for(int i=1;i<=n;i++){
    for(int j=i;j<=n;j+=i)
      ans+=j;
  }
  cout<<ans<<"\n";
  
  return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)

using namespace std;

typedef pair<int,int>P;

struct edge{
    int to;
    int cost;
};

const int MAX_N = 100010;

int a[MAX_N];
int n;
int d[MAX_N];
vector<edge> G[MAX_N];

void dijkstra(int s)
{
	priority_queue<P,vector<P>,greater<P> > que;
	d[s] = 0;
	que.push(P(0,s));
	while(!que.empty()){
		P p = que.top();
		que.pop();
		int v = p.second;
		if(d[v] < p.first) continue;
		vector<edge>::iterator it = G[v].begin();
		rep(i,G[v].size()){
			if(d[G[v][i].to] > d[v] + G[v][i].cost){
				d[G[v][i].to] = d[v] + G[v][i].cost;
				que.push(P(d[G[v][i].to],G[v][i].to));
			}
		}
	}
}

int main()
{
	scanf("%d",&n);
	rep(i,n){
		scanf("%d",&a[i]);
        if(a[i] == 0){
            rep(j,6){
                G[i].push_back((edge){i+j+1,1});
            }
        }else{
            G[i].push_back((edge){i+a[i],0});
        }
	}
    rep(i,n+6){
        d[i] = INF;
    }
    dijkstra(0);
    int mn = INF;
    rep(i,5){
        mn = min(mn,d[n-1+i]);
    }
    printf("%d\n",mn);
	return 0;
}

Measured memory_bytes: 11056
n=int(input())
S=[]

for _ in range(n):
    s=input()
    vari=len(set(s))
    S.append([vari,s])

S.sort()   # 文字種類が少ない順にソート。
count={}   # 各文字の個数をカウント
elem=set(S[0][1])

for i in elem:
    count[i]=S[0][1].count(i)

for i in range(n-1):
    for j in elem:
        count[j]=min(count[j],S[i+1][1].count(j))

a=""
for i in count:
    a+=i*count[i]
a=sorted(list(a))
ans=""
for i in a:
    ans+=i
print(ans)


Measured memory_bytes: 3064
n=int(input())
h=list(map(int,input().split()))
dp=[0 for i in range(n)]
dp[1]=abs(h[1]-h[0])
for i in range(2,n):
    dp[i]=min(dp[i-1]+abs(h[i]-h[i-1]),dp[i-2]+abs(h[i]-h[i-2]))
print(dp[n-1])

Measured memory_bytes: 20620
n = int(input())
w = list(map(int, input().split()))
l = []
for t in range(1, n):
    a = 0
    b = 0
    for i in range(t):
        a = a + w[i]
    for i in range(t, n):
        b = b + w[i]
    if a > b:
        l.append(a - b)
    else: l.append(b - a)
print(min(l))


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,a,b,ans;
    string s1,s2,s3;
    cin>>s1>>s2;
    cin>>a>>b;
    cin>>s3;
    if(s3==s1)
    {
        ans=a-1;
        cout<<ans<<" "<<b<<endl;
    }
    else
    {
        ans=b-1;
        cout<<a<<" "<<ans<<endl;
    }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		while (n-- > 0) {
			float xa = sc.nextFloat();
			float ya = sc.nextFloat();

			float xb = sc.nextFloat();
			float yb = sc.nextFloat();

			float xc = sc.nextFloat();
			float yc = sc.nextFloat();

			float xd = sc.nextFloat();
			float yd = sc.nextFloat();

			float katamukiab = (yb-ya) / (xb -xa);
			float katamukicd = (yd-yc) / (xd -xc);

			if (katamukiab == katamukicd) {
				System.out.println("YES");
			} else {
				System.out.println("NO");
			}
		}
	}

}

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

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define watch(x);       cout << "\n" <<  #x << " is: " << x << "\n";
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd(a,b)
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (int i = a; i <= b; i++)
#define rloop(i,a,b)    for (int i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n;
        cin>>n;
        ll a[n];
        loop(i,0,n-1) cin>>a[i];
        sort(a,a+n);
        loop(i,0,n-2) a[i]*=2;
        ll x=(n-2)/2;
        ll ans=a[n-1];
        ll i=0;
        while(x>0)
        {
            ans+=a[n-i-2];
            i++;
            x--;
        }
        if(n&1) ans+=(a[n-i-2]/2);
        cout<<ans;

    }
    return 0;
}


Measured memory_bytes: 5168
#include <iostream>
using namespace std;
typedef long long ll;
ll a,b,ans;
int main(void){
    cin>>a>>b;
    ll cnt=1;
    for(ll i=b+1;i<=a;i++){
        ans+=a/i*cnt;
        ans+=max(0LL,a%i-(b-1));
        cnt++;
        //cout<<ans<<endl;
    }
    if(b==0)cout<<a*a<<endl;
    else cout<<ans<<endl;
}


Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */

// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */

using namespace std;

/* ---------- Type Abbreviation ---------- */

template <typename T>
using PQ = priority_queue<T>;
template <typename T>
using GPQ = priority_queue<T, vector<T>, greater<T>>;

using ll = long long;

#define fst first
#define snd second
#define mp make_pair
#define mt make_tuple

/* ---------- conversion ---------- */

#define INT(c) static_cast<int>(c)
#define CHAR(n) static_cast<char>(n)
#define LL(n) static_cast<ll>(n)
#define DOUBLE(n) static_cast<double>(n)

/* ---------- container ---------- */

#define ALL(v) (v).begin(), (v).end()
#define SIZE(v) (LL((v).size()))

#define FIND(v, k) (v).find(k) != (v).end()
#define VFIND(v, k) find(ALL(v), k) != (v).end()

#define gsort(b, e) sort(b, e, greater<decltype(*b)>())

/* ----------- debug ---------- */

template <class T>
ostream& operator<<(ostream& os, vector<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class T>
ostream& operator<<(ostream& os, set<T> v) {
    os << "[";
    for (auto vv : v)
        os << vv << ",";
    return os << "]";
}

template <class L, class R>
ostream& operator<<(ostream& os, pair<L, R> p) {
    return os << "(" << p.fst << "," << p.snd << ")";
}

/* ---------- Constants ---------- */

const ll MOD = 1e9 + 7;
// const int INF = 1 << 25;
// const ll INF = 1LL << 50;
// const double PI = acos(-1);
// const double EPS = 1e-10;
// mt19937 mert(LL(time(0)));

/* ---------- Short Functions ---------- */

template <typename T>
T sq(T a) {
    return a * a;
}

template <typename T>
T gcd(T a, T b) {
    if (a > b) return gcd(b, a);
    return a == 0 ? b : gcd(b % a, a);
}

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b % MOD;
    if (n % 2 == 0) {
        return mypow(b * b % MOD, n / 2);
    } else {
        return mypow(b, n - 1) * b % MOD;
    }
}

ll pcnt(ll b) {
    return __builtin_popcountll(b);
}

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */

int main() {
    int N, K;
    string S;
    cin >> N >> S;
    K = S.length();

    ll dp[N + 1];
    fill(dp, dp + N + 1, 0);
    dp[0] = 1;
    // dp[i] = i文字打たれているパターン数

    for (int q = 0; q < N; ++q) {
        ll ndp[N + 1];
        fill(ndp, ndp + N + 1, 0);

        for (int i = 0; i < N; ++i) {
            ndp[i + 1] += dp[i] * 2;
            ndp[max(0, i - 1)] += dp[i];
        }

        for (int i = 0; i <= N; ++i) {
            dp[i] = ndp[i] % MOD;
        }
    }

    cout << dp[K] * mypow(mypow(2LL, K), MOD - 2) % MOD << endl;

    return 0;
}


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

int main()
{
    int n, ans = 0;
    cin >> n;
    for (int i = 1;i <= n; i++) {
        if (to_string(i).length() % 2 != 0) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	string s;
	cin>>s;
	int a[26];
	for(int i=0;i<26;i++)a[i]=0;
	for(int j=0;j<s.size();j++){
		a[s[j]-'a']++;
	}
	for(int i=0;i<26;i++){
		if(a[i]==0){
			char c='a'+i;
			cout<<c<<endl;
			return 0;
		}
	}
	cout<<"None"<<endl;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<map>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main(){
    int n,t;
    cin>>n>>t;
    int data[n][2];
    rep(i,n) rep(j,2) cin>>data[i][j];
    int cost=1001;
    rep(i,n){
        if(data[i][0]<cost&&data[i][1]<=t){
            cost=data[i][0];
        }
    }
    if(cost==1001) cout<<"TLE"<<endl;
    else cout<<cost<<endl;
}

Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() (int, []int) {
	n := readInt()
	return n, readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func eprintln(args ...interface{}) (int, error) {
	return fmt.Fprintln(os.Stderr, args...)
}

func eprintf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(os.Stderr, f, args...)
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int

// -----------------------------------------------------------------------------

func main() {
	defer stdout.Flush()
	n := readInt()
	h := make([]int, n)
	for i := range h {
		h[i] = readInt()
	}

	count := 0
	max := 0
	for _, v := range h {
		if max <= v {
			count++
			max = v
		}
	}
	println(count)
}

// -----------------------------------------------------------------------------


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

#define REPR(i,n) for(int i=(n); i >= 0; --i)
#define FOR(i, m, n) for(int i = (m); i < (n); ++i)
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define ALL(a)  (a).begin(),(a).end()

template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return true; } return false; }
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return true; } return false; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}
typedef long long ll;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}


int main() {
    ll N,M;
    cin >> N >> M;
    ll score = 0;
    if (N*2<=M) {
        score+=N;
        M-=N*2;
        score+=M/4;
        cout << score << endl;
        return 0;
    }
    cout << M/2 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
using namespace std;
int main() {
  int N,K;
  cin >> N >> K;
  int susumi = K-1;
  int cnt = 0;
  for (int i=0;;i++) {
    if (K+susumi*i >= N) {
      cnt = i+1;
      break;
    }
  }
  cout << cnt << endl;
}
  

Measured memory_bytes: 256
//B - Two Colors Card Game: 
//Assunto: 
#include <bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define loop(i, a, b) for(int i = a; i < b; i++)
#define loopBack(i, a, b) for(int i = a; i >= b; i--)
#define INF INT_MAX
#define LINF LLONG_MAX
#define DINF DBL_MAX
#define MAX 100005
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    int b, r, maxi = 0;
    string x;
    map<string, int> timesB, timesR;
    cin >> b;
    loop(i, 0, b) {
        cin >> x;
        timesB[x]++;
    }
    cin >> r;
    loop(i, 0, r) {
        cin >> x;
        timesR[x]++;
    }
    for(auto x : timesB) maxi = max(maxi, x.se - timesR[x.fi]);
    cout << maxi << "\n";
}

Measured memory_bytes: 256
import numpy as np
w,h,n=map(int,raw_input().split())
mp = np.zeros((w,h))
for i in range(n):
  xi,yi,ai=map(int,raw_input().split())
  if ai==1: # x < xi
    mp[:xi,:] = 1
  elif ai==2: # x > xi
    mp[xi:,:] = 1
  elif ai==3: # y < yi
    mp[:,:yi] = 1
  elif ai==4: # y > yi
    mp[:,yi:] = 1
print w*h - np.sum(mp)


Measured memory_bytes: 19308
#include<bits/stdc++.h>
using namespace std;
#define MAX_N 100005
#define MAX_M 100005
typedef pair<int,int> P;

int n,m;
vector<int> group[MAX_N];

vector<int> G[MAX_N];

int x[MAX_M],y[MAX_M],w[MAX_M];

int id[MAX_N];
bool visited[MAX_N];

int c[MAX_N];
vector<int> g[MAX_N];
vector<int> vd;

int dp[MAX_N];

bool dfs(int pos,int prev,int root){
  id[pos]=root;
  visited[pos]=true;
  group[root].push_back(pos);
  
  for(int to:G[pos]){
    if(to==prev)continue;
    if(visited[to])return true;
    if(dfs(to,pos,root))return true;
  }
  return false;
}

bool check(){
  map<P,bool> mp;
  for(int i=0;i<m;i++){
    if(w[i]==1)continue;
    if(x[i]>y[i])swap(x[i],y[i]);
    if(mp[ P(x[i],y[i]) ])return true;
    mp[ P(x[i],y[i]) ]=true;
  }
    
  memset(visited,false,sizeof(visited));
  for(int i=0;i<n;i++){
    if(visited[i])continue;
    if( dfs(i,-1,i) )return true;
  }


  
  for(int i=0;i<m;i++){
    if(w[i]==2)continue;
    int X=id[ x[i] ];
    int Y=id[ y[i] ];
    if(X==Y){
      return true;
    }
    g[X].push_back(Y);
    c[Y]++;
  }

  queue<int> Q;
  for(int i=0;i<n;i++){
    if(c[i]==0&&id[i]==i){
      Q.push(i);
    }
  }

  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    vd.push_back(pos);
    for(int to:g[pos]){
      c[to]--;
      if(c[to]==0)Q.push(to);
    }
  }

  for(int i=0;i<n;i++)
    if(c[i]>0)return true;
  
  return false;
}

int d[MAX_N];
void init(int root){
  root=id[root];
  for(int pos:group[root]){
    d[pos]=-1;
  }
}

void bfs(int root){
  init(root);
  queue<int> Q;
  Q.push(root);
  d[root]=0;
  while(!Q.empty()){
    int pos=Q.front();Q.pop();
    for(int to:G[pos]){
      if(d[to]!=-1)continue;
      d[to]=d[pos]+1;
      Q.push(to);
    }
  }
}

void update(int root,int dif){
  for(int pos:group[root]){
    for(int to:g[pos]){
      dp[to]=max(dp[to],d[pos]+dif+1);
    }
  }
}

int solve(int root){
  int res=0;
  bfs(root);
  int maxm=-1,maxmid;
  for(int pos:group[root])
    if(d[pos]+dp[pos]>maxm)maxm=d[pos]+dp[pos],maxmid=pos;
  
  bfs(maxmid);
  update(root,dp[maxmid]);
  for(int pos:group[root])res=max(res,d[pos]+dp[maxmid]);
  
  maxm=-1;
  for(int pos:group[root])
    if(d[pos]+dp[pos]>maxm)maxm=d[pos]+dp[pos],maxmid=pos;

  bfs(maxmid);
  update(root,dp[maxmid]);
  for(int pos:group[root])res=max(res,d[pos]+dp[maxmid]);
  
  return res;
}

int main(){
  scanf("%d %d",&n,&m);
  for(int i=0;i<m;i++){
    scanf("%d %d %d",&x[i],&y[i],&w[i]);
    x[i]--,y[i]--;
    
    if(w[i]==2){
      G[x[i]].push_back(y[i]);
      G[y[i]].push_back(x[i]);
    }
  }
  
  if( check() ){
    printf("Infinite\n");
    return 0;
  }

  for(int i=0;i<n;i++){
    g[i].clear();
  }
  for(int i=0;i<m;i++){
    if(w[i]==1){
      g[ x[i] ].push_back(y[i]);
    }
  }
  
  int ans=0;
  
  for(int root : vd ){
    if(root!=id[root])continue;
    ans=max(ans,solve(root));
  }
  printf("%d\n",ans);  
  return 0;
}

Measured memory_bytes: 27644
def Even(x):
  return  2 * x

def Odd(x):
  return 2 * x - 1

N, M = map(int, input().split())
G = list(map(Even, range(1, N+1)))#偶数
K = list(map(Odd, range(1, M+1)))#奇数

even=list()

for n in range(0, N):
  for nm in range(n+1, N):
    even.append(G[n]+G[nm])
  
for m in range(0, M):
  for mm in range(m+1, M):
    even.append(K[m]+K[mm])

print(len(even))

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <iomanip>
using namespace std;
using ll = long long;
#define pi 3.1415926
 
 int x[101];

int main()
{
    int a, b;
    cin >> a >> b;
    string sa(b, '0' + a);
    string sb(a, '0' + b);
    if(a < b)
        cout << sa;
    else    
        cout << sb;
    
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import java.lang.*;
public class Main{
  public static void main(String args[]){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt(),b=sc.nextInt(),c=sc.nextInt(); long k=sc.nextLong();
    if(k%2==0)
      System.out.println(a-b);
    else 
      System.out.println(b-a);
  }
}

Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <map>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <vector>
#include <cmath>
using namespace std;

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

typedef long long ll;

int SURP = 1000000007;

int ctoi(char c){
	int r = c - '0';
	return r;
}

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

	int ret = 100000000;

	REPI(i,1,N){
		int tmp = 0;
		string s1 = to_string(i);
		string s2 = to_string(N-i);

		REP(j,(int)s1.length()){
			tmp += ctoi(s1[j]);
		}

		REP(j,(int)s2.length()){
			tmp += ctoi(s2[j]);
		}

		if (ret > tmp) ret = tmp;
	}

	cout << ret << endl;
	return 0;
}


Measured memory_bytes: 256
n = int(input())
card = [[False for i in range(13)] for j in range(4)]

for i in range(n) :
    mark, suit = input().split()
    if mark == "S" :
        mark_num = 0
    elif mark == "H" :
        mark_num = 1
    elif mark == "C" :
        mark_num = 2
    elif mark == "D" :
        mark_num = 3
    card[mark_num][int(suit)-1] = True

for j in range(4) :
    for i in range(13) :
        if card[j][i] == False :
            if j == 0 :
                print("S", i+1)
            elif j == 1 :
                print("H", i+1)
            elif j == 2 :
                print("C", i+1)
            elif j == 3 :
                print("D", i+1)




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

using namespace std;

#define REP(i,n) for(int i=0; i<int(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
#define VI vector<int>
#define VLL vector<long long>
#define VVI vector<vector<int>>
#define VVLL vector<vector<long long>>
#define VC vector<char>
#define VS vector<string>
#define VVS vector<vector<string>>
#define VVC vector<vector<char>>
#define fore(i,a) for(auto &i:a)
typedef long long ll;
const int  INF = 2147483647;
const ll INFL = 9223372036854775807;
const ll mod = 1000000007;




int main() {
	int n, h;
	cin >> n >> h;
	VI a(n), b(n);
	REP(i, n)cin >> a[i] >> b[i];
	ll ans = 0;
	ll d = 0;
	sort(ALL(a));
	sort(ALL(b));
	reverse(ALL(a));
	reverse(ALL(b));
	REP(i, n) {
		if (a[0] <= b[i]) {
			ans++;
			d += b[i];
		}
		if (d >= h) {
			cout << ans << endl;
			return 0;
		}
	}
	ans += (h - d + a[0] - 1) / a[0];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
import sys

read = sys.stdin.read
readline = sys.stdin.buffer.readline

sys.setrecursionlimit(10 ** 8)
INF = float('inf')
MOD = 10 ** 9 + 7


def main():
    H, W, A, B = map(int, readline().split())
    L = [[0]*W for _ in range(H)]
    for h in range(B):
        for w in range(A,W):
            L[h][w] = 1
    for h in range(B,H):
        for w in range(A):
            L[h][w] = 1
    for l in L:
        print(''.join(map(str,l)))
    


if __name__ == '__main__':
    main()


Measured memory_bytes: 16844
//
//  main.cpp
//

#include <algorithm>
#include <array>
#include <assert.h>
#include <iomanip>
#include <iostream>
#include <limits>
#include <math.h>
#include <memory>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

using ll = int64_t;
using ull = uint64_t;

template<typename T>
vector<T> make_vec_nd(T init, ll size) {
    return vector<T>(size, init);
}
template<typename T, typename... Args>
auto make_vec_nd(T init, ll size, Args... rest) {
    auto inner = make_vec_nd(init, rest...);
    return vector<decltype(inner)>(size, inner);
}

#define rep(i,a,b) for(ll i=(a);i<(b);i++)
#define rrep(i,a,b) for(ll i=(a)-1;i>=(b);i--)

ll ans_for(ll H, unordered_map<ll, ll>& memo) {
    if (memo.find(H) != memo.end()) {
        return memo[H];
    } else if (H == 1) {
        return 1;
    } else {
        return 1 + 2 * ans_for(H/2, memo);
    }
}

int main() {
    unordered_map<ll, ll> memo;
    ll H;
    cin >> H;
    ll ans = ans_for(H, memo);
    cout << ans << endl;
}



Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep (i ,n) for(int i=0;i<(n);i++) 
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;} 


ll f(ll x,ll c,ll d){
	ll res=x;
	res-=x/c;
	res-=x/d;
	res+=x/lcm(c,d);
	return res;
}

int main(){
	ll a,b,c,d;
	cin>>a>>b>>c>>d;
	ll ans=f(b,c,d)-f(a-1,c,d);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
#include<queue>
#include<vector>
using namespace std;
const int maxn=1e6+10;
struct Point
{
    int x;
    int y;
    int t;
    Point(int x=0,int y=0,int t=0)
    {
        this->x=x;
        this->y=y;
        this->t=t;
    }
};
vector<Point> p;
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        int a,b,c;
        cin>>c>>a>>b;
        p.push_back(Point(a,b,c));
    }
    Point now;

    int flag=1;
    for(int i=0;i<n;i++)
    {
        Point temp=p[i];
        int t=abs(temp.x-now.x)+abs(temp.y-now.y);
        if(now.t+t>temp.t)
        {
            flag=0;
            break;
        }
        else if(now.t+t<temp.t)
        {
            int k=now.t+t;
            int h=temp.t-k;
            if(h%2)
            {
                flag=0;
                break;
            }
        }
        now=temp;
    }
    if(flag)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define DEBUG
#define PI 3.141592653589793238462643383279
 
#define _GLIBCXX_DEBUG
#ifdef DEBUG
#define s(...) show(__VA_ARGS__);
#define sl(...) show(__VA_ARGS__);cout<<endl;
#else
#define s(...)
#define sl(...)
#endif
void show() {}
template <class Head,class... Args>void show(Head t,Args... args){std::cout<<t<<" ";show(args...);}
#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define REP1(i, n) for(ll i = 1; i <= n; i++)
#define REPR1(i, n) for(ll i = n; i >= 1; i--)
#define FOR1(i, m, n) for(ll i = m; i <= n; i++)
const ll INF = LLONG_MAX;
const ull MOD = 1000000007;
#define VEC(type,A,N) vector<type> A(N)
#define VECi(type,A,N,i) vector<type> A(N,i)
#define VEC2(type,A,N,M) vector<vector<type>> A(N,vector<type>(M))
#define VEC2i(type,A,N,M,i) vector<vector<type>> A(N,vector<type>(M,i))
#define ALL(v) v.begin(), v.end()
ll frac(ll k){
    int s = 1;
    for (ll i=1; i<=k; ++i)s *= i;
    return s;
}
ll gcd(ll a, ll b){
   if (a%b==0)return(b);
   else return(gcd(b, a%b));
}
ll lcm(ll a,ll b){
    return a*b/gcd(a,b);
}
ll antidiv(ll N,ll C,ll D){
    return N-floor(N/C)-floor(N/D)+floor(N/lcm(C,D));
}
vector<ll> yakusuu(ll N){
    vector<ll> ret;
    for (ll i = 1; i * i <= N; i++) {
        if (N % i == 0) {
            ret.push_back(i);
            if (i * i != N) ret.push_back(N / i);
        }
    }
    sort(ret.begin(), ret.end());
    return ret;
}
ll digitPoor(ll n)
{
    assert(INT_MAX == 2147483647);
    assert(n >= 0);

    if (n < 10)         return 1;
    if (n < 100)        return 2;
    if (n < 1000)       return 3;
    if (n < 10000)      return 4;
    if (n < 100000)     return 5;
    if (n < 1000000)    return 6;
    if (n < 10000000)   return 7;
    if (n < 100000000)  return 8;
    if (n < 1000000000) return 9;
    return 10;
}
struct p{
  ll x;
  bool b;
};
int main(){
    ll R,G,B,N;
    cin>>R>>G>>B>>N;
    
    ll cnt=0;
    for(ll i=0;i<N+1;i++){
        ll t=R*i;
        for(ll j=0;j<N+1;j++){
            ll tt=t+G*j;
            if(N>=tt&&(N-tt)%B==0){
                //sl(i,j,(N-tt)/B)
                cnt++;
            }
        }
    }
    cout<<cnt;
    //cout<<fixed<<setprecision(32)<<m;
    //sort(ALL(C),[](auto& a, auto& b) {return a[2] < b[2];});
    //if(equal(D.begin(), D.end()-1, K.begin()))cout<<"Yes";else cout<<"No";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 3604
n = int(input())
s = list(map(str, input().split()))
d = {}
for i in range(n):
    if s[i] not in d:
        d[s[i]] = 1
    else:
        d[s[i]] += 1
if len(d.keys()) == 3:
    print('Three')
else:
    print('Four')
#print(d)

Measured memory_bytes: 38384
#ifndef HEADER_H
#define HEADER_H
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<vector>
#include<queue>
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<algorithm>
#include<stack>
#include<ctype.h>
#include<cstdlib>
#include<cmath>

#define F(t,i,s,r) for(t i=s;i<r;i++)
#define FE(t,i,s,r) for(t i=s;i<=r;i++)
#define R(t,i,s,r) for(t i=s;i>r;i--)
#define RE(t,i,s,r) for(t i=s;i>=r;i--)

using namespace std;
//freopen("i.txt", "r", stdin);
//freopen("o.txt","w",stdout);
#endif
#define ll long long
vector<bool>isprime;
void seiveAtkin (ll n) {
	isprime.resize (n + 1, false);
	isprime[2] = true, isprime[3] = true;
	ll lim = ceil (sqrt (n)), num;
	FE (ll, x, 1, lim) {
		FE (ll, y, 1, lim) {
			num = 4 * x*x + y*y;
			if (num <= n && (num % 12 == 1 || num % 12 == 5)) {
				isprime[num] = true;
			}
			num = 3 * x*x + y*y;
			if (num <= n && num % 12 == 7) {
				isprime[num] = true;
			}
			if (x > y) {
				num = 3 * x*x - y*y;
				if (num <= n && num % 12 == 11) {
					isprime[num] = true;
				}
			}
		}

	}
	FE (ll, i, 5, lim) {
		if (isprime[i]) {
			for (ll j = i*i; j <= n; j += i) {
				isprime[j] = false;
			}
		}
	}
}
int main () {
	int n;
	seiveAtkin (999999);
	vector<int>count;
	count.resize (1000000, 0);
	FE (int, i, 1, 999999) {
		count[i] += count[i - 1];
		if (isprime[i]) {
			count[i]++;
		}
	}
	while (cin>>n)
	{
		cout<<	count[n]<<endl;
	}
}

Measured memory_bytes: 6588
#include<iostream>
#include<string>
using namespace std;
int main()
{
  string S;
  cin>>S;
  int ans=0;
  for(int i=1;i<S.size();i++){
    if(S[i]==S[i-1]){
      if(S[i]=='0'){
        S[i]='1';
      }
      else{
        S[i]='0';
      }
      ans++;
    }
  }
  
  cout<<ans;
}

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

using namespace std;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define debug(x) cerr << #x << ":" << x << endl;
#define OK(ok) cout << (ok ? "Yes" : "No") << endl;
typedef long long ll;

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail) {
  cin >> head; CINT(move(tail)...);
}
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;
const int MAX_N = 1e5 + 1;

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  CIN(N, A, B);
  SCIN(s);

  int a, b;
  a = b = 0;

  REP(i, s.size()) {
    if (s[i] == 'a') {
      OK(a + b < A + B);
      if (a + b < A + B) a++;
    } else if (s[i] == 'b') {
      OK(a + b < A + B && b < B);
      if (a + b < A + B && b < B) b++;
    } else {
      OK(false);
    }
  }
  

  return 0;
}



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

#define all(x) (x).begin(), (x).end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef array<int, 3> tri;
typedef array<int, 2> duo;
typedef long double ld;

template <class T> istream& operator>>(istream& I, vector<T>& v) {for (T &e: v) I >> e; return I;}
template <class T> ostream& operator<<(ostream &O, const vector<T>& v) {for (const T &e: v) O << e << ' '; return O;}




void _main() {
        int n, x; cin >> n >> x;
        vector<int> L(n); cin >> L;
        int d = 0, ans = 0;
        for (int i = 1; i <= n + 1; i++) {
                if (d <= x) ans++;
                d += L[i - 1];
        }
        cout << ans;
}



signed main() {
        ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
//        freopen("input.txt", "r", stdin);
        int _t = 1;
//        cin >> _t;
        while (_t--) _main();
        return 0;
}


Measured memory_bytes: 3588