akhauriyash/Code-Regression huggingface dataset:
#pragma region Include
#include <bits/stdc++.h>
// #include <algorithm>
// #include <bitset>
// #include <climits>
// #include <cmath>
// #include <iostream>
// #include <iterator>
// #include <map>
// #include <queue>
// #include <sstream>
// #include <stack>
// #include <string>
// #include <unordered_map>
// #include <unordered_set>
// #include <vector>
#pragma endregion

using namespace std;

#pragma region Macros
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i, n) rep2(i, 0, n)
#define rep2(i, m, n) for (int i = m; i < (n); i++)
#define all(c) (c).begin(), (c).end()
#define newl "\n"
#define out(x) cout << (x) << newl
#define dump(x) \
  cout << "Line " << __LINE__ << " : " << #x << " = " << (x) << newl
template <class T>
using VV = vector<vector<T>>;
#define Uni(v) (v).erase(unique((v).begin(), (v).end()), (v).end());

template <typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
  os << "[";
  rep(i, vec.size()) os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "]";
  return os;
}

template <typename T>
ostream& operator<<(ostream& os, vector<vector<T>>& mat) {
  os << "[";
  rep(i, mat.size()) os << mat[i] << (i + 1 == mat.size() ? "" : ",\n ");
  os << "]";
  return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& vec) {
  for (T& x : vec) is >> x;
  return is;
}

template <typename V, typename H>
void resize(vector<V>& vec, const H head) {
  vec.resize(head);
}

template <typename V, typename H, typename... T>
void resize(vector<V>& vec, const H& head, const T... tail) {
  vec.resize(head);
  for (auto& v : vec) resize(v, tail...);
}
constexpr double EPS = 1e-10;
const int INF = 0x3f3f3f3f;

string tostring(int i, int digit) {
  auto cur = cout.flags();
  stringstream ss;
  ss << setw(4) << setfill('0') << i;
  string ret = ss.str();
  cout.flags(cur);
  return ret;
}

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

#pragma endregion

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  vector<ll> d(60);
  ll mod = pow(10, 9);
  mod += 7;
  ll N;
  cin >> N;
  rep(i, N) {
    ll A;
    cin >> A;
    ll ind = 0;
    while (A != 0) {
      d[ind] += A & 1;
      A = A >> 1;
      ++ind;
    }
  }

  ll ans = 0;
  rep(i, 60) {
    ll tmp = d[i] * (N - d[i]);
    rep(j, i) { tmp = (tmp * 2) % mod; }
    ans = (ans + tmp) % mod;
  }

  out(ans);

  return 0;
}

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

int main() {
    ll h;
    cin >> h;

    ll i = 0;
    ll ans = 0;

    while (h != 0) {
        h /= 2;
        ans += pow(2, i);
        i++;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
bool f(int a){
int b = a % 10 ;a/=10;
	while(a)
      if(b != a % 10)
        	return false;
  		else
      		a /= 10;
  return 1;
}
main(){
 	int a;
  cin >> a;
  for(int i = a; i < 1000; i++)
  		if(f(i))
          return cout << i << endl ,0;
}

Measured memory_bytes: 256
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.io.PrintWriter
import java.lang.StringBuilder
import java.util.*

fun PrintWriter.solve(sc: FastScanner) {
    val k = sc.nextInt()
    val a = sc.nextInt()
    val b = sc.nextInt()
    for (i in 0 until 1000) {
        val v = k * i
        if (v in a..b) {
            println("OK")
            return
        }
    }
    println("NG")
}

fun main(args: Array<String>) {
    val writer = PrintWriter(System.out, false)
    writer.solve(FastScanner(System.`in`))
    writer.flush()
}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

Measured memory_bytes: 34368
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
#define shandom_ruffle random_shuffle

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy


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

    ll n;
    cin >> n;
    ll a[n];
    F0R(i,n) cin >> a[i];
    ll ans=0;
    FOR(i,1,n-1){
      if(a[i] > a[i-1] && a[i] < a[i+1])
      ++ans;
      else if(a[i] < a[i-1] && a[i] > a[i+1])
        ++ans;
    }
    cout << ans;


    return 0;
}

// read the question correctly (ll vs int)
// template by super1 derived from bqi343


Measured memory_bytes: 256
from numba import njit

@njit('i8(i8)', cache=True)
def fun(n):
    #mx = n#int((n**.5) // 3) + 1
    mx = int(n**.5 + 0.5)
    pairs = 0
    for x in range(1, mx + 1):
        for y in range(x, mx + 1):
            for z in range(y, mx + 1):
                v = x*x + y*y + z*z + x*y + y*z + z*x
                if v == n:
                    if x == y == z:
                        pairs += 1
                    elif x == y or y == z:
                        pairs += 3
                    else:
                        pairs += 6
    return pairs

n = int(input())
for i in range(n):
    ps = fun(i + 1)
    print(ps)


Measured memory_bytes: 106588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;

int main() {
    int x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    int p[a], q[b], r[c];
    for (int i = 0; i < a; i++) {
        cin >> p[i];
    }
    for (int i = 0; i < b; i++) {
        cin >> q[i];
    }
    for (int i = 0; i < c; i++) {
        cin >> r[i];
    }

    sort(p, p + a);
    reverse(p, p + a);
    sort(q, q + b);
    reverse(q, q + b);
    sort(r, r + c);
    reverse(r, r + c);

    int s[x + y];
    for (int i = 0; i < x; i++) {
        s[i] = p[i];
    }
    for (int j = 0; j < y; j++) {
        s[x + j] = q[j];
    }
    sort(s, s + (x + y));

    ll cnt = 0;
    for (int i = 0; i < x + y; i++) {
        cnt += s[i];
    }

    ll ans = cnt;
    for (int i = 0; i < min(c, x + y); i++) {
        cnt -= s[i];
        cnt += r[i];
        ans = max(ans, cnt);
    }

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

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

int main(){
  int N;
  cin >> N;
  vector<int> R,G,B;
  string S;
  cin >> S;
  for(int i=0; i<N; i++){
    if(S[i] == 'R')
      R.push_back(i);
    else if(S[i] == 'G')
      G.push_back(i);
    else
      B.push_back(i);
  }
  int64_t ans = 0;
  for(auto r: R){
    for(auto g: G){
      int minus=0;
      if((r+g)%2==0 && S[(r+g)/2]=='B')
        minus++;
      if(r+(r-g)<N && 0<=r+(r-g) && S[2*r-g]=='B')
        minus++;
      if(2*g-r<N && 2*g-r>=0 && S[2*g-r]=='B')
        minus++;
      ans += B.size();
      ans -= minus;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3604
#include <stdio.h>
int main() {
    int N,i,v,j,k;
    scanf("%d",&N);
    int A[N]; 
    for(i=0; i<N; i++){
        scanf("%d",&A[i]);
    }
    for(i=0; i<N; i++){
        v = A[i];
        j = i-1;
        while( j>= 0 && A[j] > v){
            A[j+1] = A[j];
            j--;
        }
        A[j+1] = v;
        for(k=0; k<N; k++){
            printf("%d",A[k]);
            if(k<N-1) printf(" ");
        }
        printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double
#define fi first
#define se second
#define endl '\n'
#define MAX INT_MAX
#define MIN INT_MIN
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define mod 1000000007
#define pb push_back
#define sz(a) (int)((a).size())
#define all(a) a.begin(),a.end()
#define loopf(i,a,b) for(int i = a;i < b;i++)
#define loopb(i,a,b) for(int i = a;i >= b;i--)
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;


int32_t main()
{
    fast

   int test=1;
   //cin>>test;

  while(test--)
  {
  int n,x,y;
  cin>>n>>x>>y;
 
  vi ans(n,0);
  int c;
  for(int i=1;i<=n;i++)
  {
    for(int j=i+1;j<=n;j++)
    {
      c=min(j-i,min(abs(x-i)+1+abs(y-j),abs(y-i)+1+abs(x-j)));
      ans[c]++;
    }
  }

  for(int i=1;i<n;i++)cout<<ans[i]<<endl;

  //while loop ending 
  }

return 0;
}

Measured memory_bytes: 256
import std.algorithm;
import std.array;
import std.container;
import std.conv;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

void scan(T...)(ref T a) {
    string[] ss = readln.split;
    foreach (i, t; T) a[i] = ss[i].to!t;
}
T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

long calc(long L, long R) {
    long ans = long.max;
    foreach (i; L..R+1) {
        foreach (j; i+1..R+1) {
            ans = min(ans, i * j % 2019);
            if (ans == 0) return ans;
        }
    }
    return ans;
}

void main() {
    int L, R; scan(L, R);
    writeln(calc(L, R));
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main()
{
  int i,j,k,time=0,leng=0,key=0;
  int prop[N];

  scanf("%d",&time);

  for( i = 0 ; i < time ; i++ )
  {
    scanf("%d",&prop[i]);
  }


  for( i = 1 ; i < time+1 ; i++ )
  {

    for( k = 0 ; k < time ; k++ )
    {
      if( k == time-1 )printf("%d",prop[k]);
      else printf("%d ",prop[k]);
    }
    printf("\n");

    key = prop[i];

    j = i-1;
    while( j>= 0 && prop[j] > key )
    {
      prop[j+1] = prop[j];
      j--;
    }

    prop[j+1] = key;

  }

  return 0;
}



Measured memory_bytes: 2128
#include <stdio.h>

int main(){
	int N, a, i, min = 1000, max = 0;
	scanf("%d", &N);
	for(i = 0; i < N; i++){
		scanf("%d", &a);
		if(a < min){
			min = a;
		}
		if(a > max){
			max = a;
		}
	}
	printf("%d\n", max - min);
	return 0;
}

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

typedef pair<int,int> PII;

int main(){
	int n;
	cin>>n;
	double total=0;
	for (int i = 0; i < n; ++i){
		double b;
		string s;
		cin>>b>>s;
		if(s=="JPY")
			total += b;
		else
			total += b * 380000;
	}

	cout<<total<<endl;
}


Measured memory_bytes: 256
k = int(input())

l = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
print(l[k-1])

Measured memory_bytes: 3060
#include<iostream>
#include<cmath>
#include<cstdlib>
#include<string>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<iomanip>

using namespace std;

typedef long long ll;

typedef std::pair<int, int> ipair;
bool lessPair(const ipair& l, const ipair& r){return l.second < r.second;}
bool morePair(const ipair& l, const ipair& r){return l.second > r.second;}

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

const ll MOD = 1e9 + 7;
// const long long INF = 1LL<<60;
void add(long long &a, long long b) { a += b; if (a >= MOD) a -= MOD; }
void sub(long long &a, long long b) { a -= b; if (a < 0) a += MOD; }
void mul(long long &a, long long b) { a *= b; a %= MOD; }
ll llmin(ll a, ll b) { if (a < b) return a; else return b; }
ll llmax(ll a, ll b) { if (a < b) return b; else return a; }
ll llabs(ll a) { if (a >= 0) return a; else return - a; }
ll llmodpow(ll a, ll n) {
   if (n == 0) return 1;
   ll tmp = llmodpow(a, n / 2);
   mul(tmp, tmp);
   if (n & 1) mul(tmp, a);
   return tmp;
}

int main() {
   ll L, R;
   cin >> L >> R;
   
   ll l = L % 2019;
   ll l2 = L / 2019;
   ll r = R % 2019;
   ll r2 = R / 2019;

   ll ans = 0;
   if (R - L >= 2018) ans = 0;
   else if (r2 != l2) ans = 0;
   else {
      ans = 2019;
      for (int i = l; i <= r; i++) {
         for (int j = i + 1; j <= r; j++) {
            ans = llmin(ans, i * j % 2019);
         }
      }
   }   
   cout << ans << endl;
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#define REP(i, b, n) for (Int i = b; i < Int(n); i++)
#define rep(i, n) REP(i, 0, n)
using namespace std;
using Int = long long;
Int inf = 1000000000000000001LL;
using vi = vector<Int>;
using vvi = vector<vi>;
using mapis = unordered_map<Int,string>;
using mapii = unordered_map<Int,Int>;
using pii = pair<Int,Int>;

Int GCD(Int a, Int b){
    if(b==0) return a;
    if(a < b) return GCD(b, a);
    unsigned r;
    while ((r=a%b)) {
        a = b;
        b = r;
    }
    return b;
}
Int printX(Int r, Int D, Int X, int count){
    if(count == 10){
        return 0;
    }
    Int nextX = r*X - D;
    cout<< nextX <<endl;
    printX(r,D,nextX,count+1);

}

int myPow(int x, int p) {
    if (p == 0) return 1;
    if (p == 1) return x;
    return x * myPow(x, p-1);
}

int main() {
    int N;
    string S,T;
    cin >>N;
    cin >> S >>T;

    rep(i,N){
        cout << S[i] << T[i];
    }

    cout << endl;





    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
using namespace std;
#define pb push_back
int dy[]={0, 0, 1, -1, 1, 1, -1, -1};
int dx[]={1, -1, 0, 0, 1, -1, -1, 1};

#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define mp make_pair
#define fi first
#define sc second
int n,K,a[200],b[200],dc[200];
int dp[200][3][2];
int main(){
    scanf("%d%d",&n,&K);
    REP(i,n + 1)
        dc[i] = -1;
    REP(i,K){
        scanf("%d%d",a + i,b + i);
        b[i]--;
        dc[a[i]] = b[i];
    }

    REP(j,3){
        REP(k,2){
            dp[1][j][k] = (k == 0 && (dc[1] == -1 || dc[1] == j));
        }
    }

    FOR(i,2,n + 1){
        REP(j,3){
            REP(k,2){
                if(dc[i] != j && dc[i] >= 0)
                    dp[i][j][k] = 0;
                else{
                    if(k == 0){
                        int s = 0;
                        REP(jj,3){
                            REP(kk,2){
                                s += dp[i - 1][jj][kk] * (j != jj);
                            }
                        }
                        dp[i][j][k] = s;
                    }else{
                        dp[i][j][k] = dp[i - 1][j][k - 1];
                    }
                }
                dp[i][j][k] %= 10000;
            }
        }
    }

    int ans = 0;
    REP(j,3)
        REP(k,2){
            ans += dp[n][j][k];
            ans %= 10000;
        }
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 3204
def main():
    N, M = map(int, input().split())
    num = [0]*N
    flag = [False]*N
    num[0] = 1
    
    if N == 1 and M == 0:
        print(0)
        exit()

    for m in range(M):
        s, c = map(int, input().split())

        if s == 1 and c == 0:
            if N == 1:
                print(0)
                exit()
            else:
                print(-1)
                exit()

        if flag[s-1]:
            if num[s-1] != c:
                print(-1)
                exit()
        else:
            num[s-1] = c
            flag[s-1] = True
    

    print(''.join(map(str, num)))


if __name__ == '__main__':
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main(void)
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int _=1;
    //cin>>_;
    while(_--)
    {
        ll k,n;
        cin>>k>>n;
        ll a[n];
        for(int i=0;i<n;i++)
        {cin>>a[i];}
        sort(a ,a+n);
        ll md=0;
        for(int i=0;i<n-1;i++)
        {
         md=max(md,a[i+1]-a[i]);
        }
        md=max(md,(k-a[n-1])+a[0]);
        
            cout<<k-md;
    }
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr int MOD = 1e9 + 7;

int main() {
  int n, k;
  cin >> n >> k;
  vector<ll> a(n);
  for (auto& e : a) cin >> e;

  vector<ll> ne, po;
  for (auto e : a) {
    if (e < 0) {
      ne.push_back(e);
    } else if (e > 0) {
      po.push_back(e);
    }
  }

  ll r = 1;

  if (k == n) {
    bool b = false;
    for (auto e : a) {
      (r *= abs(e)) %= MOD;
      if (e < 0) b = !b;
    }
    if (b) r = (MOD - r) % MOD;
    cout << r << endl;
    return 0;
  }

  if (ne.size() - ne.size() % 2 + po.size() >= k && (po.size() > 0 || k % 2 == 0)) {
    sort(ne.begin(), ne.end());
    sort(po.rbegin(), po.rend());
    int i = 0, j = 0;
    if (k % 2 == 1) {
      r = po[0];
      j++;
    }
    while (i + j < k) {
      if (i + 1 < ne.size() && (j + 1 >= po.size() || ne[i] * ne[i + 1] > po[j] * po[j + 1])) {
        r *= ne[i] * ne[i + 1] % MOD;
        i += 2;
      } else {
        r *= po[j] * po[j + 1] % MOD;
        j += 2;
      }
      r %= MOD;
    }
  } else if (n - (ne.size() + po.size()) > 0) {
    r = 0;
  } else {
    sort(ne.rbegin(), ne.rend());
    for (int i = 0; i < k; i++) (r *= -ne[i]) %= MOD;
    r = (MOD - r) % MOD;
  }
  cout << r << endl;
}


Measured memory_bytes: 6900
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair< ll, ll > Pi;
#define rep(i,n) for(int i=0;i<(n);i++)
#define rep2(i,n) for(int i=1;i<=(n);i++)
#define rep3(i,i0,n) for(int i=i0;i<(n);i++)
#define pb push_back
#define mod 1000000007
const ll INF = 1LL << 60;
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; }
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;}
#define all(x) x.begin(), x.end()
#define mp make_pair
bool compare(Pi a, Pi b) {
    if(a.first != b.first){
        return a.first < b.first;
        
    }else{
        return a.second < b.second;
    }
}


bool In_map(ll y,ll x,ll h,ll w){
    if(y<0 || x<0 || y>=h || x>=w){
        return 0;
    }else{
        return 1;
    }
}
const vector<ll> dx{1,0,-1,0};
const vector<ll> dy{0,1,0,-1};


int main() {
    ll H,W;
    cin >>H>>W;
    vector<string>A(H);
    rep(i,H){
        cin>>A[i];
    }
    vector<bool>DH(H);
    vector<bool>DW(W);
    rep(i,H){
        rep(j,W){
            if(A[i][j]=='#'){
                break;
            }
            if(j==W-1){
                DH[i]=1;
            }
        }
    }
    rep(i,W){
        rep(j,H){
            if(A[j][i]=='#'){
                break;
            }
            if(j==H-1){
                DW[i]=1;
            }
        }
    }

    rep(i,H){
        if(DH[i]==0){
            rep(j,W){
                if(DW[j]==0){
                    cout<<A[i][j];
                }
                    
            }
            cout<<endl;
        }
    }
    



    return 0;
    

}

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

using namespace std;
typedef long long ll;

#define rep(i , j , n) for(long long i = j ; i <= n ; i++)
const ll N = 123456;

ll a[N];

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n , m;
    cin >> n >> m;

    ll in = (n - 1) * (m - 1);

    if(n == 2 && m == 2) {
        cout << 0 << endl;
        return 0;
    }

    if(n == 1 && m == 1) {
        cout << 1 << endl;
        return 0;
    }

    if(n == 1 || m == 1) {
        cout << max(n , m) - 2 << endl;
        return 0;
    }

    cout << n * m - (2 * n + 2 * m - 4) << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	string S;
  	int ans=0;
  	cin >> S;
  	if(S == "SUN") ans = 7;
  	else if(S== "MON") ans = 6;
  	else if(S== "TUE") ans = 5;
  	else if(S== "WED") ans = 4;
  	else if(S== "THU") ans = 3;
  	else if(S== "FRI") ans = 2;
  	else if(S== "SAT") ans = 1;
	cout << ans << endl;
	return 0;
}

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

const int N = 20 + 5;

char mp[N][N];
int vis[N][N];
const int dir[4][2] = {1, 0, 0, 1, -1, 0, 0, -1};

struct A {
  int x, y;
};

int h, w;

bool inter(int x, int y) {
  return x >= 0 && x < h && y >= 0 && y < w;
}

int dfs(int x, int y) {
  memset(vis, 0, sizeof(vis));
  queue<A> Q;
  Q.push((A){x, y});
  vis[x][y] = 1;
  int rtn = 1;
  while (!Q.empty()) {
    A q = Q.front(); Q.pop();
    for (int i = 0; i < 4; ++i) {
      int nx = q.x + dir[i][0];
      int ny = q.y + dir[i][1];
      if (!inter(nx, ny)) continue;
      if (vis[nx][ny] || mp[nx][ny] == '#') continue;
      Q.push((A){nx, ny});
      vis[nx][ny] = vis[q.x][q.y] + 1;
      rtn = max(rtn, vis[nx][ny]);
    }
  }
  return rtn - 1;
}

void solve() {
  int ans = 0;
  scanf("%d%d", &h, &w);
  for (int i = 0; i < h; ++i) scanf("%s", mp[i]);
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (mp[i][j] == '.') ans = max(ans, dfs(i, j));
    }
  }
  printf("%d\n", ans);
}

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


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using lli = long long;
using pii = pair<int, int>;

#define rep(i,k,n) for(int i=(k); i != int(n); ++i)
#define sz(x) x.size()
#define all(x) x.begin(), x.end()

#define dbg(x) cout << #x << '=' << x << '\n'
#define dbg2(x, y) cout << #x << '=' << x << ' ' << #y << '=' << y << '\n' 

#define input() (*istream_iterator<int>(cin))
#define strin() (*istream_iterator<string>(cin))
#define output(x) cout << x << '\n' 

int main(){
    ios::sync_with_stdio(false);
    string a, b;
    cin >> a >> b;
    b.resize(sz(a));
    if(a == b) cout << "Yes\n";
    else cout << "No\n";
}

Measured memory_bytes: 3660
using System;

namespace abc100A
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split();
            int A = int.Parse(str[0]);
            int B = int.Parse(str[1]);
            if (A <= 8 && B <= 8)
                Console.WriteLine("Yay!");
            else
                Console.WriteLine(":(");
        }
    }
}


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

int main() {
	int n, m;
	cin >> n >> m;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	map<int, int> mp;
	priority_queue<pair<ll, int>> que;
	rep(i, n) que.emplace(a[i], i);
	rep(ri, m) {
		int b = que.top().second;
		que.pop();
		mp[b]++;
		ll tmp = a[b] / pow(2, mp[b]);
		que.emplace(tmp, b);
	}
	ll ans = 0;
	while (que.size()) {
		ll tmp = que.top().first;
		que.pop();
		ans += tmp;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 6896
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ii pair<ll,ll>
#define iii pair<ll,ii>
#define endl '\n'


const int MOD=1000000007;

long long fen[200005]; //initialize to 0, this is 1-indexed
void update(int i,long long j){ //adds j to ith term
	i+=3; //im lazy
    while (i<200005){
        fen[i]+=j;
		fen[i]%=MOD;
        i+=(i&(-i));
    }
}
long long query(int i){ //calculate the sum of the 0-i terms
	i+=3;
    long long k=0;
    while (i>0){
        k+=fen[i];
        i-=(i&(-i));
    }
    return k%MOD;
}

long long query(int i,int j){
	return (query(j)-query(i-1)+MOD)%MOD;
}


struct dat{
	int v;
	int pos;
	
	int maxv;
	int minv;
};

int n;
dat arr[200005];

int main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	
	cin>>n;
	
	for (int x=0;x<n;x++){
		cin>>arr[x].pos>>arr[x].v;
	}
	
	sort(arr,arr+n,[](dat i,dat j){
		return i.v<j.v;
	});
	
	for (int x=0;x<n;x++) arr[x].v=x;
	
	sort(arr,arr+n,[](dat i,dat j){
		return i.pos<j.pos;
	});
	
	for (int x=0;x<n;x++) arr[x].pos=x;
	
	int temp;
	
	temp=0;
	for (int x=0;x<n;x++){
		temp=max(temp,arr[x].v);
		arr[x].maxv=temp;
	}
	
	temp=1000000000;
	for (int x=n-1;~x;x--){
		temp=min(temp,arr[x].v);
		arr[x].minv=temp;
	}
	
	update(-1,1);
	
	for (int x=0;x<n;x++){
		//cout<<arr[x].minv<<" "<<arr[x].maxv<<endl;
		update(arr[x].maxv,query(arr[x].minv-1,arr[x].maxv));
	}
	
	cout<<query(n-1,n-1);
}

Measured memory_bytes: 4992
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
	Scanner scan = new Scanner(System.in);
	int A = scan.nextInt();
	int B = scan.nextInt();
	int C = scan.nextInt();
	int D = scan.nextInt();
	int sum1, sum2 ;
	if(A>=B){
		sum1 = B;
	}else{
		sum1 = A;
	}
	
	if(C>=D){
		sum2 = D;
	}else{
		sum2 = C;
	}
	
	int sum = sum1 + sum2;
	System.out.print(sum);


	}

}


Measured memory_bytes: 23764
#include<iostream>
#include<string>
#include<cmath>
//#include<array>
#include<algorithm>
#include<deque>
#include<vector>
//#include<utility>
//#include<set>
#include<map>
//#include<list>

using namespace std;
using LLI = long long int;
LLI N;

//vector<int>dir_x = { 0,0,1,1,1,-1,-1,-1 };
//vector<int>dir_y = { 1,-1,1,0,-1,1,0,-1 };
//vector<int>dir_x2 = { 0,0,1,-1 };
//vector<int>dir_y2 = { 1,-1,0,0 };
//vector<char>alp = { 'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z' };

//class UnionFind {
//public:
//	vector<int>data;
//	UnionFind(int size) :data(size, -1) {};
//	bool unionset(int x, int y) {
//		x = root(x), y = root(y);
//		if (x != y) {
//			if (data[y] < data[x]) {
//				swap(x, y);
//			}
//			data[x] += data[y];
//			data[y] = x;
//		}
//		return x != y;
//	}
//	bool findset(int x, int y) {
//		return root(x) == root(y);
//	}
//	int root(int x) {
//		return data[x] < 0 ? x : data[x] = root(data[x]);
//	}
//	int size(int x) {
//		return -data[root(x)];
//	}
//};

//LLI gcd(LLI x, LLI y) {
//	LLI tmp, r;
//	if (x < y) {
//		tmp = x;
//		x = y;
//		y = tmp;
//	}
//	r = x % y;
//	while (r != 0) {
//		x = y;
//		y = r;
//		r = x % y;
//	}
//	return y;
//}
//LLI lcm(LLI x,LLI y) {
//	return x / gcd(x,y) * y;
//}

//long nCr(int n,int r) {
//	long ans = 1;
//	for (int i = n; i > n - r;i--) {
//		ans = ans * i;
//	}
//	for (int i = 1; i < r + 1;i++) {
//		ans = ans / i;
//	}
//	return ans;
//}

//const int n_max = 8;
//array<array<bool, n_max>, n_max>graph;
//int dfs(int v,int N,array<bool,n_max>visited) {
//	int ret = 0;
//	bool all_visited = true;
//	for (int i = 0; i < N;i++) {
//		if (visited[i] == false) {
//			all_visited = false;
//		}
//	}	
//	if (all_visited) {
//		return 1;
//	}
//	for (int i = 0; i < N;i++) {
//		if (graph[v][i] == false) {
//			continue;
//		}
//		if (visited[i] == true) {
//			continue;
//		}
//		visited[i] = true;
//		ret += dfs(i,N,visited);
//		visited[i] = false;
//	}
//	return ret;
//}

//vector<vector<int>>sub;
//int dfs(int id) {
//	if (sub[id].size() == 0) {
//		return 1;
//	}
//	int minP = (int)1e9;
//	int maxP = 0;
//	for (int i : sub[id]) {
//		int P = dfs(i);
//		minP = min(minP, P);
//		maxP = max(maxP, P);
//	}
//	return minP + maxP + 1;
//}

int main(void) {
	LLI X, Y,res = 0;
	cin >> X >> Y;
	while (1) {
		if (X <= Y) {
			X *= 2;
			res++;
		}
		else {
			break;
		}
	}
	cout << res << endl;
}

Measured memory_bytes: 256
import Data.List

main = interact $ unlines . map (show . mazes) . read' . lines
 where
  read' ("0 0":_) = []
  read' (wh:xs) = ((w,h),m) : read' xs'
   where
    [w,h] = map read (words wh)
    (m,xs') = splitAt (2*h-1) xs

mazes ((w,h),m) = bfs (2*(w-1),2*(h-1)) m 1 u [(0,0)]
 where u = tail [(x,y) | x<-[0,2..2*(w-1)], y<-[0,2..2*(h-1)]]

bfs e m s u c 
 | elem e c = s
 | null u || null c = 0
 | otherwise = bfs e m (succ s) (u \\ c') c'
 where
  c' = intersect (nub (concatMap neighbor c)) u
  neighbor (x,y) = map snd (filter movable dir)
   where 
    movable ((wx,wy),(x',y')) = elem (x',y') u && m!!wy!!wx == '0'
    dir = [((x-1,y),(x-2,y)),((x+1,y),(x+2,y)),((x,y-1),(x,y-2)),((x,y+1),(x,y+2))]

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

int main(){
	int n;
	string str;
	stringstream ss;
	while(cin >> n,n){
		cin >> str;
		for(int i = 0;i < n;++i){
			int c = 1,len = str.size();
			ss.str("");
			for(int j = 1;j < len;++j){
				if(str[j - 1] == str[j]) {
					++c;
				}
				else{
					ss << c << str[j - 1];
					c = 1;
				}
			}
//			cout << "b" << ss.str() << "count" << c << endl;
			ss << c << str[len - 1];
//			cout << "a" << ss.str() << endl;
			ss >> str;
			ss.clear();

		}
		cout << str << endl;
	}
	return 0;
}

Measured memory_bytes: 1364
#include <iostream>
    #include <cstdio>
    #include <cstring>
    #include <vector>
    #include <algorithm>
    #include <cmath>
    #include <set>
     
    using namespace std;
     
    #define mp make_pair
    #define pb push_back
    #define ll long long
     
    #define maxN 100011
     
    ll R, C, n, i;
    ll x, y, xx, yy;
    vector< pair<ll, ll> > ord;
    set<ll> S;
     
    bool on_edge(ll x, ll y) {
        if (x == 0 || y == 0) return true;
        if (x == R || y == C) return true;
        return false;
    }
     
    ll get_pos(ll x, ll y) {
        if (y == 0) return x;
        if (x == R) return R + y;
        if (y == C) return R + C + (R - x);
        if (x == 0) return R + C + R + (C - y);
    }
     
    int main()
    {
      //  freopen("test.in","r",stdin);
     
        cin >> R >> C >> n;
        for (i = 1; i <= n; i++) {
            cin >> x >> y >> xx >> yy;
            if (!on_edge(x, y)) continue;
            if (!on_edge(xx, yy)) continue;
     
            ll p1 = get_pos(x, y);
            ll p2 = get_pos(xx, yy);
            if (p2 < p1) swap(p1, p2);
     
            ord.pb(mp(p1, p2));
            ord.pb(mp(p1 + 2LL * (R + C), p2 + 2LL * (R + C)));
            ord.pb(mp(p1 + 4LL * (R + C), p2 + 4LL * (R + C)));
        }
     
     
        sort(ord.begin(), ord.end());
        for (auto e : ord) {
            auto it = S.lower_bound(e.first + 1);
            if (it != S.end()) {
                if (*it < e.second) {
                    printf("NO");
                    return 0;
                }
            }
            S.insert(e.second);
        }
     
        printf("YES");
     
     
     
        return 0;
    }

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

int h , w , k ;

const int mod = 1e9 + 7 ;
int memo[105][10] ;

int solve(int height , int pos){

    if(height == 0) return pos == k ;

    int &ret = memo[height][pos] ;
    if(ret != -1) return ret ;

    ret = 0 ;
    for(int i = 0 ; i < (1 << (w - 1)) ; i++){
          vector < int > temp ;
          for(int j = 0  ; j < w - 1 ; j++)
               if(i & (1 << j)) temp.push_back(j) ;

          bool flag = false ;
          for(int j = 1 ; j < temp.size() ; j++)
               if(temp[j - 1] + 1 == temp[j]) flag = true ;

          if(flag) continue ;

          int cur = pos ;
          for(int j = 0 ; j < temp.size() ; j++){
                if(temp[j] == cur){
                       cur ++ ;
                       break;
                }
                if(temp[j] + 1 == cur){
                      cur -- ;
                      break ;
                }
          }
          ret += solve(height - 1 , cur);
          ret %= mod ;
    }

    return ret ;
}

int main(){

    ios::sync_with_stdio(false) , cin.tie(0) , cout.tie(0) ;

    cin >> h >> w >> k ;
    k-- ;
    memset(memo , -1 , sizeof memo) ;
    cout << solve(h , 0) << endl ;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t a,b,c,d;
    cin >> a >> b >> c >> d;
    if(abs(c-a)<=d || (abs(c-b) <= d && abs(b-a) <= d)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
/* -----------------------------------------------------------------------------
	AIZU ONLINE JUDGE
	JOI 2010/11本選問2 0561 Books
	DP
	
    g++ joifin1102.cpp

7 4
14 1
13 2
12 3
14 2
8 2
16 3
11 2

考察と出力．
	(15)
	(15)14
14	(14)(16) 7
------------------------------------------------------------------------------*/
#include <cstdio>
#include <algorithm> // sort, max, min

using namespace std;

#define MAX_N 	2001
#define MAX_GL	11

int N;		// 2 ≦ N ≦ 2000	あなたが持っている本の冊数
int K;		// 1 ≦ K < N    	JOI 古本店に売る本の冊数
int price[MAX_GL][MAX_N];	// 基準価格
int acc[MAX_GL][MAX_N];		// 基準価格(累積)
int cnt[MAX_GL] = {0} ;		// ジャンルごとの冊数
int dp[MAX_GL][MAX_N];		// DP Table

int main() {

	int g, c;

	// 読込み
	scanf("%d%d", &N, &K);
	// 基準価格の読み込み
	for(int i = 0; i < N; i++) {
		scanf("%d%d", &c, &g);
		price[g-1][cnt[g-1]++] = c;	// 値段
	}

	// 降順ソート
	for(int g = 0; g < MAX_GL; g++) {
		sort(price[g], price[g] + cnt[g]);
		reverse(price[g], price[g] + cnt[g]);
	}

	// 上乗せ金額込みの累積和 acc
	for(int g = 0; g < MAX_GL; g++) {
		acc[g][0] = 0; 
		for(int i = 1; i <= cnt[g]; i++)
			acc[g][i] = acc[g][i-1] + price[g][i-1] + 2 * (i - 1);
	}

	// DP(初期化，g=0)
	for(int i = 0; i <= K; i++) { 
		if(0 < i && i <= cnt[0]) dp[0][i] = acc[0][i];
		else dp[0][i] = 0;
	};

	// DP(過程; g>0)
	for(int g = 1; g <= MAX_GL; g++) {
		for(int i = 0; i <= K; i++) {
			dp[g][i] = 0;
			for(int j = 0; j <= min(i, cnt[g]); j++) {
					dp[g][i] = max(dp[g][i], dp[g-1][i-j] + acc[g][j]);
			}
		}
	}

	// 最大値出力
	printf("%d\n", dp[MAX_GL][K]);

	return 0;
}



Measured memory_bytes: 2968
size,K = map(int, raw_input().split())
S = raw_input()
flag = 0
a = []
temp1 = []
temp2 = []
n = 0
for c in S:
	if(flag == 0):
		if(c == '1'):
			temp1.append(n)
			flag = 1
	else:
		if(c == '0'):
			flag = 0
			temp2.append(n)
	n += 1
n = 0
if(K <= len(temp2)):
	a.append(temp2[K-1])
	for i in temp1:
		if(n + K < len(temp2)):
			a.append(temp2[n + K] - i)
		else:
			a.append(size - i)
		n += 1
else:
	a.append(size)
print(max(a))

Measured memory_bytes: 7556
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;

int n, k, ans, a[1005];
int main() {
	int i;
	cin >> n >> k;
	for(i=0; i<n; i++) cin >> a[i];
	sort(a, a+n);
	for(i=0; i<k; i++) ans += a[i];
	cout << ans;
	return 0;
}


Measured memory_bytes: 3608
"Train Ticket"
# numbers = list(map(int, list(str(input()))))
#
# print(numbers)

numbers = list(input())

# '+' or '-'を挿入する箇所は桁数-1

for mask in range(1 << (len(numbers)-1)):
    fomula = ""
    for i in range(len(numbers)):
        if (mask >> i) & 1:  # 1のビットが立つなら
            fomula += numbers[i] + "+"
        else:
            fomula += numbers[i] + "-"

    # print(fomula[:-1])

    if eval(fomula[:-1]) == 7:
        print(fomula[:-1]+"="+"7")
        break


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

int main() {
	int h, w;
	while (cin >> h >> w, h) {
		rep(i, h) {
			rep(j, w) {
				if ((i + j) & 1)cout << ".";
				else cout << '#';
			}
			cout << endl;
		}
		cout << endl;
	}
}

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

int cnt[100010];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    int ans = 1;
    int A[100010];
    rep(i, N) cin >> A[i];
    rep(i, N) {
        if (A[i] == 0) ans = (ans * (3 - cnt[A[i]])) % mod;
        else ans = (ans * (cnt[A[i] - 1] - cnt[A[i]])) % mod;
        cnt[A[i]]++;
    }
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 1792
from copy import deepcopy
n = int(input())
a = []
for _ in range(n):
    a.append(int(input()))
b = deepcopy(a)

first_max = max(b)
b.remove(first_max)
second_max = max(b)

for x in a:
    if x == first_max:
        print(second_max)
    else:
        print(first_max)


Measured memory_bytes: 18724
import java.util.Scanner;

public class Main {
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);

    int N = sc.nextInt();
    int[] A = new int[N];

    double invalid = 0d;
    for(int i = 0; i < N; i++) {
      invalid += 1d / sc.nextInt();
    }

    double ans = 1d / invalid;


    System.out.println(ans);
  }
}


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

int main(){
int a,count,countb,counta,countsum;
cin>>a;
  count=0;
  counta=0;
  countb=0;
  countsum=0;
 string b;
  for(int i=0;i<a;i++){
    cin>>b;
    for(int j=0;j<b.size();j++){
      if(j!=b.size()-1){
      if(b[j]=='A'&&b[j+1]=='B'){
        count++;
      }
      }
      
    }
    if(b[b.size()-1]!='A'&&b[0]=='B'){
        countb++;
      }
     else if(b[b.size()-1]=='A'&&b[0]!='B'){
        counta++;
      }
    else if(b[b.size()-1]=='A'&&b[0]=='B'){
        countsum++;
      }
  }
    if(counta+countb==0){
    if(countsum!=0){
      cout<<count+countsum-1<<endl;
    }
  else{
  cout<<count<<endl;
  }
    }
  else{
 
  cout<<count+min(countb,counta)+countsum<<endl;
}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int gcd(int a,int b){return b%a ? gcd(b%a,a) : a;}
int main(){
    int N;
    cin>>N;
    int a,b,c;
    cin>>a>>b;
    if(N==3) cin>>c;
    int tmp=gcd(a,b);
    if(N==3) tmp=gcd(tmp,c);
    for(int i=1;i<=tmp;i++){
        if(tmp%i==0) cout<<i<<endl;
    }
    return 0;
}



Measured memory_bytes: 3068
// clang-format

#include <bits/stdc++.h>
#define rep(i, n) for (lli i = 0; i < (n); i++)
#define rrep(i, n) for (lli i = (n)-1; i >= 0; i--)
using namespace std;

using lli = long long int;
int sim(int cur, long long N, long long Q, std::string s, std::vector<char> t,
           std::vector<char> d) {
  rep(i, Q){
    if(s[cur]==t[i]){
      if(d[i]=='L')cur--;
      else cur++;
    }
    if(cur==-1) return 1;
    else if(cur==N)return 2;
  }
  return 0;
}

void solve(long long N, long long Q, std::string s, std::vector<char> t,
           std::vector<char> d) {
  lli left = -1, right = N;
  while(right-left>1){
    lli mid = (left+right)/2;
    lli p = sim(mid, N, Q, s, t, d);
    if(p==1){
      left = mid;
    }else {
      right = mid;
    }
  }
  if(left==N-1){
    cout << 0 << endl;
    return;
  }
  lli tmp_l = right;
  left = -1, right = N;
  while(right-left>1){
    lli mid = (left+right)/2;
    lli p = sim(mid, N, Q, s, t, d);
    if(p==2){
      right = mid;
    }else {
      left = mid;
    }
  }
  lli tmp_r = left;
  if(right==0){
    cout << 0 << endl;
    return;
  }

  cout << tmp_r - tmp_l +1 << endl;

}


int main() {
  int a;
  long long N;
  scanf("%lld", &N);
  long long Q;
  scanf("%lld", &Q);
  std::string s;
  std::cin >> s;
  std::vector<char> t(Q);
  std::vector<char> d(Q);
  for (int i = 0; i < Q; i++) {
    std::cin >> t[i];
    std::cin >> d[i];
  }
  solve(N, Q, s, std::move(t), std::move(d));
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vector<int>> vvi;
typedef vector<string> vs;
typedef unordered_set<int> si;
typedef pair<int, int> pp;
typedef vector<pp> vpp;
typedef unsigned int i64;

#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#define all(e) (e).begin(), (e).end()
#define pb push_back

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

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


template <typename T>
void printV(vector<T> A) {
  if (A.empty()) cerr << "EMTPY\n";
  else { 
    cerr << "[";
    for (int i = 0; i < A.size() -1 ; ++i) {
      cerr << A[i] << ", ";
    }
    if (A.size()) cerr << A.back() << "]\n";
  }
}


template <typename T>
void printVV(vector<vector<T>> A) {
  cerr << "[";
  for (auto v : A) {
    printV<T>(v);
  }
  cerr << "]";
}

template <typename Arg1>
void __f(const char* name, Arg1&& arg1) {
  cerr << name << ": " << arg1 << endl;
}

template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&& ...args) {
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}

int main(int argc, char **argv) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n; cin >> n;
  for (int i = 0; i < 10; ++i) {
    for (int j = 0; j < 10; ++j) {
      if (i * j == n) {
        cout << "Yes\n";
        return 0;
      }
    }
  }
  cout << "No\n";
  return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<=(int)(n);i++)
#define all(c) c.begin(),c.end()
#define pb push_back
#define fs first
#define sc second
#define show(x) cout << #x << " = " << (x) << endl
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
using namespace std;
template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){return o<<"("<<p.fs<<","<<p.sc<<")";}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){o<<"sz = "<<vc.size()<<endl<<"[";for(const T& v:vc) o<<v<<",";o<<"]";return o;}
bool B(int x,int i){return (x>>i)&1;}
int H,W;
string s[12];

void solve(vector<int> p){
	vector<bool> dp(1<<H);
	dp[0] = 1;

	vector<vector<bool>> ok(H,vector<bool>(H));
	rep(i,H) rep(j,H){
		bool can = 1;
		rep(k,W) if(s[i][k] != s[j][p[k]]) can = 0;
		ok[i][j] = can;
	}

	rep(b,1<<H) if(dp[b]){
		if(b==0 && H%2==1){
			rep(i,H){
				if(ok[i][i]) dp[1<<i] = 1;
			}
			continue;
		}
		rep(i,H) if(!B(b,i)){
			rep(j,i) if(!B(b,j)){
				if(ok[i][j]) dp[b|(1<<i)|(1<<j)] = 1;
			}
		}
	}
	if(dp[(1<<H)-1]){
		puts("YES");
		exit(0);
	}
}

void dfs(vector<int> p){
	vector<int> left;
	rep(i,W) if(p[i]==-1) left.pb(i);

	if((int)left.size() == W && W%2 == 1){
		rep(i,W){
			p[i] = i;
			dfs(p);
			p[i] = -1;
		}
		return;
	}
	if((int)left.size() == 0){
		solve(p);
		return;
	}
	int x = left[0];
	int K = left.size();
	rep1(i,K-1){
		int y = left[i];
		p[x] = y;
		p[y] = x;
		dfs(p);
		p[x] = p[y] = -1;
	}
}

int main(){
	cin>>H>>W;
	rep(i,H) cin>>s[i];
	vector<int> p(W,-1);
	dfs(p);
	puts("NO");
}


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

using namespace std;

#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define endl "\n"
#define fff ff
#define sss ss.ff
#define ttt ss.ss
#define INF (1 << 30)
#define LLF (1ll << 60)
#define PRIME (1000000007)
#define FASTIO std::ios::sync_with_stdio(false)
#ifdef DEBUG
#define debug(x) cerr << #x << " = " << x << endl
#else
#define debug(x)
#endif
#define rep(i, begin, end)                            \
  for (__typeof(end) i = (begin) - ((begin) > (end)); \
       i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define FILE_INPUT                  \
  freopen("input.txt", "r", stdin); \
  freopen("output.txt", "w", stdout)

#define all(x) x.begin(), x.end()

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vi;
typedef pair<ll, ll> ii;
typedef pair<ll, ii> iii;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<string> vs;

/*-----------------END TEMPLATE-----------------*/

ll fast_exp(ll b, ll e) {
  ll res = 1;
  while (e > 0) {
    if (e & 1) res = (res * b) % PRIME;
    e = e >> 1;
    b = (b * b) % PRIME;
  }
  return res;
}

int main() {
  FASTIO;
  ll n, k;
  cin >> n >> k;
  vi a(n), is(n), more(n);
  rep(i, 0, n) { cin >> a[i]; }

  for (int i = 0; i < n; i++) {
    is[i] = 0;
    more[i] = 0;
    for (int j = i - 1; j >= 0; j--) {
      if (a[j] > a[i]) is[i]++;
    }
    for (int j = 0; j < n; j++) {
      if (a[j] > a[i]) more[i]++;
    }
  }

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ll a1 = is[i];
    ll an = (a1 + ((k - 1) * more[i]) % PRIME) % PRIME;
    ll sn = ((k * (a1 + an))) % PRIME;
    ans = (ans + sn) % PRIME;
  }
  cout << (ans * fast_exp(2, PRIME - 2)) % PRIME << endl;
}


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

int main(int argc, char const *argv[]) {
  int N;
  cin >> N;
  int* T;
  int totalTime = 0;
  T = (int*)malloc(sizeof(int)*N);
  for(int i=0; i<N; i++){
    cin >> T[i];
    totalTime += T[i];
  }

  int M;
  cin >> M;
  int P;
  int X;
  // int* ansArray;
  // ansArray = (int*)malloc(sizeof(int)*M);
  for (int i=0; i<M; i++) {
    cin >> P >> X;
    cout << totalTime - T[P-1] + X << endl;
    // ansArray[i] =
  }
  return 0;
}


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

int n;
int m;
char buf[100000];
set<string> ids;

int main() {
  scanf("%d", &n);
  for (int i=0; i<n; i++) {
    scanf(" %s", buf);
    ids.insert(buf);
  }

  scanf("%d", &m);

  bool opened = false;
  for (int i=0; i<m; i++) {
    scanf(" %s", buf);
    if (ids.count(buf)) {
      opened ^= 1;
      if (opened) printf("Opened by %s\n", buf);
      else printf("Closed by %s\n", buf);
    } else printf("Unknown %s\n", buf);
  }
}

Measured memory_bytes: 3344
#include<bits/stdc++.h>
using namespace std;
const long long M=1e9+7;
int a[2010]; 
long long n, k;
long long ans;
long long js(long long k)
{
	if (k==0) return 0; 
	return ((((1+k)%M)*(k%M))/2)%M;
}
int main()
{	
	while (cin>>n>>k)
	{
		memset(a,0,sizeof(a));
		for (int i=0;i<n;i++)
			cin>>a[i];
		long long  sum=0,sum2=0;
		for (int i=0;i<n;i++)
		{
			for (int j=i+1;j<n;j++)
			{
				if (a[i]>a[j])
				{
					sum++;
				}
				else if (a[j]>a[i])
				{
					sum2++;
				}
									
			}	
		}
		ans=((sum*js(k))%M+(sum2*js(k-1))%M);
		cout<<(ans%M)<<endl;	
	}
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = []
for i in range(2):
    a.append(list(map(int, input().split())))

l = []

for i in range(1,n):
    l.append(sum(a[0][:i]) + sum(a[1][i-1:]))

if len(l) == 0:
    print(a[0][0] + a[1][0])
    exit()
print(max(l))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <iostream>
using namespace std;
 
int main() {
  int N, M, AC = 0, WA = 0;
  cin >> N >> M ;
  int A[N] ;
  int B[N] ;
  for(int i=0;i<N;i++) A[i] = 0 ;
  for(int i=0;i<N;i++) B[i] = 0 ;
  int Pro[M] ;
  string Res[M] ;
  for(int i=0;i<M;i++){
    cin >> Pro[i] >> Res[i] ;
    if(Res[i] == "AC") A[Pro[i]-1] = 1 ;
    else if(A[Pro[i]-1] == 0) B[Pro[i]-1]++ ;
  }  
  for(int i=0;i<N;i++){
    if(A[i] == 1){
      AC++ ;
      WA += B[i] ;
    }  
  }  
  cout << AC << " " << WA << endl;
  return 0;
}

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

int main() {
	int A, B, K, count = 0, C[100];
	cin >> A >> B >> K;
	for (int i = 1; i <= min(A, B); i++) {
		if (A % i == 0 && B % i == 0) {
			C[count] = i;
			count++;
		}
	}
	cout << C[count - K] << endl;
}

Measured memory_bytes: 256