akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
  int N;
  cin >> N;
  vector<long long> num(N+2,0);
  for (int i=2; i<N+1; i++){
    int check = i;
    for (int j=2; j<i+1; j++){
      if (check==1) break;
      while (check%j==0){
        num[j] += 1;
        check /= j;
      }
    }
  }
  long long ans = 1;
  for (int i=2; i<N+1; i++){
    ans *= (num[i]+1);
    ans = ans % ((int)pow(10,9)+7);
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
S = list(input())
N = len(S)

if N % 2 == 0:
    m = int(N/2)
    LS = S[:m]
    RS = S[N:m-1:-1]
    ans = 0
    for i in range(m):
        if LS[i] == RS[i]:
            pass
        else:
            ans += 1
else:
    m = int((N+1)/2)
    LS = S[:m-1]
    RS = S[N:m-1:-1]
    ans = 0
    for i in range(m-1):
        if LS[i] == RS[i]:
            pass
        else:
            ans += 1

print(ans)

Measured memory_bytes: 9096
program main
  implicit none
  integer :: n, i, d, x, res
  integer, allocatable :: l(:)
  read (*, *) n, x
  allocate (l(n))
  read (*, *) l(:)
  d = 0
  res = 1
  do i = 1, n
    d = d + l(i)
    if (d <= x) res = res + 1
  end do
  write (*, "(i0)") res
end program main



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll tt = (a + (d - 1)) / d;
    ll at = (c + (b - 1)) / b;
    if (tt < at) cout << "No" << endl;
    else cout << "Yes" << endl;
    return 0;
}


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

using namespace std;

typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;

#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back

int solve(int money,int year,int type,double per,int mine){
	if(type==1){
		rep(i,year){
			money=money+(int)( money * per);
			money-=mine;
		}
		return money;
	}
	else{
		int tmp=0;
		rep(i,year){
			tmp+=(int)( money * per);
			money-=mine;
		}
		return money+tmp;
	}

}



int main(){
	int m;

	cin>>m;

	rep(loop,m){
		int money,year,n;
		cin>>money>>year>>n;
		int type,mine;
		double per;
		int maxi=-1;
		rep(i,n){
			cin>>type>>per>>mine;
			maxi=max(solve(money,year,type,per,mine),maxi);
		}
		cout<<maxi<<endl;
	}
}

//テ・ツ債佚・ツ按ゥテ」ツδサティツ、ツ?・ツ按ゥテ」ツ?ョテ・ツ按・ テ・ツケツエテ・ツ按ゥテァツ篠?テヲツッツ偲・ツケツエテ」ツ?ョテヲツ可凝ヲツ閉ーテヲツ鳴? 

Measured memory_bytes: 1232
#define _CRT_SECURE_NO_WARNINGS

#include <algorithm>
#include <vector>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

class Stack {
public:
	Stack(int n) : s_(n), top_(0){};

	bool isEmpty() { return top_ == 0; }
	bool isFull() { return top_ == s_.size(); }

	void push(int x) {
		if (isFull()) {
			return;
		}
		top_++;
		s_[top_] = x;
	}

	int pop() {
		if (isEmpty()) { return -1; }
		top_--;
		return s_[top_ + 1];
	}

private:
	vector<int> s_;
	size_t top_;
};


int main() {
	char s[1000];

	Stack stack(110);

	while (scanf("%s", s) != EOF) {
		if (s[0] == '+') {
			// 加算
			int rhs = stack.pop();
			int lhs = stack.pop();
			int t = lhs + rhs;
			stack.push(t);
		}
		else if (s[0] == '-') {
			// 減算
			int rhs = stack.pop();
			int lhs = stack.pop();
			int t = lhs - rhs;
			stack.push(t);
		}
		else if (s[0] == '*') {
			// 乗算
			int rhs = stack.pop();
			int lhs = stack.pop();
			int t = lhs * rhs;
			stack.push(t);
		}
		else {
			// スタックに値を追加
			stack.push(atoi(s));
		}
	}

	printf("%d\n", stack.pop());
	
	return 0;
}


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

int main(){
    int k, x, y;
    cin >> k >> x >> y;

    int px = x / abs(x);
    int py = y / abs(y);
    x = abs(x);
    y = abs(y);

    bool flag = false;
    if(x < y){ swap(x,y); flag = true; }

    if(k % 2 == 0 && (x+y) % 2 == 1){
        cout << -1 << endl;
        return 0;
    }

    vector<pair<int, int>> shot;
    int cx = 0, cy = 0;

    // tee
    while(x + y > 2 * k){
             if(x > k){ x -= k; cx += k;}
        else if(y > k){ y -= k; cy += k;}
        shot.push_back({cx, cy});
    }

    // putter
    if((x + y) % 2 == 1){
        if(x + y == k){// Par 1
            cx += x;
            cy += y;
            shot.push_back({cx, cy});
        }
        else{// Par 3
            cx += k;
            shot.push_back({cx, cy});
            int dx = abs(x - k);
            int px = 1;
            if(x - k < 0) px = -1;

            int rem = (2 * k - dx - y) / 2;
            if(dx > y){
                //cout << cy << " " << y << " " << rem << endl;
                cy += y + rem;
                cx += (k - (y + rem)) * px;
                shot.push_back({cx, cy});
                cy -= rem;
                cx += (k - rem) * px;
                shot.push_back({cx, cy});
            }else{
                //cout << cx << " " << dx << " " << rem << endl;
                cx += (dx + rem) * px;
                cy += k - (dx + rem);
                shot.push_back({cx, cy});
                cx -= rem * px;
                cy += k - rem;
                shot.push_back({cx, cy});
            }
        }
    }
    else if(x != 0 || y != 0){// Par 2
        int rem = (2 * k - x - y) / 2;
        rem %= k;
        if(y > x){
            //cout << cx << " " << x << " " << rem << endl;
            cx += x + rem;
            cy += k - (x+rem);
            y  -= k - (x+rem);
            shot.push_back({cx, cy});
            shot.push_back({cx - rem, cy + y});
        }
        else{
            //cout << cy << " " << y << " " << rem << endl;
            cy += y + rem;
            cx += k - (y+rem);
            x  -= k - (y+rem);
            shot.push_back({cx, cy});
            shot.push_back({cx + x, cy - rem});
        }
    }
    
    cout << shot.size() << endl;
    for(auto s : shot){
        if(flag == true) swap(s.first, s.second);
        cout << px * s.first << " " << py * s.second << endl;
    }
    return 0;
}


Measured memory_bytes: 5224
#include<iostream>
#include<stdio.h>
#include<cstring>
#include<cmath>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<unordered_map>
#include<bits/stdc++.h>
#define ll long long 
#define dd double
using namespace std;
const ll MOD = 1e9 + 7; 
 
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  
  char ch;
  cin>>ch;
  if(ch=='A'){
  	cout<<"T"<<endl;
  }
  else if(ch=='T'){
  	cout<<"A"<<endl;
  }
  else if(ch=='C'){
  	cout<<"G"<<endl;
  }
  else if(ch=='G'){
  	cout<<"C"<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 3584
// inputに入力データ全体が入る
function Main(input) {
  input = input.replace('\n', '');
  var n = String(input);

  ans = '';
  for(var i = 0; i < n.length; i++){
    if (n.substr(i, 1) === '1'){
      ans += '9';
    }else{
      ans += '1';
    }
  }

  console.log('%s', ans);

}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 21064
<?php
fscanf(STDIN, "%s", $S);
$arr = str_split($S);

for ($i=0; $i < count($arr); $i++) {
  if($arr[$i] == "R") {
    $arr[$i] = 1;
  } else {
    $arr[$i] = 0;
  }
}
$ans = 0;
for ($i=0; $i < count($arr); $i++) {
  $ans += $arr[$i];
}
if($ans >= 2) {
  if ($arr[1] == 1) {
    echo $ans;
  } else {
    echo 1;
  }
} else {
  echo $ans;
}

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

typedef struct {
	int b;
	int t;
	float r;
	float genri;
} cash;

int main () {
	int n;
	float y,max;
	int maxb;
	while ( cin >> n, n ) {
		//初期化
		max = 0;
		maxb = 0;
		
		cin >> y;
		cash ginko[n];
		for ( int i = 0; i < n; i++ ) {
			cin >> ginko[i].b >> ginko[i].r >> ginko[i].t;
			
			ginko[i].genri = 1;
			if ( ginko[i].t == 1 ) {
				ginko[i].genri = 1.0 + y * ginko[i].r / 100.0;
			} else {
				for ( int j = 0; j < y; j++ ) {
					ginko[i].genri *= 1.0 + ginko[i].r / 100.0;
				}
			}
		}
		max = 0;
		maxb = 0;
		for ( int i = 0; i < n; i++ ) {
			if ( max < ginko[i].genri ) {
				max = ginko[i].genri;
				maxb = ginko[i].b;
			}
		}
		
		cout << maxb << endl;
	}
	return 0;
}

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

using namespace std;

#define F first
#define S second
#define modulo ll (1e9 + 7)

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

void init(){
    cin.tie(0);
    cin.sync_with_stdio(0);
}

const int N = 1e5 + 9, M = 1e6 + 9, OO = 0x3f3f3f3f;
const ll llOO = 0x3f3f3f3f3f3f3f3f;


void go(int tc){

    int a;  cin >> a;
    cout << a  + a * a + a * a * a;



}




int main(){
    init();

//    freopen("in.in", "r", stdin);
//    freopen("out.out", "w", stdout);

    int t = 1, tc = 1;//  cin >> t;
    while(t--)  go(tc++);

}


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

vector<long> v;

int main(){
  long K, N;
  cin >> N >> K;
  for(long i=0; i<N; i++){
    int h; cin >> h;
    v.push_back(h);
  }
  sort(v.begin(), v.end());
  long min=1e9;
  for(long i=0; i<N-K+1; i++){
    if(v[i+K-1]-v[i]<min) min=v[i+K-1]-v[i];
  }
  cout << min << endl;
  return 0;
}

Measured memory_bytes: 1400
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

int main() {
  int A, B;
  cin >> A >> B;
  cout << A * B << endl;
  return 0;
}

Measured memory_bytes: 3560
import bisect

N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = list(map(int,input().split()))

B.sort()
C.sort()

BtoC = [0 for i in range(N)]

for i in range(N-1,-1,-1):
    x = bisect.bisect_right(C,B[i])
    if i == N-1:
        BtoC[i] = N-x
    else:
        BtoC[i] = BtoC[i+1]+N-x

#print(BtoC)

ans = 0

for a in A:
    y = bisect.bisect_right(B,a)
    if y != N:
        ans += BtoC[y]

print(ans)


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

namespace ConsoleApp1
{
    static class DDisjointSetofCommonDivisors
    {
        static void Main(string[] args)
        {
            var ab = Console.ReadLine().Split(' ').Select(x => long.Parse(x)).ToList();
            long a = ab[0];
            long b = ab[1];

            long gcd = Gcd(a, b);

            var answerList = new List<long>();
            for (long i = 2; i * i <= gcd; i++)
            {
                while (gcd % i == 0)
                {
                    answerList.Add(i);
                    gcd /= i;
                }
            }
            if (gcd > 1)
            {
                answerList.Add(gcd);
            }
            Console.WriteLine(answerList.Distinct().Count() + 1);
            Console.ReadLine();
        }

        static long Gcd(long a, long b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            if (a % b == 0)
            {
                return b;
            }
            return Gcd(b, a % b);
        }
    }
}

Measured memory_bytes: 13280
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
map<ll, ll>mp;
int main()
{
	int n;
	cin >> n;
	ll cnt = 0;
	ll ans = 0;
	while (n--)
	{
		ll tmp;
		scanf("%lld", &tmp);
		ll tt = tmp - cnt;
		ans += mp[tt];
		mp[- tmp - cnt]++;
		cnt++;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 26348
import itertools as it
N,M = map(int,input().split())
slk = []
for _ in range(M):
    slk.append(list(map(int,input().split())))
p = list(map(int,input().split()))
#print(N,M)
#print(slk)
#print(p)

s = [i+1 for i in range(N)]
cb = 0
for i in range(N+1):
    cmbi = list(it.combinations(s, i))
    #print('i,cmbi:',i,cmbi)
    for ccmb in cmbi:
        for j,slki in enumerate(slk):
            g = 0
            #print('slki',slki)
            for k in range(slki[0]):
                if slki[k+1] in ccmb:
                    g += 1
            #print('g,p:',g,p[j])
            if g%2 == p[j]:
                pass
            else:
                #print('error')
                break
        else:
            cb += 1
            #print('add succ;',cb)
print(cb)

Measured memory_bytes: 3064
#pragma GCC optimize "O3"

#include<bits/stdc++.h>

using namespace std;

constexpr int N = 20;

int n, ans;
string tmp, ans_rev;
vector<string> words[N+1], cands[N+1];
//vector<bool> vis[N+1];

void init() {
  for(int i = 0; i<=N; ++i)
    words[i].clear(), cands[i].clear();//, vis[i].clear();
  ans = 0;
}
bool valid(const string &tar, const string &s, string &rev) {
  assert(s.size() == tar.size());
  for(size_t i = 0; i<s.size(); ++i) {
    if(rev[s[i]] != -1 && rev[s[i]] != tar[i])
      return false;
    if(rev[tar[i]] != -1 && rev[tar[i]] != s[i])
      return false;
    if(rev[s[i]] == -1 && rev[tar[i]] != -1)
      return false;
    if(rev[tar[i]] == -1 && rev[s[i]] != -1)
      return false;
  }
  return true;
}
void dfs(int l, size_t x, string rev) {
  if(ans > 1)
    return;
  while(l && x >= words[l].size()) {
    x = 0;
    --l;
  }
  if(l == 0) {
    ans_rev = rev;
    ++ans;
    return;
  }
  const string &tar = words[l][x];
  for(size_t j = 0; j<cands[l].size(); ++j) {
    //if(vis[l][j])
    //  continue;
    const string &s = cands[l][j];
    if(valid(tar, s, rev)) {
      string nrev = rev;
      for(size_t i = 0; i<s.size(); ++i) {
        nrev[s[i]] = tar[i];
        nrev[tar[i]] = s[i];
      }
      //vis[l][j] = true;
      dfs(l, x+1, nrev);
      //vis[l][j] = false;
    }
  }
}
void cleanup(vector<string> &v) {
  sort(v.begin(), v.end());
  v.resize(unique(v.begin(), v.end()) - v.begin());
}
void solve() {
  init();
  for(int i = 0; i<n; ++i) {
    cin >> tmp;
    for_each(tmp.begin(), tmp.end(), [](char &c) { c -= 'A'; });
    cands[tmp.size()].push_back(tmp);
  }
  //for(int i = 0; i<=N; ++i)
  //  vis[i].resize(cands[i].size());
  vector<string> sent;
  bool cont = true;
  while(cont) {
    cin >> tmp;
    if(tmp.back() == '.') {
      tmp.pop_back();
      cont = false;
    }
    sent.push_back(tmp);
    for_each(tmp.begin(), tmp.end(), [](char &c) { c -= 'A'; });
    words[tmp.size()].push_back(tmp);
  }
  for(int i = 0; i<=N; ++i)
    cleanup(words[i]);
  dfs(N, 0, string(26, -1));
  assert(ans > 0);
  if(ans == 1) {
    for(auto c : ans_rev)
      if(c != -1) {
        assert(c == ans_rev[ans_rev[c]]);
      }
    for(size_t i = 0; i<sent.size(); ++i) {
      for(auto c : sent[i]) 
        putchar(ans_rev[c - 'A'] == -1 ? c : ans_rev[c - 'A'] + 'A');
      putchar(i+1 == sent.size() ? '.' : ' ');
    }
    puts("");
  } else
    puts("-.");
}
int main() {
  while(scanf("%d", &n) == 1 && n)
    solve();
}

Measured memory_bytes: 3112
N, K = map(int, input().split())

def calc_pro(ini, K):
    ans = 0
    while 1:
        if K <= ini:
            return ans
        else:
            ini *= 2
            ans += 1

ans = 0
for i in range(1,N+1):
    ans += (1/N) * (1/2) ** calc_pro(i,K)
print(ans)

Measured memory_bytes: 3060
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int H, W, h, w;
	cin >> H >> W >> h >> w;
	cout << H * W - W * h - H * w + h * w << "\n";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
vector <int> vec[2100],ths[4];
map<vector <int>,int>mp;
void leg(vector <int> &vec)
{if (vec.size()!=4) assert(0);
	vector <int> ls=vec;
	for (int i=1;i<=4;i++)
	{
		int t=vec[0];vec[0]=vec[1];vec[1]=vec[2];vec[2]=vec[3];vec[3]=t;
		if (ls>vec) ls=vec;
	}
	vec=ls;
}
int gnum(vector <int> &vec)
{
	int ans=0;
	for (int i=1;i<=4;i++)
	{
		if ((vec[0]==vec[(0+i)%4])&&(vec[1]==vec[(1+i)%4])&&(vec[2]==vec[(2+i)%4])&&(vec[3]==vec[(3+i)%4]))
			ans++;
	}
	return ans;
}
int main()
{
	int n;scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		vec[i].resize(4);
		scanf("%d%d%d%d",&vec[i][0],&vec[i][1],&vec[i][2],&vec[i][3]);
		leg(vec[i]);mp[vec[i]]++;
	}
	for (int i=0;i<4;i++) ths[i].resize(4);
	long long ans=0;
	for (int i=1;i<=n;i++)
	for (int j=1;j<i;j++)
	{
		mp[vec[i]]--;mp[vec[j]]--;
		vector <int> x=vec[i],y=vec[j];reverse(x.begin(),x.end());
		for (int d=0;d<4;d++)
		{
			ths[0][0]=x[0];ths[0][1]=x[1];ths[0][2]=y[1];ths[0][3]=y[0];
			ths[1][0]=x[1];ths[1][1]=x[2];ths[1][2]=y[2];ths[1][3]=y[1];
			ths[2][0]=x[2];ths[2][1]=x[3];ths[2][2]=y[3];ths[2][3]=y[2];
			ths[3][0]=x[3];ths[3][1]=x[0];ths[3][2]=y[0];ths[3][3]=y[3];
			long long p=1;
			for (int t=0;t<4;t++)
			{
				leg(ths[t]);
				p*=gnum(ths[t])*mp[ths[t]];
				mp[ths[t]]--;
			}
			ans+=p;
			for (int t=0;t<4;t++) mp[ths[t]]++;
			int ls=y[0];y[0]=y[1];y[1]=y[2];y[2]=y[3];y[3]=ls;
		}
		mp[vec[i]]++;mp[vec[j]]++;
	}
	cout<<ans/3<<endl;
}

Measured memory_bytes: 140032
import java.io.{BufferedReader, InputStream, InputStreamReader, PrintWriter}
import java.util.StringTokenizer

import scala.collection.mutable
import scala.util.Sorting
import math.{abs, max, min}
import scala.collection.mutable.{ArrayBuffer, ListBuffer}
import scala.reflect.ClassTag

object Main {
  val MOD = 1000000007
  val out = new PrintWriter(System.out)
  def solve(): Unit = {
    val sc = new InputReader(System.in)
    val N = sc.nextInt()
    val A = map(N){ _ => sc.nextLong() }
    rep(N - 1)(i => A(i + 1) += A(i))

    val (_, ans) = A minByEx({ s =>
      val x = s
      val y = A(N - 1) - s
      abs(x - y)
    }, 0 until N - 1)

    out.println(ans)
  }


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


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

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

    def nextInt(): Int = next.toInt
    def nextLong(): Long = next.toLong
    def nextChar(): Char = next.charAt(0)
  }

  private def rep(n: Int)(f: Int => Unit): Unit = (0 until n) foreach f

  private def map[@specialized A: ClassTag](n: Int)(f: Int => A): Array[A] = {
    val res = Array.ofDim[A](n)
    (0 until n) foreach (i => res(i) = f(i))
    res
  }

  private implicit class ArrayOpts[A](val as: Array[A]) extends AnyVal {
    def maxByOpt[B: Ordering](f: A => B): Option[A] = {
      if (as.nonEmpty) Some(as.maxBy(f)) else None
    }

    def grpBy[K](f: A => K): mutable.Map[K, ArrayBuffer[A]] = {
      val map = mutable.Map.empty[K, ArrayBuffer[A]]
      rep(a => map.getOrElseUpdate(f(a), ArrayBuffer()) += a)
      map
    }

    def rep(f: A => Unit): Unit = {
      as.indices foreach (i => f(as(i)))
    }

    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      var sum = num.zero
      rep(a => sum = num.plus(sum, f(a)))
      sum
    }

    def minByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.lt)
    }

    def maxByEx[B](f: A => B, ixRange: Range = as.indices)(implicit cmp: Ordering[B]): (A, B) = {
      limit(f, ixRange)(cmp.gt)
    }

    private def limit[B](f: A => B, ixRange: Range)(cmp: (B, B) => Boolean): (A, B) = {
      var limA = as(ixRange.head)
      var limB = f(limA)

      for (i <- ixRange.tail) {
        val a = as(i)
        val b = f(a)
        if (cmp(b, limB)) {
          limA = a
          limB = b
        }
      }
      (limA, limB)
    }
  }

  private implicit class IterableOpts[A](val as: Iterable[A]) extends AnyVal {
    def sumBy[B](f: A => B)(implicit num: Numeric[B]): B = {
      as.foldLeft(num.zero)((acc, a) => num.plus(acc, f(a)))
    }
  }
}


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

#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;

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

    int n;
    cin >> n;

    vector<vector<pair<int, int>>> g(n);

    rep(i, 0, n) {
        int u, k;
        cin >> u >> k;

        rep(j, 0, k) {
            int v, c;
            cin >> v >> c;
            g[u].push_back(make_pair(v, c));
        }
    }

    vector<bool> seen(n, false);
    vi ds(n, INT_MAX);
    priority_queue<pair<int, int>> pq;

    ds[0] = 0;
    pq.push(make_pair(0, 0));  // (cost, v)

    while (!pq.empty()) {
        pair<int, int> p = pq.top();
        pq.pop();

        int u = p.second;
        int minv = -p.first;

        if (seen[u]) { continue; }

        seen[u] = true;

        for (auto itr = g[u].begin(); itr != g[u].end(); ++itr) {
            int v = (*itr).first;
            int c = (*itr).second;

            if (!seen[v] && c != INT_MAX && ds[v] > minv + c) {
                ds[v] = minv + c;
                pq.push(make_pair(-ds[v], v));
            }
        }
    }

    rep(i, 0, n) { cout << i << " " << ds[i] << endl; }

    return 0;
}


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

int p[60], c[60];

int main(){
    int n, r;
    while(cin >> n >> r && (n | r)){
        for(int i=0;i<r;i++)
            cin >> p[i] >> c[i];
        
        int target = 1;
        for(int i=r-1;i>=0;i--){
            int t = p[i] - 1 + c[i];
            
            if(target > t)
                continue;
        
            if(target <= c[i]){
                target = p[i] - 1 + target;
            } else {
                target = target - c[i];
            }
        }
        
        cout << n + 1 - target << endl;
    }
    
    return 0;
}

Measured memory_bytes: 1160
fun main(args: Array<String>) {
    abc054b()
}

fun abc054b() {
    val (n, m) = readLine()!!.split(" ").map { it.toInt() }
    val aList = (1..n).map { readLine()!! }
    val bList = (1..m).map { readLine()!! }

    // 適当に全探索してみる
    for (i in 0..n - m) {
        for (j in 0..n - m) {
            val aTrim = aList.slice(i until i + m).map { it.substring(j until j + m) }
            if (aTrim == bList) return println("Yes")
        }
    }

    println("No")
}


Measured memory_bytes: 37820
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int[] d=new int[n];
		for(int i=0;i<n;i++){
			d[i]=sc.nextInt();
		}
		Arrays.sort(d);
		int p=n/2;
		int q=n/2-1;
		if(d[p]==d[q]){
			System.out.println(0);
		}else{
			System.out.println(d[p]-d[q]);
		}
	}
}

Measured memory_bytes: 53292
#include <stdio.h>

#define N 21
#define Q 200

int A[N], M[Q];
int n, q;

int solve(int p, int t) {

	if (t == 0)
		return 1;
	if (p >= n || p < 0)
		return 0;
	if (solve(p + 1, t - A[p]) || solve(++p, t))
		return 1;

	return 0;
}

int main() {
	int i;

	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &A[i]);
	scanf("%d", &q);
	for (i = 0; i < q; i++)
		scanf("%d", &M[i]);

	for (i = 0; i < q; i++) {
		if (solve(0, M[i]))
			printf("yes\n");
		else
			printf("no\n");
	}

	return 0;
}

Measured memory_bytes: 580
#n,k=gets.split(' ').map(&:to_i)
#h=gets.split(' ').map(&:to_i)
#tajigen = Array.new(4) { Array.new(2,0) }
k=gets.to_i
q = Queue.new

for i in 1..9
  q.push(i)
end
x=0
for i in 1..k
  x=q.pop
  if x%10 == 0
    q.push(10*x)
    q.push(10*x+1)
  elsif x%10 ==9
    q.push(10*x+8)
    q.push(10*x+9)
  else
    q.push(10*x+(x%10)-1)
    q.push(10*x+(x%10))
    q.push(10*x+(x%10)+1)
  end
end

puts x


Measured memory_bytes: 3784
#include <iostream>
#define MAX_N 1299709 + 1
using namespace std;

bool t[MAX_N];
int k;

bool isPrime(int x) {
  if(x == 2) return true;
  if(x < 2 || x % 2 == 0) return false;
  int i = 3;
  while(i * i <= x) {
    if(x % i == 0) return false;
    i += 2;
  }
  return true;
}

void table() {
  for(int i = 1; i < MAX_N; ++i) {
    if (isPrime(i)) t[i] = 1;
  }
}

void solve() {
  int p = k, n = k;
  while(t[p] != 1) p--;
  while(t[n] != 1) n++;
  cout << n - p << endl;
}

int main() {
  table();
  while(cin >> k && k) {
    solve();
  }
  return 0;
}



Measured memory_bytes: 4380
//:)
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <queue>
#include <sstream>
#include <stack>
#include <time.h>
#include <vector>
#include <complex>
#include <map>
#include <set>
#include <iomanip>
#include <math.h>
#include <stdlib.h>
#include <list>
#include <utility>
#include <memory>
#include <cstring>
#include <fstream>
#include <numeric>
#include <assert.h>
#include <bits/stdc++.h>
using namespace std;
int main() {
	string s,t;
	cin>>s>>t;
	if (s==t) {
		cout<<"Yes";
		return 0;
	}
	for (int i=1; i<s.size(); i++) {
		string p="";
		p=s.substr(i,s.size()-i+1)+s.substr(0,i);
		if (p==t) {
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
n = gets.to_i
e = []

def max(x,y)
  return x > y ? x : y
end

done = []
(n+1).times {
  e << []
  done << false
}

e2 = []
(n-1).times { |i|
  a,b = gets.split.map {|x| x.to_i}
  e[a] << [b,i]
  e[b] << [a,i]
  e2 << [a,b,-1]
}
maxe = 0
ind = 0
e.each_with_index { |_e, index|
  if _e.size > maxe
    ind = index
    maxe = _e.size
  end
}

puts maxe



def paint(node, color, done, e, e2)
  cur_col = 1
  done[node] = true
  e[node].each_with_index { |v|
    dst = v[0]
    if (done[dst] == false)
      if cur_col == color
        cur_col += 1
      end
      e2[v[1]][2] = cur_col
      paint(dst, cur_col, done, e, e2)
      cur_col += 1
    end
  }
end

que = []
que << [ind,-1]

while que.size > 0
  node,color = que.shift
  cur_col = 1
  done[node] = true
  e[node].each_with_index { |v|
    dst = v[0]
    if (done[dst] == false)
      if cur_col == color
        cur_col += 1
      end
      e2[v[1]][2] = cur_col
      que << [dst, cur_col]
      cur_col += 1
    end
  }
end
#paint(ind, -1, done, e, e2)

e2.each { |v|
  puts v[2]
}


Measured memory_bytes: 43516
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template<class F>auto recursive(F f){return[f](auto...a){return f(f,a...);};}
template<class I,class V=typename I::value_type>V sum_up(const I&l,const I&r){V v;for(I i=l;i!=r;i++)v=i==l?*i:v+*i;return v;}
template<class I,class T=iterator_traits<I>>I operator+(I it,int n){for(int i=0;i<n;i++)it++;return it;}
template<class I,class T=iterator_traits<I>>I operator-(I it,int n){for(int i=0;i<n;i++)it--;return it;}
template<class T>using rev_priority_queue=priority_queue<T,vector<T>,greater<T>>;
template<class T>using vector2d=vector<vector<T>>;
struct fixprec{int x;fixprec(int d):x(d){}};
ostream&operator<<(ostream&o,fixprec f){return o<<fixed<<setprecision(f.x);}
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    char C;
    cin >> C;
    cout << ++C << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define INF 1e15

using namespace std;

int n, a[20];
int id[2010][2010], tot;
ll dp[20][20][1 << 18];

ll solve(int l, int r, int x, int y)
{
	if (l + 1 == r) return 0;
	if (!id[x][y]) id[x][y] = ++tot;
	if (dp[l][r][id[x][y]] != -1) return dp[l][r][id[x][y]];
	ll ret = INF;
	for (int i = l + 1; i < r; i++)
		ret = min(ret, solve(l, i, x, x + y) + solve(i, r, x + y, y) + 1ll * a[i] * (x + y));
	return dp[l][r][id[x][y]] = ret;
}

int main()
{
	ios::sync_with_stdio(false);
	cin >> n;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
	memset(dp, -1, sizeof dp);
	cout << solve(1, n, 1, 1) + a[1] + a[n] << endl;
	return 0;
}


Measured memory_bytes: 833920
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
int C[3][3];
bool solve(int a1,int a2,int a3,int b1,int b2,int b3) {
 if(a1+b1!=C[0][0]||a1+b2!=C[0][1]||a1+b3!=C[0][2]||a2+b1!=C[1][0]||a2+b2!=C[1][1]||a2+b3!=C[1][2]||a3+b1!=C[2][0]||a3+b2!=C[2][1]||a3+b3!=C[2][2] ) return false;
 return true;
}
int main() {
  for(int i=0;i<3;i++) {
    for(int j=0;j<3;j++) {
        cin >> C[i][j];
    }
  }
  bool flag = false;
  for(int a1=0;a1<=100;a1++) {
    int b1 = C[0][0]-a1;
    int b2 = C[0][1]-a1;
    int b3 = C[0][2]-a1;
    int a2 = C[1][0]-b1;
    int a3 = C[2][0]-b1;
    if(solve(a1,a2,a3,b1,b2,b3)) {
        flag = true;
        break;
    }
  }
  if(flag) puts("Yes");
  else puts("No");
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;


int main() {
    int n, k, c;
    string s;
    cin >> n >> k >> c >> s;
    ++c;
    vector<int> dp1(n + 1), dp2(n + 1);
    for (int i = 1; i <= n; ++i) {
        dp2[i] = max(dp1[i - 1], dp2[i - 1]);
        if (s[i - 1] == 'o') {
            dp1[i] = max(dp1[i], 1);
            if (i > c) dp1[i] = max(dp1[i], max(dp1[i - c], dp2[i - c]) + 1);
        }
    }
    if (max(dp1[n], dp2[n]) > k) {
        cout << endl;
        return 0;
    }
    vector<bool> app(n + 1);
    for (int i = n; i > 0; --i) {
        if (dp1[i] > 0 && !app[dp1[i]]) {
            for (int j = i - 1; j >= max(0, i - c + 1); --j) {
                if (dp1[j] < dp1[i]) dp1[j] = -1;
            }
            app[dp1[i]] = true;
        }
    }
    vector<vector<int>> a(n + 1);
    for (int i = 1; i <= n; ++i) {
        if (dp1[i] >= 1) a[dp1[i]].push_back(i);
    }
    for (int i = 1; i <= n; ++i) {
        if (a[i].size() == 1) cout << a[i][0] << '\n';
    }
    return 0;
}

Measured memory_bytes: 14212
import numpy as np
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
 

N, M, K = map(int, readline().split())
AB = np.array(read().split(), np.int32)
A = [0] + np.cumsum(AB[:N]).tolist()
B = [0] + np.cumsum(AB[N:]).tolist()
assert (N == len(A) - 1) and (M == len(B) - 1)
 
ans = 0
left = M
for i in range(len(A)):
    if A[i] > K:
        break
 
    while A[i] + B[left] > K:
        left -= 1
 
    ans = max(ans, left + i)

print(ans)

Measured memory_bytes: 53436
import sys
input = sys.stdin.readline
from collections import defaultdict


def read():
    S = input().strip()
    T = input().strip()
    return S, T


def solve(S, T):
    N = len(S)
    u2t = dict()
    t2u = dict()
    for i in range(N):
        if S[i] not in u2t:
            u2t[S[i]] = T[i]
        elif u2t[S[i]] != T[i]:
            return "No"
        if T[i] not in t2u:
            t2u[T[i]] = S[i]
        elif t2u[T[i]] != S[i]:
            return "No"
    return "Yes"


if __name__ == '__main__':
    inputs = read()
    outputs = solve(*inputs)
    if outputs is not None:
        print("%s" % str(outputs))


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

int main() {
  int N, Y;
  cin >> N >> Y;

  for (int x = 0; x <= N; x++) {
    for (int y = 0; y <= N-x; y++) {
      int z = N - (x + y);
      if ((x+y+z)==N) {
        int sum = 10000*x + 5000*y + 1000*z;
        if (sum==Y) {
          cout << x << " " << y << " " << z << endl;
          return 0;
        }
      }
    } 
  }
  cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <stack>
#include <iomanip>
#include <numeric>
#include <bitset>

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

using namespace std;

typedef long long ll;

ll extgcd(ll a, ll b, ll &x, ll &y) {
    ll d = a;
    if (b != 0) {
        d = extgcd(b, a%b, y, x);
        y -= (a/b) * x;
    } else {
        x = 1; y = 0;
    }
    return d;
}

ll modinv(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

ll mod_comb(ll n, ll r, ll mod) {
    ll ans_mul = 1, ans_div = 1;

    for (int i = 0; i < r; i++) {
        ans_mul *= (n-i);
        ans_div *= (i+1);
        ans_mul %= mod;
        ans_div %= mod;
    }
    return ans_mul * modinv(ans_div, mod) % mod;
}

int main () {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << fixed;

  const ll mod = ll(1e9) + 7;

  ll x, y;
  cin >> x >> y;

  if ( (x+y) % 3 != 0 ) {
    cout << 0 << endl;
    return 0;
  }

  // n: 移動回数
  ll n = (x+y)/3;

  // 1回の移動で(x, y) の差は最大で1広がるので
  if ( abs(x-y) > n ) {
    cout << 0 << endl;
    return 0;
  }

  ll diff = abs(x-y);

  ll s = (diff + n) / 2;
  ll t = n - s;

  // ans = nCs mod 1e9+7

  cout << mod_comb(n, s, mod) << endl;

  return 0;
}


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

typedef long long ll;
const ll INF = 1010000000000000017LL;
const ll MOD = 1000000007LL;

#define REP(i, n) for(ll i = 0 ; i < n; i++)

//#define DEBUG(fmt, ...)
#define DEBUG(fmt, ...) fprintf(stderr, fmt "\n", ##__VA_ARGS__)

int main(){
    std::cout<<std::fixed<<std::setprecision(10);

    ll N;

    cin >> N;

    ll total = 0;
    for(ll i = 1; i <= N; i++ ){
        if( i % 3 == 0 && i % 5 == 0 ){
        }else if( i % 3 == 0 ){

        }else if( i % 5 == 0){
        }else{
            total += i;
        }
    }

    cout << total << endl;

}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
int read();

int fa[200005], ch[200005][2], w[200005][2], c[200005];
struct P {
    long long l, r;
};
vector<P> p[200005], tmp;

void ins(int u, long long l, long long r) {
    if (!p[u].size() || r < (--p[u].end())->r) p[u].push_back((P){l, r});
}

bool dfs(int u, long long x) {
    if (!c[u]) return p[u].clear(), p[u].push_back((P){0, 0}), 1;
    int L, R, Wl = w[u][0], Wr = w[u][1];
    if (!dfs(L = ch[u][0], x) || !dfs(R = ch[u][1], x)) return 0;
    if (p[L].size() > p[R].size()) swap(L, R), swap(Wl, Wr);

    tmp.clear(), p[u].clear();
    int i, j;
    for (i = 0, j = -1; i < p[L].size(); ++i) {
        long long tl = p[L][i].l + Wl, tr = x - p[L][i].r - (Wl + Wr);
        while (j + 1 < p[R].size() && p[R][j + 1].l <= tr) ++j;
        if (j < 0) continue;
        if (!tmp.size() || p[R][j].r + Wr < (--tmp.end())->r)
            tmp.push_back((P){tl, p[R][j].r + Wr});
    }

    for (i = 0, j = tmp.size() - 1; i < tmp.size() && j >= 0;)
        if (tmp[i].l < tmp[j].r)
            ins(u, tmp[i].l, tmp[i].r), ++i;
        else if (tmp[i].l > tmp[j].r)
            ins(u, tmp[j].r, tmp[j].l), --j;
        else {
            tmp[i].r <= tmp[j].l ? ins(u, tmp[i].l, tmp[i].r)
                                 : ins(u, tmp[j].r, tmp[j].l);
            ++i, --j;
        }
    while (j >= 0) ins(u, tmp[j].r, tmp[j].l), --j;
    while (i < tmp.size()) ins(u, tmp[i].l, tmp[i].r), ++i;

    return p[u].size();
}
int main() {
    int n = read();
    for (int i = 2; i <= n; ++i)
        fa[i] = read(), ch[fa[i]][c[fa[i]]] = i, w[fa[i]][c[fa[i]]++] = read();
    long long l = 0, r = 40000000000, rs = r, m;
    while (l <= r) dfs(1, m = l + r >> 1) ? r = m - 1, rs = m : l = m + 1;
    printf("%lld\n", rs);
    return 0;
}

int read() {
//	freopen("data.txt","r",stdin);
    int x = 0, f = 1;
    char c = getchar();
    while (c < '0' || c > '9') f = (c == '-') ? -1 : f, c = getchar();
    while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
    return x * f;
}

Measured memory_bytes: 33628
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <sstream>
#include <unordered_map>
#include <vector>


#define INF 4000000000000000000LL
#define MOD 1000000007
#define ALL(x) std::begin(x), std::end(x)


int main(int argc, char** argv)
{
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(0);

  std::cout << std::fixed << std::setprecision(6);
  std::cerr << std::fixed << std::setprecision(6);

  int N;

  std::cin >> N;

  std::vector<std::string> a(N);

  int C = 0, BA = 0, B = 0, A = 0;

  for (auto& s : a) {
    std::cin >> s;

    for (int i = 0, size = s.size(); i < size - 1; i ++)
      if (s[i] == 'A' && s[i + 1] == 'B')
        C ++;
    
    if (s[0] == 'B' && s.back() == 'A') {
      BA ++;
    }
    else if (s[0] == 'B') {
      B ++;
    }
    else if (s.back() == 'A') {
      A ++;
    }
  }

  if (BA >= 2) {
    C += BA - 1;

    BA = 1;
  }

  if (BA && A && B) {
    C += 2;

    BA --;
    A --;
    B --;
  }

  int x = std::min(A, B);

  A -= x;
  B -= x;
  C += x;

  if (BA && A)
    C ++;
  
  if (BA && B)
    C ++;

  std::cout << C << std::endl;

  return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main() {
    int h, w, n, x, y, a, m = 0;
    cin >> h >> w >> n;
    int d[h][w];
    for (int i = 0; i < h; i++)
        for (int j = 0; j < w; j++) d[i][j] = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> x >> y >> a;
        if (a == 1)
        {
            for (int j = 0; j < x; j++)
                for (int k = 0; k < w; k++) d[j][k]++;
        }
        else if (a == 2)
        {
            for (int j = x; j < h; j++)
                for (int k = 0; k < w; k++) d[j][k]++;
        }
        else if (a == 3)
        {
            for (int j = 0; j < h; j++)
                for (int k = 0; k < y; k++) d[j][k]++;
        }
        else
        {
            for (int j = 0; j < h; j++)
                for (int k = y; k < w; k++) d[j][k]++;
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
            if (d[i][j] == 0) m++;
    }
    cout << m;
}

Measured memory_bytes: 3676
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int INF=2147483647;
const double pi=3.1415926535897932384626;
inline ll read(){
	ll x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9'){
		if(ch=='-') f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9'){
		x=(x<<1)+(x<<3)+(ch^48);
		ch=getchar();
	}
	return x*f;
}
ll a;
string b;
int main(){
	a=read();
	cin>>b;
	int x=(b[0]-'0')*100,y=(b[2]-'0')*10,z=b[3]-'0';
	printf("%lld\n",a*(x+y+z)/100);
	return 0;
}


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

using namespace std;

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep2(i,n) for(int i=1;i<=(int)(n);i++)
#define rep3(i,n) for(int i=0;i<=(int)(n);i++)
#define REP(i,m,n) for(int i=m;i<(int)(n);i++)
#define repll(i,n) for(ll i=0;i<(ll)(n);i++)
#define repll2(i,n) for(ll i=1;i<=(ll)(n);i++)
#define REPLL(i,m,n) for(ll i=m;i<(ll)(n);i++)
#define INF (int)1e9  //
#define LINF (ll)4e18  //
#define MOD (int)(1e9)+7
#define MP make_pair
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define PI 3.1415926535898

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

int main() {
    int n, l;
    cin >> n >> l;
    string s[n];
    rep(i, n) cin >> s[i];
    sort(s, s + n);
    rep(i, n) cout << s[i];
    cout << endl;

    return 0;
}



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

int main(){
    string s,c;
    cin>>s;
    c.resize(100000);
    int sum1=0;
    for(int i=0;i<s.size();i++){
        if(i%2==0){
            c[i]='0';
        }
        else{
            c[i]='1';
        }
        if(s[i]==c[i]){
            sum1++;
        }
        else{
        }
    }

    if(2*sum1<=s.size()){
        cout<<sum1<<endl;
    }
    else{
        cout<<s.size()-sum1<<endl;
    }

    return 0;
}


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

using namespace std;
typedef long long int ll;
typedef pair<int, int> ii;
#define DEBUG freopen("in.txt", "r", stdin);

struct fastio {
    fastio() {
        ios::sync_with_stdio(false);
        cout << setprecision(10) << fixed;
        cin.tie(0);
    }
};

fastio _fast_io;

const int mod = 1e9 + 7;
const int N = 1e5 + 5;
string s;
ll acnt[N];
ll ccnt[N];
ll qcnt[N];
ll ans, a, c, q;
ll p[N];

void init() {
    p[0] = 1;
    for (int i = 1; i < N; ++i) {
        p[i] = p[i - 1] * 3 % mod;
    }
}

inline static ll pp(int x) {
    if (x <= 0) return 1;
    return p[x];
}

int main() {
    init();
    cin >> s;
    int n = s.length();
    for (int i = 0; i < n; ++i) {
        char C = s[i];
        if (C == 'A') {
            ++a;
        } else if (C == 'C') {
            ++c;
        } else if (C == '?') {
            ++q;
        }
        acnt[i] = a;
        ccnt[i] = c;
        qcnt[i] = q;
    }
    for (int i = 0; i < n; ++i) {
        if (s[i] == 'B' || s[i] == '?') {
            ll left = acnt[i];
            ll lq = qcnt[i] - (s[i] == '?' ? 1 : 0);
            ll right = c - ccnt[i];
            ll rq = q - qcnt[i];
            ans = (ans + left * right % mod * pp(lq + rq) % mod) % mod;
            ans = (ans + left * rq % mod * pp(lq + rq - 1) % mod) % mod;
            ans = (ans + right * lq % mod * pp(lq + rq - 1) % mod) % mod;
            ans = (ans + lq * rq % mod * pp(lq + rq  - 2) % mod) % mod;
        }
    }

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


Measured memory_bytes: 6888
// #define _CRT_SECURE_NO_WARNINGS
// #define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <cmath>
#include <cstdlib>
#include <functional>
#include <locale>
#include <cctype>
#include <sstream>
#include <iomanip>	// 10????????? cout << setprecision(10) << double;
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef map<int, int> MAPII;
typedef multimap<int, char, greater<int> > MuMAPIC;
typedef vector<pair<int, int> > VPII;
typedef multimap<int, string, greater<int> > MuMIS;

#define MP make_pair
#define FAST_IO  cin.tie(0); ios::sync_with_stdio(false);
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
//for gcc (???test)
// #define FOREACH_IT(it,c) for(typeof(c)::iterator it=(c).begin(); it!=(c).end(); ++it)
//for Visual Studio
#define foreach_it(type,it,c) for(type::iterator it=c.begin(),c_end=c.end();it!=c_end;++it)
// for Debug.
#define DUMP_VVI(b) FOR(i,0,b.size()){FOR(j,0,b[i].size())printf("%d ",b[i][j]);puts("");}
#define D_OUT(str,value) if(dbgF){cout<<str<<" : "<<value<<endl;}
// ??\??????push_back(d)???array[d]???????????????1?????§?????????
// int INPUT_INT() {int d;cin>>d;return d;}
template<class T>T IN() { T d; cin >> d; return d; }
// ?????§??¬?´???°???Greatest Common Divisor???
LL gcd(LL a, LL b) { return (b > 0) ? gcd(b, a%b) : a; }
// ????°???¬?????°???Least Common Multiple???
LL lcm(LL a, LL b) { return a / gcd(a, b) * b; }
// Y??´??????????????´?????????
bool uruu(LL Y) { return (((Y % 4 == 0 && Y % 100 != 0) || Y % 400 == 0) ? true : false);}

// ------------------- include, typedef, define END. -------------------

int main() {
	FAST_IO;
	// for D_OUT(str, value)  ... cout<< str <<" : "<< value <<endl;
	bool dbgF = true;

	//??????????????????????????????.
	int n, k, p;
	LL ans = 0;
	cin >> n;
	FOR(i, 0, n) {
		cin >> k >> p;
		// ex. 2 10
		if (k < p) {
			ans = k;
		}
		else {
			ans = k%p;
			if (ans == 0) {
				ans = p;
			}
		}

		cout << ans << endl;
		ans = 0;
	}


	//puts("");
	return 0;
}

Measured memory_bytes: 1188
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<int(n);++i)
#define updmax(dp,x) dp=(dp.first == 0 ? x : max(dp,x))

using P = pair<int,int>;

int main(void){
    int n;
    while(cin>>n, n){
        vector<int> p(n);
        rep(i,n) cin>>p[i];
        map<int,P> cur; // cur[coin] = <get,pay>
        cur[0] = {0,0};
        rep(i,n){
            map<int,P> nxt;
            for(auto &itr : cur){
                int coin = itr.first;
                int k = itr.second.first;
                int pay = itr.second.second;
                updmax(nxt[coin], P(k,pay));
                pay -= p[i];
                int mod = p[i]%500;
                if(p[i]%1000 == 0){
                    if(coin>=500) updmax(nxt[coin-500], P(k+1,pay));
                }else if(p[i]%1000 == 500){
                    updmax(nxt[coin], P(k+1,pay));
                }else if(p[i]%1000 <= 500){
                    updmax(nxt[coin+500-mod], P(k+1, pay));
                }else if(mod <= coin){
                    updmax(nxt[coin-mod], P(k+1,pay));
                }else{
                    updmax(nxt[coin+500-mod], P(k,pay));
                }
            }
            cur = move(nxt);
        }

        P res = {0,0};
        for(auto itr : cur){
            res = max(res,itr.second);
        }
        cout<<res.first<<" "<<-res.second<<endl;
    }
    return 0;
}



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

int main()
{
    string s,t;
    cin>>s>>t;
    string ss=t.substr(0,s.size());
    //cout<<ss<<endl;
    if(t.size()==s.size()+1 && ss==s) puts("Yes");
    else puts("No");
    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <cmath>
#include <map>
#include <set>
#include <string>
#include <bitset>
#include <utility>
#include <numeric>
#include <queue>
#include <stack>

using ll = long long;
using namespace std;

constexpr int MOD = 1e9 + 7;
constexpr ll MOD_LL = ll(1e9 + 7);

int main(void) {
	string s, t;
	cin >> s >> t;
	
	int sn = (int)s.size(); 
	int tn = (int)t.size();
	
	vector< pair<int, int> > p;
	bool match = true;
	
	for(int i = 0; i < sn; ++i) {
		int cnt = 0;
		match = true;
		
		for(int j = 0; j < tn; ++j) {
			if( s[i + cnt] == '?' || s[i + cnt] == t[j] ) {
				cnt++;
				continue;
			}
			
			if( s[i + cnt] != '?' && s[i + cnt] != t[j] ) {
				match = false; 
				break;
			}
		}
		
		if( match ) {
			p.push_back( {i, i + cnt} );
		}
	}
	
	vector<string> ans;
	
	if( (int)p.size() ) {
		for(int i = 0; i < (int)p.size(); ++i) {
			string tmp = "";
			int x = 0;
			
			for(int j = 0; j < sn; ++j) {
				if( j >= p[i].first && j < p[i].second ) {
					tmp += t[x];
					x++;
				} else {
					if( s[j] == '?' ) {
						tmp += 'a';
					} else {
						tmp += s[j];
					}
				}
			}
			
			ans.push_back(tmp);
		}
		
		sort(ans.begin(), ans.end());
		
		cout << ans.front();
		
	} else {
		cout << "UNRESTORABLE";
	}
	
	cout << endl;
	
	return 0;
}


Measured memory_bytes: 3612