akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <math.h>

int max(int *l, int n){
  int i, lmax=l[0];
  for(i=1; i<n; i++){
    if(lmax<l[i]){
      lmax = l[i];
    }
  }
  return lmax;
}

int main(void){
  int n, i;
  scanf("%d", &n);
  int l[n];
  for(i=0; i<n; i++){
    scanf("%d", &l[i]);
  }
  int lmax = max(&l, n);
  int lsum=0;
  for(i=0; i<n; i++){
    lsum += l[i];
  }
  if(lsum-lmax>lmax){
    printf("Yes");
  }else{
    printf("No");
  }
  return 0;
}


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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

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> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};

ll divisor_count(ll n){
    vl a;
    for(ll i=1LL;i*i<=n;i++){
        if(n%i == 0){
            a.push_back(i);
            if(n/i != i)a.push_back(n/i);
        }
    }
    sort(all(a));
    return a.size()-1;
}
ll factor_count(ll n){
    vl a;
    ll res = 0;
    for(ll i=1LL;i*i<=n;i++){
        if (n%i == 0) {
            a.push_back(i);
            if (n/i != i) a.push_back(n/i);
        }
    }

    for(auto b:a){
        if(b==1)continue;
        ll N = n;
        while(N % b == 0) N/=b;
        if(N%b==1)res++;
    }
    return res;
}
signed main()
{   
    gearup;
    ll n; cin >> n;
    ll res = divisor_count(n-1);
    res += factor_count(n);
    out(res);
    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)

using namespace std;
using ll = long long;


int main(){
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    ll cnt = 0;
    rep(i, m) {
        cin >> a[i];
        cnt += a[i];
    }
    if(n < cnt){
        cout << -1 << endl;
        return 0;
    }else{
        ll ans = n - cnt;
        cout << ans << endl;
    }

    return 0;
}



Measured memory_bytes: 3668
N, M = map(int, input().split())
adj = dict((i+1, []) for i in range(N))

for i in range(M):
    a, b = map(int, input().split())
    adj[a].append(b)
    adj[b].append(a)
queue = [(1,)]
ans = 0
while queue:
    q = queue.pop()

    if len(q) == N:
        ans+=1
        continue
    now = q[-1]

    for nextp in adj[now]:
        if not nextp in q:
            queue.append(q+(nextp,))
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+2],i,cnt = 0;
    for(i=0; i<n; i++){
        cin>>a[i];
        if((i+1)%2==1 && a[i]%2==1)cnt++;
    }
    cout<<cnt<<endl;


    return 0;
}



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

int main(){
  long long N, A, B;
  cin>>N>>A>>B;
  if((B-A)%2==0) cout<<(B-A)/2<<endl;
  if((B-A)%2==1){
    if(A-1<=N-B){
      cout<<A+(B-A-1)/2<<endl;
    }
    if(A-1>N-B){
      cout<<N-B+1+(B-A-1)/2<<endl;
    }
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <cstdio>
    #include <cstring>
    #include <cmath>
    #include <cstring>
    #include <chrono>
    #include <complex>
    #define ll long long int
    #define ld long double
    #define vi vector<int>
    #define vll vector<ll>
    #define vvi vector < vi >
    #define pii pair<int,int>
    #define pll pair<long long, long long>
    #define mod 1000000007
    #define inf 1000000000000000001;
    #define all(c) c.begin(),c.end()
    #define mp(x,y) make_pair(x,y)
    #define mem(a,val) memset(a,val,sizeof(a))
    #define eb emplace_back
    #define pb push_back
    #define f first
    #define s second
    
    using namespace std;
    int main()
    {
        std::ios::sync_with_stdio(false);
        int T;
        T=1;
        // cin.ignore(); must be there when using getline(cin, s)
        while(T--)
        {
            int n,i,j;
            cin>>n;
            cout<<(n+1)/2<<endl;
        }
        return 0;
    }


Measured memory_bytes: 256
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        n: u32,
        a: u32,
        b: u32,
    }
    let ans = (1..n + 1)
        .filter(|i| {
            let sum = i.to_string()
                .chars()
                .map(|c| (c as u8 - b'0') as u32)
                .sum::<u32>();
            a <= sum && sum <= b
        })
        .sum::<u32>();
    println!("{}", ans)
}


Measured memory_bytes: 2208
//#define _USE_MATH_DEFINES
//#pragma comment(linker, "/stack:200000000")
//#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <bits/stdc++.h>
using namespace std;
#pragma GCC diagnostic ignored "-Wmissing-declarations"
#define FINAL_OUT(x) {cout << (x) << '\n'; exit(0); }
//inline int safe_mul(const int x, const int y) __attribute__ ((warn_unused_result));


int const mod = 1e9 + 7;

inline int safe_mul(const int x, const int y) {
    return x * 1LL * y % mod;
}

inline void safe_add(int& x, const int y) {
    x += y;
    if (x >= mod)
        x -= mod;
}

int main()
{
//    freopen("in.txt","r", stdin);
//    freopen("out.txt", "w", stdout);
//    cout << fixed << setprecision(20);
    ios_base::sync_with_stdio(false);
    cin.tie(0);

    int n,k;
    cin >> n >> k;
    int sq = 1;
    while (sq * sq <= n)
        ++sq;

    vector<int> pdp(sq, 0);
    vector<int> dp(sq, 1);
    dp[0] = 0;
    pdp[1] = 1;
    for (int step = 2; step <= k; ++step) {
        int allsum = 0;
        for (int x : dp)
            safe_add(allsum, x);
        vector<int> sums(sq + 1, 0);
        for (size_t i = 1; i < sums.size(); ++i) {
            sums[i] = sums[i - 1];
            safe_add(sums[i], pdp[i - 1]);
        }
        vector<int> invsums(sq + 1, 0);
        for (int i = sq-1; i > 0; --i) {
            invsums[i] = invsums[i + 1];
            safe_add(invsums[i], safe_mul(pdp[i], n / i - sq + 1));
        }
        vector<int> ndp(sq, allsum);
        ndp[0] = 0;

        for (int i = 1; i < sq; ++i) {
            int coef = n / i - sq + 1;
            safe_add(ndp[i], safe_mul(coef, sums[i + 1]));
            safe_add(ndp[i], invsums[i + 1]);
        }
        pdp = dp;
        dp = ndp;
    }

    int ans = 0;
    for (int i = 1; i < sq; ++i)
        safe_add(ans, safe_mul(pdp[i], n / i - sq + 1));
    for (int i = 1; i < sq; ++i)
        safe_add(ans, dp[i]);

    cout << ans << endl;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 1000000000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) ((X) = ((X) + (Y) % mod) % mod)


int n;
int a[100000 + 5];

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n;
    rep(i, n) cin >> a[i];
    sort(a, a + n);
    int pre = a[0];
    int ans = 0;
    int cnt = 1;
    rep2(i, 1, n) {
        if (pre == a[i]) {
            cnt++;
            pre = a[i];
        }
        else {
            if (cnt % 2 == 1) ans++;
            cnt = 1;
            pre = a[i];
        }
    }
    if (cnt % 2 == 1) ans++;
    cout << ans << endl;

}



Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
#include <climits>

using namespace std;
int c[1001][1001];

int main() {
	int n;
	cin >> n;
	for (size_t r = 0; r < n; r++)
	{
		string s, t;
		cin >> s >> t;
		int p = s.size();
		int q = t.size();
		for (size_t i = 1; i < p+1; i++)
		{
			for (size_t j = 1; j < q+1; j++)
			{
				if(s[i-1] == t[j-1]) {
					c[i][j] = c[i-1][j-1] + 1;
				} else {
					c[i][j] = max(c[i-1][j], c[i][j-1]);
				}
			}
			
		}
		cout << c[p][q] << endl;
	}
	
}



Measured memory_bytes: 7124
#include<iostream>
using namespace std;
int main(){
	char c[100][100];
	int h,w;
	cin>>h>>w;
	for(int i=0;i<h;i++)
		for(int j=0;j<w;j++)
			cin>>c[i][j];
	for(int i=-1;i<=h;i++){
		cout<<"#";
		for(int j=0;j<w;j++)
			if(i+1&&i-h)cout<<c[i][j];
			else cout<<"#";
		cout<<"#"<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int modP = 1000000007;

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

        int[][] cost = new int[n][n];
        int inf = 1 << 29;
        for(int i = 0; i < n; i++) Arrays.fill(cost[i], inf);
        for(int i = 0; i < n; i++) cost[i][i] = 0;
        for(int i = 0; i < m; i++) {
            a[i] = in.nextInt()-1;
            b[i] = in.nextInt()-1;
            c[i] = in.nextInt();
            cost[a[i]][b[i]] = c[i];
            cost[b[i]][a[i]] = c[i];
        }

        boolean used[] = new boolean[m];
        for(int k = 0; k < n; k++) {
            for(int i = 0; i < n; i++) {
                for(int j = 0; j < n; j++) {
                    if(i == j) continue;
                    cost[i][j] = Math.min(cost[i][k] + cost[k][j], cost[i][j]);
                }
            }
        }

        int ans = 0;
        for(int i = 0; i < m; i++) if(c[i] > cost[a[i]][b[i]]) ans++;

        print(ans);
    }

    static void print(String s) {
        System.out.println(s);
    }

    static void print(int i) {
        System.out.println(i);
    }
}

class E {
    int l, r, w;
    E(int l, int r, int w) {
        this.l = l;
        this.r = r;
        this.w = w;
    }
}


Measured memory_bytes: 27628
n = int(input())
a = list(map(int,input().split()))

count=0
for i in range(n-2):
    for j in range(i+1,n-1):
        for k in range(j+1,n):
            if a[i]+a[j]>a[k] and a[j]+a[k]>a[i] and a[i]+a[k]>a[j]:
                if a[i]!=a[j] and a[i]!=a[k] and a[j]!=a[k]:
                    count+=1

print(count)
    


Measured memory_bytes: 9192
#include <bits/stdc++.h>
#define rep(i,N) for(int i=0; i<N; i+=1)
using namespace std;
 
int main() {
  int N,K;
  cin>>N>>K;
  vector<int>A(N);
  rep(i,N) cin>>A[i];
  sort(A.begin(),A.end());
  reverse(A.begin(),A.end());
  long long S=0;
  for(int i=K; i<N; i+=1) {
    S+=A[i];
  }
  if(N>K)
    cout<<S<<endl;
  else
    cout<<"0"<<endl;
  
 
 
}
 

Measured memory_bytes: 1024
import sys
input = sys.stdin.readline
from heapq import heappush
N, M = map(int, input().split())
H = list(map(int, input().split()))
x = [True] * N
for _ in range(M):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    if H[a] == H[b]:
        x[a] = False
        x[b] = False
    elif H[a] > H[b]:
        x[b] = False
    else:
        x[a] = False
ans = 0
for i in range(N):
    if x[i]:
        ans += 1
print(ans)

Measured memory_bytes: 20408
package main

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

func main() {
	N, P := ReadInt(), ReadInt()
	A := ReadInts(N)
	dp := make([][2]int, N+1)
	dp[0][0] = 1
	for i := 0; i < N; i++ {
		dp[i+1][0] = dp[i][0]
		dp[i+1][1] = dp[i][1]
		if A[i]%2 == 1 {
			dp[i+1][0] += dp[i][1]
			dp[i+1][1] += dp[i][0]
		} else {
			dp[i+1][0] += dp[i][0]
			dp[i+1][1] += dp[i][1]
		}
	}
	fmt.Println(dp[N][P])
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1848
import java.util.*;

public class Main{
  public static void main(String[]args){
    Scanner sc = new Scanner(System.in);
    int N = Integer.parseInt(sc.nextLine());
    String[] S = sc.nextLine().split(" ");
    long[] nums = new long[N];
    long p = 1000000007;
    long ans = 0;
    int s = 0;
    for(int i = 0; i < N; i++){
      nums[i] = Long.parseLong(S[i]);
      String T = Long.toBinaryString(nums[i]);
      s = T.length() > s ? T.length() : s;
    }
    
    long po = 1;
    for(int j = 0; j < s; j++){
      long z = 0, o = 0;
      for(int i = 0; i < N; i++){
        if(nums[i]%2 == 0){
          z++;
        }else{
          o++;
        }
        nums[i] /= 2;
      }
      ans += (((z*o)%p)*po)%p;
      ans %= p;
      po *= 2;
      po %= p;
    }
    System.out.println(ans);
  } 
}


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

using ll = long long int;
ll arr[300][300] = {};

int main(void){
    
    ll n;
    cin >> n;
    
    ll f = 0,ans = 0,total = 0;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            cin >> arr[i][j];
        }
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                
                //if(i == j || j == k || i == k) continue;
                if( arr[j][k] > arr[j][i] + arr[i][k] ){
                    //cout << i << " " << j << " " << k << endl;
                    f = 1;
                }
                
            }
            
            total += arr[i][j];
        }
    }
    
    if(f){
        cout << -1 << endl;
        return 0;
    }
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            for(int k = 0; k < n; k++){
                
                if(i == j || j == k || i == k) continue;
                if( arr[j][k] == arr[j][i] + arr[i][k]){
                    //cout << i << " " << j << " " << k << endl;
                    ans += arr[j][k];
                    arr[k][j] = 1000000001;
                    arr[j][k] = 1000000001;
                }
                
            }
        }
    }
    
    cout << total/2 - ans << endl;
}


Measured memory_bytes: 896
import sys
N = int(input())
v = list(map(int,input().split()))
max_num = max(v)
v.remove(max(v))

if N >2:
	x = min(v)
	v.remove(min(v))
	y = min(v)
	v.remove(min(v))
	value = (x+y)/2
	# print(x,':',y,'→',value)
	while len(v) != 0:
		target = value
		value = (value+min(v))/2
		# print(target,':',min(v),'→',value)
		v.remove(min(v))

	print((value+max_num)/2)
	sys.exit()

else:
	print((max_num+v[0])/2)
	sys.exit()


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;typedef long long ll;
ll INF = 1e18;
int main(){
  ll n, a, sum = 0, ans = 0;
  cin >> n;
  for (ll i = 0; i < n; i++) {
    cin >> a;
    sum += a;
    if (a % 10 != 0 && INF > a) INF = a;
  }
  if (sum % 10 != 0) ans = sum;
  else if (INF != 1e18) ans = sum - INF;
  
  cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
L, R =  map(int, [S[:2], S[2:]])
 
if 1 <= L <= 12 and 1 <= R <= 12:
  print("AMBIGUOUS")
elif 1 <= L <= 12 and (R == 0 or R > 12):
  print("MMYY")
elif (L == 0 or L > 12) and 1 <= R <= 12:
  print("YYMM")
else:
  print("NA")

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

map<int,int> land[200002];

int main(){
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		land[x][y] = 1;
		land[y][x] = 1;		
	}

	for(int i=2;i<=n;i++) {
		if(land[1][i] && land[i][n]){ 
			cout<<"POSSIBLE";
			return 0;
		}
	}

	cout<<"IMPOSSIBLE";
}

Measured memory_bytes: 37760
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if (a+b>c+d){
    cout<<"Left"<<endl;
  }
  if (a+b<c+d){
    cout<<"Right"<<endl;
  }
  if (a+b==c+d) {
    cout<<"Balanced"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		// スペース区切りの整数の入力
		int N = sc.nextInt();
		int M = sc.nextInt();
		
		int ans  = ( N - 1) * ( M - 1 );
		
		System.out.println(ans);
	}
}


Measured memory_bytes: 20948
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<stdlib.h>
int partition(int A[], int p, int r);
int main(){
	int *A, p,r,n,i;
	scanf("%d", &n);
	A = (int *)malloc(sizeof(int)*n);
	r = n-1;
	for (i = 0; i < n; i++) scanf("%d", A + i);
	n=partition(A, 0, r);
	for (i = 0; i < n; i++) printf("%d ", A[i]);
	printf("[%d] ", A[i++]);
	for (; i <= r; i++) printf("%d%c", A[i],i==r?'\n':' ');
	free(A);
	return 0;
}

int partition(int A[], int p, int r){
	int i,x,j,tmp;
	x = A[r];
	i = p-1;
	for (j = p; j <= r; j++) {
		if (A[j] <= x) {
			i++;
			tmp = A[i]; A[i] = A[j]; A[j] = tmp;
		}
	}
	//tmp = A[i]; A[i] = A[r]; A[r] = tmp;
	return i;
}

Measured memory_bytes: 888
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include <time.h>
typedef long long llint;
typedef long double ldouble;
// 小大
int compare(const void *a, const void *b){return *(llint *)a - *(llint *)b;}
typedef struct{
    llint aa;
    llint bb;
}frequent;
// 小大
int cmp( const void *p, const void *q ) {
    return ((frequent*)p)->bb - ((frequent*)q)->bb;
}
/*絶対値*/
llint ABS(llint a){return a>=0?a:(-a);}



int main(void){
    llint n,i;
    scanf("%lld",&n);
    if(n==1){
        scanf("%lld",&i);
        printf("1\n");
        return 0;
    }
    if(n==2){
        llint a1,a2;
        scanf("%lld%lld",&a1,&a2);
        if(ABS(a1-a2)<3){
            printf("2\n");    
        }else{
            printf("1\n");    
        }
        // printf("1\n");
        return 0;
    }
    llint a[n],count[100000],sum[n-2];
    for(i=0;i<100000;i++){
        count[i]=0;
    }
    for(i=0;i<n;i++){
        scanf("%lld",&a[i]);
        count[a[i]]++;
    }
    for(i=0;i<n-2;i++){
        sum[i] = count[i]+count[i+1]+count[i+2];
    }
    qsort(sum,n-2,sizeof(llint),compare);

    printf("%lld\n",sum[n-3]);
    return 0;
}


Measured memory_bytes: 3324
from collections import *
from heapq import *
from itertools import *
from fractions import gcd
import sys
from decimal import *
import copy
from bisect import *
input=lambda :sys.stdin.readline().rstrip()
N,W=map(int,input().split())
WV=[list(map(int,input().split())) for i in range(N)]

lst=deque([])
for w,v in WV:
    nlst=deque([[w,v]])
    for i in range(len(lst)):
        w1,v1=lst[i]
        if w1+w<=W:
            if w1:
                nlst.append([w1+w,v1+v])
    if not lst:
        lst=copy.copy(nlst)
        continue
    Xlst=lst
    lst=deque()

    if Xlst or nlst:
        w1,v1=nlst[0]
        w2,v2=Xlst[0]
        if w1<w2:
            lst.append(nlst.popleft())
        else:
            lst.append(Xlst.popleft())
    while Xlst or nlst:
        w,v=lst[-1]
        if Xlst and nlst:
            w1,v1=nlst[0]
            w2,v2=Xlst[0]

            if w==w1:
                if v>=v1:
                    nlst.popleft()
                else:
                    lst.pop()
                    lst.append(nlst.popleft())
            elif w==w2:
                if v>=v2:
                    Xlst.popleft()
                else:
                    lst.pop()
                    lst.append(Xlst.popleft())
            else:
                if w1<w2:
                    if v>=v1:
                        nlst.popleft()
                    else:
                        lst.append(nlst.popleft())
                else:
                    if v>=v2:
                        Xlst.popleft()
                    else:
                        lst.append(Xlst.popleft())
        elif nlst:
            w1,v1=nlst[0]
            if w==w1:
                if v>=v1:
                    nlst.popleft()
                else:
                    lst.pop()
                    lst.append(nlst.popleft())
            else:
                if v>=v1:
                    nlst.popleft()
                else:
                    lst.append(nlst.popleft())
        elif Xlst:
            nlst=Xlst
            Xlst=deque()



lst.append([0,0])
print(max([v for w,v in lst if w<=W]))


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

int main() {
  int N;
  string c;
  set <string> s;

  cin >> N;

  for(int i=0; i<N; i++){
    cin >> c;
    s.insert(c);
  }

  cout << s.size() << endl;
    return 0;
    }

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

signed main()
{
	string str;
	cin >> str;
	istringstream iss(str);
	if (str.size() == 1) {
		cout << str[0] << endl;
		return 0;
	}
	if (str[0] == '1') {
		bool flag = 1;
		for (int i = 1; i < (int)str.size(); ++i) {
			if (str[i] != '0')
				flag = false;
		}
		if (flag) {
			cout << 10 << endl;
			return 0;
		}
	}
	int sum = 0;
	for (int i = 0; i < (int)str.size(); ++i) {
		sum += str[i]-'0';
	}
	
	cout << sum << endl;
}


Measured memory_bytes: 256
[<EntryPoint>]
let main argv =
    let xab = stdin.ReadLine().Split() |> Array.map int
    let x = xab.[0]
    let over = xab.[2] - xab.[1]
    if over <= 0 then "delicious" else if over <= x then "safe" else "dangerous"
    |> stdout.WriteLine
    0

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

#define int long long int
#define ff first
#define ss second
#define pb push_back


int bexp(int a, int b, int mod)
{
    int res = 1;

    while (b)
    {
        if (b & 1) res = (res * a) % mod;

        a = (a * a) % mod; 
        b >>= 1;
    }
    return res;
}

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

#define N 100010
#define MOD 1000000007

struct comp {
    bool operator() (const pair<int, int> a, const pair<int, int> b) const
    {
        return a.ss > b.ss;
    }
};

int32_t main()
{
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    cout.precision(10);

   
    int n, k;
    cin >> n >> k;

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

    for (int i = 1; i < n; ++i)
    {
        dp[i] = INT_MAX;

        for (int j = 1; j <= k; ++j)
            if (i - j >= 0)
                dp[i] = min(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
            else
                break;
    }

    cout << dp[n - 1];
    return 0;
}

Measured memory_bytes: 5140
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define usecppio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(x) ((x).begin()),((x).end())
#define int ll
using pii = pair <int, int>;
#define INF 0x7f7f7f7f7f7f7f7f
const bool debug = 0;
const int mod = 998244353;

int k, n;
vector <int> v;
int ans = 0;
int32_t main()
{
    usecppio
    cin >> k >> n;
    for (int i = 0; i<n; i++)
    {
        int x; cin >> x; v.push_back(x);
    }
    v.push_back(v[0]+k);
    for (int i = 1; i<=n; i++)
        ans = max(ans, v[i]-v[i-1]);
    cout << k-ans << '\n';
}

Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().Solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";


    void Solve()
    {
        var T = cin.Scanlong;
        var K = (T[2] * (T[0] - 1) + T[1]) - (T[1] * (T[0] - 1) + T[2]) + 1;
        if (K > 0)
        {
            WriteLine(K);
        }
        else
        {
            WriteLine(0);
        }

    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] Scan { get { return ReadLine().Split(); } }
    public int[] Scanint { get { return Array.ConvertAll(Scan, int.Parse); } }
    public long[] Scanlong { get { return Array.ConvertAll(Scan, long.Parse); } }
    public double[] Scandouble { get { return Array.ConvertAll(Scan, double.Parse); } }
    public string Next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return Next;
        }
    }
    public int Nextint { get { return int.Parse(Next); } }
    public long Nextlong { get { return long.Parse(Next); } }
    public double Nextdouble { get { return double.Parse(Next); } }
}

Measured memory_bytes: 11216
from collections import deque

H, W = map(int, input().split())
grid = [list(input()) for _ in range(H)]

INF = float('inf')
path = [[INF] * W for _ in range(H)]
q = deque()

q.append((0, 0, 1))
path[0][0] = 1
isGoal = False
while q:
    x, y, s = q.popleft()
    for dx, dy in [(1, 0), (-1, 0), (0, 1), (0, -1)]:
        nx = x + dx
        ny = y + dy
        if (nx, ny) == (H - 1, W - 1):
            path[nx][ny] = s + 1
            isGoal = True
            break
        if 0 <= nx < H and 0 <= ny < W and grid[nx][ny] == '.' and path[nx][ny] > s + 1:
            q.append((nx, ny, s + 1))
            path[nx][ny] = s + 1
    else:
        continue
    break

cnt = 0
for i in range(H):
    for j in range(W):
        if grid[i][j] == '.':
            cnt += 1

if isGoal:
    print(cnt - path[H - 1][W - 1])
else:
    print(-1)


Measured memory_bytes: 40688
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int x = Integer.parseInt(sc.next());
		int a = Integer.parseInt(sc.next());
		int b = Integer.parseInt(sc.next());
		if (Math.abs(a - x) > Math.abs(b - x)) {
			System.out.println("B");
		} else {
			System.out.println("A");
		}
	}

}

Measured memory_bytes: 23764
def is_even(list):
    ans = True
    for i in list:
        if i % 2 != 0:
            ans = False
            break
    return ans            

def devide(list):
    ans = 0
    if is_even(list):
        next_list = [i/2 for i in list]
        ans = devide(next_list)
        ans = ans + 1
    return ans


N = int(input())
list = [int(s) for s in input().split()]

answer = devide(list)

print(answer)

Measured memory_bytes: 3188
fun intList() = readLine()?.split(" ")?.map(String::toInt) ?: TODO()
fun main() {
    val (h, w, a, b) = intList()

    buildString {
        repeat(h) { i ->
            repeat(w) { j ->
                if (i < b) {
                    if (j < a) {
                        append("0")
                    } else {
                        append("1")
                    }
                } else {
                    if (j < a) {
                        append("1")
                    } else {
                        append("0")
                    }
                }
            }
            appendln()
        }
    }.let {
        println(it.trimIndent())
    }
}

Measured memory_bytes: 60144
ans = []
while True:
    m, f, r = map(int, input().split())
    if m==-1 and f==-1 and r==-1:
        break
    if m==-1 or f==-1:
        ans.append("F")
    elif 80 <= (m+f):
        ans.append("A")
    elif 65 <= (m+f) < 80:
        ans.append("B")
    elif 50 <= (m+f) < 65:
        ans.append("C")
    elif 30 <= (m+f) < 50:
        if 50 <= r:
            ans.append("C")
        else:
            ans.append("D")
    else:
        ans.append("F")
[print(x) for x in ans]



Measured memory_bytes: 5604
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int MAXN=2e5+10,MAXM=2e6+10;
const int INF=INT_MAX,MOD=1e9+7;
const ll llINF=~(1ll<<63);


int main()
{
    int a,b,c,d;
    cin>>a>>b>>c>>d;
    if(d==1)
        cout<<1;
    else cout<<0;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef unsigned int uint;
typedef unsigned char uchar;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;

#define REP(i,x) for(int i=0;i<(int)(x);i++)
#define REPS(i,x) for(int i=1;i<=(int)(x);i++)
#define RREP(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define RREPS(i,x) for(int i=((int)(x));i>0;i--)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();i++)
#define RFOR(i,c) for(__typeof((c).rbegin())i=(c).rbegin();i!=(c).rend();i++)
#define ALL(container) (container).begin(), (container).end()
#define RALL(container) (container).rbegin(), (container).rend()
#define SZ(container) ((int)container.size())
#define mp(a,b) make_pair(a, b)
#define pb push_back
#define eb emplace_back
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
template<class T> ostream& operator<<(ostream &os, const vector<T> &t) {
os<<"["; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"]"; return os;
}
template<class T> ostream& operator<<(ostream &os, const set<T> &t) {
os<<"{"; FOR(it,t) {if(it!=t.begin()) os<<","; os<<*it;} os<<"}"; return os;
}
template<class S, class T> ostream& operator<<(ostream &os, const pair<S,T> &t) { return os<<"("<<t.first<<","<<t.second<<")";}
template<class S, class T> pair<S,T> operator+(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first+t.first, s.second+t.second);}
template<class S, class T> pair<S,T> operator-(const pair<S,T> &s, const pair<S,T> &t){ return pair<S,T>(s.first-t.first, s.second-t.second);}

const int INF = 1<<28;
const double EPS = 1e-8;
const int MOD = 1000000007;


int T, n, m;

int main(int argc, char *argv[]){
	ios::sync_with_stdio(false);
	cin >> n;
	vi l(n + 2, MOD), r(n + 2, MOD);
	REPS(i, n) cin >> l[i];
	REPS(i, n) cin >> r[i];
	ll ans = 1;
	REPS(i, n){
		if(l[i] != l[i-1]){
			if(r[i] < l[i]) ans = 0;
		}
		if(r[i] != r[i+1]){
			if(l[i] < r[i]) ans = 0;
		}
		
		if(l[i] == l[i-1] && r[i] == r[i+1]){
			ans = ans * min(l[i], r[i]) % MOD;
		}
		
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 1024
n=int(input())
a=list(map(int,input().split()))

i=0
j=0
s=[]
c=0
while i!=n:
    x=a[i]

    while j!=2:
        if x%2==0 and 2<=x:

            c+=1
            x=x/2
            j+=1
        else:
            break

    s.append(c)
    c=0
    j=0
    i+=1
if s.count(2)>s.count(0):
    print("Yes")
elif (s.count(0)-s.count(2))>1:
    print("No")
elif s.count(0)==s.count(2):
    print("Yes")
elif s.count(0)+s.count(2)==len(s):
    print("Yes")
else:
    print("No")


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

int main() {
  int N, K, S = 1;
  cin >> N >> K ;
  for (int i = 0; i < N; i++) {
    if (S < K) {
      S *= 2;
    } else {
      S += K;
    }
  }
  cout << S << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(ll i=a;i<b;i++)
#define loope(i,a,b) for(ll i=a;i<=b;i++)
#define test() ull t;cin>>t;while(t--)
#define puu pair<ull,ull>
#define f first
#define s second
#define pb push_back
#define mkp make_pair
#define ins insert
#define Vint vector<int>
#define Vull vector<ull>
#define nl cout<<endl
#define sp cout<<" "
#define MOD 1000000007
#define all(x) x.begin(),x.end()
vector<int> cache(100005);
int fact(int k)
{
	if(k<2)
		return 1;
	if(cache[k]!=0)
		return cache[k];
	return cache[k] = k*fact(k-1) % MOD;
}
int main() 
{
	 // #ifndef ONLINE_JUDGE
  //       freopen("input.txt", "r", stdin);
  //       freopen("output.txt", "w", stdout);
  //   #endif
  //   fastio();
    ll x,d,r;
    cin>>r>>d>>x;
    for(int i=1;i<11;i++)
    {
    	x = r*x-d;
    	cout<<x<<endl;
    }
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n,y;
    cin>>n>>y;
    y/=1000;
    rep(i,n+1){
        for(int j=0;j+i<=n;++j){
            if(10*i+j*5+n-i-j==y){
                cout<<i<<" "<<j<<" "<<n-i-j<<endl;
                return 0;
            }
        }
    }
    cout<<-1<<" "<<-1<<" "<<-1<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <cassert>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
typedef long long ll;

struct P {
  ll x, y;
};
P ps[1000+10];
int n;
char buf[50];

const int K = 40;

void go(const vector<ll> &ds, int ith) {
  ll gX = ps[ith].x + ps[ith].y;
  ll gY = ps[ith].x - ps[ith].y;
  REP(i, ds.size()) {
    int bx, by;
    if(gX > 0) {
      gX -= ds[i];
      bx = 1;
    } else {
      gX += ds[i];
      bx = -1;
    }
    if(gY > 0) {
      gY -= ds[i];
      by = 1;
    } else {
      gY += ds[i];
      by = -1;
    }
    if(bx > 0 && by > 0) {
      buf[i] = 'R';
    } else if(bx > 0 && by < 0) {
      buf[i] = 'U';
    } else if(bx < 0 && by > 0) {
      buf[i] = 'D';
    } else {
      buf[i] = 'L';
    }
  }
  assert(gX == 0);
  assert(gY == 0);
}

void solve(void) {
  int parity = (ps[0].x + ps[0].y) & 1;
  REP(i, n) {
    if(((ps[i].x + ps[i].y) & 1) != parity) {
      puts("-1");
      return;
    }
  }
  vector<ll> ds;
  ds.push_back(1);
  REP(i, K-2) {
    ds.push_back(1LL << (i+1LL));
  }
  if(parity == 0) {
    ds.push_back(1);
  }
  sort(ds.begin(), ds.end());
  reverse(ds.begin(), ds.end());
  printf("%d\n", (int)ds.size());
  REP(i, ds.size()) {
    printf("%lld%c", ds[i], i == (int)ds.size()-1 ? '\n' : ' ');
  }
  REP(i, n) {
    go(ds, i);
    puts(buf);
  }
};

int main(void) {
  scanf("%d", &n);
  REP(i, n) {
    scanf("%lld %lld", &ps[i].x, &ps[i].y);
  }
  solve();
  
  return 0;
}


Measured memory_bytes: 256
#include <cstring>
#include <sstream>
#include <cstdio>
#include <algorithm>
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <cmath>
#include <queue>
#include <set>
#include <stack>

using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = n - 1; i >= 0; i--)
#define repone(i, n) for(ll i = 1; i <= (ll)(n); i++)
#define each(i, mp) for(auto i:mp)
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll half_inf = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);
typedef unordered_map<ll, ll> ump;
typedef pair<ll, ll> P;

ump mp;

void solve() {
}

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

// 素因数分解
map<ll, ll> prime_factor(ll n) {
    map<ll, ll> mp;
    for (ll i = 2; i * i <= n; ++i) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }
    if (n != 1) mp[n]++;
    return mp;
}

// 素数判定
bool is_prime(ll n) {
    for (int i = 2; i * i <= n; i++) if (n % i == 0) return false;
    return n != 1;
}

// 約数列挙
vector<ll> divisor(ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; ++i) {
        if (n % i == 0) {
            res.emplace_back(i);
            if (i != n / i) res.emplace_back(n / i);
        }
    }
    return res;
}


int main() {
#ifdef MY_DEBUG
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wmissing-noreturn"
    while (true) {
        mp = ump();
#pragma clang diagnostic pop
#endif
        ll n, k;
        cin >> n >> k;
        vector<ll> a(n);
        rep(i, n) {
            cin >> a[i];
            if (k == a[i]) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
        if (k > *max_element(a.begin(), a.end())) {
            cout << "IMPOSSIBLE" << endl;
            return 0;
        }
        ll now = a[0];
        repone(i, n - 1) {
            now = gcd(now, a[i]);
            if (k % now == 0) {
                cout << "POSSIBLE" << endl;
                return 0;
            }
        }
        cout << "IMPOSSIBLE" << endl;

        solve();

#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

const ll INF = 1LL << 60;


int main() {
    long long K;
    scanf("%lld",&K);
    std::string S;
    std::cin >> S;

    if (S.size() <= K) {
        cout << S << endl;
    } else {
        cout << S.substr(0, K) << "..." << endl;
    }
}


Measured memory_bytes: 3696
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define pf push_front
#define fr first
#define sc second
#define r_0 return 0
#define ld long double

using namespace std;

    const ll N = 1e2 + 7;
    const ll mod = 1e9 + 7;
    const ld eps = 1e-9;



void solve(){
    int l , r;
    cin >> l >> r;
    int d ,cnt = 0;
    cin >> d;
    for(int i = l; i <= r; ++ i){
        if(i % d == 0)
            ++ cnt;
    }
    cout << cnt;
}

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int tt = 1;
    //cin >> tt;
    while(tt --){
            solve();
    }
}

/**

**/


Measured memory_bytes: 3648
#include <iostream>
#include <string>
#include <iterator>
#include <vector>
#include <unordered_map>
#include <algorithm>

struct pair_hash {
	template <class T1, class T2>
	std::size_t operator() (const std::pair<T1, T2> &pair) const {
		return std::hash<T1>()(pair.first) ^ std::hash<T2>()(pair.second);
	}
};

int main()
{
  int N;
  std::cin >> N;
  int m[N];
  int res = 0;
  int max_ = 0;
  for (int i=0; i<N; i++) {
    std::cin >> m[i];
    if (max_ <= m[i]) {
      res++;
      max_ = m[i];
    }
  }

  std::cout << res;

  return 0;
}


Measured memory_bytes: 256
/**
 *    author:  FromDihPout
 *    created: 2020-07-26
**/

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    
    vector<bool> win(k+1);
    for (int i = 1; i <= k; i++) {
        for (int j = 0; j < n; j++) {
            if (i - a[j] >= 0 && !win[i - a[j]]) {
                win[i] = true;
                break;
            }
        }
    }
    if (win[k]) {
        cout << "First" << '\n';
    }
    else {
        cout << "Second" << '\n';
    }
    return 0;
}

Measured memory_bytes: 3688
/*
 	author:: tamajit banerjee
*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
# define pll pair<ll,ll>
ll c[500001];
ll n,q,cnt;
int vis[500001];
ll l,r;
int B=720;
pair<int ,pair<int,int> > query[500001];
int ans[500001];

void fastscan(ll &number) 
{ 
    //variable to indicate sign of input number 
    bool negative = false; 
    register int c; 
  
    number = 0; 
  
    // extract current character from buffer 
    c = getchar(); 
      
    // Keep on extracting characters if they are integers 
    // i.e ASCII Value lies from '0'(48) to '9' (57) 
    for (; (c>47 && c<58); c=getchar()) 
        number = number *10 + c - 48; 
  
    // if scanned input has a negative sign, negate the 
    // value of the input number 
    if (negative) 
        number *= -1; 
} 

bool cmp(pair<int ,pair<int,int> > a, pair<int ,pair<int,int> > b){
	if(a.first/B==b.first/B){
	return a.second.first<b.second.first;
	}
	return a.first<b.first;
}

void add(int x){
	if(vis[x]==0){
		++cnt;
	}
	++vis[x];
}

void subtract(int x){
	if(vis[x]==1){
		--cnt;
	}
	--vis[x];
}
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    fastscan(n);
    fastscan(q);
  	for(int i=0;i<n;i++){
  		fastscan(c[i]);
  		--c[i];
  		vis[i]=0;
	}
	for(int i=0;i<q;i++){
		fastscan(l);
		fastscan(r);
		--l,--r;
		query[i]={l,{r,i}};
	}
	 sort(query,query+q,cmp) ;
	 l=0,r=-1;
	 cnt=0;
	 for(int i=0;i<q;i++){
	 	while(r<query[i].second.first){
		    r++;
			add(c[r]);
		 }
		 while(r>query[i].second.first){
		 	subtract(c[r]);
		 	r--;
		 }
		 while(l<query[i].first){
	 		subtract(c[l]);
	 		l++;
		 }
		 while(l>query[i].first){
		 	l--;
		 	add(c[l]);
		 }
		 ans[query[i].second.second]=cnt;
	 }
	 for(int i=0;i<q;i++){
	 	cout<<ans[i]<<'\n';
	 }
	return 0;
}
    

Measured memory_bytes: 17436
#include<bits/stdc++.h>
#define vi vector<int>
#define vvi vector<vector<int> >
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
using ll = long long;
using ld =long double;
//#define int ll
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
#define int ll
typedef pair<int, int> pii;
typedef pair<int,pii> piii;
bool IsBipartite=true;
vector<vector<int>>edge;
vector<int>var(100000+100,INF);
int zero,one;
void dfs(int vertex){
    rep(i,edge[vertex].size()){
        int next=edge[vertex][i];
        if(var[vertex]==var[next]){IsBipartite=false;return;}
        if(var[next]==INF){
            var[next]=1-var[vertex];
            if(var[next])one++;
            else zero++;
            dfs(next);
        }
    }
}
signed  main(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>>hoge(n);
    rep(i,m){
        int to,from;
        cin>>to>>from;
        --to,--from;
        hoge[to].push_back(from);
        hoge[from].push_back(to);
    }
    edge=hoge;
    var[0]=0;
    zero++;
    dfs(0);
    if(!IsBipartite){cout<<n*(n-1)/2-m<<endl;return 0;}
    else{
        cout<<one*zero-m<<endl;
    }
    
}


Measured memory_bytes: 13056
using System;
using System.Collections.Generic;

namespace abc142_c
{
  class Program
  {
    static void Main(string[] args)
    {
      var n = CIn.ReadInt();
      var a = new int[n];

      for (var i = 1; i <= n; i++)
      {
        a[CIn.ReadInt() - 1] = i;
      }

      Console.WriteLine(string.Join(" ", a));
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

Measured memory_bytes: 29916
#include<iostream>
#include<vector>
#include<algorithm>
#include<cmath>
#include<string>
#include<set>
#include<climits>
#include<map>
#define ll long long
using namespace std;

int main() {
	string a, b; 
	cin >> a >> b;
	if (a.size() > b.size()) {
		cout << "GREATER" << endl;
	}
	else if (a.size() < b.size()) {
		cout << "LESS" << endl;
	}
	else {
		for (ll i = 0; i < a.size();i++) {
			if (a[i] > b[i]) {
				cout << "GREATER" << endl;
				exit(0);
			}
			else if (a[i] < b[i]) {
				cout << "LESS" << endl;
				exit(0);
			}

		}
		cout << "EQUAL" << endl;
	}

}





Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>
using namespace std;
typedef vector<int64_t> vi;
typedef pair< int64_t,int64_t> ii;
typedef vector<pair<int64_t, int64_t> > vp;
typedef vector<pair<int64_t, ii> > vpp;
#define mp make_pair
#define f first
#define s second
#define pb push_back
#define INF 1e9
#define SIZE 200001
#define mod 1000000007
#define int int64_t
#define sz(x)       (int)x.size()
void solve();
int32_t main()
{
    ios::sync_with_stdio(0);
    cin.tie(NULL);
    solve();
    return 0;
}
void solve()
{
    int n;
    cin>>n;
    vp ar;
    int max1=0,max2=0;
    int index=0;
    for(int i=0;i<n;i++)
    {
        int x;
        cin>>x;
        if(x>max1)
        {
            max2=max1;
            max1=x;
            index=i;
        }
        else if(x>max2)
        {
            max2=x;
        }
    }
    for(int i=0;i<n;i++)
    {
        if(i==index)
        {
            cout<<max2<<"\n";
        }
        else
            cout<<max1<<"\n";
    }
}


Measured memory_bytes: 1664