akhauriyash/Code-Regression huggingface dataset:
local mmi = math.min
local mma = math.max
local mce, mfl = math.ceil, math.floor
local n, k = io.read("*n", "*n")
local a = {}
for i = 1, n do
  local at = io.read("*n")
  if at < k then
    table.insert(a, at)
  end
end
n = #a
local function solve()
  if n == 0 then return 0 end
  local tail = {}
  for i = 1, n do
    tail[i] = {}
    for j = 1, mce((k - 1) / 2) do
      tail[i][j] = 0
    end
  end
  local function gettail(i, j)
    if j % 2 == 1 then
      return tail[i][mce(j / 2)] % 2 == 1
    else
      return mfl(tail[i][mce(j / 2)] / 2) == 1
    end
  end
  local function settail(i, j)
    if gettail(i, j) then return end
    local jidx = mce(j / 2)
    tail[i][jidx] = tail[i][jidx] + 2 - (j % 2)
  end
  local curmax = 0
  for i = n, 1, -1 do
    for j = 1, curmax do
      if gettail(i + 1, j) then
        settail(i, j)
        if j + a[i] < k then
          settail(i, j + a[i])
        end
      end
    end
    curmax = mmi(curmax + a[i], k - 1)
    settail(i, a[i])
  end
  local head = {}
  for i = 1, k - 1 do
    head[i] = false
  end
  local cnt = 0
  curmax = 0
  for i = 1, n - 1 do
    local ai = a[i]
    local need = false
    for j = k - ai, k - 1 do
      for p = 1, j - 1 do
        local q = j - p
        if head[p] and gettail(i + 1, q) then
          need = true
          break
        end
      end
      if head[j] or gettail(i + 1, j) then
        need = true
      end
      if need then break end
    end
    if not need then cnt = cnt + 1 end
    for j = mmi(curmax, k - 1 - ai), 1, -1 do
      if head[j] then head[j + ai] = true end
    end
    head[ai] = true
    curmax = mmi(curmax + ai, k - 1)
  end
  do -- i == n
    local ai = a[n]
    local need = false
    for j = k - ai, k - 1 do
      if head[j] then
        need = true
        break
      end
    end
    if not need then cnt = cnt + 1 end
  end
  return cnt
end
print(solve())


Measured memory_bytes: 165976
//
//  main.cpp
//  CoderProj
//
//  Created by Minoru Hayashi on 2020/03/12.
//  Copyright © 2020 Minoru Hayashi. All rights reserved.
//
//
//  
//

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

#define REP(i,n) for (int i=0; i<(n); i++)
#define REP2(i,x,n) for (int i=x; i<(n); i++)
#define ALL(n) begin(n), end(n)

using ll = long long;

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

// const ll INF = 1LL<<60;
// const int INF = 1<<29;
// const ll MOD = 1000000007;
// const double PI=3.1415926535897932;

//#define __DBG__


void solve(void){
  
  int N;
  string S;
  string T[3]={"Sunny","Cloudy","Rainy"}; 
  
  cin >> S;
  
  REP(i,3){
    if(S==T[i]){
      N=i+1;
      N%=3;
      break;
    }
  }
  
  cout << T[N] << endl;

  return;
   
}


int main(int argc, const char * argv[]) {

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

    solve();
 
    return 0;
}




Measured memory_bytes: 256
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin >> a >> b;
    if(a==1) a=14;
    if(b==1) b=14;
    if(a>b){
        puts("Alice");
    }else if(a==b){
        puts("Draw");
    }else{
        puts("Bob");
    }

    return 0;
}

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

int main(){
    int N,M,X;
    cin >> N >> M >> X;
    vector<int>A(M);
    map<int,int>Map;
    for(int i = 0; i < M; i++) {
        cin >> A[i];
        Map[A[i]]++;
    }
    int ans = 1000000;
    int cnt = 0;
    for(int i = X; i < N; i++) {
        if(Map[i] > 0) {
            cnt++;
        }
    }
    ans = min(cnt,ans);
    cnt = 0;
    for(int i = X; i >= 0; i--) {
        if(Map[i] > 0) {
            cnt++;
        }
    }
    ans = min(cnt,ans);
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <stack>
#include <string>
#include <queue>
#include <cstdlib>
#include <cstdio>
#include <vector>
#include <list>
#include <string.h>
#define _USE_MATH_DEFINES
#include <math.h>
#include <map>
#define INFTY (1<<30)

using namespace std;

int h = 0, a[2000000+1];

void maxHeapify( int i) {
	int l = 2*i, r = 2*i+1;
	int largest;
	if( l <= h && a[l] > a[i]) largest = l;
	else largest = i;
	if( r <= h && a[r] > a[largest]) largest = r;
	
	if( largest != i) {
		swap(a[i], a[largest]);
		maxHeapify(largest);
	}
	return;
}

void increaseKey(int i, int k) {
	if( k < a[i]) return;
	a[i] = k;
	while( i > 1 && a[i/2] < a[i]) {
		swap(a[i], a[i/2]);
		i = i/2;
	}
}

int extract() {
	if(h < 1) return -INFTY;
	int max = a[1];
	a[1] = a[h--];
	maxHeapify(1);
	return max;
}

int main(){
	while(1) {
		char str[10];
		int k;
		scanf("%s", str);
		if(str[0] == 'e' && str[1] == 'n') break;
		else if(str[0] == 'i') {
			cin >> k;
			h++;
			a[h] = -INFTY;
			increaseKey(h, k);
		} else {
			cout << extract() <<endl;
		}
	}
	return 0;
}

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

ll N;
vector<ll> a;

int main() {
    cin >> N;
    a.resize(N);
    for (int i = 0; i < N; i++) {
        ll temp; scanf("%Ld", &temp);
        a[i] = temp - i - 1;
    }
    sort(a.begin(), a.end());
    ll ans = 0;
    for (int i = 0; i < N/2; i++) ans += abs(a[N-1-i] - a[i]);

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

Measured memory_bytes: 1792
#include <iostream>
#include <cstring>
using namespace std;
typedef long long ll;
ll dp[256][256][256];

int main(){
    int n;
    int const mod=1000000007;
    while(cin>>n && n){
        memset(dp,0,sizeof(dp));
        dp[0][0][0]=1;
        for(int k=0;k<n;k++){
            char c;cin>>c;
            if(c=='-'){
                for(int x=0;x<=k;x++){
                    for(int y=0;y<=k;y++){
                        dp[k+1][x][y]+=dp[k][x][y];
                    }
                }
            }

            if(c=='D'){
                for(int x=1;x<=k;x++){
                    for(int y=1;y<=k;y++){
                        dp[k+1][x-1][y-1]+=dp[k][x][y]*x*y;
                        dp[k+1][x-1][y-1]%=mod;
                    }
                }
                for(int x=0;x<=k;x++){
                    for(int y=0;y<=k;y++){
                        dp[k+1][x][y]+=dp[k][x][y]*y;
                        dp[k+1][x][y]%=mod;
                    }
                }
            }
            
            if(c=='U'){
                for(int x=0;x<=k;x++){
                    for(int y=0;y<=k;y++){
                        dp[k+1][x][y]+=dp[k][x][y]*x;
                        dp[k+1][x][y]%=mod;
                    }
                }
                for(int x=0;x<=k;x++){
                    for(int y=0;y<=k;y++){
                        dp[k+1][x+1][y+1]+=dp[k][x][y];
                        dp[k+1][x+1][y+1]%=mod;
                    }
                }            
            }
        }

        // for(int i=0;i<=n;i++){
        //     for(int j=0;j<=n;j++){
        //         cout<<dp[n][i][j]<<" ";
        //         if(j==n)cout<<endl;
        //     }
        // }
        cout<<dp[n][0][0]<<endl;
    }
}

Measured memory_bytes: 132236
#include <iostream>
#include <vector>

using namespace std;

int main() 
{
  vector<int> v;
  vector<int> c;
  int x = 0;
  int y = 0;
  int n;
  cin >> n;
  for (int i = 0; i < n; i++) {
    int input;
    cin >> input;
    v.push_back(input);
  }
  for (int i = 0; i < n; i++) {
    int input;
    cin >> input;
    c.push_back(input);
  }

  for (int i = 0; i < n; i++) {
    if (v[i] > c[i]) {
      x += v[i];
      y += c[i];
    }   
  }
  cout << x - y << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int, input().split()))
A.insert(0, 0)
A.append(0)
total = 0

for i in range(1, len(A)):
	total += abs(A[i] - A[i - 1])


for i in range(1, N + 1):
	org = total
	org -= abs(A[i] - A[i - 1])
	org -= abs(A[i + 1] - A[i])
	org += abs(A[i + 1] - A[i - 1])
	print(org)

Measured memory_bytes: 64236
/**
 *    viet the nay ko phai bat chuoc tourist
 *    ma la muon noi rang
 *	 doc code ban khac la suc vat khong phai con nguoi
**/


#include <bits/stdc++.h>

using namespace std;

typedef long long ll;
typedef long double ldb;
typedef unsigned long long ull;
typedef pair<ll,ll> ii;
typedef pair<ll, pair<ll,ll> > iii;
typedef vector<ll> vi;

const int kn = 2e5 + 1;
const int N = 200001;
const ll mod = 1e9 + 7;

//#define x first
//#define y second
#define _it iterator
#define pb push_back
#define f(i,a,b) for(int i=a;i<=b;i++)
#define ff(i,n) for(int i=1;i<=n;i++)
#define ms(val,a) memset(a,val,sizeof(a))
#define _ff(i,n) for(int i=n;i>=1;i--)
#define _f(i,a,b) for(int i=b;i>=a;i--)
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int a,b,t;

int main() {
	cin >> a >> b >> t;
	a = t/a;
	cout << b*a;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int n,line[100000];
string s;
void co(){
	for(int i=0;i<n;i++){
		if(line[i]==0)cout<<"S";
		else cout<<"W";
	}
	return ;
}
int main(void){
	cin>>n>>s;
	for(int i=0;i<=1;i++){
		for(int j=0;j<=1;j++){
			line[0]=i;
			line[1]=j;
			for(int k=1;k<n-1;k++){
				if((line[k]==0&&s[k]=='o')||(line[k]==1&&s[k]=='x'))line[k+1]=line[k-1];
				else line[k+1]=!line[k-1];
			}
			if(line[0]==0){
				if(s[0]=='o')if(line[1]!=line[n-1])continue;
				if(s[0]=='x')if(line[1]==line[n-1])continue;
			}
			else{
				if(s[0]=='o')if(line[1]==line[n-1])continue;
				if(s[0]=='x')if(line[1]!=line[n-1])continue;
			}
			if(line[n-1]==0){
				if(s[n-1]=='o')if(line[0]!=line[n-2])continue;
				if(s[n-1]=='x') if(line[0]==line[n-2])continue;
			}
			else{
				if(s[n-1]=='o')if(line[0]==line[n-2])continue;
				if(s[n-1]=='x')if(line[0]!=line[n-2])continue;
			}
			co();
			return 0;
		}
	}
	cout<<"-1";
	return 0;
}

Measured memory_bytes: 896
// C - Unification
#include <bits/stdc++.h>
using namespace std;

int main(){
	string s; cin>>s;
	int a = 0, b = 0;
	for(int i=0; i<s.size(); ++i){
		if(s[i]=='0')++a;
		if(s[i]=='1')++b;
	}
	int c = min(a,b);
	cout<< c*2 <<endl;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <string.h>
using namespace std;
 
int n;
char s[205];
 
int main()
{
	cin>>s+1;
	
	if (strlen(s+1)%2 == 1) n=strlen(s+1)-1;
	else n=strlen(s+1)-2;
	
	for (int i=n;i>=1;i-=2)
	{
		int dis=i/2,flag=0;
		for (int j=1;j<=dis;j++)
			if (s[j] != s[j+dis]) {
				flag=1;break;
			}
		if (!flag) {
			cout<<dis*2<<endl;
			return 0;
		}
	}
	
	cout<<0<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <vector>
#include <climits>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb(a) push_back(a)
#define pf(a) push_front(a)
#define MP make_pair
#define pii pair<int,int>

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

using namespace std;

int main(){

  llong dp[201][201];
  int n, m, r;
  int city[8];
  
  scanf("%d %d %d", &n, &m, &r);

  REP(i,r){
    int t;
    scanf("%d", &t);
    t--;
    city[i] = t;
  }

  SORT(city,r);

  REP(i,n){
    REP(j,n){
      dp[i][j] = INF;
    }
  }
  REP(i,n){
    dp[i][i] = 0;
  }

  REP(i,m){
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    a--; b--;
    dp[a][b] = c; dp[b][a] = c;
  }

  REP(k,n){
    REP(i,n){
      REP(j,n){
        dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
      }
    }
  }

  llong res = LLONG_MAX;
  do{
    llong sum = 0;
    REP(i,r - 1){
      sum += dp[city[i]][city[i + 1]];
    }
    if(res > sum){
      res = sum;
    }
  }while(next_permutation(city,city + r));

  printf("%lld\n", res);

  return 0;
}



Measured memory_bytes: 640
N, M = map(int, input().split())
c = [False] * N
d = [False] * N
for _ in range(M):
    a, b = map(int, input().split())
    if a == 1:
        c[b - 1] = True
    if b == N:
        d[a - 1] = True
ans = any([c[i] and d[i] for i in range(N)])
print("POSSIBLE" if ans else "IMPOSSIBLE")


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

using namespace std;

typedef vector<int> vi;
typedef long long ll;

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

  string s, t;
  cin >> s >> t;

  int c = 0;

  if (s.size() != t.size())
  {
    if (s.size() < t.size())
    {
      c += t.size() - s.size();
    }
    else
    {
      c += s.size() - t.size();
    }
  }

  for (int i = 0; i < s.size(); i++)
  {
    if (s[i] != t[i])
      c++;
  }

  cout << c << "\n";

  return 0;
}


Measured memory_bytes: 3864
// At Corder.cpp : このファイルには 'main' 関数が含まれています。プログラム実行の開始と終了がそこで行われます。
//

#include <algorithm>
#include <iostream>
using namespace std;
#include <bits/stdc++.h>
#include <vector>
#include <numeric>
#include <math.h>
#define ld long double
#define rep(i,n) for (int i = 0; i < (n); ++i)
using ll = long long;
using p = pair<int, int>;//<key,value>

int main()
{

	vector<int> a(5);
	rep(i,5)
		cin >> a[i] ;

	rep(i,5)
	{
		if (a[i] == 0){
			cout << i+1 << endl;

		return 0;}
	}
   return 0;}



// プログラムの実行: Ctrl + F5 または [デバッグ] > [デバッグなしで開始] メニュー
// プログラムのデバッグ: F5 または [デバッグ] > [デバッグの開始] メニュー

// 作業を開始するためのヒント:
//    1. ソリューション エクスプローラー ウィンドウを使用してファイルを追加/管理します
//   2. チーム エクスプローラー ウィンドウを使用してソース管理に接続します
//   3. 出力ウィンドウを使用して、ビルド出力とその他のメッセージを表示します
//   4. エラー一覧ウィンドウを使用してエラーを表示します
//   5. [プロジェクト] > [新しい項目の追加] と移動して新しいコード ファイルを作成するか、[プロジェクト] > [既存の項目の追加] と移動して既存のコード ファイルをプロジェクトに追加します
//   6. 後ほどこのプロジェクトを再び開く場合、[ファイル] > [開く] > [プロジェクト] と移動して .sln ファイルを選択します


Measured memory_bytes: 3516
def resolve():
    N = int(input())
    A = list(map(int, input().split(" ")))
    import collections
    cnter = collections.Counter(A)
    #print(cnter)
    evens = 0
    for i in cnter.values():
        if i%2 == 0:
            evens += 1
    print(len(cnter)-1 if evens%2==1 else len(cnter))


if __name__ == '__main__':
    resolve()


Measured memory_bytes: 18528
#include <iostream>
#include <iomanip>
#include <stdlib.h>
#include <vector>
#include <iterator>
#include <algorithm>

using namespace std;

int main(){
	uint16_t A, B, C;
	cin >> A >> B >> C;
	uint8_t Flag = 0;

	if(A > B){
		while(A != B){
			if(A == C){
				Flag = 1;
				break;
			}
			--A;
		}

	}else if(A < B){
		while(A != B){
			if(A == C){
				Flag = 1;
				break;
			}
			++A;
		}

	}
	if(A == C)
		Flag = 1;

	if(Flag)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


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

using namespace std;

int main(){
  string s;
  cin >> s;
  
  if (s[0] == s[1] && s[1] == s[2]){
    cout << "Yes" << endl;
  }
  else if (s[1] == s[2] && s[2] == s[3]) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <list>
#include <string>

void insert(std::list<int> &lst);
void del(std::list<int> &lst);
void deleteFirst(std::list<int> &lst);
void deleteLast(std::list<int> &lst);
void command(std::list<int> &lst, std::string str);
void print(std::list<int> &lst);

int main(){
    int n;
    std::string str;
    std::list<int> lst;
    std::cin >> n;
    for(int i=0;i<n;i++){
        std::cin >> str;
        command(lst,str);
    }
    print(lst);
}

void insert(std::list<int> &lst){
    int x;
    std::cin >> x;
    lst.push_front(x);
}
void del(std::list<int> &lst){
    std::list<int>::iterator itr;
    int x;
    std::cin >> x;
    for(itr=lst.begin();itr!=lst.end();++itr){
        if(*itr==x){
            lst.erase(itr);
            break;
        }
    }
}
void deleteFirst(std::list<int> &lst){
    lst.pop_front();
}
void deleteLast(std::list<int> &lst){
    lst.pop_back();
}
void command(std::list<int> &lst, std::string str){
    if(str=="insert"){
        insert(lst);
    }else if(str=="delete"){
        del(lst);
    }else if(str=="deleteFirst"){
        deleteFirst(lst);
    }else{
        deleteLast(lst);
    }
}

void print(std::list<int> &lst){
    std::list<int>::iterator itr;
    std::list<int>::iterator itr2 = lst.end();
    itr2--;
    for(itr = lst.begin();itr != lst.end();++itr){
        std::cout << *itr;
        if(itr!=itr2){
            std::cout << " ";
        }
    }
    std::cout << "\n";
}


Measured memory_bytes: 34396
//17571@nith.ac.in @Ankit Verma
#include <bits/stdc++.h>
using namespace std;
#define ff          first
#define ss          second
#define pb          push_back
#define MP          make_pair
#define int         long long
#define ll          long long
#define inf         0x3f3f3f3f
#define MOD         1000000007
#define ld          long double
#define eb          emplace_back
#define pii         pair<int,int>
#define ull         unsigned long long
#define all(v)      v.begin(), v.end()
#define f(i,x,n)    for(int i=x;i<n;i++)
#define fr(i,x,n)   for(int i=x;i>=n;i--)
#define fastio      ios::sync_with_stdio(false)

void IO() {
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}

int32_t main() {
    IO();
    fastio;
    cin.tie(nullptr);
    cout.tie(nullptr);
    int k, a, b; cin >> k >> a >> b;
  	for (int i = a; i <= b; i++) {
      if (i % k == 0) {
        cout << "OK" << endl;
        return 0;
      }
    }
    cout << "NG" << endl;

    return 0;
}

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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i,0,n) cin >> a[i];
    vector<bool> found(n*n);
    vector<ll> dp(n*n);
    function<ll(int,int)> f = [&](int l, int r) {
        if(l==r) return a[l];
        int code = n*l+r;
        if(found[code]) return dp[code];

        ll ans = max(a[l]-f(l+1,r),a[r]-f(l,r-1));
        
        found[code] = true;
        dp[code] = ans;
        return ans;
    };
    ll ans = f(0,n-1);
    cout<<ans<<"\n";
}


Measured memory_bytes: 71936
from itertools import combinations
n,k = map(int,input().split())
if k > (n-1)*(n-2)//2:
    print(-1)
else:
    count = n-1 + (n-1)*(n-2)//2 - k
    ans = [(1,i) for i in range(2,n+1)]
    plus = (n-1)*(n-2)//2 - k
    print(count)
    num = 0
    rem = [i for i in range(2,n+1)]
    for a,b in combinations(rem,2):
        if num == plus:
            break
        ans.append((a,b))
        num += 1
    for a,b in ans:
        print(a,b)

Measured memory_bytes: 44784
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

bool solve(vi v) {
    int e = 0;
    for (int i: v) if (i % 2 == 0) e ++;
    // cout << e << "\n"
    if (e&1) return 1;
    if (e+1 == sz(v)) {
        for (int& i: v) {
            if (i % 2 == 1) i --;
            if (i == 0) return 0;
        }
        int g = 0; 
        for (int& i: v) g = __gcd(g,i);
        for (int& i: v) i /= g;
        return !solve(v);
    }
    return 0;
}

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    int n; cin >> n; vi v(n); F0R(i,n) cin >> v[i];
    if (solve(v)) cout << "First";
    else cout << "Second";
}

// read the question correctly (is y a vowel? what are the exact constraints?)
// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS

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

int n;

vector<pair<int, int> > v;
int ich(int cur, int er) {
	if (cur >= er) {
		cur--;
	}
	return cur;
}
int ans[200002];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		int a;
		scanf("%d", &a);
		v.push_back(make_pair(a, i));
	}
	sort(v.begin(), v.end());
	int p = v.size() / 2;
	int sz = v.size() - 1;
	sz /= 2;
	for (int i = 0; i < v.size(); i++) {
		int b = p;
		while (ich(b, i) != sz) {
			if (ich(b, i) < sz) {
				b++;
			}
			else {
				b--;
			}
		}
		if (b == i) {
			if (ich(b - 1, i) == sz) {
				b--;
			}
			else {
				b++;
			}
		}
		ans[v[i].second] = v[b].first;
	}
	for (int i = 0; i < n; i++) {
		printf("%d\n", ans[i]);
	}
	return 0;
}

Measured memory_bytes: 4720
import java.util.*;
public class Main {
	public static void main(String []args) {
		Scanner input = new Scanner(System.in);
		int len = input.next().length();
		String s = "";
		for(int i = 0; i < len; ++i) {
			s += 'x';
		}
		System.out.println(s);
		input.close();
		
	}
}














Measured memory_bytes: 23764
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
bool []a=new bool[100000];
for(int i=0;i<a.Length;i++){a[i]=IsPrime(i);}
    while(true){
        string str=Console.ReadLine();
        if(str==null){break;}
        int ans=int.Parse(str);
        for(int i=ans-1;i>0;i--){if(a[i]){Console.Write(i+" ");break;}}
        for(int i=ans+1;;i++){if(a[i]){Console.WriteLine(i);break;}}
        
    }
        
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
  public static bool IsPrime(int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false; // ??¶??°????????????????????????

    double sqrtNum = Math.Sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2)
    {
        if (num % i == 0)
        {
            // ?´???°??§?????????
            return false;
        }
    }

    // ?´???°??§??????
    return true;
}}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

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

using namespace std;

typedef long long          ll;
typedef unsigned long long ull;
typedef vector<int>	       vi;
typedef vector<bool>       vb;
typedef map<int, int>      mii;
typedef pair<int, int>     ii;

#define INF                0x3f3f3f3f
#define INFLL              0x3f3f3f3f3f3f3f3f
#define each(x, s)         for(auto& x : s)
#define loop(x)	           for(int i = 0;i < x;i++)
#define vloop(v, x)        for(int v = 0;v < x;v++)
#define avg(l, r)          l + (r - l) / 2
#define iter(a)            a.begin(), a.end()
#define riter(a)           a.rbegin(), a.rend()
#define endl               "\n"

const ll mod = 1000000007;

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

  int h, w, m;
  cin >> h >> w >> m;
  mii l, c;
  map<ii, bool> used;
  int x, y;
  loop(m) {
    cin >> x >> y;
    l[x]++;
    c[y]++;
    used[ii(x, y)] = true;
  }
  vector<ii> ls(iter(l)), cs(iter(c));
  sort(iter(ls), [](ii a, ii b) { return a.second == b.second ? a.first > b.first : a.second > b.second; });
  sort(iter(cs), [](ii a, ii b) { return a.second == b.second ? a.first > b.first : a.second > b.second; });
  x = ls.size(), y = cs.size();
  int ans = 0;
  int ml = 0, mc = 0;
  for (;ml < x and ls[0].second == ls[ml].second;ml++);
  for (;mc < y and cs[0].second == cs[mc].second;mc++);

  bool ok = false;
  int trg = ls[0].second + cs[0].second;
  loop(ml) vloop(j, mc) {
    if (ok) break;
    int aux = ls[i].second + cs[j].second;
    int u = used[ii(ls[i].first, cs[j].first)];
    aux -= u;
    if (!u and aux > ans) ok = true;
    ans = max(aux, ans);
  }
  loop(ml) for (int j = mc;j < y;j++) {
    if (ok) break;
    int aux = ls[i].second + cs[j].second;
    if (aux < trg) break;
    int u = used[ii(ls[i].first, cs[j].first)];
    aux -= u;
    if (!u and aux >= ans) ok = true, ans = aux;
  }
  for (int i = ml;i < x;i++) vloop(j, mc) {
    if (ok) break;
    int aux = ls[i].second + cs[j].second;
    if (aux < trg) break;
    int u = used[ii(ls[i].first, cs[j].first)];
    aux -= u;
    if (!u and aux >= ans) ok = true, ans = aux;
  }
  cout << ans << endl;
	return 0;
}



Measured memory_bytes: 54680
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define chmax(a, b) a = (a >= b ? a : b)
#define chmin(a, b) a = (a <= b ? a : b)
#define out(a) cout << a << endl
#define outa(a, n) { rep(_, n) cout << a[_] << " "; cout << endl; }
#define outp(a, n) { cout << endl; rep(_, n) cout << a[_].F << " " << a[_].S << endl; }
#define sz(v) (int)v.size()
#define inf (int)(1e9+7)
#define abs(x) (x >= 0 ? x : -(x))
#define ceil(a, b) a / b + !!(a % b)
#define FIX(a) fixed << setprecision(a)
#define LB(v, n) (int)(lower_bound(all(v), n) - v.begin())
#define UB(v, n) (int)(upper_bound(all(v), n) - v.begin())
ll pow(ll a, int b) { return b ? pow(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
template<typename T> T gcd(T a, T b) { if (b == 0) return a; return gcd(b, a % b); }




int main() {
    
    
   
    int k;
    cin >> k;
    vector<int> a(k);
    for (auto& ai : a) cin >> ai;
    if (a[k - 1] != 2) { cout << -1 << endl; return 0; }
  
    ll u = 2, d = 2;
    for (int i = k - 1; i >= 1; --i) {
        // 超える
        u = u + a[i] - 1;
        
        // 倍数以外落とす
        d = (d + a[i - 1] - 1) / a[i - 1] * a[i - 1];
        u = u / a[i - 1] * a[i - 1];
        // out(d << " " << u);
    }
    u = u + a[0] - 1;
    if (d > u) out(-1);
    else out(d << " " << u);
}


Measured memory_bytes: 640
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <map>
#include <set>
using namespace std;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 2000000000
bool prime[1000005]={};
int main(){
	int a,d,n;
	for(int i=2;i<=1000000;i++){
		bool p=false;
		for(int j=2;j*j<=i;j++){
			if(i%j==0){
				p=true;
				break;
			}
		}
		if(!p) prime[i]=true;
	}
	while(1){
		scanf("%d %d %d",&a,&d,&n);
		if(a+d+n==0) break;
		int cou=0;
		for(int i=a;;i+=d){
			if(prime[i]){
				cou++;
				if(cou==n){
					printf("%d\n",i); break;
				}
			}
		}
	}
}

Measured memory_bytes: 2164
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <string>
#include <cstdio>
#include <cmath>

#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
#define RREP(i, n) for(int i = (n) - 1; i >= 0; --i)
#define ALL(a) begin(a), end(a)

using ll = long long;
using namespace std;

constexpr int INF = 2147483647; // 2 * 1e9
constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;
	cin >> s;
	if(s[0] == s[2])cout << "Yes\n";
	else cout << "No\n";
	return 0;
}


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
using namespace std;
pair<int, int> p[200010];

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

  vector<int> v1[n+1];
  for (int i = 0; i < k; i++) {
    int a, b; cin >> a >> b;
    v1[a].push_back(b);
    v1[b].push_back(a);
  }
  int mi = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i].first == 0) {
      mi++;
      queue<int> q; q.push(i);
      while(!q.empty()) {
        int c = q.front(); q.pop();
        if (p[c].first != 0) continue;
        p[c].first = mi;
        for (int j = 0; j < v1[c].size(); j++) {
          q.push(v1[c][j]);
        }
      }
    }
  }
  vector<int> v2[n+1];
  for (int i = 0; i < l; i++) {
    int a, b; cin >> a >> b;
    v2[a].push_back(b);
    v2[b].push_back(a);
  }
  mi = 0;
  for (int i = 1; i <= n; i++) {
    if (p[i].second == 0) {
      mi++;
      queue<int> q; q.push(i);
      while(!q.empty()) {
        int c = q.front(); q.pop();
        if (p[c].second != 0) continue;
        p[c].second = mi;
        for (int j = 0; j < v2[c].size(); j++) {
          q.push(v2[c][j]);
        }
      }
    }
  }

  map<pair<int, int>, int> se;
  for (int i = 1; i <= n; i++) {
    if (p[i].first * p[i].second == 0) continue;
    if (se.find(p[i]) !=  se.end()) {
      se[p[i]]++;
    } else se.insert(make_pair(p[i], 1));
  }
  for (int i = 1; i <= n; i++) {
    if (i != 1) printf(" ");
    if (p[i].first * p[i].second == 0) printf("0");
    else printf("%d", se[p[i]]);
  }
  printf("\n");
  return 0;
}


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

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

  string s;
  cin >> s;

  if (s[0] == s[1] && s[1] == s[2]) cout << "No\n";
  else cout << "Yes\n";

  return (0);
}


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

int main(void)
{
	ios_base::sync_with_stdio(false);    
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n;
	cin>>n;
	
	vector<ll> dp(3);
	ll a,b,c;
	for(int i=0;i<n;i++)
	{
		vector<ll> s=dp;
		cin>>a>>b>>c;
		
		dp[0]=a+max(s[1],s[2]);
		dp[1]=b+max(s[0],s[2]);
		dp[2]=c+max(s[0],s[1]);
	}
	
	ll m=0;
	for(int i=0;i<3;i++)
		m=max(m,dp[i]);
		
	cout<<m<<"\n";
	
	return 0;
}

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

int main() {
  string o,e;
  cin >> o >> e;
  string ans;
  for( int i=0;i< e.size();i++){
    ans += o.at(i);
	ans += e.at(i);
  }
  if( o.size() - e.size() > 0 ){
    ans += o.back();
  }
  cout << ans << endl;
    
  return 0;
  
}

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

const int MOD = 1000000007;

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

	vector <long long> dp(s + 1, 0);
	
	dp[0] = 1;
	for(int i = 1; i <= s; i++){
		for(int j = 3; j <= i; j++)
			dp[i] = (dp[i] + dp[i - j]) % MOD;
	}
	
	printf("%lld\n", dp[s]);

	return 0;
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define P pair<ll,ll>
#define FOR(I,A,B) for(ll I = ll(A); I < ll(B); ++I)
#define FORR(I,A,B) for(ll I = ll((B)-1); I >= ll(A); --I)
#define TO(x,t,f) ((x)?(t):(f))
#define SORT(x) (sort(x.begin(),x.end())) // 0 2 2 3 4 5 8 9
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin()) //xi>=v  x is sorted
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin()) //xi>v  x is sorted
#define NUM(x,v) (POSU(x,v)-POSL(x,v))  //x is sorted
#define REV(x) (reverse(x.begin(),x.end())) //reverse
ll gcd(ll a,ll b){if(a%b==0)return b;return gcd(b,a%b);}
ll lcm(ll a,ll b){ll c=gcd(a,b);return ((a/c)*(b/c)*c);}
#define NEXTP(x) next_permutation(x.begin(),x.end())
const ll INF=ll(1e18)+ll(7);
const ll MOD=1000000007LL;
#define out(a) cout<<fixed<<setprecision((a))



int main(){
	
	string s,t;
	cin >> s >> t;
	ll sl = s.size();

	vector<ll> indexabc[27];
	FOR(i,0,sl){
		indexabc[s[i]-'a'].push_back(i);
	}

	ll ans = 0;
	ll nowi=-1;

	ll tl = t.size();
	FOR(i,0,tl){
		ll len = indexabc[t[i]-'a'].size();
		if(len == 0){
			cout << -1 << endl;
			return 0;
		}
		ll j = POSU(indexabc[t[i]-'a'],nowi);
		if(j == len){
			ans++;
			nowi = indexabc[t[i]-'a'][0];
		}else{
			nowi = indexabc[t[i]-'a'][j];
		}

	}
	//cout << sl << " " << nowi << endl;
	cout << ans*sl+nowi+1LL << endl;

}


Measured memory_bytes: 1724
#include <bits/stdc++.h>
using namespace std;
using Int = long long;
string solve(int a, int b)
{
    b += 1;
    if (a <= 0 && 0 < b) return "Zero";
    int cnt = 0;
    cnt += max(0, 0 - a);
    cnt -= max(0, 0 - b);
    return cnt % 2 ? "Negative" : "Positive";
}
int main() 
{
    int a, b; cin >> a >> b;
    cout << solve(a, b) << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <sstream>
#include <utility>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <fstream>
#include <bitset>
#include <cstdio>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <ctime>
#include <stack>
#include <map>
#include <set>
#if __cplusplus > 199711L
#include <unordered_set>
#include <unordered_map>
#include <tuple>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
//	tree<key, mapped = null_type, cmp = less<key>, rb_tree_tag, tree_order_statistics_node_update> name;
//	order_of_key
//	find_by_order
#endif

using namespace std;

#define pb push_back
#define ppb pop_back
#define mp make_pair
#define fs first
#define sc second
#define abs(a) ((a) < 0 ? -(a) : (a))
#define sqr(a) ((a) * (a))

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

inline pair<pair<bool, bool>, string> useinout();

void init() {
#ifdef SOL
	if (useinout().fs.fs)
		freopen("input.txt", "r", stdin);
	if (useinout().fs.sc)
		freopen("output.txt", "w", stdout);
#else
	srand(time(0));
	const string file = useinout().sc;
	if (!file.empty()) {
		freopen((file + ".in").c_str(), "r", stdin);
		freopen((file + ".out").c_str(), "w", stdout);
	}
#endif
}

int solve();

void finish(int exitval) {
	fflush(stdout);
#ifdef SOL
	fprintf(stderr, "\nexit value: %d\ntime: %.3lf ms\n", exitval, 1000. * clock() / CLOCKS_PER_SEC);
#endif
}

int main() {
	init();
	int exitval = solve();
	finish(exitval);
	return (0);
}

const double eps = 1e-9;
const int mod = (int) 1e+9 + 7;
const double pi = acos(-1.);
const int maxn = 100100;

inline pair<pair<bool, bool>, string> useinout() {
	return (mp(mp(0, 0), ""));
}

vector<char> vc;

int solve() {

	int cnt = 0;
	string s;
	getline(cin, s);
	for (int i = 0; i < (int) s.length(); i++) {
		vc.pb(s[i]);
		if (vc.size() >= 2 && vc[vc.size() - 1] == 'T' && vc[vc.size() - 2] == 'S') {
			cnt++;
			vc.ppb();
			vc.ppb();
		}
	}

	printf("%d\n", (int) s.length() - 2 * cnt);

	return (0);
}

// by Andrey Kim


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
typedef long long int lli;

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


    vector<lli> v(n);
    vector<lli> p(n);
    for(int i = 0; i < n; i++)
    {
        cin >> v[i];
    }

    p[0] = v[0];
    lli sol = 0;

    for(int i  = 1; i < n; i++)
    {
        p[i] = max(p[i-1], v[i]);
        sol += p[i] - v[i];
    }

    cout << sol << endl;
}



Measured memory_bytes: 6424
#include<bits/stdc++.h>
#define ll long long
#define MOD 1000000007
using namespace std;
ll dp[100000+1];

void add(ll &a,ll b){
    a+=b;
    if(a>=MOD){
        a-=MOD;
    }
}
void sub(ll &a,ll b){
    a-=b;
    if(a<0){
        a+=MOD;
    }
}


//ll pref[100000+1];
int main(){
    dp[0]=1;
    ll n,k;
    cin>>n>>k;
    for(int i=0;i<n;i++){
        ll limit;
        cin>>limit;
        vector<ll> pre(k+1);
        for(int j=k;j>=0;j--){
            int L=j+1;
            int R=min(j+limit,k);
            if(L<=R){
                add(pre[L],dp[j]);
                if((R+1)<=k){
                    sub(pre[R+1],dp[j]);
                }
            }
        }
        ll prefix_sum=0;
        for(int i=0;i<=k;i++){
            add(prefix_sum,pre[i]);
            add(dp[i],prefix_sum);
        }


    }
    cout<<dp[k]<<endl;


}


Measured memory_bytes: 1792
#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>
#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;


struct stc
{
	long long name; long long dif;
};

ll const MAX = 200005;
ll a[MAX];
ll b[MAX];
ll c[MAX];

ll f(ll x, ll y) {
	ll ans = 0;
	if (y > x) {
		while (y > x) {
			ans++;
			x *= 4;
		}
		return ans * 2;
	}
	else if(y==x){
		return 0;
	}
	else {
		swap(x, y);
		while (y >= x*4) {
			ans++;
			x *= 4;
		}
		return -ans * 2;

	}
}



int main() {
	ll n;
	cin >> n;
	REP(i, 1, n) {
		cin >> a[i];
	}
	b[n] = b[n + 1] = 0; b[0] = 0;
	ll cnt_b = 0;
	stack<stc> st1;
	PER(i, n - 1, 1) {
		ll x = f(a[i+1], a[i]);
		if (x < 0) {
			//cout << i <<" " << x << endl;
			st1.push({ i,-x });
			b[i] = b[i + 1];
		}
		else if (x == 0) {
			b[i] = b[i + 1];
		}
		else {
			b[i] = b[i + 1];
			bool flag = 1;
			while (!st1.empty()) {
				stc cur = st1.top();
				st1.pop();
				if (x <= cur.dif) {
					//cout << i << "! ";

					b[i] += x * (cur.name - i);
					//cout << b[i] << endl;
					cur.dif -= x;
					if (cur.dif > 0) {
						st1.push(cur);
					}
					flag = 0;
					break;
				}
				else {
					b[i] += cur.dif*(cur.name - i);
					x -= cur.dif;
				}
			}
			if (flag) {
				b[i] += (n - i)*x;

			}
		}

	}
	stack<stc> st2;
	c[0] = c[1] = 0; c[n + 1] = 0;
	REP(i, 2, n) {
		ll x = f(a[i-1], a[i]);
		if (x < 0) {
			st2.push({ i, -x });
			c[i] = c[i - 1];
		}
		else if(x==0){
			c[i] = c[i - 1];
		}
		else {
			c[i] = c[i - 1];
			bool flag = 1;
			while (!st2.empty()) {
				stc cur = st2.top();
				st2.pop();
				if (x <= cur.dif) {
					c[i] += x * (-cur.name + i);
					cur.dif -= x;
					if (cur.dif > 0) {
						st2.push(cur);
					}
					flag = 0;
					break;
				}
				else {
					c[i] += cur.dif*(-cur.name + i);
					x -= cur.dif;
				}
			}
			if (flag) {
				c[i] += (i - 1)*x;
			}
		}
	}
	ll ans = 1e18;
	REP(i, 1, n+1) {
		ans = min(ans, (i - 1) + c[i - 1] + b[i]);
	}
	/*
	REP(i, 0, n+1) {
		cout << b[i] << " ";
	}
	cout << endl;
	REP(i, 0, n+1) {
		cout << c[i] << " ";
	}
	cout << endl;
	*/
	cout << ans << endl;
}

Measured memory_bytes: 4992
// May this submission get accepted!

#pragma GCC optimize ("O3")
#pragma GCC target ("tune=native")
#pragma GCC target ("avx")

#include <bits/stdc++.h>

// 汎用マクロ
#define ALL_OF(x) (x).begin(), (x).end()
#define REP(i,n) for (long long i=0, i##_len=(n); i<i##_len; i++)
#define RANGE(i,is,ie) for (long long i=(is), i##_end=(ie); i<=i##_end; i++)
#define DSRNG(i,is,ie) for (long long i=(is), i##_end=(ie); i>=i##_end; i--)
#define STEP(i, is, ie, step) for (long long i=(is), i##_end=(ie), i##_step = (step); i<=i##_end; i+=i##_step)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
template<class T> bool chmax(T &a, const T &b) {if (a < b) {a = b; return true;} return false; }
template<class T> bool chmin(T &a, const T &b) {if (a > b) {a = b; return true;} return false; }
#define INF 0x7FFFFFFF
#define LINF 0x7FFFFFFFFFFFFFFFLL
#define Yes(q) ((q) ? "Yes" : "No")
#define YES(q) ((q) ? "YES" : "NO")
#define Possible(q) ((q) ? "Possible" : "Impossible")
#define POSSIBLE(q) ((q) ? "POSSIBLE" : "IMPOSSIBLE")
#define DUMP(q) cerr << "[DEBUG] " #q ": " << (q) << " at " __FILE__ ":" << __LINE__ << endl
#define DUMPALL(q) do { cerr << "[DEBUG] " #q ": ["; REP(i, (q).size()) { cerr << (q)[i] << (i == i_len-1 ? "" : ", "); } cerr << "] at " __FILE__ ":" << __LINE__ << endl; } while (false)
template<class T> T gcd(T a, T b) { if (a < b) std::swap(a, b); while (b) std::swap(a %= b, b); return a; }
template<class T> T lcm(const T a, const T b) { return a / gcd(a, b) * b; }

// gcc拡張マクロ
#define popcount __builtin_popcount
#define popcountll __builtin_popcountll

// エイリアス
#define DANCE_ long
#define ROBOT_ unsigned
#define HUMAN_ signed
#define CHOKUDAI_ const
using  ll = DANCE_ HUMAN_ DANCE_;
using ull = DANCE_ ROBOT_ DANCE_;
using cll = DANCE_ DANCE_ CHOKUDAI_;
using  ld = long double;
using namespace std;

// モジュール


// 処理内容
int main() {
    
    // インタラクティブ問題では除去した方がいいかも
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    
    ll n; cin >> n;
    vector<ll> a(n);
    REP(i, n) cin >> a[i];

    vector<vector<ll>> bitimos(n+1, vector<ll>(20, 0));
    REP(i, n) {
        REP(j, 20) {
            if (a[i] & (1LL << j)) {
                bitimos[i+1][j]++;
            }
        }
    }
    REP(i, n) {
        REP(j, 20) {
            bitimos[i+1][j] += bitimos[i][j];
        }
    }

    ll ans = 0;
    ll right = 0;
    REP(left, n) {
        chmax(right, left);
        while (right < n) {
            bool okay = true;
            REP(j, 20) {
                if (bitimos[right+1][j] - bitimos[left][j] > 1) {
                    okay = false;
                    break;
                }
            }
            if (!okay) break;
            right++;
        }
        ans += right - left;
    }
    cout << ans << endl;
    
}

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

int main() {
  int a,b,res;
  cin >> a >> b;
  res=b/100-a/100;  //bある aない
  int a21000=a/10000+((a/1000)%10)*10;
  int b21000=b/10000+((b/1000)%10)*10;
  if(a%100-a21000<=0)res++;
  if(b%100-b21000<0)res--;
  cout << res << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repp(i, a, b) for (int i = a; i <= (b); ++i)
#define repr(i, a, b) for (int i = a; i >= (b); --i)
#define bit(n) (1LL << (n))
#define len(x) ((ll)(x).size())
#define debug(var) cout << "[" << #var << "]\n" << var << endl
#define int long long
typedef long long ll;
const int INF = 1001001001001001001ll;
const ll LINF = 1001001001001001001ll;
const int MOD = 1000000007;
const double EPS = 1e-9;

template <typename T>
ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i];
    if (i < len - 1)
      s << ' ';
  }
  return s;
}

template <typename T>
ostream& operator<<(ostream& s, const vector<vector<T>>& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i];
    if (i != len - 1)
      s << '\n';
  }
  return s;
}

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

__attribute__((constructor)) void initial() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

struct Doubling {
  const int LOG;
  vector<vector<int>> table;

  Doubling(int sz, int64_t lim_t = 1e+18 + 1)
      : LOG(64 - __builtin_clzll(lim_t)) {
    table.assign(LOG, vector<int>(sz, -1));
  }

  void set_next(int k, int x) {
    table[0][k] = x;
  }

  void build() {
    for (int k = 0; k + 1 < LOG; k++) {
      for (int i = 0; i < table[k].size(); i++) {
        if (table[k][i] == -1)
          table[k + 1][i] = -1;
        else
          table[k + 1][i] = table[k][table[k][i]];
      }
    }
  }

  int query(int k, int64_t t) {
    for (int i = LOG - 1; i >= 0; i--) {
      if ((t >> i) & 1)
        k = table[i][k];
    }
    return k;
  }
};

signed main() {
  int N, K;
  cin >> N >> K;
  vector<int> A(N);
  rep(i, N) {
    cin >> A[i];
    A[i]--;
  }

  Doubling d(N);

  rep(i, N) {
    d.set_next(i, A[i]);
  }
  d.build();

  cout << (d.query(0, K) + 1) << endl;
}

Measured memory_bytes: 100144
n, k, q = gets.chop.split.map(&:to_i)

correct = Array.new(n, 0)
for num in 1..q do
  a = gets.chop.to_i

  correct[a - 1] += 1
end

border = q - k
for c in correct do
  if border < c
    puts 'Yes'
  else
    puts 'No'
  end
end


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main()
{
  int N, M;
  while (cin >> N >> M) {
    if ((N|M) == 0)
      break;

    vector<int> P(N+1, 0);
    for (int i = 0; i < N; ++i)
      cin >> P[i];

    vector<int> PP;
    for (int i = 0; i < N+1; ++i) {
      for (int j = 0; j < N+1; ++j)
	PP.push_back(P[i]+P[j]);
    }
    sort(PP.begin(), PP.end());

    int ans = 0;
    for (int i = 0; i < PP.size(); ++i) {
      int tar = M - PP[i];
      vector<int>::iterator it = upper_bound(PP.begin(), PP.end(), tar);
      if (it != PP.begin())
	ans = max(ans, PP[i] + *(it-1));
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 4956
#include <bits/stdc++.h>
using namespace std;
 
int main(){
 long long int N;
 cin >> N;
 if(N==1)cout << 1 << endl;
 else{
 long long int count = 1;
 long long int countsum = 0;
 long long int downsum = 0;
 while(N!=1){
     N/=2;
     countsum += count;
     count *= 2;
 }
 cout << countsum+count << endl;
 }
 }

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
   // freopen("in.txt","r",stdin);
   
    int n,k,r,p,s,points = 0;
    vector < char > moves;
    string t;
    
    cin >> n >> k >> r >> s >> p >> t;
    
    for(int i=0;i<k;i++){
        if(t[i]=='r'){
            points += p;
            moves.push_back('p');
        }
        
        else if(t[i]=='p'){
            points += s;
            moves.push_back('s');
        }
        
        else if(t[i]=='s'){
            points += r;
            moves.push_back('r');
        }
    }
    
    for(int i=k;i<t.size();i++){
        if(t[i]=='r'){
            if(moves[i-k] != 'p'){
                points += p;
                moves.push_back('p');
            }
            else{
                moves.push_back('?');
            }
        }
    
        else if(t[i]=='p'){
            if(moves[i-k] != 's'){
                points += s;
                moves.push_back('s');
            }
            else{
                moves.push_back('?');
            }
        }
        
        else if(t[i]=='s'){
            if(moves[i-k] != 'r'){
                points += r;
                moves.push_back('r');
            }
            else{
                moves.push_back('?');
            }
        }
    }
    
    cout << points << endl;
}


Measured memory_bytes: 640