akhauriyash/Code-Regression huggingface dataset:
import java.io.{BufferedReader, IOException, InputStream, InputStreamReader}
import java.util.{Scanner, StringTokenizer}

import scala.util.Sorting

object Main {
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val H = sc.nextInt()
    val W = sc.nextInt()
    val D = sc.nextInt()
    val N = H * W
    val A = Array.ofDim[(Int, Int)](N + 1)
    
    for {
      h <- 1 to H
      w <- 1 to W
    } {
      val x = sc.nextInt()
      A(x) = (h, w)
    }

//    def move(s: (Int, Int), t: (Int, Int)) = math.abs(s._1 - t._1) + math.abs(s._2 - t._2)

    // (1 to D-1) から xまでのコスト
    val cost = Array.ofDim[Int](N + 1)
    (1 to D) foreach { d =>  // 最初の地点dから
      (0 until (N / D) + (if(d <= N % D) 1 else 0)) foreach { j =>  // j回移動する
        if (j == 0) cost(d) = 0
        else {
          val next = d + D * j
          val prev = d + D * (j - 1)
          val s = A(prev)
          val t = A(next)
          val move = math.abs(s._1 - t._1) + math.abs(s._2 - t._2)
          cost(next) = cost(prev) + move
        }
      }
    }

    val Q = sc.nextInt()
    (0 until Q) foreach { _ =>
      val L = sc.nextInt()
      val R = sc.nextInt()
      println(cost(R) - cost(L))
    }
  }

  def main(args: Array[String]): Unit = {
    solve()
  }

  class InputReader(val stream: InputStream) {
    val reader = new BufferedReader(new InputStreamReader(stream), 32768)
    var tokenizer: StringTokenizer = null

    def next: String = {
      while (tokenizer == null || !tokenizer.hasMoreTokens)
        tokenizer = new StringTokenizer(reader.readLine)
      tokenizer.nextToken
    }

    def nextInt(): Int = next.toInt
  }
}


Measured memory_bytes: 53088
#include <iostream>


int main()
{
	int a, b, c;
	int ans[301];
	while(1){
		for(int l=1; l<301; l++){
			ans[l] = 2;
		}
		std::cin >> a;
		std::cin >> b;
		std::cin >> c;
		if(!a && !b && !c)
			break;

		int N;
		std::cin >> N;

		int i[1000]={0}, j[1000]={0}, k[1000]={0}, r[1000]={0};
		for(int l=0;l<N;l++){
			std::cin >> i[l];
			std::cin >> j[l];
			std::cin >> k[l];
			std::cin >> r[l];

			if(r[l]){
				ans[i[l]] = 1;
				ans[j[l]] = 1;
				ans[k[l]] = 1;
			}
		}

		for(int l=0;l<N;l++){
			if(r[l])
				continue;
			if(ans[i[l]]==1 && ans[j[l]]==1)
				ans[k[l]] = 0;
			else if(ans[i[l]]==1 && ans[k[l]]==1)
				ans[j[l]] = 0;
			else if(ans[k[l]]==1 && ans[j[l]]==1)
				ans[i[l]] = 0;
		}

		for(int l=1; l<=a+b+c; l++)
			std::cout << ans[l] << std::endl;
	}
}

Measured memory_bytes: 1176
// 参考：https://beta.atcoder.jp/contests/abc097/submissions/2511354

#include <iostream>
#include <algorithm>
#include <set>
using namespace std;

int main() {
  string s;
  getline(cin, s);
  int K;
  cin >> K;

  set<string> S;
  int l = s.size();

  for (int i = 0; i <= l-1; i++) {
    for(int j = 1; j <= K; j++) {
      S.insert(s.substr(i, j));
    }
  }

  for (int i = 0; i < K-1; i++) {
    S.erase(S.begin());
  }

  cout << *S.begin() << endl;

  return 0;
}

Measured memory_bytes: 1664
from sys import stdin
import sys
##  input functions for me
def ria(sep = ''):
    if sep == '' :
        return list(map(int, input().split())) 
    else: return list(map(int, input().split(sep)))
def rsa(sep = ''):
    if sep == '' :
        return input().split() 
    else: return input().split(sep)
def ri(): return int(input())
def rd(): return float(input())
def rs(): return input()
##
def main():
    A, B = map(int, input().split())
    print (max(0, A - 2 * B))


if __name__ == "__main__":
    main()


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

using namespace std;

#define ll long long
#define ull unsigned long long
#define PI acos(-1.0)
#define eps 1e-12
#define fi first
#define se second
#define MEM(a,b) memset((a),(b),sizeof(a))
#define mod(x) ((x)%MOD)
#define pii pair<int,int>
#define wz cout<<"-----"<<endl;
const int INF_INT = 2147483647;
const ll INF_LL = 9223372036854775807LL;
const ull INF_ULL = 18446744073709551615Ull;
const ll P = 92540646808111039LL;

const ll maxn = 1e5 + 10, MOD = 1e9 + 7;
const int Move[4][2] = {-1,0,1,0,0,1,0,-1};
const int Move_[8][2] = {-1,-1,-1,0,-1,1,0,-1,0,1,1,-1,1,0,1,1};

inline int read(){
    int x=0,f=1;char ch=getchar();
    while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
    while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}


void init() {

}

int a[10];

int main(){
//    freopen("C:\\Users\\Administrator\\Desktop\\in.txt","r",stdin);
//    freopen("C:\\Users\\Administrator\\Desktop\\out.txt","w",stdout);
//    ios_base::sync_with_stdio(0);
    init();
    for (int i = 0; i < 4; i++){
        int x; cin >>x;
        a[x]++;
    }
    if (a[1] == 1 && a[7] == 1 &&  a[9] == 1 && a[4] == 1) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = (1LL << 31) - 1;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1
#define MAX_N 100100 * 3

int n, m;

ll dp[1000010];

int main() {
	cin >> n >> m;
	dp[0] = 1;
	FOR(i, 1, max(n, m) + 1) {
		dp[i] = dp[i - 1] * i%MOD;
	}
	ll MAX = max(n, m);
	ll MIN = min(n, m);
	if (MAX - MIN > 1) {
		cout << 0 << endl;
	}
	else if (MAX - MIN == 1) {
		cout << dp[MIN] * dp[MAX] % MOD << endl;
	}
	else {
		cout << 2 * dp[MIN] % MOD * dp[MAX] % MOD << endl;
	}
}

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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	char a, b;
	cin >> a >> b;
	if (a == b)cout << '=' << endl;
	else if (a < b)cout << '<' << endl;
	else cout << '>' << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <stdio.h>
#include <queue>
#include <stack>
#include <climits>
#include <map>
#include <set>

const int mod = 1e9 + 7;
const int inf = 1e9;
const long long INF = 1LL << 60;
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
using namespace std;

struct edge {ll from,to,cost;};

int main()
{
    string s;
    cin >> s;
    for(int i = 0; i < s.size(); i++){
        cout << 'x';
    }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
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; }
const ll INF = 1LL << 60;
vector<int> to[605];
double dp[605][605];
int main(){
    int n, m;
    cin >> n >> m;
    rep(i,m){
        int s,t;
        cin >> s >> t;
        s--; t--;
        to[s].push_back(t);
    }
    vector<int> split(n-1);
    rep(i,n-1) split[i] = to[i].size();
    vector<double> ex(n);
    
    double ans = 1e12 + 1.0;
    for(int i=0; i<=n-2; i++){
        int midx = -1;
        for(int j=n-2; j>=0; j--){
            if(i==j && split[i]>1){
                double mex = -1.0;
                for(auto p :to[j]){
                    if(dp[i][p]>mex){
                        mex = dp[i][p];
                        midx = p;
                    }
                }
            }
            for(auto p :to[j]){
                if(i==j && p==midx) continue;
                if(i!=j || split[j]==1) dp[i][j] += dp[i][p] * (1.0/split[j]);
                else dp[i][j] += dp[i][p] * (1.0 / (split[j]-1));
            }
            dp[i][j] += 1.0;
            //cout << i << " " << j << " " << dp[i][j] << endl;
        }
        chmin(ans,dp[i][0]);
    }
    printf("%.10f\n",ans);
    return 0;
}

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

//qsort
int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

//比較
int max(int a, int b){
	if (a>b) return a;
	else return b;
}

int min(int a,int b) {
	if(a>b) return b;
	else return a;
}


//main関数
int main() {
	int N,M;
	scanf("%d %d",&N,&M);
    char oppai;
    scanf("%c",&oppai);
	
	char A[70][70];
	char B[70][70];
	
	for(int i=0; i<N; i++) {
		for(int j=0; j<N; j++) {
			scanf("%c",&A[i][j]);
		}
      	scanf("%c",&oppai);
	}
	
	for(int i=0; i<M; i++) {
		for(int j=0; j<M; j++) {
			scanf("%c",&B[i][j]);
		}
        scanf("%c",&oppai);
	}
	
	int sakoda=0;
	for(int i=0; i<=N-M; i++ ) {
		for(int j=0; j<=N-M; j++ ) {
			sakoda=0;
			for(int k=0; k<M; k++ ) {
				for(int m=0; m<M; m++ ) {
					if( A[i+k][j+m] != B[k][m] ){
						sakoda = 1;
					}
				}
			}
			if ( sakoda == 0 ) {
				printf("Yes");
				return 0;
			}
		}
	}
	printf("No");
	return 0;
}



Measured memory_bytes: 1712
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tiii;
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;

int main() {
    int H, W;
    cin >> H >> W;
    string A;
    int sum = 0;
    for (int i = 0; i < H; i++) {
        cin >> A;
        for (int j = 0; j < W; j++) {
            if (A[j] == '#') {
                sum++;
            }
        }   
    }
    if (sum == H + W - 1) {
        cout << "Possible" << endl;
    } else {
        cout << "Impossible" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
signed main()
{
  int a,b;
  for(int i=0;i<4;i++){
    cin>>a>>b;
    if(a==1){
      cout<<b*6000<<"\n";
    }
    if(a==2){
      cout<<b*4000<<"\n";
    }
    if(a==3){
      cout<<b*3000<<"\n";
    }
    if(a==4){
      cout<<b*2000<<"\n";
    }
  }
    return(0);
  }



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

using namespace std;

using ll = long long;

const ll MOD = 1000000007;

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

ll n, k;
vector<ll> tree[100001];

// given, x and par, k-2_P_c
ll dfs(ll x, ll par){
    ll color = k - 2;
    if(par == -1){
        color = k - 1;
    }
    /*
    if(tree[x].size() <= 0){
        return 0;
    }
    */ 

    ll res = 1;
    for(ll t: tree[x]){
        // cout << t << endl;
        if(t == x || t == par) continue;
        // color of x
        res *= color;
        res %= MOD;
        color--;
        // color of t
        res *= dfs(t, x);
        res %= MOD;
    }
    return res;
}

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cin >> n >> k;
    for(ll i=0;i<n-1;i++){
        ll a, b; cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }
    cout << (k * dfs(0, -1)) % MOD << endl;
}

Measured memory_bytes: 10368
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>

using namespace std;

#define FOR(i,n) for(int i = 0; i < n; i++)
#define FORa(i,a,b) for(int i = a; i < b; i++)
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a, b)
#define F first
#define S second
#define SORT(a,n) sort(begin(a), begin(a) + n)
#define VSORT(v) sort(v.begin(), v.end())
#define MAX 1000000
#define ll long long
#define LOW(s) transform(s.begin(),s.end(),s.begin(),::tolower)
#define UP(s) transform(s.begin(),s.end(),s.begin(),::toupper)

//-------------------------------------------------------//

int main() {
	int n, m, ans = 0;
	cin >> n >> m;
	
	vector<int> elevation(n);
	FOR(i, n) cin >> elevation[i];
	
	unordered_map<int, unordered_set<int>> map;
	FOR(i,m) {
		int a, b;
		cin >> a >> b;
		map[a].insert(b);
		map[b].insert(a);
	}
	
	for(int i = 1; i <= n; i++) {
		unordered_set<int>::iterator it;
		bool good = true;
		
		for(it = map[i].begin(); it != map[i].end(); it++) {
			good &= elevation[i-1] > elevation[*it-1];
		}
		
		if(good) ans++;
	}
	
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 22020
import numpy as np
import itertools

N, M, X = map(int, input().split())
CA = np.zeros((N, M + 1))

for i in range(N):
    CA[i, :] = [int(x) for x in input().split()]

min_price = float('inf')
All = [i for i in range(N)]

for x in range(1, N + 1):
    for comb in list(itertools.combinations(All, x)):
        if min(CA[comb, 1:].sum(axis=0)) >= X and CA[comb, 0].sum() < min_price:
            min_price = CA[comb, 0].sum()
        else:
            pass

if min_price == float('inf'):
    print(-1)
else:
    print(int(min_price))

Measured memory_bytes: 27448
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=300010;
int n,x,y;
string s;
int main()
{
	cin>>n;
	ll ans=0;
	ans+=n/500*1000;
	n%=500;
	ans+=n/5*5;
	cout<<ans;
	return 0; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define For(i,n,k) for(ll i=(n);i<(k);i++)
int n,ans=0;
string s;
int kasanari(string x,string y){
    int t=0;
    For(i,0,26){
        bool flag1=false,flag2=false;
        char c='a'+i;
        For(j,0,x.size()){
            if(c==x.at(j)){
                flag1=true;
                break;
            }
        }
        For(j,0,y.size()){
            if(c==y.at(j)){
                flag2=true;
                break;
            }
        }
        if(flag1&&flag2) t++;
    }
    return t;
}
bool Main(){
    cin>>n>>s;
    For(i,1,n-1){
        string left="",right="";
        For(j,0,i){
            left+=s.at(j);
        }
        For(j,i,n){
            right+=s.at(j);
        }
        ans=max(ans,kasanari(left,right));
    }
    cout<<ans<<endl;
}
int main(){
    Main();
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string s;
  cin>>s;
  string nen="";
  string tuki="";
  string hi="";
  char iranai;
  int hantei=0;
  for(int i=0;i<s.size();i++){
    char a;
    a=s[i];
    if(a=='/'){
      hantei++;
    }else if(hantei==0){
      nen.push_back(a);
    }else if(hantei==1){
      tuki.push_back(a);
    }else if(hantei==2){
      hi.push_back(a);
    }
  }
  int nen1,tuki1,hi1;
  nen1=stoi(nen);
  tuki1=stoi(tuki);
  hi1=stoi(hi);
  if(nen1<=2019){
    if(tuki1==4){
      if(hi1<=30){
        cout<<"Heisei"<<endl;
        return 0;
      }
    }else if(tuki1<4){
      cout<<"Heisei"<<endl;
      return 0;
    }
  }
  cout<<"TBD"<<endl;
  return 0;
}

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

def fb(num):
    fblist = []
    x, y = 1, 0
    for _ in range(num):
        fblist.append(x)
        x, y = x + y, x
    return fblist

n, m = map(int, input().split())

l = fb(n + 1)

now = 0
p_cnt = []
for i in range(m):
    a = int(input())
    if now == a:
        print(0)
        exit()
    p_cnt.append(l[a - 1 - now])
    now = a + 1

# print(n)
# print(now)
# print(l)
p_cnt.append(l[n - now])

# print(p_cnt);
ans = 1
for j in range(len(p_cnt)):
    # print(ans)
    ans *= p_cnt[j]
    # print(ans)
    
print(ans %  1000000007)    


Measured memory_bytes: 460628
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

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

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

    int n;
    cin >> n;
    vector<int> a(n);
    ll S = 0;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        S += a[i];
    }
    vector<ll> ans(n);
    ans[0] = S;
    for(int i = 1; i < n; i += 2)   ans[0] -= 2LL * a[i];
    for(int i = 0; i + 1 < n; ++i){
        ans[i + 1] = (a[i] - (ans[i] >> 1)) << 1;
    }
    for(int i = 0; i < n; ++i){
        cout << ans[i];
        cout << ((i == n - 1) ? '\n' : ' ');
    }
}

Measured memory_bytes: 2560
import sys
lines = sys.stdin.readlines()
x = []

for i,line in enumerate(lines):
    line = line.strip("\n")
    x.append(line)
newx = str.lower("".join(x))
num = ord("a")

for i in range(26):
    countn = newx.count(chr(num))
    print(chr(num) + " : " + str(countn))
    num += 1


Measured memory_bytes: 5572
n,m = map(int,input().split())
a = [i for i in map(int,input().split())]
bc = [[i for i in map(int,input().split())] for j in range(m)]

a.sort()
bc.sort(key=lambda x: x[1], reverse=True)
j = 0
for i in range(n):
  if a[i] < bc[j][1]:
    a[i]=bc[j][1]
    bc[j][0]-=1
    if bc[j][0]==0:
      j += 1
    if j >= m:
      break
print(sum(a))

Measured memory_bytes: 26948
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <math.h>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>

using namespace std;
typedef long long ll;
typedef unsigned long long ull;


// 68 11 55 - rank 3
// 69 12 19 - rank 3
// 70 12 34

int gcd(int a, int b) {
    while (b != 0) {
        auto na = a % b;
        a = b;
        b = na;
    }
    return a;
}


void oneCase() {
    int n;
    cin >> n;
    if (n < 10) {
        cout << "Yes" << "\n";
    }
    auto l  =to_string(n);
    for (int i = 0; i < l.size(); ++i) {
        if (l[i] != l[l.size() - 1 - i]) {
            cout << "No" << "\n";
            return;
        }
    }
    cout << "Yes" << "\n";
}


int main() {
    int t = 1;
//    cin >> t;
    while (t--) {
       oneCase();
    }

    return 0;
}

ll fact(ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        res = (res * n) % mod;
        --n;
    }
    return res;
}


Measured memory_bytes: 256
#include <map>
#include <vector>
#include <cstdio>
#include <algorithm>

using namespace std;
const int Max_N(100050);
const int Max_Q(100050);

int X, Q, N, A[Max_N], Ans[Max_Q];
map< int, vector<pair<int, int>> > S;

void init()
{
	scanf("%d", &X);
	int K;
	scanf("%d", &K);
	for (int r;K--;)
		scanf("%d", &r), S[r].push_back(make_pair(0, 0));
	scanf("%d", &Q);
	for(int i = 1, t, a;i <= Q;++i)
		scanf("%d%d", &t, &a), S[t].push_back(make_pair(i, a)), A[++N] = a;
	sort(A + 1, A + 1 + N), N = unique(A + 1, A + 1 + N) - (A + 1);
}

#define LEFT  (segt[cur].l)
#define RIGHT (segt[cur].r)
#define MID   (segt[cur].mid)
#define COV   (segt[cur].Cov)
#define MUL   (segt[cur].Mul)
#define PLS   (segt[cur].Pls)
#define MIN   (segt[cur].Min)
#define MAX   (segt[cur].Max)
#define LCH   (cur << 1)
#define RCH   ((cur << 1) | 1)

struct node
{
	int l, r, mid, Cov, Mul, Pls, Min, Max;
};
node segt[Max_N << 2];

inline void pushup(int cur)
{
	MIN = min(segt[LCH].Min, segt[RCH].Min), MAX = max(segt[LCH].Max, segt[RCH].Max);
}

inline void Cover(int cur, int v)
{
	COV = v, MUL = 1, PLS = 0, MIN = MAX = v;
}

inline void Mult(int cur, int v)
{
	MUL *= v, PLS *= v, MIN *= v, MAX *= v;
	if (MIN > MAX)
		swap(MIN, MAX);
}

inline void Plus(int cur, int v)
{
	PLS += v, MIN += v, MAX += v;
}

inline void pushdown(int cur)
{
	if (COV != -1)
		Cover(LCH, COV), Cover(RCH, COV), COV = -1;
	if (MUL != +1)
		Mult(LCH, MUL), Mult(RCH, MUL), MUL = +1;
	if (PLS != 0)
		Plus(LCH, PLS), Plus(RCH, PLS), PLS = 0;
}

void build_tree(int cur, int l, int r)
{
	LEFT = l, RIGHT = r, MID = l + ((r - l) >> 1), COV = -1, MUL = +1, PLS = 0, MIN = A[l], MAX = A[r];
	if (LEFT == RIGHT)
		return;
	build_tree(LCH, l, MID), build_tree(RCH, MID + 1, r);
}

void Minus(int cur, int v)
{
	if (MIN - v >= 0)
	{
		Plus(cur, -v);
		return;
	}
	if (MAX - v <= 0)
	{
		Cover(cur, 0);
		return;
	}
	pushdown(cur), Minus(LCH, v), Minus(RCH, v), pushup(cur);
}

int query(int cur, int p)
{
	if (LEFT == RIGHT)
		return MIN;
	return pushdown(cur), (p <= A[MID] ? query(LCH, p) : query(RCH, p));
}

void work()
{
	build_tree(1, 1, N);
	int rev(0);
	for (map< int, vector<pair<int, int>> >::const_iterator i = S.begin(), j;i != S.end();++i)
	{
		if (i == S.begin())
			Minus(1, i -> first);
		else
			--(j = i), Minus(1, i -> first - j -> first);
		for (int x = 0;x != i -> second.size();++x)
		{
			pair<int, int> v = i -> second[x];
			if (v.first == 0)
				Mult(1, -1), Plus(1, X), rev ^= 1;
			else
			{
				Ans[v.first] = query(1, v.second);
				if (rev)
					(Ans[v.first] *= -1) += X;
			}
		}
	}
	for (int i = 1;i <= Q;++i)
		printf("%d\n", Ans[i]);
}

int main()
{
	init();
	work();
	return 0;
}

Measured memory_bytes: 34048
#include <stdio.h>
#include <stdlib.h>
#define MAX 101
 
void initialize();
int Empty();
int Full();
void push(int);
int pop();
 
int n[MAX],top;
 
int main(){
  char m[MAX];
  int a,b;
 
  initialize();
 
  while(scanf("%s", m) != EOF){
    if(m[0] == '+'){
     b = pop();
     a = pop();
     push(a+b);
   }
   else if(m[0] == '-'){
    b = pop();
    a = pop();
    push(a-b);
  }
  else if(m[0] == '*'){
    b = pop();
    a = pop();
    push(a*b);
  }
  else {
    push(atoi(m));
  }
}
 
printf("%d\n", n[top]);
return 0;
}
 
void initialize(){
  top = 0;
}
 
int Empty(){
  return top == 0;
}
 
int Full(){
  return top >= MAX - 1;
}
 
void push(m){
  if(Full()){
    printf("WTF1\n");
    exit(1);
  }
  top++;
  n[top] = m;
}
 
int pop(){
  if (Empty()){
    printf("WTF2\n");
    exit(2);
  }
  top--;
  return n[top+1];
}

Measured memory_bytes: 548
#include <bits/stdc++.h>
#define endl '\n'
#define int long long
#define lint long long
#define pii pair<int,int>
#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 SZ(v) ((int)v.size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MINF(a) memset(a,0x3f,sizeof(a))
#define POW(n) (1LL<<(n))
#define POPCNT(n) (__builtin_popcount(n))
#define IN(i,a,b) (a <= i && i <= b)
using namespace std;
template <typename T> inline bool CHMIN(T& a,T b) { if(a>b) { a=b; return 1; } return 0; }
template <typename T> inline bool CHMAX(T& a,T b) { if(a<b) { a=b; return 1; } return 0; }
template <typename T> inline void SORT(T& a) { sort(ALL(a)); }
template <typename T> inline void REV(T& a) { reverse(ALL(a)); }
template <typename T> inline void UNI(T& a) { sort(ALL(a)); a.erase(unique(ALL(a)),a.end()); }
template <typename T> inline T LB(vector<T>& v, T a) { return *lower_bound(ALL(v),a); }
template <typename T> inline int LBP(vector<T>& v, T a) { return lower_bound(ALL(v),a) - v.begin(); }
template <typename T> inline T UB(vector<T>& v, T a) { return *upper_bound(ALL(v),a); }
template <typename T> inline int UBP(vector<T>& v, T a) { return upper_bound(ALL(v),a) - v.begin(); }
template <typename T1, typename T2> ostream& operator<< (ostream& os, const pair<T1,T2>& p) { os << p.first << " " << p.second; return os; }
template <typename T1, typename T2> istream& operator>> (istream& is, pair<T1,T2>& p) { is >> p.first >> p.second; return is; }
template <typename T> ostream& operator<< (ostream& os, const vector<T>& v) { REP(i,v.size()) { if (i) os << " "; os << v[i]; } return os; }
template <typename T> istream& operator>> (istream& is, vector<T>& v) { for(T& in : v) is >> in; return is; }
template <typename T = int> vector<T> make_v(size_t a) { return vector<T>(a); }
template <typename T, typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...)); }
template <typename T, typename V> typename enable_if<is_class<T>::value == 0>::type fill_v(T &t, const V &v) { t = v; }
template <typename T, typename V> typename enable_if<is_class<T>::value != 0>::type fill_v(T &t, const V &v) { for(auto &e : t) fill_v(e,v); }
const lint MOD = 1000000007;
const lint INF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1e-10;

// 最大部分列を求める
long long maximum_subarray(vector<int> &a) {
    long long res = numeric_limits<long long>::min();
    long long s = 0;
    for (int i = 0; i < (int)a.size(); ++i) {
        s = max(s, 0LL) + a[i];
        res = max(res, s);
    }
    return res;
}

void _main() {
    int n;
    while (cin >> n, n) {
        vector<int> a(n);
        cin >> a;
        cout << maximum_subarray(a) << endl;
    }
}

signed main(signed argc, char **argv) {
    if (argc > 1) {
        if (strchr(argv[1], 'i'))
            freopen("input.txt", "r", stdin);
        if (strchr(argv[1], 'o'))
            freopen("output.txt", "w", stdout);
    }
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
    _main();
    return 0;
}


Measured memory_bytes: 3164
#!/usr/local/bin python
# -*- coding: utf-8 -*-
#
# /PycharmProjects/atcoder/C-TaxIncrease.py
#
A, B = map(int, input().split())
ans = -1
for i in range (1000 + 1):
    if (int(i*0.08) == A) and (int(i*0.10) == B):
        ans = i
        break
print(ans)

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

using namespace std;

typedef long long ll;
typedef long double Double;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

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

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

int ADD = 0;
int DEL = 1;
int QUE = 2;
struct Query {
    int t, x;
    int type;
    int idx;

};

void solve(long long N, long long Q, std::vector<long long> S,
           std::vector<long long> T, std::vector<long long> X,
           std::vector<long long> D) {

    vector<Query> qs;
    for (int i = 0; i < N; i++) {
        int s = S[i], t = T[i], x = X[i];
        Query q;
        q.x = x;
        q.type = ADD;
        q.t = s - x;
        qs.push_back(q);
        q.type = DEL;
        q.t = t - x;
        qs.push_back(q);
    }
    for (int i = 0; i < Q; i++) {
        int d = D[i];
        qs.push_back({d, 0, QUE, i});
    }
    sort(qs.begin(), qs.end(), [](Query a, Query b) {
        if (a.t != b.t) return a.t < b.t;
        return a.type < b.type;
    });

    multiset<int> V;
    vector<int> res(Q, -2);
    for (auto i : qs) {
        if (i.type == DEL) {
            V.erase(V.find(i.x));
        }else if( i.type == ADD ){
            V.insert(i.x);
        }else{
            res[i.idx] = V.size() ? *V.begin() : -1;
        }
    }
    for( auto i : res){
        cout << i << endl;
    }

}

int main() {
    long long N;
    scanf("%lld", &N);
    long long Q;
    scanf("%lld", &Q);
    std::vector<long long> S(N);
    std::vector<long long> T(N);
    std::vector<long long> X(N);
    for (int i = 0; i < N; i++) {
        scanf("%lld", &S[i]);
        scanf("%lld", &T[i]);
        scanf("%lld", &X[i]);
    }
    std::vector<long long> D(Q);
    for (int i = 0; i < Q; i++) {
        scanf("%lld", &D[i]);
    }
    solve(N, Q, std::move(S), std::move(T), std::move(X), std::move(D));
    return 0;
}


Measured memory_bytes: 28388
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
# include <bitset>
# include <complex>
#include<limits.h>
#include<random>
#include<deque>
#include<cstdio>
#include<fstream>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
const int N = 2000100;
const int mod = (int)pow(10, 9) + 7;
const ll INF = 1LL << 60;
#define rep(i,n) for(ll i=(ll)0;i<(ll)n;++i)
#define ALL(x) x.begin(),x.end()
#define pp pair<ll,ll>
#define ppp pair<pp,ll>
#define fi first
#define se second
#define pb push_back
#define fix(n) fixed<<setprecision(n)
#define itr vector<ll>::iterator
#define print(s) cout<<s<<endl
#define inp(s) cin>>s
string yn(bool b) { return (b ? "Yes" : "No"); }
string YN(bool b) { return (b ? "YES" : "NO"); }
ll n, a[300010];
bool ans=1;
int main(){
	cin >> n;
	ll r = 0;
	rep(i, n) {
		cin >> a[i], a[i] /= 10;
		if (i <= r && i + a[i] > r)r = min(i + a[i],n-1);
	}
	if (r != n - 1)ans = 0;
	reverse(a, a + n);
	r = 0;
	rep(i, n) {
		if (i <= r && i + a[i] > r)r = min(n-1,i + a[i]);
	}
	if (r != n - 1)ans = 0;
	cout << (ans ? "yes" : "no") << endl;
	return 0;
}


Measured memory_bytes: 5468
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace _1_6_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            string[] str = Console.ReadLine().Split(' ');
            string[] array = new string[n];
            array[n - 1] = str[n - 1];
            string reverse = array[n-1];
            for (int i = n-2; i >=0 ; i--)
            {
                array[i] = str[i];
                reverse = reverse + " " + array[i];
            }
            Console.WriteLine(reverse);
        }
    }
}



Measured memory_bytes: 17932
#include<cstdio>
int main()
{
	int n,a,b,ans=0;
	scanf("%d",&n);
	for(int i=1;i<=n;++i)
	{
		scanf("%d%d",&a,&b);
		if(a==b)
			++ans;
		else
			ans=0;
		if(ans==3)
		{
			printf("Yes");
			return 0;
		}
	}
	printf("No");
}

Measured memory_bytes: 1728
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>

const int MAX = 1e9+5;

int main()
{
    int n;
    scanf("%d" ,&n);
    std::vector<int>a(n), dp(n, MAX);
    dp[0]=0;
    for(int& i: a){
        scanf("%d", &i);
    }
    
    for(int i=0 ; i<n; i++){
        for(int j: {i+1, i+2}){
            if(j<n){
                dp[j] = std::min(dp[j], dp[i]+std::abs(a[i]-a[j]));    
            }
            
        }
    }
    printf("%d\n", dp[n-1]);

    return 0;
}





Measured memory_bytes: 1024
# スイッチN個, 電球M個

N, M = map(int,input().split())
S = [list(map(int,input().split()))[1:] for _ in range(M)]
P = list(map(int,input().split()))

ans = 0

for mask in range(1<<N):
    flag = True
    for i in range(M):
        cnt = 0
        for j in S[i]:
            if (mask >> (j-1)) & 1:
                cnt += 1
        flag &= (cnt % 2) == P[i]
    if flag:
        ans += 1

print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int list[20]={0};
int main(){
	int n,i,m,e,sum=0,bo=0,si=0;
	double per;
	for(;scanf("%d %d %d",&n,&m,&e)!=EOF;sum=0,bo=0,si=0){
		sum=n+m;
		for(i=1;i<11;i++)list[i]=0;
		list[n]=1;list[m]=1;list[e]=1;
		for(i=1;i<=10;i++){
			if(list[i]==0){
				bo++;
				sum+=i;
				if(sum<=20)si++;
				sum-=i;
			}
		}
		per=(double)(si*100)/(double)bo;
		if(per>=50.0)printf("YES\n");
		else printf("NO\n");
	}
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
// input
int N; cin >> N;
vector <int> H(N);
for (int i = 0; i < N; ++i) {
cin >> H[i];
}
// compute
int ans = 0;
for (int i = 0; i < N; ++i) {
bool is_candidate = true;
for (int j = 0; j < i; ++j) {
if (H[j] > H[i]) {
is_candidate = false;
break;
}
}
if (is_candidate) {
++ans;
}
}
// output
cout << ans << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [0]*(N+1)
if N == 0 or N == 1:
    print(1)
else:
    A[0] = 1
    A[1] = 1
    for i in range(2, N+1):
        A[i] = A[i-1] + A[i-2]
    print(A[N])


Measured memory_bytes: 5596
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    string s;
    cin>>s;
    int len=s.size();
    ll ans=0,p=1,now=0,cnt[2020]={0};
    cnt[0]=1;
    for(int i=len;i--;){
        now=(now+ll(s[i]-'0')*p)%2019;
		ans+=cnt[now]++;
		p=p*10%2019;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3728
#include<stdio.h>
#include<math.h>

int main(){

	int N = 0;
	int K = 0;
	int val = 0;
	scanf("%d %d",&N,&K);

	if(N == 1){
		val = K;
	}else if(N == 2){
		val = K*(K-1);
	}else{
		val = K*pow(K-1,N-1);
	}

	printf("%d",val);

	return 0;

}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
    string s1,s2;
    cin>>s1>>s2;
    int cnt = 0;
    for(int i=0;i<3;i++)
    {
        if(s1[i] == s2[i])
            cnt++;
    }
    cout<<cnt<<endl;
    
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define all(x) (x).begin(),(x).end()
const int mod=1000000007,MAX=200005,INF=1<<30;

int main(){
    
    std::ifstream in("text.txt");
    std::cin.rdbuf(in.rdbuf());
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int N;cin>>N;
    vector<pair<ll,ll>> S(N);
    for(int i=0;i<N;i++){
        ll a,b;cin>>a>>b;
        S[i].first=a-b;
        S[i].second=a+b;
    }
    
    sort(all(S),[](pair<ll,ll> a,pair<ll,ll> b){
        return a.second<b.second;
    });
    
    ll ans=0,now=-INF;
    
    for(int i=0;i<N;i++){
        if(now<=S[i].first){
            ans++;
            now=S[i].second;
        }
    }
    
    cout<<ans<<endl;
}



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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))
 
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;
 
const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(long long A, long long B, long long K){
    VI memo;
    REP1(i, 101){
        if(A%i==0 && B%i==0) memo.PB(i);
    }

    cout << memo[memo.size()-K] << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long K;
    scanf("%lld",&K);
    solve(A, B, K);
    return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;

string s;
vector<string> cand;

int ans;
void dfs(int p, int C) {
    if (p == (int)s.size()) {
        cand.push_back(s);
        return;
    }
    // change
    int idx = (s[p] - 'a');
    if (~C >> idx & 1) {
        if (s[p] != 'z') {
            s[p]++;
            C ^= 1 << idx;
            dfs(p + 1, C);
            C ^= 1 << idx;
            s[p]--;
        }
    }
    // not change
    if (idx == 0 || C >> (idx - 1) & 1) {
        dfs(p + 1, C);
    }
}

int main() {
    while (cin >> s && s[0] != '#') {
        cand.clear();
        dfs(0, 0);
        cout << cand.size() << endl;
        sort(cand.begin(), cand.end());
        if (cand.size() <= 10) {
        } else {
            vector<string> new_cand;
            for (int i = 0; i < 5; ++i) {
                new_cand.push_back(cand[i]);
                new_cand.push_back(cand.rbegin()[i]);
            }
            cand = new_cand;
        }
        sort(cand.begin(), cand.end());
        for (auto &s : cand) cout << s << "\n";
    }
}

Measured memory_bytes: 4108
n, m = map(int, input().split())
hl = list(map(int, input().split()))

l = [True] * n
# print(l)

count = n
for _ in range(m):
    a, b = map(int, input().split())
    
    a = a - 1
    b = b - 1
    
    ah = hl[a]
    bh = hl[b]
    
    if ah >= bh:
        if l[b] == True:
            count -= 1
            l[b] = False
    if ah <= bh:
        if l[a] == True:
            count -= 1
            l[a] = False
    
    
# print(l)    
print(count)

Measured memory_bytes: 20128
#include<stdio.h>
#include<string.h>
int n,m;
int k;
int len;
int flgj=0,flgo=0,flg;
int j=0,o=0,i=0;
int max=0;
int temp;
char s[1000010];
int main(void){
	scanf("%s",s);
	len=strlen(s);
	for(k=0;k<len;k++){
		flg=0;
		if(s[k]=='J' && flgo==0){
			j++;
			flgj=1;
			if(s[k+1]=='I'){
				flg=1;
			}
		}
		else if(s[k]=='O' && flgj==1){
			o++;
			flgo=1;
			if(s[k+1]=='J'){
				flg=1;
			}
		}
		else if(s[k]=='I' && flgo==1){
			i++;
			if(s[k+1]!='I'){
				flg=2;
			}
			if(k==len-1){
				flg=2;
			}
		}
		if(flg==1){
			j=0;
			o=0;
			flgj=0;
			flgo=0;
		}
		if(flg==2){
			//printf("%d %d %d\n",j,o,i);
			if(j<o || i<o){
			}
			else {
				temp=j;
				if(temp>o){
					temp=o;
				}
				if(temp>i){
					temp=i;
				}
			}
			if(max<temp){
				max=temp;
			}
			j=0;
			o=0;
			i=0;
			flgj=0;
			flgo=0;
		}
	}
	printf("%d\n",max);
	return 0;
}

Measured memory_bytes: 1948
n,a,b=map(int,input().split())

mod=10**9+7

def pow_cal(x,n,mod):
    if n==0:
        return 1
    elif n==1:
        return x%mod
    elif n>=2:
        if n%2==0:
            return (pow_cal(x,n//2,mod)**2)%mod
        else:
            return (x*pow_cal(x,n//2,mod)**2)%mod

def find_power(n,mod):
    # 0!からn!までのびっくりを出してくれる関数(ただし、modで割った値に対してである）
    powlist=[0]*(n+1)
    powlist[0]=1
    powlist[1]=1
    for i in range(2,n+1):
        powlist[i]=powlist[i-1]*i%(mod)
    return powlist

def find_inv_power(n,mod):
    #0!からn!までの逆元を素数modで割ったあまりリストを作る関数
    c=1
    uselist=[0 for i in range(n+1)]
    for i in range(1,n+1):
        c*=i
        c%=mod
    first=pow_cal(c,mod-2,mod)
    uselist[n]=first
    for i in range(n,0,-1):
        uselist[i-1]=(uselist[i]*i)%(10**9+7)
    return uselist
A=find_power(2*10**5,mod)
B=find_inv_power(2*10**5,mod)

d=pow_cal(2,n,mod)-1
p=1
q=1

for i in range(1,a+1):
    p*=(n+1-i)
    p%=mod

p=p*B[a]%mod

for j in range(1,b+1):
    q*=(n+1-j)
    q%=mod

q=q*B[b]%mod

print((d-p-q)%mod)

Measured memory_bytes: 18996
# -*- coding: utf-8 -*-
"""
Created on Sun Aug  2 21:49:26 2020

@author: naoki
"""

N = int(input()) # N = the number of stones 
stones = input() # input the colors of stones 
count1 = stones.count("R") #the number of red stones 
stones2 = stones[count1:]
count2 = stones2.count("R")
print(count2)


Measured memory_bytes: 9432
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; ++i) // マクロ
using namespace std; // stdの省略
using pii = pair<int, int>; // pairの略記
using ll = long long; // long longの略記


int main(void) {
   
   int n, x, t;
   cin >> n >> x >> t;
   
   
   
   cout << (n+(x-1))/x*t << endl;
   
   return 0;
}

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

template <typename T> inline void Read(T& x) {
	int si = 1; char c = getchar(); x = 0;
	while(!isdigit(c)) si = c == '-' ? -1 : si, c = getchar();
	while(isdigit(c)) x = x * 10 + c - 48, c = getchar();
	x *= si;
}
template <typename T, typename... Args>
inline void Read(T& x, Args&... args) { Read(x); Read(args...); }

typedef long long ll;

const int kN = 2e4 + 5;

int p[kN], pre[kN];

int main() {
	int n; Read(n);
	for(int i = 1; i <= n; ++i) Read(p[i]), pre[p[i]] = i;
	for(int i = 1; i <= n; ++i) printf("%lld ", (ll)n * i);
	printf("\n");
	for(int i = 1; i <= n; ++i) printf("%lld ", (ll)n * n + pre[i] - (ll)n * i);
	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#define fl(i,a,n)      for(int i=a;i<=n;i++)
#define pb             push_back
#define int            long long int
#define ump            unordered_map
#define pii            pair<int,int>
#define ff             first
#define ss             second
#define PI             3.1415926535898
#define inf            1e18
#define vi             vector<int>
#define endl           "\n"
#define print(a)       for(auto x:a){cout<<x<<" ";}cout<<endl;
#define mod            1000000007
using namespace std;
template <typename Arg, typename... Args>
void db(Arg&& arg, Args&&... args) {
    cout << std::forward<Arg>(arg);
    using expander = int[];
    (void)expander{0, (void(cout << ',' << std::forward<Args>(args)), 0)...}; cout << endl;
}
inline int mymod(int A, int M) {return ((A % M) + M) % M;}
ump<int, int>mp;
int dfs(int src, vector<int>v[]) {
    mp[src] = 1;
    int ans = 1;
    for (auto x : v[src]) {
        if (!mp[x]) {
            ans += dfs(x, v);
        }
    }
    return ans;
}
inline void solve() {
    int n; cin >> n;
    int m; cin >> m;
    vector<int>v[n + 1];
    fl(i, 0, m - 1) {
        int x, y;
        cin >> x >> y;
        v[x].pb(y);
        v[y].pb(x);
    }
    int ans = 0;
    fl(i, 1, n) {
        if (!mp[i]) {
            ans = max(ans, dfs(i, v));
        }
    }
    cout << ans << endl;
}
int32_t main() {
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
#endif
    int t = 1;
    // cin >> t;
    fl(i, 1, t)
    {
        solve();
    }

    return 0;
}

Measured memory_bytes: 40968
import math
A, B = input().split()
Afrac = A[-2:].zfill(2)
Aint = A[:-2].zfill(1)
Bfrac = B[-2:].zfill(2)
Bint = B[:-3].zfill(1)

ans = int(A) * int(Bint) + int(Aint) * int(Bfrac) + math.floor(int(Afrac) * int(Bfrac) / 100)
print(ans)

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

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

	string devide[4] = {"dream","dreamer","erase","eraser"};
    string S;
    cin  >> S;

    reverse(S.begin(),S.end());
    for(int i=0; i < 4; ++i) reverse(devide[i].begin(), devide[i].end());

    bool can = true;
    for(int i=0; i < S.size();){
    	bool can2 = false;
    	for(int j = 0; j < 4; ++j){
    		string d = devide[j];
    		if(S.substr(i, d.size()) == d){
    			can2 = true;
    			i += d.size();
    		}
    	}
    	if(!can2){
    		can = false;
    		break;
    	}
    }

    if(can) cout << "YES" << "\n";
    else cout << "NO" << "\n";

}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
int main(){
  int n,m;//n:カード枚数 m:ゲート数
  cin>>n>>m;
  int s=0,e,start,end=n;
  while(m>0){
    cin>>s>>e;
    if(s>start)start=s;
    if(e<end)end=e;
    if(end<start){
      end=0;
      start=1;
      break;
    }
    m--;
  }
  cout<<end-start+1;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int m[10001][2];
int main()
{
  int n,i,j,k,l,c;
  for(;;){
    scanf("%d",&n);
    if(n==0) break;
    memset(m,0,sizeof(m));
    scanf("%d",&c);
    j = 1;
    l = 1;
    k = c;
    for(i=1;i<n;i++){
      scanf("%d",&c);
      if(c == k) l++;
      else {
	m[j][0] = k;
	m[j++][1] = l;
	l = 1;
	k = c;
      }
    }
    m[j][0] = k;
    m[j++][1] = l;
    /*
    for(i=1;i<j;i++){
      printf("%d %d\n",m[i][0],m[i][1]);
    }
    */
    for(i=1;i<j;i++){
      if(m[i][1] == 1){
	if(m[i-1][0] == m[i+1][0] && m[i-1][1] + m[i+1][1] > 2){
	  k = i - 2; l = i + 2;
	}else if(m[i-1][1] == 3){
	  k = i - 2; l = i + 1;
	}else if(m[i+1][1] == 3){
	  k = i - 1; l = i + 2;
	}else{
	  continue;
	}
	while(k > 0 && l < j && m[k][0] == m[l][0] && m[k][1] + m[l][1] > 3){
	  k--; l++;
	}
	c = 0;
	while(k > 0) c += m[k--][1];
	while(l < j) c += m[l++][1];
	if(n > c) n = c;
      }else{
	if(m[i-1][1] == 3){
	  k = i - 2; l = i;
	}else if(m[i+1][1] == 3){
	  k = i; l = i + 2;
	}else{
	  continue;
	}
	m[i][1]--;
	while(k > 0 && l < j && m[k][0] == m[l][0] && m[k][1] + m[l][1] > 3){
	  k--; l++;
	}
	c = 0;
	while(k > 0) c += m[k--][1];
	while(l < j) c += m[l++][1];
	if(n > c) n = c;
	m[i][1]++;
      }
    }
    printf("%d\n",n);
  }
  return 0;
}

Measured memory_bytes: 0
a=int(input())
b=int(input())
c=int(input())
x=int(input())
ans=chk=0
for i in range(a+1):
    for j in range(b+1):
        tmp=i*500+j*100
        if x-tmp>=0 and (x-tmp)//50<=c: ans+=1
print(ans)

Measured memory_bytes: 3064
import java.util.*;
import static java.lang.System.*;
 
public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		HashMap<String,Integer> map = new HashMap<>();
		int n = sc.nextInt();
		String s;
		for (int i=0; i<n; i++) {
			s = sc.next();
			map.put(s,map.getOrDefault(s,0));
			map.put(s,map.get(s)+1);
		}
		int m = sc.nextInt();
		for (int i=0; i<m; i++) {
			s = sc.next();
			map.put(s,map.getOrDefault(s,0));
			map.put(s,map.get(s)-1);
		}
		int max = 0;
		for (Map.Entry<String,Integer> e : map.entrySet()) {
			max = Math.max(max,e.getValue());
		}
		out.println(max);
	}
}

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

int main() {
  string s;cin>>s;
  int n=s.size();
  ll ans=0;
  for(int bit=0;bit<(1<<n-1);bit++){
    ll cnt=s[0]-'0';
    rep(i,n-1){
      if(bit&(1<<i)){
        ans+=cnt;
        cnt=0;
      }
      cnt=cnt*10+s[i+1]-'0';
    }
    ans+=cnt;
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rrep(i, n) for (int i = 1; i < (n+1); ++i)
const double PI  =3.141592653589793238463;
using namespace std;
using ll = long long;
const ll INF = +10010010000;
typedef pair<int,int> P;
const int mod = 1e9+7;

struct mint{
    ll x;
    mint(ll x=0):x((x%mod+mod)%mod){}
    mint& operator+=(const mint a){
        (x+=a.x)%=mod;
        return *this;
    }
    mint& operator-=(const mint a){
        (x-=mod-a.x)%=mod;
        return *this;
    }
    mint& operator*=(const mint a){
        (x *= a.x)%= mod;
        return *this;
    }
    mint operator+(const mint a)const{
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a)const{
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a)const{
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
      if(!t)return 1;
      mint a = pow(t>>1);
      a*=a;
      if(t%1)a*=*this;
      return a;
    }

    // for prime mod
    mint inv() const {
      return pow(mod-2);
    }
    mint& operator/=(const mint a){
      return (*this) *= a.inv();
    }
    mint operator/(const mint a)const{
      mint res(*this);
      return res/=a;
    }
};

struct combination{
  vector<mint> fact, ifact;
  combination(int n):fact(n+1),ifact(n+1){
    fact[0] = 1;
    for(int i = 1; i<n;++i)fact[i] = fact[i-1] * i;
    ifact[n] = fact[n].inv();
    for(int i = n; i>=1;--i) ifact[i-1] = ifact[i] * i;
  }
  mint operator()(int n, int k){
    if(k<0 || k>n)return 0;
    return fact[n] * ifact[k] + ifact[n-k]; 
  }
};

int main(){
    int x, y;
    cin >> x >> y;
    int mini,maxi;
    mini = x*2;
    maxi=x*4;
    if(y%2==1){
        cout << "No"<<endl;
    }else{
        if(mini <=y &&y<=maxi){
            cout << "Yes"<<endl;
        }else{
            cout << "No"<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 3596