akhauriyash/Code-Regression huggingface dataset:
s = input()

five = ["dream", "erase"]
six = ["eraser"]
seven = ["dreamer"]

i = len(s) - 1

ans = False
while True:
  if i < 4:
    break
  elif i == 4:
    ans = s[:5] in five
    break
  elif i == 5:
    ans = s[:6] in six
    break
  elif i == 6:
    ans = s[:7] in seven
    break
  else:
    if s[i+1-5:i+1] in five:
      i -= 5
    elif s[i+1-6:i+1] in six:
      i -= 6
    elif s[i+1-7:i+1] in seven:
      i -= 7
    else:
      break

if ans:
  print("YES")
else:
  print("NO")


Measured memory_bytes: 40432
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define mod 1000000007
using ll=long long;
const int INF=1000000000;
const ll LINF=1001002003004005006ll;
int dx[]={1,0,-1,0},dy[]={0,1,0,-1};
// ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(b<a){a=b;return true;}return false;}
 
struct IOSetup{
    IOSetup(){
        cin.tie(0);
        ios::sync_with_stdio(0);
        cout<<fixed<<setprecision(12);
    }
} iosetup;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os,const pair<T1,T2>&p){
    os<<p.first<<" "<<p.second;
    return os;
}
 
template<typename T>
ostream &operator<<(ostream &os,const vector<T>&v){
    for(int i=0;i<(int)v.size();i++) os<<v[i]<<(i+1==(int)v.size()?"":" ");
    return os;
}

template<typename T1,typename T2>
istream &operator>>(istream &is,pair<T1,T2>&p){
    is>>p.first>>p.second;
    return is;
}

template<typename T>
istream &operator>>(istream &is,vector<T>&v){
    for(T &x:v)is>>x;
    return is;
}

// 2^127 = 170141183460469231731687303715884105728 ~ 10^38
using int128=__int128;
 
ostream &operator<<(ostream &os,const __int128 n){
    if(n==0){
        os<<0;
        return os;
    }
    __int128 num=n;
    bool neg=false;
    if(num<0)neg=true,num=-num;
    string res="";
    while(num>0){
        res.push_back('0'+num%10);
        num/=10;
    }
    if(neg) res.push_back('-');
    reverse(begin(res),end(res));
    os<<res;
    return os;
}
 
istream &operator>>(istream &is,__int128 &n){
    string s;
    is>>s;
    int idx=0;
    bool neg=false;
    if(s[0]=='-')neg=true,idx++;
    n=0;
    for(;idx<(int)s.size();idx++){
        n=10*n+s[idx]-'0';
    }
    if(neg) n=-n;
    return is;
}
 
__int128 abs(__int128 x){
    return x<0?-x:x;
}
 
__int128 gcd(__int128 a,__int128 b){
    if(a==0) return b;
    if(b==0) return a;
    return b>0?gcd(b,a%b):a;
}



signed main(){
    int128 x,k,d;cin>>x>>k>>d;
    if(x<0)x=-x;

    if(x-k*d<0){
        // 反復横跳び
        ll t=x/d;
        x-=t*d;
        // pl
        k-=t;
        k%=2;
        if(k==0)cout<<x<<endl;
        else cout<<d-x<<endl;
    }
    else cout<<x-k*d<<endl;
    return 0;
}


Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define REP(i, n) for (long long i = 0; i < (long long)n; i++)
//#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using Vl = vector<ll>;
using vi = vector<int>;
using Graph = vector<vi>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(15); //"for float-base
  // problem"
  Vl A(3);
  cin >> A[0] >> A[1] >> A[2];
  sort(A.begin(), A.end());
  if (A[0] % 2 == A[1] % 2 == A[2] % 2 == 1)
    cout << A[0] * A[1] << endl;
  else
    cout << 0 << endl;
}

Measured memory_bytes: 3620
/**
 * @copyright (c) 2020 Daisuke Hashimoto
 */

#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
using Pair = pair<int32_t, int32_t>;

// std::cout << std::setprecision(20) << 1.1 << endl;

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

  int32_t N;
  string S;
  cin >> N >> S;
  int32_t x = 0;
  int32_t result = 0;
  const int32_t length = static_cast<int32_t>(S.length());
  for (int32_t i = 0; i < length; ++i) {
    const char ch = S.c_str()[i];
    if (ch == 'I') {
      ++x;
    } else {
      --x;
    }
    result = max(result, x);
  }
  cout << result << endl;

  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
int main(){
	int n;
	scanf("%d",&n);
	if(n==3)printf("2 5 63\n");
	else if(n==4)printf("2 3 4 9\n");
	else if(n==5)printf("2 3 4 6 9\n"); 
	else{
	 	int q;
	 	if(n<15000)q=n%6;
	 	else q=n-15000;
	 	for(int i=1;i<=q;i++){
	 		printf("%d ",6*i);
	 	}
		for(int i=0;i<n/6&&i<2500;i++){
			printf("%d ",12*i+2);
			printf("%d ",12*i+3);
			printf("%d ",12*i+4);
			printf("%d ",12*i+8);
			printf("%d ",12*i+9);				
			printf("%d",12*i+10);
			if(i+1<n/6&&i+1<2500)printf(" ");
		}
		printf("\n");
	}
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#define ri register int
#define rc register char
#define ll long long int
#define rl register long long int
#define in inline
#define gc getchar
in int read()
{
	ri x=0,p=1;
	rc ch=gc();
	while(ch<'0' || ch>'9')
	{
		if(ch=='-')
		{
			p=-1;
		}
		ch=gc();
	}
	while(ch>='0' && ch<='9')
	{
		x=x*10+ch-'0',ch=gc();
	}
	return x*p;
}
int n,a[15];
bool book[15];
void dfs(int step,int cnt)
{
	if(step==n)
	{
		for(ri i=1;i<=n;++i)
		{
			putchar(a[i]+'a'-1);
		}
		putchar('\n');
		return;
	}
	for(ri i=1;i<=cnt;++i)
	{
		if(book[i])
		{
			a[step+1]=i,dfs(step+1,cnt);
		}
	}
	book[cnt+1]=true,a[step+1]=cnt+1,dfs(step+1,cnt+1),book[cnt+1]=false;
}
int main()
{
	n=read(),a[1]=1,book[1]=true,dfs(1,1);
	return 0;
}

Measured memory_bytes: 1408
lst = []
for i in range(3):
    a,b,c = map(int, input().split())
    lst.append(a)
    lst.append(b)
    lst.append(c)

n = int(input())
checker = [0]*9
for i in range(n):
    bingo = int(input())
    try:
        checker[lst.index(bingo)] = 1
    except:
        pass

if checker[0]==checker[1]==checker[2]==1 or checker[3]==checker[4]==checker[5]==1 or checker[6]==checker[7]==checker[8]==1 or checker[0]==checker[3]==checker[6]==1 or checker[1]==checker[4]==checker[7]==1 or checker[2]==checker[5]==checker[8]==1 or checker[0]==checker[4]==checker[8]==1 or checker[2]==checker[4]==checker[6]==1:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
#include <utility> // pair
#include <string>
#include <vector>
#define MAX_N 100001
#define rep(i, n) for(ll i=0; i<n; i++)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll n;
unordered_map<double, double> m;
ll f1(ll n){
    return n / 2;
}

ll f2(ll n){
    return 3 * n + 1;
}

signed main(){
    ll s;
    cin >> s;
    m[s] = 1;
    rep(i, 1000000){
        if(s % 2 == 0) s = f1(s);
        else s = f2(s);
        if(m.find(s) != m.end()){
            cout << i + 2 << endl;
            break;
        }
        m[s] = 1;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
import math
 
def INT(): return int(input())
def MAPINT(): return map(int, input().split())
def LMAPINT(): return list(map(int, input().split()))
def STR(): return input()
def MAPSTR(): return map(str, input().split())
def LMAPSTR(): return list(map(str, input().split()))
 
f_inf = float('inf')
 
n = INT()
a = sorted(LMAPINT())

length = (max(a) + 1)

ans = [0] * length
for x in a:
  # 重複
  if ans[x] != 0:
    ans[x] = 2
    continue
  for j in range(x, length, x):
    ans[j] += 1
 
count = 0
for x in a:
  if ans[x] == 1:
    count += 1
print(count)

Measured memory_bytes: 135540
fun main(args: Array<String>) {
    val (K, N) = readLine()!!.split(" ").map(String::toInt)
    val AN = readLine()!!.split(" ").map(String::toInt).run {
        this.plus(this[0] + K)
    }
    val list = mutableListOf<Int>()
    for (i in 0 until N) {
        list += AN[i + 1] - AN[i]
    }
    println(list.sum() - list.max()!!)
}





Measured memory_bytes: 84636
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author cherrypi59
 */

#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define popcnt(x) __builtin_popcount(x)
#define popcntll(x) __builtin_popcountll(x)
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class DAnythingGoesToZero {
public:
    void solve(std::istream& in, std::ostream& out){
        ios_base::sync_with_stdio(false);
        in.tie(nullptr), out.tie(nullptr);
        int N;
        in>>N;
        string X;
        in>>X;
        reverse(ALL(X));
        int cnt = 0;
        for(auto& x : X) if(x=='1') ++cnt;
        int r1 = 0, r2 = 0, cur1 = 1, cur2 = 1;
        int mod1 = (cnt==1 ? 1 : cnt-1), mod2 = cnt + 1;
        vc<int> pow1(N), pow2(N);
        REP(i, N){
            pow1[i] = cur1;
            pow2[i] = cur2;
            if(X[i]=='1'){
                r1 = (r1+cur1) % (mod1);
                r2 = (r2+cur2) % (mod2);
            }
            cur1 = cur1 * 2 % (mod1);
            cur2 = cur2 * 2 % (mod2);
        }
        for(int i=N-1;0<=i;--i){
            if(X[i]=='1'){
                if(cnt==1){
                    out<<"0\n";
                    continue;
                }
                int now = (r1-pow1[i]+mod1) % (mod1), ans = 1;
                while(now){
                    now %= popcnt(now);
                    ++ans;
                }
                out<<ans<<'\n';
            }else{
                int now = (r2+pow2[i]) % (mod2), ans = 1;
                while(now){
                    now %= popcnt(now);
                    ++ans;
                }
                out<<ans<<'\n';
            }
        }
    }
};


int main() {
	DAnythingGoesToZero solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


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

using namespace std;
#define ll long long 
#define lf long double
#define F first
#define S second
#define pb push_back
typedef vector <ll> vi;
typedef vector <pair <ll,ll> > vii;
typedef vector <vector <ll> > vv;
#define inf 999999999999ll
int main() 
{
	ll T=1;
	//cin>>T;
	while(T--)
	{
	ll n,m;
	cin>>n>>m;
	vi price(m);
	vv k(m,vi());//  k[i]->list of boxes opended by key i
	for(ll i=0;i<m;i++)
	{
		ll b;
		cin>>price[i]>>b;
		for(ll j=0;j<b;j++)
		{
			ll x;
			cin>>x;
			x--;
			k[i].pb(x);
		}
	}
	vi dp((1<<n),inf);
	dp[0]=0;
	for(ll i=1;i<(1<<n);i++)
	{
		set <ll> boxes;
		for(ll k=0;k<n;k++)
		{
			if(i&(1<<k))
				boxes.insert(k);
		}
		for(ll j=0;j<m;j++)
		{
			set <ll> box=boxes;
			for(auto p:k[j])
			{
				if(box.find(p)!=box.end())
				{
					box.erase(p);
				}
			}
			ll left=0;
			for(auto p:box)
			{
				left=(left|(1<<p));
			}
			dp[i]=min(dp[i],dp[left]+price[j]);
		}
	}
	if(dp.back()!=inf)
	cout<<dp.back()<<endl;
	else
	cout<<-1<<endl;
	
	
	
	}
	
}

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

int main() { 
    int n;
    cin >> n;
    int64_t ans = 0;
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++){
            for(int k = 1; k <= n; k++){
                int64_t a = gcd(i,j);
                ans += gcd(a,k);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 3636
#include<stdio.h>

int main(void){

int a,b,c,z;

scanf("%d %d %d",&a,&b,&c);

if(a>b){

z=b; b=a; a=z;

}
if(a>c){

z=c; c=a; a=z;


}


if(b>c){


z=c; c=b; b=z;


}


printf("%d %d %d\n",a,b,c);

return 0;

}

Measured memory_bytes: 596
<?php
    $ABK = explode(" ",trim(fgets(STDIN)));
    $A = intval($ABK[0]);
    $B = intval($ABK[1]);
    $K = intval($ABK[2]);
    
    $turn = 0;
    for ($i = 0; $i < $K; $i++) {
        if ($turn == 0) {
            if ($A % 2 == 1) {
                $A--;
            }
            $gift = $A / 2;
            $A = $A - $gift;
            $B = $B + $gift;
            $turn++;
        } else {
            if ($B % 2 == 1) {
                $B--;
            }
            $gift = $B / 2;
            $B = $B - $gift;
            $A = $A + $gift;
            $turn--;
        }
    }
    
    
    echo $A." ".$B;
?>


Measured memory_bytes: 3956
#include <bits/stdc++.h>
using namespace std;
 
#define int long long
#define pb push_back
#define ub upper_bound
#define lb upper_bound
#define mp make_pair
#define F first
#define S second
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define SORT(c) sort((c).begin(),(c).end())
#define ve vector
#define vi vector<int>
#define vp vector<pair<int,int>>
#define vvi vector<vector<int>>
 
using ll = long long;
const ll INF = LLONG_MAX - 100;
ll mod = 1e9 + 7;
int dx[] = {-1,0,1,0}, dy[] = {0,1,0,-1};
vector<ll> prime;

class fact {
public:
	int fmod = 1e9+7;
	vector<int> fac, inv;
	fact (int n, int Mod = 1e9+7) {
		fmod = Mod;
		fac = vector<int>(n,0);
		inv = vector<int>(n,0);
		fac[0] = 1; for (int i = 1; i < n; i++) fac[i] = fac[i-1] * i % fmod;
		for (int i = 0;i < n;i++) inv[i] = fact::POW(fac[i],fmod-2);
	}
	ll nCr(ll n, ll r) {return (fac[n] * inv[r] % fmod) * inv[n-r] % fmod;}
	ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%fmod;}a = a * a%fmod; b >>= 1;}return c;}
};
 
template <class T = ll> T in() {T x; cin >> x; return (x);}
void DEBUG(vector<int> a) {for(int i=0;i<a.size();i++)cout<<a[i]<<" ";cout<<endl;}
void EMP(int x) {cout<<"!!!"<<x<<"!!!"<<endl;}
ll GCD(ll a, ll b) {ll c; while (b != 0) {c = a % b; a = b; b = c;}return a;}
ll LCM(ll a, ll b) {return a * b / GCD(a, b);}
ll POW(ll a, ll b) {ll c = 1; while (b > 0) {if (b & 1) {c = a * c%mod;}a = a * a%mod; b >>= 1;}return c;}
void PRI(ll n) {bool a[n + 1LL]; for (int i = 0; i < n + 1LL; i++) {a[i] = 1LL;}for (int i = 2; i < n + 1LL; i++) {if (a[i]) {prime.pb(i); ll b = i; while (b <= n) {a[b] = 0; b += i;}}}}
template <typename T> T chmin(T& a, T b) {if(a>b)a=b;return a;}
template <typename T> T chmax(T& a, T b) {if(a<b)a=b;return b;}
bool isSqrt(ll a) {return pow(sqrt(a),2) == a ? 1 : 0;}
void YesNo(bool a) {if (a) cout << "Yes"; else cout << "No"; cout << endl;}
void yesno(bool a) {if (a) cout << "yes"; else cout << "no"; cout << endl;}
void YESNO(bool a) {if (a) cout << "YES"; else cout << "NO"; cout << endl;}

bool solve() {
	int n; cin >> n;
    int a[n]; REP (i,n) cin >> a[i];
    int tmp = 0;
    REP (i,n) {
        tmp ^= a[i];
    }
    YesNo(tmp == 0);
}

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


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

#define rep(i,n) for(long long int (i)=0;(i)<(int)(n);(i)++)
#define rrep(i,a,b) for(long long int i=(a);i<(b);i++)
#define rrrep(i,a,b) for(long long int i=(a);i>=(b);i--)
#define all(v) (v).begin(), (v).end()
#define pb(q) push_back(q)
#define Abs(a,b) max(a,b)-min(a,b)
#define YES(condition) if(condition){cout << "YES" << endl;}else{cout << "NO" << endl;}
#define Yes(condition) if(condition){cout << "Yes" << endl;}else{cout << "No" << endl;}
#define Cout(x) cout<<(x)<<endl
#define POSSIBLE(condition) if(condition){cout << "POSSIBLE" << endl;}else{cout << "IMPOSSIBLE" << endl;}
#define Possible(condition) if(condition){cout << "Possible" << endl;}else{cout << "Impossible" << endl;}
#define possible(condition) if(condition){cout << "possible" << endl;}else{cout << "impossible" << endl;}
#define Size(n) (n).size()

typedef long long ll;


using namespace std;

const int INF = 1e9,MOD = 1e9 + 7,ohara = 1e6;
const ll LINF = 1e18;


long long int n,cnt=0,ans=0,a,b,c,d,cmp,cmpp,m,h,w,x,y,sum=0,pos,k;
int dy[]={1,0,-1,0};
int dx[]={0,1,0,-1};
string alph("abcdefghijklmnopqrstuvwxyz"),s,co[ohara];
bool fl=true;
struct edge{int to,cost;};

//-------------------------↓↓↓↓↓↓------------------------

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

      
      cin>>s>>k;
      map<string,ll> mp;
      rep(i,26){
        rep(j,Size(s)){
          string coo;
          if(s[j]==alph[i]){
            rrep(kk,j,Size(s)){
              coo+=s[kk];
              if(Size(coo)>k)break;
              mp[coo]++;
              if(mp[coo]==1){
                co[cnt]=coo;
                cnt++;
                if(cnt==k)break;
              }
            }
          }
        }
      }
      sort(co,co+cnt);
      Cout(co[k-1]);
     

       
return 0;
}


Measured memory_bytes: 9728
def main():
    k, a, b = map(int, input().split())
    if (b - a) <= 2:
        ans = k + 1
    else:
        n = (k - (a - 1)) // 2
        ans = n * b - (n - 1) * a + (k - (a - 1)) % 2

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
/*************************************
 * problem:      AT2162 Prefix and Suffix.
 * user ID:      63720.
 * user name:    Jomoo.
 * time:         2019-08-14.
 * language:     C++.
 * upload place: Luogu.
*************************************/ 

#include <bits/stdc++.h>
using namespace std;
#define puts_return(x) { puts(x); return 0; }
#define write_return(x) { write(x); return 0; }

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

int n;
char s[107], t[107];

bool same(int x)
{
    for (int i = 1; i <= x; i++) {
        if (s[n - x + i] != t[i]) return false;
    }
    return true;
}

int main()
{
    n = read<int>();
    scanf("%s%s", s + 1, t + 1);
    for (int i = n; i >= 1; i--) {
        if (same(i)) write_return(n * 2 - i);
    }
    write(n * 2);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
//#include<stdlib.h>
#include<string.h>
//#include <cmath>
//#include <vector>
#pragma GCC optimize("O3")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
static inline void PUT(char c)
{
  static char buf[1<<15],*ptr=buf;
  if(ptr==buf+strlen(buf)||c==0){fwrite(buf,1,ptr-buf,stdout),ptr=buf;}*ptr++=c;
}
static inline int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
static inline void OUT(int a)
{
  if(a<0)PUT('-'),a=-a;
  int d[40],i=0;do{d[i++]=a%10;}while(a/=10);
  while(i--){PUT(d[i]+48);}PUT('\n');
}
static inline int Max(int a,int b){return a>b?a:b;}
static inline int Min(int a,int b){return a<b?a:b;}
#define rep(i,n) FOR(i,0,n-1)
#define FOR(i,a,b) for(int i=a;i<=b;i++)
const int INF=0x7f7f7f7f;
struct SqrtDecomposition
{
  int k,n,sqrtn=0,dat[500708],buk[709]={0},lazy[709]={0},lazyflag[709]={0};
  void init(int x)
  {
    n=x;
    while(sqrtn*sqrtn<=n){sqrtn++;}
    k=(n+sqrtn-1)/sqrtn;
    rep(i,n){dat[i]=i;}
  }
  void eval(int b)
  {
    if(!lazyflag[b]){return;}
    lazyflag[b]=0;
    FOR(i,sqrtn*b,sqrtn*(b+1)-1){dat[i]=lazy[b];}
  }
  //[l,r)
  void update(int l,int r,int x)
  {
    rep(b,k)
    {
      int p=sqrtn*b,q=sqrtn*(b+1);
      if(q<=l||r<=p){continue;}
      if(l<=p&&q<=r){buk[b]=p-x;lazyflag[b]=1;lazy[b]=x;}
      else
      {
        eval(b);
        FOR(i,Max(l,p),Min(r,q)-1){dat[i]=x;}
        buk[b]=INF;
        FOR(i,p,q-1){buk[b]=Min(buk[b],i-dat[i]);}
      }
    }
  }
  //[l,r)
  int query(int l,int r)
  {
    int ret=INF;
    rep(b,k)
    {
      int p=sqrtn*b,q=sqrtn*(b+1);
      if(q<=l||r<=p){continue;}
      if(l<=p&&q<=r){ret=Min(ret,buk[b]);}
      else{eval(b);FOR(i,Max(l,p),Min(r,q)-1){ret=Min(ret,i-dat[i]);}}
    }
    return ret;
  }
};
int main(void)
{
  int H=IN(),W=IN();
  SqrtDecomposition sd;sd.init(W);
  rep(i,H)
  {
    int l=IN()-1,r=IN(),u=-INF;
    if(l>0){int b=(l-1)/sd.sqrtn;sd.eval(b);u=sd.dat[l-1];}
    sd.update(l,r,u);
    int ans=sd.query(0,W);
    if(ans>=INF){ans=-1;}else{ans+=i+1;}
    OUT(ans);
  }
}

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

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

    int n;
    cin>>n;

    int ans=0;
    for(int i=0;i<n;i++)
    {
        int a;
        cin>>a;
        ans+=a-1;
    }

    cout<<ans<<"\n";

    return 0;
}


Measured memory_bytes: 3636
from queue import Queue

while True:
    w, h = map(int, input().split())
    if w == h == 0:
        break

    vl = list()
    hl = list()
    for i in range(h * 2 - 1):
        if i % 2:
            hl.append(list(map(int, input().split())))
        else:
            vl.append(list(map(int, input().split())))

    q = Queue()
    d = [[w * h + 1 for i in range(h)] for j in range(w)]
    q.put((0, 0))
    d[0][0] = 1
    while not q.empty():
        x, y = q.get()

        if x > 0 and (not vl[y][x - 1]) and d[x - 1][y] > h * w:
            d[x - 1][y] = d[x][y] + 1
            q.put((x - 1, y))

        if x < w - 1 and (not vl[y][x]) and d[x + 1][y] > h * w:
            d[x + 1][y] = d[x][y] + 1
            q.put((x + 1, y))

        if y > 0 and (not hl[y - 1][x]) and d[x][y - 1] > h * w:
            d[x][y - 1] = d[x][y] + 1
            q.put((x, y - 1))

        if y < h - 1 and (not hl[y][x]) and d[x][y + 1] > h * w:
            d[x][y + 1] = d[x][y] + 1
            q.put((x, y + 1))
    
    if d[w - 1][h - 1] > h * w:
        print(0)
    else:
        print(d[w - 1][h - 1])


Measured memory_bytes: 6848
#include <bits/stdc++.h>
#define all(x) (x).begin(), (x).end()
using namespace std;

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

        if (!n)
            break;

        vector<double> s(n);
        for (auto&& i : s) {
            cin >> i;
        }

        double m = accumulate(all(s), 0.0) / n;
        double a = 0;
        for (size_t i = 0; i < n; i++) {
            a += pow(s[i] - m, 2) / n;
        }
        printf("%0.5lf\n", sqrt(a));
    }
}



Measured memory_bytes: 3188
#include <iostream>  // cin,cout
#include <stdio.h>   // printf,scanf (standard input/output)
#include <cmath>     // abs(x),pow(x,2)
#include <string>
#include <string.h>  // strlen, strcmp
#include <algorithm> // min,max, sort(v.begin(),v.end())
#include <vector>
#include <time.h>
using namespace std;



int main(){
    int N, M;
    cin >> N >> M;
    
    int X[M];
    int Y[M-1];
    
    for (int i=0;i<M;i++) cin >> X[i];
    
    sort(X,X+M);
    
    for (int i=0;i<M-1;i++) Y[i] = X[i+1]-X[i];
    long long total = 0;
    for (int i=0;i<M-1;i++) total += Y[i];
    //cout << total << endl;
    
    sort(Y,Y+M-1);
    //cout << Y[M-2] << endl;
    
    if (N>=M) cout << 0 << endl;
    else {
        long long temp = 0;
        for (int i=0;i<N-1;i++) temp += Y[M-2-i];
        //cout << temp << endl;
        
        cout << total-temp << endl;
    }
        
    
    
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n; cin  >> n;
  vll a(n+1); REP(i, n) cin >> a[i];
  ll m=0, ans = 1;
  rep(i, 1, n) {
    if (m==0) {
      if (a[i] > a[i-1]) m = 1;
      else if (a[i] < a[i-1]) m = 2;
    } else if (m == 1) {
      if (a[i] < a[i-1]) {
        m = 0; ans++;
      }
    } else if (m == 2) {
      if (a[i] > a[i-1]) {
        m=0; ans++;
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
using namespace std;
#define endl "\n"
#define int long long 
#define mp make_pair
#define pb push_back
#define pi 3.14159265358979323846
#define reus ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int32_t main()
{
	reus;
	int a;
	cin>>a;
	cout<<a+(a*a)+(a*a*a)<<endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;

long long c[10][10];

void warshall_floyd(){
    for(long long k = 0; k < 10; k++){
        for(long i = 0; i < 10; i++){
            for(long long j = 0; j < 10; j++){
                c[i][j] = min(c[i][j], c[i][k]+c[k][j]);
            }
        }
    }
}

int main(){
    long long h, w;
    cin >> h >> w;

    for(long long y = 0; y < 10; y++){
        for(long long x = 0; x < 10; x ++){
            cin >> c[y][x];
        }
    }

    long long a[h][w];
    for(long long y = 0; y < h; y++){
        for(long long x = 0; x < w; x++){
            cin >> a[y][x];
        }
    }

    warshall_floyd();

    long long count = 0;
    for(long long y = 0; y < h; y++){
        for(long long x = 0; x < w; x++){
            if(a[y][x] != -1){
                count += c[a[y][x]][1];
                
            }
        }
    }

    cout << count << endl;
    return 0;

}

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

#define mainspring cout<<"mainspring\n";
#define barrel cout<<"barrel\n";
#define escapement cout<<"escapement\n";

#define pb push_back
#define eb emplace_back
#define all(v) (v).begin(), (v).end() 
#define sz(v) (int)((v).size())
#define fs first
#define sd second
#define tik(i,a,b) for(int i = a; i < b; i++)
#define tok(i,a,b) for(int i = a; i >= b; i--)
#define error(args...) {string _s = #args; replace(_s.begin(), _s.end(), ',',' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it,args);}

typedef long long ll;
typedef unsigned long long ull;

typedef pair < int, int > pi;
typedef pair < pi, int > ppi;

typedef vector < int > vi;
typedef vector < vector < int > > vvi;
typedef vector < pi > vpi;
typedef vector < vpi > vvpi;
typedef vector < ppi > vppi;

void fast() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
}

void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cerr << *it << " = " << a << " ";
    err(++it, args...);
}

int main() {
	string s;
	cin >> s;
	bool ok = 1;
	for(int i = 0; i < sz(s); i++)
		ok &= (s[i] == s[sz(s) - 1 - i]);
	for(int i = 0; i < (sz(s) - 1)/2; i++)
		ok &= (s[i] == s[(sz(s) - 1)/2 - 1 - i]);
	for(int i = 0; i < (sz(s) - 1)/2; i++)
		ok &= (s[i + (sz(s) + 1)/2] == s[(sz(s) + 1)/2 + (sz(s) - 1)/2 - 1 - i]);
	if(ok)
		cout << "Yes";
	else
		cout << "No";	

}

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

int main() {
#define int long long
    int n,k;
    cin >> n >> k;

    int h[n+1],dp[n+1];
    for(int i=1;i<=n;i++)
    {
        cin >> h[i];
    }
    for(int i=1;i<=n;i++)
       dp[i]=INT_MAX;

    dp[1]=0;
    dp[2]=abs(h[2]-h[1]);

    for(int i=3;i<=n;i++)
    {
        for(int j=1;j<=k;j++)
        {
            if(i>j)
            {
                dp[i]=min(dp[i-j] + abs(h[i]-h[i-j]) , dp[i]);
            }
        }
    }

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

Measured memory_bytes: 1792
import fractions
n, k = map(int, input().split())
a = list(map(int, input().split()))
s = max(a)
gcd = 0
for i in a:
    gcd = fractions.gcd(gcd, i)
print("POSSIBLE" if k <= s and (k - s) % gcd == 0 else "IMPOSSIBLE")


Measured memory_bytes: 16240
#include<cstdio>
#define maxn 200050
using namespace std;
struct enode{
	int y,nxt;
}e[maxn*2];
int tot=0;
int first[maxn],ans[maxn];
void adde(int x,int y){
	e[tot].nxt=first[x];
	e[tot].y=y;
	first[x]=tot++;
}
void dfs(int x,int fa){
	for (int i=first[x];i>=0;i=e[i].nxt){
		int y=e[i].y;
		if (y!=fa) ans[y]+=ans[x],dfs(y,x);
	}
}
int main(){
	int n,q;
	scanf("%d%d",&n,&q);
	for (int i=1;i<=n;i++)
	first[i]=-1;
	for (int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		adde(x,y);
		adde(y,x);
	}
	for (int i=1;i<=q;i++){
		int x,d;
		scanf("%d%d",&x,&d);
		ans[x]+=d;
	}
	dfs(1,0);
	for (int i=1;i<=n;i++)
	printf("%d ",ans[i]);
	return 0;
}

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

const int INF = 1000000;
const int town_max = 10;

int main()
{
	while(true){
		int n;
		cin >> n;
		if(n==0)
			break;

		int T[town_max][town_max];
		for(int i=0;i<town_max;i++){
			for(int j=0;j<town_max;j++){
				if(i==j)
					T[i][j] = 0;
				else
					T[i][j] = INF;
			}
		}

		int m = 0;	//頂点の数
		for(int i=0;i<n;i++){
			int a, b, c;	//町の番号は0から
			cin >> a >> b >> c;
			T[a][b] = T[b][a] = c;
			if(a+1>m)
				m = a+1;
			if(b+1>m)
				m = b+1;
		}

		for(int i=0;i<m;i++){
			for(int j=0;j<m;j++){
				for(int k=0;k<m;k++){
					if(T[j][k]>T[j][i]+T[i][k])
						T[j][k] = T[j][i]+T[i][k];
				}
			}
		}


		int T_min = INF;    //時間の総和の最小値
		int town_min = -1;  //最小になる町の番号
		for(int i=0;i<m;i++){
			int T_sum = 0;
			for(int j=0;j<m;j++){
				T_sum += T[i][j];   //総和を計算
			}
			if(T_sum<T_min){    //最小なら
				T_min = T_sum;  //それを最小値に
				town_min = i;   //そのときの町の番号
			}
		}

		cout << town_min << " " << T_min << endl;
	}
}


Measured memory_bytes: 3100
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;
int dp[5001][5001];

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  string s;
  cin>>n>>s;
  reverse(all(s));
  int res=0;
  repi(i,1,n+1)
  {
    repi(j,i+1,n+1)
    {
      if(s[i-1]!=s[j-1])continue;
      dp[i][j]=min(dp[i-1][j-1]+1,j-i);
      chmax(res,dp[i][j]);
    }
  }
//  cout<<dp[5][11];
  cout<<res<<endl;
  return 0;

}


Measured memory_bytes: 96768
#include <iostream>
#include <string>
using namespace std;
bool check(string s){
    for(int i = 1;i<s.size();i++){
        if(s[i] != '0'){
            return false;
        }
    }
    if(s[0] == '1'){
        return true;
    }    
    return false;
}
int main(){
    string s;
    cin >> s;
    int ans = 0;
    if(check(s)){
        cout << 10 << endl;
    }
    else{
        for(int i = 0;i<s.size();i++){
            ans+=s[i]-'0';
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i,a,b) for(int i=a;i<=b;i++)
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define sz(x) ((int)x.size())
#define int ll
using namespace std;
using ll=long long;
using pii=pair<int,int>;

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

int32_t main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int a,b; cin>>a>>b;
	if(a<=5) cout<<"0\n";
	else if(a<=12) cout<<b/2<<"\n";
	else cout<<b<<"\n";
	return 0;
}















Measured memory_bytes: 256
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
#include <deque>
#include <iomanip>
#include <limits>
#include <fstream>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s, t;
  cin >> s >> t;
  map<char, set<char> > in;
  map<char, set<char> > out;
  FOR(i,0,s.length()) {
    out[s[i]].insert(t[i]);
    in[t[i]].insert(s[i]);
  }
  FOR(i,0,26) {
    if(in[char(i + 'a')].size() > 1 || out[char(i + 'a')].size() > 1) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}

Measured memory_bytes: 916
n, p = map(int, input().split())
alist = list(map(int, input().split()))

odda = 0
for a in alist:
  if a % 2 == 1:
    odda += 1

if odda == 0:
  if p == 0:
    print(pow(2, n))
  else:
    print(0)
else:
  print(pow(2, n-1))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin,(a).rend()
#define dunk(a) cout << (a) << endl
using namespace std;
typedef long long ll;
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	string s; cin >> s;
	int ans = 0;
	int res = 0;
	rep(i, n) {
		if (s[i] == 'I') res++;
		else res--;
		ans = max(ans, res);
	}
	dunk(ans);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int i,j,n,k,a[100001],ans;
  	scanf("%d%d",&n,&k);
  
  	for(int i=0;i<n;i++){
      scanf("%d",&a[i]);
      	if(a[i]=1){
          j=i;
        }
    }
  
  	if(j%(k-1)==0){
		if((n-j-1)%(k-1)==0){
			ans=j/(k-1)+(n-j-1)/(k-1);
        }else{
			ans=j/(k-1)+(n-j-1)/(k-1)+1;
        }
    }else{
      	if((n-j-1)%(k-1)==0){
			ans=j/(k-1)+(n-1-j)/(k-1)+1;
        }else{
			ans=j/(k-1)+(n-j-1)/(k-1)+2;
        }
    }

  	printf("%d",ans);
}

          


Measured memory_bytes: 512
using System;
using System.Linq;

class Program {
    static void Main(string[] args) {
        string sp = Cin.Next();
        string t = Cin.Next();

        Console.WriteLine(TryChange(sp, t));
    }

    private static string TryChange(string sp, string t) {
        char[] tmpSt = sp.ToCharArray();
        for (int i = sp.Length - t.Length; i >= 0; i--) {
            if (CanChange(sp, t, ref tmpSt, i)) {
                return new string(tmpSt).Replace('?', 'a');
            }
        }
        return "UNRESTORABLE";
    }

    private static bool CanChange(string sp, string t, ref char[] tmpSt, int i) {
        for (int ti = 0; ti < t.Length; ti++) {
            if (i + ti >= sp.Length) return false;
            if (sp[i + ti] == t[ti] || sp[i + ti] == '?') {
                tmpSt[i + ti] = t[ti];
            } else {
                tmpSt = sp.ToCharArray();
                return false;
            }
        }

        return true;
    }
}


public class Cin {
    private static string[] s = new string[0];
    private static int i = 0;

    private static char[] cs = new char[] { ' ' };

    public static string Next() {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        i = 0;
        return Next();
    }

    public static int Ni() {
        return int.Parse(Next());
    }

    public static long NextLong() {
        return long.Parse(Next());
    }

    public static double NextDouble() {
        return double.Parse(Next());
    }

}


Measured memory_bytes: 13140
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.Text;

class TEST{
	static void Main(){
		Sol mySol =new Sol();
		mySol.Solve();
	}
}

class Sol{
	public void Solve(){
		Console.WriteLine(new int[]{
			Math.Abs(A[0] - A[1]) + Math.Abs(A[1] - A[2]),
			Math.Abs(A[0] - A[2]) + Math.Abs(A[2] - A[1]),
			Math.Abs(A[1] - A[0]) + Math.Abs(A[0] - A[2]),
			Math.Abs(A[1] - A[2]) + Math.Abs(A[2] - A[0]),
			Math.Abs(A[2] - A[0]) + Math.Abs(A[0] - A[1]),
			Math.Abs(A[2] - A[1]) + Math.Abs(A[1] - A[0])
		}.Min());
	}
	int[] A;
	public Sol(){
		A = ria();
	}

	static String rs(){return Console.ReadLine();}
	static int ri(){return int.Parse(Console.ReadLine());}
	static long rl(){return long.Parse(Console.ReadLine());}
	static double rd(){return double.Parse(Console.ReadLine());}
	static String[] rsa(char sep=' '){return Console.ReadLine().Split(sep);}
	static int[] ria(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>int.Parse(e));}
	static long[] rla(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>long.Parse(e));}
	static double[] rda(char sep=' '){return Array.ConvertAll(Console.ReadLine().Split(sep),e=>double.Parse(e));}
}


Measured memory_bytes: 13268
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,a) for(ll i=ll(a-1);i>=0;--i)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}

const ll INF = 1e10;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
const ll EPS = 1e-10;
int sgn(const double a){
    return (a < -EPS ? -1 : (a > EPS ? +1 : 0));
}
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
typedef complex<double> Point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    ll k,one = 0;
    cin >> s >> k;
    while (s[one] == '1'){
        one++;
    }
    if (k <= one){
        PRINT(1);
    }
    else{
        PRINT(s[one]);
    }
}



Measured memory_bytes: 3648
/**
*   @Author : MeGA
*   @InitTime :02/08/20 16:00:27
*   @Idea : 
*
*
*
*
*
*
*
**/
#include <bits/stdc++.h>
using namespace std;
int main(){
#ifndef ONLINE_JUDGE
  // freopen("in","r",stdin);
  // freopen("out","w",stdout);
#endif

     ios::sync_with_stdio(false);
     cin.tie(0);
     int sz,n;
     cin>>sz>>n;
     string s;
     cin>>s;
     s[n-1]=tolower(s[n-1]);
     cout<<s<<endl;


}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int n;
  cin>>n;
  long long r;
  long double d=1;
  long long ans=1;
  bool flagf=1,flagz=0;
  for(int i=0;i<n;++i){
      cin>>r;
      if(r==0)flagz=1;
      if(flagf&&!flagz){
          d*=r;
          if(d>1e18){
              flagf=0;	
          }else{
              ans*=r;
          }
      }
  }
  if(flagz)cout<<0<<endl;
  else if(flagf)cout<<ans<<endl;
  else cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 3192
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#include <fstream>
#define FI first
#define SE second
#define VE vector<int>
#define PB push_back
#define PA pair<int,int>
#define MA make_pair
#define LLI long long int
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
#define POS(i) cout<<(i?"POSSIBLE":"IMPOSSIBLE")<<endl
#define Pos(i) cout<<(i?"Possible":"Impossible")<<endl
#define co(i) cout<<i<<endl
using namespace std;
//
const int INF=1e9+7;
const int MOD=1e9+7;
//
int main(){
    int n; cin>>n;
    int a[300001]={};
    FOR(i,0,3*n){
        cin>>a[i];
    }
    LLI b[100001]={};
    LLI c[100001]={};
    b[0]=0;
    priority_queue<int,vector<int>,greater<int>> q;
    FOR(i,0,n){
        q.push(a[i]);
        b[0]+=a[i];
    }
    FOR(i,0,n){
        q.push(a[n+i]);
        int t=q.top(); q.pop();
        b[i+1]=b[i]+a[n+i]-t;
    }
    priority_queue<int> q2;
    FOR(i,2*n,3*n){
        q2.push(a[i]);
        c[n]+=a[i];
    }
    ROF(i,0,n){
        q2.push(a[n+i]);
        int t=q2.top(); q2.pop();
        c[i]=c[i+1]+a[n+i]-t;
    }    
    LLI ans=-1e18;
    FOR(i,0,n+1){
        ans=max(ans,b[i]-c[i]);
    }
    co(ans);
}


Measured memory_bytes: 4088
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <unordered_map>
using namespace std;
using ll = long long;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr ll MOD = 1000000007;
constexpr ll INF = 1LL << 60;

void rec(int i, int pos, vector<int> &num, vector<unordered_map<int, bool>> &dp) {
	if (dp[i][pos]) return;
	dp[i][pos] = true;

	if (i == num.size()) return;
	rec(i + 1, pos + num[i], num, dp);
	rec(i + 1, pos - num[i], num, dp);
}

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	string s; int x, y;
	cin >> s >> x >> y;
	int n = s.size();
	int r = 0;
	while (r < n && s[r] == 'F') ++r;
	x -= r;

	int t = 0;
	int cnt = 0;
	vector<vector<int>> num(2, vector<int>());
	rep(i, r + 1, n) {
		if (s[i] == 'T') {
			t ^= 1;
			num[t].push_back(cnt);
			cnt = 0;
		}
		else ++cnt;
	}
	num[t ^ 1].push_back(cnt);
	vector<unordered_map<int, bool>> dp1(n + 1), dp2(n + 1);
	rec(0, 0, num[0], dp1);
	rec(0, 0, num[1], dp2);

	if (dp1[num[0].size()][x] && dp2[num[1].size()][y]) cout << "Yes";
	else cout << "No";
	return 0;
}


Measured memory_bytes: 208128
<?php
fscanf(STDIN, "%s", $w);
$s = 'a';
$arr = [];
for($i = 0; $i < 26; $i++) {
    $arr[$s] = 0;
    $s++;
}
//var_dump($arr); //exit;
for($i = 0; $i < strlen($w); $i++) {
    $s = 'a';
    for($j = 0; $j < 26; $j++) {
        if($w[$i] == $s) {
            $arr[$s] += 1;
        }
        $s++;
    }
}
//var_dump($arr); //exit;
foreach($arr as $key => $val) {
    if($val % 2 != 0) {
        echo 'No', PHP_EOL;
        exit;
    }
}
echo 'Yes', PHP_EOL;

Measured memory_bytes: 4728
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        List<Integer> h = new ArrayList<>();

        IntStream.rangeClosed(1, N).forEach(i -> h.add(sc.nextInt()));

        int answer = (int) h.stream()
                .filter(hi -> hi >= K)
                .count();

        sc.close();

        System.out.println(answer);
    }
}

Measured memory_bytes: 51212
#include <bits/stdc++.h>
#define che
#define debug(...) fprintf(stderr, __VA_ARGS__)
#define MP make_pair
#define PB push_back
using namespace std;
typedef long long LL;
const int MAXN=100000+10;
 
vector<int> G[MAXN];
int n,m, f[MAXN], que[MAXN], fro, rea,lef[MAXN];
bool tkn[MAXN];
int DP(int u,int fa){
	int vac=0,chil=0;
	f[u] = tkn[u]=0;
	for (int i=0; i< G[u].size(); i++){
		int v= G[u][i];
		if( v==fa) continue;
		f[u]+= DP(v, u);
		++chil;
		if ( !tkn[v]) ++vac;
	}
	if ( vac>1){
		tkn[u] =true;
		f[u] += vac-1;
	}	else
	if ( chil!=vac) tkn[u]=true;
	if ( fa==-1) ++f[u];
	#ifdef che
	debug("fa=%d\tf[%d] = %d\n",fa, u, f[u]);
	#endif
	return f[u];
}
int FindRt(){
	fro=rea=0;
	for (int i=0; i<n; i++){
		lef[i] = -1;
		if ( G[i].size()==1) que[rea++] = i, lef[i] = i;
		
	}
	while (fro < rea)
		for (int u=que[fro++], i=0,v; i< G[u].size()?v=G[u][i],1:0; i++){
			if( lef[v]==lef[u]) continue;
			if ( lef[v] !=-1) return lef[v];
			lef[v] = lef[u];
			if( G[v].size()<=2) que[rea++] =v;
		}
	return que[0];
}
int main(){
//	freopen("input.txt","rt",stdin);
//	freopen("output.txt","wt",stdout);
	scanf("%d", &n);
	srand(time(0));
	for (int i=1, u,v; i<n; i++){
		scanf("%d%d", &u, &v);
		G[u].PB(v); G[v].PB(u);
	}
	int rt= FindRt();
	int ans=DP(rt, -1);
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 14848
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[][] next = new int[n][n];
		for (int i = 0; i < n; i++) {
		    for (int j = 0; j < n; j++) {
		        next[i][j] = sc.nextInt();
		    }
		}
		long total = 0;
		for (int i = 0; i < n - 1; i++) {
		    for (int j = i + 1; j < n; j++) {
		        boolean flag = false;
		        for (int k = 0; k < n; k++) {
		            if (i == j || j == k || i == k) {
		                continue;
		            }
		            if (next[i][j] > next[i][k] + next[k][j]) {
		                System.out.println(-1);
		                return;
		            } else if (next[i][j] == next[i][k] + next[k][j]) {
		                flag = true;
		            }
		        }
		        if (!flag) {
		            total += next[i][j];
		        }
		    }
		}
        System.out.println(total);
   }
}




Measured memory_bytes: 52092
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <fstream>
#include <string>
#include <math.h>
#include <cstdlib>
#include <istream>
#include <sstream>
#include <cctype>
#include <iomanip>
//cout << fixed << setprecision(20) << *** << endl;
#define rep(i,N) for(int i=0;i<(int)N;++i)
typedef long long ll;
using namespace std;
int main()
{
	ll K;
	cin>>K;
	if(K==4||K==6||K==9||K==10||K==14||
		K==21||K==22||K==25||K==26){
		cout<<"2"<<endl;
	}
	else if(K==8||K==12||K==18||K==20||K==27){
		cout<<"5"<<endl;
	}
	else if(K==16){
		cout<<"14"<<endl;
	}
	else if(K==24){
		cout<<"15"<<endl;
	}
	else if(K==28||K==30){
		cout<<"4"<<endl;
	}
	else if(K==32){
		cout<<"51"<<endl;
	}
	else{
		cout<<"1"<<endl;
	}
}

Measured memory_bytes: 632
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#define SF scanf
#define PF printf
#define MAXN 200010
using namespace std;
int n;
struct node{
	int x;
	node *nxt;	
}edge[MAXN*2];
node *head[MAXN],*ncnt=edge;
void add_edge(int x,int y){
	ncnt++;
	ncnt->x=y;
	ncnt->nxt=head[x];
	head[x]=ncnt;
}
int sg[MAXN];
void dfs(int x,int fa){
	for(node *v=head[x];v!=NULL;v=v->nxt){
		int u=v->x;
		if(u==fa)
			continue;
		dfs(u,x);
		sg[x]^=(sg[u]+1);	
	}
}
int main(){
	SF("%d",&n);
	int u,v;
	for(int i=1;i<n;i++){
		SF("%d%d",&u,&v);
		add_edge(u,v);
		add_edge(v,u);
	}
	dfs(1,0);
	if(sg[1]==0)
		PF("Bob");
	else
		PF("Alice");
}

Measured memory_bytes: 10112