akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main()
{
    double N, K;
    cin >> N >> K;
    vector<int> A(N);
    for (int i = 0; i < N; i++){
        cin >> A.at(i);
    }

    cout << ceil((N - 1) / (K - 1)) << endl;
}

Measured memory_bytes: 640
#include <stdio.h>
int main(void) {
	int n, h, m, s;
	scanf("%d", &n);

	h = n / 3600;
	n = n % 3600;
	m = n / 60;
	s = n % 60;

	printf("%d:%d:%d\n", h, m, s);
	return 0;
}

Measured memory_bytes: 592
#include<bits/stdc++.h>
//#pragma comment(linker,"/STACK:1024000000,1024000000")
//251103FD
//4008802802
//4008160009
using namespace std;
#define PB pop_back
#define PF pop_front
#define np next_permutation
#define eb emplace_back
#define pb push_back
#define bf push_front
#define mp make_pair
#define s second
#define f first
#define foreach(it, a) for(__typeof((a).begin()) it=(a).begin(); it!=(a).end(); it++)
#define Foreach(it, a) for(__typeof((a).rbegin()) it=(a).rbegin(); it!=(a).rend(); it++)
#define forn(i, a) for(register int i=0; i<a; i++)
#define Forn(i, a) for(register int i=1; i<=a; i++)
#define memINF 127
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false)

typedef long long ll;
typedef pair<int,int> pi;
typedef pair<pi,int> pii;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef unsigned int uint;

inline int in() 
{
    int x=0, c;
    while((uint)((c=getchar())-48)>=10) 
		if(c=='-') 
			return -in();
    do 
	{ x=(x<<3)+(x<<1)+(c^48); }
	while((uint)((c=getchar())^48)<10);
    return x;
}
inline int lcm(int a, int b){return a*b/__gcd(a, b);}

const int MAX=1e5+5;
const int MAX_LOG=20;

int N, L, Q, l, r, ret, x[MAX], to[MAX], st[MAX_LOG][MAX];

int main()
{
    N=in();
    Forn(i, N)
        to[i]=x[i]=in();
    for(int i=N; i>0; --i)
        to[i]-=to[i-1];
    to[1]=0;
    
    Forn(i, N)
        to[i]+=to[i-1];
    
    L=in(), Q=in();
    Forn(i, N)
    {
        st[0][i]=lower_bound(to+1, to+1+N, L+to[i])-to;
        if(to[st[0][i]]!=L+to[i])
            --st[0][i];
    }
    
    forn(lg, MAX_LOG-2)
        Forn(i, N)
            st[lg+1][i]=st[lg][st[lg][i]];
    
    while(Q--)
    {
        l=in(), r=in(), ret=0;
        if(l>r)
            swap(l, r);
        for(int lg=MAX_LOG-1; lg>-1; --lg)
            if(st[lg][l]&&st[lg][l]<r)
                l=st[lg][l], ret+=1<<lg;
        printf("%d\n", ret+1);
    }
    return 0;
}

Measured memory_bytes: 9472
//2020-06-02 
#include <bits/stdc++.h>
using namespace std;
#define loop(v, st, en) for (int v = st; v < en; v++)
#define loopdesc(v, st, en) for (int v = st; v >= en; v--)
#define INF 1E9
#define clr(v, d) memset(v, d, sizeof(v))
#define pb push_back
#define MP make_pair
#define P(x) cout << #x  <<" = { "<< x<<" }\n"
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef vector<int> vi;
const int M=2e5+5;



int main () {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    //freopen("input.txt", "r", stdin);
    int x , y; cin>>x>>y;
    cout<<x*y;
    return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define Rep(i,n) for(int i=0;i<(int)(n);i++)
#define For(i,n1,n2) for(int i=n1;i<(int)(n2);i++)
using namespace std;

signed main()
{
	string v;
	cin >> v;

	if(v == "Sunny"){
		cout << "Cloudy";
	}else if(v == "Cloudy"){
		cout << "Rainy";
	}else if(v == "Rainy"){
		cout << "Sunny";
	}

	return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python2
# -*- coding: utf-8 -*-
"""
Created on Thu Dec 14 22:14:39 2017

@author: Kanoh
"""

#Placing Marbles
input_line1 = raw_input()#標準入力
total=0
counter=0
for i in range(len(input_line1)):
    if(int(input_line1[i])==1):
        counter=counter+1
        
print counter

Measured memory_bytes: 2568
import java.util.Scanner;

public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();

	if(a<b&&b<c){
		System.out.println("Yes");
		}else{
		System.out.println("No");
		}
	}
}

Measured memory_bytes: 17356
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			long n = sc.nextLong();
			long m = sc.nextLong();

			long max = m / n;

			for (long i = max; 0 < i; i--) {
				if (m % i == 0) {
					System.out.println(i);
					return;
				}
			}
		}
	}
}


Measured memory_bytes: 21972
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>

using namespace std;
int main()
{
	string a;
	cin >> a;

	
	if (a[0] == a[2])
		cout << "Yes" << endl;

	else
		cout << "No" << endl;


	return 0;
}

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

using namespace std;

int h, w, k, ans;
char c[6][6];

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	cin >> h >> w >> k;
	for (int i = 0; i < h; ++i)
		for (int j = 0; j < w; ++j)
			cin >> c[i][j];

	int rows = 1 << h, columns = 1 << w;
	for (int i = 0; i < rows; ++i) {
		for (int j = 0; j < columns; ++j) {
			int cnt = 0;

			for (int p = 0; p < h; ++p) {
				if ((i >> p) & 1)
					continue;

				for (int q = 0; q < w; ++q) {
					if ((j >> q) & 1)
						continue;

					if (c[p][q] == '#')
						++cnt;
				}
			}

			if (cnt == k)
				++ans;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3632
"use strict";
var input=require("fs").readFileSync("/dev/stdin","utf8");
var cin=input.split(/ |\n/),cid=0;
function next(a){return a?cin[cid++]:+cin[cid++];}
function nexts(n,a){return a?cin.slice(cid,cid+=n):cin.slice(cid,cid+=n).map(a=>+a);}
function nextm(h,w,a){var r=[],i=0;if(a)for(;i<h;i++)r.push(cin.slice(cid,cid+=w));else for(;i<h;i++)r.push(cin.slice(cid,cid+=w).map(a=>+a));return r;}
function xArray(v){var a=arguments,l=a.length,r="Array(a["+--l+"]).fill().map(x=>{return "+v+";})";while(--l)r="Array(a["+l+"]).fill().map(x=>"+r+")";return eval(r);}

var myOut = main();
if(myOut !== undefined)console.log(myOut);

function main(){
  var a = nexts(9);
  var n = next();
  var m = xArray(0,8);
  for(var i = 0; i < n; i++){
    var b = next();
    switch(b){
      case a[0]: m[1]++, m[4]++, m[7]++; break;
      case a[1]: m[1]++, m[6]++; break;
      case a[2]: m[1]++, m[0]++, m[5]++; break;
      case a[3]: m[2]++, m[7]++; break;
      case a[4]: m[2]++, m[0]++, m[4]++, m[6]++; break;
      case a[5]: m[2]++, m[5]++; break;
      case a[6]: m[3]++, m[0]++, m[7]++; break;
      case a[7]: m[3]++, m[6]++; break;
      case a[8]: m[3]++, m[4]++, m[5]++; break;
    }
  }
  return Math.max(...m) === 3 ? "Yes" : "No";
}

Measured memory_bytes: 9420
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define PP pair<P,P>
using namespace std;

const int mod = 1000000007;
struct mint {
  ll x; // typedef long long ll;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res+=a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res-=a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res*=a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const {
    return pow(mod-2);
  }
  mint& operator/=(const mint a) {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const {
    mint res(*this);
    return res/=a;
  }
};

#define P pair<ll, ll>

// 出力は.xで！！！！
/*
ll ni(ll a){
    if(a==0) return 1;
    else if(a%2==0) return ((ni(a/2)%MOD)*(ni(a/2)%MOD)%MOD);
    else return ((ni(a-1)%MOD)*2%MOD);
}
*/

mint dp[2005][2005];
mint sum[2005][2005];

int main(){
int n,m; cin >> n >> m;
  int s[n];
  int t[m];
  rep(i,n) cin >> s[i];
  rep(i,m) cin >> t[i]; 
  rep(i,n+1) sum[i][0]=0;
  rep(i,m+1) sum[0][i]=0;

  for(int i=1; i<=n; i++){
    for(int j=1; j<=m; j++){
        sum[i][j]=sum[i-1][j]+sum[i][j-1]-sum[i-1][j-1]+dp[i-1][j-1];
        //sum[i][j]%=MOD;
        if(s[i-1]==t[j-1]) dp[i][j]=sum[i][j]+1;
        else dp[i][j]=0;
        //dp[i][j]%=MOD;
    }
  }

  mint ans=1;
  rep(i,n+1)rep(j,m+1){
      ans+=dp[i][j];
      //ans%=MOD;
  }
  cout << ans.x << endl;
return 0;
}


Measured memory_bytes: 63104
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <cmath>
#include <cassert>
#include <cstdarg>
#include <sys/time.h>
#include <fstream>
//#include "cout.h"

using namespace std;

#define SZ(x) ((int)x.size())
#define MSET(x,a) memset(x, a, (int)sizeof(x))
#define PB push_back
#define VI vector < int >
#define PII pair < int, int >
#define LL long long
#define FOR(i,a,b) for (int i = (a); i < (b); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(), (v).end()
#define FIT(it,v) for (typeof((v).begin()) it = (v).begin(); it != (v).end(); it++)
#define OUT(A) cout << #A << " = "<< (A) << endl
#define OUT2(A, B) cout << "(" << #A << ", " << #B << ") = (" << (A) << ", "<< (B) << ")" << endl
template<class T> void chmin(T &t, T f) { if (t > f) t = f; } 
template<class T> void chmax(T &t, T f) { if (t < f) t = f; } 

#define present(c, e) ((c).find((e)) != (c).end())
#define cpresent(c, e) (find(all(c), (e)) != (c).end())

int n, x[110];

    const int MAX_V = 210;
    
    int V; // 左の頂点数。忘れずに設定すること。
    // ちなみに、Vは左右合わせた全部の頂点数でも問題ない。（左が終わった後に右からのをチェックしても、マッチ数は絶対増えない）
    
    
    VI G[MAX_V]; // ちゃんとGもケースごとに全部clear。
    int match[MAX_V];
    bool used[MAX_V];
    
    void add_edge(int u, int v){
        G[u].PB(v);
        G[v].PB(u);
    }
    
    bool dfs(int v){
        used[v] = true;
        REP(i, SZ(G[v])){
            int u = G[v][i], w = match[u];
            if(w < 0 || (!used[w] && dfs(w))){
                match[v] = u;
                match[u] = v;
                return true;
            }
        }
        return false;
    }
    
    int bipartite_matching(){
        int res = 0;
        MSET(match, -1);
        REP(v, V){
            if(match[v] < 0){
                MSET(used, 0);
                if(dfs(v)) res++;
            }
        }
        return res;
    }

void init() {
}

void input() {
	cin >> n;
	REP(i, n) cin >> x[i];
	
}

bool g[110][110];
VI res;

int cnt(VI used, int a){
	bool canuse[n]; REP(i, n) canuse[i] = true;
	REP(i, a) canuse[i] = false;
	REP(i, SZ(used)){
		canuse[used[i]] = false;
		REP(j, n) if(g[used[i]][j] || g[j][used[i]]) canuse[j] = false;
	}
	
	map<int, int> idx;
	V = 0;
	REP(i, MAX_V) G[i].clear();
	REP(i, n) if(canuse[i]) idx[i] = V++;
	REP(i, n) REP(j, n) if(i != j && canuse[i] && canuse[j] && g[i][j]) add_edge(idx[i], idx[j]+V);
	return V - bipartite_matching();
}

void solve() {
	REP(i, 110) REP(j, 110) g[i][j] = false;
	REP(i, n) REP(j, n) if(i != j && x[i]%x[j] == 0) g[i][j] = true;
	
	res.clear();
	REP(i, n){
		int cnt1 = cnt(res, i+1);
		int cnt2 = 0;
		bool test = true;
		REP(j, SZ(res)) if(g[res[j]][i] || g[i][res[j]]) test = false;
		VI tmp = res; tmp.push_back(i);
		if(test) cnt2 = cnt(tmp, i+1) + 1;
		if(cnt2 >= cnt1 && cnt2 != 0) res.push_back(i);
	}
	REP(i, SZ(res)) cout << res[i]+1 << (i == SZ(res)-1 ? "" : " ");
	cout << endl;
}

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

Measured memory_bytes: 1268
#include<bits/stdc++.h>
using namespace std;
int main()
  {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  
  while(b<=a&&k>0)
    {
    b = b*2;
    k--;
    }
  while(c<=b&&k>0)
    {
    c = c*2;
    k--;
    }
  if(c>b&&b>a)
    cout<<"Yes"<<endl;
  else
    cout<<"No"<<endl;
  }

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

import numpy
import scipy
#import sys


N, Y = map(int, input().split())

find = False
for x in range(N+1):
    for y in range(N+1-x):
        z = N - x - y
        if find:
            break
        sum = x*10000 + y*5000 + z*1000
        if sum == Y:
            find = True
            print("{} {} {}".format(x, y, z))
            #sys.exit()

if not find:
    print("-1 -1 -1")


Measured memory_bytes: 14456
import itertools
import math

n = int(input())
xy = []

for _ in range(n):
	xy.append(list(map(int,input().split())))

l = list(itertools.permutations(range(n)))

ans = 0
count = 0
for i in range(len(l)):
	for j in range(n-1):
		ans += math.sqrt((xy[l[i][j]][0] - xy[l[i][j+1]][0])**2 + (xy[l[i][j]][1] - xy[l[i][j+1]][1])**2)
	count += 1

print(ans / count)


Measured memory_bytes: 7972
while True:
	time=input()

	if time==0:
		break

	worr={}
	mem=[]

	for i in range(time):
		shain=map(int, raw_input().split())
		if shain[0] not in worr:
			worr[shain[0]]=shain[1]*shain[2]
			mem.append(shain[0])
		else:
			worr[shain[0]]+=shain[1]*shain[2]

	check=1
	for i in mem:
		if worr[i]>=1000000:
			print i
			check=0
	if check==1:
		print "NA"

Measured memory_bytes: 6372
#include <stdio.h>
#include <limits.h> 
#define N 100

void  matrixChainOrder(int , int * );
int min(int , int );

int M[N+1][N+1];

int main(){

  int n;
  int P[N+1];
  int i;

  scanf("%d",&n);

  for(i=1; i<=n ;i++){
    scanf("%d%d",&P[i-1],&P[i]);
  }
//printf("\n");
  for(i=0; i<=n ;i++){
//  printf("%d ",P[i]);
  }

  
matrixChainOrder(n,P);
//printf("\n");
printf("%d\n",M[1][n]);
  
return 0;
}

void  matrixChainOrder(int n, int *p){
int i,l,k,q,j;
int INF = INT_MAX;
//n = n -1;//p.length -1

for( i=1 ; i < n ; i++ ){
M[i][i]=0;  
  }

  for(l=2; l <=n ;l++){
    for(i=1 ; i<=n-l+1 ;i++){
      j= i+l-1;
      M[i][j] = INF;
    
      for(k= i ; k <= j-1; k++){
	q = M[i][k] + M[k+1][j] + p[i-1]*p[k]*p[j];
	M[i][j] = min(M[i][j],q);
      }
    }
  }
}

int min(int a, int b){
  if(a < b)return a;
  else return b;
}



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

using namespace std;
typedef long long ll;
const int N = 2e5 + 5;

int n, h[N];

int main() {
    scanf("%d",&n);
    for(int i=0;i<n;++i){
        scanf("%d",h+i);
    }
    for(int i=n-2;i>-1;--i){
        if(h[i]>h[i+1]+1)
            return printf("No"), 0;
        if(h[i]==h[i+1]+1)
            h[i]=h[i+1];
    }
    printf("Yes");
    return 0;
} 

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

int main()
{
	int m,d;
	cin >> m >> d;
	int ans = 0;
	
	for(int i = 4;i <= m;i++){
		for(int j = 22;j <= d;j++){
			if((j/10)*(j%10) == i && (j/10) >= 2 && (j%10) >= 2) ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
from collections import Counter

def main():
    N = int(input())
    pf = prime_factorize(N)

    ans = 0
    for v in pf.values():
        for i in range(1, 100000000):
            if i > v:
                break
            ans += 1
            v -= i

    print(ans)


def prime_factorize(n):
    a = []
    while n % 2 == 0:
        a.append(2)
        n //= 2
    f = 3
    while f * f <= n:
        if n % f == 0:
            a.append(f)
            n //= f
        else:
            f += 2
    if n != 1:
        a.append(n)
    return Counter(a)

main()

Measured memory_bytes: 9468
#include<stdio.h>
int main(){
  int a,b,c,k,s=0;
  scanf("%d %d %d %d",&a,&b,&c,&k);
  if(k<a){
    printf("%d",k);
  }else{
    s+=a;
    k-=a;
    if(k<b){
      printf("%d",s);
    }else{
      k-=b;
      printf("%d",s-k);
    }
  }
  return 0;
}

Measured memory_bytes: 1728
#include<stdio.h>

void printSharp(int w){
    for(int i = 0;i < w+2;i++) printf("#");
    printf("\n");
}

int main(void){

    int H,W,i,j;
    char a[101][101];

    scanf("%d %d",&H,&W);
    for(i = 0;i < H;i++){
        scanf("%s",a[i]);
    }

    printSharp(W);
    for(i = 0;i < H;i++){
        printf("#");
        printf("%s",a[i]);
        printf("#");
        printf("\n");
    }
    printSharp(W);

    return 0;
}

Measured memory_bytes: 128
import sys
sys.setrecursionlimit(10**7)

n,q=map(int,input().split())
ans=[0 for _ in range(n)]
gra=[[] for _ in range(n)]
visited=[0 for _ in range(n)]

for _ in range(n-1):
  a,b=map(int,input().split())
  gra[a-1].append(b-1)
  gra[b-1].append(a-1)
  
for _ in range(q):
  p,x=map(int,input().split())
  ans[p-1]+=x
  
def dfs(st):
  temp=gra[st]
  for i in temp:
    if visited[i]==0:
      visited[i]+=1
      ans[i]+=ans[st]
      dfs(i)
      
visited[0]+=1
dfs(0)

for h in range(n):
  ans[h]=str(ans[h])
  
print(' '.join(ans))

Measured memory_bytes: 232960
from enum import Enum

class Status(Enum):
    EQUAL =1
    BIG = 2
    SMALL = 3

N = input()
P = [int(x) for x in input().split()]

count = 0

before_status = Status.EQUAL
before_value = P[0]
for p in P:
    if before_value == p:
        before_status = Status.EQUAL
    elif before_status == Status.BIG:
        if before_value < p:
            before_status = Status.BIG
            count += 1
        else:
            before_status = Status.SMALL
    elif before_status == Status.SMALL:
        if before_value > p:
            before_status = Status.SMALL
            count += 1
        else:
            before_status = Status.BIG
    else:
        if before_value < p:
            before_status = Status.BIG
        else:
            before_status = Status.SMALL
    before_value = p

print(count)

Measured memory_bytes: 3444
// #include <bits/stdc++.h>
#include <iostream>
#include <map>
#include <cmath>
#include <ios>
#include <iomanip>
#include <algorithm>
#include <queue>
#include <stack>
#include <numeric>
// #include <windows.h>
using namespace std;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;
template<class T> using VVV = V<VV<T>>;
template<class T1, class T2> using P = pair<T1, T2>;
using I = int;
using D = double;
using B = bool;
using C = char;
using S = string;
using LL = long long;
using LD = long double;
using ULL = unsigned long long;
using PII = P<I, I>;
using VPII = V<PII>;
using PLL = P<LL, LL>;
using VPLL = V<PLL>;
using VI = V<I>;
using VVI = VV<I>;
using VLL = V<LL>;
using VVLL = VV<LL>;
using VC = V<C>;
using VVC = VV<C>;
using VS = V<S>;
using VVS = VV<S>;
using VB = V<B>;
using VVB = VV<B>;
#define REP(type, i, n) for (type i = 0; i < (type)(n); ++i)
#define REP2(type, i, m, n) for (type i = (m); i < (type)(n); ++i)
#define REPR(type, i, n) for (type i = (n)-1; i >= 0; --i)
#define REPR2(type, i, m, n) for (type i = (n)-1; i >= (m); --i)
#define REPx(x, a) for(auto x : a)
#define ALL(a) a.begin(), a.end()
#define SORT(a) sort(ALL(a))
#define SORTR(a, type) sort(ALL(a), greater<type>())
#define SORTF(a, comp) sort(ALL(a), comp)
#define REVERSE(a) reverse(ALL(a))
#define SIZE(a, type) ((type)(a).size())
#define bit_search(bit, n) REP(LL, bit, 1LL<<(n))
#define bit_check(bit, i) ((bit>>(i)) & 1)
#define setpre(n) fixed << setprecision((n))
#define UNIQUE(a) do {SORT(a); (a).erase(unique(ALL(a)), (a).end());} while(0)
#define MAX(a) *max_element(ALL(a))
#define MIN(a) *min_element(ALL(a))
#define bisect_left(a, x) (lower_bound(ALL(a), (x)) - a.begin())
#define bisect_right(a, x) (upper_bound(ALL(a), (x)) - a.begin())
#define INPUT(a) REPx(&x, a) cin >> x;
#define INPUT2(a) REPx(&x, a) INPUT(x);
#define INPUTP(a) REPx(&x, a) cin >> x.first >> x.second;
#define ENDL cout << endl;

// const int INF = 2e9;
const LL INF = 9e18;
const LL MOD = 1e9+7;

template<class T> using PRIORITY_QUEUE = priority_queue< T, V<T>, greater<T> >;
template<class T> inline bool chmin(T &a, T b){if (a > b) {a = b; return true;} return false;}
template<class T> inline bool chmax(T &a, T b){if (a < b) {a = b; return true;} return false;}
template<class T> inline void debug1(V<T> A){REP(int, i, SIZE(A, int)){if (A[i] == INF) cout << "I ";else cout << A[i] << " ";}ENDL}
template<class T> inline void debug2(VV<T> A){REP(int, i, SIZE(A, int)){REP(int, j, SIZE(A[i], int)){if (A[i][j] == INF) cout << "I "; else cout << A[i][j] << " ";}ENDL}}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  LL x, y, ans = INF;
  cin >> x >> y;
  if (x*y == 0) ans = abs(x+y)+1;
  if (x*y > 0)
  {
    if (y >= x) ans = abs(x-y);
    else ans = x - y + 2;
  }
  else
  {
    if (y > x) ans = abs(x-y);
    chmin(ans, abs(x+y)+1);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3640
#!/usr/bin/env python
import os
import sys
from io import BytesIO, IOBase

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")

import math

n = int(input())
ans = 0

for i in range(1, n + 1):
    for j in range(1, n + 1):
        for k in range(1, n + 1):
            ans += math.gcd(math.gcd(i, j), k)

print(ans)


Measured memory_bytes: 68080
#include<stdio.h>
#include<string.h>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define lln long long int

int main(){

	lln nn,kk,aa,bb;
	lln ans = 0;

	scanf("%lld %lld",&nn,&kk);

	lln array[100001];
	memset(array,0,sizeof(array));

	while(nn--){
		scanf("%lld %lld",&aa,&bb);
		array[aa] += bb;
	}

	FOR(i,0,100001){
		ans += array[i];
		if(ans >= kk){
			printf("%d\n",i);
			break;
		}
	}
}

Measured memory_bytes: 896
#include <iostream>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <functional>
#include <string>
#include <stack>
#include <set>
#include <sstream>
#include <iomanip>
#include <limits>
#include <cstring>


using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<double, double >pd;
typedef pair<string, string> sP;
typedef pair<ll, P> PP;


const ll mod = 1e4;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const double eps = 1e-10;
const double PI = 3.14159265358979323846;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };


#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int N, M, L, R, D;

struct weight_Union_Find_Tree {
private:
	vector<ll>par;
	vector<ll>Rank;
	vector<ll>diff_weight;
public:
	void init(int n) {//初期化
		n += 10;
		par.resize(n);
		Rank.resize(n);
		diff_weight.resize(n);
		for (int i = 0;i < n;i++) {
			par[i] = i;
			Rank[i] = 0;
			diff_weight[i] = 0;
		}
		return;
	}

	ll root(int x) {//経路圧縮＋重み差分更新
		if (par[x] == x) return x;
		ll r = root(par[x]);
		diff_weight[x] += diff_weight[par[x]];
		return par[x] = r;
	}

	ll weight(int x) {//重みの取得
		root(x);
		return diff_weight[x];
	}

	bool same(int x, int y) {//根が同じか判定
		if (root(x) == root(y))return true;
		return false;
	}

	bool merge(int x, int y, ll w) {//併合したい頂点x,yと、その間の重みw
		w += weight(x);
		w -= weight(y);
		x = root(x), y = root(y);
		if (x==y)return false;//すでに併合されているならfalse
		if (Rank[x] < Rank[y])swap(x, y), w = -w;
		if (Rank[x] == Rank[y])Rank[x]++;
		par[y] = x;
		diff_weight[y] = w;
		return true;
	}

	ll diff(int x, int y) {//頂点間の重みの差分を返す
		return weight(y) - weight(x);
	}
};


int main() {	
	cin >> N >> M;
	weight_Union_Find_Tree uf;
	uf.init(N);
	for (int i = 0;i < M;i++) {
		cin >> L >> R >> D;
		if (!uf.merge(L, R, D) && uf.diff(L, R) != D) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}



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

#define FOR(i, a, b) for (int i = a; i <= b; ++i)
#define FORD(i, b, a) for (int i = b; i >= a; --i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define FORE(i, v) for (auto i = v.begin(); i != v.end(); ++i)

const int maxN = 1e5 + 10;
const int MOD = 1e9 + 7;

int n, d;
int pos[maxN];
int fact[maxN], inv[maxN];

int power(int n, int k) {
    int res = 1;
    while (k) {
        if (k & 1) res = 1ll * res * n % MOD;
        n = 1ll * n * n % MOD;
        k >>= 1;
    }
    return res;
}

int C(int n, int k) {
    if (n < k) return 0;
    return 1ll * fact[n] * inv[k] % MOD * inv[n - k] % MOD;
}

int main() {
   // freopen("input.in", "r", stdin);
//    freopen("output.out", "w", stdout);

    scanf("%d", &n);
    FOR(i, 1, n + 1){
        int x;  scanf("%d", &x);
        if (!pos[x])
            pos[x] = i;
        else
            d = i - pos[x];
    }

    fact[0] = inv[0] = 1;
    FOR(i, 1, n + 1) {
        fact[i] = 1ll * fact[i - 1] * i % MOD;
        inv[i] = power(fact[i], MOD - 2);
    }

    FOR(k, 1, n + 1) {
        printf("%d\n", (C(n + 1, k) - C(n - d, k - 1) + MOD) % MOD);
    }


    return 0;
}


Measured memory_bytes: 2432
#include<stdio.h>
int m,k,i,r,a,b;
char n[101];
int main(){
    scanf("%s%d",n,&k);
    for(m=0;n[m]!='\0';m++);
    if(k==1)r=(n[0]-48)+9*(m-1);
    if(k==2){
        a=-1;
        for(i=1;i<m;i++)if(n[i]>48){a=i;break;}
        r=81*(m-1)*(m-2)/2+9*(n[0]-49)*(m-1);
        r+=a>0?(n[a]-48)+9*(m-a-1):0;
    }
    if(k==3){
        a=b=-1;
        for(i=1;i<m;i++){
            if(n[i]>48){
                if(a<0)a=i;
                else if(b<0)b=i;
            }
        }
        r=729*(m-1)*(m-2)*(m-3)/6+81*(n[0]-49)*(m-1)*(m-2)/2;
        r+=a>0?(n[a]-49)*9*(m-a-1)+81*(m-a-1)*(m-a-2)/2:0;
        r+=a>0&&b>0?(n[b]-48)+9*(m-b-1):0;
    }
    printf("%d",r);
    return 0;
}

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

int main(){
	char a[20];
	size_t n;
	cin>>a;
	n=strlen(a);
	for(int i=n-1 ; i>=0 ; i--){
		cout << a[i] ;
	}
	cout << endl;
	return 0;
}

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

int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  for (auto& e : a) cin >> e;

  ll r = 0;
  for (int i = 1; i < n; i++) {
    ll d = max(0ll, a[i - 1] - a[i]);
    a[i] += d;
    r += d;
  }
  cout << r << endl;
}


Measured memory_bytes: 4788
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;

import static java.lang.Math.max;



public class Main {

   

    public static void main(String args[]) throws Exception {
        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        System.out.println(n+n*n+n*n*n);

    }
}

Measured memory_bytes: 35672
object Main extends App {
    for (Array(a, b, n) <- io.Source.stdin.getLines.map(_.split(" ").map(_.toInt))) {
        var rem = a % b
        var res = 0
        (0 until n).foreach(_ => {
            rem *= 10
            res += rem / b
            rem %= b
        })
        println(res)
    }
}

Measured memory_bytes: 44140
/* ?  ?        ????????????????         ? ? ?            ????????????????               ??     ??        ? ? ?           ???????        
		?             ??              ?       ?                 ??                      ??   ??        ?       ?        ??    ??     
   		 ?            ??             ?         ?                ??                      ?? ??         ?         ?      ??     ??         
  ?????????           ??             ?         ?                ??                      ??            ?         ?     ??      ??         
		 ?            ??             ?         ?                ??                      ?? ??         ?         ?   ??????????????                    
		?             ??              ?       ?                 ??                      ??   ??        ?       ?    ??          ??         
   ?  ?               ??                ? ? ?                   ??                      ??     ??        ? ? ?     ??           ??          
 
 
    ??     ?        ??    ?   ?   ?  ?   ??          ?  ?      ??     ?    ?    ????????  ?    ?                       
   ?      ? ?      ?  ?    ???    ????  ?  ?         ????     ?  ?    ?  ? ?       ??     ?  ? ?                       
   ?     ?   ?     ?  ?    ???    ?  ?  ?  ?         ?  ?    ??????   ? ?  ?       ??     ? ?  ?                 
    ??  ?     ?     ??    ?   ?   ?  ?   ??          ?  ?   ?      ?  ?    ?       ??     ?    ?                                      
                                                                                       
     ?      ?????    ??????    ?  ?    ???           ???????     ???     ????????    ???????       ?? ??      ?? ??     ??????????    ??                                                                               
    ? ?     ?        ??        ? ?   ?     ?         ??   ??   ?     ?      ??       ??            ??  ??    ??  ??         ??        ?? 
   ?   ?    ?????    ??        ??    ?     ?         ??   ??   ?     ?      ??       ???????       ?? ??      ?? ??         ??        ?? ??                                                           
  ?     ?   ?        ??        ? ?   ?     ?         ??   ??   ?     ?      ??       ??            ??        ??  ??         ??        ??  ?? 
 ?       ?  ?????    ??        ?  ?    ???           ??   ??     ???        ??       ????????      ??       ??   ??         ??        ?? ??                         
 
 
 
 
 
*/
 
#include <bits/stdc++.h>
 
using namespace std;
 
 
#define pb push_back
#define F first
#define S second
#define sz(a) (int)a.size()
#define all(a) a.begin(), a.end() 
 
int n,m,y,cnt,l,r;
int sum[1000005];
int a[1000005];
vector <int> v;
char s[1000001],c[1000001];
 
 
int main () {
	cin >> n;
	for (int i = 0; i < n; i++){
		cin >> s[i];
	}
	for (int i = 0; i < n; i++){
		cin >> c[i];
	}
	for (int i = 0; i < n; i++){
		cout << s[i] << c[i];
	}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll t,n,i,j,k,a,b,c,sum=0;
    cin>>n;
    vector<string>v(n),v1(n);
    for(i=0;i<n;i++)
    {
        cin>>v[i];
        v1[i]=v[i];
    }
    sort(v1.begin(),v1.end());
    v1.erase(unique(v1.begin(),v1.end()),v1.end());
    if(v1.size()!=v.size())
     {
         cout<<"No";
         return 0;
     }
     for(i=1;i<n;i++)
     {
         if(v[i][0]==v[i-1][(v[i-1].size())-1])
            sum++;
     }
     if(sum==(n-1))
        cout<<"Yes";
     else
        cout<<"No";

}


Measured memory_bytes: 384
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define print(x) cout<<(x)<<endl
#define INF10 1001001001 
#define INF5 100000
#define EPS 1e-10



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

	int ans = 0;
	for (int i = 1; i <= N; i++) {
		if (0 <= i && i <= 9)ans++;
		else if (100 <= i && i <= 999)ans++;
		else if (10000 <= i && i <= 99999)ans++;
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
	long long a,b,c,k;
	cin>>a>>b>>c>>k;
	if(a+b>=k) 
	{
		if(a<=k)cout<<a<<endl;
		else cout<<k<<endl;
	}
	else cout<<a-(k-(a+b))<<endl;
	return 0;
}

Measured memory_bytes: 3188
import itertools

h, w, k = map(int, input().split())

mat = []

for i in range(h):
    s = list(input())
    mat.append(s)

brack = 0

for i in range(h):
    for j in range(w):
        if mat[i][j] == "#":
            brack += 1

tate = [0] * w
yoko = [0] * h
for i in range(h):
    for j in range(w):
        if mat[i][j] == "#":
            tate[j] += 1
            yoko[i] += 1

tcom = []
ycom = []
for i in range(w):
    l = list(itertools.combinations(range(w), i+1))
    for j in l:
        tcom.append(j)
for i in range(h):
    l = list(itertools.combinations(range(h), i+1))
    for j in l:
        ycom.append(j)

ans = 0

for i in tcom:
    for j in ycom:
        cnt = 0
        for n in i:
            cnt += tate[n]
        for n in j:
            cnt += yoko[n]
        for n in i:
            for m in j:
                if mat[m][n] == "#":
                    cnt -= 1
        if brack - cnt == k:
            ans += 1

for i in tcom:
    tcnt = 0
    for n in i:
        tcnt += tate[n]
    if brack - tcnt == k:
        ans += 1

for i in ycom:
    ycnt = 0
    for n in i:
        ycnt += yoko[n]
    if brack - ycnt == k:
        ans += 1

if k == brack:
    ans += 1

print(ans)

Measured memory_bytes: 68152
n=int(input())
def count(s):
  if int(s) > n:
    return 0
  else:
    flag = 0
    for c in '753':
      if s.count(c):
        flag = 1
      else:
        flag = 0
        break
    if flag: ret = 1
    else: ret = 0
    for c in '753':
      ret += count(s+c)
    return ret

print(count('0'))

Measured memory_bytes: 2940
#include<bits/stdc++.h>
using namespace std;
long gcd(long c,long d){
  if(c%d==0)return d;
  return gcd(d,c%d);
}
int main(){
  long a,b,c,d;cin>>a>>b>>c>>d;
  long e=c*d/gcd(c,d);
  cout<< (b-a+1)-((b/c-(a-1)/c)+(b/d-(a-1)/d)-(b/e-(a-1)/e));
  
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <cmath>
#include <climits>
#include <iomanip>
#include <set>
#include <map>
using namespace std;
typedef long long ll;
int main(){
    ll k;
    cin >> k;
    for(int i = 0;i < k;i++)cout << "ACL";
    cout << endl;   
}

Measured memory_bytes: 3632
while True:
    a, op, b = input().split()
    a = int(a)
    b = int(b)
    if op == '?':
        break
    elif op == '+':
        print(a+b)
    elif op == '-':
        print(a-b)
    elif op == '*':
        print(a*b)
    elif op == '/':
        print(int(a/b))


Measured memory_bytes: 5596
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
#define maxs(x,y) x = max(x, y)
#define mins(x,y) x = min(x, y)
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n;
    cin >> n;
    vector<int> x(n);
    vector<int> y(n);
    REP(i, n) {
        cin >> x[i];
        y[i] = x[i];
    }
    
    sort(ALL(y));
    for(int i = 0; i < n; i++) {
        if (x[i] == y[n/2+1-1]) cout << y[n/2-1] << endl;
        else if (x[i] == y[n/2-1]) cout << y[n/2+1-1] << endl;
        else if (x[i] < y[n/2-1]) cout << y[n/2+1-1] << endl;
        else if (x[i] > y[n/2+1-1]) cout << y[n/2-1] << endl;
    }

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

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

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vector<int> > vvi;
typedef vector<pair<int, int> > vii;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

// ────────────────────────────────────────────────────

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

	vector<int> d(n);
	rep(i, n) {
		cin >> d[i];
		d[i] /= 10;
	}

	int maxD1 = 0, maxD2 = 0;
	int j = 0;
	for (int i = 0; i <= j && j < n; ++i) {
		maxD1 = max(maxD1, d[i] + i);
		j = max(j, i + d[i]);
		if (j > n - 1) j = n - 1;
	}

	j = n - 1;
	for (int i = n - 1; i >= j && j >= 0; --i) {
		maxD2 = max(maxD2, d[i] + abs(n - 1 - i));
		j = min(j, i - d[i]);
		if (j < 1) j = 1;
	}

	if (n - 1 <= maxD1 && n - 1 <= maxD2) cout << "yes" << endl;
	else cout << "no" << endl;
}


Measured memory_bytes: 3824
<?php
$k = (int)trim(fgets(STDIN));
$ary = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51];
echo $ary[$k-1];

Measured memory_bytes: 4728
#include<bits/stdc++.h>
using namespace std;
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
#pragma GCC optimize("Ofast")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
typedef long long int ll;
// #define int long long int
#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define FRE freopen("input.txt","r",stdin); freopen("output.txt","w",stdout);
#define debug(x) cout << #x << " is: " << (x) << endl;
#define debugx(x) cout << #x << " is: " << (x) << endl; exit(0);
#define f(i,n) for(ll i=0;i<n;i++)
#define fa(i,a,n) for(ll i=a;i<n;i++)
#define loop(i,a, n) for(ll i = a; i <= n; i++)
#define loopb(i,a, n) for(ll i = a; i >= n; i--)
#define pb push_back
#define pf push_front
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define setmem(x, k) memset(x, k, sizeof(x))
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define PI 3.1415926535897932384626
#define MOD 1000000007
#define INF 1000111000111000111LL
#define endl "\n"
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef long double ld;
typedef vector<vector<ll>> matrix;
ll dx[] = {0, 1, 0, -1};
ll dy[] = {-1, 0, 1, 0};
const ll N = 5e5+5;
// ll a[N], b[N], dp[N], level[N], vis[N], in[N], out[N];
// vl g[N];
ll n, m;

// sqrt(n)
ll BLOCK = 555;

struct query{
    ll l;
    ll r;
    ll i;
};
query Q[N];
ll ar[N] , ans[N];
ll freq[N];
ll cnt = 0;

bool compare(query a , query b) {
    if(a.l / BLOCK != b.l/BLOCK)
    return a.l/BLOCK < b.l/BLOCK;
 
    return a.r < b.r;
}

void add(ll pos) {
    freq[ar[pos]]++;
    if(freq[ar[pos]] == 1)
    cnt++;
}
 
void remove(ll pos) {
    freq[ar[pos]]--;
    if(freq[ar[pos]] == 0)
    cnt--;
}

 
void solve() {
    ll q;
    cin >> n >> q;
    f(i, n) cin >> ar[i];
    f(i, q){
        cin >> Q[i].l >> Q[i].r;
        Q[i].i = i;
        Q[i].l--, Q[i].r--;
    }
    sort(Q, Q + q, compare);

    ll ML = 0 , MR = -1;
    f(i, q){
        ll L = Q[i].l;
        ll R = Q[i].r;
        
        // Its always suggested to use in this method : R A A R 

        // contraction
        while(ML < L){
            remove(ML) , ML++;
        }
        // expansion
        while(ML > L){
            ML-- , add(ML);
        }
        // expansion
        while(MR < R){
            MR++ , add(MR);
        }
        // contraction
        while(MR > R){
            remove(MR) , MR--;
        }
 
        ans[Q[i].i] = cnt;
    }
 
    f(i, q) cout << ans[i] << endl;
}   
 
int32_t main() {
    IOS
    clock_t begin = clock();
    ll T = 1;
    // cin >> T;
    while(T--)
    solve();
    cerr<<"Time elapsed : "<<(clock()-begin)*1000.0/CLOCKS_PER_SEC<<"ms"<<'\n';
    return 0;
}

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

int main()
{
	int ary[101] ;
	int get ;
	int tmp = 0 ;

	for( int i = 1 ; i < 101 ; i ++ )
	{
		ary[i] = 0 ;
	}

	while( cin >> get )
	{
		ary[get] ++ ;

		if( ary[get] > tmp )
		{
			tmp = ary[get] ;
		}
	}

	for( int i = 1 ; i < 101 ; i ++ )
	{
		if( ary[i] == tmp )
		{
			cout << i << endl ;
		}
	}
	return 0 ;
}

Measured memory_bytes: 1160
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<queue>
#include<algorithm>
#include<vector>
#include<math.h>
#include<bitset>
#include<iomanip>
using namespace std;

typedef stack<int> IntStack;
typedef queue<int> IntQueue;

const double pi = 3.141592653589793;

int char_to_int(char c)
{
	if (c == '0') return 0;
	if (c == '1') return 1;
	if (c == '2') return 2;
	if (c == '3') return 3;
	if (c == '4') return 4;
	if (c == '5') return 5;
	if (c == '6') return 6;
	if (c == '7') return 7;
	if (c == '8') return 8;
	if (c == '9') return 9;
	else return -1;
}

/*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*//*ここまでテンプレ*/

double win[20];

int main()
{	
	double N, K;
	cin >> N >> K;
	double n = N;
	
	int i = 0;
	while (N >= 1)
	{
		while (K <= N)
		{
			win[i]++;
			N--;
		}
		K /= 2;
		i++;
	}

	double ans = 0;
	double d = 1;
	for (int j = 0; j < 20; j++)
	{
		ans += win[j] / d;
		d *= 2;
	}

	cout << fixed << setprecision(12) << ans / n;

	return 0;
}


Measured memory_bytes: 256
# https://atcoder.jp/contests/abc112/tasks/abc112_c

def calc(cx, cy, v)
  v.h + (cx - v.x).abs + (cy - v.y).abs
end

V = Struct.new(:x, :y, :h)

N = gets.to_i
vs = Array.new(N)

N.times do |i|
  vs[i] = V.new(*gets.split.map(&:to_i))
end

0.upto(100) do |cx|
  0.upto(100) do |cy|
    h0 = calc(cx, cy, vs.find { |v| v.h > 0 })
    f = vs.all? do |v|
      h = calc(cx, cy, v)
      (v.h > 0 && h == h0) || (v.h == 0 && h >= h0)
    end
    if f
      puts "#{cx} #{cy} #{h0}"
      exit 0
    end
  end
end


Measured memory_bytes: 1788
from  queue import Queue
r,c  = map(int,input().split() )

INF = 10001000100
dx = [-1 ,1, 0, 0 ]
dy = [0 ,0, -1, 1 ]

meiro = []
for i in range(r):
    meiro.append(list(input()) ) 


def kyori(x, y):
    global r
    global c
    global meiro
    global dx
    global dy
    global INF

    if (meiro[y][x] =="#"):
        return 0

    k = [[INF for j in range (r) ] for i in range(c)]
    #初期化
    q = Queue()
    # 初期位置を保存
    q.put( (x,y) )

    k[x][y] = 0
    
    mk = 0
    while True:
        if q.empty():
            break

        p = q.get()
        for i in range(4):
            nx = dx[i] + p[0]
            ny = dy[i] + p[1]
            # 次に移動できるかどうかの判定
            if (nx < 0 or nx >= c  or
                ny < 0 or ny >= r   ):
                
                continue
            if (k[nx][ny] != INF or 
                meiro[ny][nx] == "#"):
                
                continue
            q.put((nx, ny))
            k[nx][ny] = k[p[0]][p[1]] + 1
            mk = k[nx][ny]
            
            
    return mk

mkList = []
for y in range(r):
    for x in range(c):
        mkList.append(kyori(x, y))
        

print(max(mkList))
        






Measured memory_bytes: 4208
#include <iostream>
#include <iomanip>
#include <iomanip>
#include <sstream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <cstring>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;
#define ALL(a)  (a).begin(),(a).end()
#define REP(i,n) for(int i=0;i<(n);++i)
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x) cerr << "  (L" << __LINE__ << ") " << #x << " = " << (x) << endl;
#define dumpv(x) cerr << "  (L" << __LINE__ << ") " << #x << " = "; REP(q,(x).size()) cerr << (x)[q] << " "; cerr << endl;
template<typename T1, typename T2>
ostream& operator<<(ostream& s, const pair<T1, T2>& d) {return s << "(" << d.first << "," << d.second << ")";}

struct edge {
  int to; double cost;
  edge(int t, double c): to(t), cost(c) {}
};

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

  int N, M; cin >> N >> M;
  vector<int> x(N), y(N);
  REP(i, N) cin >> x[i] >> y[i];

  vector<vector<edge> > G(N);
  
  double totalfence = 0.0;
  REP(i, M) {
    int p, q; cin >> p >> q;
    p--; q--;
    double dist = sqrt((x[p]-x[q]) * (x[p]-x[q]) + (y[p]-y[q]) * (y[p]-y[q]));
    G[p].push_back(edge(q, dist));
    G[q].push_back(edge(p, dist));
    totalfence += dist;
  }

  vector<bool> used(N, false);
  priority_queue<pair<double, int> > que;
  double usedfence = 0.0;

  while (find(used.begin(), used.end(), false) != used.end()) {
    int first_unused = find(used.begin(), used.end(), false) - used.begin();
    que.push(make_pair(0, first_unused));

    while (!que.empty()) {
      pair<double, int> p = que.top(); que.pop();
      if (!used[p.second]) {
        used[p.second] = true;
        usedfence += p.first;
        REP(i, G[p.second].size()) {
          edge& e = G[p.second][i];
          if (!used[e.to]) que.push(make_pair(e.cost, e.to));
        }
      }
    }
  }
  
  cout << setprecision(3) << setiosflags(ios::fixed);
  cout << (totalfence - usedfence) << endl;
}

Measured memory_bytes: 2568
n=int(input())
a=list(map(int,input().split()))
ans=0
for i in range(n):
	mini=i
	for j in range(i,n):
		if a[j]<a[mini]:
			mini=j
	if a[i]>a[mini]:
		ans+=1
	a[i],a[mini]=a[mini],a[i]
print(*a)
print(ans)


Measured memory_bytes: 5604
#include <iostream>
#include <vector>
#include <cstring>
using namespace std;
string str;
vector<string> ans;
bool used[26];

void dfs(int i, string substr){
    if (i == str.size()) {
        ans.push_back(substr);
        return;
    }
    char ch = str[i] + 1;
    int chi = ch - 'a';
    if (str[i] == 'a') {
        dfs(i + 1, substr + str[i]);
    }
    else if (used[str[i] - 'a']) {
        dfs(i + 1, substr + str[i]);
    }
    if (chi < 26 && !used[chi]) {
        used[chi] = true;
        dfs(i + 1, substr + ch);
        used[chi] = false;
    }
}

int main()
{
    while (true) {
        cin >> str;
        if (str == "#") {
            break;
        }
        fill(used, used+26, false);
        ans.clear();
        dfs(0, "");
        cout << ans.size() << endl;
        if (ans.size() <= 10) {
            for (int i = 0; i < ans.size(); i++) {
                cout << ans[i] << endl;
            }
        }
        else {
            for (int i = 0; i < 5; i++) {
                cout << ans[i] << endl;
            }
            for (int i = ans.size() - 5; i < ans.size(); i++) {
                cout << ans[i] << endl;
            }
        }
    }
    
    return 0;
}

Measured memory_bytes: 2380
#include <bits/stdc++.h>
#include <math.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using ll = long long;
using vec = vector<ll>;
using vec2 = vector<vector<ll>>;
ll inf = pow(2,62);

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = max(a*c,a*d);
    ans = max(ans,b*c);
    ans = max(ans,b*d);
    cout << ans << endl;
}

Measured memory_bytes: 3636