akhauriyash/Code-Regression huggingface dataset:
# include <bits/stdc++.h>

using namespace std;

#define pii pair<int, int>
#define pll pair<ll, ll>

#define pb push_back
#define eb emplace_back
#define mp make_pair

#define fi first
#define se second

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

const int inf = (int)1e9 + 7;
const int maxn = (int)6e5 + 7;
const int lmaxn = (int)6e6 + 7;
const ll linf = (ll)1e16 + 7;

const ld eps = ld(1e-11);

const ll dx[] = {-1, 0, 0, 1};
const ll dy[] = {0, -1, 1, 0};

ll gcd(ll a, ll b){
    while(b) a %= b, swap(a, b);
    return a | b;
}

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

ll n, mn = linf;
ll a[maxn];

int main(){
    scanf("%lld", &n);
    for(ll i = 1; i <= n; ++i){
        scanf("%lld", &a[i]);
    }
    for(ll i = -200; i <= 200; ++i){
        ll ans = 0;
        for(ll j = 1; j <= n; ++j)
            ans += (a[j] - i) * (a[j] - i);
        mn = min(mn, ans);
    }
    printf("%lld", mn);
    return 0;
}



Measured memory_bytes: 384
#include<stdio.h>

int main(void)

{  

int a,b,c;

int tmp,i,j;

scanf("%d %d %d",&a,&b,&c);  

if(a>b)

{   

tmp = a;   

a = b;   

b = tmp;  

}  

if(a>c)

{  

tmp = a;   

a = c;   

c = tmp;  

}  

if(b>c){   

tmp = b;   

b = c;   

c = tmp;  

}  

printf("%d %d %d\n",a,b,c);  

return 0;

}

Measured memory_bytes: 596
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Map;
import java.util.Scanner;
import java.util.HashMap;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author teiwa
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            char[][] s = new char[N][];
            for (int i = 0; i < N; i++) {
                s[i] = in.next().toCharArray();
            }
            long counter = 0;
            Map<String, Long> mp = new HashMap<>();
            for (int i = 0; i < N; i++) {
                Arrays.sort(s[i]);
                mp.compute(String.valueOf(s[i]), (key, value) -> value == null ? 1 : value + 1);
            }

            for (long value : mp.values()) {
                counter += value * (value - 1) / 2;
            }
            out.println(counter);
        }

    }
}



Measured memory_bytes: 54640
using System;
using System.Linq;
using System.Collections.Generic;
using System.Collections;

class Program
{
    static void Main(string[] args)
    {
        var sol = new Solve();
        sol.Exec();
    }
}

class Solve
{
    public void Exec()
    {
        var N = int.Parse(Console.ReadLine());
        var P = Console.ReadLine().Split().Select(int.Parse).ToArray();

        var min = int.MaxValue;
        var ans = 0;
        for (var i = 0; i < N; i++)
        {
            if (P[i] <= min)
                ans++;
            min = Math.Min(min, P[i]);
        }

        Console.WriteLine(ans);
    }
}


Measured memory_bytes: 33628
//Written by Zhu Zeqi
//Come on,baby
//Hack,please
#include<cmath>
#include<math.h>
#include<ctype.h>
#include<algorithm>
#include<bitset>
#include<cassert>
#include<cctype>
#include<cerrno>
#include<cfloat>
#include<ciso646>
#include<climits>
#include<clocale>
#include<complex>
#include<csetjmp>
#include<csignal>
#include<cstdarg>
#include<cstddef>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<ctime>
#include<cwchar>
#include<cwctype>
#include<deque>
#include<exception>
#include<fstream>
#include<functional>
#include<iomanip>
#include<ios>
#include<iosfwd>
#include<iostream>
#include<istream>
#include<iterator>
#include<limits>
#include<list>
#include<locale>
#include<map>
#include<memory>
#include<new>
#include<numeric>
#include<ostream>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<stdexcept>
#include<streambuf>
#include<string>
#include<typeinfo>
#include<utility>
#include<valarray>
#include<vector>
#include<string.h>
#include<stdlib.h>
#include<stdio.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define pii pair<int,int>
#define vi vector<int>
#define MAX 100000000000000000
#define MOD 1000000007
#define PI 3.141592653589793238462
#define INF 1000000000
typedef long long ll;
using namespace std;
int main(){
	//freopen("input.in","r",stdin);
	//freopen("output.out","w",stdout);
	ll N,A,B,C,D;
	scanf("%lld%lld%lld%lld%lld",&N,&A,&B,&C,&D);
	ll dif=B-A;
	ll a,b;
	for(a=0;a<=N-1;a++){
		b=N-1-a;
		ll Min=(a-b)*C+b*(C-D);
		ll Max=(a-b)*C+a*(D-C);
		if(dif<=Max && dif>=Min){
			printf("YES");
			return 0;
		}
	}
	printf("NO");
	//system("pause");
	return 0;
}

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

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

    int count = 0;
    for (int j = 0; j < n; j++) {
        if ((j % 2 == 0 && masu[j] % 2 != 0)) {
            count++;
        }
    }
    cout << count << endl;

    return 0;
}


Measured memory_bytes: 3572
#include<iostream>
#include<iomanip>
#include<math.h>
#include<algorithm>
#include<utility>
#include<functional>
#include<queue>
#include<string.h>
#include<string>
#include<set>
#include<map>
#include<vector>
using namespace std;
typedef long long LL;
typedef pair<int, int> P;
LL N,K;
int main(){
    cin>>N>>K;
    LL ans=K;
    for(int i=1;i<N;i++){
        ans*=K-1;
    }
    cout<<ans;
        
    return 0;
}


Measured memory_bytes: 256
import java.io.IOException;
import java.util.Scanner;

/**
 * Created on 2017/09/29 8:06.
 */
public class Main {
    public static void main(String[] args) throws IOException {
        // BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        Scanner sc = new Scanner(System.in);
        final int MAX_COST = 1000000001;

        while (sc.hasNextInt()) {
            int N = sc.nextInt();
            int t[][] = new int[N][N];
            int backup[][] = new int[N][N];

            for (int i = 0; i < N; i++) {
                for (int j = 0; j < N; j++) {
                    t[i][j] = sc.nextInt();
                    backup[i][j] = t[i][j];
                }
            }

            for (int k = 0; k < N; k++) {
                for (int i = 0; i < N; i++) {
                    for (int j = 0; j < N; j++) {
                        if (i == j) {
                            continue;
                        }
                        t[i][j] = Math.min(t[i][j], t[i][k] + t[k][j]);
                    }
                }
            }

            boolean exists = true;
            for (int i = 0; exists && i < N; i++) {
                for (int j = 0; exists && j < N; j++) {
                    if (t[i][j] != backup[i][j]) {
                        exists = false;
                        break;
                    }
                }
            }
            if (!exists) {
                System.out.println(-1);
                continue;
            }

            for (int k = 0; k < N; k++) {
                for (int i = 0; i < N; i++) {
                    for (int j = 0; j < N; j++) {
                        if (i == j || j == k || i == k) {
                            continue;
                        }
                        if (t[i][j] == backup[i][k] + backup[k][j]) {
                            t[i][j] = MAX_COST;
                        }
                    }
                }
            }

            long ans = 0;
            for (int i = 0; i < N; i++) {
                for (int j = i + 1; j < N; j++) {
                    if (t[i][j] == MAX_COST) {
                        continue;
                    }
                    ans += t[i][j];
                }
            }
            System.out.println(ans);
        }
    }
}

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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int k,n;
  cin>>k>>n;
  vector<int> a(2*n);
  rep(i,n)cin>>a[i];
  for(int i=n;i<2*n;i++)a[i]=a[i-n]+k;
  ll mini=a[n-1]-a[0];
  for(int i=0;i<=n;i++){
    ll tmp=a[i+n-1]-a[i];
    mini=min(mini,tmp);
  }
  cout<<mini<<endl;
  return 0;
}


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

using namespace std;
template<typename T>
using reversed_priority_queue = std::priority_queue<T, std::vector<T>, std::greater<T> >;
typedef unsigned long long int ull;
typedef long long int ll;
#define rep(i,a,b) for (ll i=(a); i<(b); i++)
typedef pair<ll,ll> PLL;
// }}}

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

signed main() {
    ll h,w;
    cin>>h>>w;
    vector<string> s(h);
    rep(i,0,h)
        cin>>s[i];

    rep(y,0,h){
        rep(x,0,w){
            if (s[y][x]=='.')
                continue;
            bool t = false;
            rep(k,0,4){
                ll nx = x+dx[k];
                ll ny = y+dy[k];
                if (nx>=0 && nx<w && ny>=0 && ny<h && s[ny][nx]=='#'){
                    t = true;
                    break;
                }
            }
            if(!t){
                cout<<"No"<<endl;
                return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}


Measured memory_bytes: 256
<?php
$N = intval(trim(fgets(STDIN)));
$A = explode(' ', trim(fgets(STDIN)));
$c1=$c2=$c3=0;
foreach($A as $a){
    if($a == '1')$c1++;
    if($a == '2')$c2++;
    if($a == '3')$c3++;
}
$dp = array_fill(0, $N+1, array_fill(0,$N+1, array_fill(0,$N+1,0)));
for($k = 0; $k <= $c3; ++$k){
    $dpk = &$dp[$k];
    if($k>0)$dpkm = &$dp[$k-1];
    for($j = 0, $J = $c2 + $c3 - $k; $j <= $J; ++$j){
        $dpkj = &$dp[$k][$j];
        for($i = 0, $I = $c1+$c2+$c3-$k-$j; $i <= $I ; ++$i){
            if($i==0&&$j==0&&$k==0)continue;
            $tmp = $N;
            if($i>0)$tmp+=$i*$dpkj[$i-1];
            if($j>0)$tmp+=$j*$dpk[$j-1][$i+1];
            if($k>0)$tmp+=$k*$dpkm[$j+1][$i];
            $dpkj[$i] = $tmp/($i+$j+$k);
        }
    }
}
echo $dp[$c3][$c2][$c1];


Measured memory_bytes: 895360
import sys
import math
def I():return int(sys.stdin.readline().replace("\n",""))
def I2():return map(int,sys.stdin.readline().replace("\n","").split())
def S():return str(sys.stdin.readline().replace("\n",""))
def L():return list(sys.stdin.readline().replace("\n",""))
def Intl():return [int(k) for k in sys.stdin.readline().replace("\n","").split()]
def Lx(k):return list(map(lambda x:int(x)*-k,sys.stdin.readline().replace("\n","").split()))

if __name__ == "__main__":
    n = I()
    s = S()
    t = S()
    cnt = 0
    for i in range(n):
        #print(s[i:n],t[:n-i])
        now = 0
        for j in range(n-i):
            if s[i:n][j] == t[:n-i][j]:now += 1
        cnt = max(cnt,now)
    print(2 * n - cnt)

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

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

	int count = 0 ;
	int maxcount = 0;
	for(int i = 0;i < n-1 ; i++)
	{	
		if(arr[i] >= arr[i+1])
		{
			count++;
		}
		else 
		{
			count = 0 ;
		}
		if(count > maxcount)
		{
			maxcount = count;
		}
		
	}
	cout << maxcount << endl;
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <cmath>

using namespace std;
int main(void)
{
    int a, b, c;
    cin >> a >> b;
    c = abs(b - a);
    if (c%2 == 0)
    {
        if (a > b)
        {
            cout << a - c/2 << endl;
        }
        else
        {
            cout << b - c/2 << endl;
        }
    }
    else
    {
        cout << "IMPOSSIBLE" << endl;
    }
    
    
    return 0;
}

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

int main () {
  string S;
  cin >> S;
  
  if ((S.at(0) != S.at(1)) && (S.at(0) != S.at(2)) && (S.at(1) != S.at(2))) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<set>
#include<math.h>
#include<vector>
#include<sstream>
#include<queue>
#include<functional>
#include<bitset>
#include<cstdio>
#include<iomanip>
#include<map>
#include<unordered_map>
#include<unordered_set>
#include <string.h>
using ll = long long;

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define reps(i,x) for(ll i=1;i<=(ll)(x);i++)
#define rrep(i,x) for(ll i=((ll)(x)-1);i>=0;i--)
#define rreps(i,x) for(ll i=(ll)(x);i>0;i--)
#define all(x) (x).begin(),(x).end()
#define m0(x) memset(x,0,sizeof(x))
#define vll vector<ll>
#define vi vector<int>
#define vpll vector<pair<ll,ll>>
#define vpi vector<pair<int,int>>
#define mod 1000000007 
using namespace std;


int main() {
  string s;
  cin >> s;
  bool f = true;
  rep(i, s.size()-1){
    if(s[i]!=s[i+1]) {
      f = false;
      }
  }
  if(f){
    cout << s;
  }else{
    f = true;
    int fs = s[0];
    reps(i, 2){
      if(fs < s[i]) f = false;
    }

    if(f){
      rep(i, s.size())
        cout << (s[0]-'0');
    }
    else{
      rep(i, s.size())
        cout <<(s[0]-'0')+1;
    }

  }
  cout << endl;
  return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll mod = 1000000009;
const ll INF = (ll)1000000007 * 1000000007;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-4;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
//各nodeには、グループ分けの個数と、その中での予備力の最大値をもつ。
P ans[32][32][32][32];
bool used[32][32][32][32];
int sum[32][32][32][32];
int h, w, s;
int u[32][32];
void init() {
	rep(i, 32) {
		rep(j, 32) {
			rep(k, 32) {
				rep(l, 32) {
					used[i][j][k][l] = false;
					sum[i][j][k][l] = 0;
				}
			}
		}
	}
	rep(i, h) {
		rep(j, w) {
			sum[0][0][i][j] = u[i][j];
			if (i > 0) {
				sum[0][0][i][j] += sum[0][0][i - 1][j];
			}
			if (j > 0) {
				sum[0][0][i][j] += sum[0][0][i][j - 1];
			}
			if (i > 0 && j > 0){
				sum[0][0][i][j] -= sum[0][0][i - 1][j - 1];
		    }
		}
	}
	rep(lx, h) {
		rep(ly, w) {
			rep(rx, h) {
				rep(ry, w) {
					sum[lx][ly][rx][ry] = sum[0][0][rx][ry];
					if (lx > 0) {
						sum[lx][ly][rx][ry] -= sum[0][0][lx - 1][ry];
					}
					if (ly > 0) {
						sum[lx][ly][rx][ry] -= sum[0][0][rx][ly - 1];
					}
					if (lx > 0 && ly > 0) {
						sum[lx][ly][rx][ry] += sum[0][0][lx - 1][ly - 1];
					}
				}
			}
		}
	}
}
P dfs(int lx, int ly, int rx, int ry) {
	if (used[lx][ly][rx][ry])return ans[lx][ly][rx][ry];
	used[lx][ly][rx][ry] = true;
	P res = { 1,s-(sum[0][0][h-1][w-1]-sum[lx][ly][rx][ry]) };
	//cout << lx << " " << ly << " " << rx << " " << ry << " " << res.second << endl;
	if (res.second < 0) {
		res.first = -mod;
	}
	Rep(x, lx, rx) {
		P s1 = dfs(lx, ly, x, ry); P s2 = dfs(x + 1, ly, rx, ry);
		P s3 = { s1.first + s2.first,min(s1.second, s2.second) };
		res = max(res, s3);
	}
	Rep(y, ly, ry) {
		P s1 = dfs(lx, ly, rx, y); P s2 = dfs(lx, y + 1, rx, ry);
		P s3 = { s1.first + s2.first,min(s1.second , s2.second) };
		res = max(res, s3);
	}
	return ans[lx][ly][rx][ry] = res;
}
int main(){
	while (cin >> h >> w >> s, h) {
		rep(i, h) {
			rep(j, w) {
				cin >> u[i][j];
			}
		}
		init();
		P out = dfs(0, 0, h - 1, w - 1);
		cout << out.first << " " << out.second << endl;
	}
	return 0;
}


Measured memory_bytes: 16004
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define watch(x) cout << (#x) << " is " << (x) << endl
#define f(t) for(ll i =0;i<t;i++)
#define ll long long int
#define ul unsigned long int
#define ld long double
#define umpi unordered_map<int,int> 
#define umpl unordered_map<ll,ll> 
#define vi vector<int>
#define vl vector<ll>
#define vvl vector<vl>
#define fill(a,p) memset(a,p,sizeof(a))
#define pb push_back
#define mod 1000000007
#define N 100005
#define all(a) a.begin(),a.end()
#define point pair<ll,ll>
#define endl "\n"

const int inf = 1000000007;
const ll linf = 1ll * inf * inf;
const ll MAXIMUM =2005;

inline ll mul(ll a, ll b){ return (a * 1ll * b) % mod; }
inline ll sub(ll a, ll b){ ll c = a - b; if(c < 0) c += mod; return c; }
inline ll add(ll a, ll b){ ll c = a + b; if(c >= mod) c -= mod; return c; }
inline ll max(ll a, ll b){return a>b?a:b;}
inline ll min(ll a, ll b){return a<b?a:b;}
inline ll ceil(ll a,ll b){if(a%b==0)return a/b;else return a/b+1;}
inline ll mo(ll a,ll b){if(b<0){b=abs(b)%mod;b=a-b;return (b<0)?b+mod:b;}else{return (a+b)%mod;}}
inline ll pow(ll a,ll b){if(b==0){return 1;}else{if(b%2==0){ll temp=pow(a,b/2);return temp*temp;}
else{return a*pow(a,b-1);}}}

struct hash_pair { 
    template <class T1, class T2> 
    size_t operator()(const pair<T1, T2>& p) const
    { 
        auto hash1 = hash<T1>{}(p.first); 
        auto hash2 = hash<T2>{}(p.second); 
        return hash1 ^ hash2; 
    } 
};

int main()
{
    ll a[5];
    f(5)cin>>a[i];
    f(5){
        if(a[i]==0){
            cout<<i+1<<endl;
            return 0;
        }
    }
}

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

int main(){
	int n,m,l;
	cin >> n >> m >> l;
	
	long long int a[100][100], b[100][100];
	for(int i=0; i<n; i++){
		for(int j=0; j<m; j++){
			cin >> a[i][j];
		}
	}
	for(int i=0; i<m; i++){
		for(int j=0; j<l; j++){
			cin >> b[i][j];
		}
	}
	for(int i=0; i<n; i++){
		for(int j=0; j<l; j++){
			long long int elem=0;
			for(int k=0; k<m; k++){
				elem += a[i][k]*b[k][j];
			}
			if(j==0) cout << elem;
			else cout << " " << elem;
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3220
#include<iostream>
#include<algorithm>
#include<vector>
#include<utility>
typedef long long lint;
using namespace std;

int main() {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int> > ps(M);
    for (int i = 0; i < M; i++) {
        cin >> ps[i].second >> ps[i].first;
    }
    sort(ps.begin(), ps.end());
    int ans = 0;
    for (int i = 0; i < M; ) {
        const int last = ps[i].first;
        int ni = i+1;
        while (ni < M && ps[ni].second < last) {
            ++ni;
        }
        ++ans;
        i = ni;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define next Next
#define gc getchar
#define int long long
const int N=1e6+5;
int n,m,ans,a[N],b[N],f[N];
char s[N];
/*char buf[1<<21],*p1=buf,*p2=buf;
inline int gc(){return p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<21,stdin),p1==p2)?EOF:*p1++;}*/
inline int read()
{
    int ret=0,f=0;char c=gc();
    while(!isdigit(c)){if(c=='-')f=1;c=gc();}
    while(isdigit(c)){ret=ret*10+c-48;c=gc();}
    if(f)return -ret;return ret;
}
signed main()
{
	m=read();n=read();
	for(int i=1;i<=n;i++)a[i]=read(),b[i]=read();
	memset(f,0x3f,sizeof(f));
	f[0]=0;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=a[i];j++)f[j]=min(f[j],b[i]);
		for(int j=a[i];j<=m;j++)f[j]=min(f[j],f[j-a[i]]+b[i]);
	}
	cout<<f[m];
	return 0;
}

Measured memory_bytes: 11648
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

template<typename F>
struct FixPoint : F{
  FixPoint(F&& f):F(forward<F>(f)){}
  template<typename... Args>
  decltype(auto) operator()(Args&&... args) const{
    return F::operator()(*this,forward<Args>(args)...);
  }
};
template<typename F>
inline decltype(auto) MFP(F&& f){
  return FixPoint<F>{forward<F>(f)};
}

//INSERT ABOVE HERE
signed main(){
  int n;
  cin>>n;

  vector< vector<int> > G(n);
  using P = pair<int, int>;
  map<P, int> idx;
  for(int i=1;i<n;i++){
    int a,b;
    cin>>a>>b;
    a--;b--;
    G[a].emplace_back(b);
    G[b].emplace_back(a);
    idx[minmax({a,b})]=i;
  }

  int m;
  cin>>m;
  vector<int> us(m),vs(m);
  for(int i=0;i<m;i++) cin>>us[i]>>vs[i],us[i]--,vs[i]--;

  vector< vector<int> > par(n,vector<int>(n,-1));
  for(int i=0;i<n;i++){
    MFP([&](auto dfs,int v,int p)->void{
          par[i][v]=p;
          for(int u:G[v]){
            if(u==p) continue;
            dfs(u,v);
          }
        })(i,-1);
  }

  using ll = long long;
  vector<ll> po(n,1);
  for(int i=0;i+1<n;i++) po[i+1]=po[i]*2;

  vector<ll> es(m,0);
  for(int i=0;i<m;i++){
    int x=us[i],y=vs[i];
    while(x!=y){
      es[i]|=1LL<<idx[minmax({x,par[y][x]})];
      x=par[y][x];
    }
  }

  int sz=1<<m;
  ll ans=0;
  for(int bit=0;bit<sz;bit++){
    ll res=0;
    for(int i=0;i<m;i++)
      if((bit>>i)&1) res|=es[i];

    if(__builtin_parity(bit))
      ans-=po[n-1-__builtin_popcountll(res)];
    else
      ans+=po[n-1-__builtin_popcountll(res)];
  }

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


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

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

	sort(a.begin(), a.end());
	
	bool flag = false;

	for (int i = 0; i < n-1; i++) {
		if (a[i] == a[i + 1]) {
			flag = true;
			break;
		}
	}
		

	if (flag) {
		cout << "NO" << endl;
	}
	else {
		cout << "YES" << endl;
	}
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define rep(i, m, n) for(int i = m; i < (n); i++)
#define print(x) cout << (x) << endl;
#define printv(x) for(int i = 0; i < x.size(); i++){ cout << (x[i]) << " "; } cout << endl; 
#define printa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ cout << (x[i]) << " ";} cout << endl;
#define printaa(x) for(int i = 0; i < (sizeof(x)/sizeof(x[0])); i++){ for(int j = 0; j < (sizeof(x[0])/sizeof(x[0][0])); j++){ cout << x[i][j] << " ";} cout << endl;}
#define INF (1e9)
typedef long long ll;
typedef struct{
    int x;
    int y;
} P;

using namespace std;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    int A[101];
    cin >> N;
    rep(i,0,N){
        cin >> A[i];
    }
    int max_a = 0;
    int min_a = 1e9;
    rep(i,0,N){
        max_a = max(max_a, A[i]);
        min_a = min(min_a, A[i]);
    }
    int ans = max_a - min_a;
    print(ans);

}


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

///******************************** C o n t a i n e r ********************************///

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;

///*********************************** C o n s t ***********************************///

const int       N=1e6+3;
const double    PI = acos(-1);
const ll        MOD=1000000007;                 ///1e9+7
ll dx[] = {+1, 0, -1, 0, +1, +1, -1, -1};
ll dy[] = {0, +1, 0, -1, +1, -1, +1, -1};

///********************************** M a r c o ***********************************///

#define pb push_back
#define F first
#define S second
#define test int tc; cin>>tc; while(tc--)
#define forn(i,n) for(i=0;i<n;i++)
#define rforn(i,n) for(i=n-1;i>=0;i--)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define sz(x) x.size()
#define el <<'\n'
#define sp <<' '
#define print(a) {for(auto x:a)cout<<x<<" ";cout<<endl;}
#define mem(a,b) memset(a, b, sizeof(a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define sqr(a) (a)*(a)

#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

///*********************************** F u n c t i o n ***********************************///

ll powmod(ll a,ll b){ll p=MOD;a%=p;if(!a) return 0;ll pr=1;while(b>0){if(b&1){pr*=a;pr%=p;--b;}a*=a;a%=p;b/=2;}return pr;}
bool isPrime(ll n){ if(n<=1)return false;if(n<=3)return true;if(n%2==0 or n%3==0)return false;for(ll i=5;i*i<=n;i+=6){if(n%i==0 or n%(i+2)==0)return false;}return true;}
void seive(bool a[]){ll mx=sqrt(N),ii,jj;for(ii=3;ii<=mx;ii+=2)if(!a[ii])for(jj=ii*ii;jj<=N;jj+=2*ii)a[jj]=true;}
void numofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]++; else a[jj]+=2;}}}
void sumofdiv(ll a[]){ll mx=sqrt(N),ii,jj;for(ii=1;ii<=mx;ii++){for(jj=ii*ii;jj<=N;jj+=ii){if(jj==ii*ii) a[jj]+=ii; else a[jj]+=ii+jj/ii;}}}

///**************************************************** C o d e ****************************************************///
///-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=///



void _case()
{
    ll n,d;
    cin>>n>>d;
    d*=2;
    d++;
    cout<<(n+d-1)/d el;

}

main()
{
//      fastio();
        _case();

}


///Thank you.


///Brainless_Loco Terminates Here!


Measured memory_bytes: 3600
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
#define filein freopen("input.txt","r",stdin)
#define fileout freopen("output.txt","w",stdout)
using namespace std;
int n;
int  main()
{
    scanf("%d",&n);
    int ans=0;
    ll a=0;
    while(n--)
    {
        int x;
        scanf("%d",&x);
        if(x>=a)
        {
            ans++;
            a=x;
        }
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#! /usr/bin/python
# -*- coding: utf-8 -*-

n = int(raw_input())

while n != 0:
    cnt = 0
    for i in range(1, n/2+1):
        sum = 0
        for j in range(i, n):
            sum += j
            if sum > n:
                break
            elif sum == n:
                cnt += 1
                break
    print cnt
    n = int(raw_input())

Measured memory_bytes: 4228
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <random>

using namespace std;

const int N = 2e5 + 7;

vector<int> g[N];
vector<int> v1;
vector<int> v2;

void dfs(int cur, int p, int cd) {
	if (cd % 2 == 0) v1.push_back(cur);
	else v2.push_back(cur);
	for (auto t : g[cur]) {
		if (t != p) dfs(t, cur, cd + 1);
	}
}

int n;

int cnt[3];
int ans[N];

signed main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);

	mt19937 rng(3);

	cin >> n;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		u--;	
		v--;
		g[u].push_back(v);
		g[v].push_back(u);
	}
	for (int i = 1; i <= n; i++) cnt[i % 3]++;
	dfs(0, -1, 0);
	if (v1.size() > v2.size()) swap(v1, v2);
	if ((int)v1.size() <= cnt[0]) {
		fill(ans, ans + n, -1);
		for (auto t : v1) {
			ans[t] = 0;
			cnt[0]--;
		}
		for (int i = 0; i < n; i++) {
			if (ans[i] == -1) {
				for (int j = 0; j < 3; j++) {
					if (cnt[j] > 0) {
						ans[i] = j;
						cnt[j]--;
						break;
					}
				}
			}
			assert(ans[i] != -1);
		}
	} else {
		assert(cnt[2] <= (int)v1.size());
		assert(cnt[1] <= (int)v2.size());
		fill(ans, ans + n, 0);
		for (int i = 0; i < cnt[2]; i++) {
			ans[v1[i]] = 2;
		}
		for (int i = 0; i < cnt[1]; i++) {
			ans[v2[i]] = 1;
		}	
	}
	vector<int> pnt = {3, 1, 2};
	for (int i = 0; i < n; i++) {
		auto t = ans[i];
		cout << pnt[t % 3] << ' ';
		pnt[t % 3] += 3;
	}
	cout << endl;
}


Measured memory_bytes: 21620
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

fn main() {
    let (N, K) = read!(usize, usize);
    let A = read![[usize]];

    let mut freq = vec![0; N + 1];
    for a in A {
        freq[a] += 1_usize;
    }

    freq.sort();

    let count = N - freq.iter().rev().take(K).sum::<usize>();

    println!("{}", count);
}


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

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;cin>>n;
  vector<int> a(n);
  rep(i,n)cin>>a[i];
  sort(all(a));
  int mini=1e9;
  for(int i=a[0];i<=a[n-1];i++){
      int tmp=0;
      for(int j=0;j<n;j++){
          tmp+=(a[j]-i)*(a[j]-i);
      }
      mini=min(mini,tmp);
  }
  cout<<mini<<endl;
  return 0;
  }


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

#define int long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define REP(i, n) for (int i = 0; i < n; ++i)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x) cout << #x << ' ' << '=' << ' ' << (x) << endl;
#define fs first
#define sc second
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;
typedef vector<ll> vec;
typedef vector<P> pvec;
typedef vector<vector<ll>> vvec;
typedef vector<vector<P>> pvvec;
typedef priority_queue<ll> PQI;
typedef priority_queue<P> PQP;
typedef priority_queue<ll,vector<ll>,greater<ll>> PQIG;
typedef priority_queue<P,vector<P>,greater<P>> PQPG;

const vector<int> dx = {0, -1, 0, 1, 1, 1, -1, -1};
const vector<int> dy = {1, 0, -1, 0, 1, -1, 1, -1};
constexpr int MOD = (1000000007);
// const int MOD = (998244353);
// const int INF = (1 << 30); // 1073741824
const int INF = (1LL << 60); // 1152921504606846976
const double EPS = (1 >> 30);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b; return 1;} return 0;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b; return 1;} return 0;}
template<class T> inline T ceil(T a, T b) {return T((a + b - 1)/b);}
template< typename T1, typename T2 > istream &operator>>(istream &is, pair< T1, T2 > &p) { is >> p.first >> p.second; return is; }

int nmax=200000; // 2*(10^5)
vvec g(nmax);



signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(15);
    //---------------------------------------------
    
    int s;
    cin>>s;

    int v=1000000000;
    int x=(v-s%v)%v;
    int y=(s+x)/v;

    cout<<"0 0 1000000000 1 "<<x<<" "<<y<<endl;
    
}

Measured memory_bytes: 4992
#!/usr/bin/env python3
#ABC84 C

n = int(input())

csf = [list(map(int,input().split())) for _ in range(n-1)]

for i in range(n):
    now = 0
    for j in range(i,n-1):
        c,s,f = csf[j]
        if now >= s:
            now += (s - now) % f + c
        else:
            now = c + s
    print(now)



Measured memory_bytes: 42092
import fractions
import functools

N, K = [int(i) for i in input().split()]
A = [int(i) for i in input().split()]
maximum = max(A)
lcm = functools.reduce(lambda a, b: fractions.gcd(a, b), A)
if K % lcm == 0 and K <= maximum:
    ans = "POSSIBLE"
else:
    ans = "IMPOSSIBLE"
print(ans)


Measured memory_bytes: 88172
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <map>
#include <cstdlib>
#include <math.h>

using namespace std;

typedef long long ll;
#define rep(i, n) for(long (i) = 0; (i) < (long) (n); (i)++)
#define rep1(i,n) for(int i=1;i<=(n);i++)
#define rrep(i,a,b) for(long i=(a);i<(b);i++)
#define rrep1(i,a,b) for(long i=(a);i<=(b);i++)
#define rrrep(i,a,b) for(long i=(a);i>=(b);i--)
#define define pb push_back
#define ALL(obj) (obj).begin(), (obj).end()
#define X first
#define Y second
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vector<int> >
#define vpl vector<pair<long, long> >
#define vppl vector<pair<long, pair<long, long> > >

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
const ll LINF = 1e18;


int pow(int x) {
	if (x == 0) {
		return 1;
	}
	else {
		return pow(x - 1) * 2;
	}
}

int ans;

int printAns() {
    cout << ans << endl;
    return 0;
}

int main(int argc, char const *argv[])
{
    int a,b;
    cin >> a >> b;
    ans = a * b;
    printAns();
    return 0;
}


Measured memory_bytes: 3588
import sys
def input(): return sys.stdin.readline().rstrip()
sys.setrecursionlimit(10 ** 7)

N = int(input())

def chk(K):
    n = N
    while n >= K:
        if n%K:
            n %= K
        else:
            n //= K
    if n == 1:
        return True
    else:
        return False

ans = set([N-1, N])

for i in range(2, int(N**0.5)+1):
    if N%i==0:
        if chk(i):
            ans.add(i)
        j = N//i
        if chk(j):
            ans.add(j)
    elif (N-1)%i==0:
        if chk(i):
            ans.add(i)
        j = (N-1)//i
        if chk(j):
            ans.add(j)

# print(ans)
if N == 2:
    print(1)
else:
    print(len(ans))

Measured memory_bytes: 40940
N=int(input())
H=[int(i) for i in input().split()]
S=sum(H)
ans=0
while S>0:
    for i in range(N):
        if H[i]>0:
            break
    for j in range(i,N):
        if H[j]==0:
            break
    if j==N-1 and H[j]>0:
        j+=1
    for k in range(i,j):
        H[k]-=1
    ans+=1
    S-=j-i
print(ans)
    

Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define se second
#define fi first
#define ll long long int
#define INF INT_MAX
#define mod
#define chutiyaap ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
using namespace std;
bool sortbysec(const pair<ll,ll> &a,const pair<ll,ll> &b){return (a.second < b.second);}
ll gcd(ll a, ll b){if(a==0)return b;return gcd(b % a, a);}
int main()
{
	chutiyaap;
	ll n,d;cin>>n>>d;
	ll res=0;
	for(ll i=d+1;i<=n+d;i+=2*d+1)
	{
		res++;
	}
	cout<<res;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <algorithm>
#include <map>
#include <fstream>
#include <bitset>

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> ii;
typedef vector<ii> vii;
typedef tuple<int, int, int> iii;
typedef vector<iii> viii;
typedef priority_queue<int> pqi;
typedef priority_queue<ii> pqii;
typedef map<int, int> mii;
typedef map<int, string> mis;
typedef map<string, int> msi;
typedef set<int> si;
typedef set<ll> sl;
typedef map<ll, ll> mll;
typedef queue<int> qi;
typedef queue<ii> qii;
typedef vector<string> vs;
typedef pair<ll, ll> iil;
typedef vector<iil> viil;
typedef vector<vi> vvi;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define rep(i, n) for (int i = 0 ; i < n ; i++)
#define INF 1000000000

void solve() {
    int n, m, k;
    cin >> n >> m >> k;
    bool mat[n][m];
    rep(i, n) {
        rep(j, m) {
            char c;
            cin >> c;
            if (c == '#') {
                mat[i][j] = true;
            }
            else {
                mat[i][j] = false;
            }
        }
    }
    int tt = 0;
    rep(i, n) {
        rep(j, m) {
            if (mat[i][j]) tt++;
        }
    }
    int c = 0;
    bool seen[5000];
    memset(seen, false, sizeof seen);
    rep(i, (1<<(n+m))) {
        //if (i != 6) {
        //    continue;
        //}
        int tk = 0;
        int nm = 0;
        string s = "";
        bool used[n][m];
        memset(used, false, sizeof used);
        for (int j = 0 ; j < n ; j++) {
            if (((1<<j)&i)) {
                rep(k, m) {
                    if (mat[j][k]) used[j][k] = true;
                }
            }
        }
        for (int j = n ; j < n + m ; j++) {
            if (((1<<j)&i)) {
                rep(k, n) {
                    if (mat[k][j - n]) used[k][j - n] = true;
                }
            }
        }
        //cout << ct << " " << nm << endl;
        int ct = 0;
        
        rep(i, n) {
            string st = "";
            rep(j, m) {
                if (mat[i][j] && used[i][j]) {
                    ct++;
                }
            }
            
        }
        if (tt-ct==k) {
            //cout << i << endl;
            c++;
        }
    }
    cout << c << '\n';
}

void querySolve() {
    int n;
    cin >> n;
    while (n--) {
        solve();
    }
}

int main() {
    //querySolve();
    solve();

}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#pragma GCC optimize ("Ofast")
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

using namespace __gnu_pbds;
using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define fbo find_by_order
#define ook order_of_key
 
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<long long,long long> ii; 	
typedef complex<long double> com;

const ll mod = 1e9+7;

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
   ll a,b;
   cin >> a >> b;
   for (int z=0;z<=100;z++){
      for (int x=0;x<=100;x++){
         if (z+x == a && 2*z+4*x == b){
            cout << "Yes" << endl;
            return 0;
         }
      }
   }
   cout << "No" << endl;
} 

Measured memory_bytes: 3604
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
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; }
template<typename T> T gcd(T a,T b){return b?gcd(b,a%b):a;}
const LL mod=1000000007;
const LL LINF=1LL<<62;
const int INF=1<<30;
int dx[]={1,0,-1,0,1,-1,1,-1};
int dy[]={0,1,0,-1,1,-1,-1,1};



template< typename T >
struct BinaryIndexedTree{

    //0-indexed
    vector< T > bit;

    BinaryIndexedTree(int sz){
        bit.assign(sz, 0);
    }

    //[0,k)までの総和を返す
    T sum(int k){
        T ret = 0;
        for (--k; k >= 0; k = (k&(k+1))-1) ret += bit[k];
        return ret;
    }
    
    //[l,r)の総和を返す
    T sum(int l, int r){
        return sum(r) - sum(l);
    }

    //kにx加算する
    void add(int k, T x){
        for (; k < bit.size(); k |= k+1) bit[k] += x;
    }
};

int main(){
    LL n,q;cin >> n >> q;
    vector<LL> a(n), l(n + 1, -1);
    BinaryIndexedTree<LL> bit(n + 1);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }
    vector<pair<P,int>> v(q);
    for (int i = 0; i < q; i++) {
        cin >> v[i].fs.sc >> v[i].fs.fs;
        v[i].fs.sc--, v[i].fs.fs--;
        v[i].sc = i;
    }
    sort(ALL(v));
    int now = 0;
    vector<LL> ans(q);
    for (int i = 0; i < q; i++) {
        while(now <= v[i].fs.fs){
            if(l[a[now]] != -1) bit.add(l[a[now]], -1);
            bit.add(now, 1);
            l[a[now]] = now;
            now++;
        }
        ans[v[i].sc] = bit.sum(v[i].fs.sc, v[i].fs.fs + 1);
    }
    for (int i = 0; i < q; i++) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 31128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define N 10000
int max,S[N];
void sonyou(int x){
  S[++max]=x;
}
int ketunyou(){
  return S[max--];
}
int main(){
  int a,b;
  char s[N];
  max=0;
  while(scanf("%s",s)!=EOF){
    if(s[0]=='+'){
      b=ketunyou();
      a=ketunyou();
      sonyou(a+b);
    }
    else if (s[0]=='-'){
      b=ketunyou();
      a=ketunyou();
      sonyou(a-b);
    }
    else if(s[0]=='*'){
      b=ketunyou();
      a=ketunyou();
      sonyou(a*b);
    }
    else {
      sonyou(atoi(s));
    }
  }
  printf("%d\n",ketunyou());
  return 0;
}


Measured memory_bytes: 2080
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;
 
public class Main {
 
    void solve() throws IOException {
        int H1 = ni();
        int M1 = ni();
        int H2 = ni();
        int M2 = ni();
        int K = ni();
        
        int ans = H2*60+M2 - (H1*60+M1) -K;
        out.println(ans);
    }

 
    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }
 
    int ni() throws IOException {
        return Integer.parseInt(ns());
    }
 
    long nl() throws IOException {
        return Long.parseLong(ns());
    }
 
    double nd() throws IOException {
        return Double.parseDouble(ns());
    }
 
    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }
 
    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }
 
    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }
 
    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;
 
    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 32976
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stdio.h>
#include <stdlib.h>

using namespace std;
//DP用
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;
}
const long long INF = 1LL << 60;

int count(int i,int c) {
    if(i % c == 0) {
        return i/c;
    }else {
        return i/c+1;
    }
}

int main() {
    int n;
    cin >> n;
    int l[n],r[n];
    for(int i = 0; i < n; i++) {
        cin >> l[i] >> r[i];
    }
    int seat[100000] = {};
    int count = 0;
    for(int i = 0; i < n; i++) {
        for(int j = l[i]- 1; j < r[i]; j++) {
            seat[j] = 1;
        }
    }
    for(int i = 0; i < 100000; i++) {
        if(seat[i] == 1) {
            count++;
        }
    }
    cout << count;
    return 0;
}



Measured memory_bytes: 640
import java.util.Scanner;

public class Main {
	public static void main(String []args){
		//????????£?????????????????????
		Scanner sc = new Scanner(System.in);
		//??°?????????
		while(true){
			//??????????????????
			int H = sc.nextInt();
			//?¨????????????????
			int W = sc.nextInt();	
			//?????¶??? ????????¨???0?????´?????????
			if(H == 0 && W ==0){
				break;
			}
			//?¨?????????°?????????
			for(int i = 0; i < H; i++){
			//???????????°?????????
				for(int j = 0; j < W; j++){
					System.out.print("#");
				}
				System.out.println("");
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 32440
import math
def main():
    N, K = map(int, input().split())
    l = [0] * (math.ceil(math.log2(K)) + 1)
    t = 2
    for i in range(len(l)):
        l[i] = t * 1/2
        t = l[i]
    p = 0
    for i in range(1, min(K, N+1)):
        p += l[math.ceil(math.log2(K/i))]
    p += max(N-K + 1, 0)
    p /= N
    return p

print(main())


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;

  int cur_y = 0, cur_x = 0;
  while (n--) {
    int t, x, y;
    cin >> t >> x >> y;

    int distance = abs(y - cur_y) + abs(x - cur_x);
    if (distance > t || (distance & 1) != (t & 1)) {
      cout << "No" << endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
using namespace std;

#define ll long long
#define pb push_back

int main(){

	int N;
	vector<int> P;

	cin >> N;
	for(int i = 0; i < N; i ++){
		int p;
		cin >> p;
		P.pb(p);
	}
	sort(P.begin(), P.end());
	int sum = 0;
	for(int i = 0; i < N; i ++){
		sum += P[i];
	}
	sum -= P[N - 1] / 2;

	cout << sum << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<cctype>
using namespace std;
template <class code>inline code read(const code &a)
{
    code x=0;short w=0;char ch=0;
    while(!isdigit(ch)) {w|=ch=='-';ch=getchar();}
    while(isdigit(ch)) {x=(x<<3)+(x<<1)+(ch^48);ch=getchar();}
    return w?-x:x;
}
int a[1005];
int main()
{
	int n=read(n),ans=0;
	for(int i=1;i<=2*n;i++)a[i]=read(a[i]);
	sort(a+1,a+2*n+1);
	for(int i=1;i<=2*n;i+=2)ans+=a[i];
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 128