akhauriyash/Code-Regression huggingface dataset:
def get_next_int():
    return int(input().rstrip("\n"))


def get_next_ints(delim=" "):
    return tuple([int(x) for x in input().rstrip("\n").split(delim)])


def main():
    n = get_next_int()

    a = get_next_ints()
    b = get_next_ints()

    a_offsets = []
    b_offsets = []
    for i in range(n):
        a_offsets.append(str(a[i] ^ a[i - 1]))
        b_offsets.append(str(b[i] ^ b[i - 1]))
    #print(a_offsets)
    #print(b_offsets)
    a_text = " ".join(a_offsets)
    b_text = " ".join(b_offsets)
    target_text = a_text + " " + a_text
    start_pos = 0
    if target_text.find(b_text, start_pos) >= 0:
        fisrt_pos = target_text.find(b_text, start_pos)
        fisrt_pos_diff = target_text[:fisrt_pos].count(" ")
        fisrt_xor_diff = b[0] ^ a[fisrt_pos_diff]
        print(fisrt_pos_diff, fisrt_xor_diff)
        if target_text.find(b_text, fisrt_pos+1) >= 0:
            second_pos = target_text.find(b_text, fisrt_pos+1)
            second_pos_diff = target_text[:second_pos].count(" ")
            if second_pos_diff < len(a):
                second_xor_diff = b[0] ^ a[second_pos_diff]
                print(second_pos_diff, second_xor_diff)
                interval = (second_pos_diff - fisrt_pos_diff)
                remain = (n - second_pos_diff - 1) // (second_pos_diff - fisrt_pos_diff)
                for i in range(remain):
                    print(second_pos_diff + interval * (i + 1), [fisrt_xor_diff,second_xor_diff ][i % 2])

if __name__ == '__main__':
    main()


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

a = input()
b = input()
c = input()
sa = [a[i] for i in range(len(a))]
sb = [b[i] for i in range(len(b))]
sc = [c[i] for i in range(len(c))]
turn = sa[0]
while True:
    if turn == 'a':
        if len(sa) == 0:
            print("A")
            break
        turn = sa[0]
        sa.pop(0)
    if turn == 'b':
        if len(sb) == 0:
            print("B")
            break
        turn = sb[0]
        sb.pop(0)
    if turn == 'c':
        if len(sc) == 0:
            print("C")
            break
        turn = sc[0]
        sc.pop(0)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <cstring>
using namespace std;
const int mod=998244353;
long long dp[5003][5003];
long long lgput (long long val)
{
    long long exp=mod-2;
    long long rez=1;
    while(exp)
    {
        if(exp&1)
        {
            rez=(rez*1LL*val)%mod;
            exp^=1;
        }
        else
        {
            val=(val*1LL*val)%mod;
            exp>>=1;
        }
    }
    return rez;
}
long long cmmdc (long long a, long long b)
{
    long long r;
    while(b)
    {
        r=a%b;
        a=b;
        b=r;
    }
    return a;
}
int v[200005];
int main()
{
    long long n,m,k,i,j,s=0,rz=0,a,b;
    cin>>n;
    s=1;
    for(i=1;i<=n;++i)
    {
        cin>>a;
        if(a==s)
        {
            ++s;
        }
    }
    if(n-s+1!=n)
    cout<<n-s+1;
    else
    cout<<-1;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef tuple<int, int, int> ti;
#define rep(i, n) for(ll i = 0;i < n;i++)
#define all(i) i.begin(), i.end()
template<class T, class U> void cmax(T& a, U b) { if (a<b) a = b; }
template<class T, class U> void cmin(T& a, U b) { if (a>b) a = b; }
int x8[8] = {1, -1, 0, 0, 1, 1, -1, -1};
int y8[8] = {0, 0, 1, -1, 1, -1, 1, -1};

int h, w;
vector<string> field(1010);
vector<vector<int>> mindis(1010, vector<int>(1010, -1));

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

  cin >> h >> w;
  rep(i, h) {
    cin >> field[i];
  }

  queue<ti> que;
  rep(i, h) rep(j, w) {
    if (field[i][j] == '#') {
      mindis[i][j] = 0;
      que.push(ti(0, i, j));
    }
  }

  while(que.size()) {
    ti p = que.front(); que.pop();

    rep(i, 4) {
      int ny = get<1>(p) + y8[i], nx = get<2>(p) + x8[i];
      int cnt = get<0>(p);

      if (0 <= nx && nx < w && 0 <= ny && ny < h) {
        if (mindis[ny][nx] == -1) {
          mindis[ny][nx] = cnt+1;
          que.push(ti(cnt+1, ny, nx));
        }
      }
    }
  }

  ll ans = 0;
  rep(i, h) {
    rep(j, w) {
//      cerr << mindis[i][j] << " ";
      cmax(ans, mindis[i][j]);
    }
 //   cerr << endl;
  }
  cout << ans << endl;
}


Measured memory_bytes: 17424
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std ;
using vi = vector<int> ;
int main(){
    int n ; cin >> n ;
    vi a(n) ;
    for(int i=0;i<n;i++) cin >> a.at(i) ;
    vi b = a ;
    sort(b.begin(),b.end()) ;
    int l = b.at(n/2-1) ;
    int r = b.at(n/2) ;
    for(int i=0;i<n;i++){
        if(a.at(i)<r) cout << r << endl ;
        else cout << l << endl ;
    }
}


Measured memory_bytes: 3712
N = int(input())
div = [2]*(N+1)
div[0] = 0
div[1] = 1
for i in range(2,N//2+2):
    for j in range(i+i,N+1,i):
        div[j] += 1
ans = 0
for i in range(1,N+1):
    ans += div[i]*i
print(ans)

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) unique(v.begin(), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
#define all(v) (v).begin(), (v).end()
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1ll << 60;

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<int MOD> struct ModInt {
    static const int Mod = MOD; unsigned x; ModInt() : x(0) { }
    ModInt(signed sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    ModInt(signed long long sig) { x = sig < 0 ? sig % MOD + MOD : sig % MOD; }
    int get() const { return (int)x; }
    ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
    ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }
    ModInt &operator/=(ModInt that) { return *this *= that.inverse(); }
    ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
    ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
    ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
    ModInt operator/(ModInt that) const { return ModInt(*this) /= that; }
    ModInt inverse() const { long long a = x, b = MOD, u = 1, v = 0;
        while (b) { long long t = a / b; a -= t * b; std::swap(a, b); u -= t * v; std::swap(u, v); }
        return ModInt(u); }
    bool operator==(ModInt that) const { return x == that.x; }
    bool operator!=(ModInt that) const { return x != that.x; }
    ModInt operator-() const { ModInt t; t.x = x == 0 ? 0 : Mod - x; return t; }
};
template<int MOD> ostream& operator<<(ostream& st, const ModInt<MOD> a) { st << a.get(); return st; };
template<int MOD> ModInt<MOD> operator^(ModInt<MOD> a, unsigned long long k) {
    ModInt<MOD> r = 1; while (k) { if (k & 1) r *= a; a *= a; k >>= 1; } return r; }
typedef ModInt<1000000007> mint;

string K;
int D;
mint dp[100010][2][110];

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

    cin >> K >> D;

    dp[0][0][0] = 1;
    rep(i, 0, K.length()) rep(j, 0, 2) rep(k, 0, D) {
        int lim = j ? 9 : K[i] - '0';
        rep(d, 0, lim + 1) {
            dp[i + 1][j || d < lim][(k + d) % D] += dp[i][j][k];
        }
    }

    mint rsl = 0;
    rep(j, 0, 2) {
        rsl += dp[K.length()][j][0];
    }
    cout << rsl - 1 << endl;

}


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

int main() {
    long long H;
    cin >> H;
    int count = 0;

    while (true) {
        H = (long long)(H / 2);
        count++;
        if (H == 0)break;
    }
    //cout << count << endl;
    long long ans = 2;
    for (int i = 0; i < count - 1; i++) {
        ans *= 2;
    }

    cout << ans - 1;
}

Measured memory_bytes: 256
n = gets.to_i
a = [0] + gets.split.map(&:to_i) + [0]
aa = a.each_cons(2).map{|a,b|(b-a).abs}
left = [0]
aa.inject(0){|m,i|left << m+i; m+i}
right = []
aa.reverse.inject(0){|m,i|right << m+i; m+i}
right.reverse!; right << 0
1.upto(n) do |i|
  p left[i-1] + right[i+1] + (a[i-1] - a[i+1]).abs
end


Measured memory_bytes: 19436
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int a[] = new int[N];
		for (int i=0; i<N; i++) {
			a[i] = sc.nextInt(); 
		}
		int max = 0; int min = 1000;
		for (int i=0; i<N; i++) {
			if (max < a[i]) max = a[i];
			if (min > a[i]) min = a[i];
		}
		System.out.println(max-min);
	}
}


Measured memory_bytes: 21588
from collections import deque
n = int(input())
i = 2
a = []
x = n
while(i * i <= n):
    if (n % i == 0):
        a.append(i)
        n //= i
        while(n % i == 0):
            n //= i
            a.append(a[-1] * i)
    i += 1
if (n != 1):
    a.append(n)
a.sort(reverse = True)
ans = 0
while(x != 1 and len(a)):
    while(x % a[-1]):
        a.pop()
        if (len(a) == 0):
            break
    if (len(a) == 0):
        break
    x //= a[-1]
    a.pop()
    ans += 1
print(ans)
    


Measured memory_bytes: 9496
#include <bits/stdc++.h>
using i64 = long long;

template <class T>
T pow(T x, T n, T mod) {
    T ret = 1;
    while(n > 0) {
        if ((n & 1) == 1) ret = (ret * x) % mod;
        x = (x * x) % mod;
        n >>= 1;
    }
    return ret;
}

template <class T>
T inverse(T x, T p) { return pow(x, p - 2, p); }

int main() {
    int n, a, b;
    std::cin >> n >> a >> b;
    std::vector<i64> v(n);
    std::unordered_map<i64, int> cnt;
    for (int i = 0; i < n; i++) {
        std::cin >> v[i];
        cnt[v[i]]++;
    }
    std::sort(v.begin(), v.end(), std::greater<>());

    std::vector<i64> w(n + 1), ss(n + 1);
    i64 mm = 0;
    for (int i = a; i <= b; i++) {
        i64 tmp = 0, tc = 0;
        for (int j = 0; j < i; j++) {
            tmp += v[j];
            if (j && v[j] != v[j - 1]) tc = 1;
            else tc++;
        }
        w[i] = tmp;
        ss[i] = 1;
        for (i64 j = 1; j <= tc; j++) {
            ss[i] = ss[i] * (cnt[v[i - 1]] - j + 1) / j;
        }
        if (!mm || (double)1.0 * tmp / i > (double)1.0 * w[mm] / mm) mm = i;
    }

    printf("%.10lf\n", (double)w[mm] / mm);
    i64 ret = 0;
    for (int i = a; i <= b; i++) {
        if (w[mm] * i == w[i] * mm) ret += ss[i];
    }
    std::cout << ret << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct record {
	int s, t, c;
	bool operator<(const record& right)const {
		if (s != right.s) {
			return s < right.s;
		}
		else {
			return t < right.t;
		}
	}
};

int n, C, info[30][2];
vector<record> r;

int main() {
	cin >> n >> C;
	for (int i = 0; i < n; i++) {
		int s, t, c;
		cin >> s >> t >> c;
		r.push_back(record{ s, t, c });
	}

	sort(r.begin(), r.end());

	bool flag = true;
	int i;
	for (i = 0; i < C; i++) {
		//cout << (i+1) << "個の機器を使用する" << endl;
		for (int j = 0; j < n; j++) {
			//cout << " j:" << j << endl;
			for (int k = 0; k <= i; k++) {//k機目を使用する
				//cout << "  k:" << k << endl;
				record re = r.at(j);
				if (info[k][0] <= re.s - 0.5 || (info[k][0] <= re.s && (info[k][1] == 0 || info[k][1] == re.c))) {
					//cout << "  " << j << "個目代入成功" << endl;
					info[k][0] = re.t;
					info[k][1] = re.c;
					break;
				}
				if (k == i)flag = false;
			}
		}
		if (flag)break;
		for (int j = 0; j <= i; j++) {
			for (int k = 0; k < 2; k++)info[j][k] = 0;
		}
		flag = true;
	}

	cout << (i + 1) << endl;
}

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

#pragma GCC optimize("unroll-loops")
#pragma GCC optimize("Ofast")

using namespace std;

typedef long long ll;
typedef long double ld;

const ll MOD = 998244353;

void solve() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i] >> b[i];
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    int am = -1, bm = -1;
    if (n % 2) {
        am = a[n / 2];
        bm = b[n / 2];
    } else {
        am = a[n / 2] + a[n / 2 - 1];
        bm = b[n / 2] + b[n / 2 - 1];
    }
    cout << bm - am + 1 << "\n";
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    solve();
    return 0;
}

Measured memory_bytes: 4784
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N, M, X, Y;
  cin >> N >> M >> X >> Y;
  ll x, y, max_x = X, min_y = Y;
  for (int i = 0; i < N; i++) {
    cin >> x;
    max_x = max(max_x, x);
  }
  for (int i = 0; i < M; i++) {
    cin >> y;
    min_y = min(min_y, y);
  }
  if (max_x < min_y) {
    cout << "No War" << endl;
  } else {
    cout << "War" << endl;
  }
  return 0;
}

Measured memory_bytes: 3628
# -1- method

def A(n,k,array,i):
	count = n
	if k >= n:
		count = 1
	elif i == n-1:
		count = int(-(-(n-1)/k-1)) 
	else:
		count = -(-(n-1)//(k-1))
	return count

	
	
baseinfo = input().split(" ")
baseinfo = [int(c) for c in baseinfo]
n, k = baseinfo[0], baseinfo[1]

array = input().split(" ")
array = [int(c) for c in array]

#print(n,k,array.index(1))
print(A(n, k, array, array.index(1)))


Measured memory_bytes: 14324
#include <array>
#include <cstdlib>
#include <iostream>
#include <queue>
#include <tuple>
#include <vector>
using namespace std;

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

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

	int turn[128];
	turn['L'] = -1;
	turn['R'] = 1;

	for(int h, w, n; cin >> h >> w >> n && h;) {
		string command;
		cin >> command;

		vector<int> dir(n + 1, 0);
		array<vector<int>, 4> get_d;

		for(int i = 0; i < n; ++i) {
			get_d[dir[i]].emplace_back(i);
			dir[i + 1] = (dir[i] + turn[command[i]] + 4) % 4;
		}

		get_d[dir.back()].emplace_back(n);

		vector<string> field(h);
		for(auto &e : field) cin >> e;

		typedef tuple<int, int, int> P;
		priority_queue<P, vector<P>, greater<P>> que;
		vector<vector<int>> dist(h, vector<int>(w, n + 1));

		for(int i = 0; i < h; ++i) {
			for(int j = 0; j < w; ++j) {
				if(field[i][j] == 'S') {
					dist[i][j] = 0;
					que.push(make_tuple(0, j, i));
					goto unloop;
				}
			}
		}

	unloop:;

		while(!que.empty()) {
			int di, x, y;
			tie(di, x, y) = que.top();
			que.pop();

			if(dist[y][x] < di) continue;

			for(int d = 0; d < 4; ++d) {
				const int nx = x + dx[d];
				const int ny = y + dy[d];

				if(nx < 0 || ny < 0 || nx >= w || ny >= h || field[ny][nx] == '#') continue;

				const auto it = lower_bound(get_d[d].begin(), get_d[d].end(), di);
				if(it == get_d[d].end()) continue;

				if(dist[ny][nx] > *it) {
					if(field[ny][nx] == 'G') goto ok;
					dist[ny][nx] = *it;
					que.push(make_tuple(*it, nx, ny));
				}
			}	
		}

		cout << "No" << endl;
		continue;

	ok:;
		cout << "Yes" << endl;
	}

	return EXIT_SUCCESS;
}

Measured memory_bytes: 6736
#include <iostream>
  
using namespace std;
  
int a[100];
int N;
  
void print() {
    cout << a[0];
    for (int i = 1; i < N; i++) {
        cout << " " << a[i];
    }
    cout << endl;
}
  
void insertionSort() {
    print();
    for (int i = 1; i < N; i++) {
        int key = a[i];
        int j = i-1;
        for (; j>=0; j--) {
            if(a[j] > key)
                a[j+1] = a[j];
            else
                break;
        }
        a[j+1] = key;
        print();
    }
}
  
int main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
    }
    insertionSort();
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>

using namespace std;

int main()
{
    int num1, num2;
    cin >> num1;
    cin >> num2;

    if((num1 +num2)%2 == 1)
    {
        num1++;
    }
    cout << (num1 + num2)/2 << endl;

    return 0;
}


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


typedef long long ll;
#define reg register
#define rep(a,b,c) for(reg int a=b,a##end=c;a<=a##end;++a)
#define drep(a,b,c) for(reg int a=b,a##end=c;a>=a##end;--a)

char IO;
int rd(){
	int s=0,f=0;
	while(IO=getchar(),IO<'0'||IO>'9')if(IO=='-')f=1;
	do s=(s<<1)+(s<<3)+(IO^'0');
	while(IO=getchar(),IO>='0'&&IO<='9');
	return f?-s:s;
}


const int N=100+10,K=20;

int n,m;
int a[N][N];


int main(){
	n=rd(),m=rd();
	rep(i,1,n) rep(j,1,m) a[i][j]=rd();
	int ans=0;
	rep(i,1,n) rep(j,i+1,n){
		ll dis=0;
		rep(o,1,m) dis+=(a[i][o]-a[j][o])*(a[i][o]-a[j][o]);
		if((ll)sqrt(dis)*(ll)sqrt(dis)==dis) ans++;
	}
	cout<<ans<<endl;
}















Measured memory_bytes: 256
#include <ctype.h>
#include <float.h>
#include <inttypes.h>
#include <limits.h>
#include <signal.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <unistd.h>
#include <math.h>
#ifdef __cplusplus
#include <bits/stdc++.h>
#endif
#pragma GCC target("avx2")
//#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#define getchar getchar_unlocked
#define putchar putchar_unlocked
int32_t nextint(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); bool s=false; if(c=='-'){s=true;c=getchar();} uint32_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
int64_t nextlong(void){ char c=getchar(); while(c!='-'&&(c<'0'||'9'<c)) c=getchar(); int s=0; if(c=='-'){s=1;c=getchar();} uint64_t x=0; while('0'<=c && c<='9'){ x=x*10+c-'0'; c=getchar(); } return s?-x:x; }
uint32_t nextstr(char *s){ char c=getchar(); while(c==' '||c=='\n') c=getchar(); uint32_t len=0; while(c!=' '&&c!='\n'){ *s++=c; len++; c=getchar(); } *s='\0'; return len; }
void rsorta_d32(void *base, const int count, const int size, const int index){
	typedef int32_t rsort_t;
	rsort_t (*a)[size] = (rsort_t(*)[size])base;
	rsort_t (*b)[size] = (rsort_t(*)[size])malloc(count*size*sizeof(rsort_t));
	int c[0x100];
	for(int k=0; k<4; k++){
		memset(c, 0, sizeof(c)); for(int i=0; i<count; i++){ c[(a[i][index]>>(k<<3))&0xFF]++; } for(int i=1; i<0x100; i++) c[i]+=c[i-1]; for(int i=count-1; i>=0; i--){ int to=--c[(a[i][index]>>(k<<3))&0xFF]; for(int j=0; j<size; j++){ b[to][j]=a[i][j]; } }{rsort_t(*t)[size]=a; a=b; b=t;}
	}
	free(b);
}

inline int comp(long *a, long *b){
	return (*a<*b)-(*a>*b);
}

int n;
int a[300000][2];
bool bs(int x, int y){
	int k[2]={x,y};
	int l=0, r=n-1;
	while(l<=r){
		int m=(l+r)/2;
		if(comp((long*)k, (long*)a[m])>=0) r=m-1; else l=m+1;
	}
	return comp((long*)k, (long*)a[l])==0;
}
int bx[300000][2], by[300000][2];
int cx[300000], cy[300000];
int main(void){
	int h=nextint();
	int w=nextint();
	n=nextint();
	for(int i=0; i<n; i++){
		int x=nextint()-1;
		int y=nextint()-1;
		a[i][0]=x; bx[x][1]++; cx[x]++;
		a[i][1]=y; by[y][1]++; cy[y]++;
	}
	for(int x=0; x<h; x++) bx[x][0]=x;
	for(int y=0; y<w; y++) by[y][0]=y;
	rsorta_d32(a, n, 2, 0);
	rsorta_d32(a, n, 2, 1);
	rsorta_d32(bx, h, 2, 1);
	rsorta_d32(by, w, 2, 1);
	int ans=0;
	int H=0, W=0;
	for(int i=h-1; i>=0; i--){
		if(bx[i][1]!=bx[h-1][1]) break;
		H++;
	}
	for(int j=w-1; j>=0; j--){
		if(by[j][1]!=by[w-1][1]) break;
		W++;
	}
	if(H*W>n){
		int x=bx[h-1][0], y=by[w-1][0];
		int ans=cx[x]+cy[y];
		printf("%d\n", ans);
	}else{
		for(int i=h-1; i>=0; i--){
			if(bx[i][1]!=bx[h-1][1]) break;
			for(int j=w-1; j>=0; j--){
				if(by[j][1]!=by[w-1][1]) break;
				int x=bx[i][0], y=by[j][0];
				int now=cx[x]+cy[y];
				if(bs(x, y)){
					now--;
					if(now>ans) ans=now;
				}else{
					if(now>ans) ans=now;
					break;
				}
			}
		}
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 14488
#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;

int main()
{
    int N;
    cin >> N;
    vector<int> H(N);
    rep (i, N) {
        cin >> H[i];
    }

    vector<int> answer;
    rep (i, N) {
        if (i == 0) {
            answer.push_back(0);
        } else {
            if (H[i - 1] >= H[i]) {
                answer[answer.size() - 1]++;
            } else {
                answer.push_back(0);
            }
        }
    }

    sort(answer.begin(), answer.end(), greater<>());

    cout << answer[0] << endl;
    return 0;
}

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


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

    int A[Q];
    for(int i = 0; i < Q ; i++) cin >> A[i];

    if( K > Q) {
      for (int i =0 ; i < N; i++){
        cout << "Yes" << endl;
      }
      return 0;
    }
    
    vector<int> answerCount(N, 0);
    for(int i = 0; i < Q ; i++){
      int person = A[i] -1;
      answerCount[person] ++;
    }

    vector<int> lastPoint(N, K);
    for(int i = 0; i < N; i++){
      lastPoint[i] -= Q - answerCount[i];
    }

    for (auto point: lastPoint){
      if(point > 0 ){
        cout << "Yes" << endl;
      } else {
        cout << "No" << endl;
      }
    }
    return 0;
}

Measured memory_bytes: 1664
N,M = [int(i) for i in input().split()]
P = [0 for _ in range(N)]
ans,pen = 0,0
for _ in range(M):
    p,s = input().split()
    p = int(p) - 1
    if P[p] == -1:
        continue
    if s == "WA":
        P[p] += 1
    else:
        ans += 1
        pen += P[p]
        P[p] = -1
print(ans,pen)


Measured memory_bytes: 3888
#include "bits/stdc++.h"
using namespace std;
#define all(v) (v).begin(), (v).end()
#define io ios::sync_with_stdio(0)
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define rson rt << 1 | 1, mid + 1, r
#define lson rt << 1, l, mid
#define lll __int128
#define pii pair<int, int>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eps 1e-12
#define int long long
const int mod = 1e9 + 7;
inline int ksm(int a, int b)
{
    int ans = 1;
    for (; b; b >>= 1, a = a * a % mod)
        if (b & 1)
            ans = ans * a % mod;
    return ans;
}
int a[2000000];
int vis[2000000];
signed main()
{
    io;
    int n;cin>>n; int ans=0;
    rep(i,1,n)cin>>a[i];
    rep(i,1,n){
        int t=a[i];
        for(int j=2;j*j<=t;j++){
            int cnt=0;
            while(t%j==0)cnt++,t/=j;
            vis[j]=max(vis[j],cnt);
        }
        if(t>1)vis[t]=max(vis[t],1ll);
    }
    int mul=1;
    rep(i,2,1000000){
        mul=mul*ksm(i,vis[i])%mod;
    }
    rep(i,1,n){
        ans =(ans+mul*ksm(a[i],mod-2))%mod;
    }

    
    cout<<ans<<endl;


    getchar(); //

    getchar();
}


Measured memory_bytes: 10240
import java.util.*;
import java.lang.*;
import java.io.*;
import java.math.*;
 
import java.util.*;
import java.lang.*;
import java.io.*;

@SuppressWarnings("unchecked")
public class Main implements Runnable {

  static BufferedReader in;
  static PrintWriter out;
 
  public static void main(String[] args) {
      new Thread(null, new Main(), "whatever", 1<<29).start();
  }
 
  public void run() {
    in = new BufferedReader(new InputStreamReader(System.in));
    out = new PrintWriter(System.out, false);
 
    try
    {
      // in = new BufferedReader(new FileReader("class_treasurer.txt"));
      // out = new PrintWriter("output.txt");

      int t,x1,M,D,i,j,d1,d10,productDays;
      String str;
      String[] token;

      str=in.readLine().trim();
      token=str.split(" ");
      M=Integer.parseInt(token[0]);
      D=Integer.parseInt(token[1]);

      productDays=0;

      for(i=1;i<=M;i++) {
        for(j=1;j<=D;j++) {
          d1=j%10;
          d10=j/10;
          if(d1>=2 && d10>=2 && d1*d10==i) {
            productDays++;
          }
        }
      }

      out.println(productDays);

      out.flush();
      out.close();
    }
    catch(Exception e) {
      e.printStackTrace();
    }
  }
}


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

int main(){
    int n, m;
    cin >> n >> m;
    priority_queue<int> pq;
    for (int i = 0; i < n; i++){
        int x;
        cin >> x;
        pq.push(x);
    }
    for (int i = 0; i < m; i++){
        int x;
        x = pq.top(); pq.pop();
        x /= 2;
        pq.push(x);
    }
    long long ans = 0;
    for (int i = 0; i < n; i++){
        int x;
        x = pq.top(); pq.pop();
        ans += x;
    }
    cout << ans << endl;
}

Measured memory_bytes: 892
import java.util.Scanner;

public class Main {
    public static Scanner sc = new Scanner(System.in);
    public static void main(String[] args) throws Exception {
        while (sc.hasNext()) {
            int h = sc.nextInt();
            int w = sc.nextInt();
            if (h == 0 && w == 0) break;
            for (int i = 0; i < h; i++) {
                StringBuilder sb = new StringBuilder();
                for (int j = 0; j < w; j++) {
                    sb.append("#");
                }
                System.out.println(sb.toString());
            }
            System.out.println("");
        }
    }
}

Measured memory_bytes: 28996
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct edge{ int to,cost; };
const int INF = INT_MAX/3;

int main(){
    int n,m;
    while(cin >>n >>m,n){
        string s,p,g;
        cin >>s >>p >>g;

        map<string,int> name2idx;
        name2idx[s] = 0;
        name2idx[p] = 1;
        name2idx[g] = 2;

        int V = 3;

        vector<string> a(m),b(m);
        vector<int> c(m);
        rep(i,m){
            int d,t;
            cin >>a[i] >>b[i] >>d >>t;

            c[i] = d/40 + t;

            if(!name2idx.count(a[i])){
                name2idx[a[i]] = V;
                ++V;
            }
            if(!name2idx.count(b[i])){
                name2idx[b[i]] = V;
                ++V;
            }
        }

        vector<vector<edge>> G(V);
        rep(i,m){
            int u = name2idx[a[i]], v = name2idx[b[i]];
            G[u].pb({v,c[i]});
            G[v].pb({u,c[i]});
        }

        vector<int> d(V,INF);
        d[1] = 0;

        using pi = pair<int,int>;
        priority_queue<pi, vector<pi>, greater<pi>> pq;
        pq.push({0,1});
        while(!pq.empty()){
            pi now = pq.top();
            pq.pop();
            int v = now.se;
            if(now.fi > d[v]) continue;
            for(const auto &e:G[v]){
                if(d[e.to] > d[v]+e.cost){
                    d[e.to] = d[v]+e.cost;
                    pq.push({d[e.to], e.to});
                }
            }
        }

        cout << d[0]+d[2] << "\n";
    }
    return 0;
}



Measured memory_bytes: 3844
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int n;
    std::cin >> n;
    int a[100001];
    for (int i = 1; i <= n; i++) {
        std::cin >> a[i];
    }
    int x=1;
    int cnt=0;
    while(cnt<=n){
        cnt++;
        x=a[x];
        if(x==2){
            std::cout << cnt << std::endl;
            return 0;
        }
    }
    std::cout << -1 << std::endl;
    return 0;
    
}


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


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

    cout<< (((s[0]==s[1] && s[1]==s[2]) || (s[1]==s[2] && s[2]==s[3])) ? "Yes" :"No")<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// increment
#define rep_n(_1, _2, _3, NAME, ...) NAME
#define rep_2(i, n) for (int(i) = 0; (i) < (int)(n); ++(i))
#define rep_3(i, initial, n) for (int(i) = (int)(initial); (i) < (int)(n); ++(i))
#define rep(...) rep_n(__VA_ARGS__, rep_3, rep_2, rep_1)(__VA_ARGS__)
// decrement
#define rep_r_n(_1, _2, _3, NAME, ...) NAME
#define rep_r_2(i, n) for (int(i) = (int)(n); (i) > 0; (i)--)
#define rep_r_3(i, initial, n) for (int(i) = (int)(initial); (i) > (int)(n); (i)--)
#define rep_r(...) rep_r_n(__VA_ARGS__, rep_r_3, rep_r_2)(__VA_ARGS__)
// define type definition
using namespace std;
typedef long long ll;
using mpint = boost::multiprecision::cpp_int; // 多倍長整数（任意精度）
typedef pair<int, int> P;

// define construct variable
const double EPS = numeric_limits<double>::epsilon();
// 10^9 + 7
const ll MOD = ll(1e9)+7;
const ll INF = ll(1e10);
const string ALPHABET = "abcdefghijklmnopqrstuvwxyz";
const double PI = acos(-1);

// define methods
// 最大公約数
ll gcd(const ll a, const ll b) { return b ? gcd(b, a % b) : a; }
// 最小公倍数
ll lcm(const ll a, const ll b) { return a / gcd(a, b) * b; }
// char -> int
int ctoi(char c) { return (int)(c - '0'); }
// 素因数分解
vector< pair<ll, ll> > prime_factorize(ll n) {
  vector< pair<ll, ll> > p;
  for (ll i = 2; i * i <= n; i++) {
    if ((n % i) != 0) continue;
    p.push_back(make_pair(i, 0));
    while ((n % i) == 0) {
      n /= i;
      p[i].second += 1;
    }
    p.push_back(make_pair(n, 0));
  }

  if (n != 1) p.push_back(make_pair(n, 1));
  return p;
}
// 組み合わせの整合性を保つ（後ほど解析する）
ll modinv(ll a) {
	ll b = MOD, u = 1, v = 0;
	while (b) {
		ll t = a / b;
		a -= t * b;
		swap(a, b);
		u -= t * v;
		swap(u, v);
	}
	u %= MOD;
	if (u < 0) { u += MOD; }
	return u;
}
// 順列
ll permutation(const ll n, const ll m) {
	ll result = 1;
	for (ll i = n; i > n - m; i--) { result = (result * i) % MOD; }
	return result;
}

// 繰り返し n 乗法
ll repeat_square(const ll n, const ll x) {
	if (x == 0) return 1;
	ll res = repeat_square(n, x/2);
	res = res * res % MOD;
	if ((x % 2) == 1) res = res * n % MOD;
  return res;
}
// 組み合わせ nCm
ll combination(ll n, ll m) {
	ll p = permutation(n, m);
	ll div = 1;
	for (ll i = 2; i <= m; i++) {
		div = (div * i) % MOD;
	}
	return (p * modinv(div)) % MOD;
}

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

	int P [100000], Y [100000];
	vector <ll> yd [100001];



	rep(i, M) {
		int p;
		ll y;
		cin >> p >> y;

		P[i] = p;
		Y[i] = y;
		yd[p].push_back(y);
	}
	
	rep (i, N) {
		sort(yd[i+1].begin(), yd[i+1].end());
	};

	rep (i, M){
		// binary-tree is very fast...!
		auto key = lower_bound(yd[P[i]].begin(), yd[P[i]].end(), Y[i]);

		int idx = distance(yd[P[i]].begin(), key) + 1;
		printf("%06d%06d\n",P[i], idx);
	}

  return 0;
}


Measured memory_bytes: 7808
import java.io.*;
public class Main {
    public static void main(String[] args) {    
        InputStreamReader in = new InputStreamReader(System.in);
        BufferedReader reader = new BufferedReader(in);
        PrintWriter out = new PrintWriter(System.out);
        try{
            String text = reader.readLine();
            String pattern = reader.readLine();
            
            int txtCsl = 1;
            int ptnCsl = 0;
            
            int[] skip = new int[pattern.length() + 1];
            
            skip[txtCsl] = 0;
            
            //????´¢????±??????????????????????+1?????§
            while (txtCsl != pattern.length()) {
                //??????????????????????????????????????????
                if (pattern.charAt(txtCsl) == pattern.charAt(ptnCsl)) {
                    skip[++txtCsl] = ++ptnCsl;
                } else if (ptnCsl == 0) {
                    skip[++txtCsl] = ptnCsl;
                } else {
                    ptnCsl = skip[ptnCsl];
                }
            }
            
            txtCsl = ptnCsl = 0;
            while (txtCsl != text.length() && ptnCsl != pattern.length()) {
                if (text.charAt(txtCsl) == pattern.charAt(ptnCsl)) {
                    txtCsl++;
                    ptnCsl++;
                    if (ptnCsl == pattern.length()) {
                    	out.println(txtCsl - ptnCsl);
                    	ptnCsl = skip[ptnCsl];
                    }
                } else if (ptnCsl == 0) {
                    txtCsl++;
                } else {
                    ptnCsl = skip[ptnCsl];
                }
            }
            out.flush();
      
        
        }catch(IOException e){
            System.out.println(e);
        }
     }
}

Measured memory_bytes: 63968
x,y = map(int,input().split())

ans = 0

for n in range(x+1):
    kame = x - n

    tsuru_leg = n*2
    kame_leg = kame*4

    if y == (tsuru_leg+kame_leg):
        ans = ans + 1

if ans == 0:
    print('No')
else:
    print('Yes') 

Measured memory_bytes: 9084
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
   ll n,i;
   cin>>n;
   ll arr[n+1],dp[n+1];
   for(i=1;i<=n;i++)
    cin>>arr[i];

   dp[1]=0;
   dp[2]=abs(arr[1]-arr[2]);
   for(i=3;i<=n;i++)
   {
       dp[i]=min(dp[i-1]+abs(arr[i-1]-arr[i]),dp[i-2]+abs(arr[i-2]-arr[i]));
   }
   cout<<dp[n];
}


Measured memory_bytes: 5108
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
//const int MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int n;cin>>n;
    ll c;cin>>c;
    vector<pLL> x(n);
    rep(i,n){
        cin>>x[i].first>>x[i].second;
    }
    
    //// right////
    
    vector<ll>r;
    
    ll mx=0;
    ll tot=-INF;
    ll pre =0;
    rep(i,n){
        mx+=x[i].second-(x[i].first-pre);
        pre = x[i].first;
        tot=max(mx,tot);
        r.push_back(tot);
    }
    
    ////
    
    
    //// left////
    vector<ll> l;
    mx=0;
    tot=-INF;
    pre =c;
    rep(i,n){
        mx+=x[n-1-i].second-(pre-x[n-1-i].first);
        pre = x[n-1-i].first;
        tot=max(mx,tot);
        l.push_back(tot);
    }
    
    ////
    
    
    ll ans = *max_element(all(l));
    ans = max(ans,*max_element(all(r)));
    
    
    /// right-left///
    vector<ll> cumsum;
    ll temp = 0;
    rep(i,n){
        cumsum.push_back(temp + x[i].second);
        temp = cumsum[i];
    }
    
    rep(i,n){
        cumsum[i]-=x[i].first * 2;
    }
    
    rep(i,n-1){
        
        ans = max(ans,cumsum[i]+l[n-1-i-1]);
        
    }
    
    
    /// left-right
    
    cumsum.clear();
    temp = 0;
    rep(i,n){
        cumsum.push_back(temp + x[n-1-i].second);
        temp = cumsum[i];
    }
    
    rep(i,n){
        cumsum[i]-=(c-x[n-1-i].first) * 2;
    }
    
    rep(i,n-1){
        
        ans = max(ans,cumsum[i]+r[n-1-i-1]);
        
    }
    
    cout<<max(0LL,ans)<<endl;
    
    
    
    return 0;
}


Measured memory_bytes: 4852
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::{Bytes, Chars};
#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
	input! {
		n: usize,
		a: [Chars; n],
	}

	// M:12, A:0, R:17, C:2, H:7

	let mut count = vec![0; 26];
	for i in 0..n {
		count[(a[i][0] as u8 - 'A' as u8) as usize] += 1;
	}

	let c5 = [count[12], count[0], count[17], count[2], count[7]];
	let mut ans = 0usize;
	for i in 0..5-2 {
		for j in i+1..5-1 {
			for k in j+1..5 {
				ans += c5[i] * c5[j] * c5[k];
			}
		}
	}
	println!("{}", ans);
}



Measured memory_bytes: 10580
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  ll A, B, K;
  cin >> A >> B >> K;
  ll res = K - A;
  if (res >= 0) {
    A = 0;
    if (res >= B) B = 0;
    else B -= res;
  }
  else A -= K;
  cout << A << ' ' << B << endl;
  return 0;
}

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

int main() {
   // freopen( "C:\\Users\\ehab\\Desktop\\problems\\in.txt" , "r" , stdin );

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

    if ( n % k == 0 )
        cout << 0;
    else
        cout << 1;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize(2)
#include<bits/stdc++.h>
#define ll long long
#define maxn 1000005
#define inf 1e9
#define pb push_back
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
using namespace std;

inline int read()
{
	int x=0,w=1; char c=getchar();
	while(c<'0'||c>'9') {if(c=='-') w=-1; c=getchar();}
	while(c<='9'&&c>='0') {x=(x<<1)+(x<<3)+c-'0'; c=getchar();}
	return w==1?x:-x;
}

struct node{int x,y,a,b,c,d;}p[maxn];
int bx[maxn],by[maxn],cntx,cnty,n,c[maxn];
const ll mod=998244353;

inline void add(int x,int val){for(int i=x;i<=n;i+=i&(-i)) c[i]+=val;}
inline int q(int x){int res=0; for(int i=x;i;i-=i&-i) res+=c[i]; return res;}

inline bool cmp1(node a,node b){return a.x<b.x;}
inline bool cmp2(node a,node b){return a.y<b.y;}

inline ll pw(ll a,ll b)
{
	ll ans=1,base=a;
	while(b)
	{
		if(b&1) ans=(ans*base)%mod;
		base=(base*base)%mod; b>>=1;
	}
	return ans;
}

inline ll M(ll a,ll b){return (a*b)%mod;}

inline ll gs(int i)
{
	ll a=pw(2,p[i].a),b=pw(2,p[i].b),c=pw(2,p[i].c),d=pw(2,p[i].d);
	ll p1=M(M(M(c,d),a-1),b-1);
	ll p2=M(M(M(a,b),c-1),d-1);
	ll p3=M(M(M(a-1,b-1),c-1),d-1);
	return (p1+p2-p3+mod)%mod;
}

inline ll g2(int x)
{
	int cnt=0;
	while(x) {if(x&1) cnt++; x>>=1;}
	return cnt;
}

int main()
{
	n=read(); rep(i,1,n) p[i].x=read(),p[i].y=read(),bx[++cntx]=p[i].x,by[++cnty]=p[i].y;
	sort(bx+1,bx+cntx+1); sort(by+1,by+cnty+1); sort(p+1,p+n+1,cmp1);
	rep(i,1,n)
	{
		int tmp=lower_bound(by+1,by+cnty+1,p[i].y)-by;
		p[i].c=q(tmp); p[i].a=i-1-p[i].c; add(tmp,1);
	}
	rep(i,1,n) c[i]=0; sort(p+1,p+n+1,cmp2);
	rep(i,1,n)
	{
		int tmp=lower_bound(bx+1,bx+cntx+1,p[i].x)-bx;
		p[i].c=q(tmp); p[i].b=i-1-p[i].c; add(tmp,1); p[i].d=n-1-p[i].a-p[i].b-p[i].c;
	}
	ll ans=0;
	rep(i,1,n) ans=(ans+gs(i))%mod; ans=(ans+M(n,pw(2,n-1)))%mod;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10664
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<cstdio>
#define initdp(a,b) for(int i=0;i<=a;i++)for(int j=0;j<=b;j++)dp[i][j]=-1;
#define fi first
#define se second
#define pb push_back
#define pii pair<int,int>
#define ppi pair<pii,int>
#define pip pair<int,pii>
#define ll long long
#define pll pair<ll,ll>
#define rep(i,n) for(int i=0;i<n;i++)
#define repd(i,n) for(int i=n-1;i>=0;i--)
#define inf 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846
#define N 500005
#define mid(l,r) l+(r-l)/2
using namespace std;
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
void mad(ll &a,ll b){a=(a+b)%mod;if(a<0)a+=mod;}
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}
int bit[N];
void update(int u,int k,int n){
	for(int i=u;i<=n;i+=(i&-i))bit[i]+=k;
}
int getsum(int u){
	int ans=0;
	for(int i=u;i;i-=(i&-i))ans+=bit[i];
	return ans;
}

void solve(){
	int n,q;
	cin>>n>>q;
	int c[n];
	rep(i,n)cin>>c[i];
	vector<pii>qry;
	int ans[q],l[q];
	memset(ans,0,sizeof(ans));
	rep(i,q){
		int l1,r;
		cin>>l1>>r;
		//if(l>1)qry.pb(pii(l-2,i));
		l[i]=l1-1;
		qry.pb(pii(r-1,i));
	}
	int last_visit[n+1];
	memset(last_visit,-1,sizeof(last_visit));
	sort(qry.begin(), qry.end());
	int j=0;
	for(int i=0;i<n;i++){
		if(last_visit[c[i]]!=-1)update(last_visit[c[i]]+1,-1,n);
		last_visit[c[i]]=i;
		update(i+1,1,n);
		while(j<qry.size()&&i==qry[j].fi){
			int id=qry[j].se;
			ans[id]=getsum(i+1)-getsum(l[id]);
			//cout<<ans[id]<<" "<<id<<" "<<getsum(i+1)<<" "<<getsum(l[id])<<"\n";
			j++;
		}
	}
	for(int i=0;i<q;i++)cout<<ans[i]<<"\n";
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int t;
	//cin>>t;
	t=1;
	while(t--){
		solve();
	}
}

Measured memory_bytes: 17596
#include <iostream>
#include <vector>
#include <string.h>
#include <set>
#include <map>
#include <unordered_map>
#include <assert.h>
#include <algorithm>
#include <queue>
#include <bitset>
#include <stack>
#include <chrono>
#include <random>
#define all(x) x.begin(),x.end()
#define ff first
#define ss second
#define ll long long
#define INF 1000000000000000000
#define MOD 998244353
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define uid uniform_int_distribution <int>
using namespace std;
// Read the question carefully and see all the given sample tests
// Think about the correctness before implementing

int main() {
	int n, k;
	cin >> n >> k;
	vector <vector<int>> A(k, vector<int>(k));
	int sum1 = 0, sum2 = 0;
	for (int i = 0; i < n; i++) {
		int x, y;
		char ch;
		cin >> x >> y >> ch;
		int val = ((x / k) + (y / k) + (ch == 'B')) % 2 ? -1 : 1;
		A[x % k][y % k] += val;
		if(val == 1)
			sum1++;
		else
			sum2++;
	}
	vector <vector<int>> dp(k + 1, vector<int>(k + 1));
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			dp[i + 1][j + 1] = dp[i + 1][j] + dp[i][j + 1] - dp[i][j] + A[i][j];
		}
	}
	int ans = 0;
	for (int i = 0; i < k; i++) {
		for (int j = 0; j < k; j++) {
			int val = dp[i][k] + dp[k][j] - 2 * dp[i][j];
			ans = max(ans, sum1 - val);
			ans = max(ans, sum2 + val);
		}
	}
	cout << ans;
}


Measured memory_bytes: 8192
N = int(input())
ans = 10**10 #適当に初期化
ans_ = 10**10

divisors = []
for i in range(1, int(N**0.5)+1):
    if N % i == 0:
        divisors.append(i)
        divisors.append(N//i)
        if len(str(N//i))<=ans:
            ans =N//i
            ans_=i
            
if N ==1:
    ans =1
            
print((len(str(ans))))

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

#define MAX 100005
#define NIL -1

struct Node {
  int parent = NIL;
  int left = NIL;
  int right = NIL;
};

Node trees[MAX];
int depths[MAX];

void print(int id) {
  cout << "node " << id << ": ";
  cout << "parent = " << trees[id].parent << ", ";
  cout << "depth = " << depths[id] << ", ";

  if (trees[id].parent == NIL) {
    cout << "root, ";
  } else if (trees[id].left == NIL) {
    cout << "leaf, ";
  } else {
    cout << "internal node, ";
  }

  cout << "[";

  for (int i = 0, current = trees[id].left; current != NIL ; ++i, current = trees[current].right) {
    if (i != 0) {
      cout << ", ";
    }
    cout << current;
  }
  cout << "]" << endl;
}

void set_depths(int id, int depth) {
  depths[id] = depth;
  if (trees[id].right != NIL) {
    set_depths(trees[id].right, depth);
  }
  if (trees[id].left != NIL) {
    set_depths(trees[id].left, depth + 1);
  }
}

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

  for (int i = 0; i < n; ++i) {
    int id, k;
    cin >> id >> k;
    int left;
    for (int j = 0; j < k; ++j) {
      int current;
      cin >> current;
      if (j == 0) {
        trees[id].left = current;
      } else {
        trees[left].right = current;
      }
      left = current;
      trees[current].parent = id;
    }
  }
  int root;
  for (int i = 0; i < n; ++i) {
    if (trees[i].parent == NIL) {
      root = i;
    }
  }

  set_depths(root, 0);

  for (int i = 0; i < n; ++i) {
    print(i);
  }

  return 0;
}



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

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

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

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

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

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

void nCrprep() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

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

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

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




int main(){
  string s; 
  
  rep(i,4){
    char c; cin >> c;
    s += c;
  }
  
  sort(all(s));
  if(s == "1479") cout << "YES" << endl;
  else cout << "NO" << endl;
  
  
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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

int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    for(int i=0;i<n;i++) cin >> a[i];
    deque<int> dq;
    bool rev=false;
    for(int i=0;i<n;i++){
        if(rev){
            dq.push_front(a[i]);
            rev=false;
        }else{
            dq.push_back(a[i]);
            rev=true;
        }
    }
    if(rev){
        for(int i=n-1;i>=0;i--){
            cout << dq[i] << " ";
        }
        cout << endl;
        return 0;
    }else{
        for(int i=0;i<n;i++){
            cout << dq[i] << " ";
        }
        cout << endl;
        return 0;
    }
}

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

typedef long long ll;
const int p = (int)1e9+7;

int main() {
	ll N, M;
	cin >> N >> M;
	vector<ll> A(N+1,0), B(N+1,0);
	for (ll i = 1; i <= N; i++) {
		cin >> A[i];
		B[i] = B[i-1] + A[i];
	}
	map<ll,ll> m;
	for (ll i = 0; i <= N; i++) {
		//cout << B[i] <<" "<< B[i]%M << endl;
		m[B[i]%M]++;
	}
	ll ans=0;
	for (auto x : m) {
		if (x.second > 1) {
			ans += (x.second*(x.second-1))/2;
		}
	}

	cout << ans << endl;
}

Measured memory_bytes: 5760