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

using namespace std;

typedef pair<int,int>   II;
typedef vector< II >      VII;
typedef vector<int>     VI;
typedef vector< VI > 	VVI;
typedef long long int 	LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(),a.end()
#define SET(a,b) memset(a,b,sizeof(a))
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

#define si(n) scanf("%d",&n)
#define dout(n) printf("%d\n",n)
#define sll(n) scanf("%lld",&n)
#define lldout(n) printf("%lld\n",n)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif

//FILE *fin = freopen("in","r",stdin);
//FILE *fout = freopen("out","w",stdout);

const int N = 1e5 + 10;
VI g[N];
int ans;
bool dfs(int x, int p){
  int numBad = 0;
  int numChild = 0;
  for(auto y : g[x]){
    if(y == p)continue;
    if(!dfs(y, x)){
      numBad++;
    }
    numChild++;
  }
  ans += max(0, numBad - 1);
  if(numChild > 1)return true;
  if(numChild == 1)return 1 - numBad;
  return false;
}
int main()
{
  int n;si(n);
  REP(i, n - 1){
    int x, y;
    si(x);si(y);
    g[x].PB(y);
    g[y].PB(x);
  }
  int root = 0;
  REP(i, n)if(SZ(g[i]) > 2){
    root = i;
  }
  if(SZ(g[root]) <= 2){
    puts("1");
    return 0;
  }
  dfs(root, root);
  dout(max(1, ans));
	return 0;
}

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

int main(){
    int a,b;
    
    cin >> a >> b;
    
    if(a < b){
        cout << "a < b" << endl;
    }else if(a > b){
        cout << "a > b" << endl;
    }else{
        cout << "a == b"<< endl;
    }
   
    
    return 0;
}
 


Measured memory_bytes: 3072
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
#define ff first
#define ss second
#define pb push_back
#define pf push_front
#define mp make_pair
#define pu push
#define pp pop_back
#define in insert
#define ld long double
#define endl '\n'
#define debug cout << "Hold right there sparky.....\n";
#define forn(low,high,i) for(i=low;i<high;i++)
#define forrev(high,low,i) for(i = high; i>= low;i--)
#define trace(x) cerr << #x << ": " << x << " " << endl;
 
typedef long long int ll;
void hack(ll n)
{
    if(n==124)
    cout<<"hacked";   
}
ll gcd(ll a,ll b)
{
    if(b==0) return a;
    else return gcd(b,a%b);
}
ll mod=998244353;
ll mod1=1e9+6;
#define int ll
ll power(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0) return power(a*a%mod,b/2);
    else return a*power(a*a%mod,b/2)%mod;
}
ll power1(ll a,ll b)
{
    if(b==0) return 1;
    else if(b%2==0) return power(a*a%mod1,b/2);
    else return a*power(a*a%mod1,b/2)%mod1;
}
void show(vector <pair<int,int>> v)
{
    for(int i=0;i<v.size();++i) cout<<v[i].first<<" "<<v[i].second<<" ";
        cout<<endl;
}
#define endl '\n'


int32_t main()
{
    IOS
   
 
    int n;
    cin>>n;
    vector<string> v;
    for(int i=0;i<n;++i)
    {
        string s;
        cin>>s;
        sort(s.begin(),s.end());
        v.push_back(s);
    }
    sort(v.begin(),v.end());
    int ans=0;
    for(int i=0;i<v.size();++i)
    {
        int count=0;
        for(int j=i;j<v.size();++j)
        {
            if(v[j]==v[i])
            {
                count++;
                if(j==v.size()-1)
                    i=v.size()-1;
            }
            else
            {
                i=j-1;
                break;
            }
        }
        ans+=((count)*(count-1))/2;
    }
    cout<<ans;
}


Measured memory_bytes: 7796
import java.util.Scanner;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        while (sc.hasNext()) {
            int n = sc.nextInt();
            if (n == 0) {
                break;
            }
            int[] aa = new int[n];
            int[] ab = new int[n];
            int sa = 0;
            int sb = 0;
            for (int i = 0; i < n; i++) {
                int a = sc.nextInt();
                int b = sc.nextInt();
                if (a > b) {
                    sa = sa + a + b;
                } else if (b > a) {
                    sb = sb + a + b;
                } else if (a == b) {
                    sa += a;
                    sb += b;
                }
            }
            System.out.println(sa + " " + sb);
        }
    }
}

Measured memory_bytes: 58892
import sys
N,K=map(int,input().split())
X=[int(i) for i in input().split()]
A=[]
B=[]
for x in X:
    if x<0:
        A.append(x)
    else:
        B.append(x)
ans=10**18
a=len(A)
b=len(B)
if a==0:
    print(B[K-1])
    sys.exit()
if b==0:
    print(abs(A[-K]))
    sys.exit()
for i in range(max(1,K-b),a+1):
    if i>=K:
        ans=min(ans,abs(A[-i]))
        continue
    ans = min(ans,2*abs(A[-i])+B[K-i-1])
for i in range(max(0,K-a-1),b):
    if i>=K-1:
        ans=min(ans,abs(B[i]))
        continue
    ans=min(ans,2*abs(B[i])+abs(A[-K+i+1]))
print(ans)

Measured memory_bytes: 14224
#include "bits/stdc++.h"
using namespace std;
int main() {
	int N;
	cin >> N;
	vector<long long>A(N);
	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
	}
	sort(A.begin(), A.end(), greater<int>());
	int m = A.at(0), n;
	long double ave = double(m / 2);
	long double s = 9e9;
	for (int i = 1; i < N; i++) {
		if (abs(ave - double(A.at(i))) < s) {
			n = A.at(i);
			s = abs(ave - double(A.at(i)));
		}
	}
	cout << m << ' ' << n << endl;
}

Measured memory_bytes: 1024
import heapq

X, Y, A, B, C = map(int, input().split())
p = list(map(int, input().split()))
q = list(map(int, input().split()))
r = list(map(int, input().split()))
p.sort(reverse=True)
q.sort(reverse=True)
p = p[:X]
q = q[:Y]
all_apples = p + q + r
all_apples.sort(reverse=True)
print(sum(all_apples[:X+Y]))

Measured memory_bytes: 23456
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <cstring>
#include <numeric>
#include <cstdlib>
#include <cmath>

#define INF 10e10
#define REP(i,n) for(int i=0; i<n; i++)
#define REP_R(i,n,m) for(int i=m; i<n; i++)
#define MAX 100

using namespace std;

typedef long long ll;
typedef pair<ll,ll> P;

ll N, K;
std::vector<P> data;

int main() {
  P vec;
  cin >> N >> K;
  REP(i,N) {
    scanf("%lld %lld", &vec.first, &vec.second);
    data.push_back(vec);
  }

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

  ll total = 0;
  ll ans;
  bool flag = false;
  for (auto itr = data.begin(); itr != data.end(); itr++) {
    total += itr->second;
    if (K <= total) {
      ans = itr->first;
      flag = true;
    }
    if (flag) break;
  }

  printf("%lld\n", ans);
}


Measured memory_bytes: 2420
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace B
{
    public class IO
    {
        public static string ReadStr() => Console.ReadLine();
        public static string[] ReadStrArr() => ReadStr().Split(' ');
        public static int ReadInt() => int.Parse(ReadStr());
        public static int[] ReadIntArr() => Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        public static double ReadDouble() => double.Parse(ReadStr());
        public static double[] ReadDoubleArr() => Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
        public static long ReadLong() => long.Parse(ReadStr());
        public static long[] ReadLongArr() => Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
    }

    class Frog2
    {
        const long INF = long.MaxValue;
        const int SIZE = 100000;

        static void Fill<T>(out T[] array, T value, int count) 
            => array = Enumerable.Repeat(value, count).ToArray();

        public static void Main(string[] args)
        {
            int[] inp = IO.ReadIntArr();
            int n = inp[0];
            int k = inp[1];

            int[] bh = IO.ReadIntArr();
            int[] h = new int[n + k + 1];

            Array.Copy(bh, 0, h, 0, n);
            int[] dp = new int[n + k + 1];

            for (int i = 1; i < n; i++) dp[i] = 999999999;
            for (int i = 0; i < n; i++)
            {
                for (int j = 1; j <= k; j++)
                    dp[i + j] = Math.Min(dp[i + j], Math.Abs(h[i] - h[i + j]) + dp[i]);
            }
            Console.WriteLine(dp[n - 1]);
        }
    }
}


Measured memory_bytes: 19680
using System;
using System.Linq;

namespace B___Two_Switches
{
    class Program
    {
        static void Main(string[] args)
        {
            var A_B_C_D = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var AB = Enumerable.Range(A_B_C_D[0], A_B_C_D[1] - A_B_C_D[0] + 1).ToArray();
            var CD = Enumerable.Range(A_B_C_D[2], A_B_C_D[3] - A_B_C_D[2] + 1).ToArray();

            Console.WriteLine(AB.Intersect(CD).Any() ? Math.Max(0, AB.Intersect(CD).Count() - 1) : 0);
        }
    }
}


Measured memory_bytes: 13404
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<int, ll> pli;
typedef pair<double,double> pdd;
#define SQ(i) ((i)*(i))
#define MEM(a, b) memset(a, (b), sizeof(a))
#define SZ(i) int(i.size())
#define FOR(i, j, k, in) for (int i=j ; i<k ; i+=in)
#define RFOR(i, j, k, in) for (int i=j ; i>=k ; i-=in)
#define REP(i, j) FOR(i, 0, j, 1)
#define REP1(i,j) FOR(i, 1, j+1, 1)
#define RREP(i, j) RFOR(i, j, 0, 1)
#define ALL(_a) _a.begin(),_a.end()
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define X first
#define Y second
#ifdef tmd
#define TIME(i) Timer i(#i)
#define debug(...) do{\
    fprintf(stderr,"%s - %d (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
    _do(__VA_ARGS__);\
}while(0)
template<typename T>void _do(T &&_x){cerr<<_x<<endl;}
template<typename T,typename ...S> void _do(T &&_x,S &&..._t){cerr<<_x<<" ,";_do(_t...);}
template<typename _a,typename _b> ostream& operator << (ostream &_s,const pair<_a,_b> &_p){return _s<<"("<<_p.X<<","<<_p.Y<<")";}
template<typename It> ostream& _OUTC(ostream &_s,It _ita,It _itb)
{
    _s<<"{";
    for(It _it=_ita;_it!=_itb;_it++)
    {
        _s<<(_it==_ita?"":",")<<*_it;
    }
    _s<<"}";
    return _s;
}
template<typename _a> ostream &operator << (ostream &_s,vector<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,set<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a> ostream &operator << (ostream &_s,deque<_a> &_c){return _OUTC(_s,ALL(_c));}
template<typename _a,typename _b> ostream &operator << (ostream &_s,map<_a,_b> &_c){return _OUTC(_s,ALL(_c));}
template<typename _t> void pary(_t _a,_t _b){_OUTC(cerr,_a,_b);cerr<<endl;}
#define IOS()
class Timer {
private:
    string scope_name;
    chrono::high_resolution_clock::time_point start_time;
public:
    Timer (string name) : scope_name(name) {
        start_time = chrono::high_resolution_clock::now();
    }
    ~Timer () {
        auto stop_time = chrono::high_resolution_clock::now();
        auto length = chrono::duration_cast<chrono::microseconds>(stop_time - start_time).count();
        double mlength = double(length) * 0.001;
        debug(scope_name, mlength);
    }
};
#else
#define TIME(i)
#define debug(...)
#define pary(...)
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
#endif

const ll MOD = 1000000007;
const ll INF = 0x3f3f3f3f3f3f3f3f;
const int iNF = 0x3f3f3f3f;
// const ll MAXN = 

/********** Good Luck :) **********/
int main () {
    TIME(main);
    IOS();
    int a, b;
    cin >> a >> b;
    cout << max(0, a-2*b) << endl;
    return 0;
}


Measured memory_bytes: 256
def partition(A, p, r):
    """
    ???????????????????????????????????????A[r]?????°?????????????????????????????????????????????A[r-1]??¨?´??????????????????§??¨???
    """
    x = A[r]
    i = p - 1
    for j in range(p, r):
        if A[j] <= x:
            i += 1
            temp = A[i]
            A[i] = A[j]
            A[j] = temp
    temp = A[i+1]
    A[i+1] = A[r]
    A[r] = temp
    return i+1


if __name__ == '__main__':
    # ??????????????\???
    # A = [13, 19, 9, 5, 12, 8, 7, 4, 21, 2, 6, 11]
    num_of_data = int(input())
    A = [int(x) for x in input().split(' ')]

    # ???????????????
    p = partition(A, 0, len(A)-1)  # ????????????????????????????????????len(A)??§?????????-1???????????????????????????

    # ???????????¨???
    left = A[:p]
    partition = A[p]
    right = A[p+1:]
    print('{0} [{1}] {2}'.format(' '.join(map(str, left)), partition, ' '.join(map(str, right))))

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

#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define ll long long

using namespace std;

signed main() {
  IOS;
  int A,P, ans;
  cin >> A >> P;
  cout << (A*3+P) / 2<< endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stack>
#include <cctype>
#include <algorithm>
#include <vector>
#include <map>
#include <cmath>
#include <stdlib.h>
#include <tuple>
#include <iomanip>
using namespace std;
const double PI = 3.14159265358979323846;



int main() {
	
	double A, B;
	double H, M;
	cin >> A >> B >> H >> M;

	double radM = 2.0 * PI * (M / 60.0);
	
	double radH = 2.0 * PI * (H / 12.0) + 2.0 * PI * (M / 60.0) / 12.0;

	double c1 = sqrt(A * A + B * B - 2.0 * A * B * cos(radM - radH));

	cout << setprecision(15) << c1  << endl;
	return 0;
}

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

int main() {
  int N, sum=0;
  cin >> N;
  vector<int> d(N);
  for(int i=0; i<N; i++) cin >> d.at(i);
  
  for(int i=0; i<N; i++) {
    for(int j=0; j<N; j++) {
      if(i != j) sum += d.at(i)*d.at(j);
    }
  }
  cout << sum/2 << endl;
}

Measured memory_bytes: 3596
use proconio::input;

fn main() {
    input! {
        _: usize,
        t: usize,
        mut a: [i64; t]
    };
    a.sort();
    let mut l = 0;
    let mut r = t - 1;
    while l < r {
        a[l] -= 1;
        a[r] -= 1;
        if a[l] == 0 {
            l += 1;
        }
        if a[r] == 0 {
            r -= 1;
        }
    }
    let ans = std::cmp::max(0, a[l] - 1);
    println!("{}", ans);
}


Measured memory_bytes: 2148
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define jizz ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define pb push_back
#define F first
#define S second
#define MEM(i,j) memset(i,j,sizeof i)
#define ALL(v) v.begin(),v.end()
#define MP make_pair
#define ET cout << "\n"
#define DB(a,s,e) {for(int i=s;i<e;i++) cout << a[i] << " ";ET;}
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

ll dp[1<<16],arr[16][16],w[1<<16];

int main()
{jizz
	ll n,L;
	cin >> n,L=1<<n;
	for(int i=0;i<n;++i)
		for(int j=0;j<n;++j)
			cin >> arr[i][j];
	for(int i=1;i<L;++i)
	{
		for(int j=i&i-1,k=__lg(i&-i);j;j&=j-1)
			w[i]+=arr[k][__lg(j&-j)];
		dp[i]=w[i]+=w[i&i-1];
	}
	for(int i=1;i<L;++i)
	{
		vector<ll> v;
		for(int x=i;x;x&=x-1)
			v.pb(x&-x);
		for(int j=(1<<v.size())-1;j>0;--j)
		{
			ll tmp=0;
			for(int x=j;x;x&=x-1)
				tmp+=v[__lg(x&-x)];
			dp[i]=max(dp[i],dp[i^tmp]+w[tmp]);
		}
	}
	cout << dp[L-1] << "\n";
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
#define all(x) (x).begin(), (x).end()
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = acos(-1);
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

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

	ll n, m;
	cin >> n >> m;
	vll a(m), b(m);
	vector<bitset<12>> c(m);
	for (ll i = 0; i < m; i++) {
		cin >> a[i] >> b[i];
		for (ll j = 0; j < b[i]; j++) {
			ll x;
			cin >> x;
			c[i][x - 1] = 1;
		}
	}

	ll h = pow(2, n);
	vector<vll> dp(h, vll(m, inf));
	for (ll i = 0; i < m; i++) dp[0][i] = 0;
	for (ll i = 1; i < h; i++) {
		for (ll j = 0; j < m; j++) {
			if (j > 0) dp[i][j] = dp[i][j - 1];
			bitset<12> bs(i);
			//cout << bs << endl;
			//cout << c[j] << endl;
			for (ll k = 0; k < 12; k++) {
				if (bs[k] && c[j][k]) bs[k] = 0;
			}
			ll x = bs.to_ullong();
			if (j == 0) {
				if (x > 0) continue;
				else dp[i][j] = a[j];
			}
			else {
				if (dp[x][j - 1] == inf) continue;
				else dp[i][j] = min(dp[i][j], dp[x][j - 1] + a[j]);
			}
			//cout << x << endl;
		}
	}

	if (dp[h - 1][m - 1] == inf) cout << -1 << endl;
	else cout << dp[h - 1][m - 1] << endl;
}


Measured memory_bytes: 32384
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef pair<int,int> pii;
typedef long long ll;
const long long MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,m,n) for(ll i=(m);i<(n);i++)
#define ALL(v) v.begin(), v.end()
#define pb push_back





int main(){



    string s,t;
    cin>>s>>t;

    int ssize=int(s.size());
    int tsize=int(t.size());

    int answer=1000;

    rep(i,ssize-tsize+1){
        int cnt=0;
        rep(j,tsize){
            if (s.at(i+j)!=t.at(j)){
                cnt++;

            }
        }

        if (cnt<=answer){
            answer=cnt;
        }

    }

    cout<<answer<<endl;





}

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

N, M = map(int, input().split())
bridge_m = [list(map(int, input().split())) for _ in range(M)]
# print(bridge_m)

class UnionFind():
    def __init__(self, n):
        self.node = [-1] * n
    
    def is_root(self, nid):
        return self.node[nid] < 0

    def find(self, nid):
        # find group id
        if self.is_root(nid):
            return nid
        else:
            self.node[nid] = self.find(self.node[nid])
            return self.node[nid]

    def is_same_group(self, nid1, nid2):
        return self.find(nid1) == self.find(nid2)

    def size(self, nid):
        return - self.node[self.find(nid)]

    def union(self, nid1, nid2):
        if self.is_same_group(nid1, nid2):
            return

        g1 = self.find(nid1)
        g2 = self.find(nid2)
        if self.size(g1) < self.size(g2):
            self.node[g2] -= self.size(g1)
            self.node[g1] = g2
        else:
            self.node[g1] -= self.size(g2)
            self.node[g2] = g1

uf = UnionFind(N + 1)
ans = [0] * M
ans[M - 1] = int(N * (N - 1) / 2)
g_num = 0
for i in range(M - 1, 0, -1):
    a = bridge_m[i][0]
    b = bridge_m[i][1]

    if uf.is_same_group(a, b):
        ans[i - 1] = ans[i]
    else:
        ans[i - 1] = ans[i] - uf.size(a) * uf.size(b)
        uf.union(a, b)

for i in range(M):
    print(ans[i])


    

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

int main() {
  int n,t;
  cin >> n >> t;
  int a[100000];
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int bene = 0, count = 0, mini = a[0];
  for (int i = 1; i < n; i++) {
    mini = min(mini,a[i]);
    if (a[i] - mini == bene) {
      count++;
    } else if (a[i] - mini > bene) {
      bene = a[i] - mini;
      count = 1;
    }
  }
  cout << count << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <cstring>
#include <queue>
#include <assert.h>
#include <cmath>
#include <deque>
#include <set>
#include <unordered_map>
#include <complex>
#include <fstream>
#include <map>
using namespace std;
using ll = long long;
using ld = long double;
const int mxn = 5e5+10;
int c[mxn];

int block_size;

struct Query {
    int l, r, idx;
};
bool cmp(Query p, Query q) {
    if (p.l / block_size != q.l / block_size)
        return p.l<q.l or (p.l==q.l and p.r<q.r);
    return (p.l / block_size & 1) ? (p.r < q.r) : (p.r > q.r);
}
int ans = 0;
int cnt[mxn];

inline void add(int i) {
	cnt[c[i]]++; if(cnt[c[i]]==1) ans++;
}

inline void remove(int i) {
	cnt[c[i]]--; if(cnt[c[i]]==0) ans--;
}

inline int get_answer() {
	return ans;
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

	int n, Q; cin>>n>>Q; for(int i=0; i<n; i++) cin>>c[i];
	vector<Query> queries(Q);
	block_size = ceil(sqrt(n))+10;
	for(int i=0; i<Q; i++) {
		cin>>queries[i].l>>queries[i].r; queries[i].idx = i;
		queries[i].l--; queries[i].r--;
	}
	vector<int> answers(Q, 0);
	sort(begin(queries), end(queries), cmp);
	int cur_l = 0;
    int cur_r = -1;
    for (Query q : queries) {
        while (cur_l > q.l) {
            cur_l--;
            add(cur_l);
        }
        while (cur_r < q.r) {
            cur_r++;
            add(cur_r);
        }
        while (cur_l < q.l) {
            remove(cur_l);
            cur_l++;
        }
        while (cur_r > q.r) {
            remove(cur_r);
            cur_r--;
        }
        answers[q.idx] = get_answer();
    }

    for(int i=0; i<Q; i++) {
    	cout << answers[i] << '\n';
    }

	return 0;
}

Measured memory_bytes: 15468
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
const int INF=1145141919,MOD=1e9+7;
const int64_t LINF=8931145141919364364,LMOD=998244353;
// const int dy[]={0,-1,0,1,1,-1,-1,1};
// const int dx[]={1,0,-1,0,1,1,-1,-1};

map<string, int> mp;
int main() {
	int n; cin >> n;
	int cnt = 0;
	while(n--) {
		string s; cin >> s;
		++mp[s];
		cnt = max(cnt, mp[s]);
	}
	set<string> st;
	for(auto e : mp) {
		if(e.second == cnt) {
			st.insert(e.first);
		}
	}
	for(auto s : st) {
		cout << s << '\n';
	}
	return 0;
}

Measured memory_bytes: 34560
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<cstdint>
#include<cstddef>
#include<vector>
#include<set>
#include<string>
#include<algorithm>
using namespace std;
using i32 = int_fast32_t;
using i64 = int_fast64_t;
using usize = uint_fast64_t;
#define rep(i, n) for (usize i = 0; i < (usize)(n); i++)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
using P = pair<i64,i64>;

int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
string s;
cin >> s;
vector<string> rec;
set<char>st;
i32 n = s.size();
rep(i,n){
    string k = s.substr(0,i + 1);
    //cout << k << endl;
    st.insert(k.back());
    rep(j,26){
        char l = 97 + j;
        if(!st.count(l)){
            rec.emplace_back(k + l);
        }
        string f;
        f = f + l;
        rec.emplace_back(f);
    }
}
rec.emplace_back(s);
sort(all(rec));
rec.erase(unique(all(rec)),rec.end());
if(rec.back() == s){
    cout << -1 << endl;
}
else{
    rep(i,rec.size()){
        if(rec[i] == s){
            cout << rec[i + 1] << endl;
            break;
        }
    }
}
}

Measured memory_bytes: 3652
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
	int e,y;
	cin>>e>>y;
	if(e==0){
		if(1868<=y&&y<=1911) cout<<'M'<<y-1867<<endl;
		if(1912<=y&&y<=1925) cout<<'T'<<y-1911<<endl;
		if(1926<=y&&y<=1988) cout<<'S'<<y-1925<<endl;
		if(1989<=y&&y<=2016) cout<<'H'<<y-1988<<endl;
	}
	if(e==1) cout<<1867+y<<endl;
	if(e==2) cout<<1911+y<<endl;
	if(e==3) cout<<1925+y<<endl;
	if(e==4) cout<<1988+y<<endl;
	return 0;
}

Measured memory_bytes: 3104
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		String t = sc.next();
		int cnt = 0;
		for (int i = 0, f = s.length(); i < f; ++i) {
			if (s.charAt(i) != t.charAt(i)) {
				++cnt;
			}
		}
		System.out.println(cnt);
	}

}


Measured memory_bytes: 41096
import java.math.BigInteger;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import java.util.PriorityQueue;
import java.util.Scanner;

class Main {
    static final int MOD = 1000000007;
    static final int INF = 1 << 30;
    static final int ALF = 26;

    Main() {
        Scanner sc = new Scanner(System.in);
        int R = sc.nextInt();
        System.out.println(R*R);
    }

    public static void main(String[] args) {
        new Main();
    }
}


Measured memory_bytes: 23892
for i in range(1000):
    n = int(input())
    if n == 0:
        exit()
    s = list(map(int,input().split()))
    ave = sum(s) / len(s)
    num = 0
    for j in s:
        num += (j-ave)**2
    num /= len(s)
    print(num**(1/2))


Measured memory_bytes: 5660
#include <bits/stdc++.h>
using namespace std;
const long double PI = acos(-1);
typedef long long ll;
typedef pair<int64_t,int64_t> pll;
int dx[]={1,-1,0,0,1,-1,1,-1};
int dy[]={0,0,1,-1,1,-1,-1,1};
#define INF (2147483647)
#define mod (1000000007)
#define limit (7368791)
#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)
#define ALL(a) begin(a),end(a)
#define sz(s) (s).size()
#define pb push_back
#define mp make_pair
#define fi first
#define se second

 
void solve()
{
    int n;cin>>n;
    int sum=0;
    rep(i,1,n+1)
    {
        string s=to_string(i);
        if(s.size()%2)sum++;
    }
    cout<<sum<<endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

template <class T>
inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}

const ll INF = 1e18;
ll n, m;
vector<ll> dp;
vector<vector<ll>> a;

// S\T
ll setMinus(ll s, ll t) { return s & (t ^ (m - 1)); }
ll cntOnes(ll s) {
  ll res = 0;
  REP(i, n) {
    if ((1LL << i) & s) {
      res++;
    }
  }
  return res;
}

ll calc(ll s) {
  if (dp[s] != -INF) {
    return dp[s];
  }
  // わけない
  ll res = 0;
  REP(i, n) FOR(j, i + 1, n) if (((1LL << i) & s) > 0 && ((1LL << j) & s) > 0) {
    res += a[i][j];
  }

  for (ll t = m - 1; t > 0; t--) {
    t = t & s;
    if (t == s || t == 0) {
      continue;
    }
    ll x = calc(t);
    ll y = calc(setMinus(s, t));
    chmax(res, x + y);
  }
  dp[s] = res;
  return res;
}

int main() {
  cin >> n;
  a = vector<vector<ll>>(n, vector<ll>(n));
  REP(i, n) REP(j, n) { cin >> a[i][j]; }
  m = 1LL << n;
  dp = vector<ll>(m, -INF);
  dp[0] = 0;
  cout << calc(m - 1) << endl;
}

Measured memory_bytes: 768
N = int(input())
a = list(map(int, input().split()))
b = [0]*N
d = 1
r = []
for i in range(N, 0, -1):
  m = 0
  c = 2*i
  while c <= N:
    m += b[c-1]
    c += i
  if m % 2 != a[i-1]:
    b[i-1] = 1
    r.append(i)
print(sum(b))
print(" ".join([str(s) for s in r]))

Measured memory_bytes: 19872
#include <stdio.h>

 int main(void){
 int a[3][10][4] = {0};
 int i, j, k;
 int n, p;
 int b, f, r, v; 

scanf("%d", &n);
 for(i=0; i<n; i++){
 scanf("%d%d%d%d", &b, &f, &r, &v);

 a[f-1][r-1][b-1] += v;
 }

 for(k=0; k<4; k++){
 for(i=0; i<3; i++){
 for(j=0; j<10; j++){
 if(a[i][j][k] == 0){
 printf(" 0");
 }else{
 printf(" %d", a[i][j][k]);
 }
 }
 printf("\n");
 }
 if(k != 3){
 printf("####################\n");
 }
 }

 return 0;
 }


Measured memory_bytes: 2128
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//INSERT ABOVE HERE
signed main(){
  using BS = bitset<32>;
  Int x;
  cin>>x;
  BS b(x);
  cout<<b<<endl;
  cout<<(~b)<<endl;
  cout<<(b<<1)<<endl;
  cout<<(b>>1)<<endl;
  return 0;
}



Measured memory_bytes: 3152
#include <bits/stdc++.h>
using namespace std;
struct edge {
    int to;     // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using Graph = vector<vector<int>>;
using dou =long double;
string Yes="Yes";
string YES="YES";
string NO="NO";
string No="No";
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define res resize
#define as assign
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum(a) accumulate(all(a),0ll)
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
 
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 922337203685477580ll;
const int mod = 1000000007ll;
const ll  MOD = 1000000007LL;
int main(){
    int n,x,y;
    std::cin >> n>>x>>y;
    x--;y--;
    std::vector<int> l(n+1);
    rep(i,n){
        rrep(j,i+1,n){
            if(j<=x){
                l[j-i]++;
            }
            else if(j<=y){
                if(i<=x){
                    int d=min(j-i,(y-j)+1+x-i);
                    
                    l[d]++;
                }
                else {
                    int d=min(j-i,(i-x)+(y-j)+1);
                   // std::cout << (i-x)+(y-j)+1 << std::endl;
                    l[d]++;
                }
            }
            else {
                if(i<=x){
                    l[j-y+x-i+1]++;
                }
                else if(i<=y){
                    int d=min(j-i,(j-y)+1+i-x);
                    l[d]++;
                }
                else l[j-i]++;
            }
      //     std::cout <<i<<" "<<j<< " ";
        //    rep(ii,n+1)std::cout << l[ii] << " ";
          //  std::cout << std::endl;
        }
        
    }
    rrep(i,1,n)std::cout << l[i] << std::endl;
}

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

using namespace std;

    int N, L;
    int sum_N, max_taste, min_taste;

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

    cin >> N >> L;

    sum_N = N * (N + 1) / 2 + N * (L - 1);

    max_taste = L - 1 + N;
    min_taste = L;

    if (max_taste >= 0 && min_taste <= 0)
    {
      cout << sum_N << "\n";      
    }else if(abs(max_taste) < abs(min_taste)){
        cout << sum_N - max_taste << "\n";
    }else{
        cout << sum_N - min_taste << "\n";
    }
    
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <math.h>
#include <random>
#include <time.h>
using namespace std;
int main() {
	string s[100];
	long long int h, w;
	cin >> h >>w;
	for (int i = 0; i < h;i++) {
		cin >> s[i];
	}
	for (int i = 0; i < w+2; i++) {
		cout << "#";
	}
	cout << endl;
	for (int i = 0; i < h; i++) {
		cout << "#" << s[i] << "#" << endl;
	}
	for (int i = 0; i < w + 2; i++) {
		cout << "#";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
 
int main() {
int N;
 
int secsum=0;
 
 
cin >> N;
vector<string> sing(N);
vector<int> sec(N);
 
for(int i=0; i < N; i++){
    cin >> sing.at(i) >> sec.at(i);
    
}
 
string X;
cin >> X;
 
 
for(int j=0; j<N; j++){
 
    if(sing.at(j)==X){
        for(int h=j+1;h<N;h++){
            secsum+=sec.at(h);
        }
        
    }
}
cout << secsum <<endl;
}

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

#define rep(i, n) for(int i=0; i<n; ++i)
#define repit(it, li) for(auto it=li.begin(); it!=li.end(); it++)
#define ll long long int
#define P pair<int, int>

vector<int> bit;
void bitinit(int n){
	bit=vector<int>(n);
}
int bitget(int i){
	if(i== -1) return 0;
	int ii=i+1, j=0;
	while((ii>>j&1)==0)j++;
	return bit[i]+bitget((ii& ~(1<<j))-1);
}
void bitadd(int i, int x){
	if(i>=bit.size()) return ;
	bit[i]+=x;
	int ii=i+1, j=0;
	while((ii>>j&1)==0)j++;
	ii+=(1<<j);
	bitadd(ii-1, x);
}

int main(){
	int n, q;
	cin>>n>>q;
	vector<int> c(n);
	rep(i, n) cin>>c[i];
	vector<vector<P>> qs(n);
	rep(i, q){
		int l, r;
		cin>>l>>r; l--; r--;
		qs[l].push_back(make_pair(r, i)); 
	}

	vector<int> pi(n+1, -1);
	vector<vector<int>> rs(n);
	rep(i, n){
		int p=pi[c[i]];
		if(p!= -1)
			rs[p].push_back(i);
		pi[c[i]]=i;
	}

	vector<int> ans(q);
	bitinit(n);
	for(int l=n-1; l>=0; l--){
		for(int s : rs[l]) bitadd(s, 1);
		for(P p : qs[l]){
			int r=p.first, qi=p.second;
			ans[qi]=(r-l+1)-bitget(r);
		}
	}

	rep(i, q) cout<<ans[i]<<endl;
	return 0;
}


Measured memory_bytes: 60016
#include <iostream>
#include <algorithm>
#include <math.h>
#include <string.h>
#include <cstdio>
#include <vector>
#include <set>
#include <cassert>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <cmath>
#include <ctime>
#include <deque>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <sstream>
#include <functional>
#include <iomanip>
//#include <windows.h>  //Should be deleted when using AtCoder&POJ
using namespace std;

#define ll long long
#define pii pair<int,int>
/**==Info==
*Program:4
*Problem:Symmetric Grid
*Date:2018-4-21
*Algorithm:kawatea's Solution
*Stats:Unknown*/

bool debug=false;

int n,m;
string s[15];
string ss[15];
int a[15],b[15];

void dfs2(int pos,bool mid){
	if(pos==m){
		puts("YES");
		exit(0);
	}
	if(b[pos]!=-1){
		dfs2(pos+1,mid);
		return;
	}
	for(int i=pos+1;i<m;i++){
		if(b[i]!=-1){
			continue;
		}
		int j;
		for(j=0;j<n;j++){
			if(s[j][pos]!=s[a[j]][i]) break;
		}
		
		
		if(j==n){
			b[pos]=i;
			b[i]=pos;
			dfs2(pos+1,mid);
			b[pos]=-1;
			b[i]=-1;
		}
	}
	
	if(!mid){
		int j;
		for(j=0;j<n;j++){
			if(s[j][pos]!=s[a[j]][pos]) break;
		}
		
		if(j==n){
			b[pos]=pos;
			dfs2(pos+1,true);
			b[pos]=-1;
		}
	}
}

void dfs(int pos,bool mid){
	if(pos==n){
		dfs2(0,!m%2);
		return;
	}
	if(a[pos]!=-1){
		dfs(pos+1,mid);
		return;
	}
	for(int i=pos+1;i<n;i++){
		if(a[i]!=-1){
			continue;
		}
		if(ss[i]!=ss[pos]){
			continue;
		}
		
		a[i]=pos;
		a[pos]=i;
		
		dfs(pos+1,mid);
		
		a[pos]=-1;
		a[i]=-1;
	}
	
	if(!mid){
		a[pos]=pos;
		dfs(pos+1,true);
		a[pos]=-1;
	}
}

int main(int argc,char* argv[]){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		cin>>s[i];
		ss[i]=s[i];
		sort(ss[i].begin(),ss[i].end());
	}
	
	memset(a,-1,sizeof(a));
	memset(b,-1,sizeof(b));
	
	dfs(0,!n%2);
	
	puts("NO");
	
	//Atcoder is just a fuck
	return 0;
}



Measured memory_bytes: 764
///Mn kotr el labawy mb2t4 nawy
#include<bits/stdc++.h>

#define ll long long
using namespace std;
const int N = 2e5 + 5;
const int MOD =  998244353;

int main(){
  ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

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

  for(auto & c : s){
    c -= 'A';
    c += n;
    c %= 26;
    c += 'A';
  }
  cout << s << endl;

  return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
    public static void main(String[] args) {
    
    Scanner sc = new Scanner(System.in);
      
      //入力
      int N = sc.nextInt();//数列の長さ
      
      //空箱用意
      HashSet youso = new HashSet();
      
      //要素をlistに追加する(重複なし)
      for(int i =1; i<=N; i++){
      		youso.add(sc.next());
      }
      //list内の数とN が一致しているか
      if((youso.size())==(N)){
      	System.out.println("YES");
      }
      else{
        System.out.println("NO");
      }
    }
}

Measured memory_bytes: 77384
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<bitset>
using namespace std;
//#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;
typedef pair<int,int> P;
struct edge{int to,cost;};
#define REP(i,n) for(int i=0;i<(n);i++)
const int INF=100000000;

int N;
string S;

int main(){
	cin>>N;
	if(N==0){
		cout<<0<<endl;
		return 0;
	}
	while(N!=0){
		if(N%2!=0){
			S.push_back('1');
			N--;
		}
		else{
			S.push_back('0');
		}
		N/=-2;
	}
	reverse(S.begin(),S.end());
	cout<<S<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cctype>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define ll long long
#define imfor(i, n) for(int i = 0; i < n; i++)
using namespace std;
ll MOD = 1000000007;

int main() {
    int n, K;
    cin >> n >> K;
    ll x[60], y[60];
    imfor(i, n) {
        cin >> x[i] >> y[i];
    }
    ll ans = 9223372036854775807;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j || y[i] < y[j]) {
                continue;
            }
            for (int k = 0; k < n; k++) {
                for (int l = 0; l < n; l++) {
                    if (k == l || x[k] > x[l]) {
                        continue;
                    }
                    int cnt = 0;
                    for (int m = 0; m < n; m++) {
                        if (y[m] <= y[i] && y[j] <= y[m] && x[k] <= x[m] && x[m] <= x[l]) {
                            cnt++;
                        }
                    }
                    if (cnt >= K) {
                        ll area = abs(y[i] - y[j]) * abs(x[l] - x[k]);
                        ans = min(ans, area);
                    }
                }
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#ifdef LOCAL
#include "debug.h"
#else
#define dump(...)
#endif
#define endl '\n'
//#define int long long
#define FOR(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define REP(i, x) for (int i = 0; i < (int)(x); i++)
#define REPS(i, x) for (int i = 1; i <= (int)(x); i++)
#define RREP(i, x) for (int i = ((int)(x)-1); i >= 0; i--)
#define RREPS(i, x) for (int i = ((int)(x)); i > 0; i--)
#define INF 2147483647
#define LLINF 9223372036854775807LL
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define BIT(n) (1LL << (n))
#define TOUPPER(s) transform(s.begin(), s.end(), s.begin(), ::toupper)
#define TOLOWER(s) transform(s.begin(), s.end(), s.begin(), ::tolower)
#define FILLZERO(s, n)                      \
    do {                                    \
        ostringstream os;                   \
        os << setw(n) << setfill('0') << s; \
        s = os.str();                       \
    } while (0);
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end()) //sortしてからつかうこと
#define INIT                               \
    std::cin.tie(nullptr);                 \
    std::ios_base::sync_with_stdio(false); \
    cout << std::fixed << std::setprecision(10);

using ll = long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using pi = pair<int, int>;
template <typename T>
using Pq = priority_queue<T>;
template <typename T>
using pQ = priority_queue<T, vector<T>, greater<T>>;

template <typename T>
vector<T> make_vec(size_t a, T n) { return vector<T>(a, n); }
template <typename T, typename... Ts>
auto make_vec(size_t a, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...)); }
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>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec)
        is >> x;
    return is;
}

constexpr ll MOD = 1e9 + 7;
int dx[8] = {1, 0, -1, 0, 1, 1, -1, -1};
int dy[8] = {0, 1, 0, -1, 1, -1, 1, -1};
ll A, B, C, D, E, F, G, H, N, M, L, K, P, Q, R, W, X, Y, Z;
string S, T;
ll ans = 0;

signed main() {
    INIT;
    cin >> N;
    vector<pi> d(N);
    REP(i, N) {
        cin >> d[i].first >> d[i].second;
    }
    REP(i, N - 2) {
        bool flag = true;
        REP(j, 3) {
            if (d[i + j].first != d[i + j].second) {
                flag = false;
            }
        }
        if (flag) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 3660
#include <iostream>

using namespace std;

void func_a() {
    int x, y, z;
    cin >> x;
    cin >> y;
    cin >> z;

    cout << z << " " << x << " " << y << "\n";

}

void func_b() {

}

void func_c() {

}

int main()
{
    func_a();
    //func_b();
    //func_c():
    return 0;
}

Measured memory_bytes: 256
while 1:
    n, k = map(int, raw_input().split())
    if n == 0: break
    l = map(int, raw_input().split())
    for _ in range(n):
        m = map(int, raw_input().split())
        for i in range(k):
            l[i] -= m[i]
    print "No" if min(l) < 0 else "Yes"

Measured memory_bytes: 6432
n = int(input())
alh = "abcdefghijklmnopqrstuvwxyz"
ans = []

while n >= 1:
    ans.append((n-1)%26)
    n = (n-1)//26

   
   
#print(ans)

for i in range(len(ans)-1, -1, -1):
        #print(ans[i])
    print(alh[ans[i]], end="")
print()
    

Measured memory_bytes: 9184
#include<cstdio>
using namespace std;

bool used[900000];
int main()
{
    int n, x;
    scanf("%d%d", &n, &x);
    int j = 2 * n - 1;
    if (x != 1 && x != j)
    {
        puts("Yes");
        if (x + j / 2 <= j)
        {
            for (int i = x + j / 2; i >= x; i--)
            {
                printf("%d\n", i);
                used[i] = 1;
            }

            for (int i = 1; i <= j; i++)
            {
                if (!used[i])
                    printf("%d\n", i);
            }
        }
        else
        {
            for (int i = x - j / 2; i <= x; i++)
            {
                printf("%d\n", i);
                used[i] = 1;
            }
            for (int i = j; i >= 1; i--)
            {
                if (!used[i])
                    printf("%d\n", i);
            }
        }
    }
    else puts("No");
}


Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <vector>
using namespace std;
typedef long long llong;

#define INFTY 1000000000



int main() {
	int N[4];
	vector<int> vt;

	cin >> N[0] >> N[1] >> N[2] >> N[3];


	for (int i = 0; i < 4; i++) {
		vt.push_back(N[i]);
	}
	sort(vt.begin(), vt.end());

	if (vt[0] == 1 && vt[1] == 4 && vt[2] == 7 && vt[3] == 9) {
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
	


	


	



	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void) {

  int r, D, x_2000;
  do {
    scanf("%d %d %d", &r, &D, &x_2000);
  } while (r < 2 || r > 5 || D < 1 || D > 100 || x_2000 <= D || x_2000 > 200);

  int x[11];
  x[0] = x_2000;
  for (int i = 1; i < 11; i++) {
    x[i] = r * x[i - 1] - D;
    printf("%d\n", x[i]);
  }

  return 0;
}

Measured memory_bytes: 128
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		StringBuilder sb = new StringBuilder("ai1333");
		for (int i = 0; i < n / 100; i++) {
		    sb.append("3");
		}
		System.out.println(sb);
	}
}



Measured memory_bytes: 26348
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
#define pb push_back;
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<char, char> c_c;
typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
const int INF = 1e9;
const ll LLINF = 1e16;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int k, x;
    cin >> k >> x;
    
    if(500*k>=x) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

Measured memory_bytes: 384
#include <cstdio>

int main() {
  int N;
  int x;
  scanf("%d", &N);
  for(int i=0;i<N;i++) {
    scanf("%d",&x);
    if(x%2) {
		printf("first\n");
		return 0;
    }
  }
  printf("second\n");
  return 0;
}

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

const int mxN = 2e5 + 5;
int a[mxN];

int main() {
	int n;
	cin >> n;
	for(int i = 1; i < n; ++i) {
		int x;
		cin >> x;
		++a[x];
	}
	for(int i = 1; i <= n; ++i)
		cout << a[i] << '\n';
}


Measured memory_bytes: 4316
n = int(input())
s = input()

ok, ng = 0, n//2+1
while ng-ok > 1:
	x = (ok+ng)//2
	possible = False
	d = set()
	for i in range(n-2*x+1):
		d.add(s[i:i+x])
		if s[i+x:i+2*x] in d:
			possible = True
			break
	if possible:
		ok = x
	else:
		ng = x
print(ok)

Measured memory_bytes: 6388
package main

import (
	"fmt"
	"strings"
)

func main() {
	var s string
	var o, t int
	fmt.Scan(&s)
	cols := strings.Split(s, "")
	for _, c := range cols {
		if c == "1" {
			o++
		} else {
			t++
		}
	}
	if o > t {
		fmt.Println(t * 2)
	} else {
		fmt.Println(o * 2)
	}
}


Measured memory_bytes: 2944
n,k = map(int,input().split())
dict = {}
ans = 0

for i in range(n):
  a,b = map(int,input().split())
  if a not in dict:
    dict[a] = b
  else:
    dict[a] += b
    
dic = sorted(dict.items())


for key,v in dic:
  ans += v
  if ans >= k:
    print(key)
    exit()

Measured memory_bytes: 14560
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N=999999;

bool prime[MAX_N+1];
int p[MAX_N+1];

int main(){
	fill(prime,prime+MAX_N+1,true);
	for (int i=2;i<=MAX_N;i++){
		if (prime[i]){
			for (int j=2*i;j<=MAX_N;j+=i){
				prime[j]=false;
			}
		}
	}
	p[1]=0;
	for (int i=2;i<=MAX_N;i++){
		p[i]=p[i-1]+(prime[i] ? 1 : 0);
	}
	int n;
	while (cin>>n){
		cout<<p[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 6044
def STR(): return input()

def func(a, b):
    if a > b:
        return 0
    else:
        return 1

def solve_dp(arr, ii):
    dp = [[0, 0] for _ in range(ii)]
    lenarr = len(arr)
    n0 = int(n[0])
    a = lenarr
    for j in range(lenarr):
        a -= func(n0, arr[j])
    dp[0][0] = a
    dp[0][1] = 1 if n0 in arr else 0
    for i in range(1, ii):
        ni = int(n[i])
        a = lenarr
        for j in range(lenarr):
            a -= func(ni, arr[j])
        dp[i][0] = dp[i-1][0] * lenarr + dp[i-1][1] * a
        dp[i][1] = dp[i-1][1] if ni in arr else 0
    return sum(dp[ii-1])

n = STR()
l = len(n)
ans = 0

arr = [[3], [5], [7], [3, 5], [5, 7], [7, 3], [3, 5, 7]]
ans = solve_dp(arr[6], l)
for i in range(3):
    ans += solve_dp(arr[i], l)
for i in range(3, 6):
    ans -= solve_dp(arr[i], l)
for i in range(1, l):
    ans += pow(3, i) + 3 - 3 * pow(2, i)
print(ans)

Measured memory_bytes: 38384
#include<iostream>
#include<vector>

struct Pages{
	int first, last;
};

std::vector<Pages> v;

void add(int n){
	for(int i=0;i<v.size();i++){
		Pages &p = v[i];
		if(n == p.last + 1){
			p.last = n;
			return;
		}
	}
	v.push_back({n, n});
	return;
}

void print(Pages& p){
	if(p.first == p.last)
		std::cout << p.first;
	else
		std::cout << p.first << "-" << p.last;
}

int main(){
	int n;
	while(std::cin >> n, n){
		v.clear();
		while(n--){
			int i;
			std::cin >> i;
			add(i);
		}
		print(v[0]);
		for(int i=1;i<v.size();i++){
			std::cout << " ";
			print(v[i]);
		}
		std::cout << "\n";
	}
}

Measured memory_bytes: 1208
#include<iostream>
#include <string>
#include <vector>
#include <algorithm> 
#include <map>
using namespace std;
int main()
{
    int i;
    long N,M,A,B;
  	long count = 0;
  	long sum = 0;
    cin >> N >> M;
  	vector<pair<long, long> > pairs(N);
	
 	for(i=0;i<N;i++){
    	cin >> A >> B;
      	pairs[i] = make_pair(A,B);
    }
  	sort(pairs.begin(),pairs.end());
  	for(i=0;i<N;i++){
      	count += pairs[i].second;
        sum += pairs[i].first * pairs[i].second;
      	if (count >= M){
        	sum -= pairs[i].first * ( count - M );
          	count -= M;
          	break;
        }
    }
  	cout << sum << endl;
  	return 0;
}

Measured memory_bytes: 1792