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

template<typename T>
class queue {
public:
    explicit
    queue(int size) : size_(size), head_(0), tail_(0), data_(std::make_unique<T[]>(size)) {}

    void enqueue(T x) {
        data_[tail_] = x;
        tail_ = (tail_ + 1) % size_;
    }

    T dequeue() {
        auto x = data_[head_];
        head_ = (head_ + 1) % size_;
        return x;
    }

    bool is_empty() {
        return head_ == tail_;
    }

    bool is_full() {
        return tail_ == size_;
    }

private:
    int size_;
    int head_;
    int tail_;
    std::unique_ptr<T[]> data_;
};

struct proc {
    proc() : name_(""), value_(0) {}

    std::string name_;
    int value_;
};

int main() {
    int n, q;
    std::cin >> n >> q;
    queue<proc> proc_q(n + 1);
    for (int i = 0; i < n; ++i) {
        proc p;
        std::cin >> p.name_ >> p.value_;
        proc_q.enqueue(p);
    }

    int elapsed_time = 0;
    while (true) {
        auto p = proc_q.dequeue();
        if (p.value_ > 0) {
            elapsed_time += std::min(p.value_, q);
            p.value_ = std::max(p.value_ - q, 0);
            if (p.value_ == 0) {
                std::cout << p.name_ << " " << elapsed_time << std::endl;
            }
            else {
                proc_q.enqueue(p);
            }
        }

        if (proc_q.is_empty()) {
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 6096
#include <algorithm>
#include <climits>
#include <iostream>
#include <string>
#include <utility>
#include<vector>
#include<iomanip>
#include<map>
#include <queue>
#include<cmath>
#include<cstdio>
#include<iomanip>
#include<set>
#include <bits/stdc++.h>
 
using namespace std;
using ll = long long int;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++) //REP(i, 5) cout<<i;
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define MOD 1000000007 //10^9+7
//#define MOD 1
 
ll gcd(ll a, ll b) {
  ll tmp;
  if ( b > a) {
    tmp = a;
    a = b;
    b = tmp;
  }
  while (a % b !=0) {
    tmp = b;
    b = a % b;
    a = tmp;
  }
  return b;
}
 
const int MAX = 2000;

long long fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int 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;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}


void sosuu(ll n, vector<ll> &v){

  vector<ll> num(n, 0);

  FOR(i, 1, sqrt(n)){
    if(num[i]==0){
      FOR(j, 0, n/i){
        num[i+(j*i)] = 1;
      }
    }
  }
  REP(i, n){
    if(num[i]==0) v.push_back(i+1);
  }
}


int main(void){

  ll n;
  cin>>n;
  ll ans = 0;
  vector<ll> v1(n);
  vector<ll> v2(n);
  ll sum1 = 0;
  ll sum2 = 0;

  REP(i, n){
    ll x;
    cin>>x;
    v1[i] = x;
  }
  REP(i, n){
    ll x;
    cin>>x;
    v2[i] = x;
    sum2 += x;
  }

  REP(i, n){
    ll calc = 0;
    sum1 += v1[i];
    sum2 -= v2[i];
    calc = sum1 + sum2 + v2[i];
    ans = max(calc, ans);
  }

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

Measured memory_bytes: 256
#include <bits/stdc++.h> 
#define INF INT_MAX/2;
#define MOD 1000000007

using namespace std;

using ll = long long;
using ull = unsigned long long ;

vector<ll>x;

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

   int x1,y1,x2,y2,x3,y3,x4,y4;
   cin>>x1>>y1>>x2>>y2;

   x2-=x1;
   y2-=y1;
   x4=-y2;
   y4=x2;

   x2+=x1;
   y2+=y1;
   x4+=x1;
   y4+=y1;

   x1-=x2;
   y1-=y2;
   x3=y1;
   y3=-x1;

   x3+=x2;
   y3+=y2;
   cout<<x3<<" "<<y3<<" "<<x4<<" "<<y4;
   return 0; 
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<vector>
#define LL long long
#define PI pair<LL,LL>
using namespace std;
LL D,St1[25],St2[25],P[25];
vector<LL>V;
void DFS(LL L,LL R,vector<PI>& Rec,LL Val,LL Cnt){
	if(L==R){
		Rec.push_back(PI(Val,Cnt));
		return; 
	}
	for(LL I=-9;I<=9;I++) DFS(L+1,R,Rec,Val+I*V[L],Cnt*(L==0?St2[I+10]:St1[I+10]));
}
LL Solve(LL Len){
	V.clear();
	for(LL I=0;Len-I-1>I;++I) V.push_back(P[Len-I-1]-P[I]);
	vector<PI>An1,An2;
	LL Res=0;
	DFS(0,(V.size()+1)/2,An1,0,1);
	DFS((V.size()+1)/2,V.size(),An2,0,1);
	map<LL,LL>Mp;  
	for(LL I=0;I<An2.size();I++) Mp[An2[I].first]+=An2[I].second;
	for(LL I=0;I<An1.size();I++) Res+=Mp[D+An1[I].first]*An1[I].second;
	if(Len&1) Res*=10;
	return Res;
}
int main(){
    scanf("%lld",&D);
    P[0]=1;
    for(LL I=1;I<=18;I++) P[I]=P[I-1]*10;
    for(LL I=0;I<=9;I++)
    	for(LL J=0;J<=9;J++){
    		St1[I-J+10]++;
			if(I) St2[I-J+10]++;	
		}
	LL Ans=0;
	for(LL I=1;I<=18;I++) Ans+=Solve(I);
	printf("%lld",Ans);
	return 0;
}


Measured memory_bytes: 207052
import java.util.Scanner;

/**
 * コッホ曲線
 * @author nobu
 * @see <a href="http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=ALDS1_5_C&lang=ja">ALDS1_5_C</a>
 */
public class Main {

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

		Point a = new Point();
		Point b = new Point();

		a.x = 0;
		a.y = 0;
		b.x = 100;
		b.y = 0;

		System.out.println(a.x + " " + a.y);
		koch(n, a, b);
		System.out.println(b.x + " " + b.y);


		sc.close();
	}

	private static void koch(int n, Point a, Point b) {
		if (n == 0) return;

		Point s = new Point();
		Point t = new Point();
		Point u = new Point();

		// 度からラジアンへ単位を変換
		double th = Math.PI * 60.0 / 180.0;

		s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
		s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
		t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
		t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
		u.x = (t.x - s.x) * Math.cos(th) - (t.y - s.y)* Math.sin(th) + s.x;
		u.y = (t.x - s.x) * Math.sin(th) + (t.y - s.y)* Math.cos(th) + s.y;

		koch(n - 1, a, s);
		System.out.println(s.x + " " + s.y);
		koch(n - 1, s, u);
		System.out.println(u.x + " " + u.y);
		koch(n - 1, u, t);
		System.out.println(t.x + " " + t.y);
		koch(n - 1, t, b);

	}

}

class Point {
	double x, y;
}



Measured memory_bytes: 32292
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream> 
#include<unordered_map>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

const int inf = numeric_limits<int>::max() >> 2;
const ll linf = numeric_limits<ll>::max() >> 2;
const ull ulinf = numeric_limits<ull>::max() >> 2;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define umap(i,j) unordered_map<i,j>
#define P(p) cout<<(p)<<endl
#define PS(p) cout<<(p)<< " "
#define IN cin >> 
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i = (m-1); i >= (int)(n); i--)
#define inrep(n,a) for(int i = 0; i < (int)(n); i++)cin >> a[i];
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end())
#define rvsort(v) sort(v.begin(), v.end(), greater<c>()) 
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
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; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////


int main(){

    int n;
    cin >> n;
    string s;
    cin >> s;

    int l = 0, r = 0;
 
    rep(i,0,sz(s)){
	if(s[i] == '('){
	    r++;
	 
	}else{
	    r--;
	    if(r < 0){
		r = 0;
		l++;
	    }
	}
    }

    rep(i,0,l)cout << "(";
    cout << s;
    rep(i,0,r)cout << ")";
    cout << endl;
    
    return  0;
}


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

//iteration
#define rep(i,m) for(int i=0;i<(m);++i)
#define rev(i,m) for(int i=(int)(m) - 1;i>=0;--i)
#define repn(i) for(int i = 0; i < n; ++i)
#define revn(i) for(int i=(int)(n) - 1;i>=0;--i)
#define repr(i,a,b) for(int i=(a);i<(b);++i)
#define revr(i,a,b) for(int i=(int)(a)-1;i>=(b);--i)

//IO
#define newline() cout<<'\n'
#define line(s) cout<<(s)<<'\n'
#define spaced(s) cout<<(s)<<' '
#define rint(n) int n;cin>>n

#define all(x) (x).begin(),(x).end()
#define sqr(x) ((x)*(x))
#define present(c,x) ((c).find(x) != (c).end()) 

#define long long long

using namespace std;

//constants
const int inf = 1234567890;
const long infl = 8876543210123456789ll;
const int mod = 1000000007;

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

template <class RandomAccessIterator>
void print(RandomAccessIterator a, RandomAccessIterator b) {
	for (; a < b; ++a) {
		line(*a);
	}
}

template <class RandomAccessIterator>
void println(RandomAccessIterator a, RandomAccessIterator b) {
	for (; a < b; ++a) {
		spaced(*a);
	}
	newline();
}

int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
#pragma endregion

long a[5011][5011];

int main() {
	init();
	rint(n);
	string s;
	cin >> s;
	int m = s.length();
	a[0][0] = 1;
	repr(i,1,n+1) {
		a[i][0] = (a[i - 1][0] + a[i - 1][1] * 2) % mod;
		repr(j, 1, n + 1) {
			a[i][j] = (a[i - 1][j - 1] + a[i - 1][j + 1] * 2) % mod;
		}
	}
	cout << a[n][m];
}

Measured memory_bytes: 195968
#include<stdio.h>
int main()
{
    int N, M;
    scanf("%d%d", &N, &M);
    int n[50] = {0};
    int a, b;
    for(int i=0; i<M; i++){
            scanf("%d%d", &a, &b);
            n[a-1]++;
            n[b-1]++;
            }
    for(int i=0; i<N; i++){
             printf("%d\n", n[i]);
             }
    return 0;
    }

Measured memory_bytes: 128
/*
 * FileName:     C
 * CreatedDate:  2020-04-12 21:49:50 +0900
 * LastModified: 2020-04-12 21:53:18 +0900
 */

#include <stdio.h>
int gcd(int x,int y){
    int r;
    while((r=x%y)!=0){
        x=y;
        y=r;
    }
    return y;
}
int main(void){
    int n,count=0;
    scanf("%d",&n);
    for(int i=1;i<n+1;i++){
        for(int j=1;j<n+1;j++){
            for(int k=1;k<n+1;k++){
                int ngcd = gcd(i,j);
                int nngcd = gcd(ngcd,k);
                count+=nngcd;
                
            }
        }
    }
    printf("%d\n",count);
    return 0;
}


Measured memory_bytes: 1728
#include<bits/stdc++.h>
#include<vector>
#include<string>
#include<stack>
#include<iostream>
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
#define MOD 1000000007
#define vec(a) vector<int>a
using namespace std;


int main()
{
#ifndef ONLINE_JUDGE
	freopen("output.txt", "w", stdout);
	freopen("input.txt", "r", stdin);
#endif
	fastio
	ll n,b,i,j;
	cin>>n>>b;
	cout<<floor(log(n)/log(b))+1<<"\n";
	return 0;
}
	

Measured memory_bytes: 3972
n=int(input())
AB=[list(map(int,input().split())) for _ in range(n)]

cnt,A=0,[]
for a,b in AB:
    cnt -=b
    A.append(a+b)

A.sort(reverse=True)
for i in range(0,n,2):
    cnt +=A[i]
print(cnt)

Measured memory_bytes: 67288
N,M,C = map(int,input().split())
deep  = list(map(int,input().split()))
score = 0
for n in range(1,N+1):
  blue = list(map(int,input().split()))
  linear = 0
  for m in range(1,M+1):
    linear += deep[m-1] * blue[m-1]
  if linear + C > 0:
    score += 1
print(score)

Measured memory_bytes: 3060
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
char s[120];
int main()
{
	scanf("%s",s);
	if(strlen(s)>=4&&s[0]=='Y'&&s[1]=='A'&&s[2]=='K'&&s[3]=='I') printf("Yes\n");
	else printf("No\n");
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<stdio.h>
using namespace std;
int main()
{
	long long a,b;
	char op;
	scanf("%lld %c %lld",&a,&op,&b);
    if(op=='+')
	{
		printf("%lld\n",a+b);
	}
	else if(op=='-')
	{
		printf("%lld\n",a-b);
	}
	else if(op=='*')
	{
		printf("%lld\n",a*b);
	}
	else if(op=='/'&&b>1e-6)
	{
		printf("%lld\n",a/b);
	}
	return 0;
}

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

using namespace std;

using ll = long long;
using ld = long double;

using pll = pair<ll, ll>;
using vll = vector<ll>;
using vpll = vector<pll>;
using gr = vector<vll>;
using wgr = vector<vpll>;

#define pb push_back
#define FOR(i, m, n) for (ll i(m); i < n; i++)
#define DWN(i, m, n) for (ll i(m); i >= n; i--)
#define REP(i, n) FOR(i, 0, n)
#define DW(i, n) DWN(i, n, 0)
#define F(n) REP(i, n)
#define FF(n) REP(j, n)
#define D(n) DW(i, n)
#define DD(n) DW(j, n)
struct d_ {
    template<typename T> d_ & operator ,(const T & x) { cerr << ' ' <<  x; return *this;}
    template<typename T> d_ & operator ,(const vector<T> & x) { for(auto x: x) cerr << ' ' <<  x; return *this;}
} d_t;
#define dbg(args ...) { d_t,"|",__LINE__,"|",":",args,"\n"; }
#define EPS (1e-10)
#define INF (1LL<<61)
#define CL(A,I) (memset(A,I,sizeof(A)))
#define all(x) begin(x),end(x)
#define IN(n) ll n;cin >> n;
#define x first
#define y second

ll n,m;
const int N = 107;
string mx[N];
ll DP[N][N];

int main(void) {
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    F(n) cin >> mx[i];
    D(n-1)DD(m-1){
        ll a = (i+1<n ? DP[i+1][j] + (mx[i][j]=='.'&&mx[i+1][j]=='#') : INF);
        ll b = (j+1<m ? DP[i][j+1] + (mx[i][j]=='.'&&mx[i][j+1]=='#') : INF);
        DP[i][j] = min(a,b)==INF?0:min(a,b);
    }
    cout << DP[0][0]+(mx[0][0]=='#') << endl;
    return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
using namespace std;
using ll = long long;

int main() {
  int X, A, B;
  cin >> X >> A >> B;
  int res = (X - A) % B;
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<stdlib.h>
#include<vector>
#include<algorithm>
#include<utility>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<iterator>
//#include<math.h>

using namespace std;
#define int long long
/*                      */    //#undef int
#define INF 1000000009
#define INFL 1000000000000000018ll
#define mod 1000000007ll
#define pb push_back
#define fi first
#define se second
#define mk make_pair
typedef pair<int, int> PA;
typedef priority_queue<int> PQ;
typedef priority_queue<PA, vector<PA>, greater<PA> >PQG;

int N, K, x[60], y[60], ans = 9200000000000000000ll;

signed main()
{
    cin >> N >> K;
    for(int i = 0; i < N; i++){
        cin >> x[i] >> y[i];
    }
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            for(int k = 0; k < N; k++){
                for(int r = 0; r < N; r++){
                    int cnt = 0;
                    if(x[k] - x[i] < 0 || y[r] - y[j] < 0)continue;
                    for(int l = 0; l < N; l++){
                        if(x[i] <= x[l] && x[l] <= x[k] && y[j] <= y[l] && y[l] <= y[r]){
                            cnt++;
                        }
                    }
                    if(cnt >= K){
                        ans = min(ans, (x[k] - x[i]) * (y[r] - y[j]));
                    }
                }
            }
        }
    }
    cout << ans << endl;


    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);
        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int cnt = 0;
        if (a == b && b == c) {
            if (a % 2 == 1) {
                System.out.println(0);
                return;
            }
            System.out.println(-1);
            return;
        }
        while (true) {
            if (a % 2 == 1 || b % 2 == 1 || c % 2 == 1) {
                break;
            }
            int atmp = a;
            int btmp = b;
            int ctmp = c;
            a = (btmp + ctmp) / 2;
            b = (atmp + ctmp) / 2;
            c = (atmp + btmp) / 2;
            cnt++;
        }
        System.out.println(cnt);
    }
}


Measured memory_bytes: 21844
import sys

s = input()
p = input()

s_len = len(s)
p_len = len(p)
cur_s_pos = 0
cur_p_pos = 0

for i in range(s_len):
    if s[i] == p[0]:
        cur_s_pos = i
        cur_p_pos = 0
        #print("比較：%s %s" % (s[cur_s_pos], p[cur_p_pos]))
        try:
            for j in range(100):
                if s[cur_s_pos] == p[cur_p_pos]:
                    cur_s_pos += 1
                    cur_p_pos += 1
                else:
                    break

                if cur_p_pos == p_len:
                    break

                if cur_s_pos >= s_len:
                    cur_s_pos = 0
        except IndexError:
            print("s_pos, p_pos : %d, %d" % (cur_s_pos, cur_p_pos))
            sys.exit()

        if cur_p_pos == p_len:
            break

        

if cur_p_pos == p_len:
    print("Yes")
else:
    print("No")



Measured memory_bytes: 5568
N = int(input())
L = list(map(int, input().split()))
L.sort()

ans = 0

for i in range(N-2):
	for j in range(i,N-1):
		for k in range(j,N):
			if L[i] + L[j] > L[k] and L[i]!=L[j] and L[j]!=L[k]:
				ans += 1

print(ans)


Measured memory_bytes: 9164
#include<stdio.h>

int dp[50];

int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}


int main(){
  int n, i;
  for(i = 0 ; i < 50 ; i++) dp[i] = -1;

  scanf("%d", &n);
  printf("%d\n", fib(n));

  return 0;
}


Measured memory_bytes: 2104
import sys
input=sys.stdin.readline
n = int(input())
lis = []
lis.append(input()[:-1])
ans = 0
for i in range(n-1):
    word = input()[:-1]
    if word in lis:
        ans += 1
    if word[0] != lis[-1][-1]:
        ans += 2
    lis.append(word)
if ans == 0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii              pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define pw(b,p)         pow(b,p) + 0.1
#define __              ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define rep(i,a,b) 		for(int i=a;i<b;i++)
#define repb(i,a,b) 	for(int i=a;i>=b;i--)
#define endl			"\n"
#define m(a)		    memset(a,0,sizeof(a))
#define all(x)                          begin(x), end(x)

void fastscan(int &x){
bool neg = false;register int c;
x = 0;c = getchar();
if(c=='-'){neg = true;c = getchar();}
for(; (c>47 && c<58); c=getchar()){x = x *10 + c - 48;}
if(neg){x *= -1;}}

void file(){
	#ifndef ONLINE_JUDGE
	freopen("in.txt" , "r" , stdin);
	freopen("out.txt" , "w" , stdout);
	#endif
}

int bs(int a[] , int s , int e, int x){
	if(s<=e){
		int m = (s+e)/2;
		if(a[m]==x)
			return m;
		else if(a[m] > x)
			return bs(a,s,m-1,x);
		else return bs(a,m+1,e,x);
	}
	return -1;
}

#define tr(x) cout<<x<<endl;
#define tr2(x,y) cout<<x<<" "<<y<<endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(w,x,y,z) cout<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr5(v,w,x,y,z) cout<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;
#define tr6(u,v,w,x,y,z) cout<<u<<" "<<v<<" "<<w<<" "<<x<<" "<<y<<" "<<z<<endl;

#define deb(x) cout<<#x<<"="<<x<<endl
#define deb2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<endl
#define deb3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<endl

#define sd(x) cin >> x;
#define sd2(x,y) cin >> x >> y;
#define sd3(x,y,z) cin >> x >> y >> z;
#define sd4(w,x,y,z) cin >> w >> x >> y >> z;

bool is_pal(string s) {return equal(all(s), s.rbegin());}

int mypow(int a, int b){        //(logn) fast exponentiation
    int res = 1;            // call int x = mypow(2,5);
    while (b > 0) {
        if (b & 1)
            res = (res * a)%mod;
        a = (a * a)%mod;
        b >>= 1;
    }
    return (res%mod);
}	

int32_t main(){	
	__;
	file();
	int n; sd(n);
	if(n%1000){
		cout << 1000-(n%1000) << endl;
	}
	else{
		cout << 0 << endl;
	}
	return 0;
}






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

int main() {
	string w;

	cin >> w;
	vector<int> hash(26);
	int n = w.length();

	for (int i=0; i<n; i++) {
		hash[w[i]-'a']++;
	}

	bool flag = true;
	for (int i=0; i<26; i++) {
		if (hash[i]%2 == 1) {
			flag = false;
			break;
		}
	}
	if (flag)
		cout << "Yes";
	else
		cout << "No";
}

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

int main() {
	int A, B; cin >> A >> B;
	if (A > 8 || B > 8) {
		cout << ":(" << endl;
		return 0;
	}
	cout << "Yay!" << endl;
}

Measured memory_bytes: 256
N = int(input())
A = [int(i) for i in input().split(" ")]
flag = False
cnt = 0
for i in range(1,N-1):
    if A[i-1]>A[i]:
        if A[i+1]<A[i]:
            flag = True
    else:
        if A[i+1]>A[i]:
            flag = True
    if flag:
        cnt+=1
        flag = False
print(cnt)

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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;

int main() {
    string S, T;
    cin >> S >> T;
    T.pop_back();
    if(S == T) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 3612
from collections import deque
def resolve():
    drc4 = [(0, 1), (0, -1), (-1, 0), (1, 0)]
    warp = [(i, j) for i in range(-2, 3) for j in range(-2, 3) if (i, j) not in [(0, 0)] + drc4]

    H, W = map(int, input().split())
    sy, sx = map(lambda x: int(x) - 1, input().split())
    gy, gx = map(lambda x: int(x) - 1, input().split())
    G = [input() for _ in range(H)]

    INF = 10 ** 12
    dist = [[INF] * W for _ in range(H)]

    q = deque()
    q.append((sy, sx))
    dist[sy][sx] = 0
    cnt = 0
    while True:
        next_warp = []
        while q:
            sy, sx = q.popleft()
            next_warp.append((sy, sx))
            for dy, dx in drc4:
                ny = dy + sy
                nx = dx + sx
                if 0 <= ny < H and 0 <= nx < W and G[ny][nx] == "." and dist[ny][nx] == INF:
                    dist[ny][nx] = cnt
                    q.append((ny, nx))

        for sy, sx in next_warp:
            for dy8, dx8 in warp:
                ny8 = dy8 + sy
                nx8 = dx8 + sx
                if 0 <= ny8 < H and 0 <= nx8 < W and G[ny8][nx8] == "." and dist[ny8][nx8] == INF:
                    dist[ny8][nx8] = cnt + 1
                    q.append((ny8, nx8))

        if not q or dist[gy][gx] != INF:
            break
        cnt += 1

    ans = dist[gy][gx] if dist[gy][gx] != INF else -1
    print(ans)


if __name__ == "__main__":
    resolve()

Measured memory_bytes: 93868
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define debug(x) cerr << "[debug] " << #x << ": " << x << endl;
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << endl;
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

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;
}

signed main() {
  init();
  ll N;
  cin >> N;
  ll ans = 1;
  rep(i, N) {
    ll a;
    cin >> a;
    ans = lcm(a, ans);
  }
  COUT(ans);
  return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<cstring>
#include<vector>
#include<set>
#include<list>
#include<queue>
#include<cmath>
#include<functional>
#include<algorithm>
#define INF (1<<30)
#define rep(i,n) for(int i=0;i<n;i++)
#define EPS 1e-6
using namespace std;

struct KYOJU{
	int a,b;
	bool operator<(const KYOJU &A)const{return a<A.a;}
};
int N,M;

int main(){
	KYOJU k[100];
	int seg=1;
	int max,count=0;
	string ans;
	cin>>N>>M;
	rep(i,M)cin>>k[i].a>>k[i].b;
	while(seg<=N){
		max=-1;
		rep(i,M){
			if(k[i].a<=seg && seg<=k[i].b &&max<k[i].b)
				max=k[i].b;
		}
		seg=max+1;
		if(max==-1){
			cout<<"Impossible\n";
			return 0;
		}
		count++;
	}
	cout<<count<<endl;
	return 0;
}

Measured memory_bytes: 0
N = int(input())
S =input()

def F(S,M): #output: count:: not in S
    if M ==1:
        ans = 0
        for i in range(10):
            if str(i) in S:
                continue
            else:
                ans +=1
        return ans
    ans = 0
    for i in range(10):
        for j in range(len(S)):
            if i == int(S[j]):
                ans += F(S[j+1:], M-1)
                break
        else:
            ans += 10**(M-1)
    return ans
    
ans = F(S,3)


print(10**3 - ans)

    

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

public class Main {
	static final StdIn in = new StdIn();
	static final PrintWriter out = new PrintWriter(System.out);
	
	public static void main(String[] args) {
		int n=in.nextInt(), k=in.nextInt();
		long a1=0, a2=0;
		for(int i=1; i<=n; ++i) {
			if(i%k==0)
				++a1;
			if(k%2==0&&i%k==k/2)
				++a2;
		}
		out.println(a1*a1*a1+a2*a2*a2);
		out.close();
	}
	
	static class StdIn {
		final private int BUFFER_SIZE = 1 << 16;
		private DataInputStream din;
		private byte[] buffer;
		private int bufferPointer, bytesRead;
		public StdIn() {
			din = new DataInputStream(System.in);
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}
		public StdIn(InputStream in) {
			try{
				din = new DataInputStream(in);
			} catch(Exception e) {
				throw new RuntimeException();
			}
			buffer = new byte[BUFFER_SIZE];
			bufferPointer = bytesRead = 0;
		}
		public String next() {
			int c;
			while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
			StringBuilder s = new StringBuilder();
			while (c != -1)
			{
				if (c == ' ' || c == '\n'||c=='\r')
					break;
				s.append((char)c);
				c=read();
			}
			return s.toString();
		}
		public String nextLine() {
			int c;
			while((c=read())!=-1&&(c==' '||c=='\n'||c=='\r'));
			StringBuilder s = new StringBuilder();
			while (c != -1)
			{
				if (c == '\n'||c=='\r')
					break;
				s.append((char)c);
				c = read();
			}
			return s.toString();
		}
		public int nextInt() {
			int ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');

			if (neg)
				return -ret;
			return ret;
		}
		public int[] readIntArray(int n, int os) {
			int[] ar = new int[n];
			for(int i=0; i<n; ++i)
				ar[i]=nextInt()+os;
			return ar;
		}
		public long nextLong() {
			long ret = 0;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');
			if (neg)
				return -ret;
			return ret;
		}
		public long[] readLongArray(int n, long os) {
			long[] ar = new long[n];
			for(int i=0; i<n; ++i)
				ar[i]=nextLong()+os;
			return ar;
		}
		public double nextDouble() {
			double ret = 0, div = 1;
			byte c = read();
			while (c <= ' ')
				c = read();
			boolean neg = (c == '-');
			if (neg)
				c = read();
			do
				ret = ret * 10 + c - '0';
			while ((c = read()) >= '0' && c <= '9');
			if (c == '.')
				while ((c = read()) >= '0' && c <= '9')
					ret += (c - '0') / (div *= 10);
			if (neg)
				return -ret;
			return ret;
		}
		private void fillBuffer() throws IOException {
			bytesRead = din.read(buffer, bufferPointer = 0, BUFFER_SIZE);
			if (bytesRead == -1)
				buffer[0] = -1;
		}
		private byte read() {
			try{
				if (bufferPointer == bytesRead)
					fillBuffer();
				return buffer[bufferPointer++];
			} catch(IOException e) {
				throw new RuntimeException();
			}
		}
		public void close() throws IOException {
			if (din == null)
				return;
			din.close();
		}
	}
}

Measured memory_bytes: 22740
#include<stdio.h>

struct data{
	int n;
	int x;
};

int judge(struct data *a){
	int answer = 0;
	int i_1, i_2, i_3;
	for (i_1 = 1; i_1 < (a->n)+1; i_1++){
		for (i_2 = 1; i_2 < (a->n)+1; i_2++){
			for (i_3 = 1; i_3 < (a->n)+1; i_3++){
				if ((a->x == i_1 + i_2 + i_3)&&
					(i_1 < i_2 && i_2 < i_3)){
					answer++;
				}
			}
		}
	}
	return answer;
}

int main(void){
	struct data a[100];
	int i=0;
	while (1){
		scanf("%d %d", &a[i].n, &a[i].x);
		if (a[i].n == 0 && a[i].x == 0)
			break;

		i++;
	}
	int j = i;
	for (i = 0; i < j; i++){
		printf("%d\n", judge(&a[i]));
	}


	return 0;
}


Measured memory_bytes: 2060
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(a) (a).size() 
#define all(c) (c).begin(),(c).end()
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,n) for(int i=1;i<=n;i++)
#define ford(i,n) for(int i=n;i>=0;i--) 
#define REP(i,a,n) for(int i=a;i<n;i++)
#define foreach(itr,c) for(__typeof((c).begin(),(c).end())itr=c.begin();itr!=c.end();itr++) 
#define fill(a,b) memset(a,b,sizeof(a))
#define re return
#define INF 1e9
#define LINF 1e18
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pi;
typedef vector<int> vi;
typedef vector<pi > vpi; 
int main(){
	int n;
	cin>>n;
	int a[n];
	rep(i,n){
		cin>>a[i];
	}
	rep(i,n){
		if(a[i]%2==0){
			if(a[i]%3==0||a[i]%5==0){
				continue;
			}
			else{
				cout<<"DENIED";
				re 0;
			}
		}
	}
	cout<<"APPROVED";
	re 0;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
import collections
mo = 1000000007
INF = 10**100
r = range

class infix(object):
    def __init__(self, function):
        self.function = function

    def __ror__(self, other):
        self.left = other
        return self

    def __or__(self, other):
        return self.function(self.left, other)

    def __call__(self, value1, value2):
        return self.function(value1, value2)

@infix
def c(f_t_u, f_u_r): return lambda t: f_u_r(f_t_u(t))

class _Ap(object):
    def __rlshift__(self, other):
        self.value = other
        return self

    def __rshift__(self, other):
        return other(self.value)
Ap = _Ap()
ap = Ap

#d = {1:2, 3:5, 6:10, 1000043:3814}
#zip(d.keys(), d.values())<<ap>>(list |c| sorted |c| reversed |c| list |c| print)




a = input()<<ap>>(int)
b = input()<<ap>>(int)
h = input()<<ap>>(int)

print((a+b)*h//2);


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

int main() {
	string n;
	cin >> n;
	if (n.at(n.size() - 1) == '3') {
		cout << "bon" << endl;
	}
	else if (n.at(n.size() - 1) == '0' || n.at(n.size() - 1) == '1' || n.at(n.size() - 1) == '6' || n.at(n.size() - 1) == '8') {
		cout << "pon" << endl;
	}
	else {
		cout << "hon" << endl;
	}
}

Measured memory_bytes: 3628
#include<stdio.h>

int main(void){
  int a[200],b[200];
  int i,j,tmp;
  for(i=0;i<200;i++){
    a[i]=0;
    b[i]=0;
  }
  for(i=0;i<200;i++){
    scanf("%d %d",&a[i],&b[i]);
  }
  for(i=0;i<200&&a[i]+b[i]!=0;i++){
    tmp=a[i]+b[i];
    for(j=0;tmp!=0;j++){
      tmp/=10;
    }
    printf("%d\n",j);
  }
  return 0;
}

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

using ll = long long;

constexpr ll MOD = 1e9+7;
constexpr ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()

int main(int argc, char **argv)
{
	string s; cin >> s;
	string ns;
	ll N = (ll)s.size();

	for (ll i = 0; i < N;)
	{
		if (i + 1 < N && s[i] == 'B' &&  s[i+1] == 'C')
		{
			ns.push_back('D');
			i += 2;
		}
		else
		{
			ns.push_back(s[i]);
			++i;
		}
	}

	/* std::cout << ns << std::endl; */
	N = (ll)ns.size();

	ll res{0};
	for (ll i = 0; i < N;)
	{
		ll k = i + 1;
		if (ns[i] == 'A')
		{
			while (k < N && (ns[k] == 'A' || ns[k] == 'D')) {++k;}

			string tmp = ns.substr(i, k-i);
			/* std::cout << "i : " << i << std::endl; */
			/* std::cout << "k : " << k << std::endl; */
			/* std::cout << "tmp : " << tmp << std::endl; */
			while (tmp.empty() && tmp.back() == 'A') {tmp.pop_back();}
			reverse(tmp.begin(), tmp.end());
			ll l{0};

			ll M = (ll)tmp.size();
			REP(m, M)
			{
				if (tmp[m] == 'A')
				{
					res += m - l;
					++l;
				}
			}
		}
		i = k;
	}

	std::cout << res << std::endl;
}

Measured memory_bytes: 904
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;
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 (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e9;
const ll MOD = 1e9 + 7;


int main(){
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> v(h);
    rep(i, h) cin >> v[i];

    int ans = INF;

    for(int bit=0; bit<(1<<(h-1)); bit++){
        bool imp = false;//分割が荒いとき不可能な場合が存在
        int on = __builtin_popcount(bit);
        vector<int> ord(h);//セグメントに番号付けする
        rep(i, h-1){
            if(!((bit>>i) & 1)) ord[i+1] = ord[i];
            else ord[i+1] = ord[i]+1;
        }

        int split = on; //分割の回数
        vector<int> cnt(on+1);
        rep(i, w){
            vector<int> one(on+1);//impな場合の判定と更新用
            bool ok = true;
            rep(j, h){
                one[ord[j]] += (v[j][i] - '0');
                cnt[ord[j]] += (v[j][i] - '0');

                if(one[ord[j]] > k) imp = true;
                if(cnt[ord[j]] > k) ok = false;
            }
            if(!ok){
                split++;
                cnt = one;
            }
        }
        if(!imp) chmin(ans, split);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
sa = str(raw_input())
sb = str(raw_input())
sc = str(raw_input())

n = 'a'
h = ''
while True:
    if n == 'a':
        if len(sa) < 1:
            break
        h, sa = sa[0], sa[1:]
        n = h
    elif n == 'b':
        if len(sb) < 1:
            break
        h, sb = sb[0], sb[1:]
        n = h
    elif n == 'c':
        if len(sc) < 1:
            break
        h, sc = sc[0], sc[1:]
        n = h

print str.upper(n)


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

int	main()
{
	int	N, K;
	cin >> N >> K;
	vector<int64_t>	a_vec(N);
	for (int i = 0; i < N; ++i)
		cin >> a_vec.at(i);
	int64_t	min_cost = -1;
	int64_t	cost;
	for (int i = 0; i < (1 << N); ++i) {
		bitset<15>	choice(i);
		if (choice.count() != static_cast<size_t>(K)) continue;
		int64_t	prev_hight = 0;
		cost = 0;
		for (int j = 0; j < N; ++j) {
			if (choice.test(j)) {
				if (prev_hight >= a_vec.at(j)) {
					cost += prev_hight + 1 - a_vec.at(j);
					prev_hight += 1;
				}
			}
			prev_hight = max(prev_hight, a_vec.at(j));
		}
		if (min_cost == -1 || min_cost > cost)
			min_cost = cost;
	}
	cout << min_cost << endl;
}



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

int x[10], y[10];

int fact(int k){
    int sum = 1;
    for(int i = 1; i <= k; i++){
        sum *= i;
    }
    return sum;
}

double dist(int i, int j){
    double dx = x[i] - x[j];
    double dy = y[i] - y[j];
    return pow(dx*dx + dy*dy, 0.5);
}

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

    for(int i = 1; i <= n; i++) cin >> x[i] >> y[i];
    double sum = 0.0;
    vector<int> v(n);

    for(int i = 0; i < n; i++) v[i] = i + 1;
    do{
        for(int i = 0; i < n-1; i++) sum += dist(v[i], v[i+1]);
    } while(next_permutation(v.begin(), v.end()));

    int num = fact(n);

    printf("%.9lf\n", sum / num);
}

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

Measured memory_bytes: 640
import sys
reader = (s.rstrip() for s in sys.stdin)
input = reader.__next__

class Binary_Indexed_Tree_RAQ():
    def __init__(self, n):
        self.bit = [0]*(n+1)
        self.n = n+1

    def __add(self, ind, num):
        while(ind <= self.n):
            self.bit[ind - 1] += num
            ind += ind & -ind

    def range_add(self, s, t, x):
        self.__add(s,x)
        self.__add(t+1,-x)

    def query(self, i):
        ret = 0
        while(i > 0):
            ret += self.bit[i-1]
            i -= i & -i
        return ret

n,q = map(int, input().split())
a = list(map(int, input().split()))
m = 10**6 + 1
prev = [-1]*m

query = []
for i in range(q):
    l,r = map(int, input().split())
    l,r = l-1,r-1
    query.append((l,r,i))
ans = [0]*q
query.sort(key=lambda x: x[1])

BIT = Binary_Indexed_Tree_RAQ(n+1)
cur = 0
for l,r,i in query:
    while cur <= r:
        ai = a[cur]
        BIT.range_add(prev[ai]+2, cur+1, 1)
        prev[ai] = cur
        cur += 1
    ans[i] = BIT.query(l+1)
print(*ans, sep="\n")

Measured memory_bytes: 238824
from sys import stderr, setrecursionlimit
from functools import reduce
from operator import add
from collections import defaultdict as dd
setrecursionlimit(2147483647)
def f(): return [int(i) for i in input().split()]
def yes(n): print("Yes" if n else "No")
def debug(*x, sep=" ", end="\n"):
    for item in x:
        stderr.write(str(item))
        stderr.write(sep)
    stderr.write(end)

n, m = f()
graph = dd(list)
for i in range(m):
    a, b = f()
    graph[a].append(b)

for a in graph[1]:
    if n not in graph[a]:
        continue
    print("POSSIBLE")
    break
else:
    print("IMPOSSIBLE")

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

int main() {
	string s;
	long k;
	cin>>s;
	cin >> k;
	bool f = false;
	for (int i=0;i<k;i++) {
		if(s[i] != '1') {
			cout << s[i] << endl;
			f = true;
			break;
		}
		if(i == k-1)break;
	}
	if (!f) cout << 1 << endl;
}


Measured memory_bytes: 256
use std::io::Read;

pub fn read_stdin() -> String {
    let mut s = String::new();
    ::std::io::stdin().read_to_string(&mut s).unwrap();
    s
}

pub trait Parse {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr;
}

impl<'a> Parse for std::str::SplitWhitespace<'a> {
    fn to<T>(&mut self) -> T
    where
        T: std::str::FromStr,
    {
        let word = self.next().unwrap();
        word.parse().ok().unwrap()
    }
}

fn find_row(v: &Vec<Vec<char>>) -> Option<usize> {
    for (i, x) in v.iter().enumerate() {
        if x.iter().all(|&c| c == '.') {
            return Some(i);
        }
    }
    None
}

fn to_col(v: &Vec<Vec<char>>, i: usize) -> Vec<char> {
    let mut out = Vec::new();
    for x in v {
        out.push(x[i]);
    }
    out
}

fn find_col(v: &Vec<Vec<char>>) -> Option<usize> {
    let w = v[0].len();
    for i in 0..w {
        let col = to_col(v, i);
        if col.into_iter().all(|c| c == '.') {
            return Some(i);
        }
    }
    None
}

fn main() {
    let source = read_stdin();
    let mut iter = source.split_whitespace();
    let h = iter.to();
    let _: usize = iter.to();
    let mut v = (0..h)
        .map(|_| iter.to::<String>().chars().collect::<Vec<_>>())
        .collect::<Vec<_>>();
    loop {
        if let Some(i) = find_row(&v) {
            v.remove(i);
        } else if let Some(i) = find_col(&v) {
            for x in v.iter_mut() {
                x.remove(i);
            }
        } else {
            break;
        }
    }
    println!(
        "{}",
        v.into_iter()
            .map(|x| {
                x.into_iter()
                    .map(|c| c.to_string())
                    .collect::<Vec<_>>()
                    .join("")
            })
            .collect::<Vec<_>>()
            .join("\n")
    );
}

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

int main() {
    list<char> ans;
    string S;
    ll Q;
    bool swap = false;
    cin >> S >> Q;
    rep(i, S.length()) { ans.push_back(S[i]); }
    rep(i, Q) {
        ll T;
        cin >> T;
        if (T == 1) {
            swap = !swap;
        } else {
            ll F;
            char C;
            cin >> F >> C;
            if (F == 1) {
                if (!swap) {
                    ans.push_front(C);
                } else {
                    ans.push_back(C);
                }
            } else {
                if (!swap) {
                    ans.push_back(C);
                } else {
                    ans.push_front(C);
                }
            }
        }
    }
    if (swap) {
        ans.reverse();
    }
    for (auto i = ans.begin(); i != ans.end(); i++) {
        cout << *i;
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 13048
#include <bits/stdc++.h>
using namespace std;
#define int long long int
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define all(x) x.begin(), x.end()
#define tr(it, a) for (auto it = a.begin(); it != a.end(); it++)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; k < n ? i < n : i > n; k < n ? i += 1 : i -= 1)
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef pair<int, pair<int, int>> pipii;
typedef priority_queue<pii, vector<pii>, greater<pii>> minpq;
typedef priority_queue<pii> maxpq;
//const double PI = acos(-1);
const int mod = 998244353;

// ----------------------DEBUG TEMPLATE--------------------------
void __print(int x) { cerr << x; }
void __print(float x) { cerr << x; }
void __print(double x) { cerr << x; }
void __print(long double x) { cerr << x; }
void __print(char x) { cerr << '\'' << x << '\''; }
void __print(const char *x) { cerr << '\"' << x << '\"'; }
void __print(const string &x) { cerr << '\"' << x << '\"'; }
void __print(bool x) { cerr << (x ? "true" : "false"); }

template <typename T, typename V>
void __print(const pair<T, V> &x)
{
	cerr << '{';
	__print(x.first);
	cerr << ',';
	__print(x.second);
	cerr << '}';
}
template <typename T>
void __print(const T &x)
{
	int f = 0;
	cerr << '{';
	for (auto &i : x)
		cerr << (f++ ? "," : ""), __print(i);
	cerr << "}";
}
void _print() { cerr << "]\n"; }
template <typename T, typename... V>
void _print(T t, V... v)
{
	__print(t);
	if (sizeof...(v))
		cerr << ", ";
	_print(v...);
}
#ifndef ONLINE_JUDGE
#define debug(x...)               \
	cerr << "[" << #x << "] = ["; \
	_print(x)
#else
#define debug(x...)
#endif
// ----------------------DEBUG TEMPLATE--------------------------

//1->first 0->second
void solve(vi&arr,int n,int k){
	vi dp(k+1,0);
	// int dp[n+1]={0};
	int mini = *min_element(all(arr));
	// for(int i =0;i <=mini;i++){
	// 	dp[i]=0;
	// }

	for(int i =mini+1;i <=k;i++){
		for(int j = 1;j <=n;j++){
			if(arr[j]>i) break;

			if(i>= arr[j] && dp[i-arr[j]]==0){
				dp[i]=1;
			}
		}
	}
	// debug(dp);
	if(dp[k]){
		cout<<"First"<<endl;
	}
	else{
		cout<<"Second"<<endl;
	}


}
int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int n,k;
	cin>>n>>k;
	vi arr(n+1);
	Fo(i,1,n+1){
		cin>>arr[i];
	}
	solve(arr,n,k);
	


}

Measured memory_bytes: 3984
#include<bits/stdc++.h>
using namespace std;
long long num[34];
void init()
{
    num[0]=1;
    for(int i=1;i<34;i++)num[i]=3*num[i-1];
}
int main()
{
    long long n;
    int ans=0;
    init();
    cin>>n;
    if(n==0){cout<<0<<endl;return 0;}
    n--;
    int i;
    for(i=1;i<34;i++)
    {
        if(n>=2*num[i])
        {
            n-=2*num[i];
            ans+=2;
        }
        else if(n<2*num[i]&&n>=num[i])
        {
            n-=num[i];
            ans++;
            break;
        }
        else break;
    }
    for(int j=i-1;j>=0;j--)
    {
        while(n>=num[j]){n-=num[j];ans++;}
    }
    cout<<ans+1<<endl;
    return 0;
}


Measured memory_bytes: 3092
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    cout << (n % 500 <= a ? "Yes" : "No") << endl;

    return 0;
}

Measured memory_bytes: 256
N, M = map(int,input().split())
A = list(map(int,input().split()))
B = [list(map(int,input().split())) for i in range(M)]
A.sort()
B.sort(reverse=True, key=lambda x: x[1])

cot = 0
add = 0
for b,c in B:
    cot += b
    if cot > N:
        add = N-cot+b
        A.extend([c]*add)
        break
    else:
        A.extend([c]*b)
print(sum(sorted(A, reverse=True)[:N]))

Measured memory_bytes: 36032
#include <bits/stdc++.h>
#define int long long int
using namespace std;
template<typename T,typename U> using P=pair<T,U>;
template<typename T> using V=vector<T>;
template<typename T>bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<typename T>bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x)  cerr<<#x<<" = "<<(x)<<endl;

struct edge { int to, cost; };

const int INF = 1e18;
const int MOD = 1e9+7;

signed main()
{
   int n; cin >> n;
   V<int> a(n);
   for (int i = 0; i < n; i++) {
      cin >> a[i];
   }

   int suma = accumulate(a.begin(), a.end(), 0);
   bitset<4000001> dp;
   dp[0] = 1;
   for (int i = 0; i < n; i++) {
      bitset<4000001> nxt;
      nxt |= dp;
      nxt |= dp << a[i];
      swap(dp, nxt);
   }

   for (int i = (suma+1)/2; ; i++) {
      if (dp[i]) {
         cout << i << endl;
         return 0;
      }
   }

   return 0;
}


Measured memory_bytes: 2176