akhauriyash/Code-Regression huggingface dataset:
/**
 * @brief ユーザ定義リテラル
 * @author えびちゃん
 */

#ifndef H_int_literals
#define H_int_literals

#include <cstddef>
#include <cstdint>

constexpr intmax_t  operator ""_jd(unsigned long long n) { return n; }
constexpr uintmax_t operator ""_ju(unsigned long long n) { return n; }
constexpr size_t    operator ""_zu(unsigned long long n) { return n; }
constexpr ptrdiff_t operator ""_td(unsigned long long n) { return n; }

#endif  /* !defined(H_int_literals) */

/**
 * @brief 多次元 vector の作成
 * @author えびちゃん
 */

#ifndef H_make_vector
#define H_make_vector

#include <cstddef>
#include <type_traits>
#include <vector>

namespace detail {
  template <typename Tp, size_t N>
  std::vector<Tp> make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N == 1), Tp const&>::type x
  ) {
    return std::vector<Tp>(sizes[0], x);
  }
  template <typename Tp, size_t N>
  auto make_vector(
      std::vector<size_t>& sizes,
      typename std::enable_if<(N > 1), Tp const&>::type x
  ) {
    size_t size = sizes[N-1];
    sizes.pop_back();
    return std::vector<decltype(make_vector<Tp, N-1>(sizes, x))>(
        size, make_vector<Tp, N-1>(sizes, x)
    );
  }
}  // detail::

template <typename Tp, size_t N>
auto make_vector(size_t const(&sizes)[N], Tp const& x = Tp()) {
  std::vector<size_t> s(N);
  for (size_t i = 0; i < N; ++i) s[i] = sizes[N-i-1];
  return detail::make_vector<Tp, N>(s, x);
}

#endif  /* !defined(H_make_vector) */

#include <cstdio>
#include <algorithm>

int main() {
  size_t n;
  scanf("%zu", &n);

  auto a = make_vector({n, n}, 0_jd);
  for (auto& ai: a)
    for (auto& aij: ai) scanf("%jd", &aij);

  auto b = a;
  for (size_t k = 0; k < n; ++k)
    for (size_t i = 0; i < n; ++i)
      for (size_t j = 0; j < n; ++j)
        b[i][j] = std::min(b[i][j], b[i][k]+b[k][j]);

  if (a != b) return puts("-1"), 0;

  intmax_t const inf = 1e13;
  for (size_t k = 0; k < n; ++k)
    for (size_t i = 0; i < n; ++i)
      for (size_t j = 0; j < n; ++j)
        if (i != k && j != k && b[i][j] == b[i][k]+b[k][j])
          b[i][j] = inf;

  intmax_t res = 0;
  for (size_t i = 0; i < n; ++i)
    for (size_t j = 0; j < n; ++j)
      if (b[i][j] < inf) res += b[i][j];

  res /= 2;
  printf("%jd\n", res);
}


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

int main() {
	string S;
	map<char, int>ch;
	cin >> S;
	int len = S.size();
	for(int i = 0; i < len; i++)
	{
	    ch[S[i]]++;
	}
	int ck = 0;
	for(char i = 'a'; i <= 'z'; i++)
	{
	    if(!ch[i])
	    {
	        cout<<S<<i<<endl;
	        ck = 1;
	        break;
	    }
	}
	if(!ck)
	{
	    int key = -1;
	    for(int i = len - 1; i >= 0; i--)
	    {
	        for(char j = S[i] + 1; j <= 'z'; j++)
	        {
	            int ok = 0;
	            for(int k = 0; k < i; k++)
                {
                    if(j == S[k])
                    {
                        ok = 1;
                    }
                }
                if(!ok)
                {
                        S[i] = j;
                        key = i;
                        break;
                }
	        }
	        if(key == i)
	            break;
	    }
	    if(key != -1)
        {
            for(int i = 0; i <= key; i++)
                cout << S[i];
            cout << endl;
        }
        else if(!ck)
            cout << -1 << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <vector> 
#include <cstdint>
#define FOR(i,l,r) for(int i=(l);i<(r);++i)
#define RFOR(i,l,r) for(int i=(l);i>=(int)(r);i--)
#define rep(i,n)  FOR(i,0,n)
#define rrep(i,n)  RFOR(i,n-1,0)

// #define int long long
using namespace std;
const int MX = 1e6;
const int inf = 1e9;
const int mod = 1e9+7;

int arr[100][100];
signed main(){
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    cout << 100<<" "<<100 << endl;
    rep(i,50) {
        rep(j,100) {
            arr[i][j]=1;
        }
    }
    rep(i,50) {
        rep(j,100) {
            if(i%2==0 && j%2==0) {
                if(a>0) {
                   arr[i][j]=0;
                   a--; 
                }else break;
            }
        }
    }
    rep(i,50) {
        rep(j,100) {
            if(i%2==1 && j%2==0) {
                if(b>0) {
                   arr[i+50][j]=1;
                   b--; 
                }else break;
            }
        }
    }

    rep(i,100) {
        rep(j,100) {
            if(arr[i][j]==0) cout << "." << flush;
            else cout << "#" << flush;
        }
        cout << "" << endl;
    }



    return 0;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;

int main(){
    i64 ans=0;
    string s;
    cin>>s;
    for(i64 i=0;i<s.size()/2;i++){
        if(s[i]!=s[s.size()-i-1]) ans++;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <queue>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
using namespace std;

#define ll long long

int main(){

    int n;
    cin >> n;

    int buf;
    vector<int> hairetu;
    for(int i=0; i<n; i++){
        cin >> buf;
        hairetu.push_back(buf);
    }

    sort(hairetu.begin(), hairetu.end(), greater<int>());
    
    long long sum = 0;
    for(auto it : hairetu){
        sum += it;
    }

    cout << hairetu.at(n - 1) << " " << hairetu.at(0) << " " << sum << endl;

    return 0;
}

Measured memory_bytes: 3168
a = []

s = [1,2,3,4,5,6,7,8,9,10,11,12,13]
h = [1,2,3,4,5,6,7,8,9,10,11,12,13]
c = [1,2,3,4,5,6,7,8,9,10,11,12,13]
d = [1,2,3,4,5,6,7,8,9,10,11,12,13]

counter = 0
n = int(input())

while counter < n:
    a.append(list(input().split()))
    counter += 1

for i in range(n):
    if a[i][0] == "S":
        s.remove(int(a[i][1]))
    elif a[i][0] == "H":
        h.remove(int(a[i][1]))
    elif a[i][0] == "C":
        c.remove(int(a[i][1]))
    elif a[i][0] == "D":
        d.remove(int(a[i][1]))

for i in s:
    print("S %s" % i)
for i in h:
    print("H %s" % i)
for i in c:
    print("C %s" % i)
for i in d:
    print("D %s" % i)


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

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> s(n+1);
  int m;
  for(int i = 0; i < n; i++){
    cin >> m;
    s.at(i+1) = s.at(i) + m+1;
  }
  
  int ans = 0;
  int tmp = 0;
  for(int i = 0; i + k <= n; i++){
    tmp = s.at(i+k) - s.at(i);
    if(ans < tmp) ans = tmp;
  }
  cout << setprecision(12) << ans/2.0;
}




Measured memory_bytes: 1024
#include<stdio.h>
#include<iostream>
#include<queue>
#include<string.h>
using namespace std;
struct Y{
int hx,hy,rx,ry,t;
};
int c[51][51][51][51],mp[52][52];
int main(){
int w,h,i,j,a[2]={1,-1},b[2];
Y e;
while(1){
queue<Y> q;
cin>>w>>h;
if(w==0&&h==0)break;
cin>>e.hx>>e.hy>>e.rx>>e.ry;
e.t=0;
q.push(e);
memset(c,0,sizeof(c));
memset(mp,-1,sizeof(mp));
for(i=1;i<=h;i++){
for(j=1;j<=w;j++){
cin>>mp[i][j];
}
}
while(!q.empty()){
e=q.front();
q.pop();
c[e.hy][e.hx][e.ry][e.rx]=1;
if(e.t>=100||e.hx==e.rx&&e.hy==e.ry)break;
e.t++;
for(i=0;i<2;i++){
if(mp[e.hy+a[i]][e.hx]==0&&c[e.hy+a[i]][e.hx][e.ry-a[i]][e.rx]==0&&mp[e.ry-a[i]][e.rx]==0){
b[0]=0;
b[1]=0;
if(mp[e.hy+a[i]][e.hx]==0){
e.hy+=a[i];
b[0]=1;
}
if(mp[e.ry-a[i]][e.rx]==0){
e.ry-=a[i];
b[1]=1;
}
c[e.hy][e.hx][e.ry][e.rx]=1;
q.push(e);
if(b[0]==1)e.hy-=a[i];
if(b[1]==1)e.ry+=a[i];
}
if(mp[e.ry-a[i]][e.rx]==0&&c[e.hy][e.hx][e.ry-a[i]][e.rx]==0&&mp[e.hy+a[i]][e.hx]!=0){
b[0]=0;
b[1]=0;
if(mp[e.hy+a[i]][e.hx]==0){
e.hy+=a[i];
b[0]=1;
}
if(mp[e.ry-a[i]][e.rx]==0){
e.ry-=a[i];
b[1]=1;
}
c[e.hy][e.hx][e.ry][e.rx]=1;
q.push(e);
if(b[0]==1)e.hy-=a[i];
if(b[1]==1)e.ry+=a[i];
}
if(mp[e.hy+a[i]][e.hx]==0&&mp[e.ry-a[i]][e.rx]!=0&&c[e.hy+a[i]][e.hx][e.ry][e.rx]==0){
b[0]=0;
b[1]=0;
if(mp[e.hy+a[i]][e.hx]==0){
e.hy+=a[i];
b[0]=1;
}
if(mp[e.ry-a[i]][e.rx]==0){
e.ry-=a[i];
b[1]=1;
}
c[e.hy][e.hx][e.ry][e.rx]=1;
q.push(e);
if(b[0]==1)e.hy-=a[i];
if(b[1]==1)e.ry+=a[i];
}

if(mp[e.hy][e.hx+a[i]]==0&&mp[e.ry][e.rx-a[i]]==0&&c[e.hy][e.hx+a[i]][e.ry][e.rx-a[i]]==0){
b[0]=0;
b[1]=0;
if(mp[e.hy][e.hx+a[i]]==0){
e.hx+=a[i];
b[0]=1;
}
if(mp[e.ry][e.rx-a[i]]==0){
e.rx-=a[i];
b[1]=1;
}
c[e.hy][e.hx][e.ry][e.rx]=1;
q.push(e);
if(b[0]==1)e.hx-=a[i];
if(b[1]==1)e.rx+=a[i];
}
if(mp[e.hy][e.hx+a[i]]==0&&c[e.hy][e.hx+a[i]][e.ry][e.rx]==0&&mp[e.ry][e.rx-a[i]]!=0){
b[0]=0;
b[1]=0;
if(mp[e.hy][e.hx+a[i]]==0){
e.hx+=a[i];
b[0]=1;
}
if(mp[e.ry][e.rx-a[i]]==0){
e.rx-=a[i];
b[1]=1;
}
c[e.hy][e.hx][e.ry][e.rx]=1;
q.push(e);
if(b[0]==1)e.hx-=a[i];
if(b[1]==1)e.rx+=a[i];
}
if(mp[e.ry][e.rx-a[i]]==0&&mp[e.hy][e.hx+a[i]]!=0&&c[e.hy][e.hx][e.ry][e.rx-a[i]]==0){
b[0]=0;
b[1]=0;
if(mp[e.hy][e.hx+a[i]]==0){
e.hx+=a[i];
b[0]=1;
}
if(mp[e.ry][e.rx-a[i]]==0){
e.rx-=a[i];
b[1]=1;
}
c[e.hy][e.hx][e.ry][e.rx]=1;
q.push(e);
if(b[0]==1)e.hx-=a[i];
if(b[1]==1)e.rx+=a[i];
}

}
e.t--;
}
if(e.hy==e.ry&&e.hx==e.rx)cout<<e.t<<endl;
else cout<<"NA"<<endl;
}
return 0;
}

Measured memory_bytes: 29580
#include<iostream>
#include<vector>
#include<algorithm>
#include<utility>

using namespace std;

typedef pair<long long, long long> P;

int M, N;

int main() {
	cin >> N >> M;
	vector<P> AB(N);
	for (int i = 0; i < N; i++) {
		cin >> AB[i].first >> AB[i].second;
	}
	sort(AB.begin(), AB.end());
	long long int ans = 0;
	for (int i = 0; i < N; i++) {
		if(AB[i].second < M){
			M -= AB[i].second;
			ans += AB[i].second * AB[i].first;
		}
		else {
			ans += M * AB[i].first;
			break;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1792
#1st arg is the how far from the most upper side
#2nd arg is the how far from the most left side
#right means +1 in terms of x-axis
#upper means -1 in terms of y-axis

def Right(position):
	position[1] += 1

def Down(position):
	position[0] += 1 

def Collect(position,candy):
	x = position[0]
	y = position[1]
	total = 0
	total += candy[x][y]
	return total

N = int(input())
candy = []
while True:
    try:
        candy.append(list(map(int,input().split())))
    except:
        break;
position = [0,0]
score = 0
max_score = 0
k = 0
for t in range(N):
	score = candy[0][0]
	position[0] = 0
	position[1] = 0
	for i in range(N):
		if t == i:
			Down(position)
			score += Collect(position,candy)
		if i < N - 1:	
			Right(position)
			score += Collect(position,candy)
	if max_score < score:
		max_score = score
		k = t
print(max_score)




Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int64_t N, A, B;
  cin >> N >> A >> B;
  vector<int64_t> H(N);
  rep(i, N) { cin >> H[i]; }

  int64_t left = 0;
  int64_t right = 1e9;
  while (left + 1 < right) {
    int64_t mid = left + (right - left) / 2;

    int64_t dmgB = B * mid;
    int64_t numA = 0;
    rep(j, N) {
      if (H[j] <= dmgB) continue;
      numA += (H[j] - dmgB + A - B - 1) / (A - B);
    }

    if (numA <= mid) {
      right = mid;
    } else {
      left = mid;
    }
  }
  cout << right << endl;
  return 0;
}

Measured memory_bytes: 4048
#include<iostream>
#include<map>
using namespace std;
int main(void){
  int n,a;
  while(cin >> n,n){
    map<int,int> hoge;
    int m=0,mm=0;
    for(int i=0;i<n;i++){
      cin >> a;
      hoge[a]++;
      if(hoge[a]>m){
	m=hoge[a];
	mm=a;
      }
    }
    if(n/2<m) cout << mm << endl;
    else cout << "NO COLOR" << endl;
  }
}


Measured memory_bytes: 2728
from queue import deque
def main():
    que=deque()
    que.append(input())
    head = True
    for i in range(int(input())):
        q=input().split()
        if q[0]=="1":
            head = not head
        else:
            h = q[1]=="1"
            if (head and h) or (not head and not h):
                que.appendleft(q[2])
            else:
                que.append(q[2])      
    string = "".join(que)
    print(string if head else string[::-1])
main()

Measured memory_bytes: 7536
#include<bits/stdc++.h>
using namespace std;
int main(){
 string s;
  cin>>s;
  if(s=="Sunny"){
    cout<<"Cloudy"<<endl;
  }else if(s=="Cloudy"){
    cout<<"Rainy"<<endl;
  }else{
    cout<<"Sunny"<<endl;
  }
}


Measured memory_bytes: 256
def calc_variance(size, nums):
    average = sum(nums) / size
    variance = sum([(x - average) ** 2 for x in nums]) / size
    return variance

while True:
    n = int(input())
    if n == 0:
        break
    scores = list(map(int, input().split()))
    standard_deviation = calc_variance(n, scores) ** 0.5
    print(standard_deviation)



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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
    for (int i = 0; i < S.size(); i++)
    {
        if ('Z' < S[i] + N)
        {
            cout << char((S[i] + N) - 'Z' - 1 + 'A');
        }
        else
            cout << char(S[i] + N);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
S = list(input())
ans = {}
for i in range(4):
    if S[i] not in ans.keys():
        ans[S[i]] = 1
    else :
        ans[S[i]] += 1
for i in ans.keys():
    if ans[i] == 2 :
        pass
    else :
        print("No")
        exit()

print("Yes")

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

using namespace std;

#define ll long long
#define ld long double
#define P pair<ll, ll>

#define FORm(i, m) for (auto i = m.begin(); i != m.end(); i++)

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

#define sortAl(v) sort(all(v))
#define sortAlr(v)          \
  sort(v.begin(), v.end()); \
  reverse(v.begin(), v.end())

#define cout(n) cout << fixed << setprecision(n)

#define rep(i, n) for (int i = 0; i < n; i++)
#define REP(i, n) for (int i = 1; i < n; i++)

template <class T>
inline void chmax(T &a, T b) {
  a = std::max(a, b);
}
template <class T>
inline void chmin(T &a, T b) {
  a = std::min(a, b);
}

#define mod (ll)(1e9 + 7)
#define INF LLONG_MAX

vector<vector<ll>> b(100001);
vector<ll> nodes(100001);

void update(int n, const int num) {
  nodes[n] = num;
  FORm(itr, b[n]) {
    if (!nodes[*itr]) {
      nodes[*itr] = num;
      update(*itr, num);
    }
  }
}

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

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

  rep(i, m) {
    vector<ll> tmp(3);
    cin >> tmp[0] >> tmp[1] >> tmp[2];
    b[tmp[0]].push_back(tmp[1]);
    b[tmp[1]].push_back(tmp[0]);
  }

  int num = 0;

  REP(i, n + 1) {
    if (!nodes[i]) {
      num++;
      update(i, num);
    }
  }

  cout << num << endl;

  return 0;
}


Measured memory_bytes: 11264
#include <iostream>
#include <string>

using namespace std;

char calc(string str, int index) {
    char answer = str[0]; // if str[0] is not 1.

    // take 1 into account
    if (str[0] == '1') {
        int last_index = 0;
        for (int i = 1; i < str.size(); i++) {
            if (str[i] == '1') {
                last_index = i;
            } else {
                break;
            }
        }

        if (index - 1 <= last_index) {
            answer = '1';
        } else {
            answer = str[last_index + 1];
        }
    }

    return answer;
}

int main()
{
    string S;
    int K;

    cin >> S;
    cin >> K;

    cout << calc(S, K) << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        Set<Integer> s = new HashSet<Integer>();
        for (int i = 0; i < N; i++) {
            s.add(sc.nextInt());
        }
        System.out.println(s.size());
    }
}

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

int main(){
  int k, s, a, l;
  cin >> k >> s;
  a = 0;
  for(int i = 0; i < k + 1; i++){
    for(int j = 0; j < k + 1; j++){
      l = s - i - j;
      if(0 <= l && l <= k)
          a++;
    }
  }
  cout << a << endl;
}

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

int main() {
  int a;
  cin >> a;
  
  cout << a+a*a+a*a*a << endl;

  return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <queue>
#include <stack>
#include <algorithm>
#include <list>
#include <vector>
#include <complex>
#include <utility>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <bitset>
#include <ctime>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <cassert>
#include <cstddef>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <sstream>
#include <fstream>

#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR(i,a,b) for(int (i)=(a);(i)<(b);(i)++)
#define RREP(i,a) for(int (i)=(a)-1;(i)>=0;(i)--)
#define FORR(i,a,b) for(int (i)=(a)-1;(i)>=(b);(i)--)
#define PI acos(-1.0)
#define DEBUG(C) cout<<C<<endl;
#define VI vector<int>
#define VII vector<VI>
#define VL vector<LL>
#define VLL vector<VL>
#define VD vector<double>
#define VDD vector<VD>
#define PII pair<int,int>
#define PDD pair<double,double>
#define PLL pair<LL,LL>
#define VPII vector<PII>
#define ALL(a) (a).begin(),(a).end()
#define SORT(a) sort(ALL(a))
#define REVERSE(a) reverse(ALL(a))
#define MP make_pair
#define FORE(a,b) for(auto &&a:b)

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int INF=1e9;
const int MOD=INF+7;

int main(void){
    string w; cin >> w;
    map<char,int> mp;
    REP(i,w.size()){
        mp[w[i]]++;
    }
    FORE(el,mp){
        if(el.second&1){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}


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

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

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

using namespace std;

int main() {
	int N, X[200000], Y[200000]; //X→元の数列　Y→ソート後の数列

	cin >> N;

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

	sort(Y , Y + N);

	for (int i = 0; i < N; i++) {
		if (X[i] <= Y[(N / 2)-1]) {
			cout << Y[(N / 2) ] << endl;
		}
		else {
			cout << Y[(N / 2)-1] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3712
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, c) for (int i = 0; i < (int)c; i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using P = pair<int, int>;
//const int inf = 1e9; //1(1倍)e(指数)9(10^9)
//const ll MX = 1e18; //1(1倍)e(指数)18(10^18)
//const ll MOD = 1e9 + 7; //1000000007で割った余りを聞かれたら使う
//加算代入演算子は+=
//int 2^31 10^9まで
//intは10桁、long longは18桁、doubleは308桁、long double は4932桁
//10^10くらいまででdoubleは誤差が発生しちゃう。なるべく整数にすること
//doubleからlong longにキャストするときは、+0.5で切り捨ての誤差を調整
//__int128()で128bit対応の整数（多倍長整数）
//||は片方が成り立つとき
int main()
{
    int a, b;
    cin >> a >> b;
    if(a + b >= 10) cout << "error" << endl;
    else cout << a + b << endl;
    return 0;
}

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


int main() {
	int n,k,ans;
	k = 0;
	cin >> n;
	vector<string>s(n);
	vector<int>t(n);
	for (int i = 0; i < n; i++) {
		cin >> s.at(i) >> t.at(i);
	}
	string x;
	cin >> x;
	for (int i = 0; i < n; i++) {
		if (x == s.at(i)) {
			k = i;
		}
	}
	ans = 0;
	for (int i = (k+1); i < n; i++) {
		ans += t.at(i);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
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; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> tri;
typedef pair<double,double> point;
const ll MAX = 30000;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string t,b;
    cin >> t >> b;
    ll lt = t.length(),lb = b.length();
    vector<vector<ll>> dp(lt+1,vector<ll>(lb+1,0));
    dp[0][0] = 1;
    rep(i,lt){
        rep(j,lb){
            if (t[i] == b[j]){
                (dp[i+1][j+1] += dp[i][j])%=MOD;
            }
            (dp[i+1][j] += dp[i][j])%=MOD;
        }
        (dp[i+1][lb] += dp[i][lb])%=MOD;
    }
    PRINT(dp[lt][lb]);
}



Measured memory_bytes: 10712
N, K, Q = map(int,input().split())
scores = [K for _ in range(N)]
for _ in range(Q):
    answerer = int(input()) - 1
    scores[answerer] += 1
for final_score in scores:
    if final_score - Q <= 0:
        print("No")
    else:
        print("Yes")
    

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)

int main(){
    int N;
    cin >> N;
    int a[N];
    int ma = -1;
    int mi = INT_MAX/3;
    REP(i, N){
        cin >> a[i];
        ma = max(a[i], ma);
        mi = min(a[i], mi);
    }
    if(ma-mi>1 || ma>=N || mi>=N){
        cout << "No" << endl;
    }else if (ma-mi==1){
        int count1 = 0;
        int count2 = 0;
        REP(i, N){
            if(a[i]==ma) count1++;
            if(a[i]==mi) count2++;
        }
        if(mi-count2 + 1 < 1){
            cout << "No" <<endl;
        }else if(mi-count2+1>=1 && (N-count2)/(mi-count2+1)>=2){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }else{
        if(N==ma+1){
            cout << "Yes" << endl;
        }else if(N/ma>=2){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    return 0;
}

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


int main(void){
  int m1, m2, o1;
  while(cin >> m1 >> m2 >> o1){
    int card[10] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int n = 20 - (m1 + m2);
    int match = 0;
    card[m1-1] = -1; card[m2-1] = -1; card[o1-1] = -1;
    for(int i = 0; i < 10; i++){
      if(card[i] == -1) continue;
      for(int j = 0; j < 10; j++){
        if(card[j] == -1 || i == j) continue;
        if(card[j] <= n) match++;
      }
    }
    if(1.0 * match / 42 >= 0.5) cout << "YES" << endl;
    else cout << "NO" << endl;
  }
  return 0;
}

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

using namespace std;

int main(){
  int n, y;
  bool end=false;
  cin >> n >> y;

  for(int i=0;i<=n;i++){
    for(int j=0;j<=n-i;j++){
      int t=n-i-j;
      if(10000*i+5000*j+t*1000==y){
        cout << i << " " << j << " " << t << endl;
        end=true;
        break;
      }
    }
    if(end)break;
    if(i==n)cout << -1 << " " << -1 << " " << -1 << endl;
 }

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define REPD(i,a,b) for (int i=(a);i<(b);i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<string> vs;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef set<int> si;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<int, int> pi;
typedef queue<pi> qpi;
typedef pair<ll, ll> pll;
typedef queue<pll> qpll;
typedef vector<pi> vpi;
typedef vector<pll> vpll;
const int mod = 1000000007;
const int INF = 1001001001;
// 小数点　<< fixed << setprecision(0) <<
// sort降順　sort(ALL(),greater<int>());
// 円周率　M_PI
// 文字判定　isupper islower
// 順列　do {} while(next_permutation(ALL(X)));
// 最大値　LLONG_MAX
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
struct edge {
    int from; //出発点
    int to;   //到達点
    int cost; //移動コスト
};
typedef struct edge se;
typedef vector<edge> ve;
unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}
int main() {
  int k,a,b;
  cin >> k >> a >> b;
  string ans="NG";
  REPD(i,a,b+1) {
    if(i%k==0) ans="OK";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 3628
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <cmath>
//#include <cstdlib>
using namespace std;


int main(){
	/*input*/
	int n, t, a;
	cin >> n >> t >> a;

	int h[1000];
	for(int i = 0; i < n; i++){
		cin >> h[i];
	}

	/*calc*/
    int ans = 0;
    double min = 10000;
    double differ = 0.0;
    for(int i = 0; i < n; i++){
    	double temp = t - h[i] * 0.006;
//    	cout << "temp" << temp << endl;
    	differ = abs(a - temp);
//    	cout << "differ" << differ << endl;
    	if(min > differ){
    		ans = i+1;
    		min = differ;
    	}
    }

    /*output*/
	cout<< ans <<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
  int s = n % 10;
  
  
  
  if(s == 2 || s ==4 || s ==5 || s ==7 || s ==9){
    cout << "hon" << endl;
  }
  else if(s == 0 || s ==1 || s ==6 || s ==8){
    cout << "pon" << endl;
  }
  else if(s == 3){
    cout << "bon" << endl;
  }
  
  
  
}

Measured memory_bytes: 3600
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
  ll n;
  cin >> n;
  ll half = (ll) sqrt(n);
  ll ans = 0;
  for(int i = half; i > 0; i--){
    if(n%i == 0){
      ans = n/i + i - 2;
      break;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


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

int main()
{
	std::vector<int>high(10);

	for(int i = 0;i < 10;i++)
	{
		std::cin >> high[i];
	}

	std::sort(high.begin(),high.end(),std::greater<int>());

	for(int i = 0;i < 3;i++)
	{
		std::cout << high[i] << std::endl;
	}

    return 0;
}

Measured memory_bytes: 0
/*
 ============================================================================
 Name        : AOJ.c
 Author      :
 Version     :
 Copyright   : Your copyright notice
 Description : Hello World in C, Ansi-style
 ============================================================================
 */

#include <stdio.h>

int main(void){
	int a;
	scanf("%d",&a);
	a=a*a*a;
	printf("%d\n",a);
	return 0;
}

Measured memory_bytes: 596
n=int(input())
a=list(map(int,input().split()))
cnt=[0]*(max(a)+4)
cnt[0]=3
mod=10**9+7
ans=1
for i in range(n):
    ans*=cnt[a[i]]
    ans%=mod
    cnt[a[i]]-=1
    cnt[a[i]+1]+=1
print(ans)


Measured memory_bytes: 20692
#include<iostream>
using namespace std;
int a,b;
int ans;
int main()
{
	cin>>a>>b;
	if(b==1) {ans=0;cout<<ans<<endl;return 0;}
	for(int i=1;i<=101;i++)
	{
		if(a*i+1-i>=b)
		{
			cout<<i<<endl;
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <string>
#include <iostream>
#include <stack>

using namespace std;

int main(){
    int n, k;
    scanf("%d %d\n", &n, &k);
    vector<int> vs;
    vs.resize(n);
    for(int i = 0; i < n; ++i){
        int vi;
        scanf("%d", &vi);
        vs.at(i) = vi;
    }

    int ans = 0;
    for(int m = 0; m <= min(n, k); ++m){
        for(int l = 0; l <= m; ++l){
            const int r = m - l;

            vector<int> tmp;
            tmp.reserve(m);
            for(int i = 0; i < l; ++i){
                tmp.push_back(vs.at(i));
            }
            for(int i = 0; i < r; ++i){
                tmp.push_back(vs.at(vs.size() - i - 1));
            }
            sort(tmp.begin(), tmp.end());
            int tmp_ans = 0;
            int back_count = k - m;
            for(int vi : tmp){
                if(vi < 0 && back_count > 0){
                    back_count--;
                }else{
                    tmp_ans += vi;
                }
            }
            ans = max(ans, tmp_ans);
        }
    }
    printf("%d\n", ans);
    return 0;
}


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

int main(){

  char a;
  char b;
  cin >> a;
  b = a+1;
  cout << b << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

class Main {
	int parents[];
	int rank[];

	public void run() {
		Scanner scanner = new Scanner(System.in);
		int numVertices = scanner.nextInt();
		int numEdges = scanner.nextInt();
		int src, dest, weight;

		// Build graph
		Graph G = new Graph(numVertices, numEdges);

		for(int i = 0; i < numEdges; i++) {
			src = scanner.nextInt();
			dest = scanner.nextInt();
			weight = scanner.nextInt();

			G.addEdge(i, src, dest, weight);
		}

		// Build disjoint sets
		parents = new int[numVertices];
		rank = new int[numVertices];

		for(int i = 0; i < numVertices; i++) {
			createSet(i);
		}

		// Run Kruskal algorithm and print sum of weights of the MST
		System.out.println(KruskalMST(G, numVertices, numEdges));
	}

	public static void main(String[] args) {
		new Main().run();
	}

	public void createSet(int n) {
		parents[n] = n;
		rank[n] = 0;
	}

	public int findSet(int n) {
		if(n != parents[n])
			parents[n] = findSet(parents[n]);
		return parents[n];
	}

	public void union(int x, int y) {
		int xroot = findSet(x);
		int yroot = findSet(y);

		if(xroot == yroot)
			return;

		if(rank[xroot] > rank[yroot]) {
			parents[yroot] = xroot;
		} else {
			parents[xroot] = yroot;
			if(rank[xroot] == rank[yroot])
				rank[yroot]++;
		}
	}

	public int KruskalMST(Graph G, int numVertices, int numEdges) {
		Edge result[] = new Edge[numVertices];
		Edge edges[] = G.getEdges();

		// Sort all edges of graph G
		Arrays.sort(edges);

		int sum = 0;
		int i = 0, e = 0;
		while(e < numVertices-1) {
			
			// get the next edge with minimum weight
			Edge nextEdge = edges[i++];

			int x = findSet(nextEdge.getSrc());
			int y = findSet(nextEdge.getDest());

			if(x != y) { // if including this edge doesn't form a cycle
				result[e++] = nextEdge;
				sum += nextEdge.getWeight();
				union(x, y);
			}
		}

		return sum;
	}

	class Graph {
		private int V, E;
		private Edge edges[];

		public Graph(int v, int e) {
			V = v;
			E = e;
			edges = new Edge[e];
		}

		public void addEdge(int i, int src, int dest, int weight) {
			if(i >= E) 
				return;

			edges[i] = new Edge(src, dest, weight);
		}

		public Edge[] getEdges() {
			return edges;
		}
	}

	class Edge implements Comparable<Edge>{
		private int src, dest, weight;

		public Edge(int s, int d, int w) {
			src = s;
			dest = d;
			weight = w;
		}

		public int compareTo(Edge anotherEdge) {
			return this.weight - anotherEdge.weight;
		}

		public int getSrc() {
			return src;
		}

		public int getDest() {
			return dest;
		}

		public int getWeight() {
			return weight;
		}
	}
}


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

int main(){
  ll N;
  cin >> N;
  
  ll ans = 0;
  for (int A = 1; A < N; A++){
    if (N % A == 0){
      ans += N / A - 1;
    }
    else{
      ans += N / A;
    }
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 3624
#include<stdio.h>
 
int main(void)
{
	int n, a, b, i, j, sum, x = 0;
	scanf("%d %d %d", &n, &a, &b);

	for ( i = 1; i <= n; i++ ) {
		j = i;
		sum = 0;
		do {
			sum += j % 10;
			j /= 10;
		} while (j > 0);
		if ( a <= sum && sum <= b ) {
			x += i;
		}
	}
	printf("%d\n", x);
  return 0;
}

Measured memory_bytes: 128
import sys
import copy
import  math
from _bisect import *
from collections import *
from operator import itemgetter
from math import factorial
"""
from fractions import gcd
def lcm(x, y):
    return (x * y) // gcd(x, y)
"""
stdin = sys.stdin
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline()

a, b, c = input().split()
print('YES' if a[-1] == b[0] and b[-1] == c[0] else 'NO')


Measured memory_bytes: 3444
// 2017-02-04
#include <iostream>
#include <algorithm>
using namespace std;

int main() {
	int n, m, h[1500 + 1], w[1500 + 1];
	static int hc[1500 * 1000 + 1], wc[1500 * 1000 + 1];
	h[0] = 0; w[0] = 0;
	while (cin >> n >> m, n) {
		for (int i = 0; i < n; i++) {
			int a;
			cin >> a;
			h[i + 1] = h[i] + a;
		}
		for (int i = 0; i < m; i++) {
			int a;
			cin >> a;
			w[i + 1] = w[i] + a;
		}
		fill(hc, hc + 1500 * 1000 + 1, 0);
		fill(wc, wc + 1500 * 1000 + 1, 0);
		for (int i = 0; i < n; i++) {
			for (int j = i + 1; j <= n; j++) {
				hc[h[j] - h[i]]++;
			}
		}
		for (int i = 0; i < m; i++) {
			for (int j = i + 1; j <= m; j++) {
				wc[w[j] - w[i]]++;
			}
		}
		int c = 0;
		for (int i = 0; i < 1500 * 1000 + 1; i++) {
			c += hc[i] * wc[i];
		}
		cout << c << endl;
	}
	return 0;
}

Measured memory_bytes: 14768
#include<stdio.h>
main(){
	int n;
	while(scanf("%d",&n)!=EOF){
		int a,b,c,d,counter=0;
		for(a=0;a<=9;a++){
			for(b=0;b<=9;b++){
				for(c=0;c<=9;c++){
					for(d=0;d<=9;d++){
						if(a+b+c+d==n){
							counter++;
						}
					}
				}
			}
		}
		printf("%d\n",counter);
	}
	return 0;
}

Measured memory_bytes: 596
#include <bits/stdc++.h>
#include <boost/range/irange.hpp>

using namespace std;
using namespace boost;

main() {
    int64_t q;
    cin >> q;

    std::multiset<int64_t> a;
    auto it = a.begin();
    int64_t f = 0;
    for (auto _ : irange(0L, q)) {
        int o;
        cin >> o;

        if (o == 1) {
            // update
            int64_t aa, bb;
            cin >> aa >> bb;

            a.insert(aa);
            if (a.size() == 1) {
                it = a.begin();
            } else if (a.size() % 2 == 0) {
                f += abs(*it - aa);
                if (aa < *it) {
                    --it;
                }
            } else {
                f += abs(*it - aa);
                if (*it <= aa) {
                    auto prev = *it;
                    ++it;
                    f -= (*it - prev);
                }
            }

            f += bb;
        } else {
            // query
            cout << *it << " " << f << "\n";
        }
    }

    cout << flush;
}

Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
const int MAX = 510000;
//const int MOD = 998244353;
const int MOD = 1000000007;
long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

int main(){
    // 前処理
    COMinit();
    int S;
    cin >> S;
    int len = S/3; //配列の最大の長さ.
    ll ans = 0;
    for(int i=1;i<=len;i++){
        // 各配列の長さ分あらかじめ3を振っておき、
        // Sに足りない数numをi個の枠に自由に振り分ける
        // numをi個の枠に振り分けるのはnum個の〇とi-1個の仕切り|を並べる並べ方と同じ
        // (num+i-1)C(i-1)
        int num = S - i*3;
        ans += COM(num+i-1,i-1);
        ans %= MOD;
    }
    cout << ans << endl;
    return 0;
}

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

int main() {
    int n;
    string s;
    cin >> n >> s;
    int ans = 1;
    for (int i = 0; i < n - 1; ++i) {
        ans += s[i] != s[i + 1];
    }
    cout << ans << endl;
}


Measured memory_bytes: 3764
//Tuvshee
 
#include<iomanip>
#include<iostream>
#define _USE_MATH_DEFINES
#include<math.h>
#include<cmath>
#include<algorithm>
#include<string>
#include<cctype>
#include<vector>
#include<queue>
using namespace std;
#define I int
#define V void
#define D double
#define F float
#define C char
#define S string
#define B bool
#define L long long
#define rep(n) for(int i=0;i<n;i++)
#define reps(m,n,c) for(int c=m;c<n;c++)
#define repd(m,n,j) for(int j=n;j>m;j--)
#define whL while
#define eL endl
#define oR ||
#define anD &&
#define rtn return
#define pause system("PAUSE")
#define Max 300
#define max(m,n) ((n<m)?m:n)
#define min(m,n) ((n>m)?m:n)
 
V pRec(I m,I n)
{
	reps(0,m,i){
		reps(0,n,j){
			if((i+j)%2)cout<<'.';
			else cout<<'#';
		}
		cout<<eL;
	}
}

int main()
{
	I m,n;
	for(int i=0;;i++){
		cin>>m>>n;
		if(m==0 anD n==0)rtn 0;
		pRec(m,n);
		cout<<eL;
	}
}

Measured memory_bytes: 1152
#include <bits/stdc++.h>
using namespace std;
int main()
{
    std::ios_base::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    if(a%2==0||b%2==0)
    cout<<"Even";
    else
    {
        cout<<"Odd";
    }
}

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

const double PI = acos(-1);
using ll = long long;
using ull = unsigned long long;
const int inf = 2e9;
const ll INF = 2e18;
const ll MOD = 1e9+7;
typedef pair<int,int> P;

#define REP(i,n) for (int i = 0; i < (n); i++)
#define sz(s) (s).size()
#define pb push_back
#define fi first
#define se second


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

  int n;
  string s;
  cin >> n >> s;
  int a = 0;
  REP(i,n) {
    if (s[i] == 'R') a++;
  }
  cout << (a > n - a? "Yes": "No") << endl;
  return 0;
}


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

using namespace std;

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

void bfs(int c[][64], queue<pair<int, int> > q, int w, int h, int bit)
{
    for (; q.size(); q.pop()){
        pair<int, int> pos = q.front();
        
        for (int i = 0; i < 4; i++){
            pair<int, int> npos = make_pair(pos.first + dy[i], pos.second + dx[i]);
            
            if (0 <= npos.first && npos.first < h && 0 <= npos.second && npos.second < w){
                if ((c[npos.first][npos.second] & bit) == 0){
                    c[npos.first][npos.second] |= bit;
                    q.push(npos);
                }
            }
        }
    }
    
}

int main()
{
    int w, h;
    
    while (scanf("%d %d", &w, &h) && w){
        char mp[64];
        int c[64][64] = {0};
        
        queue<pair<int, int> > Bs, Ws;
        
        for (int i = 0; i < h; i++){
            scanf("%s", mp);
            for (int j = 0; j < 64; j++){
                if (isalpha(mp[j])){
                    c[i][j] = -1;
                    if (mp[j] == 'W') Ws.push(make_pair(i, j));
                    else Bs.push(make_pair(i, j));
                }
            }
        }
        
        bfs(c, Bs, w, h, 1);
        bfs(c, Ws, w, h, 2);
        
        int black = 0, white = 0;
        for (int i = 0; i < h; i++){
            for (int j = 0; j < w; j++){
                if (c[i][j] == 1) black++;
                else if (c[i][j] == 2) white++;
            }
        }
        
        printf("%d %d\n", black, white);
    }
    
    return (0);
}

Measured memory_bytes: 1280
/*{{{*/
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<string>
#include<iostream>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include<bitset>
#include<vector>
#include<limits.h>
#include<assert.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB push_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(LL &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const LL &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
LL get_bit(LL x,int v){return (x>>v)&1;}
LL ll,rr;
LL dp[61][2][2];
int main(){
    R(ll,rr);
    for(int i=59;i>=0;i--){
        int low=get_bit(ll,i);
        int hi=get_bit(rr,i);
        if(rr>=(1LL<<i)&&(ll>>(i+1))==0)ADD(dp[i][(rr>>(i+1))!=0][(ll>>i)==0],1);
        REP(j,2)REP(k,2){
            REP(j2,2)REP(k2,j2+1){
                if(!j&&j2>hi)continue;
                if(!k&&k2<low)continue;
                ADD(dp[i][j|(j2<hi)][k|(k2>low)],dp[i+1][j][k]);
            }
        }
    }
    LL an=0;
    REP(i,2)REP(j,2)ADD(an,dp[0][i][j]);
    W(an);
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
using namespace std;
typedef long long ll;

int main(){

    int n; cin >> n;

    vector<int> a, b, c;
    int temp;
    for(int i=0; i<n; i++){
        cin >> temp;
        a.push_back(temp);
    }
    for(int i=0; i<n; i++){
        cin >> temp;
        b.push_back(temp);
    }
    for(int i=0; i<n; i++){
        cin >> temp;
        c.push_back(temp);
    }

    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll cnt = 0;
    for(int i=0; i<n; i++){

        int bt = b[i];

        ll na = lower_bound(a.begin(), a.end(), bt) - a.begin();
        ll nc = c.end() - upper_bound(c.begin(), c.end(), bt);

        cnt += na*nc;
    }

    cout << cnt;

    return 0;
}

Measured memory_bytes: 1784
#include <bits/stdc++.h>
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL)
#define mp make_pair
#define pb push_back
#define fs first
#define sc second

using namespace std;
typedef long long ll;
typedef long double ld;

void bug();

/* BIEN CUC BO BEGIN*/
	ll n, m , k, x, A[100000+2], B[100000+2];
/* BIEN CUC BO END*/

int lb(ll x, int f){
	int l=1, h = (f?n+1:m+1), mid;
	while (l<h){
		mid = (l+h)/2;
		if (f){
			if (x <= A[mid]){
				h = mid;
			} else {
				l = mid+1;
			}
		} else {
			if (x <= B[mid]){
				h = mid;
			} else {
				l = mid+1;
			}
		}
	}
	return l;
}

void solve(){	
	cin >> n >> m >> k;
	for (int i=1; i<=n; ++i){
		cin >> A[i];
	}
	for (int i=1; i<=m; ++i){
		cin >> B[i];
	}
	
	while (k--){
		cin >> x;
		int iA = lb(x,1);
		int iB = lb(x,0);
		
//		cout << iA << " AND " << iB << '\n';
		
		ll ans = LLONG_MAX;
		for (int i=iA; i>=iA-1; --i){
			if (i >= 1 && i <= n){
				for (int j=iB; j>=iB-1; --j){
					if (j >= 1 && j <= m){
						ans = min(abs(x-A[i])+abs(A[i]-B[j]),ans);
						ans = min(abs(x-B[j])+abs(A[i]-B[j]),ans);
					}
				}
			}
		}
		cout << ans << '\n';
	}
}	

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


Measured memory_bytes: 2944
#include <iostream>
#include <iomanip>
#include <string>
#include <stack>
#include <vector>
#include <complex>
#include <math.h>
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <iterator>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <regex>
#include <limits>
#include <time.h>
#include <cstdint>
using namespace std;
using pii  = pair<int,int>;
using ll=long long;
using ld=long double;
#define pb push_back
#define mp make_pair
#define sc second
#define fr first
#define stpr setprecision
#define cYES cout<<"YES"<<endl
#define cNO cout<<"NO"<<endl
#define cYes cout<<"Yes"<<endl
#define cNo cout<<"No"<<endl
#define rep(i,n) for(ll i=0;i<(n);++i)
#define Rep(i,a,b) for(ll i=(a);i<(b);++i)
#define rrep(i,n) for(ll i=n-1;i>=0;i--)
#define rRep(i,a,b) for(ll i=a;i>=b;i--)
#define crep(i) for(char i='a';i<='z';++i)
#define psortsecond(A,N) sort(A,A+N,[](const pii &a, const pii &b){return a.second<b.second;});
#define ALL(x) (x).begin(),(x).end()
#define debug(v) cout<<#v<<":";for(auto x:v){cout<<x<<' ';}cout<<endl;
#define endl '\n'
int ctoi(const char c){
  if('0' <= c && c <= '9') return (c-'0');
  return -1;
}
ll gcd(ll a,ll b){return (b == 0 ? a : gcd(b, a%b));}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll MOD=1000000007;
constexpr ll INF=1000000011;
constexpr ll MOD2=998244353;
constexpr ll LINF = 1001002003004005006ll;
constexpr ld EPS=10e-8;
template <class T, class U> inline bool chmax(T& lhs, const U& rhs) { if (lhs < rhs) { lhs = rhs; return 1; } return 0; }
template <class T, class U> inline bool chmin(T& lhs, const U& rhs) { if (lhs > rhs) { lhs = rhs; return 1; } return 0; }
template<typename T> istream& operator>>(istream& is,vector<T>& v){for(auto&& x:v)is >> x;return is;}
template<typename T,typename U> istream& operator>>(istream& is, pair<T,U>& p){ is >> p.first; is >> p.second; return is;}
template<typename T,typename U> ostream& operator>>(ostream& os, const pair<T,U>& p){ os << p.first << ' ' << p.second; return os;}
template<class T> ostream& operator<<(ostream& os, vector<T>& v){
  for(auto i=begin(v); i != end(v); ++i){
    if(i !=begin(v)) os << ' ';
    os << *i;
  }
  return os;
}

ll A[3007],dp[3007][3007];

int main(){
  ll N,S,ANS=0;
  cin >> N >> S;
  rep(i,N){
    cin >> A[i+1];
  }
  Rep(i,1,N+1){
    rep(j,S+1){
      dp[i][j]+=dp[i-1][j];
      if(j==0){
        dp[i][j]++;
      }
      if(j>=A[i]){
        dp[i][j]+=dp[i-1][j-A[i]];
        if(j==A[i]){
          dp[i][j]++;
        }
      }
      dp[i][j]%=MOD2;
    }
    ANS=(ANS+dp[i][S])%MOD2;
  }
  cout << ANS << endl;
}

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

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

    vector<int> a(n);
    for(int i=0; i<n; i++){
        cin >> a[i];
        a[i] -= 1;
    }

    int ans = 0;
    for(int i=0; i<n; i++){
        if(a[a[i]] == i) ans += 1;
    }
    ans /= 2;
    cout << ans << endl;
    return 0;
}

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

using namespace std;

int main() {
	int k, t, n;
	cin >> k >> t;
	vector<int> a(t + 1, 0);
	for (int i = 1; i <= t; i++) {
		cin >> a[i];
	}
	sort(a.rbegin(), a.rend());
	n = a[0];
	for (int i = 1; i < t; i++) {
		n -= a[i];
	}
	cout << max(0, n - 1) << endl;
	return 0;
}

Measured memory_bytes: 256