akhauriyash/Code-Regression huggingface dataset:
var brokenStairs = mutableSetOf<Int>()
var memo = mutableMapOf<Int, Int>()
val modnum = 1000000007

fun main(args: Array<String>) {
    val (N, M) = readLine()!!.split(" ").map { it.toInt() }
    for (i in 0..M - 1) {
        brokenStairs.add(readLine()!!.toInt())
    }
    print(fibonacci(N))
}

fun fibonacci(n: Int): Int {
    if (memo.containsKey(n)) {
        return memo[n]!!
    }
    when (n) {
        0, 1 -> {
            if (brokenStairs.contains(n)) {
                memo[n] = 0
            } else {
                memo[n] = 1
            }
        }
        else -> {
            if (brokenStairs.contains(n)) {
                memo[n] = 0
                fibonacci(n - 1)
            } else {
                memo[n] = (fibonacci(n - 1) + fibonacci(n - 2)) % modnum
            }
        }
    }
    return memo[n]!!
}


Measured memory_bytes: 71604
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main() {
  string s;
  cin >> s;
  int n = s.size();
  int dp[200001];
  dp[0] = 0;
  REP(i, n) {
    if (i == 0) {
      dp[i + 1] = 1;
    } else if (i == 1) {
      dp[i + 1] = (s[i - 1] == s[i] ? 1 : 2);
    } else {
      if (s[i - 1] == s[i]) {
        dp[i + 1] = 2 + dp[i - 2];
      } else {
        dp[i + 1] = 1 + dp[i];
      }
    }
  }
  cout << dp[n] << endl;
  return 0;
}

Measured memory_bytes: 1412
n=int(input())

d=[]

for i in range(n):
    d.append(int(input()))

k=0


for i in range(n-1):

    for j in range(i+1,n):
        if d[i]==d[j]:
            j -= 1
            break

    if j == n-1:
        k += 1
k += 1

print(k)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ll long long
 
int main(void){
    int a,b; cin>>a >> b;
    string s; cin >> s;
    bool flag = true;
    if(s[a]!='-') flag = false;
    for(int i=0;i<a;i++){
        if(s[i]<'0' || '9'<s[i]) flag = false; 
    }
    for(int i=a+1;i<a+b;i++){
        if(s[i]<'0' || '9'<s[i]) flag = false; 
    }
    if(flag == true) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			long r = 1;
			while(n--!=0)
				r *= n + 1;
			Console.WriteLine(r);
		}
	}
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    string s, t;
    cin >> s >> t;
    ll L = n;
    L = L / __gcd(n, m) * m;
    for (int i = 0; i < n; i++) {
        ll hoge = (L / n) * i;
        if (hoge % (L / m) != 0) continue;
        ll foo = hoge / (L / m);
        if (foo >= m || foo < 0) continue;
        if (s[i] == t[foo]) continue;
        cout << -1 << endl;
        return 0;
    }

    for (int i = 0; i < m; i++) {
        ll hoge = (L / m) * i;
        if (hoge % (L / n) != 0) continue;
        ll foo = hoge / (L / n);
        if (foo >= n || foo < 0) continue;
        if (t[i] == s[foo]) continue;
        cout << -1 << endl;
        return 0;
    }

    cout << L << endl;
    return 0;
}

Measured memory_bytes: 640
#include <stdio.h>          // printf(), putchar(), getc()
#include <string.h>         // memcpy()
#include <ctype.h>          // isdigit()

#define MAX_N 500000
#define SENTINEL 2000000000

const char NUL = '\0';
int l[MAX_N / 2 + 2], r[MAX_N / 2 + 2];
int count;

void
merge(int a[], int left, int mid, int right)
{
	int i, j, k;

	const int n1 = mid - left;
	const int n2 = right - mid;
	memcpy(l, &a[left], sizeof(int) * n1);
	memcpy(r, &a[mid], sizeof(int) * n2);
	l[n1] = SENTINEL, r[n2] = SENTINEL;

	i = 0, j = 0;
	for (k = left; k < right; ++k)
	{
		count++;
		if (l[i] <= r[j])
			a[k] = l[i++];
		else
			a[k] = r[j++];
	}
}

void
mergesort(int a[], int left, int right)
{
	if (left + 1 < right)
	{
		int mid = (left + right) / 2;
		mergesort(a, left, mid);
		mergesort(a, mid, right);
		merge(a, left, mid, right);
	}	
}

void
print_number(int n)
{
	char text[12];
	char* s = &text[11];
	*s = NUL;
	do
	{
		int m = n % 10;
		*--s = m + '0';
		n /= 10;
	} while (n != 0);

	printf("%s", s);
}

int
main(int argc, char** argv)
{
	int a[MAX_N];
	int n, m;
	int i;
	int c;

	c = getc(stdin);
	n = 0;
	while (isdigit(c))
	{
		n = n * 10 + c - '0';
		c = getc(stdin);
	}

	for (i = 0; i < n; ++i)
	{
		while (c == ' ' || c == '\n')
			c = getc(stdin);

		m = 0;
		while (isdigit(c))
		{
			m = m * 10 + c - '0';
			c = getc(stdin);
		}

		a[i] = m;
	}

	count = 0;
	mergesort(a, 0, n);

	for (i = 0; i < n; ++i)
	{
		print_number(a[i]);
		putchar((i != n - 1) ? ' ' : '\n');
	}

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

Measured memory_bytes: 4432
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
using namespace std;

#ifdef WIN32
	#define LL "%I64d"
#else
	#define LL "%lld"
#endif

#ifdef CT
	#define debug(...) printf(__VA_ARGS__)
	#define setfile() 
#else
	#define debug(...)
	#define filename ""
	#define setfile() freopen(filename".in", "r", stdin); freopen(filename".out", "w", stdout)
#endif

#define R register
#define getc() (_S == _T && (_T = (_S = _B) + fread(_B, 1, 1 << 15, stdin), _S == _T) ? EOF : *_S++)
#define dmax(_a, _b) ((_a) > (_b) ? (_a) : (_b))
#define dmin(_a, _b) ((_a) < (_b) ? (_a) : (_b))
#define cmax(_a, _b) (_a < (_b) ? _a = (_b) : 0)
#define cmin(_a, _b) (_a > (_b) ? _a = (_b) : 0)
#define cabs(_x) ((_x) < 0 ? (- (_x)) : (_x))
char _B[1 << 15], *_S = _B, *_T = _B;
inline int F()
{
	R char ch; R int cnt = 0; R bool minus = 0;
	while (ch = getc(), (ch < '0' || ch > '9') && ch != '-') ;
	ch == '-' ? minus = 1 : cnt = ch - '0';
	while (ch = getc(), ch >= '0' && ch <= '9') cnt = cnt * 10 + ch - '0';
	return minus ? -cnt : cnt;
}
#define maxn 100010
string s, alphabet, str[maxn];
int k, id;
struct Node
{
	int size, id;
	Node *ch[26];
}mem[400010], *root = mem, *tot = mem;
void insert(R Node *now, R int dep)
{
	if (!now -> ch[s[dep] - 'a'] && dep < s.size())
		now -> ch[s[dep] - 'a'] = ++tot;
	if (dep < s.size()) insert(now -> ch[s[dep] - 'a'], dep + 1);
	else now -> id = id;
	++now -> size;
}
inline int Size(R Node *x)
{
	return x ? x -> size : 0;
}
int f[maxn][26][26], ans;
int substr[maxn];
void build(R Node *x, R int dep)
{
	if (x -> id == id) return ;
	substr[id] += x -> id > 0;
	R int now = str[id][dep] - 'a';
	for (R int i = 0; i < 26; ++i)
	{
		if (i == now) build(x -> ch[i], dep + 1);
		else f[id][now][i] += Size(x -> ch[i]);
	}
}
int main()
{
//	setfile();
	int n, Q; cin >> n;
	for (id = 1; id <= n; ++id)
	{
		cin >> s;
		str[id] = s;
		insert(root, 0);
	}
	for (id = 1; id <= n; ++id) build(root, 0);
	cin >> Q;
	for (; Q; --Q)
	{
		cin >> k >> alphabet;
		ans = 1 + substr[k];
		// cout << "substr = " << substr[k] << endl;
		for (R int i = 0; i < 26; ++i)
			for (R int j = i + 1; j < 26; ++j)
				ans += f[k][alphabet[j] - 'a'][alphabet[i] - 'a'];
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 295680
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e16;

/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/
int main(void) {
    cin.tie(0); ios::sync_with_stdio(false);
    ll N,Y; cin >> N >> Y;
    Y /= 1000;
    for(int x = 0; x <= 2000; x++){
        for(int y = 0; x + y <= 2000; y++){
            if(x + y > N) break;
            if(Y - N == 9 * x + 4 * y){
                cout << x << " " << y << " " <<  N - x - y << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " <<-1 << " " << -1 << endl;
    return 0;
}



Measured memory_bytes: 256
// 11/06/20 // 00:10 AM //

#include <bits/stdc++.h>

using namespace std;

#define int long long

const int MAXN = (int)(1e4) + 10;
const int MAXSUM = 110;
const int MOD = (int)(1e9)+7;

int d, n;
int num[MAXN], memo[MAXN][MAXSUM][3];

int solve(int i, int sum, int flag){
    if(memo[i][sum][flag] != -1) return memo[i][sum][flag];

    int& ans = memo[i][sum][flag];

    if(i>=n)
        return ans = (sum%d==0? 1: 0);

    ans = 0;
    if(!flag){
        for(int j=0; j<=9; j++){
            ans += solve(i+1, (sum+j)%d, 0)%MOD;
            ans %= MOD;
        }
    }
    else{
        for(int j=0; j<num[i]; j++){
            ans += solve(i+1, (sum+j)%d, 0)%MOD;
            ans %= MOD;
        }
        ans += solve(i+1, (sum+num[i])%d, 1)%MOD;
        ans %= MOD;
    }

    return ans;
}

int32_t main(){

    string temp;
    cin >> temp >> d;
    n = temp.size();

    for(int i=0; i<n; i++) num[i] = (int)(temp[i] - '0');

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

    cout << (MOD+solve(0, 0, 1)-1)%MOD << endl;

    return 0;
}


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

int main(){
  int H,W;
  cin >> H >> W;
  vector<string> C(H);
  for(int i=0;i<H;i++){cin >> C[i];}
  for(int i=0;i<H;i++){
    cout << C[i] << endl;
    cout << C[i] << endl;
  }
}

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

int main()
{
    int n;
    while(cin>>n)
    {
        int ans=0;
        for(int a=0;a<10;++a){
            for(int b=0;b<10;++b){
                for(int c=0;c<10;++c){
                    for(int d=0;d<10;++d)
                        if(a+b+c+d==n)ans++;
                }
            }
        }
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <deque>
#include <queue>
#include <iomanip>

using namespace std;
typedef long long ll;
typedef pair<int, int> P;

int main(){
    int N, M;
    cin >> N >> M;
    int s[2][M];
    for(int i = 0; i < M; i++){ 
        cin >> s[0][i] >> s[1][i];
    }
    int cnt = 0;
    if(N == 1){
        for(int i = 0; i <= 9; i++){
            for(int j = 0; j < M; j++){
                if(i != s[1][j]){
                    cnt++;
                }
            }
            if(cnt == 0){
                cout << i;
                return 0;
            }
            cnt = 0;
        }
        cout << -1;
        return 0;
    } else if(N == 2){
        for(int i = 10; i <= 99; i++){
            int a[2];
            a[0] = (i/10)%10;
            a[1] = i%10;
            for(int j = 0; j < M; j++){
                if(a[s[0][j]-1] != s[1][j]) cnt++;
            }
            if(cnt == 0){
                cout << i;
                return 0;
            }
            cnt = 0;
        }
        cout << -1;
        return 0;
    } else {
        for(int i = 100; i <= 999; i++){
            int a[3];
            a[0] = ((i/10)/10)%10;
            a[1] = (i/10)%10;
            a[2] = i%10;
            for(int j = 0; j < M; j++){
                if(a[s[0][j]-1] != s[1][j]) cnt++;
            }
            if(cnt == 0){
                cout << i;
                return 0;
            }
            cnt = 0;
        }
        cout << -1;
        return 0;
    }
}

Measured memory_bytes: 256
package main

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

const (
	initialBufSize = 100000
	maxBufSize     = 10000000
)

var (
	sc = bufio.NewScanner(os.Stdin)
	wt = bufio.NewWriter(os.Stdout)
)

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

func puts(a ...interface{}) {
	fmt.Fprintln(wt, a...)
}

func min(nums ...int) int {
	ret := nums[0]
	for _, v := range nums {
		if v < ret {
			ret = v
		}
	}
	return ret
}

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, initialBufSize), maxBufSize)
	defer wt.Flush()

	s := next()
	n := len(s)

	cntS, cntST := 0, 0

	for i := 0; i < n; i++ {
		if s[i] == 'S' {
			cntS++
		} else if cntS > 0 {
			cntS--
			cntST++
		}
	}

	puts(n - 2*cntST)
}


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


void solve() {
    string s;
    cin >> s;
    int ans = 0;
    int tans = 0;
    for (auto i: s) {
        if (i == 'R') tans++;
        else tans = 0;
        ans = max(ans, tans);
    }
    cout << ans << endl;
}

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


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

int solve(){
  string s;cin >> s;
  int pre = 0, suf=s.length()-1;
  int num = 0;
  while(suf-pre>=1){
    if(s[pre] ==  s[suf]){
      ++pre;
      --suf;
    }else if(s[pre] == 'x'){
      ++pre;
      ++num;
    }else if(s[suf] == 'x'){
      --suf;
      ++num;
    }else return -1;
  }
  return num;
}

int main(void){
  SPEEDUP
  cout << setprecision(15);
  cout << solve() << endl;
  return 0;
}


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

int gcd(int a, int b) {
  if (a < b) {swap(a, b);}
  if (b == 0) return a;
  return gcd(b, a % b);
}


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

  int GCD = a[1];
  for (int i = 2; i < N; i++) {
    GCD = gcd(GCD, a[i]);
  }
  
  //a[0]の約数列挙
  vector<int> div;
  for (int n = 1; n * n <= a[0]; n++) {
    if (a[0] % n == 0) {
      if (n * n != a[0]) {
        div.push_back(n);
        div.push_back(a[0] / n);
      } else {
        div.push_back(n);
      }
    }
  }
  sort(div.begin(), div.end());
  
  
  
  int ans;
  for (int i = 0; i < div.size(); i++) {
    int flag = 0;
    for (int j = 1; j < N; j++) {
      if (a[j] % div.at(i) != 0) {flag++;}
    }
    
    if (flag <= 1) {ans = div[i];}
  }
  
  ans = max(ans, GCD);
  cout << ans << endl;
}

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

unsigned long long now,n,k,flag;

void deal1()
{
	cout<<n<<endl;
	for(int i=0;i<=n;i++)
	{
		if((k-i)%50==0)
		{
			flag=i;
		}
	}
	unsigned long long tmp=(k-flag)/50;
	for(int i=1;i<=n;i++)
	{
		if(i<=flag)
		{
			printf("%lld ",tmp+50-i+1);
		}else printf("%lld ",tmp+50-i);
	}
}

void deal2()
{
	cout<<n<<endl;
	for(int i=0;i<n;i++)
	{
		printf("%lld ",n-i);
	}
}

int main()
{
	scanf("%lld",&k);
	if(k==0)
	{
		puts("2");
		puts("1 1");
	}
	else if(k==1)
	{
		puts("2");
		puts("3 0");
	}
	else if(k>50)n=50,deal1();
	else n=k,deal2();
	return 0;
}

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

int cnt;
bool isleft, now;
string leftkey = "qwertasdfgzxcvb";

int main(void){
	while(true){
		cnt = 0;
		string str;
		cin >> str;
		if(str == "#")	break;
	
		if(leftkey.find(str[0]) != string::npos){
			now = true;
		}else{
			now = false;
		}

		for(int i = 1; i < str.size(); i++){
			if(leftkey.find(str[i]) != string::npos){
				isleft = true;
			}else{
				isleft = false;
			}
			if(isleft != now)	cnt++;
			now = isleft;
		}

		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
#include <algorithm>     //sort,二分探索,など
#include <bitset>        //固定長bit集合
#include <cmath>         //pow,logなど
#include <complex>       //複素数
#include <deque>         //両端アクセスのキュー
#include <functional>    //sortのgreater
#include <iomanip>       //setprecision(浮動小数点の出力の誤差)
#include <iostream>      //入出力
#include <map>           //map(辞書)
#include <numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include <queue>         //キュー
#include <set>           //集合
#include <stack>         //スタック
#include <string>        //文字列
#include <unordered_map> //イテレータあるけど順序保持しないmap
#include <unordered_set> //イテレータあるけど順序保持しないset
#include <utility>       //pair
#include <vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int mod = 1e+9 + 7;

//マクロ
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = (ll)(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 ALL(x) (x).begin(), (x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size())      //sizeをsize_tからllに直しておく
#define MAX(x) *max_element(ALL(x))
#define INF 1000000000000
#define MOD 10000007
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define INFTY 10000001
#define WHITE 0
#define GRAY 1
#define BLACK 2

#define N 100

int main()
{
  int n, x, y;
  cin >> n >> x >> y;
  x--;
  y--;
  vector<ll> ans(n);
  rep(sv, n)
  {
    vector<ll> dist(n, INF);
    queue<int> q;
    auto push = [&](int v, int d) {
      // svからの距離
      if (dist[v] != INF)
        return;
      dist[v] = d;
      q.push(v);
    };
    push(sv, 0);
    while (!q.empty())
    {
      int v = q.front();
      q.pop();
      int d = dist[v];
      if (v - 1 >= 0)
        push(v - 1, d + 1);
      if (v + 1 < n)
        push(v + 1, d + 1);
      if (v == x)
        push(y, d + 1);
      if (v == y)
        push(x, d + 1);
    }
    // dist[i]は距離 ansは距離ごとの配列なので
    rep(i, n) ans[dist[i]]++;
  }
  rep(i, n) ans[i] /= 2;
  for (int i = 1; i <= n - 1; i++)
  {
    cout << ans[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#define M 1000000
#define L 14

char H[M][L];
int GetChar(char ch){
        if(ch=='A') return 1;
        else if(ch=='C') return 2;
        else if(ch=='G') return 3;
        else if(ch=='T') return 4;
        else return 0;
}
int h1(int key){
        return key % M;
}
int h2(int key){
        return 1+(key % (M-1));
}
long long IntegerKey(char str[]){
        long long sum=0,p=1,i;
        for(i=0; i<strlen(str); i++) {
                sum+=p*(GetChar(str[i]));
                p*=5;
        }
        return sum;
}


int Find(char str[]){
        long long key,i,h;
        key=IntegerKey(str);
        for(i=0;; i++) {
                h = (h1(key) + i * h2(key)) % M;
                if(strcmp(H[h],str)==0) return 1;
                else if(strlen(H[h])==0) return 0;
        }
        return 0;
}

int insert(char str[]){
        long long key,i,h;
        key=IntegerKey(str);
        for(i=0;; i++) {
                h = (h1(key) + i * h2(key)) % M;
                if(strcmp(H[h],str)==0) return 1;
                else if(strlen(H[h])==0) {
                        strcpy(H[h],str);
                        return 0;
                }
        }
        return 0;
}

int main(){
        int i,n,h;
        char str[L],com[9];

        for(i = 0; i < M; i++) H[i][0]='\0';
        scanf("%d",&n);
        for(i=0; i<n; i++) {
                scanf("%s %s",com,str);

                if(com[0]=='i') {
                        insert(str);
                }
                else {
                        if( Find(str) ) {
                                printf("yes\n");
                        }
                        else{
                                printf("no\n");
                        }
                }
        }
        return 0;


}



Measured memory_bytes: 15400
#include <iostream>
#include <map>
#include <string>

using namespace std;

int main(){
  int q,t,x;
  string k,l,r;
  map<string,int,less<>> a;

  cin >> q;
  for (int i = 0; i < q; i++){
    cin >> t;
    if (t == 0){
      cin >> k;
      auto itr = a.find(k);
      cin >> x;
      if (itr == a.end()){
        a.insert(make_pair(k, x));
      }else{
        a[itr->first]=x;
      }
    }else if(t == 1){
      cin >> k;
      auto itr = a.find(k);
      if (itr != a.end()){
        cout << itr->second << endl;
      }else{
        cout << "0" << endl;
      }
    }else if(t == 2){
      cin >> k;
      a.erase(k);
    }else{
      cin >> l;
      cin >> r;
      auto itr_s = a.lower_bound(l);
      auto itr_e = a.upper_bound(r);

      while (itr_s != itr_e) {
        cout << itr_s->first << " " << itr_s->second << endl;
        ++itr_s;
      }
    }
  }

  return 0;
}



Measured memory_bytes: 27684
def main():
    n = int(input())
    c = input()
    r = 0
    for i in range(n):
        if c[i]=='R':
            r += 1
    ans = 0
    for i in range(r):
        if c[i]=='W':
            ans += 1
    print(ans)

if __name__ == "__main__":
    main()


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

const int N = 200005;
char s[N];

int main(void) {
    int n; scanf("%d", &n);
    scanf("%s", s + 1);
    int l = 1, r = n;
    int ans = 0;
    while (1) {
        while (s[l] == 'R' && l < r) ++l;
        while (s[r] == 'W' && l < r) --r;
        if (l == r) break;
        swap(s[l], s[r]);
        ans++;
    }
    printf("%d\n", ans);

    return 0;
}

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

int h[100];

int main()
{
	int n;
	cin >> n;
	int max = h[1];
	int a = 0;
	for (int i = 1; i <= n; ++i)
	{
		cin >> h[i];
		if (h[i] >= max)
		{
			a = a + 1;
			max = h[i];
		}
	}
	cout << a;
}

Measured memory_bytes: 256
x,k=map(int,input().split())
a=list(map(int,input().split()))
dp=[0]*x
dp[1]=abs(a[1]-a[0])
for i in range(2,x):
    p=10000000001
    for j in range(max(0,i-k),i):
        p=min(p,dp[j]+abs(a[i]-a[j]))
        
    dp[i]=p
print(dp[x-1])    

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

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

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

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

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

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

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

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

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

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

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

    int n,m;
    cin >>n>>m;
    
    vector<pii>op(m);
    rep(i,m){
        int s,c;
        cin>>s>>c;
        pii em = {s,c};
        op[i] = em;
    }

    if(m==0){
        if(n==1)cout<<0<<endl;
        else if(n==2)cout<<10<<endl;
        else cout<<100<<endl;
        return 0;
    }

    int lim = (int)pow(10,n) + 10;
    //db(lim);ln;
    
    rep(i,lim){
        string num = to_string(i);
        //db(num);ln;

        bool jud=true;
        rep(j,m){

            if(op[j].fi > num.length() || num.length() != n){
                jud=false;
                break;
            }
            if(num[op[j].fi - 1] != '0' + op[j].se){
                jud=false;
                break;
            }
        }
        if(jud){
            ans=i;
            break;
        }
    }

    //cout <<fixed<<setprecision(16)<< << endl;
    cout<<ans<<endl;
    //if(flag)cout << "Yes" <<endl;
    //else cout << "No" <<endl;
    
    return 0;
}


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

int main()
{
    long long x; cin>>x;///103
    long long p=100,cnt=0;
    while(p<x){///100<1333333333, 100,101,102
        p+=p/100;///p=100+100/100=101, p=101+101/100=102+1=103
        cnt++;///1,2,3
    }
    cout<<cnt<<endl;
    return 0;
}


Measured memory_bytes: 3632
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <algorithm>
#include <cmath>

using namespace std;

#define mp make_pair
#define pb push_back
#define ll long long

const ll mod = 1000000007LL;
const ll limit = 10000000LL;

ll S, i, j, p, act, aux;
ll last, sols;

ll poww(ll a, ll b) {
    ll ans = 1;

    while (b > 0) {
        if (b & 1) ans = (ans * a) % mod;
        b >>= 1;
        a = (a * a) % mod;
    }

    return ans;
}

ll cnt(ll x) {
    ll ans = 0;
    while (x > 0) {
        ans++;
        x /= 10;
    }
    last = ans;
    return ans;
}

void check(ll len) {
    if (len > aux) return;

    ll val = S / len;
    ll cnt = poww(10, val) - poww(10, val - 1) + mod;
    sols += cnt - len + 1 + mod;
    sols += mod - 1;
    sols %= mod;
}

int main()
{
  //  freopen("test.in","r",stdin);

    scanf("%lld", &S);

    act = 0;
    while (act + cnt(p + 1) <= S) {
        act += last;
        p++;
    }

    for (i = 1; i < limit; i++) {
        if (act + cnt(p + 1) <= S) {
            act += last;
            p++;
        }

        if (act == S) {
            sols++;

            /*act = 0;
            for (j = i; j <= p; j++) act += cnt(j);
            if (act != S) sols--;*/
        }
        if (act == 0) break;
        act -= cnt(i);
    }

    aux = S / 8;
    sols += aux;

    for (ll d = 1; d * d <= S; d++) {
        if (S % d) continue;
        check(d);
        if (d * d != S) check(S / d);
    }

    printf("%lld", sols);

    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <cstdlib>

using namespace std;

int main(){
  int N;
  int prev_t = 0;
  int prev_x = 0;
  int prev_y = 0;
  cin >> N;
  for (int i=0;i<N;i++) {
    int t, x, y;
    cin >> t >> x >> y;
    int dt = t - prev_t;
    int dx = x - prev_x;
    int dy = y - prev_y;
    int dist = abs(dx) + abs(dy);
    if (dist > dt) {
      cout << "No" << endl;
      return(0);
    }
    if ((dist % 2) != (dt % 2)) {
      cout << "No" << endl;
      return(0);
    }
    prev_t = t;
    prev_x = x;
    prev_y = y;
  }
  cout << "Yes" << endl;
  return(0);
}


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

int cmp(void *x, void *y)
{
  return *(int *)x - *(int *)y;
}

int main(void)
{
  int n;
  int v[50];
  
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", &v[i]);
  
  qsort(v, n, sizeof(int), cmp);
  
  double ans = v[0];
  for (int i = 1; i < n; i++) {
    ans = (ans+v[i])/2;
  }
  
  printf("%.10f", ans);
  
  return 0;
}

Measured memory_bytes: 128
# encoding:utf-8
import math

def main():
	N, A, B, C, D = list(map(int, input().split()))

	for i in range(N):
		plus_band = calcBand(i, C, D)
		minus_band = calcBand(N - i - 1, C, D)
		total_band = (plus_band[0] - minus_band[1], plus_band[1] - minus_band[0])

		if total_band[0] <= B - A <= total_band[1]:
			print("YES")
			break
	else:
		print("NO")

def calcBand(n_band, C, D):
	return((C * n_band, D * n_band))

if __name__ == '__main__':
	main()

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

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(itr,v) for(auto &(itr):(v))
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define mp(x,y) make_pair((x),(y))
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define log2(x) log(x)/log(2)
#define ln '\n'
#define bln(i,n) (i==n-1?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ');}}

typedef long double ld;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<bool> vb;
typedef vector<ld> vld;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

struct oreno_initializer {
	oreno_initializer() {
		cin.tie(0);
		ios::sync_with_stdio(0);
	}
} oreno_initializer;

// ━━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…
// .｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋.｡.:( ^ω^)・ﾟ＋
// ・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・‥…━━━☆・

int a, b;
string s[100];

signed main() {
	cin >> a >> b;
	a--, b--;
	rep(i,50) rep(j,100) s[i].pb(a && i%2==0 && (i+j)%2 ? '.' : '#'), a -= (a && i%2==0 && (i+j)%2);
	reprt(i,99,50) rep(j,100) s[i].pb(b && i%2 && (i+j)%2 ? '#' : '.'), b -= (b && i%2 && (i+j)%2);
	cout << 100 << ' ' << 100 << ln;
	rep(i,100) cout << s[i] << ln;
}

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

int main()
{
  int A,B,sum,dif,in;
  cin>>A>>B;
  sum=A+B;
  dif=A-B;
  in=A*B;
  if(sum>=dif&&sum>=in) cout<<sum<<endl;
  else if(dif>=sum&&dif>=in) cout<<dif<<endl;
  else cout<<in<<endl;
}

Measured memory_bytes: 256
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

AB = []
for i in range(X):
    for j in range(Y):
        AB.append(A[i] + B[j])
AB.sort(reverse=True)

ABC = []
for i in range(min(len(AB), K)):
    for j in range(Z):
        ABC.append(AB[i] + C[j])
ABC.sort(reverse=True)

for i in range(K):
    print(ABC[i])

Measured memory_bytes: 147904
#include <bits/stdc++.h>
typedef long long int lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define LIMIT(d_in, d_min, d_max) max(d_min, min(d_max, d_in))
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int H, W, K;
	cin >> H >> W >> K;

	vector<vector<lint>> DP(H + 1, vector<lint>(W, 0));
	vector<lint> count(8);

	count[0] = 1;
	count[1] = 2;
	for (int i = 0; i < W - 2; i++)
	{
		count[i + 2] = count[i + 1] + count[i];
	}

	DP[0][0] = 1;
	for (int i = 0; i < H; i++)
	{
		for (int j = 0; j < W; j++)
		{
			if (0 < j)
			{
				DP[i + 1][j] += DP[i][j - 1] * count[max(0, j - 2)] % INV * count[max(0, W - j - 2)] % INV;
				DP[i + 1][j] %= INV;
			}
			DP[i + 1][j] += DP[i][j] * count[max(0, j - 1)] % INV * count[max(0, W - j - 2)] % INV;
			DP[i + 1][j] %= INV;
			if (j < W - 1)
			{
				DP[i + 1][j] += DP[i][j + 1] * count[max(0, j - 1)] % INV * count[max(0, W - j - 3)] % INV;
				DP[i + 1][j] %= INV;
			}
		}
	}
	//cout << H << " " << K << endl;
	cout << DP[H][K - 1] << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
	import java.util.Map.Entry;
	 
	 
	 class Main {
		 static int mod =  (int) (Math.pow(10,9)+7);
//		 static int mod =  (int) 998244353;
		 static List<ArrayList<Integer>>  list = new ArrayList<ArrayList<Integer>>();
	    public static void main(String[] args) {
	    	
	        Scanner sc = new Scanner(System.in);
	        long N = sc.nextLong();	
	        String S1 = sc.next();
	        char[] c1 = S1.toCharArray();
	        String S2 = sc.next();
	        char[] c2 = S2.toCharArray();
	        long ans=3;
	        boolean flg=false;
	        for(int i=0;i<N;i++) {
	        	if(c1[i]!=c2[i]) {
	        		if(i==0||flg==true) {
		        		ans=(ans*2)%mod;	        			
	        		} else {
		        		ans=(ans*3)%mod;	        				        			
	        		}
	        		i++;
	        		flg=false;
	        	} else {
	        		if(flg==true) {
	        			ans=(ans*2)%mod;
	        		}
	        		flg=true;
	        	}
	        }
	        
	        
	        System.out.println(ans);
	        

	    }
	    
	    

	}
	

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

#define DEBUG(x) cout<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cout<<#v<<":";for(int i=0;i<v.size();i++) cout<<" "<<v[i]; cout<<endl

typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
const int inf = 1000000001;
const ll INF = 2e18;
const ll MOD = 1000000007;
const ll mod = 1000000009;
const double pi = 3.14159265358979323846;
#define Sp(p) cout<<setprecision(15)<< fixed<<p<<endl;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
int dx2[8] = { 1,1,0,-1,-1,-1,0,1 }, dy2[8] = { 0,1,1,1,0,-1,-1,-1 };

class Cmp {
public:
	bool operator() (pll a, pll b) {
		if (a.first - a.second <= b.first - b.second) {
			return false;
		}
		else {
			return true;
		}
	}
};

int main() {
	ll x, y, z;
	cin >> x >> y >> z;
	vl a(x + y + z), b(x + y + z), c(x + y + z);
	rep(i, x + y + z) {
		cin >> a[i] >> b[i] >> c[i];
	}
	vector<pll> kg(x + y + z);
	rep(i, x + y + z) {
		kg[i].first = a[i] - b[i];
		kg[i].second = i;
	}
	sort(kg.begin(), kg.end());
	/*
	rep(i, x + y + z) {
		printf("(%lld, %lld) ", kg[i].first, kg[i].second);
	}
	cout << endl;
	//*/
	vl num(x + y + z); 
	priority_queue<pll, vector<pll>, Cmp> gd;
	ll gin = 0, dou = 0;
	rep(k, x + y + z - 1) {
		int idx = kg[k].second;
		if (gd.size() < y) {
			gin += b[idx];
			gd.push(pll(b[idx], c[idx]));
			if (gd.size() == y) {
				num[k] = gin;
			}
			else {
				num[k] = -1;
			}
			continue;
		}
		gin += b[idx];
		gd.push(pll(b[idx], c[idx]));
		dou += gd.top().second;
		gin -= gd.top().first;
		gd.pop();
		num[k] = gin + dou;
	}
	//DEBUG_VEC(num);
	priority_queue<pll, vector<pll>, Cmp> kd;
	ll kin = 0;
	dou = 0;
	for (int k = x + y + z - 1; k > 0; k--) {
		if (num[k - 1] < 0) {
			break;
		}
		int idx = kg[k].second;
		if (kd.size() < x) {
			kin += a[idx];
			kd.push(pll(a[idx], c[idx]));
			if (kd.size() == x) {
				num[k - 1] += kin;
			}
			else {
				num[k - 1] = -1;
			}
			continue;
		}
		kin += a[idx];
		kd.push(pll(a[idx], c[idx]));
		dou += kd.top().second;
		kin -= kd.top().first;
		kd.pop();
		num[k - 1] += kin + dou;
	}
	//DEBUG_VEC(num);
	ll ans = -1;
	rep(i, x + y + z) {
		ans = max(ans, num[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 7412
#include <stdio.h>
#include <string.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdlib.h>
#include <limits.h>
#include <math.h>
int acs(const void *a, const void *b) { return *(int *)a - *(int *)b; }                            /* 1,2,3,4.. */
int des(const void *a, const void *b) { return *(int *)b - *(int *)a; }                            /* 8,7,6,5.. */
int cmp_char(const void *a, const void *b) { return *(char *)a - *(char *)b; }                     /* a,b,c,d.. */
int cmp_str(const void *a, const void *b) { return strcmp(*(const char **)a, *(const char **)b); } /* aaa,aab.. */
#define min(a, b) (a < b ? a : b)
#define max(a, b) (a > b ? a : b)
#define rep(i, l, r) for (int i = l; i < r; i++)
#define MAX 100001
#define MOD 1000000007

typedef long long int lli;

int main(void)
{
  int a, b, c;
  scanf("%d %d %d", &a, &b, &c);

  int ans = a * b / 2;
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define per(i,a,b) for(int i=(b)-1;i>=(a);--i)
#define all(x) (x).begin(),(x).end()
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define fi first
#define se second
//INF = 1 061 109 567 ; INF + INF = 2 122 219 134 ;
//LINF = 4 557 430 888 798 830 399 ; LINF + LINF = 9 114 861 777 597 660 798 ;
const int INF = 0x3f3f3f3f;     // -INF: 0xc0   abs(-INF) = INF + 1
const ll LINF = 0x3f3f3f3f3f3f3f3f;
/*}}}*/                         // zr, zm
const int MOD = (int)1e9+7;     // when MOD = 1e9+7, inv2 = 500000004
const int N = (int)1e6+7;
const int M = (int)-1;

int main()

{
	int a;
	string s;
	cin>>a>>s;
	if(a >= 3200) cout<<s<<endl;
	else cout<<"red"<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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 equals(a, b) (fabs((a) - (b)) < EPS)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
const ll mod = 1000000007;
//const ll mod = 998244353;
const int inf = 1e9 + 10;
const ll INF = 1e18;
const ld EPS = 1e-10;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }



int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(25);

  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];

  ll ans = 0, sum = 0;
  stack<pair<ll, ll>> s;
  rep(i, n) {
    ll cnt = 1;
    while (!s.empty() && s.top().first > a[i]) {
      pair<ll, ll> p = s.top();
      s.pop();
      sum -= p.first * p.second;
      cnt += p.second;
    }
    sum += a[i] * cnt;
    ans += sum;
    s.push({a[i], cnt});
  }
  cout << ans << '\n';




  
  return 0;
}

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

Measured memory_bytes: 38536
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<queue>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
typedef long long ll;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    int n, q;
    cin >> n >> q;
    vector< pair<string, int> > p(n);
    queue< pair<string, int> > qu;
    rep(i, n){
        pair<string, int> p;
        cin >> p.first;
        cin >> p.second;
        qu.push(p);
    }
    int time=0;
    int flag = 0;
    while(!qu.empty()){
        pair<string, int> pt = qu.front();
        qu.pop();
        if(pt.second <= q){
            time += pt.second;
            cout << pt.first << " " << time << endl;
        }else{
            pt.second -= q;
            time += q;
            qu.push(pt);
        }
    }
}


Measured memory_bytes: 6828
#include <bits/stdc++.h>
#define rep0(i, n) for (int i = 0; i < (n); ++i)
#define rep1(i, n) for (int i = 1; i <= (n); ++i)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef tuple<string, int, int> TU;

int main()
{
    int N,M;
    cin >> N >> M;
    vector<int> dp(M+1);
    rep0(i,N){
        int K;
        cin >> K;
        rep0(j,K){
            int input ;
            cin >> input;
            dp[input]++;
        }
    }
    int res = 0;
    rep1(i,M){
        if(dp[i]==N){
            res++;
        }
    }
    cout << res << endl;
}


Measured memory_bytes: 3604
#include <algorithm>
#include <functional>
#include <iostream>

using namespace std;

int main()
{
	int n, s;
	while(cin >> n >> s, n&&s) {
		int cnt = 0, r[20000];
		for(int i = 0; i < n; i++) {
			cin >> r[i];
		}
		sort(r, r+n, greater<int>());
		for(int i = 0; i < n-1; i++) {
			if(r[i] + r[i+1] <= s) {
				break;
			}
			for(int j = n - 1; j > i; j--) {
				if(r[i] + r[j] > s) {
					cnt += j - i;
					break;
				}
			}
		}
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 908
#include "bits/stdc++.h"
using namespace std;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=2425&lang=jp
typedef long long ll;
#define INF 1<<30
#define MAXL 256
#define CENTER 128
int d[MAXL][MAXL][6];
bool masu[MAXL][MAXL];
int dx[7] = { 0,1,1,0,-1,-1,0 };
int dy1[7] = { 1,0,-1,-1,-1,0,0 };
int dy2[7] = { 1,1,0,-1,0,1,0 };
void init(int lx, int ly) {
	for (int i = -ly - 1; i <= ly + 1;i++) {
		masu[CENTER + lx + 1][CENTER + i] = true;
		masu[CENTER - lx - 1][CENTER + i] = true;
	}
	for (int i = -lx - 1; i <= lx + 1;i++) {
		masu[CENTER + i][CENTER + ly + 1] = true;
		masu[CENTER + i][CENTER - ly - 1] = true;
	}

	for (int i = 0; i < MAXL; i++) {
		for (int j = 0; j < MAXL;j++) {
			for (int k = 0; k < 6;k++) {
				d[i][j][k] = INF;
			}
		}
	}
}
int main() {
	cin.tie(0); ios::sync_with_stdio(false);
	int sx, sy, gx, gy; cin >> sx >> sy >> gx >> gy;
	sx += CENTER; sy += CENTER; gx += CENTER; gy += CENTER;
	int n; cin >> n;
	for (int i = 0; i < n;i++) {
		int x, y; cin >> x >> y;
		masu[CENTER + x][CENTER + y] = true;
	}
	int lx, ly; cin >> lx >> ly;
	init(lx, ly);

	/*                 x    y    t   */
	using Key = tuple<int, int, int>;
	d[sx][sy][0] = 0;
	queue<Key> q; q.push(Key(sx,sy, 0));
	while (!q.empty()) {
		int x, y, t; tie(x, y, t) = q.front(); q.pop();
		int dir = abs((x - CENTER)*(y - CENTER)*t) % 6;
		int nx, ny;
		int nt = t + 1;
		for (int i = 0; i < 7;i++) {
			nx = x + dx[i];
			if (x % 2 == 0) { ny = y + dy1[i]; }
			else { ny = y + dy2[i]; }

			int cost = 1;
			if (masu[nx][ny])continue;
			
			if (i == dir) cost = 0;
			if (d[nx][ny][nt % 6] > d[x][y][t % 6] + cost) {
				d[nx][ny][nt % 6] = d[x][y][t % 6] + cost;
				if (nx == gx && ny == gy) continue;
				q.push(Key(nx, ny, nt));
			}
		}
	}
	int ans = INF;
	for (int i = 0; i < 6;i++) {
		ans = min(ans, d[gx][gy][i]);
	}
	cout << (ans == INF ? -1 : ans) << endl;
	return 0;
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    string s;
    cin >> s;

    set<char> key;
    rep(i,s.size())
    {
        key.insert(s[i]);
    }

    ll ans = INF_LL;

    for( set<char>::iterator it = key.begin(); it != key.end(); it++)
    {
        ll tmp_ans = 0;
        string tmp_s = s;
        while(true)
        {
            bool flag = true;
            rep(i,tmp_s.size())
            {
                if( tmp_s[i] != *it ) flag=false;
            }
            if(flag) break;
            tmp_ans++;
            string next_s;
            rep(i,tmp_s.size()-1)
            {
                if( tmp_s[i] == *it ) next_s.push_back(tmp_s[i]);
                else next_s.push_back(tmp_s[i+1]);
            }
            tmp_s = next_s;
            //cout << s << endl;
        }
        chmin(ans, tmp_ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
inf = float('inf')

N = int(input())
S = [int(input()) for _ in range(N)]

ans = sum(S)
sub = inf
for s in S:
    if s % 10 != 0 and s < sub:
        sub = s
if ans % 10 == 0:
    if sub == inf:
        ans = 0
    else:
        ans -= sub
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
using namespace std;
using namespace std::chrono;
int main(){
    int p, q, r;
    cin >> p >> q >> r;
    int n = max({p,q,r});
    cout << p+q+r-n << endl;   
}



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

int main() {
  int N, X, T;
  cin >> N >> X >> T;
  int a;
  if (N % X == 0){
    a = N / X;
  }
  else{
    a = N / X + 1;
  }
  cout << a * T << endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int cnt=0;
	string s;
	cin>>s;
	for(int i=0;i<s.length();i++){
		if(s.substr(i,1)=="x"){
			cnt++;
		}
	}
	if(s.length()>=8 && cnt>=8){
		cout<<"NO"<<endl;
	}else{
		cout<<"YES"<<endl;
	}
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan =  new Scanner(System.in);
		int strLength = scan.nextInt();
		if(strLength % 2 == 0) {
			String strInput  = scan.next(); 				
			String result = strInput.subSequence(0, (strLength/2)).equals(strInput.substring((strLength/2), strLength)) ? "Yes" : "No";
			System.out.println(result);
		}
		else {
			System.out.println("No");
		}
			
	}
}


Measured memory_bytes: 22736
use proconio::{input, fastout};
use std::collections::HashMap;
#[fastout]
fn main() {
    input!(
        n: usize,
        s: [String; n],
    );

    let mut map = HashMap::new();

    map.insert(String::from("AC"), 0);
    map.insert(String::from("WA"), 0);
    map.insert(String::from("TLE"), 0);
    map.insert(String::from("RE"), 0);
    
    for si in s {
        let count = map.entry(si).or_insert(0);
        *count += 1;
    }

    println!("AC x {}", map.get(&String::from("AC")).unwrap());
    println!("WA x {}", map.get(&String::from("WA")).unwrap());
    println!("TLE x {}", map.get(&String::from("TLE")).unwrap());
    println!("RE x {}", map.get(&String::from("RE")).unwrap());
}


Measured memory_bytes: 7824
#coding:utf-8

while True:
    h, w = map(int, raw_input().split())
    if h == w == 0:
        break
    print(w * "#")
    for i in xrange(h - 2):
        print("#" +"." *(w - 2) +"#")
    print(w * "#")
    print("")

Measured memory_bytes: 6256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,l,r) for(long long i=(l);i<(r);++i)
#define REP(i,n) FOR(i,0,n)
#define REPS(i,n) FOR(i,1,n+1)
#define int long long
const int MOD=1e9+7;
const int INF=1e15;

signed main(){
    int N;cin>>N;
    int A[N];
    REP(i,N)cin>>A[i];
    int z=A[0]*2;
    REPS(i,N-2){
        z=A[i]*2-z;
    }
    int d=(A[N-1]*2-z)/2;
  	REP(i,N){
      	if(i==0)cout<<d<<" ";
      	else{
          	cout<<A[i-1]*2-d<<" ";
          	d=A[i-1]*2-d;
        }
    }
  	cout<<endl;
}

Measured memory_bytes: 2048