akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
using namespace std;

int main()
{
	int num;
	while (scanf("%d", &num), num){
		int map[100][100] = {0};
		
		for (int i = 0; i < num; i++){
			int x, y;
			scanf("%d %d", &x, &y);
			map[x][y] = 1;
		}
		
		int X = 10;
		int Y = 10;
		
		int M;
		scanf("%d", &M);
		for (int i = 0; i < M; i++){
			char c;
			int l;
			scanf(" %c %d", &c, &l);
			
			while (l > 0){
				switch (c){
					case 'N':
					Y++;
					break;
					
					case 'E':
					X++;
					break;
					
					case 'S':
					Y--;
					break;
					
					case 'W':
					X--;
					break;
				}
				num -= map[X][Y];
				map[X][Y] = 0;
				l--;
			}
		}
		
		if (num == 0){
			puts("Yes");
		}
		else {
			puts("No");
		}
	}
	
	return 0;
}

Measured memory_bytes: 1060
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file
#include <ext/pb_ds/tree_policy.hpp> // Including tree_order_statistics_node_update
using namespace __gnu_pbds;
using namespace std;

typedef tree<int, null_type, less<int>, rb_tree_tag,
             tree_order_statistics_node_update>
    ordered_set;

#define f first
#define se second
#define pb push_back
#define mp make_pair
#define vi vector<int>
#define pi pair<int, int>
#define all(x) x.begin(), x.end()
#define lp(i, n) for (int i = 0; i < n; i++)
#define mem(a, v) memset(a, v, sizeof(a))
#define X real()
#define Y imag()
#define angle(a) (atan2(a.Y, a.X))
#define vec(a, b) ((b) - (a))
//#define length(a) (hypot(a.Y , a.X))
#define normalize(a) (a) / length(a)
#define dotP(a, b) ((conj(a) * b).X)
#define crossP(a, b) ((conj(a) * b).Y)
#define same(p1, p2) (dotP(vec(p1, p2), vec(p1, p2)) < EPS)
#define lengthSqr(a) dotP(a, a)
#define rotate0(p, ang) ((p)*exp(point(0, ang)))
#define rotateA(p, ang, about) (rotate0(vec(about, p), ang) + about)
#define reflect0(v, m) conj(v / m) * m
#define IO ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
const double PI = acos(-1.0);
const double EPS = (1e-10);
const long long int INF = 0x3f3f3f3f;
const long long mod = 1e9 + 7;
typedef long long int ll;
typedef unsigned long long ull;
typedef complex<double> point;
long long fastpow(ll n, ll x) {
  if (!x)
    return 1;
  if (x % 2)
    return n * fastpow(n, x - 1);
  ll p = fastpow(n, x / 2);
  p %= mod;
  p *= p;
  p %= mod;
  return p;
}

ll my_mod(ll num, ll mod) {
  ll ret = num % mod;
  while (ret < 0)
    ret += mod;
  return ret;
}

ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
long double dist(pair<ll, ll> &a, pair<ll, ll> &b) {
  return sqrt(
      ((a.f - b.f) * (a.f - b.f) * 1.0 + (a.se - b.se) * (a.se - b.se)));
}
/*vector<int> ap;
bool np[MX];
void s(){
    mem(np , 1);
    np[1] = np[0] = 0;
    for(ll i = 2 ; i*i<= MX ;i++){
        if(np[i]){
            for(ll j= i*i ; j <MX; j+=i) np[j] = 0;
        }
    }
    for(ll i = 2 ; i< MX ; i++) if(np[i]) ap.pb(i);
}*/
const ll MX = 1e5+5;
string s;
int d;
int len;
ll dp[10009][105][2];

ll solve(int digit, int cmod , bool limit = 1){
	if(digit == len) return (cmod == 0);
	ll &ret = dp[digit][cmod][limit];
	if(~ret) return ret;
	ret = 0;
	int bound = 9;
	if(limit) bound = (s[digit] - '0');
	for(int test = 0 ; test <= bound ; test++){
		ret = (ret%mod + solve(digit+1
		,((cmod)%d + test%d)%d,limit&((test+'0')==s[digit])))%mod; 
	 }
	 return ret;	
}
int main()
{
    IO;
	cin>>s;
	len = s.size();
	cin>>d;
	mem(dp,-1);
	ll ans = solve(0,0)-1;
	if(ans <0 ) ans+=mod;
	cout<<ans;
    return 0;
}



Measured memory_bytes: 17536
// ConsoleApplication9.cpp : アプリケーションのエントリ ポイントを定義します。
//


#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include <fstream>

#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end());
#define ll long long
#define pb(a) push_back(a)
#define INF 9999999999
#define m0(x) memset(x,0,sizeof(x))
#define fill(x,y) memset(x,y,sizeof(x))
#define p(x) cout<<x<<endl;
#define pe(x) cout<<x<<" ";
#define lb(v,n) lower_bound(v.begin(), v.end(), n);
//#define int long long


using namespace std;


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




ll gcd(ll x, ll y) {
	ll m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
ll lcm(ll x, ll y) {
	return x / gcd(x, y)*y;
}

ll myPow(ll x, ll n, ll m) {
	if (n == 0)
		return 1;
	if (n % 2 == 0)
		return myPow(x * x % m, n / 2, m);
	else
		return x * myPow(x, n - 1, m) % m;
}

ll pow2(ll a, ll n) {//aのn乗を計算します。
	ll x = 1;
	while (n > 0) {//全てのbitが捨てられるまで。
		if (n & 1) {//1番右のbitが1のとき。
			x = x * a;
		}
		a = a * a;
		n >>= 1;//bit全体を右に1つシフトして一番右を捨てる。
	}
	return x;
}

long long nCr(int n, int r) {
	if (r > n / 2) r = n - r; // because C(n, r) == C(n, n - r)
	long long ans = 1;
	int i;

	for (i = 1; i <= r; i++) {
		ans *= n - r + i;
		ans /= i;
	}

	return ans;
}

const int MAX = 510000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

bool arr[100000100];
vector<ll>sosuu;
void Eratosthenes() {
	ll N = 10000010;
	int c = 0;
	for (int i = 0; i < N; i++) {
		arr[i] = 1;
	}
	for (ll i = 2; i < sqrt(N); i++) {
		if (arr[i]) {
			for (ll j = 0; i * (j + 2) < N; j++) {
				arr[i *(j + 2)] = 0;
			}
		}
	}

	for (ll i = 2; i < N; i++) {
		if (arr[i]) {
			sosuu.pb(i);
			//cout << sosuu[c] << " ";
			c++;
		}
	}
	//cout << endl;
	//cout << c << endl;
}

ll stoL(string s) {
	ll n = s.length();
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans += pow2(10, n - i-1)*(ll)(s[i]-'0');
	}
	return ans;
}

int a[1000100], sum[1000100];
int main() {
	string s;
	cin >> s;
	int N = s.length();
	if (N % 2 == 0) {
		if (s[0] == s[N - 1]) {
			p("First"); return 0;
		}
		else {
			p("Second"); return 0;
		}
	}
	else {
		if (s[0] != s[N - 1]) {
			p("First"); return 0;
		}
		else {
			p("Second"); return 0;
		}
	}
}



Measured memory_bytes: 2560
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long

int A[200010];
int N;

int sad(int b) {
	int ret = 0;
	rep(i, N) ret += abs(A[i] - (b + i + 1));
	return ret;
}



signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
	cin >> N;
	rep(i, N) cin >> A[i];

	int lower = -1000000000;
	int upper = 1000000000;
	int mid;
	while (true) {
		mid = (lower + upper) / 2;
		// cout << sad(mid - 1) << " " << sad(mid) << endl;
		int diff = sad(mid) - sad(mid - 1);
		if (diff < 0) lower = mid + 1;
		else upper = mid;
		if (lower == upper || diff == 0) {
			cout << min({ sad(mid), sad(mid - 1), sad(mid + 1) }) << endl;
			return 0;
		}
	}


    return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>

#define RANK_N 4
#define CARD_N 13

int main(void){
  int c[RANK_N][CARD_N];
  int n;
  char rank;
  int i,j,k;

  for (i = 0; i < RANK_N; i++) {
    for (j = 0; j < CARD_N; j++) {
      c[i][j] = 0;
    }
  }

  scanf("%d", &n);

  for (k = 0; k < n; k++) {
    scanf("%*c%c %d", &rank, &j);
    if      (rank == 'S') i = 0;
    else if (rank == 'H') i = 1;
    else if (rank == 'C') i = 2;
    else if (rank == 'D') i = 3;
    c[i][j-1] = 1;
  }

  for (i = 0; i < RANK_N; i++) {
    for (j = 0; j < CARD_N; j++) {
      if (c[i][j] == 1) continue;
      if      (i == 0) rank = 'S';
      else if (i == 1) rank = 'H';
      else if (i == 2) rank = 'C';
      else if (i == 3) rank = 'D';
      printf("%c %d\n", rank, j+1);
    }
  }

  return (0);
}



Measured memory_bytes: 2056
S = input()
L = len(S)
mod = 10**9+7
dp_c = [0] * L
dp_u = [0] * L
dp_c[0] = 1
dp_u[0] = 2

for i in range(1,L):
    if S[i] == "1":
        dp_c[i] = dp_c[i-1] * 3 + dp_u[i-1]
        dp_u[i] = dp_u[i-1] * 2
    else:
        dp_c[i] = dp_c[i-1] * 3
        dp_u[i] = dp_u[i-1] * 1
    dp_c[i] %= mod
    dp_u[i] %= mod

ans = (dp_c[-1] + dp_u[-1]) % mod
print(ans)


Measured memory_bytes: 11124
#include <iostream>

using namespace std;

int main(){
    int a,b,c;
    cin>>a>>b>>c;
    if(a<b){
        if(b<c){
            cout<<"Yes"<<endl;
        }
        else{
            cout<<"No"<<endl;
        }
    }
    else{
        cout<<"No"<<endl;
    }
}


Measured memory_bytes: 3092
#include<stdio.h>
#include<stdlib.h>

#define NIL NULL

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeSearch(Node , int );
void insert(int);
void inorder(Node);
void preorder(Node);

int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    }
  }

  return 0;
}

Node treeSearch(Node n, int k){
	while( n != NIL && k != n->key){
		if( k < n->key) n = n ->left;
		else n = n->right;
	}
	return n;
}

void insert(int num){
  Node x = root;
  Node y = NIL;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = num;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z ->key < x ->key){
      x = x->left;
    }
    else{
      x = x->right;
    }
  }
  z->parent = y;
if(y == NIL){
  root = z;
}
  else{
    if( z->key < y->key){
      y->left = z;
    }
    else{
      y->right = z;
    }
  }
}

void inorder(Node n){
  if(n== NIL)return;
  inorder(n -> left);
  printf(" %d",n -> key);
  inorder(n -> right);
}

void preorder(Node n){
  if(n == NIL)return;
	printf(" %d",n->key);
	preorder(n->left);
	preorder(n->right);
}



Measured memory_bytes: 20456
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
#include <iterator>

using namespace std;

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back

#if DEBUG
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#else
#define _DEBUG(x) ;
#define _DDEBUG(x,y) ;
#endif

#define ll long long
#define ull unsigned long long
#define MOD 1000000007

/** FOR VECTOR DEBUG */
template <typename T>
ostream& operator<< (ostream& out, const vector<T>& v) {
    if ( !v.empty() ) {
        out << '[';
        copy (v.begin(), v.end(), ostream_iterator<T>(out, ", "));
        out << "\b\b]";
    }
    return out;
}


/* template end */


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

    int r;
    cin >> r;
    string ans = "ABC";
    if(r >= 2800) {
        ans[1] = 'G';
    } else if(r >= 1200) {
        ans[1] = 'R';
    }

#if DEBUG
    cout << "** RESULT **" << endl; // debug
#endif
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <unordered_map>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <queue>

using namespace std;

struct task {
  int a;
  int b;
};

int main() {
  int n,m;
  cin >> n >> m;
  
  vector<task> tasks(n);
  for (int i = 0; i < n; i++) {
    int a,b;
    cin >> a >> b;
    tasks[i] = {a,b};
  }
  
  //払いが早い仕事の順に並べる
  sort(tasks.begin(), tasks.end(), [](task t1, task t2)-> bool{
    return t1.a < t2.a;
  });

  // priority_queueに任意の順序(Compare)を設定する場合は、型(template)も設定する必要がある (decltype)
  auto c = [](task t1, task t2)-> bool{
    return t1.b < t2.b; // いい仕事順
  };
  std::priority_queue<task, std::vector<task>, decltype(c)> que(c);

  int result = 0;
  int current = 0;
  for (int mm = 1; mm <= m; mm++) { // 1日前から逆に計算
    // mm日前に間に合う、最大の仕事をする
    
    for (; current < tasks.size(); current++) {
      if (tasks[current].a > mm) {
        break; // 払いが早い順に並んでいるので、続きは次のmmで
      }

      // 間に合う仕事をどんどん追加していく
      que.push(tasks[current]);
    }
    
    if (!que.empty()) {
      result += que.top().b; // 一番いい仕事をする
      que.pop();
    }
  }
  
  cout << result << endl;
  
  return 0;
}


Measured memory_bytes: 2168
// Believe in yourself...
#include<bits/stdc++.h>
#define MP make_pair
#define PB push_back
#define PF push_front
#define POB pop_back
#define POF pop_front
#define F first
#define S second
#define sz(c) (c).size()
#define REP(i,n)  for(ll i=0;i<n;i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=b;i++)
#define FORD(i,a,b) for(ll i=a;i>=b;i--)

#define bit(num,i) ((num>>i)&1)

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> pll;

const ll inf=4e18;
const ll maxn=310;

#pragma GCC Optimize("Ofast")

deque<string> dq;
ll ans,n;

bool check(ll num){
	REP(i,n){
		REP(j,n){
			if(dq[i][j]!=dq[j][i])
				return 0;
		}
	}
	return 1;
}

int main(){
	cin>>n;
	REP(i,n){
		string s;
		cin>>s;
		dq.PB(s);
	}
	REP(i,n){
		dq.PB(dq.front());
		dq.POF();
		ans+=check(i);
	}
	cout<<(ans*n);
}

Measured memory_bytes: 384
n=int(input())
As=list(map(int,input().split()))
Bs=list(map(int,input().split()))
Bs.append(0)

ans=0
for i in range(n):
  c=As[i]+As[i+1]
  if c>Bs[i]:
    ans+=Bs[i]
    if Bs[i]>As[i]:
      As[i+1]-=Bs[i]-As[i]
  else:
    ans+=c
    As[i+1]=0
print(ans)

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

vector<int> con[111];
int n;


int buf[111];
int mxlen;
int dim[111];

void dfs(int u, int p, int d)
{
    buf[d] = u;
    if (d > mxlen) {
        mxlen = d;
        for (int i = 1; i <= mxlen; i++)
            dim[i] = buf[i];
    }

    for (int to: con[u]) {
        if (to == p)continue;
        dfs(to, u, d + 1);
    }
}

int mxd[111];

void dfs2(int u, int p, int d)
{
    int ch = 0;
    for (int to: con[u]) {
        if (to == p)continue;

        ch++;
        dfs2(to, u, d + 1);
    }
    mxd[d] = max(mxd[d], ch);
}

int main()
{
    cin >> n;

    for (int i = 1; i < n; i++) {
        int x, y;
        cin >> x >> y;
        con[x].push_back(y);
        con[y].push_back(x);
    }

    mxlen = 0;
    dfs(1, 0, 1);

    int u = dim[mxlen];
    mxlen = 0;
    dfs(u, 0, 1);

    long long ans1 = (mxlen + 1) / 2, ans2;
    if (mxlen % 2 == 0) {
        dfs2(dim[mxlen / 2], dim[mxlen / 2 + 1], 0);
        dfs2(dim[mxlen / 2 + 1], dim[mxlen / 2], 0);
        ans2 = 2;
        for (int i = 0; mxd[i]; i++) {
            ans2 *= mxd[i];
        }
    } else {
        long long tmp = 1;
        int root = dim[mxlen / 2 + 1];
        dfs2(root, 0, 0);
        for (int i = 0; mxd[i]; i++) {
            tmp *= mxd[i];
        }
        for (int to: con[root]) {
            memset(mxd, 0, sizeof(mxd));
            dfs2(root, to, 0);
            dfs2(to, root, 0);
            long long x = 2;
            for (int i = 0; mxd[i]; i++) {
                x *= mxd[i];
            }
            if (x < tmp)
                tmp = x;
        }
        ans2 = tmp;
    }

    cout << ans1 << ' ' << ans2 << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	int m, k; cin >> m >> k;
	if(m <= 1){
		if(k == 0){
			for(int i = 0; i < 1<<m; i++) cout << i << " " << i << " "; cout << endl;
		} else {
			cout << -1 << endl;
		}
	} else {
		if(k < (1<<m)){
			deque<int> ans;
			ans.push_back(k);
			for(int i = 0; i < 1<<m; i++) if(i != k){
				ans.push_back(i);
				ans.push_front(i);
			}
			ans.push_back(k);
			while(!ans.empty()){
				cout << ans.back() << endl;
				ans.pop_back();
			}
		} else {
			cout << -1 << endl;
		}
	}
	return 0;
}

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

int main(){
    int N;
    cin>>N;
    int x=N/100;
    int a=100*x+10*x+x;
    if(N<=a){
        cout<<a<<endl;
    }else{
        cout<<a+111<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

typedef long long ll;

/////////////         modの計算
const ll mod = 1000000007LL;

class modlong {
public:
	modlong() { x = 0; }
	modlong(ll num) { x = num; }
	inline operator ll() const { return x; }
	inline void operator = (ll num) { x = num; }
	inline void operator += (ll num) { x += num; }
	inline void operator *= (ll num) { x = adjust(x * num); }
	inline modlong operator * (ll num) { modlong m(adjust(x * num)); return m; }
	inline ll adjust(ll a) {
		if (a >= mod) { return a % mod; }
		return a;
	}
	ll x;
};

constexpr int K = 16;

constexpr ll v_e[] = { 0, 765144583, 346175634, 347662323, 5655049, 184117322, 927321758, 444014759, 542573865, 237315285, 417297686, 471090892, 183023413, 660103155, 727008098, 869418286 };
constexpr ll v_o[] = { 539588932, 729548371, 700407153, 404391958, 962779130, 184117322, 927321758, 444014759, 542573865, 237315285, 417297686, 471090892, 183023413, 660103155, 727008098, 869418286 };

int main() {
	int T; scanf("%d", &T);
	for (int _t = 0; _t < T; _t++) {
		ll N; scanf("%ld", &N);
		modlong ans = 0;
		modlong x = 1;

		if (N & 1) {// odd
			for (int i = 0; i < K; i++) {
				ans += x * v_o[i];
				x *= N;
			}
		}
		else {// even
			for (int i = 0; i < K; i++) {
				ans += x * v_e[i];
				x *= N;
			}
		}
		printf("%ld\n", ans.x % mod);
	}

	return 0;
}


Measured memory_bytes: 1704
while True:
  n = int(input())
  if n == 0:
    break

  scr = list(map(int, input().split()))
  avg = sum(scr) / n
  v = 0
  for scri in scr:
    v += ((scri - avg) ** 2 ) / n
  a = v ** 0.5
  print(a)


Measured memory_bytes: 5664
#include <vector>
#include <iostream>
using namespace std;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<bool> dp(K + 1);
	for (int i = 1; i <= K; ++i) {
		for (int j = 0; j < N; ++j) {
			if (i >= A[j] && !dp[i - A[j]]) {
				dp[i] = true;
			}
		}
	}
	cout << (dp[K] ? "First\n" : "Second\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
//repマクロ定義
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
//allマクロ定義
#define all(v) v.begin(),v.end()
using namespace std;

int main(){
  int n,a,b,ans=0;
  cin >> n >> a >>b;
  for(int i=1;i<=n;i++){
    int x=i,t=0;
    while(x!=0){
      t+=x%10;
      x/=10;
    }
    if(t>=a && t<=b)  ans+=i;
  }

  cout << ans <<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <string>
#include <cstring>
#include <cstdlib>
#include <queue>
#include <cmath>
#include <stack>
#include <iterator>
#include <bitset>
#include <iomanip>
#include <sstream>
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define read freopen("input.txt","r",stdin);
#define write freopen("out.txt","w",stdout);
#define showtime cout << 1000.0 * clock() / CLOCKS_PER_SEC << " ms" << endl; 
#define pfi(a) printf("%d\n", a)
#define pfl(a) printf("%lld\n", a)
#define pfc(a) printf("%c\n", a)
#define pf printf
#define sc scanf
#define new "\n"
using namespace std;
typedef pair<int, int> poii;
typedef pair<string , int> posi;
typedef map<int, int> moii;
typedef map<string, int> mosi;
typedef long long ll;
typedef unsigned long long ull;
typedef set<int>soi;
typedef set<string>sos;
typedef set<char> soc;
typedef vector<string> vos;
typedef vector <int> voi;
#define pi acos(-1.0)
int main() 
{
    // fast;
    int a, b, c;
    sc("%d%d%d", &a, &b, &c);
    a + b + c >= 22 ? puts("bust") : puts("win");
    // showtime;                    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
A = []
A.append(list(map(int, input().split())))
A.append(list(map(int, input().split())))

total = []

for i in range(N) :
    total.append(sum(A[0][0:i+1]) +sum(A[1][i:N]))

print(max(total))


Measured memory_bytes: 3316
#include <iostream>
#include <math.h>
#include <algorithm>
#include <string>
#include <string.h>
#include <queue>
#include <vector>
#include <set>
using namespace std;
int main() {
	int N, M,c=0;
	char S[50][50], T[50][50];
	bool ans = false;
	cin >> N >> M;
	for (int i = 0; i < N; i++)for (int j = 0; j < N; j++)cin >> S[i][j];
	for (int i = 0; i < M; i++)for (int j = 0; j < M; j++)cin >> T[i][j];
	for (int i = 0; i < N-M+1; i++)
	{
		for (int j = 0; j < N-M+1; j++)
		{
			bool flag = false;
			c = 0;
			for (int k = 0; k < M; k++)
			{
				for (int l = 0; l < M; l++)
				{
					if (T[k][l] == S[k + i][l + j]) {
						flag = true;
						c++;
					}
					else flag = false;
					if (!flag)break;
					if (c == M*M)ans = true;
					if (ans)break;
				}
				if (!flag)break;
				if (ans)break;
			}
			if (ans)break;
		}
		if (ans)break;
	}
	cout << (ans ? "Yes" : "No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
  int n,m,x;
  cin >> n >> m >> x;
  int a[n][m];
  int c[n];
  rep(i,n+1){
    cin >> c[i];
    rep(j,m){
      cin >> a[i][j];
    }
  }
  int ans=1e9;
  for(int bit=0;bit<(1<<n);bit++){
    int mini=0;
    vector<int> is(m);
    rep(i,n){
      if(bit&(1<<i)){
        mini+=c[i];
        for(int j=0;j<m;j++){
          is.at(j)+=a[i][j];
        }
      }
    }
    bool pq=true;
    for(int j=0;j<m;j++){
      if(is.at(j)<x){
        pq=false;
      }
    }
    if(pq){
      ans=min(ans,mini);
    }
  }
  if(ans==1e9){
    ans=-1;
  }
  cout <<ans;
}


Measured memory_bytes: 3580
#include <bits/stdc++.h>
#define dum(x) cout<<#x<<'='<<x<<endl
#define ll long long
using namespace std;

int main() {
  int n, x;
  cin >> n >> x;
  ll c_all = 0;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a.at(i);
    c_all += a.at(i);
  }
  if (a.at(0) > x) a.at(0) = x;
  for (int i = 0; i < n - 1; i++) {
    if (a.at(i) + a.at(i + 1) > x) {
      ll tmp = a.at(i) + a.at(i + 1) - x;
      a.at(i + 1) -= tmp;
    }
  }
  ll c_min = accumulate(a.begin(), a.end(), 0LL);
  cout << c_all - c_min << endl;

}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int n;
long long ans;
map<string,long long>vis;
string st;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	getline(cin,st);
	for(int i=1;i<=n;++i){
		getline(cin,st);
		sort(st.begin(),st.end());
		ans+=vis[st];
		vis[st]++;	
	}
	printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 11264
#include <stdio.h>

void solve (long long int n) {
    n--;
    if (n >= 26) {
        solve(n / 26);
    }
    putchar(n % 26 + 'a');
}

main () {
    long long int n;
    scanf("%lld", &n);
    solve(n);
    puts("");
    return 0;
}


Measured memory_bytes: 1620
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>

using namespace std;

int const INT_MAX = 10000000;

int main(){
	
	while(true){
		
		int n;
		
		cin >> n;
		
		if(n == 0){
			break;
		}
		
		for(int loop = 0; loop < n; loop++){
			int x1, y1, z1, w1, x2, y2, z2, w2;
			cin >> x1 >> y1 >> z1 >> w1 >> x2 >> y2 >> z2 >> w2;
			int x3, y3, z3, w3;
			x3 = x1 * x2 - y1 * y2 - z1 * z2 - w1 * w2;
			y3 = x1 * y2 + y1 * x2 + z1 * w2 - w1 * z2;
			z3 = x1 * z2 + z1 * x2 - y1 * w2 + w1 * y2;
			w3 = x1 * w2 + w1 * x2 + y1 * z2 - z1 * y2;
			cout << x3 << " " << y3 << " " << z3 << " " << w3 << endl;
		}
		
	}
	return 0;
}

Measured memory_bytes: 3048
#include<bits/stdc++.h>
int num[1000+3];
const int mod = 1000000000 + 7;
int main()
{
	int n;
	scanf("%d", &n);
	
	for(int i = 2;i <= n; i++)
	{
		int val = i;
		for(int k = 2; k <= i; k++)
		{
			if(val % k == 0)
			{
				while(val % k == 0)
				{
					val /= k;
					num[k]++;
				}
			}
		}
		if(val != 1)
			num[val]++;
		
	}
	long long ans = 1;
	for(int i = 2; i <= n; i++)
	{
		if(num[i])
			{
				ans = ans * (num[i] + 1)%mod;	
			}
	}
	printf("%lld\n", ans);
		
	
	
	
	return 0;
 } 

Measured memory_bytes: 256
from collections import Counter
mod = 998244353

N = int(input())
D = list(map(int,input().split()))

if not(D.count(0) == 1 and D[0] == 0):
    print(0)
    exit()

D = sorted(D)
c = Counter()
c[-1] += 1
ans = 1

for d in D:
    ans *= c[d-1]
    ans %= mod
    c[d] += 1

print(ans)

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

int main()
{
  int N;
  cin >> N;
  vector<long long> A(N), B(N);
  for (int i = 0; i < N; i++)
    cin >> A[i] >> B[i];
  // sort
  sort(A.begin(), A.end());
  sort(B.begin(), B.end());
  if (N % 2)
  {
    long long mi = A[N / 2], ma = B[N / 2];
    cout << ma - mi + 1 << endl;
  }
  else
  {
    long long mi = A[N / 2 - 1] + A[N / 2];
    long long ma = B[N / 2 - 1] + B[N / 2];
    cout << ma - mi + 1 << endl;
  }
}


Measured memory_bytes: 6420
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <vector>
#include <regex>
#include <map>
#include <set>
#include <iomanip>

using namespace std;
using ll = long long;

int main() {
    int N;
    cin >> N;
    
    int a[100001];
    
    for(int i=1;i<=N;i++){
        cin >> a[i];
    }
    int ans = 0,i = 1;
    while(ans<N){
        i = a[i];
        ans++;
        if(i == 2){
            cout << ans << endl;
            return 0;
        }
    }
        cout << -1 << endl;
    return 0;
}


Measured memory_bytes: 640
import java.util.*;

public class Main{
	public static void main(String args[]) {

		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		ArrayList<ArrayList<Integer>> light = new ArrayList<>();
		
		for(int i = 0; i < M; i++) {
			ArrayList<Integer> l = new ArrayList<>();
			int k = sc.nextInt();
			for(int j = 0; j < k; j++) {
				l.add(sc.nextInt() - 1);
			}
			light.add(l);
		}
		
		int[] ok = new int[M];
		for(int i = 0; i < M; i++) {
			ok[i] = sc.nextInt();
		}
		
		int count = 0;
		
		for (int i = 0; i < (Math.pow(2, N)); i++) {
			int[] sw = new int[N];
			Arrays.fill(sw, 0);
			for (int j = 0; j < N; j++) {
				if ((1 & i >> j) == 1) {
					sw[j] = 1;
				}
			}
			
			boolean flag = true;
			for(int j = 0; j < M; j++) {
				int sum = 0;
				for(int k = 0; k < light.get(j).size(); k++) {
					sum += sw[light.get(j).get(k)];
				}
				if(sum % 2 != ok[j]) {
					flag = false;
					break;
				}
			}
			if(flag)count++;
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 21844
require 'pp'

# 入力値を数値で返却する
def gets_i()
  gets.chomp.to_i
end

N = gets_i
A = gets_i
B = gets_i
C = gets_i
D = gets_i
E = gets_i

abcde = [A, B, C, D, E]
min   = abcde.min
min_index = abcde.index(min)

count = (N.to_f / min).ceil

if count > 1
  puts count - 1 + 5
else
  puts 5
end

Measured memory_bytes: 2044
s=input()

if s == 'SUN':
    print('7')
elif s == 'MON':
    print('6')
elif s == 'TUE':
    print('5')
elif s == 'WED':
    print('4')
elif s == 'THU':
    print('3')
elif s == 'FRI':
    print('2')
elif s == 'SAT':
    print('1')    

Measured memory_bytes: 3060
import java.util.Scanner;

class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  private static Scanner sc = new Scanner(System.in);

  private void run() {
    int X = Integer.parseInt(sc.next());
    int Y = Integer.parseInt(sc.next());
    int Z = Integer.parseInt(sc.next());

    int man = X / Y;

    while (true) {
      if (man * Y + Z * (man + 1) > X) {
        man--;
      } else {
        break;
      }
    }
    System.out.println(man);
  }
}


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

int n, m, q;
vector<int> a, b, c, d;

int dfs(int cnt, vector<int> r) {
  int l = r.back(), ret = 0;
  if(cnt == n) {
    for(int i = 0; i < q; i++)
      if(r[b[i]] - r[a[i]] == c[i]) ret += d[i];
  } else {
    r.push_back(0);
    for(int i = l; i <= m; i++) {
      r.back() = i;
      ret = max(ret, dfs(cnt + 1, r));
    }
  }
  return ret;
}

int main() {
  scanf("%d %d %d", &n, &m, &q);
  a = vector<int>(q), b = vector<int>(q), c = vector<int>(q),
  d = vector<int>(q);
  for(int i = 0; i < q; i++) {
    scanf("%d %d %d %d", &a[i], &b[i], &c[i], &d[i]);
    a[i]--, b[i]--;
  }
  int o = 0;
  for(int i = 1; i <= m; i++) {
    vector<int> r(1, i);
    o = max(o, dfs(0, r));
  }
  printf("%d\n", o);
}

Measured memory_bytes: 3796
import sys
from collections import namedtuple
from itertools import starmap
readline = sys.stdin.readline
EPS = 1e-9
class Segment(object):
    __slots__ = ('fi', 'se')
    def __init__(self, fi, se):
        self.fi = fi
        self.se = se
def cross(a, b):
    return a.real * b.imag - a.imag * b.real
def dot(a, b):
    return a.real * b.real + a.imag * b.imag
def norm(base):
    return abs(base) ** 2
def project(s, p2):
    base = s.fi - s.se
    r = dot(p2 - s.fi, base) / norm(base)
    return s.fi + base * r
def reflect(s, p):
    return p + (project(s, p) - p) * 2.0
def ccw(p1, p2, p3):
    a = p2 - p1
    b = p3 - p1
    if cross(a, b) > EPS: return 1
    if cross(a, b) < -EPS: return -1
    if dot(a, b) < -EPS: return 2
    if norm(a) < norm(b): return -2
    return 0
def intersect4(p1, p2, p3, p4):
    return (ccw(p1, p2, p3) * ccw(p1, p2, p4) <= 0 and
			ccw(p3, p4, p1) * ccw(p3, p4, p2) <= 0)
def intersect2(s1, s2):
    return intersect4(s1.fi, s1.se, s2.fi, s2.se)
def getDistance(a, b):  return abs(a - b)
def getDistanceLP(l, p):
    return abs(cross(l.se - l.fi, p - l.fi) / abs(l.se - l.fi))
def getDistanceSP(s, p):
    if dot(s.se - s.fi, p - s.fi) < 0.0: return abs(p - s.fi)
    if dot(s.fi - s.se, p - s.se) < 0.0: return abs(p - s.se)
    return getDistanceLP(s, p)
def getDistances(s1, s2):
    if intersect2(s1, s2): return 0.0
    return min(getDistanceSP(s1, s2.fi), getDistanceSP(s1, s2.se),
               getDistanceSP(s2, s1.fi), getDistanceSP(s2, s1.se))
n = int(readline())
for _ in [0] * n:
    li = tuple(map(int, readline().split()))
    p0, p1, p2, p3 = (x + y * 1j for x, y in zip(li[::2], li[1::2]))
    s1 = Segment(p0, p1)
    s2 = Segment(p2, p3)
    print("{0:.10f}".format(getDistances(s1, s2)))

Measured memory_bytes: 8288
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=200000;

int n,T;
int t[MAXN];

void run() {
	scanf("%d%d",&n,&T);
	REP(i,n) scanf("%d",&t[i]);
	int ret=0;
	for(int at=0,to=at;at<n;at=to) {
		while(to<n&&(at==to||t[to]-t[to-1]<=T)) ++to;
		ret+=t[to-1]+T-t[at];
	}
	printf("%d\n",ret);
}

int main() {
	run();
	return 0;
}


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

using namespace std;

int main()
{
   char s[1000001];
   long long int i, sum=0;
   cin>>s;
   for(i=0; i<strlen(s); i++)
   {
       sum=sum+s[i]-48;
   }
   if(sum%9==0) cout<<"Yes\n";
   else cout<<"No\n";
}


Measured memory_bytes: 3792
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll n;
ll a[2002];
const ll  M =  4e6 + 2;
bitset< M > B;
int main()
{
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
        B.set(0);
        cin >> n;
        ll sum = 0;
        for(ll i = 1  ; i <= n ; i++) {
                cin >> a[i];
                sum += a[i];
                B = B | (B << a[i]);
        }
        sum = (sum + 1) / 2;
        for(;;sum++){
                if(B[sum]) {
                        cout << sum << endl; return 0;
                }
        }
        return 0;
}


Measured memory_bytes: 2304
import math
L, R = map(int, input().split())
if (R - L + 1) > 673:
  print(0)
else:
  i = L
  min = 2020
  while(i < R):
    j = i + 1
    while(j <= R):
      tmp = i * j % 2019
      if(min > tmp):
        min = tmp
      j += 1
    i += 1
  print(min)

Measured memory_bytes: 3060
'''input
9
basic
c
cpp
php
python
nadesico
ocaml
lua
assembly
'''
from sys import exit
s = set()
n = input()
arr = [raw_input().strip() for i in range(n)]
l = arr[0][-1]
s.add(arr[0])
for i in range(1,n):
	if arr[i][0] == l and (arr[i] not in s):
		s.add(arr[i])
		l = arr[i][-1]
	else:
		print "No"
		exit(0)
print "Yes"



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

using int32 = int_fast32_t;
using int64 = int_fast64_t;

const int32 INF = 1e9;
const int32 MOD = 1e9+7;
const int64 LLINF = 1e18;

#define YES(n) cout << ((n) ? "YES\n" : "NO\n"  )
#define Yes(n) cout << ((n) ? "Yes\n" : "No\n"  )
#define ANS(n) cout << (n) << "\n"
#define REP(i,n) for(int64 i=0;i<(n);++i)
#define FOR(i,a,b) for(int64 i=(a);i<(b);i++)
#define FORR(i,a,b) for(int64 i=(a);i>=(b);i--)
#define ALL(obj) (obj).begin(),(obj).end()
#define pii pair<int32,int32>
#define pll pair<int64,int64>
#define pb(a) push_back(a)
#define mp make_pair

vector<vector<int32>> adj;

int64 dfs(int32 x){
    if(adj[x].size() == 0){
        return 0;
    }
    if(adj[x].size() == 1){
        return dfs(adj[x][0]) + 1;
    }
    vector<int32> ls;
    REP(i,adj[x].size()){
        ls.pb(dfs(adj[x][i]) + 1);
    }
    sort(ALL(ls));
    REP(i,adj[x].size()){
        ls[i] += (adj[x].size() - i - 1);
    }
    sort(ALL(ls));
    return ls.back();
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int32 n;
    cin >> n;
    adj.resize(n);
    FOR(i,1,n){
        int32 a;
        cin >> a;
        a--;
        adj[a].pb(i);
    }
    cout << dfs(0) << endl;
    return 0;
}

Measured memory_bytes: 15104
import static java.util.Comparator.naturalOrder;
import static java.util.stream.Collectors.toList;
import java.util.*;
import java.util.Map.Entry;
import java.util.stream.IntStream;

public class Main{
	static final Scanner s=new Scanner(System.in);
	static IntStream REPS(int v){return IntStream.range(0,v);}
	static IntStream INS(int n){return REPS(n).map(i->getInt());}
	static int getInt(){return Integer.parseInt(s.next());}
	public static void main(String[]$){
		int n=getInt(),m=getInt();
		List<List<Integer>>a=REPS(n).mapToObj(i->INS(m).boxed().collect(toList())).collect(toList());
		HashMap<Integer,Integer>count=new HashMap<>();
		int r=n;
		for(int i=0;i<m-1;++i){
			count.clear();
			for(int j=0;j<n;++j)
				count.merge(a.get(j).get(0),1,Integer::sum);
			r=Math.min(r,count.values().stream().max(naturalOrder()).get());
			Integer remove=count.entrySet().stream().max(Entry.comparingByValue()).get().getKey();
			a.stream().forEach(o->o.remove(remove));
		}
		System.out.println(r);
	}
}

Measured memory_bytes: 49656
#include<bits/stdc++.h> 
//compiling code: g++ test.cpp(file) -o script(output) -std=c++11(version) -O2(make it 2x faster)
using namespace std;

int N, A[10];

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

    sort(A, A+N);
    int highest = A[N-1]/2;

    int total = 0;
    for (int i=0; i<N-1; i++){
        total += A[i];
    }

    cout << total + highest;

    return 0;
}

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

string str = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";

int main(int argc, const char * argv[]) {
    while(1){
        int n; cin >> n;
        if(!n) break;
        
        int back[100] = {0};
        for(int i = 0; i < n; i++){
            cin >> back[i];
        }
        
        string memo; cin >> memo;
        for(int i = 0; i < memo.size(); i++){
            int idx = str.find(memo[i]) - back[i%n];
            if(idx < 0) idx += str.size();
            cout << str[idx];
        }
        cout << endl;
        
    }
}

Measured memory_bytes: 1212
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<ctime>
#include<cctype>
#include<climits>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<memory>
#include<functional>

using namespace std;

#define ALL(g) (g).begin(),(g).end()
#define REP(i, x, n) for(int i = x; i < n; i++)
#define rep(i,n) REP(i,0,n)
#define F(i,j,k) fill(i[0],i[0]+j*j,k)
#define P(p) cout<<(p)<<endl;
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define INF 1<<25
#define pb push_back

typedef vector<int> vi;
typedef vector<long long> vl;
typedef vector<double> vd;
typedef pair<int, int> pii;
typedef pair<long, long> pll;
typedef long long ll;

int main() {
	int a, b;
	cin >> a >>b;
	cout << a*b << " "<< 2 * a + 2 * b << endl;
	return 0;
}

Measured memory_bytes: 1164
#include <bits/stdc++.h>
using namespace std;
const int N = 1e6 + 7, mod = 1e9 + 7;
#define debug(x) cerr << #x << " " << x << "\n";
int t[N];
int rep[N];

int re(int x) {
	if(rep[x] != x) rep[x] = re(rep[x]);
	return rep[x];
}

void uni(int a, int b) {
	rep[re(a)] = re(b);
}

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie();
	int n, k;
	cin >> n >> k;
	set <int> S;
	for(int i = 0; i <= n; i++) rep[i] = i;

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

	for(int i = 0; i < n; i++) {
		S.insert(t[i]);
		if(i >= k + 1) S.erase(S.find(t[i - k -1]));
		if((*S.begin()) == t[i - k] && (*prev(S.end())) == t[i]) uni(i - 1, i);
	}

	int ost = 0;
	for(int i = 1; i < n; i++) {
		if(t[i] < t[i - 1]) ost = i;
		if(i - ost >= k - 1) uni(i, 0);
	}

	set <int> ss;
	for(int i = k - 1; i < n; i++) {
		ss.insert(re(i));
	}

	cout << ss.size();
}

Measured memory_bytes: 17664
#include<iostream>
#include <algorithm>
#include<string>
#include <numeric>
#include<math.h>
#include <bits/stdc++.h>
using namespace std;

int main(void) {
    int a1[]{0,1,3,1,2,1,2,1,1,2,1,2,1};
    int a,b;
    cin>>a>>b;
    if(a1[a]==a1[b])cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast") 
#include<bits/stdc++.h>
#define l(i,a,b) for(auto i=a;i<b;i++)
#define lr(i,a,b) for(auto i=a;i>=b;i--)
#define ll long long
#define lli long long int
#define ld long double
#define vec vector<int>
#define mii map<ll,ll>
#define vl vector<long long>
#define se set <long long int>
#define pi pair<long long,long long>
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define all(v) v.begin(), v.end()
#define in(x) cin>>x
#define o(x) cout<<x
#define SYNC ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define PI 3.14159265359
using namespace std;
 


int main()
{
    SYNC
    //clock_t tStart = clock();
    
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    ll n,k,d; in(n)>>k>>d;
    ll ans;
    n=abs(n);
    ll y=min(n/d, k);
    k-=y;
    n-=(y*d);
    if(k%2)
    {
        ans=min(abs(n-d), abs(n+d));
    }
    else
    {
        ans=n;
        if(k>0)
            ans=min(ans, abs(n-(2*d)));
    }
    o(ans)<<endl;








    //printf("Time taken: %.2fs\n", (double)(clock() - tStart)/CLOCKS_PER_SEC);   
}


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


void solve(long long r){
    cout << r*r << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long r;
    scanf("%lld",&r);
    solve(r);
    return 0;
}


Measured memory_bytes: 3696
#include <stdio.h>

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

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

    int a, b;
    int ma[n];
    for(int i = 0; i < n; i++){
        ma[i] = 0;
    }

    for(int i = 0; i < m; i++){
        scanf("%d %d", &a, &b);
        if(h[b-1] >= ma[a-1]){
            ma[a-1] = h[b-1];
        }
        if(h[a-1] >= ma[b-1]){
            ma[b-1] = h[a-1];
        }
    }

    int cnt = 0;
    for(int i = 0; i < n; i++){
        if(h[i] > ma[i]){
            cnt++;
        }
    }
    printf("%d", cnt);
}

Measured memory_bytes: 2512
#!/usr/bin/ruby                                                                                                                                                           
# -*- coding: utf-8 -*-                                                                                                                                                   

issue = {}
issue.default = 0
n = gets.to_i
n.times {
  product = gets.split(' ')
  issue[product[0]] += product[1].to_i
}

i = issue.keys.sort {|l, r|
  if l.length < r.length
    -1
  elsif l.length == r.length
    l <=> r
  else
    1
  end
}

i.each{ |x|
  puts "#{x} #{issue[x]}"
}

Measured memory_bytes: 6108
use num;
use proconio::{fastout, input};

struct Binomial<T> {
    mod_n: T,
    fact: Vec<T>,
    fact_inv: Vec<T>,
    inv: Vec<T>,
}

impl<T> Binomial<T>
where
    T: num::PrimInt,
{
    pub fn new(size: usize, mod_n: T) -> Binomial<T> {
        let mut init = Binomial {
            mod_n,
            fact: Vec::with_capacity(size + 5),
            fact_inv: Vec::with_capacity(size + 5),
            inv: Vec::with_capacity(size + 5),
        };
        init.fact.push(T::from(1).unwrap());
        init.fact.push(T::from(1).unwrap());
        init.fact_inv.push(T::from(1).unwrap());
        init.fact_inv.push(T::from(1).unwrap());
        init.inv.push(T::from(1).unwrap());
        init.inv.push(T::from(1).unwrap());
        for i in 2..size + 5 {
            init.fact
                .push(init.fact[i - 1] * T::from(i).unwrap() % mod_n);
            init.inv.push(
                mod_n
                    - init.inv[mod_n.to_usize().unwrap() % i] * (mod_n / T::from(i).unwrap())
                        % mod_n,
            );
            init.fact_inv
                .push(init.fact_inv[i - 1] * init.inv[i] % mod_n);
        }
        init
    }

    pub fn calc(&self, n: usize, k: usize) -> T {
        self.fact[n] * (self.fact_inv[k] * self.fact_inv[n - k] % self.mod_n) % self.mod_n
    }
}

#[fastout]
fn main() {
    input! {
        n: usize,
        m: usize,
        k: usize
    }

    let mod_num: i64 = 1000_000_007;
    let binomial = Binomial::new(n * m, mod_num);

    let mut ans = 0;
    for d in 1..n {
        ans += d * (n - d) * m * m % mod_num as usize;
        ans = ans % mod_num as usize;
    }
    for d in 1..m {
        ans += d * (m - d) * n * n % mod_num as usize;
        ans = ans % mod_num as usize;
    }

    println!(
        "{}",
        (ans as i64 * binomial.calc(n * m - 2, k - 2)) % mod_num
    );
}

Measured memory_bytes: 6724
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;
typedef long long LL;
LL deal(int n)
{
	LL i,f0=2,f1=1,f;
	for(i=1;i<=n-1;i++)
	{
	    f=f0+f1;
	    f0=f1;
		f1=f;
	}
	return f;
}
int main()
{
	LL n;
	while(~scanf("%lld",&n))
	{
		LL f0=2,f1=1;
		if(n==0)
			printf("%d\n",f0);
		else if(n==1)
			printf("%d\n",f1);
		else
			printf("%lld\n",deal(n));
	}
}

Measured memory_bytes: 128
#include <iostream>
#include <utility>
#include <stdint.h>
#include <string>
#include <map>
#include <vector>

using namespace std;

int N,K,R,S,P;

int point(char c)
{
  switch (c) {
  case 'r':
    return P;
  case 's':
    return R;
  case 'p':
    return S;
  }
}

char myHand(char c)
{
  switch (c) {
  case 'r':
    return 'p';
  case 's':
    return 'r';
  case 'p':
    return 's';
  }  
}

char theOtherHand(char a, char b)
{
  if (a==b)
    cerr << "wrong input" << endl;
  if (a=='r' && b=='p')
    return 's';
  else if (a=='p' && b=='s')
    return 'r';
  else if (a=='s' && b=='r')
    return 'p';
  else if (a=='p' && b=='r')
    return 's';
  else if (a=='r' && b=='s')
    return 'p';
  else if (a=='s' && b=='p')
    return 'r';
}

int main()
{
  cin >> N >> K;
  cin >> R >> S >> P;
  string T;
  cin >> T;

  string myHands;
  
  uint64_t ans = 0;
  
  for (int n=0; n<N; ++n) {
    int prev = n-K;
    int next = n+K;
    char tHand = T[n];
    //char tHandNext = T[next];
    //char tHandPrev = T[prev];
    if (prev<0 && next>=N) {
      ans += point(tHand);
    } else if (prev < 0 && next < N) {
      char tHandNext = T[next];
      if (tHand != tHandNext) {
	ans += point(tHand);
	myHands += myHand(tHand);
      } else { // tHand == tHandNext
	if (point(tHand) >= point(tHandNext)) {
	  ans += point(tHand);
	  myHands += myHand(tHand);
	} else {
	  ans += 0;
	  myHands += tHand;
	}
      }
    } else if (prev >= 0 && next < N) {
      char tHandNext = T[next];
      char myHandPrev = myHands[prev];
      if ( (tHand != tHandNext)
	   && (myHand(tHand) != myHandPrev) ) {
	ans += point(tHand);
	myHands += myHand(tHand);
      } else if (myHand(tHand) == myHandPrev) {
	if (tHand != myHand(tHandNext)) {
	  ans += 0;
	  myHands += tHand;
	} else {
	  ans += 0;
	  myHands += theOtherHand(tHand, myHandPrev);
	}
      } else if (tHand == tHandNext) {
	if (myHand(tHand) != myHandPrev) {
	  ans += point(tHand);
	  myHands += myHand(tHand);
	} else { // myHand(tHand) == myHandPrev
	  ans += 0;
	  myHands += tHand;
	}
      }
    } else { // prev >= 0 && next >= N
      char myHandPrev = myHands[prev];
      if (myHand(tHand) != myHandPrev) {
	ans += point(tHand);
	myHands += myHand(tHand);
      } else {
	ans += 0;
	myHands += tHand;
      }
    }
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define IO                       \
    ios::sync_with_stdio(false); \
    cin.tie(0);                  \
    cout.tie(0);
#define mem(a, x) memset(a, x, sizeof(a))
#define per(x, a, b) for (int x = a; x <= b; x++)
#define rep(x, a, b) for (int x = a; x >= b; x--)

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
const int maxn = 1e5 + 10;
const int mod = 1e9 + 7;
const double eps = 1e-8;

LL n, m;
vector<LL> ans;
int fa[maxn];
LL num[maxn];
int find_set(int x) {
    if (fa[x] != x) {
        fa[x] = find_set(fa[x]);
    }
    return fa[x];
}
bool union_set(int x, int y) {
    x = find_set(x);
    y = find_set(y);
    if (x == y)
        return false;
    num[y] += num[x];
    fa[x] = y;
    return true;
}

void init() {
    ans.clear();
    for (int i = 0; i < maxn; i++) {
        fa[i] = i;
        num[i] = 1;
    }
}

int l[maxn], r[maxn];
int main() {
#ifdef LOCAL_IM0QIANQIAN
    freopen("test.in", "r", stdin);
//    freopen("test.out", "w", stdout);
#else
    IO;
#endif // LOCAL_IM0QIANQIAN

    while (cin >> n >> m) {
        init();
        LL now = 1LL * n * (n - 1) / 2;
        ans.push_back(now);
        for (int i = 0; i < m; i++) {
            cin >> l[i] >> r[i];
        }
        for (int i = m - 1; i >= 0; i--) {
            LL left = num[find_set(l[i])];
            LL right = num[find_set(r[i])];
            if (union_set(l[i], r[i])) {
                now -= left * right;
            }
            ans.push_back(now);
        }
        int len = ans.size();
        for (int i = len - 2; i >= 0; i--) {
            cout << ans[i] << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4212
N = int(input())
A = list(map(int, input().split()))
app_fl = True
for Ai in [a for a in A if a % 2 == 0]:
    if Ai % 3 != 0 and Ai % 5 != 0:
        app_fl = False
        break
 

if app_fl is True:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060