akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include<queue>
#include<set>
using namespace std;

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

  if (a % 500 <= b)
  {
    cout << "Yes" << endl;
  }
  else
  {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if((a+b) > (c+d)){
    cout << "Left" << endl;
  } else if((a+b) < (c+d)) {
    cout << "Right" << endl;
  } else {
	cout << "Balanced" << endl;
  }
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define int ll
using pint = pair<int,int>;
using Graph = vector<vector<int>>;
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 1e10; //10^10
const double PI = acos(-1.0L);
/*mod逆元*/long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}
template< typename T >T mod_pow(T x, T n, T p=MOD) {T ret = 1;while(n > 0) {if(n & 1) (ret *= x) %= p;(x *= x) %= p;n >>= 1;}return ret;}
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}

//----------------ライブラリとか----------------

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<fixed<<setprecision(15);

    int n; cin >> n;
    string s,t; cin >> s >> t;
    REP(i,n)if(s.substr(i)==t.substr(0,n-i)){ out(i+n); return 0; } //sのi番目以降==tのn-i番目まで
    out((s+t).size());

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn=1e5+5;
int main()
{
    int a,b,c;
    scanf("%d%d%d",&a,&b,&c);
    int d=(b+c)-a;
    printf("%d %d\n",min(b,c),d<0?0:d);
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<cstdio>
#include<climits>
#include<cmath>
#include<cstring>
#include<string>
#include<complex>
#include<map>

#define f first
#define s second
#define mp make_pair

#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define FOR(i,c) for(__typeof((c).begin()) i=(c).begin(); i!=(c).end(); i++)
#define ALL(c) (c).begin(), (c).end()
#define EPS (1e-10)
using namespace std;

typedef unsigned int uint;
typedef long long ll;
typedef complex<double> P;

const char *name[] = {
  "null",
  "one pair",
  "two pair",
  "three card",
  "straight",
  "full house",
  "four card"
};

int main(){
  int c[5];
  while(~scanf("%d,%d,%d,%d,%d",c,c+1,c+2,c+3,c+4)){
    int cnt[14] = {0};
    int yaku = 0;
    int cnt2[5] = {0};
    sort(c, c+5);
    REP(i,5) cnt[c[i]]++;
    REP(i,14) cnt2[cnt[i]]++;
    if(cnt2[2] == 1) yaku = 1;
    if(cnt2[2] == 2) yaku = 2;
    if(cnt2[3] == 1) yaku = 3;
    if(c[1]==c[0]+1&&
       c[2]==c[1]+1&&
       c[3]==c[2]+1&&
       c[4]==c[3]+1)
      yaku = 4;
    if(c[0]==1  &&
       c[1]==10 &&
       c[2]==11 &&
       c[3]==12 &&
       c[4]==13)
      yaku = 4;
    if(cnt2[2] == 1 && cnt2[3] == 1)
      yaku = 5;
    if(cnt2[4] == 1)
      yaku = 6;
    puts(name[yaku]);
  }
  return 0;
}

Measured memory_bytes: 0
n = gets.to_i
$xs = gets.chomp.split ''

def check(v, i)
  sheep = v[i]
  prev = i - 1
  prev = v.length - 1 if i == 0
  tugi = i + 1
  tugi = 0 if tugi == v.size

  if sheep
    if $xs[i] == 'o'
      return false if v[prev] != v[tugi]
    else
      return false if v[prev] == v[tugi]
    end
  else
    if $xs[i] == 'o'
      return false if v[prev] == v[tugi]
    else
      return false if v[prev] != v[tugi]
    end
  end
  return true
end

[true, false].repeated_permutation(3) { |a, b, c|

  v = [a, b, c]

  next if !check(v, 1)

  for i in 2..(n-2) do
      if v[i]
        if $xs[i] == 'o'
          v << v[i-1]
        else
          v << !v[i-1]
        end
      else
        if $xs[i] == 'o'
          v << !v[i-1]
        else
          v << v[i-1]
        end
      end
  end

  if check(v, 0) and check(v, v.size - 1)
    puts v.map {|b| b ? "S" : "W" }.join ''
    exit
  end
}

p -1


Measured memory_bytes: 13076
package main

import (
  "fmt"
)

func main() {
  var s string 
  fmt.Scan(&s)
  res := make([]byte, 0)
  for i := 0; i < len(s); i += 2 {
    res = append(res, s[i])
  }
  fmt.Println(string(res))
}

Measured memory_bytes: 1536
#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 complex<ld> cd;
 
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;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#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 ins insert
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
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);    
	
    int K; cin >> K;
    int N; cin >> N;
    vi data(N); F0R(i, N) cin >> data[i];
    int ans = 0;
    F0R(i, N-1) ans = max(ans, data[i+1] - data[i]);
    ans = max(ans, data[0] + K - data[N-1]);
    cout << K - ans << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Map = map<string,ll>;

int main(){
	ll N;
	cin >> N;
	vector<ll> A(N+2,0);
	vector<ll> B(N+1,0);
	for(ll i=1;i<=N+1;i++){
		cin>>A[i]
	;}
	for(ll i=1;i<=N;i++){
		cin>>B[i]
	;}
	ll ans=0;
	ll monstersh=A[N+1];
	ll monsters=A[N];
	for(ll i=N;i>=1;i--){
		monsters=A[i];
		ans+=monstersh+monsters-max(0LL,monstersh+monsters-B[i]);
		if(B[i]<monstersh){monstersh=monsters;}
		else if(monstersh<=B[i]&&monsters+monstersh>=B[i]){monstersh=monstersh+monsters-B[i];}
		else monstersh=0;
	;}
	cout<<ans<<endl;

return 0;
}  


Measured memory_bytes: 1792
n = int(input())
lia,lib,lic,lid = [],[],[],[]
count = 0
for i in range(n):
    lib.append(int(input()))
    for j in range(lib[i]):
        lid.append([int(s) for s in input().split()])
    lic.append(lid)
    lid = []
for i in range(2**n):
    b = "0"*(n-len(bin(i))+2)+bin(i)[2:]
    li = [int(b[s]) for s in range(n)]
    f = 1
    for j in range(n):
        for k in range(lib[j]):
            if li[j] == 1:
                if li[lic[j][k][0]-1] != lic[j][k][1]:
                    f = 0
    if f == 1:
        lia.append(li)
        count += 1
for i in range(count):
    lia[i] = sum(lia[i])
print(max(lia))

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

#define LL long long
#define pii pair<LL, LL>
#define mp make_pair

LL N, X, D, ans;

map<LL, vector<pii>> f;

int main()
{
	scanf("%lld %lld %lld", &N, &X, &D);
	if(D == 0)
	{
		if(X) printf("%lld", N + 1);
		else puts("1");
		return 0;
	}
	if(D < 0) X = -X, D = -D;

	for(int k = 0; k <= N; k++)
	{
		LL R = 1ll * k * X % D;
		LL l = 1ll * k * (k - 1) / 2 + 1ll * k * X / D, r = 1ll * (N - k + N - 1) * k / 2 + 1ll * k * X / D;
		f[R].push_back( mp(l, r) );
	}

	for(map<LL, vector<pii>>::iterator it = f.begin(); it != f.end(); it ++)
	{
		vector<pii> num = it -> second;
		sort(num.begin(), num.end());
		LL last = -1e18;
		for(int i = 0; i < num.size(); i++)
		{
			LL l = max(last, num[i].first), r = num[i].second;
			if(l > r) continue;
			ans += r - l + 1;
			last = max(last, num[i].second + 1);
		}
	}

	printf("%lld", ans);
	return 0;
}


Measured memory_bytes: 22144
n=int(input())
A=list(map(int,input().split()))
A.sort()
q=int(input())
m=list(map(int,input().split()))

binary=[0 for i in range(n)]
A_ls=[]

while 0 in binary:
    s=0
    for i in range(n):s+=A[i]*binary[i]
    A_ls.append(s)
    idx = binary.index(0)
    binary[idx]=1
    for i in range(idx):binary[i]=0
        
for j in m:
    if j in A_ls:print('yes')
    else:print('no')


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

#define pb         push_back

typedef long long ll;
const ll INF = 1000000000ll;
const ll MOD = 1000000007ll;
const double EPS = 1e-8;

int main(void) {
	//ios_base::sync_with_stdio(false);
	//cin.tie(0);
	
	int n;
	cin >> n;

	int m = -1;
	for(int i=1; i<n; i++){
		if(i*(i+1)/2 >= n){
			m = i;
			break;
		}
	}

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

	while(m > 0){
		cout << m << endl;
		if(n-m >= m ){
			n -= m;
			m--;
		}else{
			cout << n-m << endl;
			break;
		}
	}


	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <set>
using namespace std;
typedef unsigned long long ull;

ull pow[300010]={};

ull b_pow(ull x,ull b){
	return b ? b_pow(x*x,b/2) * ((x&1)?x:1) : 1;
}

int main(){
	
	pow[0] = 1;
	for(int i = 1 ; i < 300010 ; i++) pow[i] = pow[i-1] * 8999;
	
	
	ull inv = b_pow(8999,18446744073709551614ull);
	ios_base::sync_with_stdio(false);
	int n,m;string s;
	cin >> n >> m;
	cin >> s;
	int l = 0 , r = 1;
	ull hs = s[0];
	set<ull> answer;
	for(int i = 0 ; i < m ; i++){
		string q;
		cin >> q;
		if( q == "L++" ){
			hs -= pow[r-l-1] * s[l];
			l++;
		}else if( q == "R++"){
			hs = hs * 8999 + s[r];
			r++;
		}else if( q == "L--"){
			l--;
			hs += pow[r-l-1] * s[l];
		}else if( q == "R--"){
			r--;
			hs -= s[r];
			hs = inv * hs;
		}
		answer.insert(hs);
	}
	cout << answer.size() << endl;
}

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

int main() {
  int N,x;
  cin >> N >> x;
  vector<int> sc(N);
  long answer = 0;
  for (int i=0; i<N; i++) {
    cin >> sc[i];
  }
  for (int i=0; i<N; i++) {
    if (sc[i] > x) {
      answer += sc[i] - x;
      sc[i] = x;
    }
  }
  vector<int> scp(N);
  for (int i=0; i<N-1; i++) {
    scp[i] = sc[i] + sc[i+1];
  }
  scp[N-1] = 0;
  for (int i=0; i<N-1; i++) {
    if (scp[i] > x) {
      answer += scp[i] - x;
      scp[i+1] -= scp[i] - x;
    }
  }
  cout << answer << endl;
}

Measured memory_bytes: 1024
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#pragma warning( disable:4996 )
#define SWAP(a,b) (a += b,b = a - b,a -= b)
#define MIN(a, b) ((a) < (b) ? (a) : (b))


int main(void) {
	/*int n, k;
	char s[51];
	scanf("%d %d", &n, &k);
	scanf("%s", s);
	s[k-1] += 'a' - 'A';
	printf("%s", s);*/

	char s[5];
	scanf("%s", s);
	for (int i = 0; i < 4; i++) {
		s[i] -= '0';
	}
	int p0 = 0;
	int p1 = 0;
	if ((s[0] == 1 && s[1]<=2) || (s[0]==0 && s[1]>0)) {
		p1 = 1;
	}
	if ((s[2] == 1 && s[3]<=2) || (s[2] == 0 && s[3] > 0)) {
		p0 = 1;
	}
	if (p0) {
		if (p1) {
			printf("AMBIGUOUS\n");
		}
		else {
			printf("YYMM\n");
		}
	}
	else {
		if (p1) {
			printf("MMYY\n");
		}
		else {
			printf("NA\n");
		}
	}
	return 0;
}

Measured memory_bytes: 128
H,W,K = map(int,input().split())
nums = list( list(input()) for i in range(H))
ans = 0
for i in range(2**H):
  for j in range(2**W):
    c = 0
    for x in range(H):
      for y in range(W):
        if(i>>x & 1) == 0 and (j >> y & 1) == 0:
          if nums[x][y] == "#":
            c += 1
    if c == K:
      ans += 1
print(ans) 

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

int main(){
  int n,m;
  cin>>n;
  map<int,int> d;
  rep(i,n){
    int D;cin>>D;
    d[D]++;
  }
  cin>>m;
  bool ans=1;
  rep(i,m){
    int T;cin>>T;
    if(d[T]>0)d[T]--;
    else ans=0;
  }
  if(ans)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

}



Measured memory_bytes: 12960
#include <bits/stdc++.h>
#include <iomanip>
#include <math.h>
#define rep(i,x) for(ll i = 0;i<x;i++)
#define all(a) (a).begin(),(a).end()
using ll = long long;
using ld = long double;
using namespace std;
const ll INF = 1001001001;
const ll mod = 1000000007;
typedef pair<ll,ll> P;
using graph = vector<vector<ll>>;
ll gcd(ll a,ll b){
    if(a < b)swap(a,b);
    if(a % b == 0)return b;
    else return gcd(b,a%b);
}
bool isp(ll n){
    bool res = true;
    if(n == 1)return false;
    else{
        for(ll i = 2;i * i <= n;i++){
            if(n % i == 0){
                res = false;
                break;
            }
        }
        return res;
    }
}
//printf("%.10f\n", N);
/*
ll memo[100000];
ll fibo(ll n){
    if(memo[n] != 0)return memo[n];
    if(n <= 1)return n;
    else return memo[n] = fibo(n - 1)+ fibo(n - 2);
}*/
int main() {
    ll K;
    string S;
    cin >> S >> K;
    ll s = S.size();
    ll one = 0;
    ll noone = 0;
    rep(i,s){
        if(S[i] == '1')one++;
        else{
            noone = S[i] - '0';
            break;
        }
    }
    if(K > one){
        cout << noone << endl;
    }
    else cout << 1 << endl;
}

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

typedef long long ll;
ll n, c;
int main()
{
    cin >> n;
    if (n % 2) {puts("0"); return 0;}
    n /= 2;
    while (n) {
        n /= 5;
        c += n;
    }
    cout << c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main()
{
	long long n,x;
	cin >> n >> x;
	long long a[2005];
	long long ans=0;
	for(int i=1;i<=n;i++)
	{
		cin >> a[i-1];
		ans+=a[i-1];
	}
	long long mini[2005];

	for(int i=1;i<=n;i++)
	{
		long long tmp=x*i;
		if(i==1)
			for(int j=1;j<=n;j++)
			{
				mini[j-1]=min(a[j-1],a[(j+1-1)%n]);
				tmp+=mini[j-1];
			}
		if(i>=2)
			for(int j=1;j<=n;j++)
			{
				mini[j-1]=min(mini[j-1],a[(j+i-1)%n]);
				tmp+=mini[j-1];
			}
		ans=min(ans,tmp);
	}

	cout << ans << endl;
}
				

Measured memory_bytes: 384
#include <stdio.h>
#define MAX 250

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

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

  for(i=1;i<=h;i++){
    printf("node %d: key = %d, ",i,A[i]);
    if(i/2>=1) printf("parent key = %d, ",A[i/2]);
    if(2*i<=h) printf("left key = %d, ",A[2*i]);
    if(2*i+1<=h) printf("right key = %d, ",A[2*i+1]);
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2104
#include<iostream>

using namespace std;

int main(){
    int h,w;
    cin >> h >> w;

    char a[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++)cin >> a[i][j];
    }

    for(int i=0;i<w+2;i++)cout << "#";
    cout << endl;
    for(int i=0;i<h;i++){
        cout <<"#";
        for(int j=0;j<w;j++){
            cout << a[i][j];
        }
        cout << "#" << endl;
    }

    for(int i=0;i<w+2;i++)cout << "#";
    cout << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>

using namespace std;

int main(void){
  int n, k;
  cin >> n >> k;
  int minpos;
  for(int i = 0; i < n; ++i){
    int tmp;
    cin >> tmp;
    if (tmp == 1)
      minpos = i;
  }
  int left = minpos;
  int leftnum, leftright;
  if (left == 0){
    leftnum = 0;
    leftright = 0;
  }else{
    leftnum = (left + k - 3) / (k-1);
    leftright = leftnum * (k - 1);
  }
  int right = n - leftright;
  int rightnum = 0;
  if (right > 0){
    rightnum = (right + k - 3) / (k-1);
  }
  cout << (leftnum + rightnum) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<bits/stdc++.h>
#include<vector>
#include<string>
#define ll long long
#define IOS ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define vi vector<ll>
#define el printf("\n")
ll MAX=9223372036854775807;
using namespace std;
int main()
{   IOS;
    ll n;
    cin >> n;
    string ch;
    cin >> ch;
    if(n%2==1)
        cout << "No";
    else
    {
        for(int i=0;i<n/2;i++)
        {
            if(ch[i]!=ch[n/2+i])
                return cout << "No",0;
        }
        cout << "Yes";
    }

    return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
long long INF = 1e18;
const int mod = 1e9 + 7;

using namespace std;

int main(){
    int n,a,min=mod,d=0,cnt=0;
    scanf("%d%*d",&n);
    REP(i,n){
        scanf("%d",&a);
        if(min>a){
            min = a;
        }else if(d==a-min){
            ++cnt;
        }else if(d<a-min){
            d = a - min;
            cnt=1;
        }
    }
    printf("%d\n",cnt);
    return 0;
}


Measured memory_bytes: 256
def ri(): return int(input())
def rli(): return list(map(int, input().split()))
def rls(): return list(input())
def pli(a): return "".join(list(map(str, a)))

n, m = rli()
student = [[] for i in range(n)]
ans = [[-1,1145148101919] for i in range(n)]
for i in range(n):
    student[i] = rli()
for i in range(m):
    x, y = rli()
    for j in range(n):
        if(abs(x-student[j][0]) + abs(y-student[j][1]) < ans[j][1]):
            ans[j] = [i, abs(x-student[j][0]) + abs(y-student[j][1])]
for i in range(n):
    print(ans[i][0] + 1)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define Rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define Repe(i,a,b) for(register int i=(a);i>=(b);--i)
#define pb push_back
#define mp make_pair
#define Chkmax(a,b) a=a>b?a:b
#define Chkmin(a,b) a=a<b?a:b
typedef unsigned long long uint64;
typedef unsigned int uint32;
typedef long long ll;

using namespace std;

namespace IO
{
    const uint32 Buffsize=1<<15,Output=1<<23;
    static char Ch[Buffsize],*S=Ch,*T=Ch;
    inline char getc()
    {
        return((S==T)&&(T=(S=Ch)+fread(Ch,1,Buffsize,stdin),S==T)?0:*S++);
    }
    static char Out[Output],*nowps=Out;
    
    inline void flush(){fwrite(Out,1,nowps-Out,stdout);nowps=Out;}

    template<typename T>inline void read(T&x)
    {
        x=0;static char ch;T f=1;
        for(ch=getc();!isdigit(ch);ch=getc())if(ch=='-')f=-1;
        for(;isdigit(ch);ch=getc())x=x*10+(ch^48);
        x*=f;
    }

    template<typename T>inline void write(T x,char ch='\n')
    {
        if(!x)*nowps++='0';
        if(x<0)*nowps++='-',x=-x;
        static uint32 sta[111],tp;
        for(tp=0;x;x/=10)sta[++tp]=x%10;
        for(;tp;*nowps++=sta[tp--]^48);
        *nowps++=ch;
    }
}
using namespace IO;

inline void file()
{
#ifndef ONLINE_JUDGE
    FILE*DSA=freopen("water.in","r",stdin);
    FILE*SDU=freopen("water.out","w",stdout);
#endif
}

const int MAXN=1e5+7;

static int n;

vector<int>ed[MAXN],to[MAXN];

static char s[MAXN];

void getstr(char*q)
{
	register char ch;
	for(ch=getc();!isupper(ch);ch=getc());
	for(;isupper(ch);ch=getc())*q++=ch;
}

void init()
{
	read(n);
	static int u,v;
	Rep(i,1,n-1)read(u),read(v),to[u].pb(v),to[v].pb(u);
	getstr(s+1);
}

static int fa[MAXN];

static int ans;

bool getfa(int u)
{
	if(fa[u]&&to[u].size()==1)return s[u]=='W';
	bool flg=(s[u]=='W');
	for(register int v:to[u])if(v^fa[u])
	{
		fa[v]=u;
		if(getfa(v))flg=1,ed[v].pb(u),ed[u].pb(v),ans+=2;
	}
	return flg;
}

static int mxw;

static int dp[MAXN][2];

void getdp(int u)
{
	if(ed[u].size()&1)s[u]=(s[u]=='B'?'W':'B');
	if(s[u]=='W')++ans;
	for(register int v:ed[u])if(v^fa[u])
	{
		getdp(v);
		if(dp[v][0]>dp[u][0])dp[u][1]=dp[u][0],dp[u][0]=dp[v][0];
		else if(dp[v][0]>dp[u][1])dp[u][1]=dp[v][0];
	}
	dp[u][0]+=s[u]=='W';
	Chkmax(mxw,dp[u][0]+dp[u][1]);
}

inline void solve()
{
	static int flg=0;
	Rep(i,1,n)if(s[i]=='W')++flg;
	if(flg<=1)return(void)puts(flg?"1":"0");
	if(n==2)return(void)puts("2");
	Rep(i,1,n)if(s[i]=='W')flg=i;
	getfa(flg);
	getdp(flg);
	printf("%d\n",ans-2*mxw);
}

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


Measured memory_bytes: 18688
/* Read input from STDIN. Print your output to STDOUT*/
#include <bits/stdc++.h>
#define ll long long

using namespace std;



ll calc(string s){
    if(s.size() == 1){
        ll c = s[0]-'0';
        return c/2;
    }
    ll val = 0;
    ll ans = 4LL;
    if(s.size() > 2){
      ll prod = 10LL*(pow(10LL, s.size()-2)-1LL)/9LL;
      ans *= prod;
    }
    for(int i = 0; i < s.size()-1; i++){
        ll c = s[i] - '0';
        c = 9LL-c;
        c /= 2LL;
        ll prod = 10LL*(pow(10LL, i)-1LL)/9LL;
        val -= c*prod;
    }
    ll c = s[s.size()-1] - '0';
    c /= 2LL;
    ll prod = 10LL*(pow(10LL, s.size()-1)-1LL)/9LL;
    val += c*prod;
    cout << ans << " " << val << endl;
    if(c > 1) ans += val;
    return ans;
}

int main()
{
    int n;
    cin >> n;
    string a, b;
    cin >> a >> b;
    string s;
    for(int i = 0; i < n; i++){
        s += a[i]; s += b[i];
    }
    cout << s;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector>
#define rep(i,n) for(int i = 0; i < n; i++)
using ll = long long;
using namespace std;
// O(log N)　keyのある場所を返す。なかったら-1を返す
int search(int key, vector<int> a){
  int right = a.size();
  int left = 0;
  while(right >= left){
    int middle = left + (right - left) / 2;
    if(a[middle] == key) return middle; //keyが入ってる場所を返す
    else if(a[middle] > key) right = middle - 1;
    else if(a[middle] < key) left = middle + 1;
  }
  //なければ-1を返す
  return -1;
}
// O(N^2) babble sort
int main(){
  int n;
  cin >> n;
  if(n == 1){
    cout << 1 << endl;
    return 0;
  }
  ll before = 2;
  ll current = 1;
  for(int i = 0; i < n - 1; i++){
    ll temp = current;
    current += before;
    before = temp;
  }
  cout << current << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

int main()
{
    boost;
    ll n,i,j,x,t,y,k;
    cin>>n>>k;
    x=1;
    ll ans=0;
    while(x<=n) {
        x*=k;
        ans++;
    }
    cout<<ans;
}

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

int main(){
    stack<int> state; //this stroes the index of '\\'
    stack<pair<int, int> >lake; //this stroes the info about pits
    int sum=0, s=0;
    char c;
    for(int i=0;cin >> c; i++){ // i is the index in the input
        if(c=='\\'){
            state.push(i); //storing the index of '\\'
        }else if(c=='/' && state.size()){ //state.size() makes sure that the useless starting bit is not counted 
            s = i-state.top(); // storing the currently added area
            sum += s; // storing the total area
            while(lake.size() && lake.top().first > state.top()){ //combining the small pits
                s += lake.top().second;
                lake.pop();
            }
            lake.push(make_pair(state.top(), s));
            state.pop();
        }
        
    }
    stack<int> ans; //using this to revert the lake stack
    while(lake.size()){
        ans.push(lake.top().second);
        lake.pop();
    }
    
    //printing the output
    cout << sum << endl;
    cout << ans.size();
    while(ans.size()){
        cout << " " << ans.top();
        ans.pop();
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3184
{-# LANGUAGE BangPatterns #-}
import           Control.Exception (assert, evaluate)

main :: IO ()
main = do
  n <- readLn
  s <- getLine
  evaluate $ assert (length s == n) ()
  q <- readLn
  ks <- take q . map read . words <$> getLine
  putStr . unlines . map (show . (\k -> f k s)) $ ks

f :: Int -> String -> Int
f k = dmc . foldl g initialState . defer k
  where
    g state (c, c') = (countIn c (maybe id countOut c' state))

-- Strict にしないと TLE がでる
data State =
  State
  { d   :: !Int
  , m   :: !Int
  , dm  :: !Int
  , dmc :: !Int
  }

defer :: Int -> [a] -> [(a, Maybe a)]
defer n xs = zip xs $ replicate n Nothing ++ map Just xs

initialState :: State
initialState = State { d = 0, m = 0, dm = 0, dmc = 0 }

countIn :: Char -> State -> State
countIn 'D' count = count { d = d count + 1 }
countIn 'M' count = count { m = m count + 1, dm = dm count + d count }
countIn 'C' count = count { dmc = dmc count + dm count }
countIn _   count = count

countOut :: Char -> State -> State
countOut 'D' count = count { d = d count - 1, dm = dm count - m count }
countOut 'M' count = count { m = m count - 1 }
countOut _   count = count


Measured memory_bytes: 147836
#pragma comment (linker, "/STACK:526000000")
#define  _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
	iostream::sync_with_stdio(false);
	cout << fixed << setprecision(100);
}

#define int ll
ll inv(ll now) {
	ll ans = 1;
	ll cnt = MAX_MOD - 2LL;
	while (cnt != 0) {
		if (cnt % 2) {
			ans *= now;
			ans %= MAX_MOD;
		}
		now *= now;
		now %= MAX_MOD;
		cnt /= 2LL;
	}
	return ans;
}

ll memo[3000000];
ll gyaku[3000000];
ll comb(int a, int b) {
	ll ans = memo[a];
	ans *= gyaku[b];
	ans %= MAX_MOD;
	ans *= gyaku[a - b];
	ans %= MAX_MOD;
	return ans;
}

ll valid(ll a) {
	if (a >= 0) return a;
	a += (llabs(a) / MAX_MOD + 1LL) * MAX_MOD;
	a %= MAX_MOD;
	return a;
}
void solve(){
	memo[0] = 1;
	gyaku[0] = 1;
	for (int i = 1; i < 3000000; ++i) {
		memo[i] = memo[i - 1] * i;
		memo[i] %= MAX_MOD;
		gyaku[i] = inv(memo[i]);
	}
	ll r1, c1, r2, c2;
	cin >> r1 >> c1 >> r2 >> c2;
	ll ans = 0;
	for (int i = r1; i <= r2; ++i) {
		ans += comb(i + 1 + c2, c2);
		ans += valid(-comb(i + 1 + c1 - 1LL, c1 - 1LL));
		ans %= MAX_MOD;
	}
	cout << ans << endl;
	return;
}
#undef int
int main() {
	init();
	solve();
}

Measured memory_bytes: 47104
import sys
#from functools import lru_cache
sys.setrecursionlimit(100000)

N = int(input())
H = [int(h) for h in input().split()]
INF = 10**5+1
cost = [INF]*N
cost[0] = 0
cost[1] = abs(H[0] - H[1])

#@lru_cache(maxsize=None)
def dp(i):
  if cost[i] != INF:
    return cost[i]
  else:
    cost[i] = min(
      dp(i-1) + abs(H[i-1] - H[i]),
      dp(i-2) + abs(H[i-2] - H[i]))
  return cost[i]

for i in range(N-1):
  dp(i)
print(dp(N-1))

Measured memory_bytes: 13716
#include<bits/stdc++.h>
using namespace std;;
int main(){
    int a,b,c,d;
    cin>>a;
    b=a%10;
    c=(a/10)%10;
    d=(a/100)%10;
    if(b==d) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


Measured memory_bytes: 256
S=input()
Q=int(input())
head=""
tail=""
rev=False

for _ in range(Q):
    q = input().split()
    if len(q)==1:
        rev = not rev
    else:
        if rev ^ (q[1]=="1"):
            head+=q[2]
        else:
            tail+=q[2]
if rev:
    print(tail[::-1]+S[::-1]+head)
else:
    print(head[::-1]+S+tail)


Measured memory_bytes: 4340
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

long long mod = 1000000007;

void solve() {
	int n; cin >> n;
	long long ans = 0LL;
	vector<long long>a(n);
	for (int i = 0; i < n; i++)cin >> a[i];
	for (int i = 0; i < 60; i++) {
		long long p = 1LL << i, cnt = 0;
		for (int j = 0; j < n; j++)cnt += (p & a[j]) != 0;
		ans += p % mod * cnt % mod * (n - cnt) % mod;
		ans %= mod;
	}
	cout << ans << endl;
}

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

Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long u_ll;
typedef pair<int, int> pair_;
 
const int INF = 1001001001;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, -1, 0, 1};
int k;
 
int gcd(int a, int b){
    if(b == 0) return a;
 
    return gcd(b, a%b);
}
 
int main(){
  int s,w;

  cin >> s >> w;

  if(w>=s) cout << "unsafe";
  else cout << "safe"; 


    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n, k;
    cin >> n >> k;
    
    int x[n];
    for (int i=0; i<n; i++) {
        cin >> x[i];
    }
    
    int ans = 0;
    
    for (int i=0; i<n; i++) {
        ans += min(x[i], abs(x[i]-k)) * 2;
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 3560
#include <iostream>
#include <cstdio>
#include <vector>
#include <queue>
#include <string>
#include <cmath>
#include <algorithm>

using namespace std;

#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define BIT(X, i) ((X>>i)&1)
#define REP(i, a, b) for(int i = (a); i < (b); ++i)
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define all(a) (a).begin(), (a).end()
#define r_all(a) (a).rbegin(), (a).rend()

typedef long long ll;
typedef vector<ll> vi;
typedef vector<vi> vvi;
typedef pair<ll, ll> pii;
typedef vector<pii> vii;
typedef priority_queue<ll> pq;

const int MOD = 1e9+7;
const int INF = (1<<30);
const ll INFL = (1L<<62);

int main() {
  int r, d, x;
  cin >> r >> d >> x;
  rep(i, 10) {
    x = r*x - d;
    cout << x << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main()
{
	long long n,m,ans=0;
	scanf("%lld%lld",&n,&m);
	if(m==0)
	{
		printf("0\n");
		return 0; 
	}
	/*while(n!=0&&m>1)
	{
		m-=2;
		ans++;
		n--;
	}*/

	ans=m-n*2;
	if(ans<0)
	{
		printf("%lld",m/2);
		return 0;
	} 
	printf("%lld\n",n+ans/4);
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;

void update(vector<int> &v, pair<int, int> &a, pair<int, int> b) {
    set<int> s = {
        a.first, a.second,
        b.first, b.second
    };
    
    vector<int> ind(s.begin(), s.end());

    sort(ind.begin(), ind.end(), [&v] (int x, int y) {
        return v[x] > v[y];
    });

    a = make_pair(ind[0], ind[1]);
}

int main() {
    int n; cin >> n;
    int k = n;
    n = (1 << k);

    vector<int> v(n, 0);
    v[n + 1] = -1;

    vector<pair<int, int>> best(n, {n, n});
    
    for(int i = 0; i < n; ++i) {
        cin >> v[i];
        update(v, best[i], {i, n});
    }
        
    vector<int> ans(n, 0);

    for(int mask = 1; mask < n; ++mask) {
        for(int j = 0; j < k; ++j) {
            if(mask & (1 << j)) {
                update(v, best[mask], best[mask - (1 << j)]);
            }
        }
        ans[mask] = max(ans[mask - 1], v[best[mask].first] + v[best[mask].second]);
        cout << ans[mask] << "\n";
    }
}

Measured memory_bytes: 7168
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<(n);++i)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define all(x) (x).begin(), (x).end()
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;
int main() {
    string s;
    cin>>s;
    int n=s.size(),i=0;
    ll ans=0;
    while(i<n){
        ll left=0,right=0;
        while(i<n&&s[i]=='<'){
            left++;
            i++;
        }
        while(i<n&&s[i]=='>'){
            right++;
            i++;
        }
        if(left>right) right--;
        else left--;
        ans+=left*(1+left)/2+right*(1+right)/2;
    }
    cout<<ans;
}

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

int main() {
    int n, k;
    cin >> n >> k;
    int ans=1;
    for(int i=0; i<n; i++) {
        if(ans>=k) ans += k;
        else ans *= 2;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
using namespace std;
#define Ma_PI 3.141592653589793
#define eps 0.00000001
#define LONG_INF 3000000000000000000
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007
#define MOD 998244353
#define REP(i,n) for(long long i = 0;i < n;++i)    
#define seg_size 524288
int main(){
	int w, h;
	cin >> w >> h;
	vector<vector<int>> input;
	REP(i, h) {
		vector<int> a;
		REP(q, w) {
			int b;
			cin >> b;
			a.push_back(b);
		}
		input.push_back(a);
	}
	sort(input.begin(), input.end());
	int type = 0;
	for (int i = 1; i < h; ++i) {
		if (input[i] != input[i - 1]) {
			if (type == 0) {
				type = i;
			}
			else {
				cout << "no" << endl;
				return 0;
			}
		}
	}
	if (type == 0) {
		cout << "no" << endl;
		return 0;
	}
	if (input.size() % 2 == 0) {
		if (type != input.size() / 2) {
			cout << "no" << endl;
			return 0;
		}
	}
	else {
		if (type != input.size() / 2 && type != input.size() / 2 + 1) {
			cout << "no" << endl;
			return 0;
		}
	}
	int cnt = 0;
	for (int i = 0; i < w; ++i) {
		if (input[0][i] == 1) cnt++;
		if (input[0][i] + input[h - 1][i] != 1) {
			cout << "no" << endl;
			return 0;
		}
	}
	if (cnt != w / 2 && cnt != (w + 1) / 2) {
		cout << "no" << endl;
		return 0;
	}
	cout << "yes" << endl;
	return 0;
}


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

string divide[4] = { "dream", "dreamer", "erase", "eraser" };

int main() {
	string S;
	cin >> S;
	
	reverse(S.begin(), S.end());
	for (int i = 0; i < 4; ++i) reverse(divide[i].begin(), divide[i].end());
	
	bool can = true;
	for (int i = 0; i < S.size();) {
		bool can2 = false;
		for (int j = 0; j < 4; ++j) {
			string d = divide[j];
			if (S.substr(i, d.size()) == d) {
				can2 = true;
				i += d.size();
			}
		}
		if (!can2) {
			can = false;
			break;
		}
	}
	
	if (can) cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 512
import itertools
n=int(input())
l=[[-1 for i in range(n)] for j in range(n)]
for i in range(n):
    a=int(input())
    for j in range(a):
        x,y=map(int,input().split())
        l[i][x-1] = y
m=0
for v in list(itertools.product(range(2), repeat=n)):
    f = True
    for i in range(n):
        if v[i]==1:
            for j in range(n):
                if l[i][j] == -1 or v[j]==l[i][j]:
                    continue
                else:
                    f=False
                    break
    if f:
        m = max(sum(v),m)
print(m)

Measured memory_bytes: 8820
#include <iostream>

static const unsigned N = 50;

int main()
{
  unsigned long long v[N];
  for (unsigned ii=0; ii<N; ++ii)
    v[ii] = ii;

  unsigned long long K;
  std::cin >> K;

  std::cout << N << std::endl;
  
  for (unsigned jj=0; jj<N; ++jj)
    v[jj] += (N*(K/N) - K + K/N);
  for (unsigned jj=0; jj<K%N; ++jj)
    v[jj] += (N + 1);

  for (unsigned jj=0; jj<N; ++jj) {
    std::cout << v[jj] << ' ';
  }
  std::cout << std::endl;

  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;
using P = pair<int,int>;
const int MOD = 1000000007;

int main() {
    int n,sum=0;
    cin>>n;
    int x=n;
    while(x) {
        sum+=x%10;
        x/=10;
    }
    if (n%sum==0) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}


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


struct Linear_Sieve{
int n;
vector<int> lp,primes;
//lp[i]...the least prime of i. primes...prime numbers
Linear_Sieve(int n = 1):n(n),lp(n+1){
    for(int i = 2;i < n+1;i++){
        if(lp[i] == 0) {
            primes.push_back(i);
            lp[i] = i;
        }
        for(int j = 0;j<primes.size() && primes[j] <= lp[i] && i*primes[j] < n+1; ++j) lp[i*primes[j]] = primes[j];
    }
}
bool isPrime(int x) {return lp[x] == x;}

vector<int> factorList(int x){
    //make list which contains prime factors of x. Ans it toralates multipled components.
    vector<int> res;
    while(x != 1){
        res.push_back(lp[x]);
        x /= lp[x];
    }
    return res;
}

vector<pair<int,int>> factor(int x){
        //make list of pairs which couple prime factor and multiplicity.
    vector<int> fl = factorList(x);
    if(fl.size() == 0) return{};
    vector<pair<int,int>> res(1,pair<int,int>(fl[0],0));
    for(int p : fl){
        if(res.back().first == p){
            res.back().second++;
        }else{
            res.emplace_back(p,1);
        }
    }
    return res;
}
};

int main(){
    int q;cin >> q;
    Linear_Sieve s(100009);
    vector<int> num(100009,0);
    for(int i = 3;i<=100001;i+=2){
        if(i==3){
            num[i] = 1;
            continue;
        }
        if(s.isPrime(i) && s.isPrime((i+1)/2)) num[i] = num[i-2] + 1;
        else num[i] = num[i-2];
    }
    //rep(i,10) cout << num[i] << endl;
    rep(i,q){
        int l,r;
        cin >> l >> r;
        cout << num[r] - num[max(l-2,1)] << endl;;
    }
    

}

Measured memory_bytes: 3988
S = list(map(int, input()))

a = 0
b = 0
cnt = 0
for i in S:
  if cnt % 2 == 0:
    if i == 0:
      b += 1
    else:
      a += 1
  else:
    if i == 0:
      a += 1
    else:
      b += 1
  cnt += 1
print(min(a,b))

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

a, b =  map(int, input().split())

x = a + b
y = a - b
z = a * b

if x >= y:
    if x >= z:
        print(x)
    else:
        print(z)
else:
    if y >= z:
        print(y)
    else:
        print(z)

Measured memory_bytes: 2940
import java.util.Scanner;
import java.text.DecimalFormat;
class Main{
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        DecimalFormat d1 = new DecimalFormat("0.00000");
        int a, b;
        a = scanner.nextInt();
        b = scanner.nextInt();

        System.out.print(a/b+" "+a%b+" ");
        System.out.println(d1.format(((double)a)/b));
    }
}



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

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

static const ll INF = (__LONG_LONG_MAX__-3) /2;
static const int NMAX = 305;

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n,m;
    int l = 0;

    cin >> n >> m >> l;
    vector<vector<ll> > v(n+1, vector<ll> (n+1,INF));

    for(int i = 1; i<=m ; ++i)
    {
        int a,b,c;
        cin >> a >> b >> c;
        v[a][b] = c;
        v[b][a] = c;
    }

    // Roy-Floyd
    for(int k = 1; k<=n; ++k)
    {
        for(int i = 1; i<=n; ++i)
        {
            for(int j = 1;j<=n; ++j)
            {
                v[i][j] = min(v[i][j], v[i][k] + v[k][j]);
            }
        }
    }
    vector<vector<ll> > w(n+1, vector<ll> (n+1,INF));

    for(int i = 1; i<=n; ++i)
    {
        for(int j = 1;j<=n; ++j)
        {
            if(v[i][j] <= l)
            {
                w[i][j] = 1;
                w[j][i] = 1;
            }
        }
    }

    // Roy-Floyd again
    for(int k = 1; k<=n; ++k)
    {
        for(int i = 1; i<=n; ++i)
        {
            for(int j = 1;j<=n; ++j)
            {
                w[i][j] = min(w[i][j], w[i][k] + w[k][j]);
            }
        }
    }

    int q;
    cin >> q;
    for(int i = 1; i<= q; ++i)
    {
        int a,b;
        cin >> a >> b;
        if(w[a][b] == INF)
        {
            cout << -1 << '\n';
            continue;
        }
        cout << w[a][b]-1 << '\n';
    }

    return 0;
}

Measured memory_bytes: 2048
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <numeric>

using namespace std;

typedef long long ll;

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

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


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<ctype.h>
#define P(type,x) fprintf(stdout,"%"#type"\n",x)
#define S(type,x) fscanf(stdin,"%"#type,&x)
int main() {
	int n, m, o[1000] = {};
	scanf("%d %d", &n, &m);
	getchar();
	fflush(stdin);
	char s[100][1000],type;
	int i,c=0,tc=0;
	for (i = 0; i < n; i++) scanf("%s %d", s + i, o + i),getchar(), fflush(stdin);
	for (i = 0; i < n; i++) {
		int cur = 0, miss = 0;
		for (; cur != strlen(s[i]);) {
			printf("? %s\n", s + i);
			fflush(stdout);
			scanf("%c", &type);
			getchar();
			fflush(stdin);
			tc++;
			if (tolower(s[i][cur]) == type) { s[i][cur] = '_', c++, cur++; }
			else {
				if (++miss > o[i]) {m--; break;}
			}
		}
		if (m <= 0) { printf("! Game Over\n"); fflush(stdout); return 0; }
	}
	c = c*1000/tc;
	printf("! Game Clear %.1f\n",c/10.);
	fflush(stdout);
	return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 9223372036854775807;

int main(){

    ll N;
    cin >> N;

    ll ans = 0;
    ll AB = 0;
    ll A = 0;
    ll B = 0;

    for(ll i = 0; i < N; i++){
        string s; cin >> s;
        if(s.front() == 'B' && s.back() == 'A') AB++;
        else if(s.front() == 'B') B++;
        else if(s.back() == 'A') A++;
        
        for(ll j = 1; j < s.length(); j++){
            if(s[j-1] == 'A' && s[j] == 'B') ans++;
        } 
    }

    if(AB >= 1){
        AB--;
        if(A >= 1) AB++, A--;
        if(B >= 1) AB++, B--;
        ans += AB;
        ans += min(A, B);
    }else{
        if(A >= 1 && B >= 1) ans += min(A, B);    
    }
    
    cout << ans << endl;

}

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

/*
 * Displayed Rating == Inner Rating{
 * If the User has Participated in 10 or More Contests
 *
 * OtherWise
 *
 * Displayed Rating = InnerRating-100*(10-K) where k= number of contests participated in
 * }
 */

int main(){
    int N,R ;
    cin >> N >> R ;
    int InnerRating ;

    if(N>=10){
        cout << R << endl ;
    }else{
       cout << R+100*(10-N) << endl ;
    }

    
}

Measured memory_bytes: 256
N = int(input())
A = [int(input()) for i in range(N)]
m = max(A)
A_i = A[:]
A_i.remove(m)
m_i = max(A_i)
for i in range(N):
    if A[i] == m:
        print(m_i)
    else:
        print(m)


Measured memory_bytes: 14080
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

void maxAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) max(dst, src);
}

void main()
{
    long A, B;
    scan(A, B);
    bool b = (A % 3) == 0 || (B % 3) == 0 || ((A + B) % 3) == 0;
    writeln(b ? "Possible" : "Impossible");
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define drep(i,n) for(int i = (n-1); i >= 0; i--)
#define all(v) (v).begin(),(v).end()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template <class T> T lcm(T a, T b) { return a/gcd(a,b)*b; }
typedef pair<int, int> P;
typedef long long ll;
const int INF = 1001001001;
const ll LINF = 1001002003004005006ll;
const ll MOD = 1e9+7;

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
	int x;
	cin >> x;
    int ans = 10 - (x/200);
	cout << ans << "\n";
	return 0;
}


Measured memory_bytes: 3640
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <numeric>
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, k, n) for(int i = (k); i < (int)(n); i++)
using namespace std;
using ll = long long;
int N, A, B;
int main(){
    cin >> N >> A >> B;
    int sum = N * A;
    int ss = min(sum, B);
    cout << ss << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
const int MM = 1000000000;
const int MOD = MM + 7;
const int MAX = 510000;
#define rep(i, n) for(ll i=0; i<n; i++)
#define Rep(i, j, n) for(ll i=j; i<n; i++)
#define all(vec) vec.begin(), vec.end()
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 INF = 1LL << 60;

int main() {
    int n; cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(all(a));
    reverse(all(a));
    ll ans = a[0];
    int i = 1, sum = 2;
    while(sum < n) {
        ans += a[i];
        sum++;
        if(sum >= n) break;
        ans += a[i];
        i++;
        sum++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4852