akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int main(){
 int n,k,a[200001]={},cnt[200000]={},b=0,ans=0,j=0;
 cin>>n>>k;
 for(int i=0;i<n;i++)cin>>a[i];
 sort(a,a+n);
 
 for(int i=0;i<n-1;i++){
  b++; 
  if(a[i]!=a[i+1]){
    cnt[j]=b;
    b=0;
    j++;
  }
 }
 cnt[j]=b+1;
 j++;
 sort(cnt,cnt+j);
 b=j;
 if(b>k){ 
  b-=k;
  for(int i=0;i<b;i++)ans+=cnt[i];
 } 
 cout<<ans<<endl;
 return 0;
}

Measured memory_bytes: 1920
#include<iostream>
#include<cmath>
#include<vector>
#include<set>
#include<algorithm>
#include<tuple>
#include<utility>
#include<cctype>
#include<climits>
using namespace std;

#define REP(i,n) for(int i=0;i<n;++i)
#define RUP(a,b) ((a+b-1)/(b))
#define ENT "\n"

typedef long long ll;



int atcoder(){
    //入力
    ll a,b,c,x,y;
    cin >> a >> b >> c >> x >> y;
    ll ans = 0;
    
    //処理
    if(x<y){
        swap(a,b);
        swap(x,y);
    }
    if(a+b<=2*c){
        ans = a*x + b*y;
    }else{
        ans += 2*c*y;
        if(a<=2*c) ans += a*(x-y);
        else ans += 2*c*(x-y);
    }
    
    //出力
    cout << ans << ENT;
    return 0;
}

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


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
class Main {
    static HashSet<String> hs;
    static int[] shortestDist;
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());

        int N = Integer.parseInt(st.nextToken());
        int M = Integer.parseInt(st.nextToken());
        HashMap<Integer, List<Edge>> hm = new HashMap();
        hs = new HashSet();
        for (int i=0; i<M; i++) {
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken())-1;
            int end = Integer.parseInt(st.nextToken())-1;
            int wt = Integer.parseInt(st.nextToken());
            List<Edge> lst = hm.getOrDefault(start, new LinkedList());

            lst.add(new Edge(start, end,wt));
            hm.put(start, lst);
            lst = hm.getOrDefault(end, new LinkedList());
            lst.add(new Edge(end, start,wt));
            hm.put(end, lst);
        }
        int ans=0;
        for(int i=0; i<N; i++){
            dijkstra(hm, i, N);
            for(Edge e: hm.get(i)){
                // System.out.println(e.dest+": "+shortestDist[e.dest]+"vs"+e.weight);
                if(e.weight>shortestDist[e.dest]){
                    hs.add(Math.min(e.src, e.dest)+","+Math.max(e.src,e.dest));
                }
            }
        }
        System.out.println(hs.size());

    }
    public static class Edge{
        int src,dest,weight;
        Edge(int s, int x, int y){
            src=s;
            dest=x;
            weight=y;
        }
    }
    public static class Node{
        int u, weight;
        Node(int x, int y){
            u=x;
            weight=y;
        }
    }

    private static void dijkstra(HashMap<Integer, List<Edge>> graph, 
                                        int startVertex, int n) 
    { 
        shortestDist = new int[n];

        PriorityQueue<Node> pq = new PriorityQueue<>(new Comparator<Node>(){
            public int compare(Node a, Node b){
                return a.weight-b.weight;
            }
        });

        for(int i=0; i<n; i++)
            shortestDist[i]=Integer.MAX_VALUE;

        shortestDist[startVertex]=0;
        HashSet<Integer> visited = new HashSet();
        

        pq.offer(new Node(startVertex, 0));
        visited.add(startVertex);

        while(!pq.isEmpty()){
            
            Node curNode = pq.poll();

            visited.add(curNode.u);

            for(Edge e: graph.get(curNode.u)){
                int neigh = e.dest;
                if(!visited.contains(neigh)){
                    int newDist = shortestDist[curNode.u]+e.weight;
                    if(newDist<shortestDist[neigh]){

                        shortestDist[neigh]=newDist;
                    }

                    pq.offer(new Node(neigh, newDist));
                }
            }


        }

    }
}


Measured memory_bytes: 36416
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define mp make_pair
#define ff first
#define ss second   
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).end()
#define setval(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define trav(x , a) for(auto &x : a)
#define sz(a) ((int)a.size())
typedef long long ll ; 

#define int ll

using namespace std;

const int N = 3e5 +5 ;
const int mod = 1e9 + 7 ;
const ll inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

typedef pair<int, int> pii; 
typedef pair<int , pii> ipii ;
typedef pair<pii , int> piii ; 
typedef unsigned long long ull ;
typedef long double ld;

ll po(ll x,ll y,ll p = mod) {ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}

void solve()
{
    int n , k ;
    cin >> n >> k;
    if(n >= k){
        n = n % k; 
    }
    if(n < k){
        n = min(n , abs(n - k));
    }
    cout << n ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        cout << "\n" ;
    }
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A,B,C,D,E=[int(input()) for i in range(5)]
time = 0
#0->1
time = ((N-1)//A)+1
#1->2
time = time+1 if A<=B else ((N-1)//B)+2
#2->3
time = time+1 if min(A,B)<=C else ((N-1)//C)+3
#3->4
time = time+1 if min(A,B,C)<=D else ((N-1)//D)+4
#4->5
time = time+1 if min(A,B,C,D)<=E else ((N-1)//E)+5

print(time)

Measured memory_bytes: 3064
#include<iostream>
#include<string>
using namespace std;
int main(){
    int n;
    int tpoint = 0;
    int hpoint = 0;
    string taro, hanako;
    
    cin >> n;
    
    for(int i = 0; i < n; i++){
        cin >> taro >> hanako;
        
        if(taro > hanako){
            tpoint = tpoint + 3;
        }
        else if(taro < hanako){
            hpoint = hpoint + 3;
        }
        else{
            tpoint = tpoint + 1;
            hpoint = hpoint + 1;
        }
    }
    
    cout << tpoint << " " << hpoint << endl;
}


Measured memory_bytes: 3188
use std::io::*;

fn main() {
    let mut x = read();
    let y = read();
    let z = read();
    let mut count = 0;

    while x >= 2 * z + y {
        x -= z;
        x -= y;
        count += 1;
    }
    println!("{}", count);
}

// fn read_v() -> Vec<char> {
//     let s = stdin();
//     let b = s.bytes()
//         .map(|c| c.unwrap() as char)
//         .take_while(|c| !c.is_whitespace())
//         .collect::<Vec<char>>();
//     b
// }

fn read() -> i64 {
    let s = stdin();
    let b = s.bytes()
        .map(|c| c.unwrap() as char)
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    b.parse().ok().expect("Failed read()")
}


Measured memory_bytes: 4352
/** "Ever tried.
         Ever failed.
               No matter.
                   Try Again.
                        Fail again.
                             Fail better.**/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define bp  __builtin_popcount
#define pb push_back
#define loop(i,n) for(int i = 0;i < int(n);i++)
#define sz(s) (int)(s.size())
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define fr first
#define sc second
#define NumofDigits(n)   ((long long)log10(n)+1)
using namespace std;
using namespace __gnu_pbds;
typedef tree<int,null_type,less<int>,rb_tree_tag, tree_order_statistics_node_update> indexed_set;
const int maxn=1e5+5;
const  double EPS = 1e-9;
const int MOD = 1e9+7;
/*
ll gcd(ll a, ll b) { return !b ? a : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
ll fastpow(ll b, ll p)
{if(!p)return 1;ll ret = fastpow(b, p >> 1);ret *= ret;if(p&1)ret*= b;return ret;}
int dx[] = {- 1, 0, 0, 1, 0 };
int dy[] = { 0,- 1, 1, 0, 0 };*/
void File()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
#endif
}
ll arr[maxn],x;
int main()
{
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int n;
    cin>>n>>x;
    for(int i=0;i<n;i++)
        cin>>arr[i];
    ll ans=0;
    for(int i=0;i<n-1;i++)
    {
       if(arr[i]+arr[i+1]<x)
         continue;
       ans+=(arr[i]+arr[i+1]-x);
       arr[i+1]=max(0*1ll,x-arr[i]);
    }
    cout<<ans;
}


Measured memory_bytes: 4304
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll x;
int main() {
  cin >> x;
  ll y = x / 11LL + 1LL;
  ll t = y*11LL;

  ll res = 2LL * y;
  while( t >= x ) {
    t-=5;
    res--;
    if( t < x ) break;
    t-=6;
    res--;
  }
  cout << res+1 << endl;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

li1 = [i+1-A[i] for i in range(N)]
li2 = [A[i]+i+1 for i in range(N)]

cnt = [0 for i in range(2*N+1)]
for i in li2:
    if i<len(cnt)-1:
        cnt[i] += 1

ans = 0
for i in li1:
    if i>=0:
        ans += cnt[i]
print(ans)







Measured memory_bytes: 138088
#include <stdio.h>

int main(){
  int a[101],b,c,i;
  for(i=0;i<101;i++) a[i]=0;
  c=0;
  while(scanf("%d",&b)!=EOF) a[b]++;
  for(i=0;i<101;i++) c=(a[i]>c?a[i]:c);
  for(i=0;i<101;i++) if(a[i]==c) printf("%d\n",i);
  return 0;
}

Measured memory_bytes: 0
//#include <bits/stdc++.h>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <fstream>
#include <string.h>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <queue>
#include <math.h>
#include <assert.h>
#define ff first
#define ss second
#define ll long long
#define mod 998244353
using namespace std;
ll n, a[100009], dp[100009], k;
int main () {
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    for(int i=2;i<=n;i++) {
        dp[i] = 998244353000;
        for(int j=1;j<=k;j++) {
            ll ind = i - j;
            if(ind <= 0)
                break;
            dp[i] = min(dp[i], dp[ind] + abs(a[ind] - a[i]));
        }
    }
    cout<<dp[n];
}
/*
 2
 ((
 )))(
 */


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
typedef pair<int,int> P;
int main(void){
  int n,m,i,j,k,a[100010],br,cr;
  vector<P> b;
  cin >> n >> m;
  for (i=0;i<n;i++) cin >> a[i];
  for (i=0;i<m;i++){
    cin >> br >> cr;
    b.push_back(P(cr,br));
  }
  sort(a,a+n);
  sort(b.begin(),b.end(),greater<P>());
  
  long ans=0;
  i=j=0;
  while (1){
    for (k=0;k<b[j].second && i<n && b[j].first > a[i];k++){
      a[i]=b[j].first;
      i++;
    }
    if (i>=n || b[j].first <= a[i]) break;
    j++;
  }
  for (i=0;i<n;i++) ans+=a[i];
  cout << ans << endl;
  return 0;
}

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

string matchp(string b){
  pair<string, string> p("A", "T");
  if (b == p.first)return p.second;
  else return p.first;
}
string matchq(string b){
  pair<string, string> q("G", "C");
  if (b == q.first)return q.second;
  else return q.first;
}
int main() {
  string b;
  cin >> b;
  if (b == "A" || b == "T") cout << matchp(b) << endl;
  else cout << matchq(b) << endl;
}

Measured memory_bytes: 256
#pragma warning(disable:4996)
#include <bits/stdc++.h>

using namespace std;

#define REP(i,n) for (ll i = 0; i<n; i++)
#define ALL(a) begin(a), end(a)
#define TPL template
#define TNM typename

using ll = long long;
using ull = unsigned long long;
TPL<TNM T> using vec = vector<T>;
TPL<TNM T> using vec2 = vec<vec<T>>;
TPL<TNM T> using vec3 = vec<vec2<T>>;
TPL<TNM T> using vec4 = vec<vec3<T>>;
TPL<TNM T> using vec5 = vec<vec4<T>>;

TPL<TNM K, TNM V> using umap = unordered_map<K, V>;
TPL<TNM K, TNM V> using uset = unordered_set<K, V>;

TPL<class T> inline void OUT(const T &x) { cout << x << "\n"; }
struct pre_ { pre_() { cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(6); } } pre__;

TPL<TNM V, TNM H> void resize(vector<V>& v, const H h) { v.resize(h); }
TPL<TNM V, TNM H, TNM ... T> void resize(vector<V>& v, const H& h, const T ... t) { v.resize(h); for (auto& _v : v) resize(_v, t ...); }
TPL<TNM V, TNM T> void fill(V& x, const T& val) { x = val; }
TPL<TNM V, TNM T> void fill(vector<V>& vec, const T& val) { for (auto& v : vec) fill(v, val); }

int main(void) {
	string S;
	cin >> S;
	if (S.front() != 'A') {
		OUT("WA");
		return 0;
	}
	if (isupper(S[1])) {
		OUT("WA");
		return 0;
	}
	int cnt = 0;
	for (int i = 2; i <= S.size() - 2; ++i) {
		if (S[i] == 'C') {
			cnt++;
		}
		else {
			if (isupper(S[i])) {
				OUT("WA");
				return 0;
			}
		}
	}

	if ( (cnt != 1) || isupper(S.back())) {
		OUT("WA");
		return 0;
	}

	OUT("AC");
	return 0;
}

Measured memory_bytes: 768
def gs() gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end

def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end


n = gi() # 10**5

ans = n*(n+1)*(n+2)/6
vs = Array.new(n+1)
(n-1).times do
  u,v = gsmi.sort
  ans -= u*(n-v+1)
end

puts ans


Measured memory_bytes: 15816
#define _USE_MATH_DEFINES
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<stdio.h>
#include<cmath>
#include<stack>
#include<set>
#include<map>
#include<stdio.h>
#include<functional>
#include<queue>

using ll = long long;

using namespace std;

ll mod = 1000000007;

ll n_pow(ll a, ll n) {
	if (n == 0)return 1;
	ll t = n_pow(a, n / 2);
	t *= t;
	t %= mod;
	if (n % 2 == 1)t *= a;
	return t % mod;
}

const int INF = 1001001001;


int main() {
	int n, W;
	cin >> n >> W;
	vector<ll>value(n);
	vector<ll>weight(n);
	for (int i = 0; i < n; i++) {
		cin >> weight[i] >> value[i];
	}
	vector<vector<ll>>dp(n + 1, vector<ll>(W + 1));
	for (int i = 0; i < n; i++) {
		for (int w = 0; w < W + 1; w++) {
			if (w < weight[i]) {
				dp[i + 1][w] = dp[i][w];
			}
			else {
				dp[i + 1][w] = max(dp[i][w], dp[i][w - weight[i]] + value[i]);
			}
		}
	}
	cout << dp[n][W] << endl;
	return 0;
}

Measured memory_bytes: 80256
#include<bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define loop(n)  for(int i=0;i<n;i++)
#define loop1(i,a,n)  for(int i=a;i<n;i++)
using namespace std;
int main()
{
  fastio;
  int n;
  cin>>n;
  int h;
  cin>>h;
  int x=h;
  bool flag=true;
  loop(n-1)
  {
    cin>>h;
    if(h<x-1)
    {
      flag=false;
      break;
    }
    if(h>x)
    {
      x=h;
    }
  }
  cout<<(flag?"Yes":"No");
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int a, b, c;
	
	scanf("%d %d %d", &a, &b, &c);
	
	if (c > b){
		if (b > a){
			printf("Yes\n");
		}
		else {
			printf("No\n");
		}
	}
	else {
		printf("No\n");
	}
	
	return(0);
}

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

void solve(std::string s) {
  cout << s.find_last_of("Z") - s.find_first_of("A") + 1 << endl;
}

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

  std::string s;
  std::cin >> s;
  solve(s);
  return 0;
}


Measured memory_bytes: 720
using System;

namespace GCDandLCM
{
    class Program
    {
        static void Main(string[] args)
        {
            string buf;
            while (!string.IsNullOrEmpty(buf = Console.ReadLine()))
            {
                double[] inputs = Array.ConvertAll(buf.Split(' '), double.Parse);
                double gcd;
                if (inputs[0] > inputs[1])
                {
                    gcd = Myfunc(inputs[0], inputs[1]);
                }
                else
                {
                    gcd = Myfunc(inputs[1], inputs[0]);

                }
                Console.WriteLine("{0} {1}", gcd, inputs[0] * inputs[1] / gcd);
            }
        }


        public static double Myfunc(double a, double b)
        {
            if (b == 0)
            {
                return a;
            }
            return Myfunc(b, a % b);
        }
    }
}



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

using namespace std;

int N;
int m[100];
int X;

void solve() {
    int min = m[0];
    for (int i = 0; i < N; ++i) {
        X -= m[i];
        if (min > m[i]) {
            min = m[i];
        }
    }
    printf("%d\n", X / min + N);
}

int main() {
    cin >> N >> X;
    for (int i = 0; i < N; ++i) cin >> m[i];
    solve();
    return 0;
}

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



int main(){

int n;
cin >> n;

vector<int>a;
vector<int>b(n-1);
rep(i,n-1){
    int tmp;
    cin >> tmp;
    b[i] = tmp;
} 
int ans = 0;
rep(i,n){
    if(i==0){
        ans += b[0];
        continue;
    }
    if(i==n-1){
        ans += b[i-1];
        continue;
    }
    ans += min(b[i],b[i-1]);

}
cout << ans << endl;
}

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

struct Point {
    int64_t x, y, index;
    bool operator<(const Point& rhs) const {
        return x < rhs.x;
    }
};

int main() {
    int64_t N;
    cin >> N;
    vector<Point> points(N);
    for (int64_t i = 0; i < N; i++) {
        cin >> points[i].x >> points[i].y;
        points[i].x--;
        points[i].y--;
        points[i].index = i;
    }

//    int64_t N = 200000;
//    vector<Point> points(N);
//    for (int64_t i = 0; i < N; i++) {
//        points[i].x = i;
//        points[i].y = i;
//        points[i].index = i;
//    }

    dsu d(N);

    //y順に昇順ソート
    sort(points.begin(), points.end(), [](Point& lhs, Point& rhs) {
        return lhs.y < rhs.y;
    });
    set<pair<int64_t, int64_t>> st;
    for (const Point p : points) {
        auto itr_end = st.upper_bound(make_pair(p.x, p.index));
        bool merge = false;
        for (auto itr = st.begin(); itr != itr_end; itr++) {
            d.merge(itr->second, p.index);
            merge = true;
        }
        if (!merge) {
            st.insert(make_pair(p.x, p.index));
        }
    }

    //y順に降順ソート
    sort(points.begin(), points.end(), [](Point& lhs, Point& rhs) {
      return lhs.y > rhs.y;
    });
    st.clear();
    for (const Point p : points) {
        bool merge = false;
        for (auto itr = st.upper_bound(make_pair(p.x, p.index)); itr != st.end(); itr++) {
            d.merge(itr->second, p.index);
            merge = true;
        }
        if (!merge) {
            st.insert(make_pair(p.x, p.index));
        }
    }

    for (int64_t i = 0; i < N; i++) {
        cout << d.size(i) << endl;
    }
}

Measured memory_bytes: 14468
import scala.io.{ StdIn => in}

object Main extends App {
  val Array(n, m) = in.readLine.split(" ").map(_.toInt)
  val a = Iterator.continually(in.readLine.toCharArray)
    .take(n)
    .toArray
  val b = Iterator.continually(in.readLine.toCharArray)
    .take(m)
    .toArray
  val ans = {
    var isExsit = false
    for {
      i <- 0 to n-m
      if !isExsit
      j <- 0 to n-m
      if !isExsit
      } {
        var isCont = true
        for {
          k <- 0 until m
          if isCont
          l <- 0 until m
          if isCont
        } isCont = a(i+k)(j+l) == b(k)(l)

        if(isCont) isExsit = isCont
      }

    if(isExsit) "Yes" else "No"
  }
  println(ans)
}

Measured memory_bytes: 27340
#include <bits/stdc++.h>
using namespace std;
 
int main() {
 vector <char> vec(3);
   vector <char> vecc(3);
  
  for (int i=0; i<3; i++) {
    cin >> vec.at(i);
  }
  for (int j=0; j<3; j++) {
    cin >> vecc.at(j);
  }
  
  int sum=0;
  
  for (int i=0; i<3; i++) {
   if (vec.at(i) == vecc.at(i)) {
     sum++;
   }
  }
  cout << sum << endl;
  
   
  
    
  
  
 }

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

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

    int numN = N.size();
    if(numN==1){
        if(N[0]=='2'||N[0]=='4'||N[0]=='5'||N[0]=='7'||N[0]=='9'){
            cout << "hon" << endl;
        }
        else if(N[0]=='3'){
            cout << "bon" << endl;
        }
        else {
            cout << "pon" << endl;
        }
    }

    else if(numN==2){
        if(N[1]=='2'||N[1]=='4'||N[1]=='5'||N[1]=='7'||N[1]=='9'){
            cout << "hon" << endl;
        }
        else if(N[1]=='3'){
            cout << "bon" << endl;
        }
        else {
            cout << "pon" << endl;
        }
    }

    
    else{
        if(N[2]=='2'||N[2]=='4'||N[2]=='5'||N[2]=='7'||N[2]=='9'){
            cout << "hon" << endl;
        }
        else if(N[2]=='3'){
            cout << "bon" << endl;
        }
        else {
            cout << "pon" << endl;
        }
    }

    return 0;
}

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

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  for(int i=0;i<n;++i){
    cin >> p[i];
  }
  int k=0;
  for(int i=0;i<n;++i){
    if(p[i] != i+1) {
      k++;
    }
  }
  if(k <= 2) cout << "YES" << endl;
  else cout << "NO" << endl;
  return 0;
}


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

int main(){
    int K,T,a[101];
    cin>>K>>T;
    for(int i=0;i<T;i++)cin>>a[i];
    vector<int>v;
    for(int i=0;i<T;i++){
        v.push_back(a[i]);
    }    
    while(v.size()!=1){
        sort(v.begin(),v.end());
        vector<int>vv;
        for(int i=1;i<v.size()-1;i++){
            vv.push_back(v[i]);
        }
        vv.push_back(v[v.size()-1]-v[0]);        
        v=vv;
    }
    cout<<max(0,v[0]-1)<<endl;
    return 0;
}


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

using namespace std;

using LL = long long;

template<typename T>
ostream& operator << (ostream& out, const vector<T>& v) {
    out << "[";
    for(const auto& x : v) {
        out << x << ", ";
    }
    return out << "]";
}

template<typename S, typename T>
ostream& operator << (ostream& out, const pair<S, T>& p) {
    return out << "{" << p.first << ", " << p.second << "}";
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    int N;
    LL x, y, z = 0;
    cin >> N >> x >> y;
    for(int i = 2; i < N; ++i) {
        LL u;
        cin >> u;
        z ^= u;
    }
    LL t = (x + y - z);
    if((t & 1) or t < 0) {
        cout << "-1\n";
        return 0;
    }
    t /= 2;
    if((t & z) or t > x) {
        cout << "-1\n";
        return 0;
    }
    for(int j = 60; j >= 0; --j) {
        if(z & (1LL << j)) {
            if(t + (1LL << j) <= x) {
                t += (1LL << j);
            }
        }
    }
    if(t == 0) {
        cout << "-1\n";
        return 0;
    }
    cout << (x - t) << "\n";
    
    
    return 0;
}


Measured memory_bytes: 3652
import java.io.BufferedReader;
import java.io.Closeable;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
	
	public static void main(String[] args) throws IOException {
		try(final Scanner sc = new Scanner(System.in)){
			final char[] S = sc.next().toCharArray();
			final long K = sc.nextLong();
			
			char fst = '1';
			for(int i = 0; i < Math.min(S.length, K); i++) {
				if(S[i] != '1') { fst = S[i]; break; }
			}
			
			System.out.println(fst);
		}
	}

	public static class Scanner implements Closeable {
		private BufferedReader br;
		private StringTokenizer tok;

		public Scanner(InputStream is) throws IOException {
			br = new BufferedReader(new InputStreamReader(is));
		}

		private void getLine() throws IOException {
			while(!hasNext()){
				tok = new StringTokenizer(br.readLine());
			}
		}

		private boolean hasNext() {
			return tok != null && tok.hasMoreTokens();
		}

		public String next() throws IOException {
			getLine();
			return tok.nextToken();
		}

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

		public long nextLong() throws IOException {
			return Long.parseLong(next());
		}

		public double nextDouble() throws IOException {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) throws IOException {
			final int[] ret = new int[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextInt();
			}
			return ret;
		}

		public long[] nextLongArray(int n) throws IOException {
			final long[] ret = new long[n];
			for(int i = 0; i < n; i++){
				ret[i] = this.nextLong();
			}
			return ret;
		}

		public void close() throws IOException {
			br.close();
		}
	}
}

Measured memory_bytes: 23252
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std;
using namespace __gnu_cxx;
#define write_to_file() freopen("output.txt" , "w" , stdout)
#define read_from_file() freopen("input.txt" , "r" , stdin)
#define GeoOutputFix(VV) cout<<fixed<<setprecision(VV)
#define MAX_V  1e9
#define MIN_V -1e9
template<class T>istream& operator>> (istream& is, complex<T>& p){T value;is >> value, p.real(value), is >> value, p.imag(value);return is;}
typedef long long lld;
typedef pair<lld, lld> dd;
typedef complex<double> point;
#define X real()
#define Y imag()
#define dist(a , b) sqrt(pow(a.X - b.X , 2) + pow(a.Y- b.Y , 2))
#define dist2(a , b) ((long double)hypot(a , b))
#define mid(a,b) (((a)+(b))/point(2,0))
#define compare(a , b) (fabs(a.X - b.X) < -1e9 && fabs(a.Y - b.Y) < -1e9)
#define all(c) c.begin() , c.end()
#define MOD (lld)(1e9+7)
#define EPS 1e-9
#define neighbours(u , e , v) for(int e = head[u] , v ; v = to[e] , ~e ; e = nxt[e])
#define watch1(x) cout<<(#x)<<" = "<<x<<"\n"
#define watch2(x , y) cout<<(#x)<<" = "<<x<<"  "<<(#y)<<" = "<<(y)<<"\n"
#define watch3(x , y , z) cout<<(#x)<<" = "<<x<<"  "<<(#y)<<" = "<<(y)<"  "<<(#z)<<" = "<<(z)<<"\n"
int dr[] = {1 , 1 , 1 , 0 , 0 , -1 , -1 , -1};
int dc[] = {-1 , 0 , 1 , -1 , 1 , -1 , 0 , 1};
int ddr[] = {1 , 0 , 0 , -1};
int ddc[] = {0 , -1 , 1 , 0};
inline int SD(){int i ;scanf("%d", &i);return i;}
inline lld SLL(){lld i;scanf("%lld", &i);return i;}
inline char SC(){char i;scanf(" %c", &i);return i;}
const int AKA = 1e6 + 6 , OO = 0x3f3f3f3f;
//----------------------------------------[TO_OO]--[To infinity and beyond]--------------------------------------------------------
bool ispal(int x)
{
    vector<int> v;
    while(x)
    {
        v.push_back(x % 10);
        x /= 10;
    }
    int n = v.size();
    for(int i = 0 ; i < n / 2 ; ++i)
        if(v[i] != v[n - i - 1])
            return false;
    return true;
}
int main()
{
    int a = SD() , b = SD() , ans = 0;
    for(int i = a ; i <= b ; ++i)
        ans += ispal(i);
    printf("%d" , ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pl = pair<ll, ll>;
constexpr int MN = 1e5+5;

ll N, X, goal, b[MN], l[MN], u[MN];
bitset<MN> used;

bool solve(ll M) {
	priority_queue<pl> pq;
	for (int i = 0; i < N; ++i) pq.emplace(X*u[i]-b[i]*u[i]+b[i]*l[i], i);

	ll sum = 0, cost = 0;
	used.reset();
	for (int i = 0; i < M/X; ++i) {
		sum += pq.top().f;
		cost += X;
		used[pq.top().s] = 1;
		pq.pop();
	}
	for (int i = 0; i < N; ++i) {
		if (used[i]) {
			if (sum-(X*u[i]-b[i]*u[i]+b[i]*l[i])+((M-cost)*u[i]-b[i]*u[i]+b[i]*l[i])+pq.top().f >= goal
			 || sum-(X*u[i]-b[i]*u[i]+b[i]*l[i])+(M-cost)*l[i]+pq.top().f >= goal) return 1;
		}
		else {
			if (sum+(M-cost)*u[i]-b[i]*u[i]+b[i]*l[i] >= goal
			 || sum+(M-cost)*l[i] >= goal) return 1;
		}
	}
	return 0;
}

int main() {
    if (fopen("in", "r")) freopen("in", "r", stdin), freopen("out", "w", stdout);
    ios_base::sync_with_stdio(0), cin.tie(0);

	cin >> N >> X;
	for (int i = 0; i < N; ++i) cin >> b[i] >> l[i] >> u[i];

	for (int i = 0; i < N; ++i) goal += b[i]*l[i];

	ll x = 0, y = N*X;
	while (x < y) {
		ll m = (x+y)/2;
		solve(m) ? y = m : x = m+1;
	}
	cout << y;
}


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

int main(){
	string b;
	cin >> b;

	if(b=="A") cout << "T";
	if(b=="T") cout << "A";
	if(b=="G") cout << "C";
	if(b=="C") cout << "G";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define pb push_back
#define vl vector
#define ff first
#define ss second
using namespace std;
int main()
{
    ll a,b,i,j,n,t,c,m;
    cin>>n>>m;
    a=n+m;
    b=n-m;
    c=n*m;
    ll ans=max(a,max(b,c));
    cout<<ans;
    
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
#define     FAST            ios_base::sync_with_stdio(false); cin.tie(0), cout.tie(0);
int main()
{

        ll n;
        cin>>n;

        ll x=0;
        while(1)
        {
            x+=1000;
            if(x>=n){break;}
        }

        cout<<abs(x-n)<<endl;

















    return 0;
}


Measured memory_bytes: 3632
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <string>

using namespace std;

int main(){
    long K, N;
    cin >> K >> N;

    vector<long> A(N);
    for (int i = 0; i < N; i++){
        cin >> A[i];
    }

    long max_distance = 0;
    for (int i = 0; i < N - 1; i++){
        long distance = A[i + 1] - A[i];
        if (distance > max_distance){
            max_distance = distance;
        }
    }

    long distance = (A[0] + K) - A[N - 1];
    if (distance > max_distance){
        max_distance = distance;
    }

    cout << K - max_distance << endl;

    return 0;
}


Measured memory_bytes: 1792
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		
		try(Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			
			int[] a = new int[n];
			int[] b = new int[n+1];
			
			b[0] = Integer.MAX_VALUE;
			b[n] = Integer.MAX_VALUE;
			for(int i = 0 ; i < n - 1 ; i++) {
				b[i+1] = sc.nextInt();
			}
			
			for(int i = 0 ; i < n ; i++ ) {
				a[i] = Math.min(b[i], b[i+1]);
			}
			
			int sum = Arrays.stream(a).sum();
			
			System.out.println(sum);
		}
		
	}
}

Measured memory_bytes: 28368
#include<stdio.h>
 
#define N 2000
int solve(int,int);
 
int A[N],n;
main(){
  int i,j,q,x,m[N];
   
  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++){
    x= solve(0,m[i]);
   if(x==1){
     printf("yes\n");
     x=0;
   }
   else{
     printf("no\n");
   }
  }
  return 0;
}
 
int solve(int i,int m){
  int res;
  if(m==0){
    return 1;
  }
  if(i>n){
    return 0;
  }
  else{
    res = solve(i+1,m)||solve(i+1,m-A[i]);
    return res;
  }
}

Measured memory_bytes: 588
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long
#define INF INT_MAX
#define mod 1000000007
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
ll pw(ll a, ll b) {
    if (b == 0) return 1;
    ll t = pw(a, b / 2);
    if (b % 2 == 0) return (t * t)%mod;
    else return ((t * t)%mod * a)%mod;
}
int main()
{
	ll n;cin>>n;
	ll a[n+1];for(ll i=0;i<n;i++)cin>>a[i];
	ll xx=a[0];
	for(ll i=1;i<n;i++)xx=xx^a[i];
	for(ll i=0;i<n;i++)
	{
		ll res=xx^a[i];
		cout<<res<<" ";
	}
}


Measured memory_bytes: 5184
open Hashtbl

let h = create 5

let ls = [|'M'; 'A'; 'R'; 'C'; 'H'|]

let rec inith n =
  if n > 0 then
    let c = (read_line ()).[0] in
    match c with
    | 'M' | 'A' | 'R' | 'C' | 'H' ->
        let v = try find h c with _ -> 0 in
        replace h c (v + 1) ;
        inith (n - 1)
    | _ -> inith (n - 1)


let rec calc i j k tmp =
  if k > 4 then tmp
  else
    calc i j (k + 1)
      ( tmp
      + (try find h ls.(i) with _ -> 0)
      * (try find h ls.(j) with _ -> 0)
      * try find h ls.(k) with _ -> 0 )


let rec inner i j tmp =
  if j > 3 then tmp
  else
    let tmp' = calc i j (j + 1) tmp in
    inner i (j + 1) tmp'


let rec outer i' tmp =
  if i' > 2 then tmp
  else
    let tmp' = inner i' (i' + 1) tmp in
    outer (i' + 1) tmp'


let () =
  inith (read_int ()) ;
  outer 0 0 |> Printf.printf "%d\n"

Measured memory_bytes: 2688
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<cstring>
using namespace std;
int min(int a,int b);
int main()
{
	int a[5]	;
	cin>>a[1]>>a[2]>>a[3];
	a[4]=a[1];
	int i,count=0;
	for(i=1;i<=3;i++)
	{
		if(a[i]==a[i+1])
		{
			count++;
		}
	}
	if(count==1)
	{
		cout<<"Yes"<<endl;
	}
	else
	{
		cout<<"No"<<endl;
	}
	return 0;
}


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

typedef pair <int,int> PII;
typedef vector <PII> VPII;

int main( void )
{
	int m, n;
	while ( cin >> m && m )
	{
		int x, y;

		VPII search( m );
		for ( int i = 0; i < m; i++ )
		{
			cin >> x >> y;
			search[i] = make_pair( x, y );
		}
		cin >> n;
		VPII field( n );
		for ( int i = 0; i < n; i++ )
		{
			cin >> x >> y;
			field[i] = make_pair( x, y );
		}

		VPII d( m );
		for ( int i = 1; i < m; i++ )
		{
			d[i].first = search[i].first - search[0].first;
			d[i].second = search[i].second - search[0].second;
		}

		for ( int i = 0; i < n; i++ )
		{
			bool found = true;
			for ( int j = 1; found && j < m; j++ )
			{
				PII q = field[i];
				q.first += d[j].first;
				q.second += d[j].second;
				bool not_found = true;
				for ( int k = 0; k < n; k++ )
				{
					if ( field[k] == q ) not_found = false;
				}
				if ( not_found ) found = false;
			}
			if ( found )
			{
				cout << field[i].first - search[0].first << " " << field[i].second - search[0].second << endl;
				break;
			}
		}
	}
	return 0;
}

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

using namespace std;

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

	int count_0 = 0, count_1 = 0;
	for (int i = 0; i < S.size(); ++i)
	{
		if (S[i] - '0' == 0) ++count_0;
		else ++count_1;
	}

	if (count_0 > count_1) cout << count_1 * 2 << endl;
	else cout << count_0 * 2 << endl;
	return 0;
}


Measured memory_bytes: 512
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,a,i,x=0,y=1000;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		scanf("%d",&a);
		if(x<a) x=a;
		if(y>a) y=a;
	}
	printf("%d\n",x-y);
	return 0;
}


Measured memory_bytes: 1684
import java.io.*;
import java.util.*;

 class Main {

    public static void main(String[] args) {
        FastReader rv = new FastReader();
        int x;
        x=rv.nextInt();
        if(x>=30)
            System.out.println("Yes");
        else
            System.out.println("No");

    }



    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new
                    InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 32672
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cout << H << " "; debug_out(T...); }
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int n,m;
  cin >> n >> m;
  int mini = 1, maxi = n;
  rep(i,m) {
    int l,r;
    cin >> l >> r;
    chmax(mini, l);
    chmin(maxi, r);
  }
  int ans = max(maxi - mini +1, 0);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
/* coordinate_compress_1D.cpp
    1Dの座標圧縮を行う
        Input: 5 3 3 1 6 1
        Output: 1 1 0 2 0

    verified: [AtCoder] ABC 036 C - 座圧
        https://atcoder.jp/contests/abc036/tasks/abc036_c
*/

#include <bits/stdc++.h>
using namespace std;

/* compress
    X を座標圧縮して書き換える（副作用）
    返り値: ソート済みの値
    計算量: O(n log n)
*/
template <typename T>
vector<T> compress(vector<T> &X) {
    vector<T> vals = X;
    sort(vals.begin(), vals.end());
    // 隣り合う重複を削除(unique), 末端のゴミを削除(erase)
    vals.erase(unique(vals.begin(), vals.end()), vals.end());
    for (int i = 0; i < (int)X.size(); i++) {
        X[i] = lower_bound(vals.begin(), vals.end(), X[i]) - vals.begin();
    }
    return vals;
}

int main() {
    int N, M;
    cin >> N >> M;
    vector<int> P(M), Y(M);
    vector<vector<int>> Xs(N);
    for (int i = 0; i < M; i++) {
        cin >> P.at(i) >> Y.at(i);
        P[i]--, Y[i]--;
        Xs[P[i]].push_back(Y[i]);
    }
    for (int i = 0; i < N; i++) {
        compress(Xs[i]);
        reverse(Xs[i].begin(), Xs[i].end());
    }

    for (int i = 0; i < M; i++) {
        printf("%06d%06d\n", P[i] + 1, Xs[P[i]].back() + 1);
        Xs[P[i]].pop_back();
    }
}


Measured memory_bytes: 7808
let z()=List.map int_of_string(Str.split(Str.regexp_string" ")(read_line()))open Array;;match z()with|[r;c]->(let a=make_matrix(r+1)(c+1)0in for i=0to r-1do let x=of_list(z())in for j=0to c-1do a.(i).(j)<-x.(j);a.(i).(c)<-a.(i).(c)+x.(j)done done;for i=0to c-1do for j=0to r-1do a.(r).(i)<-a.(r).(i)+a.(j).(i)done;a.(r).(c)<-a.(r).(c)+a.(r).(i)done;for i=0to r do for j=0to c do Printf.printf(if j=0then"%d"else if j=c then" %d
"else" %d")a.(i).(j)done done)|_->()

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

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

    if(h == 1 or w == 1){
        cout << 1 << endl;
        return 0;
    }

    if(h > w) swap(h,w);
    if(h % 2 == 0 && w % 2 == 0) {
        cout << h * (w / 2) << endl;
    } else {
        cout << h * (w - 1) / 2 + (h + 1) / 2 << endl;
    }
}



Measured memory_bytes: 256
//2014
#include<iostream>
using namespace std;
int main(void){
	int h,w,i,j,cnt=0;
	bool a=false;
	cin>>h>>w;
	char str[100][100]={};
	int num[100][100]={-1};
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			cin>>str[i][j];
			if(str[i][j]=='c'){
				num[i][j]=0;
				a=true;
				cnt=0;
			}
			else if(str[i][j]=='.'&&a==true){
				cnt++;
				num[i][j]=cnt;
			}
			else{
				num[i][j]=-1;
			}
		}
		a=false;
	}
	for(i=0;i<h;i++){
		for(j=0;j<w;j++){
			if(j==w-1){
				cout<<num[i][j];
			}
			else{
				cout<<num[i][j]<<" ";
			}
		}
		cout<<"\n";
	}
	
	return 0;
}


Measured memory_bytes: 3144
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <map>
#include <numeric>
#include <queue>
#include <stack>
#include <sstream>
#include <string>
#include <vector>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using ll = long long;
//typedef long long ll;

using std::cin;
using std::cout;
using std::cerr;
using std::endl;

#define INF ((1LL << 31) - 1)
#define INFLL ((1LL << 62) - 1)
#define MOD (ll)(1e9+7)
#define EPS 1e-10
#define repi(i,j,n) for(int i = (j); i < (n); ++i)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) for(int i = n; i >= 0; --i)
#define fi first
#define se second
#define all(v) (v).begin(), (v).end()

int vx[4] = {-1, 0, 1, 0}, vy[4] = {0, -1, 0, 1};
//int vx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, vy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};

// [sx, se), [sy, ey)であることに注意
inline bool check(int sx, int ex, int sy, int ey, int x, int y) {
  return (sx <= x and x < ex and sy <= y and y < ey);
}

inline bool check(int ex, int ey, int x, int y) {
  return check(0, ex, 0, ey, x, y);
}

std::vector<std::string> split(const std::string& s, char delim) {
  std::vector<std::string> ret;
  std::stringstream ss(s);
  std::string tmp;

  while (std::getline(ss, tmp, delim)) {
    ret.push_back(tmp);
  }

  return ret;
}

inline void init() {
  cin.tie(0);
  std::ios::sync_with_stdio(false);
}

int q, l, r;

bool is_prime[100002];

void e () {
  std::fill(is_prime, is_prime + 100001, true);

  is_prime[0] = is_prime[1] = false;

  for (int i = 2; i <= 100001; ++i) {
    if (is_prime[i]) {
      for (int j = 2; i * j <= 100001; ++j) {
        is_prime[i * j] = false;
      }
    }
  }

}

int main() {
  init();

  cin >> q;

  int sum[100002] = {0};

  e();

  for (int i = 1; i <= 100000; ++i) {
    if (is_prime[i] && is_prime[(i + 1) / 2]) {
      sum[i]++;
    }
    sum[i] += sum[i - 1];
  }

  for (int i = 0; i < q; ++i) {
    cin >> l >> r;
    cout << sum[r] - sum[l - 1] << endl;
  }


  return 0;
}

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

int parse(char c)
{
	switch(c){
	case 'I':
		return 1;
	case 'V':
		return 5;
	case 'X':
		return 10;
	case 'L':
		return 50;
	case 'C':
		return 100;
	case 'D':
		return 500;
	case 'M':
		return 1000;
	default:
		return 0;
	}
}

int main(void)
{
	string roman;
	int res = 0;
	int i;

	while(cin >> roman)
	{
		for(i=0; i<roman.size()-1; i++)
		{
			if( parse(roman[i]) >= parse(roman[i+1]) )
				res += parse(roman[i]);
			else
				res -= parse(roman[i]);
		}
		res += parse(roman[roman.size()-1]);
		cout << res << endl;
		res = 0;
	}

	return 0;
}

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

int main(){
    int S;
    cin >> S;
    int h;
    int m;
    int s;

    int amari;

    h = S / 3600;

    amari = S % 3600;

    m = amari / 60;

    s = amari % 60;

    cout << h << ":" << m << ":" << s << endl;

    return 0;

}


Measured memory_bytes: 3100
/* ***********************************************
Author        :taciturnity
Created Time  :2020/2/21 8:23:51
File Name     :TEST.cpp
************************************************ */

#include <iostream>
#include <vector>
#include <queue>
#include <cstdio>
#include <map>
#include <set>
#include <stack>
#include <string>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#define ll long long
#define INF 0x3f3f3f3f
#define rep(i,x,y) for(int i = x;i <= y;++i)
#define fori(i,x,y) for(int i = x;i >= y; -- i)
#define bug puts("--------------")
const int N = 1e5+10;
const double eps = 0.00000001;
const ll mod = 1e9 + 7 ;
using namespace std;
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*10+ch-'0';ch=getchar();}
    return x*f;
}
ll fac[N],inv[N];
int a[N];
ll Qpow(ll a,ll b,ll p){
    ll ans = 1;
    a %= p;
    while(b){
        if(b&1) ans = ans * a % p;
        b >>= 1;
        a = a * a % p;
    }
    return ans;
}
ll C(ll n,ll m){
    return fac[n]*Qpow(fac[n-m]*fac[m]%mod,mod-2,mod)%mod;
}
void init(){
    fac[0] = fac[1] = 1;
    for(int i = 2;i <= N-10;++i) fac[i] = fac[i-1]*i%mod;
}
int main(){
    init();
    int n,k;
    n = read();k = read();
    init();
    for(int i = 1;i <= n;++i) a[i] = read();
    sort(a + 1, a + n + 1);
    ll ans = 0;
    for(int i = 1;i <= n;++i){
       // bug;
        ll s1 = 0,s2 = 0;
        if(i >= k) s1 = C(i-1,k-1);
        if(i <= n-k+1) s2 = C(n-i,k-1);
        //cout<<i <<' '<<s1<<' '<<s2<<endl;
        ans = (ans + (s1-s2)*a[i]%mod)%mod;
    }
    cout <<(ans%mod+mod)%mod;
}

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

// @@ !! LIM()

void solve() {
  string S, T; cin >> S >> T;
  ll nS = S.size();
  ll nT = T.size();
  auto chkI = [&](ll& res) -> bool {
    for (ll i = nS - nT; i >= 0; i--) {
      auto chkJ = [&]() -> bool {
	for (ll j = 0; j < nT; j++) {
	  char cs = S.at(i + j);
	  char ct = T.at(j);
	  if (cs == ct || cs == '?') continue;
	  return false;
	}
	return true;
      };
      if (chkJ()) {
	res = i;
	return true;
      }
    }
    return false;
  };
  ll st;
  if (!chkI(st)) {
    cout << "UNRESTORABLE\n";
    return;
  }
  for (ll i = 0; i < nS; i++) {
    if (st <= i && i < st + nT) cout << T.at(i - st);
    else if (S.at(i) == '?') cout << 'a';
    else cout << S.at(i);
  }
  cout << endl;
}


int main(int argc, char *argv[]) {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << setprecision(20);
  solve();

  return 0;
}



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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;
class Solver {
 public:
  int n;
  vector<LL> a;
  Solver(LL n) : n(n), a(n + 1){};

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

    LL v = 0;
    vector<LL> ub(n + 1);

    for (int d = n; d >= 0; --d) {
      v += a[d];
      ub[d] = v;
    }

    v = 1;
    for (int d = 0; d <= n; ++d) {
      ub[d] = min(v, ub[d]);
      v -= a[d];
      if (v < 0) {
        cout << -1 << endl;
        return;
      }
      v *= 2;
      v = min(LINF, v);
    }
    DBG(ub)
    DBG(v)

    cout << accumulate(ub.begin(), ub.end(), 0ll) << endl;
  }
};

}  // namespace Problem

signed main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 4780