akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>

/*構造体の定義*/
typedef struct {
	char suit;
	int value;
} Card ;


void swap_Card(Card *x, Card *y)
{
	Card temp = *x;
	*x = *y;
	*y = temp;
}

/*バブルソート*/
void BubbleSort(Card A[], int N) {
	int i, j;

	for (i = 0; i < N - 1; i++) {
		for (j = N - 1; j >= i; j--) {
			if (A[j].value < A[j - 1].value) {
				swap_Card(&A[j], &A[j - 1]);
			}
		}
	}
}


/*選択ソート*/
void SelectionSort(Card A[], int N) {
	int i, j;
	int minj;

	for (i = 0; i < N - 1; i++) {
		minj = i;
		for (j = i + 1; j < N; j++) {
			if (A[j].value < A[minj].value) {
				minj = j;
			}
		}
		swap_Card(&A[i], &A[minj]);
	}
}


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

	int i,j;
	Card BC[N];
	Card SC[N];

	for (i = 0; i < N; i++) {
		Card c;
		scanf("%c", &c.suit);
		scanf("%d ", &c.value);
		BC[i] = c;
		SC[i] = c;
	}

	/* Bubble Sort */
    for (i = 0; i < N - 1; i++) {
        for (j = N - 1; j > i; j--) {
            if (BC[j].value < BC[j - 1].value)
                swap_Card(&BC[j], &BC[j - 1]);
        }
    }
	
	/* Selection Sort */
    for (i = 0; i < N - 1; i++) {
        int minj = i;
        for (j = i + 1; j < N; j++) {
            if (SC[j].value < SC[minj].value)
                minj = j;
        }
        swap_Card(&SC[i], &SC[minj]);
    }
	
	/* Output */
	for (i = 0; i < N - 1; i++) {
		printf("%c%d ", BC[i].suit, BC[i].value);
	}
	printf("%c%d\n", BC[N - 1].suit, BC[N - 1].value);
	puts("Stable");

	for (i = 0; i < N - 1; i++) {
		printf("%c%d ", SC[i].suit, SC[i].value);
	}
	printf("%c%d\n", SC[N - 1].suit, SC[N - 1].value);

	for (i = 0; i < N; i++) {
		if (BC[i].suit != SC[i].suit) {
			puts("Not stable");
			return 0;
		}
	}
	puts("Stable");

	return 0;
}


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

using namespace std;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	string str;
	cin >> str;
	int n=(int)str.size();
	
	bool bo=true;
	if(n&1) bo=false;
	for(int i=0;i<n;i++){
		if(i&1){
			if(str[i]!='i') bo=false;
		}else{
			if(str[i]!='h') bo=false;
		}
	}
	if(bo) cout << "Yes\n";
	else cout << "No\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <cstdint>
#include <map>
 
using namespace std;
typedef long long ll;

bool prime(ll n){
	for(ll i=2; i*i<=n; i++){
		if(n%i==0){
			return false;
		}
	}
	return true;
}

ll ans,mx,sum;

int main(){
	ll n;
	cin>>n;
	for(int i=n; i<= 10000000; i++){
		if(prime(i)) {
			cout<<i<<endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
//↓見なくていいよ！ここから--------------------------------------------------
var read = require('readline').createInterface({
  input: process.stdin,
  output: process.stdout
});
var obj;
var inLine = [];
read.on('line', function(input){inLine.push(input);});
read.on('close', function(){
  obj = init(inLine);
  myerr("-----start-----");
  var start = new Date();
  Main();
  var end = new Date() - start;
  myerr("----- end -----");
  myerr("time : " + (end) + "ms");
  myerr("memory : " + Math.round(process.memoryUsage().heapTotal / 1024) + "KB");
});
function nextInt(){return myconv(next(),1);} function nextStrArray(){return myconv(next(),2);}
function nextIntArray(){return myconv(next(),4);} function nextCharArray(){return myconv(next(),6);}
function next(){return obj.next();} function hasNext(){return obj.hasNext();}
function init(input){  
  var returnObj = {
    list : input, index : 0, max : input.length,
    hasNext : function(){return (this.index < this.max);},
    next : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(s){console.log(s);}
function myerr(s){console.error("debug:" + require("util").inspect(s,false,null));}
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す 1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map(Number);case 6:return i.split("");case 7:return i.split("").map(Number);case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}

//↑見なくていいよ！ここまで--------------------------------------------------
function Main(){
  var one = nextIntArray();
  var N = one[0];
  var M = one[1];
  var list = getDivisorList(M);
  var output = 1;
  for(var i = 0; i < list.length; i++){
    var min = list[i] * (N - 1);
    var max = M - min;
    if(max > 0 && min + max == M){
      output = Math.max(output, gcd(list[i], max));
    }
  }
  myout(output);
}
function gcd(m, n) {return n != 0 ? gcd(n, m % n) : m;}
function getDivisorList(val){
  var list = [];
  for(var i = 1; i * i <= val; i++){
    if(val % i == 0){
      list.push(i);
      if(i * i != val){
        list.push(val / i);
      }
    }
  }
  list.sort(function(a,b){ return a - b; });
  return list;
}

Measured memory_bytes: 33116
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>

typedef long long int ll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;

using namespace std;

int main()
{
	int N;
	cin >> N;
	if (N > 999)
	{
		cout << "ABD";
	}
	else
	{
		cout << "ABC";
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using P = pair<int, int>;
#define debug(var) cerr << "[" << #var << "] " << var << endl
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
const ll mod = 1000000007;
const int dx[] = {-1,0,1,0};
const int dy[] = {0,-1,0,1};


int main(){
    ll n, m;
    cin >> n >> m;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll ans = 0;
    map<ll, ll> mp;
    vector<ll> sum(n+1);
    rep(i, n) {
        sum[i+1] = sum[i] + a[i];
    }
    rep(i, n+1) {
        mp[sum[i]%m]++;
    }
    for (auto m: mp) {
        ll v = m.second;
        ans += v*(v-1)/2;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 5760
import java.util.Scanner;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		int[] p = new int[3];
		int[] j = new int[2];
		int minp = 2000,minj = 2000;
		
		for(int i = 0; i < 3; i++){
			p[i] = sc.nextInt();
			minp = Math.min(minp, p[i]);
		}
		
		for(int i = 0; i < 2; i++){
			j[i] = sc.nextInt();
			minj = Math.min(minj, j[i]);
		}
			
			System.out.println(minp + minj - 50);
			
			sc.close();
	}
}

Measured memory_bytes: 17364
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i,n) for(ll i=0;i<n;i++)
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){int len=d.size();rep(i,len){s<<d[i];if(i<len-1) s<<" ";}return s;}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){int len=d.size();rep(i,len){s<<d[i]<<endl;}return s;}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T> ostream& operator<<(ostream& s,const multiset<T>& v){s<<"{ ";for(auto itr=v.begin();itr!=v.end();++itr) {if (itr!=v.begin()) {s<< ", ";}s<<(*itr);}s<<" }";return s;}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){s<<"{"<<endl;for(auto itr=m.begin();itr!=m.end();++itr){s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;}s<<"}"<<endl;return s;}

const ll mod=1'000'000'007;
const ll inf=1'000'000'000'000'000'00;
const int INF=1'000'000'000;
const double EPS=1e-10;
const double PI=acos(-1);

/*
高速素因数分解
https://atcoder.jp/contests/abc177/tasks/abc177_e
http://tutuz.hateblo.jp/entry/2018/10/03/074039
*/

const int mx=1'000'100;

vector<ll> minfactor(1'000'100,-1);

//エラトステネスの篩,n以下の素数の列挙の時に
//primeはi番目の素数、適当に返却を変えて
template <class T>
void sieve(T n){
	vector<bool> is_prime(n+1,true);
	vector<ll> prime;
	is_prime[0]=false;
	is_prime[1]=false;
	T ret=0;
	FOR(i,2,n+1){
		if(is_prime[i]){
			prime.push_back(i);
			minfactor[i]=i;
			for(T j=2*i;j<=n;j+=i){
				is_prime[j]=false;
				if(minfactor[j]==-1) minfactor[j]=i;
			}
		}
	}
}

//素因数分解
template <class T>
ll prime_factor(T x){
    ll ret=1;
	while(x!=1){
		ll tmp=minfactor[x],cnt=0;
		while(x%tmp==0){ 
			x/=tmp;
            cnt++;
		}
        ret*=(cnt+1);
	}
    return ret;
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    sieve(n+10);
    ll ans=0;
    FOR(c,1,n){
        ll now=n-c;
        ll cnt=prime_factor(now);
        ans+=cnt;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 12216
N,M,K=map(int,input().split(' '))
mod = 998244353
ans =0
fac=[0]*(N+1)
inv=[0]*(N+1)
finv=[0]*(N+1)
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
inv[1] = 1
for i in range(2,N+1):
    fac[i] = fac[i-1]*i%mod
    inv[i] = mod-inv[mod%i]*(mod//i)%mod
    finv[i] = finv[i-1]*inv[i]%mod
def COM(n,k):
    return fac[n]*(finv[k]*finv[n-k]%mod)%mod
for i in range(K+1):
    ans += M*pow(M-1,N-1-i,mod)*COM(N-1,i)
    ans %=mod
print(ans)

Measured memory_bytes: 32444
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;

#define INF 999999999

int N, M, L;
double P[102], T[102], V[102];
double dp[102][102];
double p[102][102];

int main(){
  while(cin >> N >> M >> L){
    for(int i = 0; i < N; i++){
      cin >> P[i] >> T[i] >> V[i];
      P[i] /= 100.0;
    }

    for(int k = 0; k < N; k++){
      memset(dp, 0, sizeof(dp));
      dp[0][0] = 1.0;

      for(int i = 0; i < M; i++){
        for(int j = 0; j <= M; j++){
          dp[i + 1][j] += dp[i][j] * (1 - P[k]);
          dp[i + 1][j + 1] += dp[i][j] * P[k];
        }
      }

      for(int j = 0; j <= M; j++){
        p[k][j] = dp[M][j];
      }
    }

    for(int i = 0; i < N; i++){
      double ans = 0;

      for(int j = 0; j <= M; j++){
        double ti = INF;
        if(V[i] != 0) ti = (double)j * T[i] + (double)L / V[i];

        double mul = 1.0;

        for(int k = 0; k < N; k++){
          if(k == i) continue;

          double sum = 0;

          for(int l = 0; l <= M; l++){
            double tk = INF;
            if(V[k] != 0) tk = (double)l * T[k] + (double)L / V[k];
            if(ti >= tk) continue;
            sum += p[k][l];
          }

          mul *= sum;
        }

        ans += mul * p[i][j];
      }

      printf("%.8lf\n", ans);
    }
  }
}

Measured memory_bytes: 0
using System;

namespace PracticeForAtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            string[] str = Console.ReadLine().Split(' ');
            string[] str2 = Console.ReadLine().Split(' ');
            int a = int.Parse(str2[0]);
            int b = int.Parse(str2[1]);

            string s = Console.ReadLine();

            if (s == str[0]) a--;
            else b--;

            Console.WriteLine("{0} {1}", a, b);




            //ここまで
        }
    }
}


Measured memory_bytes: 13140
N, M =  map(int, input().split())
L = []
for i in range(N):
    a, b =  map(int, input().split())
    L.append([a,b])
L = sorted(L)
#print(L)
ans = 0
for i in range(N):
    a = L[i][0]
    b = L[i][1]
    if M >= b:
        ans += a * b
        M -= b
    elif M >0:
        ans += a * M
        M = 0

print(ans)        

Measured memory_bytes: 59608
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <queue>
#include <algorithm>
#include <utility>
#include <cmath>
#include <map>
#include <set>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
using namespace std;

#define INF_LL (ll)1e18
#define INF (int)1e9
#define REP(i, n) for(int i = 0;i < (n);i++)
#define FOR(i, a, b) for(int i = (a);i < (b);i++)
#define all(x) x.begin(),x.end()
using ll = long long;
using PII = pair<int, int>;

const double eps = 1e-10;

template<typename A, typename B>inline void chmin(A &a, B b){if(a > b) a = b;}
template<typename A, typename B>inline void chmax(A &a, B b){if(a < b) a = b;}

int main(void){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int cnt_nx = 0;
	string s;
	cin >> s;
	/*
	REP(i, s.size()){
		if(s[i] != 'x'){
			cnt_nx++;
		}
	}
	stack<char> st;
	stack<int> xn;
	int cnt = 0;
	cnt_nx = cnt_nx/2 + cnt_nx%2;
	REP(i, s.size()){
		if(cnt_nx && s[i] != 'x'){
			st.push(s[i]);
			xn.push(cnt);
			cnt = 0;
			cnt_nx--;
		}else if(cnt_nx){
			cnt++;
		}else if(cnt_nx == 0 && s[i] != 'x'){
			char a = st.top();
			cout << a << " " << s[i] << endl;
			st.pop();
			if(a != s[i]){
				cout << -1 << endl;
				return 0;
			}
		}
	}
	*/
	int l = 0, r = s.size()-1;
	int res = 0;
	while(l < r){
		if(s[l] == s[r]){
			l++; r--;
		}else if(s[l] == 'x' && s[r] != 'x'){
			l++; res++;
		}else if(s[l] != 'x' && s[r] == 'x'){
			r--; res++;
		}else{
			cout << -1 << endl;
			return 0;
		}
	}
	cout << res << endl;
}


Measured memory_bytes: 512
var n,m,k,i,s,a:longint;
begin
  readln(n,m,k);
  for i:=1 to n do
  begin
    s:=k-i*m;
    a:=n-i-i;
    if (s=0) or (a<>0) and (a*s>=0) and (s mod a=0) and (s div a<=m) then
    begin
      writeln('Yes');
      halt;
    end;
  end;
  writeln('No');
end.

Measured memory_bytes: 128
N, M, C = map(int, input().split())
B = list(map(int, input().split()))
mat = []
for i in range(N):
    mat.append(list(map(int, input().split())))

cnt = 0
for i in range(N):
    result = C
    for j in range(M):
        result += mat[i][j] * B[j]
    if result > 0:
        cnt += 1

print(cnt)


Measured memory_bytes: 3060
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define Vd vector<double>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b?gcd(b,a%b):a;} //最小公倍数
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n,m,a,b,c,d,x,y,z;
  string s,t;
  //

  // ここから
  IN4(a,b,c,d);
  if(a>b) OUT(b*c+(a-b)*d);
  else OUT(a*c);
}

Measured memory_bytes: 256
object Main extends App {
    val inf = Int.MaxValue-10000
    val in = io.Source.stdin.getLines
    val n = in.next.toInt
    val e = in.take(n).flatMap(x => {val y = x.split(" ").map(_.toInt); y.drop(2).map(z => Array(y(0), z))}).toList
    for (Array(s, d, v) <- in.take(in.next.toInt).map(_.split(" ").map(_.toInt))) {
        val g = Array.fill(n+1)(inf)
        g(s) = 1
        var flag = true
        while(flag) {
            flag = false
            for (b <- e) if (g(b(0)) + 1 < g(b(1))) {g(b(1)) = g(b(0)) + 1; flag = true}
        }
        println(if (v >= g(d)) g(d) else "NA")
    }
}

Measured memory_bytes: 48512
#include<iostream>
using namespace std;
int main(){
	int n,m,s=0,a,f=0;
	cin>>n>>m;
	for(int i=1;i<=n;i++){
		cin>>a;
		s+=a+m;//
		s-=max(a,f);
		f=a+m;
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 384
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
int ans,i,j,k,n,m;
int main(){
	scanf("%d%d",&n,&m);
	for (ans=100*(n-m)+1900*m;m--;ans*=2);
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 128
n, k = map(int, input().split())
h = list(map(int,input().split()))
if n <= k+1:
    print(abs(h[n-1]-h[0]))
else:
    dp = []
    for i in range(k+1):
        dp.append(abs(h[0]-h[i]))
    for i in range(k+1, n):
        dp_h = [dp[i-j] + abs(h[i]-h[i-j]) for j in range(1, k+1)]
        dp.append(min(dp_h))
    print(dp[n-1])

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

int main(void) {
	int N;
	cin >> N;

	string ans = "No";
	for (int d = 0; d <= N; d += 7) {
		int rest = N - d;
		if (rest % 4 == 0) {
			ans = "Yes";
			break;
		}
	}

	cout << ans << '\n';
	return 0;
}


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

using namespace std;

typedef long long int ll;
typedef pair<ll, ll> pll;

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    ll N, R;
    cin >> N >> R;
    R += std::max(0LL, 100 * (10 - N));
    cout << R << endl;
    return 0;
}

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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16
#define mod 1000000007

ll n,q;
ll a[200010];
ll cnt[200010];
ll seg[200010];
ll cnt0;

int main(){
  cin>>n>>q;
  rep(i,n){
    cin>>a[i];
    a[i]--;
    cnt[a[i]]++;
  }
  rep(i,n){
    seg[max(0LL,i+1-cnt[i])]++;
    seg[i+1]--;
  }
  rep(i,n)seg[i+1]+=seg[i];
  rep(i,n)if(seg[i]==0)cnt0++;
  while(q--){
    ll x,y;
    cin>>x>>y;
    x--;y--;

    { // dec
      ll p=a[x];
      ll idx=p+1-cnt[p];
      if(idx>=0){
        seg[idx]--;
        if(seg[idx]==0)cnt0++;
      }
      cnt[p]--;
    }
    { // inc
      ll p=y;
      ll idx=p-cnt[p];
      if(idx>=0){
        if(seg[idx]==0)cnt0--;
        seg[idx]++;
      }
      cnt[p]++;
    }
    a[x]=y;

    cout<<cnt0<<endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> p_ll;

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

void foreach_permutation(int n, std::function<void(int *)> f) {
  int indexes[n];
  for (int i = 0; i < n; i++) indexes[i] = i;
  do {
    f(indexes);
  } while (std::next_permutation(indexes, indexes + n));
}

int main() {
    ll N;
    cin >> N;
    int P[200200];
    rep(i,N) cin >> P[i];

    int tmp = INF;
    int res = 0;
    rep(i,N) {
        if (tmp >= P[i]) {
            tmp = P[i];
            res++;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <functional>
#include <algorithm>
#include <climits>
#include <string>
#include <vector>
#include <map>
#include <cmath>

using namespace std;

namespace _{struct _{_(){ // initialize
  cin.tie(0); ios::sync_with_stdio(false);
}}_;}
template <typename T, size_t size>
inline size_t len(const T (&)[size]) { return size; }
#define println(s) cout << s << '\n';
#define str to_string
#define rep(i, n) for (int i=0; i<int(n); i++)
#define all(c) (c).begin(), (c).end()

#define MAX_N 100002

bool list[MAX_N];
int n, k;

// O(n)
int eval(int pos) {
  int ret = -1;
  int cont = 0;
  for (int i=1; i<n+1; i++) {
    if (i == pos || list[i]) cont++;
    else {
      ret = max(ret, cont);
      cont = 0;
    }
  }
  return max(ret, cont);
}

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

    // zero clear
    rep(i, MAX_N) list[i] = false;
    rep(i, k) {
      int x; cin >> x;
      // x = 0: wildcard *
      list[x] = true;
    }


    int answer = -1;
    if (!list[0]) answer = eval(-1); // no wildcard; O(n)
    else {
      vector<int> v;
      bool prev = list[1]; // the previous number is `on`
      int empty_length = 0;
      int buf_start = 1;
      for (int i=2; i<n+1+1; i++) {
        // true
        if (list[i]) {
          if (!prev) {
            // new range
            buf_start = i;
            // and finish -1s
            if (empty_length > 1) v.push_back(INT_MIN);
          }
          else {} // continue
        }
        // false
        else {
          if (prev) { // fin range
            // true -> false
            // range [buf_start, i-1], size: i-buf_start
            int size = i - buf_start;
            v.push_back(size);
            empty_length = 0;
          }
          // () - () -...- () => -1
          else { empty_length++; } // continue
        }
        prev = list[i];
      }
      int* v_array = &v[0];

      for (int i=1; i<v.size(); i++) {
        int score = v_array[i-1] + v_array[i] + 1;
        answer = max(answer, score);
      }
      // O(n(n-k))
      // for (int i=1; i<n+1; i++) if (!list[i]) {
        //for(int j=1;j<n+1;j++) cout << " " << (i==j?"*":(list[j]? str(j) : "_"));
        //cout << "\n";
        //answer = max(answer, eval(i));
      //}
    }
    cout << answer << '\n';
  }
  return 0;
}

Measured memory_bytes: 1512
#define ll long long
#include<bits/stdc++.h>
using namespace std;
ll n,t[2000005];
vector <ll> v;
set <ll> s;
ll k;
int main()
{
	cin>>n;
	//  scanf("%lld", &k);
	cin>>k;
	for(int i=0;i<n;++i)
	{
		cin>>t[i+1];
		//  scanf("%d", &t[i+1]);
	}
	ll x=t[1],cycle=1;
	v.push_back(1);
	s.insert(1);
	while(s.find(x)==s.end())
	{
		v.push_back(x);
		s.insert(x);
		x=t[x];
		cycle++;
	}
	if(k<cycle) printf("%lld\n", v[k]);
	else
	{
		k-=cycle;
		v.clear();
		ll pp=x;
		v.push_back(x);
		x=t[x];
		cycle=1;
		while(x!=pp)
		{
			v.push_back(x);
			x=t[x];
			cycle++;
		}
		printf("%lld\n", v[k%cycle]);
	}
	return 0;
}


Measured memory_bytes: 15448
import sys
from collections import defaultdict

def main():
    line = sys.stdin.readline()
    lst = line.split()
    n = int(lst[0])
    k = int(lst[1])

    cnt_dic = defaultdict(int)
    for line in sys.stdin:
        lst = line.split()
        a = int(lst[0])
        b = int(lst[1])

        cnt_dic[a] += b

    cnt = 0
    for key in sorted(cnt_dic.keys()):
        val = cnt_dic[key]
        cnt += val

        # sys.stderr.write("%d" % cnt)
        if cnt >= k:
            print("%d" % key)
            break

    return 0

if __name__ == '__main__':
    sys.exit(main())


Measured memory_bytes: 10844
def white_cells(H: int, W: int, h: int, w: int)->int:
    return (H-h) * (W-w)


if __name__ == "__main__":
    H, W = map(int, input().split())
    h, w = map(int, input().split())
    ans = white_cells(H, W, h, w)
    print(ans)


Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    string S;
    cin >> S;

    int Q;
    cin >> Q;

    vector<char> ls;
    vector<char> rs;
    for (auto c : S) {
        rs.push_back(c);
    }

    int dir = 1;

    for (int i = 0; i < Q; i++) {
        int q;
        cin >> q;
        if (q == 1) {
            dir *= -1;
        } else {
            int f;
            char c;
            cin >> f >> c;

            if (f == 1) {
                if (dir == 1) {
                    ls.push_back(c);
                } else {
                    rs.push_back(c);
                }
            } else {
                if (dir == 1) {
                    rs.push_back(c);
                } else {
                    ls.push_back(c);
                }
            }
        }
    }

    vector<char> new_ls = (dir == 1) ? move(ls) : move(rs);
    vector<char> new_rs = (dir == 1) ? move(rs) : move(ls);

    for (int i = (int) new_ls.size() - 1; i >= 0; i--) {
        cout<< new_ls[i];
    }
    for (int i = 0; i < (int) (new_rs).size(); i++) {
        cout << new_rs[i];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 3980
#include<iostream>
#include<vector>
using namespace std;
int main(void){
	int w;
	cin>>w;
	vector<int> a(w+2),d1(w+2,-1e9),d2(w+2,-1e9);
	for(int i=1;i<w+1;i++){
		cin>>a[i];
	}
	for(int i=1;i<w+1;i++){
		if(a[i]==0)d1[i]=1e9;
		else if(a[i]>0)d1[i]=d1[i-1]-1;
		else d1[i]=min(d1[i-1]-1,-a[i]);
	}
	for(int i=w;i>0;i--){
		if(a[i]==0)d2[i]=1e9;
		else if(a[i]>0)d2[i]=d2[i+1]-1;
		else d2[i]=min(d2[i+1]-1,-a[i]);
	}
	
int ans=0;
for(int i=1;i<w+2;i++){
	ans+=max(0,min(a[i],max(d1[i],d2[i])));
}
cout<<ans<<endl;
return 0;
}

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

using namespace std;

const int maxn = 10005;

int main(){
    int n,m;
    long long mod = 1e9 + 7;
    cin >> n >> m;
    if(abs(n - m) > 1){ cout << 0 << endl; return 0;}
    long long ans = 1;
    for(int i = 1;i <= n;i++){
        ans = ans * i % mod;
    }
    for(int i = 1;i <= m;i++){
        ans = ans * i % mod;
    }
    if(n == m) ans = ans * 2 % mod;
    cout << ans << endl;
    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<string> s(n);
  rep(i,n) cin >> s[i];
  sort(s.begin(),s.end());
  int kind = 0;
  for(int i = 1; i <= n; i++){
    if(s[i] != s[i-1]) kind++;
  }
  if(kind==3) cout << "Three" << endl;
  if(kind==4) cout << "Four" << endl;
}

Measured memory_bytes: 3640
X,Y = list(map(int,input().split()))
mod = 10**9+7
fac = [1, 1]
finv = [1, 1]
inv = [0, 1]

Xd = (2*X-Y)/3
Yd = (-X+2*Y)/3

def init(n):
    for i in range(2, n + 1):
        fac.append(fac[-1] * i % mod)
        inv.append(-inv[mod % i] * (mod // i) % mod)
        finv.append(finv[-1] * inv[-1] % mod)

def com(n, k, mod):
    if n < 0 or k < 0 or n < k:
        return 0
    return fac[n] * (finv[k] * finv[n - k] % mod) % mod

if Xd % 1 == 0 and Yd % 1 == 0:
    init(int(Xd+Yd))
    print(com(int(Xd+Yd), int(Yd), mod)) # 161700
else:
    print('0')

Measured memory_bytes: 84404
#! -*- coding:utf-8 -*-
a,b,c = map(int,input().split())

count = 0
flag = 0
while True:
    at = (b+c)/2
    bt = (a+c)/2
    ct = (b+a)/2

    if flag == 0 and (a % 2 == 1 or b % 2 == 1 or c % 2 == 1):
        flag = 1
        break
    if flag == 1 and at == a and bt == b and ct == c:
        flag = 0
        break
    
    a = at
    b = bt
    c = ct
    #print(a,b,c)
    count += 1
    flag = 1
    if a % 2 == 1 or b % 2 == 1 or c % 2 == 1:
        break

if flag == 0:
    print(-1)
else:
    print(count)

Measured memory_bytes: 3064
import sys,collections as cl,bisect as bs
sys.setrecursionlimit(100000)
input = sys.stdin.readline
mod = 10**9+7
Max = sys.maxsize
def l(): #intのlist
    return list(map(int,input().split()))
def m(): #複数文字
    return map(int,input().split())
def onem(): #Nとかの取得
    return int(input())
def s(x): #圧縮
    a = []
    if len(x) == 0:
        return []
    aa = x[0]
    su = 1
    for i in range(len(x)-1):
        if aa != x[i+1]:
            a.append([aa,su])
            aa = x[i+1]
            su = 1
        else:
            su += 1
    a.append([aa,su])
    return a
def jo(x): #listをスペースごとに分ける
    return " ".join(map(str,x))
def max2(x): #他のときもどうように作成可能
    return max(map(max,x))
def In(x,a): #aがリスト(sorted)
    k = bs.bisect_left(a,x)
    if k != len(a) and a[k] ==  x:
        return True
    else:
        return False

def pow_k(x, n):
    ans = 1
    while n:
        if n % 2:
            ans *= x
        x *= x
        n >>= 1
    return ans

"""
def nibu(x,n,r):
    ll = 0
    rr = r
    while True:
        mid = (ll+rr)//2

    if rr == mid:
        return ll
    if (ここに評価入れる):
        rr = mid
    else:
        ll = mid+1
"""

O = input()[:-1]
E = input()[:-1]

data = ""

for i in range(len(O) + len(E)):
    if i % 2 == 0:
        data += O[i//2]
    else:
        data += E[i//2]
print(data)

Measured memory_bytes: 65220
# DFS(再帰関数)による全探索
# AC:  msec(Python3)
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines


def dfs(s, N):
    """
    param s:今の文字列
    param N:文字列の長さ

    """
    S = "abcdefghij"

    if len(s) == N:
        print(s)
    else:
        for c in S[:len(set(s))+1]:
            dfs(s + c, N)


def main():
    N = int(readline())

    dfs("", N)


if __name__ == "__main__":
    main()


Measured memory_bytes: 4412
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[200005];

ll labs(ll v){
	if(v<0LL)return -v;
	return v;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
		a[i]-=i+1;
	}
	sort(a,a+n);
	ll val=a[(n-1)/2];
	if(n%2==0){
		val=(a[(n-1)/2]+a[n/2])/2LL;
	}
	ll ans=0;
	for(int i=0;i<n;i++){
		ans+=labs(a[i]-val);
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>

using namespace std;

long gcd(long n, long m) {
    long tmp;
    while (n % m != 0) {
        tmp = m;
        m = n % m;
        n = tmp;
    }
    return m;
}

int main() {
    long a, b;
    cin >> a >> b;

    cout << a * b / gcd(a, b);

    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main() {
	int a, b, n, sum, mod, div;

	while (scanf(" %d %d %d ", &a, &b, &n) != EOF) {
		sum = 0;
		mod = a % b;
		div = a / b;
		while (n--) {
			a = mod * 10;
			mod = a % b;
			div = a / b;
			sum += div;
		}
		printf("%d\n", sum);
	}
	return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, srt, end) for (long long i = (srt); i < (long long)(end); i++)
#define VL vector<ll>
#define VS vector<string>
#define VB vector<bool>
#define VP vector<pair<ll,ll>>
#define VVL vector<vector<ll>>
#define VVP vector<vector<pair<ll,ll>>>
#define PL pair<ll,ll>
#define ALL(v) (v).begin(), (v).end()
ll d1[4] = {1, -1, 0, 0};
ll d2[4] = {0, 0, 1, -1};


ll dp1[5000][5000];
ll dp2[5000][5000];

int main(){

    // read input
    ll N, T;
    cin >> N >> T;
    VL A(N+1), B(N+1);
    rep(i, 1, N+1) cin >> A[i] >> B[i];

    // initialize
    rep(i, 0, 5000){
        rep(j, 0, 5000){
            dp1[i][j] = 0;
            dp2[i][j] = 0;
        }
    }

    // knapsack 1 to i
    rep(i, 1, N+1){
        rep(t, 0, T){
            if(t >= A[i]){
                dp1[i][t] = max(dp1[i-1][t], dp1[i-1][t-A[i]] + B[i]);
            }else{
                dp1[i][t] = dp1[i-1][t];
            }
        }
    }

    // knapsack N to i
    for(ll i = N; i > 0; i--){
        rep(t, 0, T){
            if(t >= A[i]){
                dp2[i][t] = max(dp2[i+1][t], dp2[i+1][t-A[i]] + B[i]);
            }else{
                dp2[i][t] = dp2[i+1][t];
            }
        }
    }

    ll ans = 0;
    rep(i, 1, N+1){
        ll mx = 0;
        rep(t, 0, T){
            mx = max(mx, dp1[i-1][t] + dp2[i+1][T-1-t]);
        }
        ans = max(ans, mx + B[i]);
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 390912
from bisect import bisect_left
N = int(input())
A = sorted(int(x) for x in input().split())
B = sorted(int(x) for x in input().split())
C = sorted(int(x) for x in input().split())
cnt = [0] * (N + 1)
for i, b in enumerate(B):
    cnt[i + 1] = bisect_left(A, b)
    cnt[i + 1] += cnt[i]
print(sum(cnt[bisect_left(B, c)] for c in C))


Measured memory_bytes: 23360
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
const ll INF = 1000LL * 1000 * 1000 * 1000 * 1000 * 10;
const double EPS = 1e-9;
int field1[4000][4000];
int field2[4000][4000];
int n , K , x[100000] , y[100000];
char c[100000];
int addX[4] , addY[4];
int sum1(int l1 , int r1 , int l2 , int r2)
{
	int ans = field1[r1][r2];
	if(l2 > 0)
		ans -= field1[r1][l2 - 1];
	if(l1 > 0)
		ans -= field1[l1 - 1][r2];
	if(l1 > 0 && l2 > 0)
		ans += field1[l1 - 1][l2 - 1];
	return ans;
}
int sum2(int l1 , int r1 , int l2 , int r2)
{
	int ans = field2[r1][r2];
	if(l2 > 0)
		ans -= field2[r1][l2 - 1];
	if(l1 > 0)
		ans -= field2[l1 - 1][r2];
	if(l1 > 0 && l2 > 0)
		ans += field2[l1 - 1][l2 - 1];
	return ans;
}
int main()
{
	//freopen("input.txt" , "r" , stdin);
	scanf("%d %d\n" , &n , &K);
	addX[1] = addX[3] = 2 * K;
	addY[2] = addY[3] = 2 * K;
	for(int i = 0; i < n; i++)
	{
		scanf("%d %d %c\n" , &x[i] , &y[i] , &c[i]);
		x[i] %= 2 * K;
		y[i] %= 2 * K;
		if(c[i] == 'W')
		{
			for(int j = 0; j < 4; j++)
			{
				field1[x[i] + addX[j]][y[i] + addY[j]]++;
			}
		}
		else
		{
			for(int j = 0; j < 4; j++)
			{
				field2[x[i] + addX[j]][y[i] + addY[j]]++;
			}
		}
	}
	/*for(int i = 0; i < 2 * K; i++)
	{
		for(int j = 0; j < 2 * K; j++)
		{
			printf("%d " , field1[i][j]);
		}
		printf("\n");
	}
	printf("\n\n");
	for(int i = 0; i < 2 * K; i++)
	{
		for(int j = 0; j < 2 * K; j++)
		{
			printf("%d " , field2[i][j]);
		}
		printf("\n");
	}
	printf("\n\n");*/
	for(int i = 0; i < 4000; i++)
		for(int j = 0; j < 4000; j++)
		{
			if(i)
				field1[i][j] += field1[i - 1][j];
			if(j)
				field1[i][j] += field1[i][j - 1];
			if(i && j)
				field1[i][j] -= field1[i - 1][j - 1];
		}
	for(int i = 0; i < 4000; i++)
		for(int j = 0; j < 4000; j++)
		{
			if(i)
				field2[i][j] += field2[i - 1][j];
			if(j)
				field2[i][j] += field2[i][j - 1];
			if(i && j)
				field2[i][j] -= field2[i - 1][j - 1];
		}
	/*for(int i = 0; i < 2 * K; i++)
	{
		for(int j = 0; j < 2 * K; j++)
		{
			printf("%d " , field1[i][j]);
		}
		printf("\n");
	}
	printf("\n\n");
	for(int i = 0; i < 2 * K; i++)
	{
		for(int j = 0; j < 2 * K; j++)
		{
			printf("%d " , field2[i][j]);
		}
		printf("\n");
	}*/
	int ans = 0;
	for(int i = 0; i < 2 * K; i++)
	{
		for(int j = 0; j < 2 * K; j++)
		{
			ans = max(ans , sum1(i , i + K - 1 , j , j + K - 1) +
					sum2(i + K , i + 2 * K - 1 , j , j + K - 1)
					+ sum2(i , i + K - 1 , j + K , j + K * 2 - 1)
					+ sum1(i + K , i + K * 2 - 1 , j + K , j + K * 2 - 1)
			);
			ans = max(ans , sum2(i , i + K - 1 , j , j + K - 1) +
					sum1(i + K , i + 2 * K - 1 , j , j + K - 1)
					+ sum1(i , i + K - 1 , j + K , j + K * 2 - 1)
					+ sum2(i + K , i + K * 2 - 1 , j + K , j + K * 2 - 1)
			);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 126208
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long int n, k;
	cin >>k >> n;
	long long int a[n];
	for(int i = 0 ; i < n ; i++)
		cin >> a[i];
	long long int ans = k-abs(k-abs(a[0]-a[n-1]));
	for(int i =0  ; i < n-1; i++){
		ans = min(ans, k-abs(a[i+1]-a[i]));
	}
	cout<<ans<<"\n";
	return 0;
}


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

using namespace std;

long long MOD = 1000000007;
long long numseq[100005];

long long n, k;

long long modpow(long long x, long long e) {
    if (e == 0) return 1;
    if (e == 1) return x;
    if (e % 2 == 0) {
        long long half = modpow(x, e / 2);
        return (half * half) % MOD;
    } else {
        return (modpow(x, e - 1) * x) % MOD;
    }
}

long long calc(int x) {
    if (numseq[x] > 0) return numseq[x];
    long long ans = 0;
    long long num_div = k / x;
    ans = modpow(num_div, n);
    for (int i = x * 2; i <= k; i += x) {
        ans -= calc(i);
    }
    return numseq[x] = ans;
}

int main() {
    cin >> n >> k;

    long long ans = 0;
    for (int i = 1; i <= k; i++) {
        ans = (ans + calc(i) * i) % MOD;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4412
/* بِسْمِ اللَّهِ الرَّحْمَٰنِ الرَّحِيمِ */
//codeforces
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
#define FASTIO ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define mp make_pair
#define pb push_back
#define sz(v) ((int)v.size())
#define all(v) v.begin(), v.end()
void parseArray(ll* A,ll n){ for ( ll K = 0; K < n; K++){ cin >> A[K]; } }
ll modInverse(ll a, ll b){ return 1<a ? b - modInverse(b%a,a)*b/a : 1; }
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); }
ld dist(ll x, ll y, ll a, ll b){ return sqrt((x - a)*(x - a) + (y - b)*(y - b)); }
void debug(ll* a, ll n) { for ( int k = 0; k < n; k++ ){ cout << a[k] << " ";} cerr << "\n"; }

ll n, m;
ll cost[1111];
ll opens[1111];
ll memo[1111][(1 << 12)];
ll full;
ll dp(ll idx, ll comb) {
	if (comb >= (full)) return 0;
	if (idx >= m)
		return 1111111111111;
	if (memo[idx][comb] != -1)
		return memo[idx][comb];
	ll ans = min(dp(idx + 1, comb), cost[idx] + dp(idx + 1, comb | opens[idx]));
	return memo[idx][comb] = ans;
}

int main() {
	cin >> n >> m;
	ll a, b;
	full = (1 << n) - 1;
	for ( int k = 0; k < m; k++ ){
		cin >> cost[k] >> b;
		ll temp = 0;
		for ( int j = 0; j < b; j++ ){
			cin >> a;
			temp |= (1 << (a - 1));
		}
		opens[k] = temp;
	}
	memset(memo, -1, sizeof memo);
	cout << (dp(0, 0) >= 1111111111111? -1 : dp(0, 0)) << endl;
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    string s; cin >> s;
    int n = (int)s.size();
    ll K; cin >> K;
    REP(i, s.size()) {
        int x = s[i]-'a';
        if (x > 0 && K >= 26-x) {
            K -= 26-x;
            s[i] = 'a';
        }
    }
    s[n-1] = (s[n-1]-'a'+K)%26 + 'a';
    cout << s << endl;
}


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

using namespace std;

#pragma GCC optimize ("-O3", "unroll-loops")

// @LayCurse : https://yukicoder.me/submissions/87387
// #define mygc(c) (c)=getchar_unlocked()
// #define mypc(c) putchar_unlocked(c)
// void reader(int *x) { int k, m = 0; *x = 0; for (;;) { mygc(k); if (k == '-') { m = 1; break; }if ('0' <= k&&k <= '9') { *x = k - '0'; break; } }for (;;) { mygc(k); if (k<'0' || k>'9')break; *x = (*x) * 10 + k - '0'; }if (m)(*x) = -(*x); }
// void writer(int x, char c) { int s = 0, m = 0; char f[10]; if (x<0)m = 1, x = -x; while (x)f[s++] = x % 10, x /= 10; if (!s)f[s++] = 0; if (m)mypc('-'); while (s--)mypc(f[s] + '0'); mypc(c); }


constexpr int MAX_N = 200000;
size_t n;
unsigned a[MAX_N], b[MAX_N];

int main() {
    // Input
    // reader(&n);
    scanf("%lu", &n);
    // for (size_t i = 0; i < n; ++i) reader(&a[i]);
    // for (size_t i = 0; i < n; ++i) reader(&b[i]);
    for (size_t i = 0; i < n; ++i) scanf("%u", &a[i]);
    for (size_t i = 0; i < n; ++i) scanf("%u", &b[i]);


    // Solve
    constexpr size_t block_a = 4, block_b = 8192;
    unsigned ans = 0;
    for (size_t i = 0; i + (block_a - 1) < n; i += block_a) {
        for (size_t j = 0; j + (block_b - 1) < n; j += block_b)
            for (size_t k = j; k < j + block_b; ++k) {
                ans ^= (a[i] + b[k]) ^ (a[i + 1] + b[k]);
                ans ^= (a[i + 2] + b[k]) ^ (a[i + 3] + b[k]);
            }

        for (size_t j = n & ~(block_b - 1); j < n; ++j) {
            ans ^= (a[i] + b[j]) ^ (a[i + 1] + b[j]);
            ans ^= (a[i + 2] + b[j]) ^ (a[i + 3] + b[j]);
        }
    }

    // rest of iterations
    for (size_t i = n & ~(block_a - 1); i < n; ++i) {
        for (size_t j = 0; j + (block_b - 1) < n; j += block_b)
            for (size_t k = j; k < j + block_b; ++k)
                ans ^= a[i] + b[k];

        for (size_t j = n & ~(block_b - 1); j < n; ++j)
            ans ^= a[i] + b[j];
    }

    // Output
    printf("%u\n", ans);
    // writer(ans, '\n');

    return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>
 
int main(void) {
	int i,j;
    char str[100];
    while(scanf("%s",str) != EOF){
        for(i = 0;str[i] != 0;i++){
            if(str[i] == '@'){
                for(j = 0;j < str[i + 1] - '0';j++) printf("%c",str[i + 2]);
                i += 2;
            }
            else printf("%c",str[i]);
        }
        printf("\n");
    }
 
	return 0;
}
 

Measured memory_bytes: 524
import java.util.Scanner;

/**
 * AOJ id=1130
 * Red and Black
 * @author scache
 *
 */
public class Main {
	public static void main(String[] args) {
		Main p = new Main();
	}

	public Main() {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			w = sc.nextInt();
			h = sc.nextInt();
			if(w==0) break;
			map = new char[h][w];
			for(int i=0;i<h;i++)
				map[i] = sc.next().toCharArray();
			solve(map);
		}
	}

	int w;
	int h;
	char[][] map;
	public void solve(char[][] map) {
		int sx = -1;
		int sy = -1;
		for(int i=0;i<map.length;i++){
			for(int j=0;j<map[i].length;j++){
				if(map[i][j]=='@'){
					sx = j;
					sy = i;
					break;
				}
			}
			if(sx>=0)
				break;
		}
		System.out.println(rec(sx, sy));
		
	}

	int[] dx = { -1, 0, 1, 0 };
	int[] dy = { 0, -1, 0, 1 };
	private int rec(int curx, int cury) {
		if(map[cury][curx]=='#')
			return 0;	
		
		map[cury][curx] = '#';
		int res = 1;
		for(int i=0;i<4;i++){
			int nx = curx + dx[i];
			int ny = cury + dy[i];
			
			if(nx<0 || w<=nx || ny<0 || h<=ny)
				continue;
			res += rec(nx, ny);
		}
		
		
		return res;
	}

}

Measured memory_bytes: 26688
#include <iostream>
#include <vector>
#include <queue>
#include <string.h>
using namespace std;

class State{
public:
  int x,y,cost;

  State(){}
  State(int _x,int _y,int _cost){
    x = _x;
    y = _y;
    cost = _cost;
  }
};

int n,m;
int sx,sy;
bool t[1000][1000];
bool closed[1000][1000];
int dx[] = {0,1,1,0,-1,-1};
int dy[] = {1,1,0,-1,-1,0};

void solve(){
  queue<State> open;
  memset(closed,0,sizeof(closed));
  open.push(State(sx,sy,0));

  int ans = 0;

  while(!open.empty()){
    State st = open.front(); open.pop();
    if(closed[st.x][st.y] || st.cost>n || t[st.y][st.x]) continue;
    closed[st.x][st.y] = true;

    ans++;

    for(int i = 0; i < 6; i++){
      int nx = st.x + dx[i];
      int ny = st.y + dy[i];
      open.push(State(nx,ny,st.cost+1));
    }
  }

  cout<<ans<<endl;
}

int main(){
  while(cin>>n>>m,n||m){
    memset(t,0,sizeof(t));
    for(int i = 0; i < m; i++){
      int x,y;
      cin>>x>>y;
      x += 300;
      y += 300;
      t[y][x] = true;
    }

    cin>>sx>>sy;
    sx += 300;
    sy += 300;

    solve();
  }
}


Measured memory_bytes: 5060
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cassert>
#include <complex>
#include <stdio.h>
#include <time.h>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
# define ll int64_t
# define str string
# define rep(i,n) for(ll i=0;i<n;i++)
# define rrep(i,n) for(ll i=1;i<=n;i++)
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define mod 1000000007
# define PI 3.141592653589793
# define vec vector
#define dump(x) cerr<<#x<<"="<<x<<endl
using namespace std;



#define INF 2000000000
#define MAX_V 10



bool compare_by_b(pair<string,ll> a,pair<string,ll> b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}

bool my_compare(pair<ll,ll> a,pair<ll,ll> b){
    if(a.first != b.first) return a.first<b.first;
    if(a.second != b.second) return a.second>b.second;
    else return true;
}

ll modpow(ll a,ll n,ll mod1) {
    ll res=1;
    while(n>0){
        if(n&1) res=res*a%mod1;
        a = a*a%mod1;
        n >>= 1;
    }
    return res;
}

ll factorial(ll n){
    ll x=1;
    rrep(i,n) (x*=i)%=mod;
    return x;
}

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

ll lcm(ll a,ll b){
   return a/gcd(a,b)*b;
}
const ll MAX = 5100000;
const ll MOD = 1000000007;
 
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

using graph = vector<vector<ll>>;
pair<pair<ll,ll>,ll> p[100010];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    long double a,v,b,w,t;
    cin>>a>>v>>b>>w>>t;
    if(v>w){
        if(abs(a-b)<=(v-w)*t){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
    return 0;
}


Measured memory_bytes: 3740