akhauriyash/Code-Regression huggingface dataset:
#define  _CRT_SECURE_NO_WARNINGS
#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

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

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

unsigned long xor128() {
	static unsigned long x = 123456789, y = 362436069, z = 521288629, w = time(NULL);
	unsigned long t = (x ^ (x << 11));
	x = y; y = z; z = w;
	return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}

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

#define int ll
void solve(){
	int n;
	cin >> n;
	vector<pair<long double, long double>> inputs;
	REP(i, n) {
		long double rad;
		cin >> rad;
		long double x = rad;
		REP(q, inputs.size()) {
			long double now_go = inputs[q].second;
			now_go += sqrt(pow(rad + inputs[q].first, 2) - pow(rad - inputs[q].first, 2));
			x = max(x, now_go);
		}
		inputs.push_back(mp(rad, x));
	}
	long double ans = 0;
	REP(i, inputs.size()) {
		ans = max(ans, inputs[i].first + inputs[i].second);
	}
	cout << ans << endl;
	return;
}

#undef int
int main() {
	init();
	solve();
}


Measured memory_bytes: 3352
#include<bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds;
using namespace std;
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
#define ll long long 
#define endl "\n"
#define scn(n) scanf("%d",&n)
#define lscn(n) scanf("%lld",&n)
#define lpri(n) printf("%lld",n)
#define pri(n) printf("%d",n)
#define pln() printf("\n")
#define priln(n) printf("%d\n",n)
#define lpriln(n) printf("%lld\n",n)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define pb push_back     
#define mp make_pair
#define F first
#define S second
#define gcd __gcd
#define inf INT_MAX
#define ninf INT_MIN
const int mod=1e9+7;         
const int N=2e6+4;
 
int main()
{	
	ll n; lscn(n);

	vector<int> v;

	while(n>0)
	{
		//they are using a base notation in which [1,2,..,b] are allowed and in practice
		//[0,1,...,b-1] are allowed, hence subtract 1 to get the required last digit.

		n--;

		v.pb(n%26);

		n/=26; //right shift for base 26
	}

	reverse(v.begin(),v.end());

	for(int it: v)
	cout<<(char)('a'+it);

	return 0;
}                   

Measured memory_bytes: 3676
import scala.io.StdIn

object Main extends App {
  val out = new java.io.PrintWriter(System.out)

  val n = StdIn.readLine.toInt
  val st = Iterator.continually(StdIn.readLine)
          .take(n-1)
          .map(_.split(" ").map(_.toInt))
          .toArray

  for(i <- 0 until n) {
    // var t = 0
    // for(j <- i until n-1) {
    //   t = if(t < st(j)(1)) st(j)(1)
    //     else if (t%st(j)(2) == 0) t
    //     else t + st(j)(2) - t % st(j)(2)
    //   t += st(j)(0)
    // }
    val time = st.drop(i)
      .foldLeft(0,i)((acc,e) => {
        val s = st(acc._2)(1)
        val f = st(acc._2)(2)

        val t = if(acc._1 < s) s
          else if (acc._1 % f == 0) acc._1
          else acc._1 + f - acc._1 % f

        (t + st(acc._2)(0), acc._2 + 1)
      })
    out.println(time._1)
  }

  out.flush
}

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


int main() {
  int A, B, i=1;
  cin >> A >> B;
  if(B == 1){
    cout << 0 << endl;
    return 0;
  }
  if(A >= B){
    cout << 1 << endl;
    return 0;
  }
  
  while(true){
    if(((A-1)*i + A) >= B){
      cout << i+1 << endl;
      return 0;
    }
    i++;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef _DEBUG
#define dlog(str) cout << "====" << str << endl;
#else
#define dlog(str)
#endif
#define INF 999999999
#define MOD 1000000007
#define REP(i, n) for(int i = 0, i##_l = (n); i < i##_l; i++)
#define FOR(i, s, e) for(int i = s, i##_l = (e); i < i##_l; i++)
#define LLI long long int
#define _min(a, b) ((a < b) ? a : b)
#define _max(a, b) ((a < b) ? b : a)
#define chmax(a, b) a = _max(a, b)
#define chmin(a, b) a = _min(a, b)
#define bit(a, shift) ((a>>shift)&1))
#define pm(a) ((a) ? 1 : -1)
#define SORT(v) sort(v.begin(), v.end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
// int 2.14E±9    lli 9.2E±18    double 1.7E±380

int main() {
    cout << fixed << setprecision(10);
    int N, K;
    cin >> N;
    vector<pair<int, int>> a(N);
    REP(i, N) {
        cin >> a[i].first;
        a[i].second = i;
    }
    SORT(a);

    REP(i, N) {
        cout << a[i].second + 1 << " ";
    }
    return 0;
}

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

int main(){
  int A,B,C,D;
  cin>>A>>B>>C>>D;
  
  if (A+B>C+D){
    cout<<"Left"<<endl;
  }
  if (A+B==C+D){
    cout<<"Balanced"<<endl;
  }
  if (A+B<C+D){
    cout<<"Right"<<endl;
  }
}


Measured memory_bytes: 256
import heapq
n, m = map(int, input().split())
ab = [list(map(int, input().split())) for _ in range(n)]
ab.sort()
result, j = 0, 0
x = []
heapq.heapify(x)
for i in range(1, m+1):
    while j < n and ab[j][0] <= i:
        heapq.heappush(x, -ab[j][1])
        j += 1
    if len(x)!=0:
        result -= heapq.heappop(x)
print(result)

Measured memory_bytes: 31596
extern crate core;

use std::io::{self, Read};

#[macro_use]
mod parser {
    macro_rules! input {
    ($s:expr=>$($t:tt)*) => {
        let mut lines=$s.split("\n");
        $(
            line_parse!(lines,$t);
        )*
    };
    }

    macro_rules! line_parse {
    ($lines:expr,($($name:ident:$t:tt)*)) => {
        let mut line=$lines.next().unwrap().split_whitespace();
        $(value_def!(line,$name,$t);)*
    };

    //複数行
    ($lines:expr,{$n:expr;$name:ident:$t:tt}) => {
        values_def!($lines,$n,$name,$t);
    };
    }

    macro_rules! value_def {
        ($line:expr, $name:ident, $t:tt) => {
            let $name = value!($line, $t);
        };
    }

    macro_rules! values_def {
        ($lines:expr, $n:expr, $name:ident, $t:tt) => {
            let $name = {
                let mut vec = Vec::new();
                for i in 0..$n {
                    let mut next = $lines.next().unwrap().split_whitespace();
                    vec.push(value!(next, $t));
                }
                vec
            };
        };
    }

    macro_rules! value {
    //配列
    ($line:expr,[$t:tt]) => {
        $line.map(|x|{
        let mut iter=::std::iter::once(x);
        value!(iter,$t)
        }).collect::<Vec<_>>()
    };
    //タプル
    ($line:expr,($($t:tt),*)) => {
        ($(value!($line,$t),)*)
    };
    //文字列
    ($line:expr,#) => {
        $line.next().unwrap()
    };
    //単一値
    ($line:expr,$t:ty) => {
        $line.next().unwrap().parse::<$t>().unwrap()
    };
    }
}

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = solve(input.trim().to_string());
    println!("{}", output);
}

fn solve(input: String) -> String {
    input!(input=>(n:usize){n;list:(i64,i64)});
    let mut count_a = 0;
    let mut count_b = 0;
    for (a, b) in list {
        if count_a == 0 {
            count_a = a;
            count_b = b;
        } else {
            //a:b=ca:cbとなる最小のca、cb
            //ただしca、cbは減らない
            //a*i>ca
            //i>ca/a
            //bも同様
            for i in (std::cmp::max(count_a / a, count_b / b)).. {
                let x = a * i;
                let y = b * i;
                if x >= count_a && y >= count_b {
                    count_a = x;
                    count_b = y;
                    break;
                }
            }
        }
    }
    (count_a + count_b).to_string()
}

macro_rules! tests {
    ($($name:ident: $input:expr=>$output:expr,)*) => {
        mod tests {
            $(
                #[test]
                fn $name() {
                    assert_eq!($output.trim().to_string(),super::solve($input.trim().to_string()));
                }
            )*
        }
    }
}

tests! {
    test1: "3\n2 3\n1 1\n3 2" => "10",
    test2: "4\n1 1\n1 1\n1 5\n1 100" => "101",
    test3: "5\n3 10\n48 17\n31 199\n231 23\n3 2" => "6930",
}


Measured memory_bytes: 4352
import sys
input = sys.stdin.readline

def myAnswer(N:int,dic:dict) -> int:
   ans = 0
   for a in dic.values():
      if(a % 2 == 1):
         ans += 1
   return ans

def modelAnswer():
   return
def main():
   N = int(input())
   dic = {}
   for _ in range(N):
      a = int(input())
      if(a in dic.keys()):
         dic[a]+=1
      else:
         dic[a]=1
   print(myAnswer(N,dic))
if __name__ == '__main__':
   main()

Measured memory_bytes: 15072
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var scanner = bufio.NewScanner(os.Stdin)

func NextStr() string {
	scanner.Scan()
	return scanner.Text()
}

func NextInt() int {
	i, _ := strconv.Atoi(NextStr())
	return i
}

func main() {
	scanner.Split(bufio.ScanWords)
	n, x, t := NextInt(), NextInt(), NextInt()

	times := n / x
	if n%x != 0 {
		times++
	}

	fmt.Println(t * times)
}


Measured memory_bytes: 1772
#include<iostream>

int main(){
int a[4],b[4],i,n,hit,blow;

while(std::cin >> a[0]){
	for(i=1;i<4;i++){
	std::cin>>a[i];
	}
	for(n=0;n<4;n++){
	std::cin>>b[n];
	}
	hit=0;
	blow=0;

	for(i=0;i<4;i++){
		for(n=0;n<4;n++){
			if(a[i]==b[n]){
				if(i==n){
					hit=hit++;
				}
				else{blow=blow++;
				}
			}
		}
	}

	std::cout<<hit<<" "<<blow<<std::endl;
}

return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
vector<int> Zalgo(const string &S) {
    int N = (int)S.size();
    vector<int> res(N);
    res[0] = N;
    int i = 1, j = 0;
    while (i < N) {
        while (i+j < N && S[j] == S[i+j]) ++j;
        res[i] = j;
        if (j == 0) {++i; continue;}
        int k = 1;
        while (k+res[k] < j) res[i+k] = res[k], ++k;
        i += k, j -= k;
    }
    return res;
}

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

    int res = 0;
    for (int i = 0; i < N; ++i) {
        string T = S.substr(i);
        auto lcp = Zalgo(T);

        for (int j = 0; j < T.size(); ++j) {
            int l = min(lcp[j], j);
            res = max(res, l);
        }
    }
        
    cout << res << endl;
}

Measured memory_bytes: 256
# D - AtCoder Express 2

N, M, Q = map(int, input().split())
G = [[0] * (N+1) for _ in range(N+1)]

for _ in range(M):
    L, R = map(int, input().split())
    G[L][R] += 1

for i in range(N):
    for j in range(N):
        G[i+1][j+1] += G[i+1][j] + G[i][j+1] - G[i][j]

for _ in range(Q):
    p, q = map(int, input().split())
    ans = G[q][q] - G[p-1][q] - G[q][p-1] + G[p-1][p-1]
    print(ans)

Measured memory_bytes: 18580
#include<stdio.h>
int main()
{
	int N;int i=2;
	scanf("%d",&N);
	
	do
	{
		i*=2;
	}
	while(i<N);
	while(N%2==0&&N!=2&&N>3)
	{
		N=N/2;
	}
	
	if(N==2)
	{printf("%d",i);
	}
	else if(N==1)
	{
       printf("1");
	}
	else{printf("%d",i/2);
	}
	
	return 0;
}



Measured memory_bytes: 128
#include <iostream>

int main() {
    long long n, m, l, a[100][100], b[100][100], c[100][100];
    for (int i=0;i<100;++i)
        for (int j=0;j<100;++j)
            c[i][j] = 0;
    std::cin >> n >> m >> l;
    for (int i=0;i<n;++i)
        for (int j=0;j<m;++j) {
            int val;
            std::cin >> val;
            a[i][j] = val;
        }
    for (int j=0;j<m;++j)
        for (int k=0;k<l;++k) {
            int val;
            std::cin >> val;
            b[j][k] = val;
        }
    for (int i=0;i<n;++i)
        for (int k=0;k<l;++k)
            for (int j=0;j<m;++j)
                c[i][k] += a[i][j] * b[j][k];
    for (int i=0;i<n;++i) {
        for (int k=0;k<l-1;++k)
            std::cout << c[i][k] << " ";
        std::cout << c[i][l-1] << std::endl;
    }
    return 0;
}


Measured memory_bytes: 3316
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

const ll INF = 2e9;

ll dist[105][105];

void warchall_floyd(int N){
    rep(k,N)rep(i,N){
        if(dist[i][k] == INF) continue;
        rep(j,N){
            if(dist[k][j] == INF) continue;
	        chmin(dist[i][j], dist[i][k]+dist[k][j]);
        }
    }
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int v, e;
    cin >> v >> e;
    rep(i,v){
        rep(j,v) dist[i][j] = INF;
        dist[i][i] = 0;
    }
    rep(i,e){
        int s, t, d;
        cin >> s >> t >> d;
        dist[s][t] = d;
    }
    warchall_floyd(v);
    bool neg = false;
    rep(i,v) if(dist[i][i] < 0) neg = true;
    if(neg){
        cout << "NEGATIVE CYCLE" << endl;
        return 0;
    }
    rep(i,v){
        rep(j,v){
            if(dist[i][j] < INF) cout << dist[i][j];
            else cout << "INF";
            if(j < v-1) cout << " ";
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 3292
#include<bits/stdc++.h>
using namespace std;
#define all(vec) vec.begin(),vec.end()
typedef long long int ll;
typedef pair<ll,ll> P;
const ll MOD=1234567;
const ll INF=1000000010;
const ll LINF=1000000000000000010LL;
const int MAX=10000010;
const double EPS=1e-3;
int dx[4]={0,1,0,1};
int dy[4]={0,0,1,1};
//階乗
ll fact(int n){
    if(n==1){
        return 1;
	}
    ll res=n;
    res*=fact(n-1);
    return res;
}
int main(){
	int n;cin>>n;
	cout<<fact(n)<<endl;
	return 0;
}



Measured memory_bytes: 2984
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    // Your code here!
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    
    vector<int> nums;
    int now = 1;
    int cnt = 0;
    for (int i = 0; i < N; i++){
        if (S[i] == (char)(now + '0')) cnt++;
        else{
            nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if (cnt != 0) nums.push_back(cnt);
    
    if (nums.size() % 2 == 0) nums.push_back(0);
    
    vector<int> sum(nums.size() + 1);
    
    for (int i = 0; i < nums.size(); i++){
        sum[i + 1] = sum[i] + nums[i];
    }
    
    int Add = 2 * K + 1;
    int ans = 0;
    
    for (int i = 0; i < nums.size(); i += 2){
        int tmp = 0;
        int left = i;
        int right = min(i + Add, (int)nums.size());
        tmp = sum[right] - sum[left];
        ans = max(ans, tmp);
    }
    
    cout << ans << endl;
    
}

Measured memory_bytes: 1272
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> sv(n);

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

    for (int i = 0; i < sv.size(); i++)
    {
        int num = count(sv.begin(), sv.end(), sv[i]);
        if (num > 1)
        {
            cout << "No" << endl;
            return 0;
        }
    }

    string tmp = sv[0];
    char lst = tmp[tmp.size() - 1];

    bool ans_flag = true;
    for (int i = 1; i < sv.size(); i++)
    {
        if (lst != sv[i][0])
        {
            ans_flag = false;
            break;
        }
        lst = sv[i][sv[i].size() - 1];

        // auto itr = find(sv.begin() + i + 1, sv.end(), sv[i]);
        // if (itr != sv.end())
        // {
        //     ans_flag = false;
        //     break;
        // }
    }

    if (ans_flag)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
  int n, a, b;
  string s;
  cin >> n >> a >> b >> s;

  int tuuka = 0, kaigai = 0;

  for (int i = 0; i < s.size(); i++)
  {
    // cout << i;
    if (s[i] == 'a')
    {

      if (a + b > tuuka)
      {
        tuuka++;
        cout << "Yes" << endl;
      }
      else
      {
        cout << "No" << endl;
      }
    }
    else if (s[i] == 'b')
    {

      if (a + b > tuuka && kaigai < b)
      {
        tuuka++;
        kaigai++;
        cout << "Yes" << endl;
      }
      else
      {
        cout << "No" << endl;
      }
    }
    else
    {
      cout << "No" << endl;
    }
  }
}

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

int main() {
    int n, k, x, y;
    int cost;
    cin >> n >> k >> x >> y;
    if (n > k)
        cost = x * k + y * (n - k);
    else
        cost = x * n;

    cout << cost << endl;
    return 0;
}


Measured memory_bytes: 3524
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}

vector<pair<ll,ll>> prime_factorize(ll n){
  vector<pair<ll,ll>> res;
  
  for(ll i=2; i*i <= n; i++){
    if(n % i != 0) continue;
    
    ll ex = 0;
    while(n % i == 0){
      ex++;
      n /= i;
    }
    
    res.push_back({i,ex});
  }
  
  if(n != 1) res.push_back({n,1});
  
  return res;
  
}




int main(){
  ll x; cin >> x; ll ans = 0;
  
  if(x==1){
    cout << 1 << endl;
    return 0;
  }
  
  
  for(ll i=2; i*i <= x; i++){
    for(ll j=2; pow(i,j) <= x; j++){
      ll expo = 1;
      
      rep(k,j) expo *= i;
      
      if(expo <= x) ans = max(ans,expo);
    }
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 4044
#include<algorithm>//sort,二分探索,など
#include<bitset>//固定長bit集合
#include<climits>//long long型の最大値(LLONG_MAX)など
#include<cmath>//pow,logなど
#include<complex>//複素数
#include<deque>//両端アクセスのキュー
#include<functional>//sortのgreater
#include<iomanip>//setprecision(浮動小数点の出力の誤差)
#include<iostream>//入出力
#include<iterator>//集合演算(積集合,和集合,差集合など)
#include<map>//map(辞書)
#include<numeric>//iota(整数列の生成),gcdとlcm(c++17)
#include<queue>//キュー
#include<set>//集合
#include<stack>//スタック
#include<string>//文字列
#include<unordered_map>//イテレータあるけど順序保持しないmap
#include<unordered_set>//イテレータあるけど順序保持しないset
#include<utility>//pair
#include<vector>//可変長配列

using namespace std;
typedef long long ll;

int main() {
    ll N,M,C;
    cin >> N >> M >> C;
    vector<ll> B(M);
    for(ll i=0;i<M;i++){
        cin >> B[i];
    }
    vector<vector<ll>> A(N,vector<ll>(M));

    for(ll i=0;i<N;i++){
        for(ll j=0;j<M;j++){
            cin >> A[i][j];
        }
    }

    ll count=0;
    for(ll i=0;i<N;i++){
        ll result=0;
        for(ll j=0;j<M;j++){
            result += A[i][j]*B[j];
        }
        if((result+C) > 0){
            count++;
        }
    }

    cout << count << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <sstream>
#include <utility>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <cmath>
#include <functional>
#include <chrono>
#include <cstring>
#include <limits.h>

using namespace std;
typedef long long lint;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef vector<lint> vl;
typedef pair<lint,lint> pll;

#define mpr make_pair


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

    int n, k; cin>>n>>k;
    vi had(n, 0);
    for (int i=0; i<k; ++i){
        int d; cin>>d;
        for (int i=0; i<d; ++i){
            int p; cin>>p;
            had[p-1] = 1;
        }
    }
    int cnt = 0;
    for (int v : had) if (v==0)cnt++;
    cout<<cnt;


}


Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <vector>
#include <utility>
#include <map>
#include <algorithm>
#include <queue>
#include <cmath>
#include <numeric>
#include <set>

using namespace std;
struct aaa{aaa(){cin.tie(nullptr); ios::sync_with_stdio(false); cout<<fixed<<setprecision(20);};}aaa;
template <class T>ostream &operator<<(ostream &o,const vector<T>&v){o<<"{";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"}";return o;}
#define debug(v) {cerr<<"\033[1;36m[debug]\033[m "<<#v<<" : "<<v<<endl;}

using int64 = long long;

int main() {
    int n,k;
    cin >> n >> k;
    int ans = 0;
    while(n!=0) n/=k,ans++;

    cout << ans << endl;
}

Measured memory_bytes: 888
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(int i=0;i<n;++i)
#define REPR(i,n) for(int i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define INF 999999999
#define SUR 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  llong n, v;
  scanf("%lld %lld", &n, &v);
  vector<llong> a(n), b(n), c(n), d(n);
  REP(i,n){
    scanf("%lld", &a[i]);
  }
  REP(i,n){
    scanf("%lld", &b[i]);
  }
  REP(i,n){
    scanf("%lld", &c[i]);
  }
  REP(i,n){
    scanf("%lld", &d[i]);
  }

  map<llong, int> mp;;
  REP(i,n){
    REP(j,n){
      mp[a[i] + b[j]]++;
    }
  }

  llong ans = 0;
  REP(i,n){
    REP(j,n){
      llong tmp = v - c[i] - d[j];
      if(mp[tmp] > 0){
        ans += mp[tmp];
      }
    }
  }
  printf("%lld\n", ans);
  return 0;
}




Measured memory_bytes: 128212
N,K=map(int,input().split())
D=list(map(int,input().split()))
def func(N):
    l=[]
    while(N!=0):
        l.append(N%10)
        N//=10
    return l
for n in range(N,10**6+1):
    l=func(n)
    T=True
    for i in l:
        if i in D:
            T=False
            break
    if T:
        print(n)
        quit()


Measured memory_bytes: 2940
MOD=10**9 + 7
n,k=map(int,input().split())
mp = [0]*(k+1)
for i in range(k,0,-1):
    mp[i]=pow(k//i,n,MOD)
    t=2
    while i*t<=k:
        mp[i]-=mp[t*i]
        t+=1
ans=0
for i in range(1,k+1):
    ans += i * mp[i]
print(ans % MOD)

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

using namespace std;

typedef long long ll;

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

	vector<ll> h(n);
	for(ll i = 0; i < n; i++)
		cin >> h[i];

	ll ans = 0;
	for(ll i = 1; i < n; i++)
	{
		ans = ans + max(0LL, h[i - 1] - h[i]);
		h[i] = max(h[i], h[i - 1]);
	}

	cout << ans << endl;
}


Measured memory_bytes: 4792
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {

    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        BEEEeE solver = new BEEEeE();
        solver.solve(1, in, out);
        out.close();
    }

    static class BEEEeE {

        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            String s = in.next();
            int k = in.nextInt();
            for (int i = 0; i < s.length(); i++) {
                if (s.charAt(i) != s.charAt(k - 1)) {
                    out.print('*');
                } else {
                    out.print(s.charAt(i));
                }
            }
        }
    }

    static class InputReader {

        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }
    }
}



Measured memory_bytes: 20180
// finish date: 2018/01/20
#include <iostream>
#include <cmath>
#include <vector>
#include <bitset>
#include <algorithm>
#include <stack>
#include <map>
#include <climits>

using namespace std;

#define FOR(i, a, b) for(int (i)=a;(i)<(b);(i)++)
#define rep(i, n)  FOR(i,0,n)
#define ll long long
#define bigmod 1000000007
#define INF 500000000


int main() {
    int x,y;
    cin>>x>>y;
    map<int,int> mp;
    mp[1]=0;
    mp[2]=3;
    mp[3]=0;
    mp[4]=2;
    mp[5]=0;
    mp[6]=2;
    mp[7]=0;
    mp[8]=0;
    mp[9]=2;
    mp[10]=0;
    mp[11]=2;
    mp[12]=0;
    if(mp[x]==mp[y]) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#include<algorithm>//next_permutation
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(n) cout << fixed << setprecision(n);
#define large "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
#define small "abcdefghijklmnopqrstuvwxyz"
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;

ll gcd(ll a,ll b){
  if(b == 0) return a;
  return gcd(b , a % b);
}

const ll MOD = 1000000007;
const ll MAX = 2000001;

ll mod(ll a){
  return a % MOD;
}

ll lcm(ll a,ll b){
  return (a*b)/gcd(a,b);
}

ll fac[MAX], finv[MAX], inv[MAX];

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll 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;
    }
}

ll nCr(ll n, ll r){
    if (n < r) return 0;
    if (n < 0 || r < 0) return 0;
    return fac[n] * (finv[r] * finv[n - r] % MOD) % MOD;
}

ll nCrcheep(ll n,ll r){
  if(r == 0) return 1;
  else if(r == 1) return n;
  else return nCrcheep(n-1,r-1)*n/r;
}



int main(){

  nCrprep();
  
  ll s; cin >> s;
  
  ll ans = 0;
  
  for(ll i=1; s -3*i >= 0; i++){
    ans += nCr(s-2*i-1,s-3*i);
    ans = mod(ans);
  }
  
  cout << ans << endl;
  
  
}

Measured memory_bytes: 50504
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
int main(){
    int a,b;
    string s;
    cin >> a >> b >> s;
    bool flg=true;
    for(int i=0;i<a+b+1;i++){
        if(i!=a && !('0'<=s[i] && s[i]<='9')) flg=false;
        if(i==a && s[i]!='-') flg=false;
    }
    puts(flg?"Yes":"No");
}

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

int main(){
	istream_iterator<double> first(cin), last;
	vector<double> v(first, last);
	printf("%f", *max_element(v.begin(), v.end()) - *min_element(v.begin(), v.end()));
	puts("");
}

Measured memory_bytes: 1252
program AGC023A
    implicit none
    integer(8)::N,i,ans,scount
    integer(8),allocatable,dimension(:)::A,S
    read*,N
    allocate(A(N))
    allocate(S(N+1))
    read*,A
    S(1)=0
    ans=0

    do i=2,N+1
        S(i)=S(i-1)+A(i-1)
    end do

    call heapsort(N+1,S)

    do i=1,N+1
        if(i==1)then
            scount=1
        else if(S(i)==S(i-1))then
            scount=scount+1
        else
            ans=ans+(scount*(scount-1))/2
            scount=1
        end if
    end do
    ans=ans+(scount*(scount-1))/2

    print'(i0)',ans
end program AGC023A

subroutine heapsort(n,array)
    implicit none
    integer(8),intent(in) :: n
    integer(8),intent(inout) :: array(1:n)
   
    integer(8) ::i,k,j,l
    integer(8) :: t
   
    if(n.eq.1)return
  
    l=n/2+1
    k=n
    do while(k.ne.1)
       if(l.gt.1)then
          l=l-1
          t=array(L)
       else
          t=array(k)
          array(k)=array(1)
          k=k-1
          if(k.eq.1) then
             array(1)=t
             exit
          endif
       endif
       i=l
       j=l+l
       do while(j.le.k)
          if(j.lt.k)then
             if(array(j).lt.array(j+1))j=j+1
          endif
          if (t.lt.array(j))then
             array(i)=array(j)
             i=j
             j=j+j
          else
             j=k+1
          endif
       enddo
       array(i)=t
    enddo
  
    return
  end subroutine heapsort

Measured memory_bytes: 3968
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll INF = (ll)1e18;
#define rep(i, n)   for(ll i=0, i##_length=(n); i< i##_length; ++i)

void warshall_floyd(vector<vector<ll>> &d) {
	ll N=d.size();
	for (ll k=0; k<N; k++) {
		for (ll i=0; i<N; i++) {
			for (ll j=0; j<N; j++){
				if(d[i][k] != INF && d[k][j] != INF && d[i][k] + d[k][j] < d[i][j]){
					d[i][j] = d[i][k] + d[k][j];
				}
			}
		}
	}
}

bool dfs(vector<vector<ll>> &d,ll v,vector<ll> &seen){
	rep(nextv,d.size()){
		if(d[v][nextv]!=1)continue;
		if(seen[nextv]!=0){
			if(seen[nextv]==seen[v])return false;
			else continue;
		}
		seen[nextv]=-1*seen[v];
		bool b=dfs(d,nextv,seen);
		if(!b)return false;
	}
	return true;
}

signed main() {
	ll N;
	cin>>N;
	vector<vector<ll>> d(N, vector<ll>(N, INF));
	for (ll i = 0; i < N; i++) d[i][i] = 0;

	rep(i,N){
		string s;
		cin>>s;
		rep(j,s.size()){
			if(s[j]=='1'){
				d[i][j]=1;
			}
		}
	}

	vector<ll> seen(N,0);
	seen[0]=1;
	bool b=dfs(d,0,seen);
	if(!b){
		cout<<-1<<endl;return 0;
	}

	ll maxval=0;
	warshall_floyd(d);
	for(ll i=0; i<N; i++) {
		for(ll j=0; j<N; j++) {
			maxval=max(maxval,d[i][j]);
		}
	}	
	cout<<maxval+1<<endl;
	return 0;
}


Measured memory_bytes: 640
s=input()
n=len(s)
l=[]
for i in s:
  l.append(int(i))
for i in range(2 ** n):
    check = []
    for j in range(n):
      if ((i >> j) & 1):  
        check.append(l[j]) 
      else:
        check.append(-l[j])         
    if sum(check)==7:
      print(str(check[0]), end="")           
      for i in range(1, n):
        if check[i]>=0:
          print("+"+str(check[i]), end="")
        else:
          print(str(check[i]), end="")
      print("=7")
      exit()

Measured memory_bytes: 3064
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    i64 n, x, d;
    cin >> n >> x >> d;
    if (d == 0)
    {
        cout << (x != 0 ? n + 1 : 1) << endl;
        return;
    }
    if (d < 0)
    {
        x += d * (n - 1);
        d = -d;
    }
    map<i64, akari<pair<i64, i64>>> kukans;
    for (i64 k = 0; k <= n; k++)
    {
        kukans[(x * k % d + d) % d].emplace_back(x * k / d + k * (k - 1) / 2, x * k / d + k * (n - 1 + (n - k)) / 2);
    }
    i64 ans = 0;
    for (auto &vp : kukans)
    {
        auto &v = vp.second;
        sort(v.begin(), v.end());
        i64 r = -1e18;
        for (auto &p : v)
        {
            i64 l = max(r + 1, p.first);
            ans += max(i64(0), p.second - l + 1);
            r = max(r, p.second);
            //print(l, r, ans);
        }
    }
    cout << ans << endl;
}

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


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

const int N = 100005;

int n;
int par[N], sz[N];
vector <int> vec[N];
long long res[N];
long long lz[N];

struct edge {
	int w; int u; int v;
	bool operator < (const edge &other) const {
		return w > other.w;
	}
};
vector <edge> ed;

int anc(int p) { return p == par[p] ? p : par[p] = anc(par[p]); }

void join(int p, int q, int w) {
	p = anc(p), q = anc(q);
	if (vec[p].size() > vec[q].size()) swap(p, q);

	while(vec[p].size()) {
		int u = vec[p].back();
		res[u] += lz[p];
		res[u] -= lz[q];
		res[u] += 1LL * (sz[q] - sz[p]) * w;
		vec[q].push_back(u);
		vec[p].pop_back();
	}

	par[p] = q;
	lz[q] += 1LL * sz[p] * w;
	sz[q] += sz[p];
	lz[p] = 0;
	sz[p] = 0;
}

int main() {
	ios_base::sync_with_stdio(false); cin.tie(0);
	
	cin >> n;
	for (int i = 1; i < n; ++i) {
		int u, v, w; cin >> u >> v >> w;
		ed.push_back({w, u, v});
	}
	sort(ed.begin(), ed.end());

	for (int i = 1; i <= n; ++i) vec[i].push_back(i), par[i] = i, sz[i] = 1;

	for (auto &e : ed) {
		join(e.u, e.v, e.w);
	}

	for (int i = 1; i <= n; ++i) if (i == anc(i)) {
		for (auto &j : vec[i]) {
			res[j] += lz[i];
		}
	}

	for (int i = 1; i <= n; ++i) printf("%lld\n", res[i]);
}

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

int main() {
	
	string s;
	cin >> s;
	int ans;
	if(s == "SUN") ans = 7;
	if(s == "MON") ans = 6;
	if(s == "TUE") ans = 5;
	if(s == "WED") ans = 4;
	if(s == "THU") ans = 3;
	if(s == "FRI") ans = 2;
	if(s == "SAT") ans = 1;
	cout << ans << endl;
	return 0;
}

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

#define rep(i,n) for(ll i=0;i<(n);++i)
using ll = int_fast64_t;
using pll = pair<ll,ll>;
constexpr ll INF = 1LL<<60;
constexpr ll MOD = 1e9+7;
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(a>b){a=b;return 1;}return 0;}
#if loc||local
template<class T>void dump(T&& t){cerr<<t<<endl;}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){cerr<<h<<", ";dump(forward<Ts>(t)...);}
#else
void dump(){}
template<class T,class... Ts> void dump(T&& h, Ts&&... t){}
#endif
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T> ostream &operator<<(ostream& os,vector<T>const& v){for(auto const& vi:v)os<<vi<<" ";return os;}
template<class T,class U> ostream &operator<<(ostream& os,pair<T,U>const& p){os<<p.first<<","<<p.second;return os;}
template<class T>vector<T> vec(size_t a){return vector<T>(a);}
template<class T, class... Ts>auto vec(size_t a, Ts... ts){return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...));}

signed main(){

  int n;
  cin>>n;
  vector<ll> a(n);
  cin>>a;
  sort(begin(a),end(a));

  ll aimax = 1e6;
  vector<int> table(2*aimax+1);
  ll ans = 0;
  rep(i,n){
    if(table[a[i]]==1){
      ans--;
      table[a[i]]=2;
      continue;
    }
    if(table[a[i]]==2)continue;
    table[a[i]]=1;
    ans++;
    ll tmp = a[i]*2;
    while(tmp<2*aimax){
      table[tmp] = 2;
      tmp += a[i];
    }
  }
  cout<<(ans)<<endl;

}

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

typedef long long ll;
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; }
#define rep(i, n) for(int i = 1; i < (int)(n); i++)

using namespace std;
int main() {
	int N, K, res;
	cin >> N >> K;
	res = N - K + 1;
	cout << res << endl;
}


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

int main() {
	string s;
	cin>>s;
	int count=0;
	bool ok=true;
	if(s.at(0)=='A'){
		for(int i=2;i<s.size()-1;i++){
			if(s.at(i)=='C'){
				count++;
			}
			else if(!(s.at(i)>='a' && s.at(i)<='z')){
				ok=false;
				break;
			}
		}
		if(!(s.at(1)>='a' && s.at(1)<='z')){
			ok=false;
		}
		if(!(s.at(s.size()-1)>='a' && s.at(s.size()-1)<='z')){
			ok=false;
		}
	}
	else{
		ok=false;
	}
	if(count==1 && ok==true){
		cout<<"AC"<<endl;
	}
	else{
		cout<<"WA"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
def s_in():
    return input()

def n_in():
    return int(input())

def l_in():
    return list(map(int, input().split()))

class Interval():
    def __init__(self, li):
        self.li = li
        self.n = len(li)
        self.sum_li = [li[0]]
        for i in range(1, self.n):
            self.sum_li.append(self.sum_li[i-1] + li[i])

    def sum(self, a, b=None):
        if b is None:
            return self.sum(0, a)

        res = self.sum_li[min(self.n-1, b-1)]
        if a > 0:
            res -= self.sum_li[a-1]
        return res

N = n_in()
S = s_in()
print(len([i for i in range(N) if S[i:i+3] == "ABC"]))






Measured memory_bytes: 3064
def main():
    X = int(input())

    ans = 1
    m = int(X ** 0.5)
    for i in range(1, m+1):
        for j in range(2, m+1):
            if i ** j <= X:
                ans = max(ans, i ** j)

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
import java.io.IOException;
import java.util.Arrays;
import java.util.Scanner;

class Main {
	public static void main(String[] args) throws IOException {
		Scanner sc = new Scanner(System.in);
		long N = sc.nextLong();
		long M = sc.nextLong();

		if (N > M / 2) {
			System.out.println(Math.min(N, M / 2));
		} else {
			long 残り = M - N * 2;
			System.out.println(N + 残り / 4);
		}
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}
}


Measured memory_bytes: 21716
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <cmath>
#include <set>
#include <algorithm>

typedef long long ll;
const ll MOD = 1e9 + 7;
const long long INF = 1LL<<60;
const double PI=3.14159265358979323846;
const int NMAX=100005;
using namespace std;

ll dp[16][16][(1<<16)+1];
vector<pair<int,int> > edge[16];
int v,e;

ll rec(int from, int s, int l){
    if(dp[s][from][l] != -1) return dp[s][from][l];
    int prev = l & ~(1<<from);
    if(l == (1<<v)-1 && from == s) prev = l;
    if(prev == 0){
        if(from == s) return 0;
        else return INF;
    }
    ll ans = INF;
    for(int i = 0; i < edge[from].size(); i++){
        if(((prev>>edge[from][i].first) & 1) == 0) continue;
        if(prev != (1<<s) && edge[from][i].first == s) continue;
        ans = min(ans,rec(edge[from][i].first,s,prev)+edge[from][i].second);
    }
    dp[s][from][l] = ans;
    return ans;
}

int main(){
    cin >> v >> e;
    for(int i = 0; i < e; i++){
        int s,t,d;
        cin >> s >> t >> d;
        edge[t].push_back(make_pair(s,d));
    }


    for(int i = 0; i <= v; i++){
        for(int j = 0; j <= v; j++){
            for(int k = 0; k <= 1<<v; k++){
                dp[i][j][k] = -1;
            }
        }
    }

    ll ans = INF;
    for(int i = 0; i < v; i++){
        ans = min(ans,rec(i,i,(1<<v)-1));
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 69648
### constants

MAX_P = 1000000

### subroutines

def gen_primes(max_p)
  primes = Array.new(max_p + 1){true}
  primes[0] = primes[1] = false
  num_p = 0

  for p in (2..max_p)
    if primes[p]
      num_p += 1
      for q in (p * p).step(max_p, p)
        primes[q] = false
      end
    end
  end

  return primes
end

### main

primes = gen_primes(MAX_P)

pids = Array.new(MAX_P + 1){nil}

id = 0
for i in (0..MAX_P)
  id += 1 if primes[i]
  pids[i] = id
end

while true
  n = gets.strip.to_i
  break if n == 0

  kx = 0

  n.times.each do
    p, m = gets.strip.split(' ').map{|s| s.to_i}
    #puts "#{p}, #{m}"

    i0 = [p - m - 1, 0].max
    i1 = [p + m, MAX_P].min

    x = pids[i1] - pids[i0]

    kx += (x - 1)
  end

  puts kx
end

Measured memory_bytes: 21780
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<deque>
#include<cmath>
#include<stack>
#include<string.h>
#include <iomanip>
#define rep(i,n) for(int i = 0;i<n;i++)
#define _GLIBCXX_DEBUG
using ll = long long; 
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
	int n;
	cin >>n ;
	vector<int>x(n),y(n),h(n);
	rep(i,n) {
		cin >> x[i] >> y[i] >> h[i];
	}
	for(int Cx = 0;Cx<=100;Cx++) {
		for(int Cy = 0;Cy<=100;Cy++) {
			int H = -1;
			for(int i = 0;i<n;i++) {
				if(h[i]>0) {
					int tmp = h[i]+abs(Cx-x[i])+abs(Cy-y[i]);
					
					if(H==-1) {
						H = tmp;
					} else {
						if(H != tmp) {
							H = -2;
							break;
						}
					}
				}
			}
			
			if(H==-2) continue;
			for(int i = 0;i<n;i++) {
				if(h[i]==0) {
					int dist = abs(Cx-x[i])+abs(Cy-y[i]);
					if(H>dist) {
						H = -2;
						break;
					}
				}
			}
			if(H == -2) continue;
			cout << Cx << " " << Cy << " " << H << endl;
			return 0;
		}
	}
}

Measured memory_bytes: 256
#include <stdio.h>

int a,d,i,j, el;
char b[100000000],e[100000000],c[100000000];

int main(){
	while(1){
		scanf("%d\n",&a);
		if(a==0){
			return 0;
		}
		for(i=0;i<a;i++){
			scanf(" %c %c",&b[i],&e[i]);
		}
		scanf("%d\n",&d);
		for(i=0;i<d;i++){
			scanf(" %c",&c[i]);
			for(j=0;j<a;j++){
				if(c[i]==b[j]){
					c[i]=e[j];
					break;
				}
			}
		}
		for(i=0;i<d;i++){
			printf("%c",c[i]);
		}
		printf("\n");
	}
}

Measured memory_bytes: 4672
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AOJ
{
	class Program
	{
		static void Main(string[] args)
		{
			var n = int.Parse(Console.ReadLine());
			while (n-- != 0)
			{
				f(Console.ReadLine());
			}
		}

		static void f(string s)
		{
			var e = Regex.Replace(s, @"[\+\-\*\/\(\)=]", " $0 ").Split(' ')
				.Where(a => a != "").ToArray();
			var i = 0;
			Console.WriteLine(expr(e, ref i));
		}

		static int factor(string[] e, ref int i)
		{
			if (e[i] != "(")
			{
				i++;
				return int.Parse(e[i - 1]);
			}
			else
			{
				i++;
				return expr(e, ref i);
			}
		}

		static int term(string[] e, ref int i)
		{
			var r = factor(e, ref i);
			while (true)
			{
				if (e[i] == "*")
				{
					i++;
					r *= factor(e, ref i);
				}
				else if (e[i] == "/")
				{
					i++;
					r /= factor(e, ref i);
				}
				else
				{
					return r;
				}
			}
		}

		static int expr(string[] e, ref int i)
		{
			var r = term(e, ref i);
			while (e[i] != "=" && e[i] != ")")
			{
				if (e[i] == "+")
				{
					i++;
					r += term(e, ref i);
				}
				if (e[i] == "-")
				{
					i++;
					r -= term(e, ref i);
				}
			}
			i++;
			return r;
		}
	}
}

Measured memory_bytes: 7484
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define speed                     \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)
#define ll long long
#define eps 1e-9
#define inf 0x3f3f3f
#define mod 4999999
using namespace std;

int main() {
    speed;
    int h, w, k, ans = 0;
    cin >> h >> w >> k;
    vector<string>v(h);
    for (auto &i : v)
        cin >> i;
    for (int i = 0; i < pow(2, h); ++i) {
        bitset<6>r = i;
        for (int j = 0; j < pow(2, w); ++j) {
            bitset<6>c = j;
            vector<string>t = v;
            for (int k = 0; k < h; ++k) {
                if (r[k])
                    for (int l = 0; l < w; ++l)
                        t[k][l] = '-';
            }
            for (int k = 0; k < w; ++k) {
                if (c[k])
                    for (int l = 0; l < h; ++l)
                        t[l][k] = '-';
            }
            int cnt = 0;
            for (auto it : t)
                for (auto jt : it)
                    cnt += bool(jt == '#');
            if (cnt == k)
                ans++;
        }
    }
    cout << ans;
}

Measured memory_bytes: 4040
#include<bits/stdc++.h>
#define MOD 998244353
#define MAX 200005
using namespace std;
long long dp[MAX+1],rsq[MAX+1];
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n,k;
	cin>>n>>k;
	vector<pair<int,int>> v; 
	for(int i=0,x,y;i<k;++i)
	{
		cin>>x>>y;
		v.push_back({x,y});
	}
	sort(v.begin(),v.end());
	dp[1] = 1;
	rsq[1] = dp[1];
	for(int i=2;i<=n;++i)
	{
		rsq[i] = rsq[i-1];
		for(pair<int,int> p:v)
		{
			int x = p.first, y = p.second;
			if(i-x<=0)
				break;
			dp[i] += (rsq[i-x]-rsq[max(i-y,1)-1]+MOD)%MOD;
			dp[i] %= MOD;
		}
		rsq[i] += dp[i];
		rsq[i] %= MOD;
	}
	cout<<dp[n]<<endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  
  map<string,int> S;
  
  for(int i=0; i<N; i++){
    string tmp;
    cin >> tmp;
    S[tmp] += 1;
  }
  
  cout << S.size() << endl;
}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// cmd

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

    string st;
    cin >> st;
    int ans = 0;
    rep(i, st.size()) {
        ans += (st[i] - '0');
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define INF (1<<20)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

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

	rep(i, n) {
		ll num;
		cin >> num;

		cout << "Case " << i + 1 << ":" << endl;
		rep(j, 10) {
			num = num*num;
			string str = to_string(num);
			while (str.size() < 8)
				str = "0" + str;

			str = str.substr(2,4);
			num = stoll(str);
			cout << num << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3196