akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

# 1 "<stdin>"
# 1 "<built-in>"
# 1 "<command-line>"
# 31 "<command-line>"
# 1 "/usr/include/stdc-predef.h" 1 3 4
# 32 "<command-line>" 2
# 1 "<stdin>"

using namespace std;

# 1 "../Algo/NumberTheory/modulo.h" 1
class ModuloOps {
public:
    ModuloOps(long long mod): MOD(mod) {
    }

    long long binPow(long long a, long long b) {
        if (b == 0) {
            return 1;
        }
        auto prev = binPow(a, b/2);
        return mul(mul(prev, prev), b % 2 == 1 ? a : 1);
    }

    long long inv(long long a) {
        return binPow(a, MOD - 2);
    }

    inline long long add(long long a, long long b) {
        return (a + b) % MOD;
    }

    inline long long sub(long long a, long long b) {
        return (a - b + MOD) % MOD;
    }

    inline void inc(long long &a, long long b) {
        a = add(a, b);
    }

    inline long long mul(long long a, long long b) {
        return (a * b) % MOD;
    }

    inline long long div(long long a, long long b) {
        return mul(a, inv(b));
    }

private:
    long long MOD;
};
# 5 "<stdin>" 2

ModuloOps MOD(1e9+7);

int naive(int n, int k) {
    vector<int> cur(n, 1);
    set<vector<int>> all;
    function<void(int)> enter;
    enter = [&] (int c) {
        if (c == k) {
            all.insert(cur);
            return;
        }
        for (int i = 0; i < n; i++) {
            if (cur[i] == 0) {
                continue;
            }
            for (int j = 0; j < n; j++) {
                if (i != j) {
                    cur[j]++;
                    cur[i]--;
                    enter(c+1);
                    cur[j]--;
                    cur[i]++;
                }
            }
        }

    };
    enter(0);
    return all.size();
}


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int n, k;
    cin >> n >> k;
    k = min(k, n-1);
    vector<long long> fact(n+1);
    fact[0] = 1;
    for (int i = 1; i < fact.size(); i++) {
        fact[i] = MOD.mul(fact[i-1], i);
    }
    auto C = [&] (int n, int k) {
        return MOD.mul(fact[n], MOD.mul(MOD.inv(fact[k]), MOD.inv(fact[n-k])));
    };
    long long ans = 0;
    for (int i = 0; i <= k; i++) {
        ans = MOD.add(ans, MOD.mul(C(n, i), C(n-1, i)));
    }

    cout << ans << endl;
}


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

typedef long long ll;
typedef pair<int, int> pi;
#define mp make_pair
#define f first
#define s second

typedef vector<int> vi;
#define sz(x) (int)x.size()
#define all(x) x.begin(), x.end();
#define rsz resize
#define pb push_back

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)
#define trav(a,x) for (auto &a: x)
typedef long double ld; 
const int MOD = (119<<23) + 1;
const ld PI = 4*atan((ld)1);

vi invs, fac, ifac;
void genFac(int SZ){
	invs.rsz(SZ), fac.rsz(SZ), ifac.rsz(SZ);
	invs[1] = fac[0] = ifac[0] = 1;
	FOR(i,2,SZ) invs[i] = MOD-(ll)MOD/i*invs[MOD%i]%MOD;
	FOR(i,1,SZ){
		fac[i] = (ll)fac[i-1]*i%MOD;
		ifac[i] = (ll)ifac[i - 1]*invs[i]%MOD;
	}
}

ll comb(int a, int b){
	if (a < b || b < 0) return 0;
	return (ll) fac[a]*ifac[b]%MOD*ifac[a-b]%MOD;
}


int main(){
	int n, m; cin >> n >> m;
	//all - stars and bars
	genFac(4000000);
	ll complement = comb(3*m + n - 1, n - 1);
	for (int odds = m + 1; odds <= n; odds++){
		if ((3 * m - odds) % 2 == 0){
			if (3 * m >= odds){
				ll cnt = comb(n, odds); //these are odd
				cnt *= comb((3 * m - odds) / 2 + n - 1, n - 1);
				cnt %= MOD;
				complement -= cnt;
			}
		}
	}

	ll cnt = n; //there's a number at least 2 * m + 1
	cnt *= comb(m - 1 + n - 1, n - 1);
	cnt %= MOD;
	complement -= cnt;
	complement %= MOD;
	complement += MOD;
	complement %= MOD;
	cout << complement << endl;
}


Measured memory_bytes: 47232
{-# OPTIONS_GHC -Wall -Werror #-}

import Control.Monad

main :: IO ()
main = do
  n <- readLn :: IO Int
  replicateM_ n $ do
    [a, b] <- replicateM 2 readLn :: IO [Integer]
    let answer = show $ a + b
        digits = length answer
    putStrLn $ if digits > 80 then "overflow"
                              else answer

Measured memory_bytes: 4320
n = int(input())
a = list(map(int,input().split()))
mod = 10**9 + 7
bits = [0]*60
for x in a:
    i = 0
    while x > 0:
        if x % 2 == 1:
            bits[i] += 1
        x //= 2
        i += 1
ans = 0
for i in range(60):
    ans += (bits[i] * (n-bits[i])) * pow(2, i, mod)
    ans %= mod
print(ans)

Measured memory_bytes: 124548
// AOJ Vol-3 0326: Related Products
// 2017.9.29 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define HSIZ 2003
typedef struct { char *w; int id; } HASH;
HASH hash[HSIZ+2];				// Hash table

int lookup(char *w, int len, int id)
{
	HASH *tp;
	int i = (101 * *w + 103 * *(w + len - 1) + 107 * len) % HSIZ;

	tp = hash + i;
	if (tp->w != NULL) {
		int inc = *w + (*(w + 1) << 1);
		while (1) {
			if (!strcmp(tp->w, w)) return tp->id;
			i += inc;
			if (i >= HSIZ) i -= HSIZ;
			tp = hash + i;
			if (tp->w == NULL) break;
		}
	}
	tp->w = w, tp->id = id;
	return -1;
}

char name[1002][32];		// name body
int nsize;
unsigned tbl[1002][1002];	//relationship

typedef struct { char *a, *b; } T;
T list[20000]; int size;

int cmp(T *a, T *b)
{ 
	int r = strcmp(a->a, b->a);
	if (r) return r;
	return strcmp(a->b, b->b);
}

int main()
{
	int n, f, m, i, j;
	char *w;
	int c[12];

	scanf("%d%d", &n, &f); nsize = 0;
	while (n-- > 0) {
		scanf("%d", &m);
		for (i = 0; i < m; i++) {
			scanf("%s", w = name[nsize]);
			if ((j = lookup(w, strlen(w), nsize)) < 0) c[i] = nsize++;
			else c[i] = j;
		}
		for (i = 0; i < m; i++) for (j = i+1; j < m; j++) {
			if (tbl[c[i]][c[j]] < 110) tbl[c[i]][c[j]]++;
			if (tbl[c[j]][c[i]] < 110) tbl[c[j]][c[i]]++;
		}
	}

	size = 0;
	for (i = 0; i < nsize; i++) for (j = i+1; j < nsize; j++) {
		if (tbl[i][j] >= (unsigned char)f) {
			if (strcmp(name[i], name[j]) < 0)
				 list[size].a = name[i], list[size].b = name[j];
			else list[size].a = name[j], list[size].b = name[i];
			size++;
		}
	}

	qsort(list, size, sizeof(T), cmp);
	printf("%d\n", size);
	for (i = 0; i < size; i++) printf("%s %s\n", list[i].a, list[i].b);
	return 0;
}

Measured memory_bytes: 5816
#include<stdio.h>

int main()
{
	int m,n,i,j,temp,first;
	int place[1000],index[1000];
	char buf[201];

	while(1)
	{
		fgets(buf,10,stdin);
		sscanf(buf,"%d %d",&n,&m);

		if(n==0 && m==0)break;
		for(i=0;i<m;i++)
		{
			*(place+i)=0;
			*(index+i)=i+1;
		}
		for(i=0;i<n;i++)
		{
			fgets(buf,201,stdin);
			for(j=0;j<m;j++)
			{
				*(place+j)+=(int)(*(buf+2*j)-'0');
			}
		}
		for(i=0;i<m;i++)
		{
			for(j=i+1;j>0&&*(place+j)>*(place+j-1);j--)
			{
				temp=*(place+j);
				*(place+j)=*(place+j-1);
				*(place+j-1)=temp;
				temp=*(index+j);
				*(index+j)=*(index+j-1);
				*(index+j-1)=temp;
			}

		}
		first=1;
		for(i=0;i<m;i++)
		{
			if(first==0){putchar(' ');}
			else{first=0;}
			printf("%d",*(index+i));
		}
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 0
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {


	public static void main(String[] args) throws IOException {
		BufferedReader bf = null;
		bf = new BufferedReader(new InputStreamReader(System.in));
		int ans = 0,a,b,num = 1;
		String str;
		String[] s;
		str = bf.readLine();
		s = str.split(" ");
		a = Integer.parseInt(s[0]);
		b = Integer.parseInt(s[1]);
		while(num < b) {
			num += a-1;
			ans++;
		}
		System.out.println(ans);
	}
}

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

int main() {
  int n, k, r, s, p;
  string t;
  cin >> n >> k >> r >> s >> p >> t;
  int ans =0;
  vector<int> win(n);
  vector<int> flag(n);
  
  rep(i, n){
    if(t[i]=='r') win[i]=p;
    else if(t[i] == 's') win[i]=r;
    else win[i] = s;
    if(i>=k){
      if(t[i]==t[i-k]) flag[i] = flag[i-k]+1;
    }
    //cout << flag[i] << " " << endl;
  }
  
  rep(i, n){
    if(i < k) ans += win[i];
    
    else{//if i>= k
      if(t[i] == t[i-k] && flag[i]%2==0) ans += win[i];
      else if(t[i] != t[i-k]){
        ans += win[i];
      }
    }
  }
  cout << ans;

}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define ll long long 
using namespace std;
const int mxval = 1e9 + 1;
int main(){

  int n; cin >> n;
  int arr[n + 1];
  int count = 0;
  ll ans = 0;
  int minval = mxval;
  for(int i = 0; i < n; ++i){
    cin >> arr[i];
    if(arr[i] < 0) count++;
    ans += (ll)abs(arr[i]);
    minval = min(minval,abs(arr[i]));
  }
  //cout << count << '\n';
  if(!(count%2)) cout << ans << '\n';
  else cout << (ans - (ll)minval - (ll)minval) << '\n';
}


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

int main() {
    ll n;
    cin >> n;
    map<string, int>mp;
    int m = 0;
    rep(i, n){
        string s;
        cin >> s;
        mp[s]++;
        m = max(m, mp[s]);
    }
    for (auto x : mp) {
        if (x.second == m) {
            cout << x.first << endl;
        }
    }
    return 0;
}


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


using namespace std;

string s;
int cnt;
long long ans;

int main()
{
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    if (s[i] == 'A')
      cnt++;
    else  if (i < s.size() - 1 && s[i] == 'B' && s[i + 1] == 'C') {
      ans += cnt;
      i++;
    }
    else
      cnt = 0;
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String args[]) throws IOException{
		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		StringBuilder builder = new StringBuilder();
		while(true){
			String data[] = reader.readLine().split(" ");
			int a= Integer.parseInt(data[0]);
			int b= Integer.parseInt(data[1]);
			
			if(a==0 && b==0)
				break;
			
			for(int y=0; y<a; y++){
				for(int x=0; x<b; x++){
					builder.append(y==0||y==a-1||x==0||x==b-1? "#" : ".");
				}
				builder.append("\n");
			}
			builder.append("\n");
		
		}
		System.out.print(builder);
	}
}

Measured memory_bytes: 20784
#include <stdio.h>
int main()
{
    int a,b,c,d,e,n,m=0;
    scanf("%d%d%d%d%d",&a,&b,&c,&d,&e);
    if(a==0){
        printf("1\n");
    } else if(b==0){
        printf("2\n");
    }
    else if(c==0){
        printf("3\n");
    }
    else if(d==0){
        printf("4\n");
    } else if(e==0){
        printf("5\n");
    }
    return 0;
}

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

namespace _0060
{
    public class Program

    {
        public static void Main(string[] args)
        {
            while (true)
            {
                string line = Console.ReadLine();
                if (string.IsNullOrEmpty(line)) return;

                int[] cards = Array.ConvertAll(line.Trim().Split(' '), e => int.Parse(e));

                int cnt = 0;
                for (int i = 1 ; i <= 10 ; i++)
                {
                    if (cards.Contains(i)) continue;
                    if (cards[0] + cards[1] + i <= 20) cnt++;
                }
                Console.WriteLine(cnt >= 4 ? "YES" : "NO");
            }        
        }
    }

}



Measured memory_bytes: 14140
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <sstream>
#include <functional>
#include <numeric>
#include <cmath>
#include <cstring>
#include <queue>
#include <stack>
#include <set>

using namespace std;

#define ALL(co) co.begin(), co.end()

typedef long long LL;
typedef pair<int, int> P;
typedef pair<int, P> IP;
typedef pair<P, P> PP;
typedef vector<int> Array;
typedef vector<vector<int> > Array2;
typedef vector<int> LArray;

const int INF = 1 << 29;
const LL LINF = 1LL << 60;

int itiv;
inline int getInt() { return (cin >> itiv, itiv); }
void readAll(Array& vec, int n) { for (int i = 0; i < n; i++) cin >> vec[i]; }
inline bool between(int first, int last, int n) { return first <= n && n <= last; }
inline bool inRange(int begin, int end, int n) { return begin <= n && n < end; }
inline bool inRange(int size, int n) { return 0 <= n && n < size; }

int m, n;
int dx[] = { -1, 0, 1, 0 }, dy[] = { 0, -1, 0, 1 };
int dr[] = { 0, -1, 0, 1 }, dc[] = { -1, 0, 1, 0 };


int main(void)
{
	while(cin >> n >> m && n)
	{
		Array kyougi(n), sinsa(m);
		Array hyou(n);
		readAll(kyougi, n); readAll(sinsa, m);
		for (int i = 0; i < m; i++)
		{
			for (int j = 0; j < n; j++)
			{
				if(kyougi[j] <= sinsa[i])
				{
					hyou[j]++;
					break;
				}
			}
		}
		cout << (max_element(ALL(hyou)) - hyou.begin()) + 1 << endl;
	}
	return 0;
}

Measured memory_bytes: 1204
import sys

TYPE_ROOT = 0
TYPE_NODE = 1
TYPE_LEAF = 2


class Node:
    def __init__(self, id):
        self.id = id
        self.parent = None
        self.children = []
        self.type = None
        self.depth = 0


def set_depth(node, depth):
    node.depth = depth
    for child in node.children:
        set_depth(child, depth + 1)


nodes = {}


def get_node(id):
    if id in nodes:
        return nodes[id]
    node = Node(id)
    nodes[id] = node
    return node


n = int(sys.stdin.readline())
for _ in range(n):
    id, k, *children = map(int, sys.stdin.readline().split())
    node = get_node(id)
    for cid in children:
        child = get_node(cid)
        child.parent = node
        node.children.append(child)
    node.type = TYPE_NODE if node.children else TYPE_LEAF

root = next(node for node in nodes.values() if not node.parent)
root.type = TYPE_ROOT
set_depth(root, 0)


for _, node in sorted(nodes.items()):
    print('node %d: parent = %d, depth = %d, %s, [%s]' % (
        node.id,
        node.parent.id if node.parent else -1,
        node.depth,
        ['root', 'internal node', 'leaf'][node.type],
        ', '.join(str(child.id) for child in node.children)
    ))



Measured memory_bytes: 52248
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<ll>;
using vii = vector<vi>;
using Pll = pair<ll, ll>;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(v) v.begin(), v.end()
#define sz(x) ((int) x.size())
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define F first
#define S second
const int MOD = 1e9+7;
const int INF = 2e9;
template<class T> void print(const T& t){ cout << t << endl; }
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; }
int gcd(int a,int b){return b?gcd(b,a%b):a;}

int main(){
  ll n;
  cin >> n;
  n %= 10;
  if(n==3){
    print("bon");
  }
  else if(n==0||n==1||n==6||n==8){
    print("pon");
  }
  else{
    print("hon");
  }
}

Measured memory_bytes: 3636
#include <iostream>
using namespace std;
int main()
{
	string s;
	cin >> s;
	int first, second;
	bool check_first = false, check_second = false;
	for(int i = 0; i < s.size(); i++)
	{
		if( s[i] == 'A' and check_first == false )
		{
			first = i;
			check_first = true;
		}
		if( s[ s.size() - 1 - i] == 'Z' and check_second == false )
		{
			second = s.size() - i;
			check_second = true;
		}
		if( check_first and check_second ) break;
	}
	cout << second - first;
	return 0;
}

Measured memory_bytes: 3356
import sys
def t(A,p,r):
 x=A[r][1];i=p-1
 for j in range(p,r):
  if A[j][1]<=x:i+=1;A[i],A[j]=A[j],A[i]
 A[i+1],A[r]=A[r],A[i+1]
 return i+1
def k(A,p,r):
 if p<r:q=t(A,p,r);k(A,p,q-1);k(A,q+1,r)
def s(A):
 for i in range(n-1):
  if A[i][1]==A[i+1][1]and A[i][2]>A[i+1][2]:return'Not s'
 return'S'
n=int(input())
f=lambda x,y:(x,int(y))
A=[(*f(*e.split()),i)for i,e in enumerate(sys.stdin)]
k(A,0,n-1)
for e in[[s(A)+'table']]+A:print(*e[:2])


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

int main (){
		char str;
		while((str=getchar())!=EOF){
			if(str>=65 && str<=90){
				printf("%c",str+32);
			}else if(str>=97 && str<=122){
				printf("%c",str-32);
			}else{
				printf("%c",str);;
			}
		}
}



Measured memory_bytes: 2636
fun main(args: Array<String>) {
    val n = readLine()!!.split(" ").map { it.toInt() }
    val h = readLine()!!.split(" ").map { it.toInt() }
    var count = 0
    var maxcount = 0
    for (i in 0..n[0]-2){
        if (h[i] >= h[i+1]){
            count++
        } else {
            if (count > maxcount){
                maxcount = count
            }
            count = 0
        }
    }
    if (count > maxcount){
        maxcount = count
    }
    println(maxcount)
}


Measured memory_bytes: 72060
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,M;
int A[101010],B[101010];
vector<int> E[101010];
int did[101010];
vector<int> V[2];

int dfs(int cur,int id) {
	V[id].push_back(cur+1);
	did[cur]=1;
	
	FORR(r,E[cur]) if(did[r]==0) {
		dfs(r,id);
		break;
	}
}

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N>>M;
	FOR(i,M) {
		cin>>A[i]>>B[i];
		A[i]--,B[i]--;
		E[A[i]].push_back(B[i]);
		E[B[i]].push_back(A[i]);
	}
	
	dfs(0,0);
	dfs(0,1);
	vector<int> R;
	while(V[0].size()>1) R.push_back(V[0].back()),V[0].pop_back();
	FOR(i,V[1].size()) R.push_back(V[1][i]);
	
	
	_P("%d\n",R.size());
	FOR(i,R.size()) _P("%d%c",R[i],(i==R.size()-1)?'\n':' ');
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n';
	FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	solve(); return 0;
}


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

int main() {
  int N,M;
  cin>>N>>M;
  vector<vector<int>> v(M,vector<int>(2));
  rep(i,M) cin>>v[i][0]>>v[i][1];
  int mxL=v[0][0];
  int mnR=v[0][1];
  rep(i,M){
    mxL=max(mxL,v[i][0]);
    mnR=min(mnR,v[i][1]);
  }
  if(mxL>mnR) cout<<0<<endl;
  else cout<<mnR-mxL+1<<endl;
  return 0;
}

Measured memory_bytes: 5760
#include<iostream>

using namespace std;


int main(void){
	
	int arr[10];
	
	for(int i=0;i<10;i++){
		cin>>arr[i];
	}
	
	
	for(int i=0;i<9;i++){
		for(int j=i+1;j<10;j++){
			if(arr[i]<arr[j])
				swap(arr[i],arr[j]);
		}
	}
	
	
	for(int i=0;i<3;i++){
		cout<<arr[i]<<endl;
	}
	
	return 0;
}


Measured memory_bytes: 3100
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstdio>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i = 0; i < (n); ++i)
typedef long long ll;


int main(void) {
  int n;
  cin >> n;
  vector<int> l(n);
  rep(i, n) cin >> l[i];
  sort(l.begin(), l.end());
  int ans = 0;
  for(int i=0; i < n; ++i) {
    for(int j = i+1; j < n; ++j) {
      for(int k = j+1; k < n; ++k) {
        if(l[k] < l[i] + l[j]) ++ans;
      }
    }
  }

  cout << ans << endl;


  return 0;
}

Measured memory_bytes: 256
S= input()
q=int(input())
h=0
a=[]
for i in range(q):
    a.append(input())
t=""
w=""
for i in range(1,q+1):
    if a[q-i][0]=="2":
        if a[q - i][2] == "1":
            if h%2==0:
                t=a[q-i][4]+t
            else:
                w =  a[q-i][4]+w
        else:
            if h%2==0:
                w=a[q-i][4]+w
            else:
                t = a[q - i][4]+t
    else:
        h+=1
if h%2==0:
    print(t[::-1]+S+w)
else:
    print(t[::-1]+S[::-1]+w)

Measured memory_bytes: 17080
#include "bits/stdc++.h"

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;

using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

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

int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	int n = s.size();
	vector<string> a(n + 1), b(n+1);
	REP(i, n)a[i + 1] = a[i] + s[i];
	RREP(i, n)b[i] = s[i] + b[i + 1];
	string t = "keyence";
	REP(i, n) {
		FOR(j, i, n) {
			if (a[i] + b[j] == t) {
				cout << "YES" << endl;
				return 0;
			}
		}
	}
	cout << "NO" << endl;
}

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

int main() {
    int R, C;
    long long K;
    cin >> R >> C >> K;
    vector<vector<long long>> vs(R+1, vector<long long>(C+1, 0));
    for (long long i=0; i<K; i++) {
        long long r, c, k;
        cin >> r >> c >> k;
        vs.at(r).at(c) = k;
    }
    vector<vector<vector<long long>>> dp(R+1, vector<vector<long long>>(C+1, vector<long long>(4, 0)));
    for (int i=1; i<=R; i++) {
        for (int j=1; j<=C; j++) {
            if (vs.at(i).at(j)!=0) {
                dp.at(i).at(j).at(0) = max({dp.at(i-1).at(j).at(0), dp.at(i-1).at(j).at(1), dp.at(i-1).at(j).at(2), dp.at(i-1).at(j).at(3)});
                dp.at(i).at(j).at(1) = max(dp.at(i).at(j-1).at(1), vs.at(i).at(j)+max({dp.at(i-1).at(j).at(0), dp.at(i-1).at(j).at(1), dp.at(i-1).at(j).at(2), dp.at(i-1).at(j).at(3)}));
                dp.at(i).at(j).at(2) = max(dp.at(i).at(j-1).at(2), vs.at(i).at(j)+dp.at(i).at(j-1).at(1));
                dp.at(i).at(j).at(3) = max(dp.at(i).at(j-1).at(3), vs.at(i).at(j)+dp.at(i).at(j-1).at(2));
            }
            else {
                dp.at(i).at(j).at(0) = max({dp.at(i-1).at(j).at(0), dp.at(i-1).at(j).at(1), dp.at(i-1).at(j).at(2), dp.at(i-1).at(j).at(3)});
                dp.at(i).at(j).at(1) = dp.at(i).at(j-1).at(1);
                dp.at(i).at(j).at(2) = dp.at(i).at(j-1).at(2);
                dp.at(i).at(j).at(3) = dp.at(i).at(j-1).at(3);
            }
        }
    }
    cout << max({dp.at(R).at(C).at(0), dp.at(R).at(C).at(1), dp.at(R).at(C).at(2), dp.at(R).at(C).at(3)});
}

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


typedef long long ll;
typedef pair<ll, ll> P;

struct edge {int to, cost; };

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

ll GCD(ll a, ll b){
  if(b==0) return a;
  else return GCD(b, a%b);
}

ll LCM(ll a, ll b){
  if(a<b) swap(a,b);
  return a/GCD(a,b)*b;
}

int main(){
  int n;
  cin >> n;
  int s[n]={};
  s[0] = 0;
  s[1] = 1;
  for(int i=2; i<n; i++){
    if(s[i]!=0) continue;
    for(int j=1; j*i<n; j++){
      s[i*j] = i;
    }
  }
  int ans = 0;
  for(int i=1; i<n; i++){
    int tmp = i;
    int ms = s[i];
    int cnt = 1;
    while(tmp>1){
      int c = 1;
      while(tmp%ms==0){
        c++;
        tmp/=ms;
      }
      cnt *= c;
      ms = s[tmp];
    }
    ans += cnt;
  }
  cout << ans << endl;
  return 0;
}


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

int main()
{
	int A, B, C;
	cin >> A >> B >> C;

	set<int> myset;
	myset.insert(A);
	myset.insert(B);
	myset.insert(C);
	if(myset.size() == 2)
		cout << "Yes" << '\n';
	else cout << "No" << '\n';

	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include<sstream>
#include<string>
#include<vector>
#include <cmath>
#include <limits>
#include <queue>
#include<algorithm>
#include<cstring>
#include <cstdlib>
#include <cstdio>
#include <set>
 
using namespace std;
 
#define rep(i,n) for (int (i)=0;(i)<(n);i++)
const int maxv = 1e9;

int main(){
    int N;
    cin >> N;
    long long a[N];
    rep(i,N) cin >> a[i];
    int ans = 0;
    rep(i,N){
        while (a[i]%2 == 0){
            ans++;
            a[i] = a[i]/2;
        }
    }
    cout << ans << endl;
    return 0;
}






Measured memory_bytes: 384
#include<bits/stdc++.h>
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define all(x) (x.begin(),x.end())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define F first
#define S second
#define endl "\n"
#define FAST  ios_base::sync_with_stdio(false);cin.tie(NULL)
#define pb push_back
#define sz(a) (int)a.size()
#define deb(x) cout<<#x<<" "<<x<<endl;
#define Q(x) for(int i=0;i<x;i++)
#define show(x) for(auto i:x)cout<<i<<" ";cout<<endl;

using namespace std;
const ll mod = 1e9 + 7;
void solve() {



}
int main() {

	string s, t;
	cin >> s >> t;
	int ans = 0;
	for (int i = 0; i <= sz(s) - sz(t); i++) {
		int temp = 0;
		for (int j = 0; j < sz(t); j++) {
			if (t[j] == s[i + j]) {
				temp++;
			}
		}
		ans = max(temp, ans);
	}
	cout << sz(t) - ans;
	return 0;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i=(a);i<(b);i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
//#define KEY_DOWN(VK_NONAME) ((GetAsyncKeyState(VK_NONAME) & 0x8000) ? 1:0)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
inline void out(int x){
	if(x>=10)out(x/10);
	putchar(x%10+'0');
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int n;
	string s;
	cin>>n>>s;
	fo(i,0,s.size())cout<<char('A'+(s[i]-'A'+n)%26);
	return 0;
}

Measured memory_bytes: 256
package main

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

func main() {
	var N int
	fmt.Scan(&N)
	set := make(map[int]int, 0)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		sc.Scan()
		t, _ := strconv.Atoi(sc.Text())
		set[t]++
	}
	ks := make([]int, 0)
	for k := range set {
		ks = append(ks, k)
	}
	sort.Sort(sort.Reverse(sort.IntSlice(ks)))
	m1, m2 := 0, 0
	for i := range ks {
		v := set[ks[i]]
		if v >= 2 {
			if v > m1 {
				m1 = ks[i]
			} else if v > m2 {
				m2 = ks[i]
			}
		}
	}
	ans := 0
	if set[m1] >= 4 {
		ans = m1 * m1
	} else {
		ans = m1 * m2
	}
	fmt.Println(ans)
}


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

#define vi vector<int>
#define pii pair<int, int>
#define LL long long int 
#define x first
#define y second
#define f first
#define s second
#define INF int(1e9)
using namespace std;

LL n;

LL solve(int a, int b){
    cout << a << " " << b << endl;

    if(a*b==n)
        return 0;
    
    if(a*b>n)
        return INF;

    return min(1+solve(a+1, b), 1+solve(a, b+1));
}

int main () {
    cin >> n;
    
    LL mini = n;
    for(LL i=1; i<=int(1e6); i++){
        LL b = n/i;
        if(b*i==n){
            if((i-1)+(b-1)<mini)
                mini = (i-1)+(b-1);
        }
    }
    cout << mini << endl; 
    return 0;
}
//a*b = c
//b = c/b

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

int yakusu(int x){
  int count =0;
  for(int i=1;i<=x;i++){
    if(x%i==0) count++;
  }
  return count;
}
  

int main(){
  int n ;
  cin >> n;
  int ans =0;
//約数の個数を出力する関数を作る
  
  for(int i=1;i<=n;i+=2){
    if(yakusu(i)==8) ans++;
  }
  
  cout << ans << endl;
}

  
  


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <unordered_map>
#include <queue>
#define MOD 1000000007
#define REP(i,st,num)for(int i=(st);i<(num);++i)
#define ll long long
using namespace std;

int main() {
    ios::sync_with_stdio(false);
    int N,K,t;
    cin>>N>>K;
    REP(i,0,N){
        cin>>t;
    }
    if(N==K){
        cout<<1;
    }else{
        cout<<1 + ceil((double)(N-K)/(K-1));
    }
    return 0;
}
//7 3 1 8 4 6 2 5
//1 1 1 1 1 6 2 5 9
//1 1 1 1 1 1 1 1 9

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

int main() {
	int a,b,c;
	int n = 0;
	cin >> a >> b >> c;
	for(int i = a; i <= b; i++){
		if (c % i == 0){
			n++;
		}

	}	
	cout << n << endl;
	return 0;
}


Measured memory_bytes: 3104
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<deque>
#include<string>
#include<iostream>
using namespace std;
int main()
{
	int num, kai;
	scanf("%d%d", &num, &kai);
	string s;
	cin >> s;
	s.push_back('C');
	deque<int>deq;
	bool pal = (s[0] == 'A');
	char now = s[0];
	int cnt = 0;
	for (int i = 0; i < s.size(); i++)
	{
		if (s[i] != now)
		{
			deq.push_back(cnt);
			cnt = 1;
			now = s[i];
		}
		else cnt++;
	}
	for (int i = 0; i < min(kai, 1000000 + kai % 2); i++)
	{
		if (pal)
		{
			if (deq[0] != 1)
			{
				deq[0]--;
				deq.push_front(1);
				pal = false;
			}
			else
			{
				deq.pop_front();
				deq[0]++;
				pal = false;
			}
		}
		else
		{
			if (deq.size() % 2 == 1)deq[deq.size() - 1]++;
			else deq.push_back(1);
			if (deq[0] != 1)
			{
				deq[0]--;
				pal = true;
			}
			else
			{
				deq.pop_front();
				pal = false;
			}
		}
	}
	string ret;
	for (int i = 0; i < deq.size(); i++)
	{
		if (pal)for (int j = 0; j < deq[i]; j++)ret.push_back('A');
		else for (int j = 0; j < deq[i]; j++)ret.push_back('B');
		pal = !pal;
	}
	cout << ret << endl;
}

Measured memory_bytes: 1812
#include<bits/stdc++.h>
using namespace std;
int main(){
  int h,w,n,c;
  cin>>h>>w>>n;
  queue<int> que;
  for(int i=0;i<n;++i){
    cin>>c;
    que.push(c);
  }
  vector<vector<int>> ans(h,vector<int>(w));
  int col=0,inc=0;
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(!inc){
        inc=que.front();
        que.pop();
        col++;
      }
      ans[i][i%2?w-j-1:j]=col;
      inc--;
    }
  }
  for(int i=0;i<h;++i){
    for(int j=0;j<w;++j){
      if(j)cout<<" ";
      cout<<ans[i][j];
    }
    cout<<endl;
  }
  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#define MAX 25
 
void preParse(int);
void inParse(int);
void postParse(int);
 
typedef struct node{int p,l,r;}Node;
Node T[MAX];
int n;
 
int main(){
  int i,l,r,p,root,v;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=-1;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=-1) T[l].p=v;
    if(r!=-1) T[r].p=v;
  }
 
  for(i=0;i<n;i++){
    if(T[i].p==-1) root=i;
  }
 
  printf("Preorder\n");
  preParse(root);
  printf("\n");
  printf("Inorder\n");
  inParse(root);
  printf("\n");
  printf("Postorder\n");
  postParse(root);
  printf("\n");
 
  return 0;
}
 
void preParse(int u){
  if(u==-1) return;
  printf(" %d",u);
  preParse(T[u].l);
  preParse(T[u].r);
}
 
void inParse(int u){
  if(u==-1) return;
  inParse(T[u].l);
  printf(" %d",u);
  inParse(T[u].r);
}
 
void postParse(int u){
  if(u==-1) return;
  postParse(T[u].l);
  postParse(T[u].r);
  printf(" %d",u);
}

Measured memory_bytes: 616
#include <stdio.h>
#include <limits.h>

int main(void)
{
	int i, n, x, min, max = INT_MIN;
	
	scanf("%d", &n);
	scanf("%d", &min);
	for(i = 1; i < n; i++){
		scanf("%d", &x);
		if(max < x - min) max = x - min;
		if(x < min) min = x;
	}
	printf("%d\n", max);
	
	return(0);
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> iP;

const ll MOD = ll(1e9 + 7);
const ll LLINF = LLONG_MAX;
const int IINF = 99999999;
const int MAX_N = int(1e5) + 5;
const double EPS = 1e-8;
int dx[] = {1, 0, -1, 0}, dy[] = {0, 1, 0, -1};
#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++)

int main() {
    int a[1005][11][21];
    for(int s=1,y=1;y<=1001;y++){
        for(int m = 1;m <= 10;m++){
            for(int d = 1;d <= 20;d++){
                a[y][m][d] = s;
                s++;
                if(d==19 && y%3>0 && m%2 == 0)break;
            }
        }
    }
    int n;
    cin >> n;
    REP(t,n){
        int Y,M,D;
        cin >> Y >> M >> D;
        cout << a[1000][1][1] - a[Y][M][D] << endl;
    }
    return 0;
}



Measured memory_bytes: 3884
/*
** author:mahmoud magdy
*/
#include <bits/stdc++.h>
using namespace std;

#define ll long long
#define endl "\n"

inline int D()
{
    int m ;
    cin>>m;
    return m ;
}
inline ll lD()
{
    ll m ;
    cin>>m;
    return m ;
}
inline double dD()
{
    double m;
    cin>>m;
    return m;
}
void fast()
{
    ios_base :: sync_with_stdio( 0 ) ;
    cin.tie( 0 ) ;
    cout.tie( 0 ) ;
}
const int N=1e2+5;

int main()
{
  string s;
  cin>>s;
  deque<char>dq;
  for(int i=0;i<s.length();++i){
    if(s[i]=='B'&&dq.empty())continue;
    if(s[i]=='B')dq.pop_back();
    else if(s[i]=='0')dq.push_back('0');
    else dq.push_back('1');
  }
  for(int i=0;i<dq.size();++i)cout<<dq[i];
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
using loop = int;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(loop (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(loop (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(loop (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(loop (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10;
constexpr ld pi = 3.1415926535897932;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    ll n, s; cin >> n >> s;
    VL a(n); cin >> a;

    auto dp = vec<ll>(n + 1, s + 1);
    FOR(i, 0, n){
        eFOR(j, 1, s) {
            (dp[i + 1][j] += dp[i][j]) %= MOD;
            if (s < j + a[i])continue;
            (dp[i + 1][j + a[i]] += dp[i][j]) %= MOD;
        }
        if (s < a[i])continue;
        (dp[i + 1][a[i]] += ll(i + 1)) %= MOD;
    }

    ll ans = 0;
    eFOR(i, 0, n)(ans += dp[i][s]) %= MOD;
    cout << ans << "\n";
}

Measured memory_bytes: 70784
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	a, b, c := intScanner(), intScanner(), intScanner()
	fmt.Println(max([]int{a*10 + b + c, a + b*10 + c, a + b + c*10}))
}


Measured memory_bytes: 1772
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
	int x,y,a,b,c;
	cin>>x>>y>>a>>b>>c;
	priority_queue<pair<int,int> > h;
	while(a--)
	{
		int w;
		cin>>w;
		h.push(make_pair(w,1));
	}
	while(b--)
	{
		int w;
		cin>>w;
		h.push(make_pair(w,2));
	}
	while(c--)
	{
		int w;
		cin>>w;
		h.push(make_pair(w,3));
	}
	int z=x+y;
	int ans=0;
	while(z)
	{
		pair<int,int>
		  f=h.top();
		h.pop();
		if(f.second==3)
		{
			ans+=f.first;
			--z;
		}
		else 
		  if(f.second==1&&x)
		  {
			ans+=f.first;
			--x;
			--z;
		  }
		  else
		    if(f.second==2&&y)
			{
				ans+=f.first;
				--y;
				--z;
			}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 10604
#include<stdio.h>

#define MAX 250

int main(){
  int H,i,A[MAX+1];

  scanf("%d",&H);
  for(i=1 ; i<=H ; i++){
    scanf("%d",&A[i]);
  }

  for(i=1 ; i<=H ; i++)
  {
    printf("node %d: key = %d, ",i,A[i]);

    if(i/2 >= 1) printf("parent key = %d, ",A[i/2]);
    if(2*i <= H) printf("left key = %d, ",A[2*i]);
    if(2*i+1 <= H) printf("right key = %d, ",A[2*i+1]);

    printf("\n");
  }
  return 0;
}



Measured memory_bytes: 2048
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 
  string S;
  cin >> S;

  char current;
  string answer = "Good";

  for (int i = 0; i < S.size(); i++) {
    if (current == S[i]) {
      answer = "Bad";
      break;
    } else {
      current = S[i];
    }
  }
  
  cout << answer << endl;
  
}

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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

const LL mod = 1e9 + 7;
const int MC = 202;
LL fct[MC+1];
LL invfct[MC+1];
int N,K;
string s;
vector<int> V;
LL ans;

void build(){
	fct[0] = fct[1] = 1;
	repp(i,2,MC+1){
		fct[i] = fct[i-1] * i % mod;
	}
	LL x = fct[MC];
	invfct[MC] = 1;
	for(int i = mod - 2 ; i > 0 ; i >>= 1){
		if(i % 2 == 1) (invfct[MC] *= x) %= mod;
		(x *= x) %= mod;
	}
	repm(i,MC,0){
		invfct[i-1] = invfct[i] * i % mod;
	}
}

LL comb(int x , int y){
	if(x < 0 || y < 0) return 0;
	return invfct[x] * invfct[y] % mod * fct[x+y] % mod;
}

bool solve(int y , int z , int a , LL r , bool b){
	if(z > N+1 || a > N+1) return 0;
	if(b){
		int x = V.size();
		int itr = x - 1 , itb = x - 1;
		int p = y , q = 0;
		for(auto c : s){
			if(c=='r'){
				if(itr >= 0) --itr;
				else if(p>0) --p;
				else if(q) --q;
			} else {
				if(itb > itr){
					q += V[itb]-1;
					--itb;
				} else if(q) --q;
			}
		}
		if(~itr || ~itb || p || q) return 0;
		LL w = fct[x+y] * r % mod;
		w = w * comb(N-z+1,z+2*x) % mod;
		(ans += w) %= mod;
	}
	solve(y,z,a+1,r,0);
	V.PB(a);
	for(int i = 1 ; solve(y,z+2*a*i,a+1,r*invfct[i]%mod,1) ; ++i) V.PB(a);
	while(V.size() && *V.rbegin() == a) V.pop_back();
	return 1;
}

int main(){
	build();
	cin >> N >> K;
	cin >> s;
	for(int i = 0 ; solve(i,i*2,1,invfct[i],1) ; ++i);
	cout << ans << endl;
	return 0;
}


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


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


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

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP0(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define REP1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; ++i)

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

const int INTINF = 1e9;
const LL LLINF   = 1e18;
#define pow10(n) int(1e##n + n)

// dp[i][j] 下から i 桁目まで決めて,
// 繰り下がりが j:0/1 のときの支払う紙幣の合計最小値
int dp[1'000'002][2];

void solve()
{
    string S;
    cin >> S;
    reverse(S.begin(), S.end());
    S += '0';
    int N = S.length();

    REP0 (i, N + 1)
        REP0 (j, 2)
            dp[i][j] = INTINF;
    dp[0][0] = 0;

    REP0 (i, N)
    {
        int s = S[i] - '0';
        REP0 (j, 2)
        {
            // その桁が前の桁の引き算によって繰り下がっている j=1 とき, その桁では 1 枚多く払う必要がある.
            // また, ある桁での払い方は「s 枚ピッタリ払う（=繰り下がり発生させず）」か
            //「0 にして次の桁にまかせる（=繰り下がって,お釣りが 10-s 枚発生する）」かの二通りしかない
            dp[i + 1][0] = min(dp[i + 1][0], dp[i][j] + s + j);
            dp[i + 1][1] = min(dp[i + 1][1], dp[i][j] + 10 - (s + j));
        }
    }

    cout << dp[N][0] << endl;
}

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(10);
    solve();
    return 0;
}


Measured memory_bytes: 9116
#[allow(unused_macros)]
macro_rules! input_byline {
    ($($r:tt)* ) => {
        let stdin = std::io::stdin();
        let mut q = std::collections::VecDeque::new();
        let mut next = || {
            if q.is_empty() {
                let mut s = String::new();
                stdin.read_line(&mut s);
                for v in s.split_whitespace() {
                    q.push_back(v.to_string());
                }
            }
            q.pop_front().unwrap()
        };
        input_inner!{next, $($r)*}
    };

}

#[allow(unused_macros)]
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

trait Printable {
    fn p(&self);
}

impl<T: std::fmt::Display> Printable for T {
    fn p(&self) {
        println!("{}", self);
    }
}

impl<T: std::fmt::Display> Printable for [T] {
    fn p(&self) {
        for i in 0..self.len() {
            if i != 0 {
                print!(" ");
            }
            print!("{}", self[i]);
        }
        println!("");
    }
}

#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{BinaryHeap, HashMap};

#[allow(dead_code)]
type Graph = Vec<Vec<usize>>;

const M: usize = 1000000007;

fn main() {
    input! {
        n: usize,
        a: [usize; n],
    }

    let mut v = vec![0; n];

    let mut ans = 1;
    let mut zeros = 3;
    for &x in &a {
        if x == 0 {
            ans *= zeros;
            ans %= M;
            zeros -= 1;
            v[0] += 1;
        } else {
            ans *= v[x - 1];
            ans %= M;
            v[x - 1] -= 1;
            v[x] += 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <array>
#include <vector>
#include <functional>
#include <unordered_map> 
#include <map> 
#include <numeric>
#include <limits>
#include <utility>
#include <queue>
using namespace std;
typedef long long LL;

int main(void) {
	LL n, i, j;
	cin >> n;
	vector<LL> a(n);
	vector<LL> b;
	vector<LL> c;
	for (i = 0; i < n; i++) {
		cin >> a[i];
		if (i % 2 == 0) {
			b.push_back(a[i]);
		}
		else {
			c.push_back(a[i]);
		}
	}
	if (a.size() == 1) {
		cout << a[0] << endl;
		return 0;
	}
	if (a.size() % 2 == 0) {
		cout << c[c.size() - 1];
		for (i = c.size() - 2; i >= 0; i--) {
			cout << ' ' << c[i];
		}
		for (i = 0; i <b.size(); i++) {
			cout << ' ' << b[i];
		}

		cout << endl;
	}
	else {
		cout << b[b.size()-1];
		for (i = b.size() - 2; i >=0; i--) {
			cout << ' ' << b[i];
		}
		
		for (i = 0; i<c.size(); i++) {
			cout << ' ' << c[i];
		}
		
		cout << endl;
	}

	return 0;
}

Measured memory_bytes: 5484
#include <iostream>
#include <complex>
#include <sstream>
#include <string>

using namespace std;

typedef complex<double> Point;

//Verified PKU 2812
double cross(const Point &v1, const Point &v2) {
    return (v1.real()*v2.imag()) - (v1.imag()*v2.real());
}

//Verified AOJ 0012
bool ccw(const Point &p1, const Point &p2, const Point &p3) {
    return cross(p2-p1, p3-p1) < 0;
}

int main() {
    string line;
    while(cin >> line) {
        for(int i = 0; i < line.size(); ++i)
            if(line[i] == ',') line[i] = ' ';
        istringstream is(line);
        Point ps[4];
        for(int i = 0; i < 4; ++i) is >> ps[i].real() >> ps[i].imag();
        bool prev = ccw(ps[0], ps[1], ps[2]);
        bool ok = true;
        for(int i = 1; i < 4; ++i) {
            if(ccw(ps[i], ps[(i+1)%4], ps[(i+2)%4]) != prev) {
                ok = false;
                break;
            }
        }
        cout << (ok?"YES":"NO") << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>

using namespace std;


int main() {
    
    long n;
    cin >> n;
    string s,t;
    unordered_map <string, int> dic;
    for (int i=0;i<n;i++){
        cin >> s >> t;
        if(s == "insert"){
            dic[t] = 1;
        }else{
            if(dic[t] == 1){
                cout << "yes" << endl;
            }else{
                cout << "no" << endl;
            }
        }
    }
}


Measured memory_bytes: 50164