akhauriyash/Code-Regression huggingface dataset:
MOD = int(1e9+7)


def main():
    N, K = map(int, input().split())
    ans = 0
    # pick i numbers
    for i in range(K, N+2):
        mn = (i-1) * i // 2
        mx = (N-i+1+N) * i // 2
        ans += (mx-mn+1)
        ans %= MOD
    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 63300
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <iomanip>

using namespace std;


int main(){
   int N,M;
   cin >> N >> M;
   vector<pair<long long,long long> > v;
   for(int i=0; i<N;i++){
      long long A,B; 
      cin >> A >> B;
      v.push_back(make_pair(A,B));
   }
   sort(v.begin(),v.end());
   long long ans = 0;
   for(int i=0; i<N; i++){
      if( v[i].second > M){
         ans += M*v[i].first;
      }
      else{
         ans += v[i].second * v[i].first;
      }
      M-=v[i].second;
      if(M<=0) break;
   }
   cout << ans << endl;
   return 0;
}


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


void solve(long long N, long long A, long long B, long long C, long long D, long long E){
    vector<ll> vec;
    vec.push_back(A);
    vec.push_back(B);
    vec.push_back(C);
    vec.push_back(D);
    vec.push_back(E);
    ll m = *min_element(vec.begin(), vec.end());
    ll p = (ll)ceil(N * 1.0 / m);
    printf("%lld", p+4);


}

int main(){

    //FILE* fp_in = freopen("/Users/kokinakamura/atcoder-workspace/abc123/C/in_2.txt", "r", stdin);

    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    long long C;
    scanf("%lld",&C);
    long long D;
    scanf("%lld",&D);
    long long E;
    scanf("%lld",&E);
    solve(N, A, B, C, D, E);

    return 0;
}

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

using namespace std;

int main(){
  string s, t;
  cin >> s >> t;
  
  vector<vector<int>> next(s.size(), vector<int>(26, -1));
  
  next[s.size() - 1][s[0] - 'a'] = 1;
  
  for(int i = s.size() - 1; i > 0; i--){
    next[i - 1][s[i] - 'a'] = 1;
  }
  
  for(int i = s.size() - 1; i > 0; i--){
    for(int c = 0; c < 26; c++){
      if(next[i][c] != -1){
        next[i - 1][c] =
          next[i - 1][c] != -1 ?
            min(next[i][c] + 1, next[i - 1][c])
          : next[i][c] + 1;
      }
    }
  }
  
  for(int c = 0; c < 26; c++){
    if(next[0][c] != -1){
      next[s.size() - 1][c] =
        next[s.size() - 1][c] != -1 ?
          min(next[0][c] + 1, next[s.size() - 1][c])
        : next[0][c] + 1;
    }
  }
  
  for(int i = s.size() - 1; i > 0; i--){
    for(int c = 0; c < 26; c++){
      if(next[i][c] != -1){
        next[i - 1][c] =
          next[i - 1][c] != -1 ?
            min(next[i][c] + 1, next[i - 1][c])
          : next[i][c] + 1;
      }
    }
  }
  
  long long k = 0;
  int index = s.size() - 1;
  for(int i = 0; i < t.size(); i++){
    if(next[index][t[i] - 'a'] == -1){
      k = -1;
      break;
    }
    
    k += next[index][t[i] - 'a'];
    index += next[index][t[i] - 'a'];
    index %= s.size();
  }
  
  cout << k << endl;
  
  return 0;
}



Measured memory_bytes: 13696
#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<ll, ll> P;

const ll INF = 1LL << 60;

ll N, K;
int main() {
    cin >> N >> K;
    map<ll, ll> mp;
    for (ll i = 2; i * i <= K; i++) {
        if (K % i == 0) {
            ll cnt = 0;
            while (K % i == 0) {
                K /= i;
                cnt++;
            }
            mp[i] = cnt;
        }
    }
    if (K != 1) mp[K] = 1;

    ll ans = 1;
    for (auto iter = mp.begin(); iter != mp.end(); iter++) {
        // cout << iter->first << " " << iter->second << endl;
        ll sisuu = iter->second / N;
        ans *= pow(iter->first, sisuu);
    }
    cout << ans << endl;
}

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

int a,b,c;

void does(){
    if(a == b && b == c){
        puts("No"); return;
    }
    if(a != b && b != c && a != c){
        puts("No"); return;
    }
    puts("Yes");
}

int main()
{
    cin>>a>>b>>c;
    does();
}


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

using namespace std;

#define fore(i, s, e) for(int i = s; i < e; i++)
#define pb push_back
#define fst first
#define snd second
#define endl '\n'

typedef long long ll;

const int N = 1e5 + 10;

vector<int> g[N];

bool visited[N];

int a;

vector<int> v;

void dfs(int x) {
    if(visited[x]) return;
    visited[x] = 1;
    a = (a + v[x]) % 26;
    for(auto v : g[x]) dfs(v);
}

int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    string s; cin >> s;
    fore(i, 0, s.size()) v.pb(s[i] - 'a');
    v.pb(0);
    for(int i = v.size() - 1; i >= 0; i--) v[i] = (v[i] - v[i - 1] + 26) % 26;
    fore(i, 0, v.size()) {
        g[i].pb(v.size() - 1 - i);
    }
    int n; cin >> n;
    fore(i, 0, n) {
        int l, r; cin >> l >> r; l--;
        g[l].pb(r);
        g[r].pb(l);
    }
    bool f = true;
    fore(i, 0, v.size()) if(!visited[i]) {
        dfs(i), f = f && !a;
    }
    if(f) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

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

using namespace std;

long long g(long long a) {
    // returns 0 ^ 1 ^ ... ^ (a-1)
    if (a % 2 == 0) {
        return (a/2) & 1LL;
    }
    return (a-1) ^ g(a-1);
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    long long a, b;
    cin >> a >> b;
    cout << (g(b+1) ^ g(a)) << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

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

        int[] bArr = new int[m];

        int count = 0;

        for (int i = 0; i < m; i++) {
            bArr[i] = sc.nextInt();
        }

        for (int i = 0; i < n; i++) {
            int sum = 0;
            for (int j = 0; j < m; j++) {
                int a = sc.nextInt();
                sum += bArr[j] * a;
            }
            if (sum + c > 0) count++;
        }

        System.out.println(count);
    }

}


Measured memory_bytes: 22224
def get_input():
    X, Y, Z, K = [int(_) for _ in raw_input().split()]
    A = [int(_) for _ in raw_input().split()]
    B = [int(_) for _ in raw_input().split()]
    C = [int(_) for _ in raw_input().split()]
    return X, Y, Z, K, A, B, C

def AddToQueue(_ele, _queue, _ijk_set, K):
    if len(_queue) == 0:
        _queue.append(_ele)
    else:
        cnt = 0
        while cnt < len(_queue) and _queue[cnt][0] >= _ele[0]:
            cnt += 1
        ijk = (_ele[1], _ele[2], _ele[3])
        if not (ijk in _ijk_set):
            _queue.insert(cnt, _ele)
            _ijk_set.add(ijk)
            _queue = _queue[:K]

def solve3():
    X, Y, Z, K, A, B, C = get_input()
    A.sort(reverse = True)
    B.sort(reverse = True)
    C.sort(reverse = True)
    ijk_set = set()
    queue = [(A[0] + B[0] + C[0], 0, 0, 0)]
    ijk_set.add((0, 0, 0))
    for cnt in range(K):
        ele, i, j, k = queue.pop(0)
        print ele
        if i + 1 < X:
            AddToQueue((A[i+1] + B[j] + C[k], i+1, j, k), queue, ijk_set, K)
        if j + 1 < Y:
            AddToQueue((A[i] + B[j+1] + C[k], i, j+1, k), queue, ijk_set, K)
        if k + 1 < Z:
            AddToQueue((A[i] + B[j] + C[k+1], i, j, k+1), queue, ijk_set, K)

if __name__ == '__main__':
    solve3()


Measured memory_bytes: 35816
#include <bits/stdc++.h>
using namespace std;
int main() {
	int h, w, k; cin >> h >> w >> k;
	char MP[h][w] = {};
	for (int i = 0; i < h; i++)
		for (int j = 0; j < w; j++)
			cin >> MP[i][j];
	int ans = 0;
	for (int maskR = 0; maskR < (1 << h); maskR++) {
		for (int maskC = 0; maskC < (1 << w); maskC++) {
			int cnt = 0;
			for (int i = 0; i < h; i++) {
				for (int j = 0; j < w; j++) {
					if (!((maskR >> i) & 1) and !((maskC >> j) & 1) and MP[i][j] == '#')
						++cnt;
				}
			}
			if (cnt == k) ++ans;
		}
	}
	cout << ans << "\n";
}

Measured memory_bytes: 3632
#include<stdio.h>
#include<stdlib.h>
#define FOR(n) for(int i=0;i<n;i++)
#define FORJ(n) for(int j=0;j<n;j++)
#define PRN(n) printf("%d\n",n)
int compare(const void *a, const void *b){
    return *(int*)a - *(int*)b;
}
int z(int a){
  if(a>0)return a;
  return -a;
}
int main(void){
  int a,b;
  scanf("%d %d",&a,&b);
  PRN(z(a-b));
  return 0;
}


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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define INF 1e9
#define MOD 1e9+7

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

//library----------------------------------------------



int main() {
    CIN(a,b,c);
    if(a==b&&b==c){
        printf("No\n");
    }
    else if(a!=b&&b!=c&&c!=a){
        printf("No\n");
    }else{
        printf("Yes\n");
    }
    return 0;
}

Measured memory_bytes: 256
import sys
from collections import defaultdict as dd
sys.setrecursionlimit(10 ** 7)
input = sys.stdin.buffer.readline
N, M = map(int, input().split())
nums = list(map(int, input().split()))
ms = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6]
dp = [0] * (N + 1)
for i in range(N):
  for n in nums:
    if i + ms[n] > N: continue
    if i != 0 and dp[i] == 0: continue
    dp[i + ms[n]] = max(dp[i] * 10 + n, dp[i + ms[n]])
print(dp[N])

Measured memory_bytes: 51036
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int a,b,c;
    cin >> a >> b >> c;

    if(a+b+c >= 22){
        cout << "bust" << endl;
    }
    else{
        cout << "win" << 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 x = sc.nextInt();
		if (x < 600) {
			System.out.println(8);
		} else if (x < 800) {
			System.out.println(7);
		} else if (x < 1000) {
			System.out.println(6);
		} else if (x < 1200) {
			System.out.println(5);
		} else if (x < 1400) {
			System.out.println(4);
		} else if (x < 1600) {
			System.out.println(3);
		} else if (x < 1800) {
			System.out.println(2);
		} else {
			System.out.println(1);
		}
	}

}

Measured memory_bytes: 35616
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())

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

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

void solve(std::string S)
{
    while (S.size() > 0)
    {
        S.pop_back();
        if (S.size() % 2 == 0)
        {
            if (S.substr(0, S.size() / 2) == S.substr(S.size() / 2, S.size() / 2))
            {
                cout << S.size() << endl;
                return;
            }
        }
    }
}

int main()
{
    std::string S;
    std::cin >> S;
    solve(S);
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

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

        System.out.println(
            (a.substring(a.length()-1,a.length()).equals(b.substring(0,1)) &&
             b.substring(b.length()-1,b.length()).equals(c.substring(0,1))) ? "YES" : "NO");
    }

}

Measured memory_bytes: 23636
X, N = [ int(i) for i in input().strip().split(' ')]

if N == 0:
    _ = input()
    print(X)
else:
    p = { int(i) for i in input().strip().split(' ')}

    all_set = { n for n in range(-1, 101+1, 1)}
    candidates = list(all_set - p)
    best_distance = 1000
    cand = -2
    for c in candidates:
        distance = abs(c-X)
        if best_distance > distance:
            cand = c
            best_distance = distance
    print(cand)

Measured memory_bytes: 9216
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.run();
    }
    
    // 変数一覧
    int n;
    int m;
    int[] a;
    double total;
    double vote;
    boolean res = true;

    public void run() {
        // 入力情報取得
        Scanner sc = new Scanner(System.in);
        n = sc.nextInt();
        m = sc.nextInt();
        a = new int[n+1];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
            total += a[i];
        }
        sc.close();
        
        // 解答処理
        solve();
    }
    
    private void solve() {
        vote = total / (4 * m);
        a = sort(a, 1);

        for (int i = 0; i < m; i++) {
            if (vote > a[i]) {
                res = false;
            }
        }
        if (res) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    // 配列ソート(0:ASC 1:DESC)
    private int[] sort(int[] l, int flg) {
        ArrayList list = new ArrayList();
        for (int i = 0; i < l.length; i++) {
            list.add(l[i]);
        }
        // 昇順
        if (flg == 0)
            list.sort(Comparator.naturalOrder());
        // 降順
        if (flg == 1)
            list.sort(Comparator.reverseOrder());
        for (int i = 0; i < list.size(); i++) {
            l[i] = (int) list.get(i);
        }
        return l;
    }
}


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

using namespace std;

int main()
{
   int k;
   cin>>k;
   vector<int>v;
   v.push_back(1);
   v.push_back(1);
   v.push_back(1);
   v.push_back(2);
   v.push_back(1);
   v.push_back(2);
   v.push_back(1);
   v.push_back(5);
   v.push_back(2);
   v.push_back(2);
   v.push_back(1);
   v.push_back(5);
   v.push_back(1);
   v.push_back(2);
   v.push_back(1);
   v.push_back(14);
   v.push_back(1);
   v.push_back(5);
   v.push_back(1);
   v.push_back(5);
   v.push_back(2);
   v.push_back(2);
   v.push_back(1);
   v.push_back(15);
   v.push_back(2);
   v.push_back(2);
   v.push_back(5);
   v.push_back(4);
   v.push_back(1);
   v.push_back(4);
   v.push_back(1);
   v.push_back(51);
    cout<<v[k-1]<<endl;

}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Buffer(make([]byte, 0), 1e6) // maxTokenSize
	sc.Split(bufio.ScanWords)
	defer out.Flush()
	/* --- code --- */

	for i := 1; i <= 5; i++ {
		x := nextInt()
		if x == 0 {
			fmt.Println(i)
		}
	}

}

// -*-*-*-*-*-*-*-*-
// * I/O utilities *
// -*-*-*-*-*-*-*-*-

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextInt64() int64 {
	a, _ := strconv.ParseInt(next(), 10, 64)
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

func split(s string) []string {
	ret := make([]string, len([]rune(s)))
	for i, v := range []rune(s) {
		ret[i] = string(v)
	}
	return ret
}

// -*-*-*-*-*-*-*-*-
// * tool snippets *
// -*-*-*-*-*-*-*-*-
func duplicate2Int(base [][]int) (ret [][]int) {
	ret = make([][]int, len(base))
	for i, v := range base {
		ret[i] = append([]int{}, v...)
	}
	return
}

func max(a, b int) int {
	return int(max64(int64(a), int64(b)))
}

func max64(a int64, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func min(a, b int) int {
	return int(min64(int64(a), int64(b)))
}

func min64(a int64, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
// * math flavor typical theories *
// *-*-*-*-*-*-*-*-*-*-*-*-*-*-*-*-
func gcd(a, b int) int {
	if a > b {
		return gcd(b, a)
	}
	for a != 0 {
		a, b = b%a, a
	}
	return b
}

func pow(a, b int) (ret int) {
	ret = a
	for i := 0; i < b-1; i++ {
		ret *= a
	}
	return
}

func powMod(n, m, mod int) (ret int) {
	ret = 1
	for m > 0 {
		if m&1 == 1 {
			ret *= n
			ret %= mod
		}
		n *= n
		n %= mod
		m >>= 1
	}
	return ret
}


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

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n, w;
    cin >> n >> w;
    vector<int> value(n), weight(n);
    rep(i, n) cin >> value[i] >> weight[i];

    vector<vector<int>> dp(n+1, vector<int>(w+1, 0));
    rep(i, n) {
        rep(j, w+1) {
            chmax(dp[i+1][j], dp[i][j]);
            if (j - weight[i] >= 0)chmax(dp[i+1][j], dp[i][j-weight[i]] + value[i]);
        }
    }
    
    cout << dp[n][w] << endl;
}


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

int main() {

  long a,b,c;
  cin>>a>>b>>c;
  int i=0;
  long A[100005], B[100005], C[100005];
  A[0]=a;
  B[0]=b;
  C[0]=c;
  if(a%2!=0||b%2!=0||c%2!=0){
    cout<<0<<endl;
    return 0;
  }
  i++;
  A[1]=(b+c)/2;
  B[1]=(a+c)/2;
  C[1]=(a+b)/2;
  while(i<100000){
    if(A[i]%2!=0||B[i]%2!=0||C[i]%2!=0){
      cout<<i<<endl;
      return 0;
    }
    A[i+1]=(A[i]+A[i-1])/2;
    B[i+1]=(B[i]+B[i-1])/2;
    C[i+1]=(C[i]+C[i-1])/2;
    i++;
  }
  cout<<-1<<endl;
}


Measured memory_bytes: 2560
#include<bits/stdc++.h>
using namespace std;  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define rep(i,n) for(ll i=0;i<(n);i++)  
#define pii pair<int,int>
#define piii pair<int,pii>
#define mp make_pair
#define pb push_back  
#define ALL(a) (a).begin(),(a).end()
#define FST first
#define SEC second  
const int INF = (INT_MAX/2);
const ll LLINF = (LLONG_MAX/2);
const double eps = 1e-5;
const double PI = M_PI;  
#define DEB cerr<<"!"<<endl
#define SHOW(a,b) cerr<<(a)<<" "<<(b)<<endl
#define SHOWARRAY(ar,i,j) REP(a,i)REP(b,j)cerr<<ar[a][b]<<((b==j-1)?((a==i-1)?("\n\n"):("\n")):(" "))
  
#define DIV 1000000007
typedef vector<ll> Array;
typedef vector<Array> matrix;
typedef tuple<int,int,int> tiii;
#define mt make_tuple

int main(){
  int n,a,b; cin >> n >> a >> b;
  int ta = 0, tb = 0;
  string s; cin >> s;
  rep(i,s.size()){
    if(s[i] == 'a'){
      if(ta+tb < a + b){ta++,cout << "Yes" << endl;}
      else{cout << "No" << endl;}
    }else if(s[i] == 'b'){
      if(ta+tb < a+b && tb < b){tb++,cout << "Yes" << endl;}
      else{cout << "No" << endl;}
    }else{
      cout << "No" << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 896
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cmath>
#include<algorithm>
using namespace std;
int n,m,len;
int sum[1001010];
int c[1010100],num;
struct mol
{
	int l;
	int r;
	int id;
	int ans;
}a[1001010];
inline int read()
{
	char c=getchar();
	int tot=1;
	while((c<'0'|| c>'9')&&c!='-')
		c=getchar();
	if(c=='-')
	{
		tot=-1;
		c=getchar();
	}
	int sum=0;
	while(c>='0'&&c<='9')
	{
		sum=sum*10+c-'0';
		c=getchar();
	}
	return sum*tot;
}
inline void writ(int x)
{
	if(x<0)
	{
		putchar('-');
		writ(-x);
		return;
	}
	if(x>=10)
		writ(x/10);
	putchar(x%10+'0');
}
inline void write(int x)
{
	writ(x);
	printf("\n");
}
inline int bl(int x)
{
	return (x-1)/len+1;
}
inline int cmp(mol a,mol b)
{
	return bl(a.l)==bl(b.l)?(bl(a.l)&1)?a.r<b.r:a.r>b.r:a.l<b.l;
}
inline int cnm(mol a,mol b)
{
	return a.id<b.id;
}
inline void add(int x)
{
	num+=(++sum[c[x]]==1);
}
inline void del(int x)
{
	num-=(--sum[c[x]]==0);
}
int main()
{
	n=read();
	m=read();
	for(register int i=1;i<=n;i++)
		c[i]=read();
	len=n/sqrt(m*2/3);
	for(register int i=1;i<=m;i++)
	{
		a[i].l=read();
		a[i].r=read();
		a[i].id=i;
	}
	sort(a+1,a+m+1,cmp);
	int l=0,r=0;
	for(register int i=1;i<=m;i++)
	{
		while(l<a[i].l)
			del(l++);
		while(l>a[i].l)
			add(--l);
		while(r<a[i].r)
			add(++r);
		while(r>a[i].r)
			del(r--);
		a[a[i].id].ans=num;
	}
	for(register int i=1;i<=m;i++)
		write(a[i].ans);
	return 0;
}

Measured memory_bytes: 15292
/**
    In the name of Allah, the Most Gracious, the Most Merciful.
**/

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

typedef long long ll;

const int N = 3e5 + 5;

pair < int, int > ara[1005];
vector < pair < int, int > > ve;
int n, m, c, d, ans;

int main() {
#ifdef _OFFLINE_
        freopen("in.txt", "r", stdin);
#endif /// _OFFLINE_

        cin >> n >> m;
        for(int i=0; i<m; i++) {
                cin >> ara[i].first >> ara[i].second;
        }

        sort(ara, ara+m);

//        for(int i=0; i<m; i++) {
//                cerr << ara[i].first << " " << ara[i].second << "\n";
//        }

        if( !m ) {
                cout << n + 1 << "\n";
                exit(0);
        }

        int l = 0, r = 0;

        for(int i=0; i<m; i++) {
                if( r >= ara[i].first ) {
                        r = max(r, ara[i].second);
                }
                else if( r < ara[i].first ) {
                        if( l && r ) {
                                ve.push_back({l, r});
                        }
                        l = ara[i].first;
                        r = ara[i].second;
                }
                if( i == m-1 ) {
                        if( l && r ) {
                                ve.push_back({l, r});
                        }
                }
        }

//        cerr << endl;
//
//        for(int i=0; i<ve.size(); i++) {
//                cerr << ve[i].first << " " << ve[i].second << "\n";
//        }

        int len = ve.size(), pre = 0;

        for(int i=0; i<len; i++) {
                ans += ve[i].first - pre;
                ans += (ve[i].second - ve[i].first) * 3;
                pre = ve[i].second;
        }
        ans += (n+1) - pre;

        cout << ans << "\n";

        return 0;
}



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

 bool cmp(const pair<int,int> &a,const pair<int,int> &b){
   if (a.second!=b.second){
     return a.second > b.second;
 }else {
   return a.first > b.first;
 }
}

int main(){
  int n,m;
  cin >> n >> m;
  priority_queue<int> q;
  vector<pair<int,int> > AB;
  for (int i=0;i<n;i++){
    pair<int,int> ab;
    int A,B;
    cin >> A >> B;
    ab.first= A;
    ab.second=B;
    AB.push_back (ab);
  }
  sort(AB.begin(),AB.end());

  long long int ans=0;
  int idx=0;
  vector<pair<int,int> >::iterator itr=AB.begin();
  for (int i=m-1;i>=0;i--){
    while(itr!=AB.end() && itr->first <= m-i){
      q.push(itr->second);
      itr++;
    }
    if(!q.empty()){
      ans+= q.top();
      q.pop();
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1908
#include<stdio.h>
typedef struct bank{
	int b,r,t;
	double s;
}BANK;
BANK a[55];
int main(){
	int i,j,n,y,f;
	double max;
	while(1){
		scanf("%d",&n);
		if(n==0)break;
		max=0.0;
		scanf("%d",&y);
		for(i=0;i<n;i++){
			scanf("%d%d%d",&a[i].b,&a[i].r,&a[i].t);
			if(a[i].t==1){
				a[i].s=1+(double)(y*a[i].r)/100;
			}
			else{
				a[i].s=1.0;
				for(j=0;j<y;j++)a[i].s*=1+(double)a[i].r/100;
			}
			//printf("%lf\n",a[i].s);
			if(a[i].s>max){
				f=i;
				max=a[i].s;
			}
		}
		printf("%d\n",a[f].b);
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define pb push_back
const int maxn = 10000;
const int INF32 = 1'050'000'000;
const long long INF64 = 4'000'000'000'000'000'000;
const int MOD7 = 1'000'000'007;
const int MOD9 = 1'000'000'009;
const int mod = MOD7;

void ERROR(int num) { cout << "ERROR" << num << endl; }
ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
int dx[8]={-1,0,1,0,1,1,-1,-1};
int dy[8]={0,-1,0,1,1,-1,1,-1};

int is_prime(int n){
  if(n <= 1)
    return 0;
  int m = floor(sqrt(n) + 0.5);
  for(int i = 2; i < m; i++){
    if(n % i == 0)
      return 0;
  }
  return 1;
}

vector<pair<long long, long long> > prime_factorize(long long N) {
    vector<pair<long long, long long> > res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0; // 指数
        // 割れる限り割り続ける
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        // その結果を push
        res.push_back({a, ex});
    }
    // 最後に残った数について
    if (N != 1) res.push_back({N, 1});
    return res;
}

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

    ll A, B;
    cin >> A >> B;

    ll num = gcd(A,B);
    auto res  = prime_factorize(num);
    cout << res.size()+1 << endl;
}

Measured memory_bytes: 256
use std::process::exit;
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        n: usize,
        v: [u64; n],
    }

    if v.contains(&0) {
        println!("{}", 0);
        exit(0)
    }

    let mut ans: u64 = 1;
    for i in v {
        if ans.checked_mul(i) == None {
            println!("{}", -1);
            exit(0)
        }
        ans *= i
    }

    if ans > 1000000000000000000 as u64 {
        println!("{}", -1)
    } else {
        println!("{}", ans)
    }
}


Measured memory_bytes: 4784
line = input().split(' ')
N,M = int(line[0]),int(line[1])
A = []
B = []
exe = 0
for i in range(N):
  A.append(input())
for i in range(M):
  B.append(input())
for i in range(N-M+1):
  f = 0
  for j in range(N-M+1):
    if A[i][j:j+M] == B[0]:
      f = 1
      for k in range(M):
        if not A[i+k][j:j+M] == B[k]:
          f = 0
          break
    if f == 1:
      exe = 1
if exe == 0:
  print("No")
else:
  print("Yes")


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

int main(){
   int a,b,c,d,p;
   cin>>a>>b>>c>>d>>p;
   int mizu1,mizu2,tuika;
   tuika =0;
   mizu1 = a*p;
   if(p <= c){
      mizu2 = b;
   } else {
      for(int x=0;x < p-c;x++){
         tuika += d;
      }
      mizu2 = b + tuika;
   }
   if(mizu1 <= mizu2){
      cout<<mizu1<<endl;
   } else {
      cout<<mizu2<<endl;
   }
   return 0;
}


Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);
#define dbg(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;


int main()
{
    FASTIO
    /*
    //double start_time = clock();
#ifndef ONLINE_JUDGE
    freopen("in.txt", "r", stdin);
    freopen("out.txt", "w", stdout);
    freopen("error.txt", "w", stderr);
#endif
//*/
    int T;
    //cin >> T;
    T = 1;
    for (int cs = 1; cs <= T; cs++) {
        int a, b;
        cin >> a  >> b;
        if ((a + b) & 1) cout << "IMPOSSIBLE\n";
        else cout << (a + b) / 2 << endl;
    }

    //double end_time = clock();
    //printf( "Time = %lf ms\n", ( (end_time - start_time) / CLOCKS_PER_SEC)*1000);
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdbool.h>

int main(void) {
	
	bool C = false;
	bool F = false;
	char s[101];
	scanf("%s", s);
	char *p = s;
	while(*p!=0){
		if(*p=='C')
		{
			C = true;
			break;
		}
                p++;
	}
	while(*p!=0){
		if(*p=='F')
		{
			F = true;
			break;
		}
                p++;
	}
	if(!C || !F) printf("No");
	else printf("Yes");
	
	return 0;
}


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

int main()
{
  string s;
  cin >> s;
  
  int app[27] = {0};
  int n = s.size();
  rep(i,n){
    app[s[i] - 'a']++;
  }
  
  rep(i,27){
    if(app[i] % 2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  
  cout << "Yes" << endl;
}

Measured memory_bytes: 3536
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	int a, b, n;
	cin >> a >> b >> n;
	if (!cin) return false;

	vi v1(a), v2(b); 
	int mina = 10000000, minb = 100000000;
	for (int i = 0; i < a; ++i) {
		cin >> v1[i];
		mina = min(v1[i], mina);
	}
	for (int i = 0; i < b; ++i) {
		cin >> v2[i];
		minb = min(v2[i], minb);
	}

	int sol = mina + minb;

	for (int i = 0; i < n; ++i) {
		int ini, fin, d;
		cin >> ini >> fin >> d;
		--ini; --fin;
		sol = min(sol, v1[ini] + v2[fin] - d);
	}

	cout << sol << '\n';

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

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

int main()
{
  int a;
  rep(i, 5){
    cin >> a;
    if (a == 0) {
      cout << i + 1 << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3552
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>

using ull = unsigned long long;
using ll = long long;
using namespace std;

const ll M = 1000000007;

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

    vector<ll> a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        a[i] %= M;
    }

    vector<ll> b(n, 0);
    b[n-1] = a[n-1];


    for(int bi = 1; bi < n; ++bi) {
        b[(n-1)-bi] = (b[(n-1)-bi+1] + a[(n-1)-bi])%M;
    }
    // for(int bi = 0; bi < n; ++ bi){
    //     cout << b[bi] << " ";
    // }
    // cout << endl;

    ll ans = 0;
    for (int i = 0; i < n-1; ++i) {
        ans += (a[i]*b[i+1])%M;
        // cout << a[i] << "*" << b[i+1] << endl;
    }

    cout << ans%M << endl;
    return 0;
}

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

using namespace std;


int main() {
	long long int N;
	cin >> N;
	vector<bool>dp( 100 * 100 + 1 );
	dp[0] = true;
	for( size_t i = 0; i < N; i++ ) {
		long long int s;
		cin >> s;
		for( long long int j = 100 * 100 - s; j >= 0; j-- ) {
			dp[j + s] = dp[j + s] | dp[j];
		}
	}
	long long int ans = 0;
	for( size_t i = 0; i < 100 * 100 + 1; i++ ) {
		if( i % 10 != 0 && dp[i] ) {
			ans = i;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
//
// Created by Aditya Bhadoo on 19/08/20.
//
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    
    int cnt=0;

    for(int i=0;i<n-2;i++){
        int curr=arr[i];
        for(int j=i+1;j<n-1;j++){
            for(int c=j+1;c<n;c++){
                if(arr[i]+arr[j]>arr[c] && arr[c]+arr[j]>arr[i] && arr[i]+arr[c]>arr[j] &&(arr[i]!=arr[j] && arr[j]!=arr[c] && arr[c]!=arr[i]))
                    cnt++;
            }
        }
    }
    if(n<3){
        cout<<0;
    }else{
        cout<<cnt;    
    }
    
    return 0;
}



Measured memory_bytes: 3624
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using LL = long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VVLL = vector<VLL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;
#define REP(i,m,n) for(LL i=(m);i<(n);i++)
	//i=m -> n

int main(){
  LL n,ans=0;
  cin >> n;
  VLL a(n,0),sum(n+1,0);
  sum[n] = 0;
  REP(i,0,n){
    cin >> a[i];
  }
  for(LL i=n-1; i>=0; i--){
    sum[i] = sum[i+1] + a[i];//a[i]以降の和
    sum[i] %= 1000000007;
  }
  
  REP(i,0,n-1){
    ans += a[i]*sum[i+1];
    ans %= 1000000007;
  }
  
  
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 6420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define RI(a) scanf("%d",&a)
#define RII(a,b) scanf("%d%d",&a,&b)
#define RIII(a,b,c) scanf("%d%d%d",&a,&b,&c)
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define F first
#define S second
#define REP(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
//}}}
const ll maxn=80005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=2000000000;

int t[maxn];
int v[maxn];

int T=0;

int s[maxn];
int main()
{
	REP(i,maxn) s[i]=INF;
	
	
	int n;
	cin>>n;
	REP(i,n) cin>>t[i+1];
	REP(i,n) cin>>v[i+1];
	v[n+1]=0,t[n+1]=0;
	v[0]=0,t[0]=0;
	int cur=0;
	
	
	for(int i=0;i<=n+1;i++){
		for(int j=0;j<maxn;j++){
			if(j<=cur*2){
				s[j]=min(s[j],2*v[i]+(2*cur-j));
			}
			else if(j>=2*(cur+t[i])){
				s[j]=min(s[j],2*v[i]+(j-2*cur-2*t[i]));
			}
			else s[j]=min(s[j],2*v[i]);
		}
		cur+=t[i];
	}
	
	REP(i,n) T+=t[i+1];
	//cout<<T<<'\n';
	int ans=0;
	for(int i=0;i<2*T;i++){
		//cout<<s[i]<<' ';
		ans+=s[i]+s[i+1];
	}
	cout<<fixed<<setprecision(6)<<0.125*ans;
	return 0;
}












Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, m) for (int i = 0; i < (int)(m); i++)
const int inf = 1000000000; // 10^9 Ten to the power of nine.



int main()
{
    string s[1000000]; char ans[1000000];
	int n,a,b,c;cin>>n>>a>>b>>c;
	for(int i=1;i<=n;i++)
	cin>>s[i];
	for(int i=1;i<=n;i++)
	{
		if(s[i]=="AB"){
			if(a==0&&b==0){
				printf("No\n");
				return 0;
			}
			if(a>b)a--,b++,ans[i]='B';
			else if(a<b)a++,b--,ans[i]='A';
			else{
				if(s[i+1]=="BC")a--,b++,ans[i]='B';
				else a++,b--,ans[i]='A';
			}
		}
		if(s[i]=="BC"){
			if(c==0&&b==0){
				printf("No\n");
				return 0;
			}
			if(c>b)c--,b++,ans[i]='B';
			else if(c<b)c++,b--,ans[i]='C';
			else{
				if(s[i+1]=="AB")c--,b++,ans[i]='B';
				else c++,b--,ans[i]='C';
			}
		}
		if(s[i]=="AC"){
			if(a==0&&c==0){
				printf("No\n");
				return 0;
			}
			if(a>c)a--,c++,ans[i]='C';
			else if(a<c)a++,c--,ans[i]='A';
			else{
				if(s[i+1]=="BC")a--,c++,ans[i]='C';
				else a++,c--,ans[i]='A';
			}
		}
	}
	printf("Yes\n");
	for(int i=1;i<=n;i++)
	printf("%c\n",ans[i]);
}

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

int main(){
    string s;
    cin >> s;
    int c1 = 0;
    int c2 = 0;
    for (int i=0; i < s.length(); i++){
        if (s[i] == 'A') {
            c1 = i;
            break;
        }
    }
    for (int i=s.length()-1; i >=0; i--){
        if (s[i] == 'Z'){
            c2 = i;
            break;
        }
    }
    cout << c2 - c1 + 1<< endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
using namespace std;
using ll = long long ;
using P = pair<int,int> ;
using pll = pair<long long,long long>;
constexpr int INF = 1e9;
constexpr long long LINF = 1e17;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;

int main(){
    ll n,p;
    cin >> n >> p;
    ll ans = 1;
    for(ll i=2;i*i<=p;i++){
        if(p%i==0){
            int c = 0;
            while(p%i==0){
                p /= i;
                ++c;
            }
            int k = c/n;
            rep(j,k) ans *= i;
        }
    }
    if(p > 1 && n == 1){
        ans *= p;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		string[] str = Console.ReadLine().Split();
		int H = int.Parse(str[0]);
		int W = int.Parse(str[1]);
		string[] str2 = Console.ReadLine().Split();
		int h = int.Parse(str2[0]);
		int w = int.Parse(str2[1]);
		Console.WriteLine((H-h)*(W-w));
	}
}

Measured memory_bytes: 13140
#include <stdio.h>

int main(void)
{
	int i=0,x=0;
	char sip[100];
	char sck[6] = {'a','i','u','e','o','\0'};
	scanf("%100s",sip);
	for(i;i <= 4;i++)
		{
			if(sip[0] != sck[i]){x=0;}
	 		else{x=1;}
	 	 if(x == 1){break;}
		}
	if(x == 1)
	{
		printf("vowel\n");
	}
	else
	{
		printf("consonant\n");
	}
	return 0;
}


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

		

int main(){
	ll l,r;
	cin >> l >> r;
	int ans=2020;
	if(r-l >= 2018){
		ans=0; 
	}else{
		for(int i=l; i<=r-1; i++){
			for(int j=i+1; j<=r; j++){
				ans = min(ans, ((i%2019)*(j%2019))%2019);
			}
		}
	}
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int t;
    scanf("%d",&t);
    int a;
    int b;
    int c;
    int count = 0;
    deque< int > p;
    for(int i=0; i<t; i++)
    {
        scanf("%d",&a);
        if(a == 0)
        {
            scanf("%d",&b);
            if(b == 0)
            {
                scanf("%d",&c);
                p.push_front(c);
                count++;
            }
            else
            {
                scanf("%d",&c);
                p.push_back(c);
                count++;
            }
        }
        else if(a == 1)
        {
            scanf("%d",&b);
            cout << p[b] << endl;
        }
        else
        {
            scanf("%d",&b);
            count--;
            if(b == 0) p.erase(p.begin());
            else p.erase(p.begin()+count);
        }
    }
}



Measured memory_bytes: 4640
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

class UnionFind {
private:
	vector<int> data;

public:
	int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }

	UnionFind(int size) : data(size, -1) { }
	bool is_same(int x, int y) { return root(x) == root(y); }
	lint size(int x) { return -data[root(x)]; }

	void unify(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
};


int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N, M;
	cin >> N >> M;

	UnionFind UF(N);
	int X, Y, Z;
	for (int i = 0; i < M; i++){
		cin >> X >> Y >> Z;

		UF.unify(X - 1, Y - 1);

	}

	int ans = 0;;
	for (size_t i = 0; i < N; i++){
		ans += UF.root(i) == i;
    }

	cout << ans << "\n";

	return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>
int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
	
	int H, N;  cin >> H >> N;
	int sum = 0;
	for(int i = 0 ; i < N ; i++){
			int A;  cin >> A;
			sum += A;
	}

	if(H <= sum)  cout << "Yes" << endl;
	else        cout << "No" << endl;

	return 0;
}


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

#define ARG4(_1, _2, _3, _4, ...) _4
#define rep(...) ARG4(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define REP(i, a) FOR(i, 0, a)
#define FOR(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(...) ARG4(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define RREP(i, a) RFOR(i, 0, a)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (int)(a); --i)
#define ALL(c) (c).begin(), (c).end()
#define TEN(n) ((ll)(1e##n))
#define pb emplace_back
#define mp make_pair
#define fi first
#define se second
#define let const auto
#define USE_T template <typename T>
#define USE_Ti template <typename T = int>
#define USE_TU template <typename T, typename U>

USE_T using duo = std::pair<T, T>;
USE_T using vec = std::vector<T>;
using ll = long long;
// clang-format off
USE_TU inline bool chmax(T&x,U a){return x<a&&(x=a,1);}
USE_TU inline bool chmin(T&x,U a){return a<x&&(x=a,1);}
USE_Ti inline T in(){T x;std::cin>>x;return x;}
USE_Ti inline vec<T> in(int n){vec<T> v;v.reserve(n);rep(i,n)v.pb(in<T>());return v;}
USE_T inline void in(T*x,int n){rep(i,n)x[i]=in<T>();}
struct IoSetup {
  IoSetup(){
    using namespace std;
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout<<setprecision(10);
    cerr<<setprecision(10);
  }
} iosetup;
// clang-format on
// }}}
using namespace std;
const int inf = 1001001001;
const ll infll = 1001001001001001001ll;
const int dd[] = {0, 1, 0, -1, 0};

using Tree = vec<vec<int>>;
struct DistHelper {
  const Tree& tree;
  const int dist;
  DistHelper(const Tree& tree, int diameter) : tree(tree), dist(diameter / 2) {}
  int count(int v, int p = -1, int d = 0) const {
    int r = d > dist;
    for (int u : tree[v]) {
      if (u == p) continue;
      r += count(u, v, d + 1);
    }
    return r;
  }
};

signed main() {
  int N = in(), K = in();
  Tree tree(N);
  REP(i, N - 1) {
    int A = in() - 1, B = in() - 1;
    tree[A].pb(B);
    tree[B].pb(A);
  }
  DistHelper helper{tree, K};
  int mini = N;
  if (K % 2 == 0) {
    REP(v, N) { chmin(mini, helper.count(v)); }
  } else {
    REP(v, N) {
      for (int u : tree[v]) {
        chmin(mini, helper.count(v, u, 0) + helper.count(u, v, 0));
      }
    }
  }
  cout << mini << endl;
  return 0;
}


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

main(){
	int a[6],z[4];
	for(int i=0;i<4;i++){
		z[i]=0;
	}
	for(int i=0;i<6;i++){
		cin >> a[i];
		z[a[i]-1]++;
	}
	bool flag=true;
	for(int i=0;i<4;i++){
		if(z[i]<1 || 2<z[i]){
			flag=false;
		}
	}
	if(flag==true){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#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() {
    int n;
    cin >> n;
    vector<int> v = {1,2,4,8,16,32,64};
    cout << *prev(upper_bound(v.begin(), v.end(), n)) << endl;
}

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

int pass_cnt(vector<set<int>> &hen,int N,vector<bool> checked,int tmp,int cnt){
    if(checked.at(tmp)) return 0;

    if(cnt == N) return 1;

    checked.at(tmp) = true;
    cnt++;
    int res =0;
    for(int next:hen.at(tmp)){
        res += pass_cnt(hen,N,checked,next,cnt);
    }
    return res;
}

int solve(vector<set<int>> &hen,int N){
    vector<bool> checked(N+1,0);

    return pass_cnt(hen,N,checked,1,1);
}

int main(){
    int N,M;
    cin >> N >> M;
    vector<set<int>> hen(N+1);
    int a,b;
    rep(i,M){
        cin >> a >> b;
        hen.at(a).insert(b);
        hen.at(b).insert(a);
    }
    cout << solve(hen,N) << endl;
}   

Measured memory_bytes: 256
N, M = map(int, input().split())
flag = [0]*N
ball = [1]*N
flag[0] = 1
for _ in range(M):
    x, y = map(int, input().split())
    ball[x-1] -= 1
    ball[y-1] += 1
    if flag[x-1] == 1:
        flag[y-1] = 1
    if ball[x-1] == 0:
        flag[x-1] = 0
print(sum(flag))


Measured memory_bytes: 4596
#include<stdio.h>
int main(){
  long int N,A,B,i,j;
  scanf("%ld %ld %ld",&N,&A,&B);
  j=N/(A+B);
  i=j*A;
  if(N%(A+B)>=A)
    i=i+A;
  else
    i=i+N%(A+B);
  printf("%ld\n",i);
}
    

Measured memory_bytes: 128
#include <iostream>
#include<cmath>
#include <vector>
#include <map>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <string>
#include <math.h>
#include <set>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
 
int main() {
    ios::sync_with_stdio(false);
	int n, k;
	cin >> n >> k;
	int p[n];
	for (int i = 0 ; i < n ; i++) cin >> p[i];
	sort(p, p + n);
	ll x = 0;
	for (int i = 0 ; i < k ; i++) x += p[i];
	cout << x;
}


Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;++i)
#define all(v) v.begin(), v.end()
typedef long long int ll;
typedef unsigned long long ull;
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;}
typedef pair<ll,ll> P;
const long long MOD = 1e9+7;
const ll INF = 1LL << 60;

int main(){

    while(true){
        int x,y;
        cin >> x >> y;
        if(x == 0 && y == 0){
            return 0;
        }else{
          if(x <= y){
              cout << x << " " << y << endl;
          }else{
              cout << y << " " << x << endl;
          }
        }





    }




}


Measured memory_bytes: 3008
/*
ID: yzshang1
LANG: C++11
TASK:
*/
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define pb push_back
#define mp make_pair
#define lsh(i) (1 << (i))
#define lshll(i) (1LL << (i))
#define repn(i, n) for (int (i) = 1; (i) <= (int)n; (i)++)
#define rep(i, n) for (int (i) = 0; (i) < (int)n; (i)++)
const int INF = 0x3f3f3f3f;
const long double EPS = 1e-6;
const int N = 10010;
int dp[10010], a[N], b[N], h, n;
int main() {
	cin >> h >> n;
	repn(i, n) cin >> a[i] >> b[i];
	memset(dp, INF, sizeof(dp));
	dp[0] = 0;
	rep(i, h + 1)
		repn(j, n)
			dp[i] = min(dp[i], dp[max(i - a[j], 0)] + b[j]);
	cout << dp[h] << endl;
	return 0;
}


Measured memory_bytes: 256