akhauriyash/Code-Regression huggingface dataset:
/* Don't try to copy it!
                    nhi too,
                         goli maar ke cheed bana dunga...;););)
 
                 
    _/﹋\_
    (҂`_´)
    <,︻╦╤─҉- - - - - - - - => - => - =>
    _/﹋\_
                
*/
 
#include "bits/stdc++.h"
#define faster ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define pb push_back
#define f(a) for(ll i = 0;i<a;i++)
#define rep(i,a,b) for(ll i = a;i<b;i++)
#define rrep(i,a,b) for(ll i = a;i>b;i--)
#define vll vector<ll>
#define T ll t; cin>>t; while(t--)
#define freeopen freopen("input.txt","r",stdin);
#define freeclose freopen("output.txt","w",stdout);
#define MOD 1000000007
using namespace std;
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }

string s,t;
int dp[3010][3010],N,M;
stack<char> resposta;

int solve(int a,int b){

    if(a < 0 || b < 0) return 0;

    if(dp[a][b] != -1) return dp[a][b];

    if(s[a] == t[b]) return dp[a][b] = 1 + solve(a-1,b-1);

    return dp[a][b] = max(solve(a-1,b),solve(a,b-1));

}

void build(int a,int b){

    if(a < 0 || b < 0) return;

    if(s[a] == t[b]){
        resposta.push(s[a]);
        build(a-1,b-1);
        return;
    }

    if(solve(a-1,b) > solve(a,b-1)) build(a-1,b);
    else build(a,b-1);

}

main(){

    memset(dp,-1,sizeof(dp));

    cin >> s;
    cin >> t;

    N = (int)s.size();
    M = (int)t.size();

    build(N-1,M-1);

    while(!resposta.empty()){
        cout << resposta.top();
        resposta.pop();
    }
    cout << endl;

  

}

Measured memory_bytes: 39244
#pragma GCC optimize("-O2")
#include<bits/stdc++.h>
#define int long long
#define vi vector<int> 
#define pb push_back
#define eb emplace_back
#define For(i,n) for(int i=0;i<n;i++)
#define MOD 1000000007
#define MAX 100005
#define endl '\n'
using namespace std;
int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	#ifndef ONLINE_JUDGE
	freopen("input1.txt", "r", stdin);
	// freopen("output1.txt", "w", stdout);
	#endif
	int n,sum=0,res=0;
	cin>>n;
	vi v(n);
	For(i,n){
		cin>>v[i];
		sum+=v[i];
		sum%=MOD;
	}
	for(int i=0;i<n-1;i++){
		sum-=v[i];
		if(sum<0)sum+=MOD;
		res+=v[i]*sum;
		res%=MOD;
	}
	cout<<res<<endl;
}

Measured memory_bytes: 4752
#include <iostream>
#include<string>
using namespace std;
int main(){
   int k;
   cin>>k;

   string s;
   cin>>s;

   int l = s.length();
   if(l<=k){
    cout<<s;
   }
   else{
    for(int i=0;i<k;i++){
        cout<<s[i];
    }cout<<"...";
   }
return 0;
}




Measured memory_bytes: 3604
#include<iostream>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<functional>
#include<iterator>
#include<cmath>

using namespace std;

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

	string s;
	cin >> s;
	int w;
	cin >> w;

	for(int i=0;i<s.size();i++){
		if(i % w == 0) cout << s[i];
	}
	cout << "\n";

	return 0;
}

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

int main() {
  int n; cin >> n;
  vector<int> a(n+2);
  int sum = 0;
  for (int i = 1; i <= n+1; i ++) {
    cin >> a[i];
    sum += abs(a[i] - a[i-1]);
  }

  int tmp;
  for (int i = 1; i <= n; i ++) {
    tmp = sum - abs(a[i] - a[i-1]) - abs(a[i+1] - a[i]) + abs(a[i+1] - a[i-1]);
    cout << tmp << endl;
  }
}


Measured memory_bytes: 1664
# -*- coding: utf-8 -*-
N, M = [int(n) for n in input().split()]
students = []
check_points = []

for n in range(N):
    students.append([int(tmp) for tmp in input().split()])

for m in range(M):
    check_points.append([int(tmp) for tmp in input().split()])

for student in students:
    destination = 0
    min_dis = 10**16
    for i, check_point in enumerate(check_points):
        tmp_dis = abs(student[0] - check_point[0]) + abs(student[1] - check_point[1])
        if tmp_dis < min_dis:
            destination = i + 1
            min_dis = tmp_dis
    print(destination)

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

int main(){
    string s;
    int d;
    cin>>s>>d;
    int n=s.size();
    ll dp[n+1][2][d];
    memset(dp,0,sizeof(dp));
    dp[0][0][0]=1;
    for(int i=0;i<n;i++){
        int num=s[i]-'0';
        for(int j=0;j<2;j++){
            for(int k=0;k<d;k++){
                for(int l=0;l<=(j?9:num);l++){
                    dp[i+1][j||l<num][(k+l)%d]+=dp[i][j][k];
                    dp[i+1][j||l<num][(k+l)%d]%=MOD;
                }
            }
        }
    }
    cout<<(dp[n][0][0]+dp[n][1][0]+MOD-1)%MOD<<endl;
}

Measured memory_bytes: 15872
#include <iostream>
using namespace std;
int main()
{
	int data[105],n,ans = 0,temp;
	cin >> n;
	for(int i = 1; i <= n; ++i)
		cin >> data[i];
	bool flag = true;
	while(flag)
	{
		flag = false;
		for(int i = n; i >= 2; --i)
		{
			if(data[i] < data[i-1])
			{
				temp = data[i];
				data[i] = data[i-1];
				data[i-1] = temp;
				++ans;
				flag = true;
			}
		}
	}
	cout << data[1];
	for(int i = 2; i <= n; ++i)
		cout << ' ' << data[i];
	cout << endl << ans << endl;
	return 0;
}


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

using namespace std;
typedef vector<int> VI;
typedef long long LL;
typedef pair<int,int> PI; 
typedef pair<LL,LL> PLL;
typedef unsigned long long ULL;

#define IOSWORK ios::sync_with_stdio(0); cin.tie(0)
#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define VAR(v, n) typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)

#define PB push_back
#define IN insert
#define ST first
#define ND second
#define INF 2000000011
#define MOD 1000000007

#define MAXSIZE 100000

int sito[MAXSIZE]={0};
int main(){
	
	IOSWORK;
	
	
	for(LL i=2;i<MAXSIZE;i++){
		if(!sito[i]){
			for(LL j=i*i;j<MAXSIZE;j+=i)
				sito[j]=1;
		}
	}
	
	int n;
	cin>>n;
	
	int p=3;
	while(n){
		if(sito[p]==0&&(p%5==1)){
			cout<<p<<" ";
			n--;
		}
		p++;
	}
	
	return 0;
}


Measured memory_bytes: 640
#include <stdio.h>

int main()
{
  int n, q, t[1000000], s[1000000];
  int count = 0, i, j;

  scanf("%d", &n);
  for(i = 0; i < n; i++){
    scanf("%d", &s[i]);
  }

  scanf("%d", &q);
  for(i = 0; i < q; i++){
    scanf("%d", &t[i]);
  }

  for(i = 0; i < q; i++){
    for(j = 0; j < n; j++){
      if(t[i] == s[j]){
	count++;
	break;
      }
    }
  }

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



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

int main()
{
	long long int n;
	string s;
	cin>>n>>s;
	long long int r = 0,g = 0,b = 0;
	for(size_t i = 0; i<n; i++)
	{
		if(s[i]=='R')
			r++;
		if(s[i]=='G')
			g++;
		if(s[i]=='B')
			b++;
	}
	long long int ans = r*g*b;
	for(size_t i = 1; i<(n+1)/2; i++)
	{
		for(size_t ii = 0; ii<n-i-i; ii++)
		{
			if(s[ii]!=s[ii+i]&&s[ii]!=s[ii+i+i]&&s[ii+i]!=s[ii+i+i])
			{
				ans--;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

#define INF 1001001001
#define LINF 1001001001001001001
#define MOD 1000000007
#define MOD2 998244353

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

#define rep(i,n) for(int i=0,_i=(n);i<_i;++i)
#define rep1(i,a,b) for(int a_=(a),b_=(b),i=a_;i<b_;++i)
#define repr(i,n) for(int _i=(n),i=_i;i>0;--i)

#define db(x) cerr<<#x<<" = "<<x<<" ";
#define db2(x,y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<") ";
#define db3(x,y,z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = ("<<x<<", "<<y<<", "<<z<<") ";
#define ln cout<<endl;

#define all(a)  (a).begin(),(a).end()
#define dig(n)  to_string(n).length()

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define se second
#define fi first

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<pii,pii> ppii;

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

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

int main(){
    bool flag=false;
    ll ans=0,sum=0;

    ll a,b,c;
    cin>>a>>b>>c;

    ll r =(c-a-b)*(c-a-b);
    ll l = a*b*4;

    db2(r,l);ln;

    if(c>a+b && l<r)cout << "Yes" <<endl;
    else cout << "No" <<endl;

    return 0;
}


Measured memory_bytes: 256
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#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 FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
VI e[SIZE];
void err(){
    W("No");
    exit(0);
}
void suc(){
    W("Yes");
    exit(0);
}
bool go(int x,int lt,int st){
    if(SZ(e[x])==4)return x==st;
    for(int y:e[x]){
        if(y!=lt)return go(y,x,st);
    }
}
int main(){
    int n,m; R(n,m);
    REP(i,m){
        int x,y; R(x,y);
        e[x].PB(y);
        e[y].PB(x);
    }
    FOR(i,1,n){
        if(SZ(e[i])%2)err();
    }
    int four=0;
    VI ff;
    FOR(i,1,n){
        if(SZ(e[i])>=6)suc();
        if(SZ(e[i])==4){
            four++;
            ff.PB(i);
        }
    }
    if(four>=3)suc();
    else if(four<=1)err();
    REP(i,4)if(go(e[ff[0]][i],ff[0],ff[0]))suc();
    err();
    return 0;
}


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

typedef long long ll;

int main(){
	ll k, a, b;
	cin>>k>>a>>b;
	if(b-a<=1 || (k+1 <= a)){
		cout<<k+1<<endl;
		return 0;
	}
	ll base = a;
	ll k1 = k-a +1 ;
	base += (b-a)*(k1/2) + k1%2;
	cout<<base<<endl;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(1 << 25)
readline = sys.stdin.buffer.readline
read = sys.stdin.readline  # 文字列読み込む時はこっち
ra = range
enu = enumerate


def exit(*argv, **kwarg):
    print(*argv, **kwarg)
    sys.exit()


def mina(*argv, sub=1): return list(map(lambda x: x - sub, argv))
# 受け渡されたすべての要素からsubだけ引く.リストを*をつけて展開しておくこと


def a_int(): return int(readline())


def ints(): return list(map(int, readline().split()))


def read_col(H):
    '''H is number of rows
    A列、B列が与えられるようなとき
    ex1)A,B=read_col(H)    ex2) A,=read_col(H) #一列の場合'''
    ret = []
    for _ in range(H):
        ret.append(list(map(int, readline().split())))
    return tuple(map(list, zip(*ret)))


def read_map_as(H, replace={'#': 1, '.': 0}, pad=None):
    '''
    文字列のmapを置換して読み込み。デフォでは#→1,.→0
    '''
    if pad is None:
        ret = []
        for _ in range(H):
            ret.append([replace[s] for s in read()[:-1]])
            # 内包表記はpypyでは若干遅いことに注意
            # #numpy使うだろうからこれを残しておくけど
    else:  # paddingする
        ret = [[pad] * (W + 2)]  # Wはどっかで定義しておくことに注意
        for _ in range(H):
            ret.append([pad] + [replace[s] for s in read()[:-1]] + [pad])
        ret.append([pad] * (W + 2))

    return ret


def grid_dijkstra(grid, si: int, sj: int):
    '''grid上のdijkstra法。gridはそこに入るときにかかるコスト
    si,sj は開始の座標。'''
    from heapq import heappop, heappush
    H = len(grid)
    W = len(grid[0])
    D = [[-1] * W for _ in [0] * H]  # -1がINFを意味する
    que = [(0, si, sj)]
    while que:
        c, i, j = heappop(que)
        if D[i][j] != -1:
            continue
        D[i][j] = c
        for di, dj in product([-2, -1, 0, 1, 2], repeat=2):
            ni, nj = i + di, j + dj
            if not (0 <= ni < H and 0 <= nj < W) or D[ni][nj] != -1 or ni == nj == 0 or grid[ni][nj] == 1:
                continue
            if (di == 0 and abs(dj) == 1) or (dj == 0 and abs(di) == 1):  # 歩いて行ける
                nc = c
            else:  # ワープして行ける
                nc = c + 1
            heappush(que, (nc, ni, nj))
    return D


MOD = 10**9 + 7
INF = 2**31  # 2147483648 > 10**9
# default import
from itertools import product, permutations, combinations
from collections import deque

# もし歩くだけなら簡単
# ワープをどう処理する？
# もし周囲5*5を候補にするなら24*10**6 んー間に合うか微妙


H, W = ints()
si, sj = mina(*ints())
ti, tj = mina(*ints())

S = read_map_as(H)
D = [[-1] * W for _ in [0] * H]  # -1がINFを意味する
que = deque([(0, si, sj)])
while que:
    c, i, j = que.popleft()
    if D[i][j] != -1:
        continue
    D[i][j] = c
    for di, dj in product([-2, -1, 0, 1, 2], repeat=2):
        ni, nj = i + di, j + dj
        if not (0 <= ni < H and 0 <= nj < W) or D[ni][nj] != -1 or ni == nj == 0 or S[ni][nj] == 1:
            continue
        if (di == 0 and abs(dj) == 1) or (dj == 0 and abs(di) == 1):  # 歩いて行ける
            que.appendleft((c, ni, nj))  # コストが低いので先に出したい
        else:  # ワープして行ける
            que.append((c + 1, ni, nj))  # コストが高いのであとに出したい

print(D[ti][tj])
# print(*D, sep='\n')

# unionfindで連結成分切り出してから、連結成分をまたぐときだけ+1するdfsかな?


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

#define F first
#define S second

using namespace std;

typedef long long LL;
typedef pair<int, int> PII;

const int N = 4010, M = 1010;

int n, cnt;
char s[N];

int check(int i, int j)
{
	if (s[i] == 'R' && s[j] == 'G' || s[i] == 'G' && s[j] == 'R')
	{
		int c = cnt, d = j - i;
		if (i - d >= 0 && s[i - d] == 'B') c -- ;
		if (j + d < n && s[j + d] == 'B') c -- ;

		d = (i + j) / 2;
		if (d - i == j - d && s[d] == 'B') c -- ;
		return c;
	}
	else return 0;
}

void solve()
{ 
	scanf("%d%s", &n, s);

	for (int i = 0; i < n; i ++ )
		if (s[i] == 'B')
			cnt ++ ;

	LL res = 0;
	for (int i = 0; i < n; i ++ )
		for (int j = i + 1; j < n; j ++ )
			res += check(i, j);

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

int main()
{
	int T = 1;
	// scanf("%d", &T);
	// cin >> T;
	while (T -- ) solve();
	return 0;
}

Measured memory_bytes: 3820
import sys
import bisect

input = sys.stdin.readline


def main():
    N = int(input())
    L = list(map(int, input().split()))

    L.sort()
    ans = 0
    for a in range(N - 2):
        for b in range(a + 1, N - 1):
            c = bisect.bisect_left(L, L[a] + L[b]) - 1
            ans += c - b

    print(ans)


if __name__ == "__main__":
    main()


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

#ifdef LOCAL
#define DEBUG(...) cerr << #__VA_ARGS__ << ": ", debug(__VA_ARGS__);
#else
#define DEBUG(...)
#endif

template<typename T, typename S> ostream& operator << (ostream &os, const pair<T, S> &p) {return os << "(" << p.first << ", " << p.second << ")";}
template<typename T> ostream& operator << (ostream &os, const vector<T> &v) {os << "["; for (int i=0; i<(int)v.size(); i++) {if (i) os << ", "; os << v[i];} return os << "]";}
void debug() {cerr << "\n";} template<typename T, typename... Args> void debug(T x, Args... args) {cerr << x << "; "; debug(args...);}

int l[200000], r[200000];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);

    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;

    int j = 0;
    for (int i=0; i<k; i++) {
        while (s[j] == 'x')
            j++;
        l[i] = j;
        j += c + 1;
    }

    j = n - 1;
    for (int i=k-1; i>=0; i--) {
        while (s[j] == 'x')
            j--;
        r[i] = j;
        j -= c + 1;
    }

    for (int i=0; i<k; i++)
        if (l[i] == r[i])
            cout << l[i] + 1 << "\n";

    return 0;
}


Measured memory_bytes: 3348
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
using ll = long long;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;

int main(){
    ll a, b, c;
    cin >> a >> b >> c;
    ll sum = a + b + c;
    if(sum>=22){
        cout << "bust" << endl;
    }
    else{
        cout << "win" << endl;
    }
}

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

#define rep(i,n) for(int i=0,i##_len=(n);i<i##_len;i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define ROF(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend() //sortで大きい順
#define UNIQUE(v) v.erase(unique(all(v)),v.end())
#define SUM(a) accumulate(all(a),0)
#define pb push_back
#define fst first
#define snd second
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef long long ll;

const ll mod = 1e9 + 7;

int main(){
  int n,m; cin >> n >> m;
  ll sumx = 0, sumy = 0;

  rep(i,n){
    ll x; cin >> x;
    (sumx += ll(2 * i - n + 1) * x) %= mod;
  }
  rep(i,m){
    ll y; cin >> y;
    (sumy += ll(2 * i - m + 1) * y) %= mod;
  }
  cout << (sumx * sumy) % mod << endl;
}

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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;
const int maxN = 2e5 + 55;

int n, k;
int p[maxN];
int lf[maxN], rt[maxN];

int foo[maxN];

void brt(int x){
	for(int i = 1; i <= n; i++){
		foo[i] = p[i];
	}

	sort(foo + x, foo + x + k);

	for(int i = 1; i <= n; i++){
		cerr << foo[i] << ' ';
	}
	cerr << '\n';
}

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

	cin >> n >> k;
	
	p[0] = BIG, p[n + 1] = -BIG;

	for(int i = 1; i <= n; i++){
		cin >> p[i];
	}
		
	//cerr << "\n\n\n\n";

	for(int i = 1; i <= n; i++){
		lf[i] = 1;
		if(i > 1 && p[i - 1] < p[i]){
			lf[i] = lf[i - 1] + 1;
		}
	}

	for(int i = n; i > 0; i--){
		rt[i] = 1;
		if(i < n && p[i] < p[i + 1]){
			rt[i] = rt[i + 1] + 1;
		}
	}

	deque<int> mxDeck, mnDeck;

	for(int i = 1; i < k; i++){
		while(!mxDeck.empty() && p[mxDeck.back()] < p[i]){
			mxDeck.pop_back();
		}
		mxDeck.push_back(i);
		
		while(!mnDeck.empty() && p[mnDeck.back()] > p[i]){
			mnDeck.pop_back();
		}
		mnDeck.push_back(i);
	}
	
	bool flag = false;
	int ans = 0;

	map<pair<int, int>, int> occ;
	
	for(int i = 1; i + k - 1 <= n; i++){
		while(!mxDeck.empty() && mxDeck.front() < i){
			mxDeck.pop_front();
		}
		
		while(!mnDeck.empty() && mnDeck.front() < i){
			mnDeck.pop_front();
		}

		while(!mxDeck.empty() && p[mxDeck.back()] < p[i + k - 1]){
			mxDeck.pop_back();
		}
		mxDeck.push_back(i + k - 1);
		
		while(!mnDeck.empty() && p[mnDeck.back()] > p[i + k - 1]){
			mnDeck.pop_back();
		}
		mnDeck.push_back(i + k - 1);
	
		int mn = p[mnDeck.front()];
		int mx = p[mxDeck.front()];
		
		int lo = i, hi = i + k - 1;
		
		if((int)mnDeck.size() == k){
			flag = true;
			continue;
		}
		
		if(mn > p[i - 1]){
			lo = i - lf[i - 1];
		}
		if(mx < p[i + k]){
			hi = i + k - 1 + rt[i + k];
		}

		//brt(i);
		if(occ.count(make_pair(lo, hi)) == 0){
			ans++;
			occ[make_pair(lo, hi)]++;
		}
	}
	
	cout << ans + flag << '\n';

	return 0;
}

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

#define int long long int
#define loop(i,s,e) for(int i=s; i<e; i++)
#define endl '\n'
#define vii vector<int>
#define pii pair<int, int>
#define ff first
#define ss second
#define N 100001
#define pb push_back
#define INF LLONG_MAX
#define inf INT_MAX

void INP();

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define rtn                                       if(0)return;
template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { rtn cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{     rtn 
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

void alpha()
{	
	int k, n;
	cin>>n>>k;

	int arr[n];
	loop(i,0,n) cin>>arr[i];

	int dp[k+1]={0};

	loop(i,1,k+1){
		loop(j,0,n){
			if(i>=arr[j] and dp[i-arr[j]]==0) dp[i]=1;
		}
	}


	if(dp[k]==1) cout<<"First"<<endl;
	else cout<<"Second"<<endl;

}

int32_t main(){

	ios_base:: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	//INP();
    int t=1;
	//cin>>t;

  	while(t--) alpha();

	return 0;

}






















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

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

#define ll long long
#define ld long double
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<

ll gcd(ll x, ll y)
{
    ll r;
    while((r = x % y) != 0)  
    {
        x = y;
        y = r;
    }
    return y;
}

int main(){
  ll n;
  cin >> n;
  vector<ll> a(n), b(n), c(n), d(n);
  ll i, j;
  for(i = 0; i < n; i++)
    cin >> a[i] >> b[i] >> c[i] >> d[i];
  string result;
  ll abuf, gcdbuf, maxbuf;
  
  for(i = 0; i < n; i++){
    if(a[i] < b[i] || b[i] > d[i])
      result = "No";
    else if(b[i] <= c[i] + 1)
      result = "Yes";
    else{
      abuf = a[i] % b[i]; //15
      //cout << "abuf" << abuf;
      //dbuf = d[i] % b[i];
      //0~cの余りが許容
      gcdbuf = gcd(b[i], d[i]); //1
      //cout << "gcdbuf" << gcdbuf;
      maxbuf = b[i] - gcdbuf + (abuf % gcdbuf); //16
      //cout << "maxbuf" << maxbuf;
      if(maxbuf <= c[i])
        result = "Yes";
      else
        result = "No";
    }

      
    cout << result << endl;
  }
   
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
#include <iomanip>
#include  <cassert>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define int ll
//const int INF = 100100100;
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;


signed main() {
	ios::sync_with_stdio(false);
	int n;
	set<int> nyan;
	cin >> n;
	vector<int> nu;
	rep(i, n) {
		int x;
		cin >> x;
		nu.pb(x);
		if (nyan.count(x)) {
			nyan.erase(x);
		}
		else {
			nyan.insert(x);
		}
	}
	int ans = 0;
	rep(i, nu.size()) {
		if (nyan.count(nu[i]) > 0) {
			ans++;
			nyan.erase(nu[i]);
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 5748
import sys
from collections import defaultdict

def I(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LMI(): return list(map(int, sys.stdin.readline().split()))
MOD = 10 ** 9 + 7
INF = float('inf')


N = I()
A, B = MI()
P = LMI()

d = defaultdict(int)
for p in P:
    if p <= A:
        d[0] += 1
    elif A < p <= B:
        d[1] += 1
    else:
        d[2] += 1
print(min(d[0], d[1], d[2]))


Measured memory_bytes: 38384
# -*- coding: utf-8 -*-

def assignColor():
    global C
    for i in range(n):
        if C[i] == -1:
            C = BFS(i, C)

#@profile
def BFS(start, C):
    Q = [start]
    C[start] = start

    while len(Q) != 0:
        u = Q.pop(0)
        v = [i for i in G[u] if C[i] == -1] # v := ??£??\???????????????????????¢?´¢??????????????????
        
        for i in v:
            Q.append(i)
            C[i] = C[start]
    
    return C

if __name__ == "__main__":
    n, m = list(map(int, input().split()))
    G = [[] for i in range(n)]
    C = [-1]*n
    
    for i in range(m):
        s, t = list(map(int, input().split()))
        G[s].append(t)
        G[t].append(s)
    assignColor()
    q = int(input())
    for i in range(q):
        s, t = list(map(int, input().split()))
        if C[s] == C[t]:
            print("yes")
        else:
            print("no")
            

Measured memory_bytes: 32856
N, M = map(int, input().split())
ab = [list(map(int, input().split())) for i in range(N)]
cd = [list(map(int, input().split())) for i in range(M)]

ans = []
for i in ab:
    a, b = i
    Min = 10**9
    num = 1
    for j in cd:
        c, d = j
        L = abs(a-c) + abs(b-d)
        if L < Min:
            pt = num
            Min = L
        num += 1
    ans.append(pt)

for i in ans:
    print(i)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
using ll = long long;
using u64 = uint_fast64_t;
using pii = pair<int, int>;
using pll = pair<long long, long long>;
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
template<class T1, class T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return true;} return false; }
template<class T1, class T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return true;} return false; }
inline int popcount(int x) {return __builtin_popcount(x);}
inline int popcount(long long x) {return __builtin_popcountll(x);}
void print() { cout << "\n"; }
template<class T, class... Args>
void print(const T &x, const Args &... args) {
    cout << x << " ";
    print(args...);
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////

vector<int> bfs(const vector<vector<int>> &G, int s) {
    vector<int> ret(G.size(),-1);
    ret[s] = 0;
    queue<int> que;
    que.emplace(s);
    while (!que.empty()) {
        int v = que.front(); que.pop();
        for (auto nv : G[v]) {
            if (ret[nv] != -1) continue;
            ret[nv] = ret[v] + 1;
            que.emplace(nv);
        }
    }

    return ret;
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N; cin >> N;
    string S; cin >> S;
    vector<vector<int>> G(N);
    rep(i,N-1) {
        int u,v; cin >> u >> v;
        --u; --v;
        G[u].emplace_back(v);
        G[v].emplace_back(u);
    }

    auto color = bfs(G,0);
    int B = 0, W = 0;
    rep(i,N) {
        color[i] &= 1;
        if (S[i]=='1') {
            if (color[i]) B++;
            else W++;
        }
    }

    int ans = 1e9;
    rep(r,N) {
        if (color[r] and W&1) continue;
        if (!color[r] and B&1) continue;
        bool ok = false;
        vector<int> MAX(N),MIN(N),cnt(N);
        auto dfs=[&](auto&& self, int v, int pv)->void {
            cnt[v] = S[v]=='1';
            for (auto nv : G[v]) {
                if (nv==pv) continue;
                self(self,nv,v);
                cnt[v] += cnt[nv];
                MAX[v] += MAX[nv];
            }

            for (auto nv : G[v]) {
                if (nv==pv) continue;
                int M = MAX[v] - MAX[nv];
                int m = MIN[nv];
                chmax(MIN[v],max(0,m-M));
            }
            if (pv != -1) {
                MAX[v] += cnt[v];
                MIN[v] += cnt[v];
            } else {
                ok = MIN[v]==0;
            }
        };
        dfs(dfs,r,-1);
        if (ok) chmin(ans,MAX[r]/2);
    }

    cout << (ans==1e9 ? -1 : ans) << ln;
}


Measured memory_bytes: 3948
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter
import java.util.*
import kotlin.math.abs
import kotlin.math.min

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    val n = readInteger()
    val pList = readIntegerList().joinToString("")
    val qList = readIntegerList().joinToString("")

    val permutationList = permutationListFrom(Array(n) { it + 1 }).map { it.joinToString("") }

    val a = permutationList.indexOf(pList)
    val b = permutationList.indexOf(qList)
    out.println(abs(a - b))
}

/** O((array.size)!) */
fun <T : Comparable<T>> permutationListFrom(array: Array<T>): List<Array<T>> {
    val current = array.copyOf()
    val permutationList = mutableListOf<Array<T>>()
    do { permutationList += current.copyOf() } while (nextPermutation(current))
    return permutationList
}

/** O(n): n = currentPermutation.size */
fun <T : Comparable<T>> nextPermutation(currentPermutation: Array<T>): Boolean {
    fun <T> Array<T>.reverse(start: Int, end: Int) {
        val midPoint = ((start + end) / 2) - 1
        if (midPoint < 0) return
        var reverseIndex = end - 1
        for (index in start..midPoint) {
            val tmp = this[index]
            this[index] = this[reverseIndex]
            this[reverseIndex] = tmp
            reverseIndex--
        }
    }

    val n = currentPermutation.size
    var i = n - 2
    while (i >= 0) {
        if (currentPermutation[i] < currentPermutation[i + 1]) break
        i--
    }
    if (i < 0) return false
    var j = n
    do { j-- } while (currentPermutation[i] > currentPermutation[j])
    if (currentPermutation[i] < currentPermutation[j]) {
        val tmp = currentPermutation[i]
        currentPermutation[i] = currentPermutation[j]
        currentPermutation[j] = tmp
        currentPermutation.reverse(i + 1, n)
        return true
    }
    return false
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


Measured memory_bytes: 60280
#include<iostream>
#include<algorithm>
using namespace std;
int a[10],b[10];
int main(){
	for(int i=0;i<10;i++)cin>>a[i];
	for(int i=0;i<10;i++)cin>>b[i];
	sort(a,a+10);sort(b,b+10);
	cout<<a[7]+a[8]+a[9]<<' '<<b[7]+b[8]+b[9]<<endl;
	return 0;
}

Measured memory_bytes: 2988
s=list(input())
n=len(s)
flag=False

if ''.join(s)=='keyence':
    print('YES')
    flag=True
    
else:
    for i in range(n):
        for j in range(i,n):
            t=s.copy()
            del t[i:j+1]
            if ''.join(t)=='keyence':
                print('YES')
                flag=True
                break
        if flag:
            break

if not flag:
    print('NO')


Measured memory_bytes: 3060
#include <stdio.h>

int main(){
    int n,k,m;
    int h1;
    double h2,sum=0;

    scanf("%d %d",&n,&k);

    for(m=1;m<=n;m++){
        h1 = m;
        h2 = 1;
        while(h1<k){
            h1 = 2*h1;
            h2 = h2/2;
        }
        sum = sum + h2;
    }
    sum = sum/(double)n;
    printf("%.12lf",sum);
    return 0;
}

Measured memory_bytes: 128
#include<cstdio>
int pow(int x, int y)
{
	int temp = x;
	while (y--)
	{
		temp *= 2;
	}
	return temp;
}

int main()
{
	int a, b, c, max = -1;
	scanf("%d %d %d", &a, &b, &c);
	int k;
	scanf("%d", &k);
	max = a > b ? a : b;
	max = max > c ? max : c;
	int sum = a + b + c - max;
	max = pow(max, k);
	sum += max;
	printf("%d\n", sum);

	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
 
int main() {

    int x;
    cin >>x;

    if(400<=x&&x<600) {
        cout<<8<<endl;
    }
    if(600<=x&&x<800) {
        cout<<7<<endl;
    }
    if(800<=x&&x<1000) {
        cout<<6<<endl;
    }
    if(1000<=x&&x<1200) {
        cout<<5<<endl;
    }
    if(1200<=x&&x<1400) {
        cout<<4<<endl;
    }
    if(1400<=x&&x<1600) {
        cout<<3<<endl;
    }
    if(1600<=x&&x<1800) {
        cout<<2<<endl;
    }
    if(1800<=x&&x<2000) {
        cout<<1<<endl;
    }
    

 return 0;
}

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

/*------------------------------------------------------------------*/

#define ll long long int
#define mp make_pair
#define pb push_back
#define MOD 1000000007

bool isvowel(char c)
{
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u')
        return true;
        return false;
}
ll isprime(ll n)
{
    ll ans=1;
    for(ll i=2;i<=sqrt(n);i++)
    {
        if(n%i==0)
            ans = i;
    }
    return ans;
}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    if(b==1)
        return a%m;
    ll temp=power(a,b/2,m);
    if(b%2==0)
        return ((temp%m)*(temp%m))%m;
    else
        return ((((temp%m)*(temp%m))%m)*a%m)%m;
}

/*-----------------------------------------------------------------------------*/

ll c(ll n, ll k)
{
    ll C[n + 1][k + 1];
    ll i, j;

    for (i = 0; i <= n; i++)
    {
        for (j = 0; j <= min(i, k); j++)
        {

            if (j == 0 || j == i)
                C[i][j] = 1;

            else
                C[i][j] = (C[i - 1][j - 1]%MOD +
                          C[i - 1][j])%MOD;
        }
    }
    return C[n][k]%MOD;
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
      return 0;

    while (a > 1)
    {

        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;


        y = x - q * y;
        x = t;
    }
    if (x < 0)
       x += m0;

    return x;
}
ll func(ll n)
{
    ll ans=0;
    for(ll i=2;i*i<=n;i++)
    {
        if(n%i==0)
        {
            if(i/10==0)
                ans+=1+func(i)*func(n/i);
            else
                ans+=func(i)*func(n/i);
        }
    }
    return ans;
}
ll dp[205][205][205];
ll check(ll red[],ll gre[],ll blu[],ll r,ll g,ll b,ll i,ll j,ll k)
{
   if(dp[i][j][k]!=-1)
    return dp[i][j][k]; 
   if(i<r&&j<g&&k<b)
   {
       return dp[i][j][k]=max(red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k),max(gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1),blu[k]*red[i]+check(red,gre,blu,r,g,b,i+1,j,k+1)));
   }
   else if(i<r&&j<g) 
   {
       return dp[i][j][k]=red[i]*gre[j]+check(red,gre,blu,r,g,b,i+1,j+1,k);
   }
   else if(j<g&&k<b)
   {
       return dp[i][j][k]=gre[j]*blu[k]+check(red,gre,blu,r,g,b,i,j+1,k+1);
   }
   else if(i<r&&k<b)
   {
       return dp[i][j][k]=red[i]*blu[k]+check(red,gre,blu,r,g,b,i+1,j,k+1);
   }
   else
   {
       return 0;
   }
}
int main()
{
    ios_base::sync_with_stdio(false);
	cin.tie(NULL);

    //freopen("1.txt","rt",stdin);
    //freopen("output.txt","wwt",stdout);

    ll t;
    t=1;
    //cin>>t;
    //ll t1=0;
    while(t--)
    {
        int r;
        cin>>r;
        double d = 2*acos(0.0) ;
        double ans=2*d*r;
        cout.precision(20);
        cout<<fixed<<ans;
    }
}


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

long long n,l;
vector<long long> a,ans;

bool solve();

int main(){
    cin >> n >> l;
    a.resize(n);
    for(int i = 0;i < n;++i)cin >> a[i];
    if(solve()){
        cout << "Possible" << endl;
        for(int i = 0;i < n-1;++i)cout << ans[i] + 1 << endl;
    }
    else
        cout << "Impossible" << endl;
    return 0;
}

bool solve(){
    for(int i = 0;i + 1 < n;++i)if(a[i] + a[i+1] >= l){
        for(int j = 0;j < i;++j)ans.push_back(j);
        for(int j = n-2;j > i;--j)ans.push_back(j);
        ans.push_back(i);
        return  1;
    }
    return 0;
}

Measured memory_bytes: 2548
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Scanner;

/**
 * @author kumar1
 *
 */
public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		try {
			solve();
		} catch (IOException e) {
			// TODO 自動生成された catch ブロック
			e.printStackTrace();
		}
	}

	/**
	 * @throws IOException 
	 * 
	 */
	private static void solve() throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		//File file = new File("case.txt");
		ArrayList<Integer> list = new ArrayList<Integer>();
		BufferedReader in = new	BufferedReader(new InputStreamReader(System.in));
		String s;
		while((s = in.readLine()) != null) {
			Scanner scan = new Scanner(s);
			int n = 0;
			while(scan.hasNextInt()) {
				n = scan.nextInt();
				list.add(n);
			}
			scan.close();
			if(n == 0)
				break;
		}
		in.close();
		//System.out.println(list);
		int max = 0;
		for(int x : list) {
			if(max < x) {
				max = x;
			}
		}
		
		// max * 2までの篩をつくる
		boolean[] arr = new boolean[max * 2 + 1];
		arr[0] = true;
		for(int i = 2; i < arr.length; i++) {
			if(arr[i] == true)
				continue;
			for(int j = 2; i * j < arr.length; j++) {
				arr[i * j] = true;
			}
		}
		//System.out.println("unko");
		
		// 個数を得る
		int[] ans = new int[list.size() - 1];
		for(int i=0; i < ans.length; i++) {
			ans[i] = getPrimeNum(arr, list.get(i) + 1, list.get(i) * 2);
		}
		
		// 出力
		for(int i=0; i < ans.length; i++) {
			System.out.println(ans[i]);
		}
	}

	/**
	 * @param arr
	 * @param i
	 * @param j
	 * @return
	 */
	private static int getPrimeNum(boolean[] arr, int i, int j) {
		// TODO 自動生成されたメソッド・スタブ
		int ret = 0;
		for(int k = i; k <= j; k++) {
			if(arr[k] == false) {
				ret++;
			}
		}
		return ret;
	}
	
	
	

}

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

int main() {
    char s[4];
    int a[4];
    cin >> s;
    for (int i = 0; i < 4; i++)
        a[i] = s[i] - '0';

    bool plus[3];
    for (int i = 0; i < (1 << 3); i++) {
        int sum = a[0];
        for (int j = 0; j < 3; j++) {
            if ((i >> j) & 1) {
                sum += a[j + 1];
                plus[j] = true;
            } else {
                sum -= a[j + 1];
                plus[j] = false;
            }
            if (sum == 7) {
                printf("%d%c%d%c%d%c%d=7\n", a[0], plus[0]?'+':'-',
                        a[1], plus[1]?'+':'-',
                        a[2], plus[2]?'+':'-',
                        a[3]);
                return 0;
            }
        }
    }
}

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

int main(){
    int num[1024];
    int tmp[512],tmp2[512];
    int n,m,k;
    cin >> n >> m;
    for(int i=1;i<=2*n;i++) num[i-1] = i;
    while(m--){
        cin >> k;
        if(k != 0){
            for(int i=0;i<k;i++) tmp[i] = num[i];
            for(int i=k,value=0;i<2*n;i++,value++) tmp2[value] = num[i];
            for(int i=0;i<2*n-k;i++) num[i] = tmp2[i];
            for(int i=2*n-k,value=0;i<2*n;i++,value++) num[i] = tmp[value];
        }
        else {
            for(int i=0;i<n;i++) tmp[i] = num[i];
            for(int i=n,value=0;i<2*n;i++,value++) tmp2[value] = num[i];
            for(int i=0,value=0;i<2*n;i+=2,value++){
                num[i] = tmp[value];
                num[i+1] = tmp2[value];
            }
        }
    }
    for(int i=0;i<2*n;i++) cout << num[i] << endl;
}

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

int read(){
	int x=0,f=1;
	char c=getchar();
	while(!isdigit(c)){if(c=='-')f=-1;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+c-48;c=getchar();}
	return x*f;
}

int k,m,n;
char c[100],s[100];
int main(){
	scanf("%s",c+1);
	scanf("%s",s+1);
	int num=0;
	if(c[1]==s[1])num++;
	if(c[2]==s[2])num++;
	if(c[3]==s[3])num++;
	printf("%d\n",num);
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
 
int parent(int);
int left(int);
int right(int);
 
int main()
{
  int n,i;
  int A[250];
 
  scanf("%d",&n);
  for(i = 1;i <= n;i++){
    scanf("%d",&A[i]);
  }
 
  for(i = 1;i <= n;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(parent(i) > 0) printf("parent key = %d, ",A[parent(i)]);
    if(left(i) <= n) printf("left key = %d, ",A[left(i)]);
    if(right(i) <= n) printf("right key = %d, ",A[right(i)]);
    printf("\n");
  }
 
  return 0;
}
 
int parent(int i)
{
  return i/2;
}
 
int left(int i)
{
  return 2*i;
}
 
int right(int i)
{
  return 2*i+1;
}

Measured memory_bytes: 600
#include<bits/stdc++.h>
#define F first
#define S second

using namespace std;

typedef pair<int, int> P;
typedef long long LL;
static const int INF = INT_MAX;


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, h, w;
    cin >> n >> h >> w;
    int cnt = 0;
    for(int i = 0; i < n; ++i) {
        int a, b;
        cin >> a >> b;
        if(a >= h && b >= w) ++cnt;
    }
    cout << cnt << endl;

    return 0;
}



Measured memory_bytes: 256
a = int(input())
b = int(input())
c = int(input())
x = int(input())

ans = 0
for i in range(0,a+1):
    for j in range(0,b+1):
        for k in range(0,c+1):
            if 500*i + 100*j + 50*k == x:
                ans += 1
print(ans)

Measured memory_bytes: 3060
#include<cstdio>
#include<vector>
#include<algorithm>

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

using namespace std;

int main(){
	int n,k; scanf("%d%d",&n,&k);
	vector<int> boat[50];
	rep(i,k){
		int m; scanf("%d",&m);
		boat[i].resize(m);
		rep(j,m) scanf("%d",&boat[i][j]), boat[i][j]--;
	}

	bool bad[50]={};
	int n_bad; scanf("%d",&n_bad);
	rep(_,n_bad){
		int u,v; scanf("%d%d",&u,&v), u--, v--;
		rep(i,k) if(count(boat[i].begin(),boat[i].end(),u)==1 && count(boat[i].begin(),boat[i].end(),v)==1) bad[u]=bad[v]=true;
	}
	printf("%d\n",count(bad,bad+n,true));

	return 0;
}

Measured memory_bytes: 0
def examC():
    St = S()
    t = ["dream", "dreamer", "erase", "eraser"]
    i = len(St)-1
    cur = ""
    while i>=0:
#        print(cur)
        cur = St[i] + cur
        i -=1
        if cur in t:
            cur = ""
    if len(cur)==0:
        ans = "YES"
    else:
        ans = "NO"
    print(ans)


import sys
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examC()


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

int main() {
  int N, l, r, answer;
  
  cin >> N;
  
  for ( int i = 0; i < N; i++ ) {
    cin >> l >> r;
	answer += (r - l + 1);
  }
  
  cout << answer << endl;
}


Measured memory_bytes: 256
N = int(input())

digit = [5, 4, 3, 2, 1]
if N < 10:
    print(N)
elif N < 100:
    print(9)
elif N < 1000:
    print(9 + N - 99)
elif N < 10000:
    print(9 + 900)
elif N < 100000:
    print(9 + 900 + N - 9999)
else:
    print(9 + 900 + 90000)

Measured memory_bytes: 3060
while True:
    n,x=list(map(int,input().split()))
    s=0
    if n==x==0:
        break
    
    for i in range(1,n+1):
        for j in range(i+1,n+1):
            for k in range(j+1,n+1):
                if (i+j+k==x):
                    s += 1
    print(s)
            


Measured memory_bytes: 5596
N,W = map(int,input().split())
v = [0]*N;w = [0]*N

for i in range(N):
    v[i],w[i] = map(int,input().split())

value = [0 for i in range(W+1)]
for i in range(N):
    for j in range(W,-1,-1):
        if j<w[i]:
            value[j] = value[j]
        else:
            value[j] = max(value[j],value[j-w[i]]+v[i])

print(value[W])

Measured memory_bytes: 7936
from sys import exit

ii = lambda : int(input())
mi = lambda : map(int,input().split())
li = lambda : list(map(int,input().split()))

n = ii()
ps = li()
cnt = 0
for i in range(n):
    if ps[i] != i+1:
        cnt += 1
if cnt == 0 or cnt == 2:
    print("YES")
else:
    print("NO")

Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>

#define ll long long

int main(){
  ll a, b, n, ans;
  scanf("%lld %lld %lld", &a, &b, &n);

  if(b-1>=n){
    ans = a*n/b - a*(n/b);
  }else{
    ans = a*(b-1)/b - a*((b-1)/b);
  }
  printf("%lld\n",ans);
  return 0;
}

Measured memory_bytes: 1732
#include <iostream>
#include <algorithm>
#include <numeric>
#include "math.h"
#include <string>
#include <vector>
#include <iomanip>

#define pai 3.14159265358979323846264338327950288
using namespace std;



//ROT N
int main() {

	int n;
	string s;
	cin >> n >> s;

	vector<char>h(s.begin(),s.end());

	for (int i = 0; i < h.size(); i++) {
		for (int j = 0; j < n; j++) {
			if (h[i] == 'Z') {
				h[i] = 'A';
				continue;
			}
			h[i]++;
		}
	}
	for (int i = 0; i < h.size(); i++) {
		cout << h[i];
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
//#define LOCAL
#define fastIO ios::sync_with_stdio(0), cin.tie(0)
#define endl '\n'
#define forn(i,a,b) for(ll i=a;i<b;i++)
#define ft first
#define sd second
#define sz size()
#define pb push_back
#define pob pop_back()
#define pf push_front
#define pof pop_front()
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<char,char> pcc;
typedef pair<double,double> pdd;
typedef pair<long long,long long> pll;
//cout << fixed << setprecision(12) <<x<<endl;

const int MAX=1e4;
ll a[MAX];
int main(){
fastIO;
#ifdef LOCAL
     freopen("in.txt", "r", stdin);
#endif
int n;
cin>>n;

forn(i,0,n) cin>>a[i];
if(n==2){
    cout<<0<<endl;
}else{
    sort(a,a+n);
    int c=0;
    forn(i,0,n){
        forn(j,i+1,n){
            forn(k,j+1,n){
                if(a[i]+a[j]>a[k] && a[i]!=a[j] && a[j]!=a[k]) c++;
            }
        }
    }
    cout<<c<<endl;
}


}


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> v(n),c(n);
  rep(i,n) cin >> v[i];
  rep(i,n) cin >> c[i];
  int ans = 0;
  rep(i,n){
    if(v[i]>c[i]) ans += v[i]-c[i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256