akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
using namespace std;



class list {
public:
    int val;
    list* prev;
    list* next;
};
list* nil;
void initialize()
{
    nil = new list;
    nil->prev = nil;
    nil->next = nil;
}

void insert_(int val)
{
    list* p = new list;
    p->val = val;
    p->prev = nil;
    p->next = nil->next;
    p->next->prev = p;
    p->prev->next = p;
}

void delete_(int val)
{
    for (list* p = nil->next; p != nil; p = p->next) {
        if (p->val == val) {
            p->prev->next = p->next;
            p->next->prev = p->prev;
            delete p;
            return;
        }
    }
}

void deleteFirst()
{
    list* p = nil->next;
    p->prev->next = p->next;
    p->next->prev = p->prev;
    delete p;
}

void deleteLast()
{
    list* p = nil->prev;
    p->prev->next = p->next;
    p->next->prev = p->prev;
    delete p;
}

void trace()
{
    for (list* p = nil->next; p != nil; p = p->next) {
        cout << p->val;
        if (p->next != nil) {
            cout << " ";
        } else {
            cout << "\n";
        }
    }
}

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

    list* head;

    for (int i = 0; i < n; i++) {
        string command;
        cin >> command;
        if (command == "deleteFirst") {
            deleteFirst();
            continue;
        }
        if (command == "deleteLast") {
            deleteLast();
            continue;
        }
        int val;
        cin >> val;
        if (command == "insert") {
            insert_(val);
        } else {
            delete_(val);
        }
    }
    trace();
}

Measured memory_bytes: 34264
#include<bits/stdc++.h>
using namespace std;
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }


ll MAX_V = 1e5 + 5; //頂点数
struct edge {
    ll to;
    ll cost;
};

// <最短距離, 頂点の番号>
using P = pair<ll, ll>;

vector<vector<struct edge>> G(MAX_V); //隣接リスト
vector<ll> d(MAX_V); //各頂点への最短距離

void dijkstra(ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(ALL(d), INF);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;

        for (ll i=0; i<G[v].size(); i++) {
            struct edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

vector<vector<struct edge>> G2(MAX_V); //隣接リスト
vector<ll> d2(MAX_V); //各頂点への最短距離
void dijkstra2(ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(ALL(d2), INF);
    d2[s] = 0;
    que.push(P(0, s));
    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d2[v] < p.first) continue;

        for (ll i=0; i<G2[v].size(); i++) {
            struct edge e = G2[v][i];
            if (d2[e.to] > d2[v] + e.cost) {
                d2[e.to] = d2[v] + e.cost;
                que.push(P(d2[e.to], e.to));
            }
        }
    }
}


int main() {
  ll i, j;
  ll n,m,s,t;
  cin >> n>>m>>s>>t;
  //string s; cin >> s;
  //ll result = 0;
  bool judge = true;
  vector<ll> u(m),v(m),a(m),b(m);
  for(i=0;i<m;i++){
    cin>>u[i]>>v[i]>>a[i]>>b[i];
    struct edge e ={v[i],a[i]};
    G[u[i]].push_back(e);
    e ={u[i],a[i]};
    G[v[i]].push_back(e);

    e ={v[i],b[i]};
    G2[u[i]].push_back(e);
    e ={u[i],b[i]};
    G2[v[i]].push_back(e);
  }
  
  dijkstra(s);
  vector<ll> result(n,INF);
  dijkstra2(t);
  result[n-1]=d[n]+d2[n];
  
  for(i=n-1;i>=1;i--){
    result[i-1]=min(result[i],d[i]+d2[i]);
  }

  ll teisu=1e15;
  for(i=0;i<n;i++){
    cout<<teisu - result[i]<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 22316
import java.util.*;

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

        Arrays.sort(a);
        String a_asc = new String(a);

        Arrays.sort(b);
        String b_asc = new String(b);
        b_asc = new StringBuilder(b_asc).reverse().toString();

        if(a_asc.compareTo(b_asc) < 0){
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

    public static void printListOneLine(List list){
        for(int i=0; i<list.size(); i++){
            System.out.println(list.get(i));
        }
    }

    public static void printList(List list){
        for(int i=0; i<list.size(); i++){
            if(i == list.size()){
                System.out.println(list.get(i));
            } else {
                System.out.print(String.format("%d ", list.get(i)));
            }
        }
    }

    public static void printArray(int[] array){
        for(int i=0; i<array.length; i++){
            if(i == array.length){
                System.out.println(array[i]);
            } else {
                System.out.print(String.format("%d ", array[i]));
            }
        }
    }

    public static int gcd(int a, int b){
        if (b == 0) return a;
        return gcd(b, a % b);
    }

    public static int lcm(int a, int b){
        return a * b / gcd(a, b);
    }
}


Measured memory_bytes: 23636
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n;
  cin >> n;
  for (int i = n; i <= 999; i++) {
    string str = to_string(i);
    set<char> st;
    for (int i = 0; i < str.size(); i++) {
      st.insert(str[i]);
    }
    if (st.size() == 1) {
      cout << i << endl;
      break;
    }
  }
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> x(n);
	rep(i, n) cin >> x[i];
	int ans = 1000001;
	for(int p = 1; p <= 100; p++) {
		int sum = 0;
		rep(i, n)sum += (x[i] - p) * (x[i] - p);
		ans = min(ans, sum);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long n,cnt;
long long fa[100005];
set<long long>a[100005];
struct node
{
	long long x,y;
};
bool operator <(node aa,node bb)
{
	return aa.x==bb.x?aa.y<bb.y:aa.x<bb.x;
}
queue<node>q;
map<node,long long>mp;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-1;ch=getchar();}
	while(ch>='0'&&ch<='9') {x=x*10+ch-'0';ch=getchar();}
	return ff*x;
}
void write(long long z)
{
	if(z<0){putchar('-');z=-z;}
	if(z>=10){write(z/10);}
	putchar(z%10+'0');
}
node bh(long long aa,long long bb)
{
	node A;
	A.x=min(aa,bb);
	A.y=max(aa,bb);
	return A;
}
int getfa(int aa)
{
	return fa[aa]==aa?aa:fa[aa]=getfa(fa[aa]);
}
int main()
{
	n=read();
	for(long long i=1;i<=n;++i) fa[i]=i;
	for(long long i=1;i<n*2-1;++i) 
	{
		long long x=read(),y=read();
		a[x].insert(y);
		a[y].insert(x);
		node aa=bh(x,y);
		if(++mp[aa]==2) cnt++,q.push(aa);
	}
	while(!q.empty())
	{
		node kk=q.front();
		q.pop();
		long long X=getfa(kk.x),Y=getfa(kk.y);
		if(X==Y) continue;
		if(a[X].size()<a[Y].size()) swap(X,Y);
		a[X].erase(Y);
		for(set<long long>::iterator it=a[Y].begin();it!=a[Y].end();++it)
		{
			long long tmp=(*it);
			if(tmp==X) continue;
			a[X].insert(tmp);
			a[tmp].erase(Y);
			a[tmp].insert(X);
			if(++mp[bh(X,tmp)]==2) cnt++,q.push(bh(X,tmp));
		}
		fa[Y]=X;
		a[Y].clear();
	}
	if(cnt==n-1) puts("YES");
	else puts("NO");
	return 0;
}

Measured memory_bytes: 39680
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <algorithm>
#include <map>
using namespace std;
int x[4000];
int main()
{
	int n;
	scanf("%d\n",&n);
	int m=0;
	int ans=0;
	for (int i=1;i<=n;i++)
	{
		scanf("%d",&x[i]);
		ans=ans+x[i]-1;
	}
	printf("%d\n",ans);
	return 0;
}

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define pb push_back
#define pf push_front
#define mod 1000000007
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK puts("OK")
#define OK1 puts("OK1")
#define OK2 puts("OK2")
#define SIZE(s) (int)s.size()
#define INF ((1LL<<62)-(1LL<<31))
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<long long> vll;
typedef vector<double> vd;
typedef vector<char> vc;
typedef vector<string> vs;

typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

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

ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll n,q,a,t,x;
	vll v;
	cin >> n >> q;
	vector<priority_queue<ll>> pq(n);
	rep(i,q){
		cin >> a >> t;
		if(a==0){
			cin >> x;
			pq[t].push(x);
		}
		else if(a==1 && !(pq[t].empty())) v.pb(pq[t].top());
		else if(a==2 && !(pq[t].empty())) pq[t].pop();
	}
	for(auto& e:v) cout << e << endl;
	return 0;
}


Measured memory_bytes: 5540
#include<cstdio>
#include<iostream>
#include<bits/stdc++.h>
#define Max(a,b) (a>b?a:b)
#define Min(a,b) (a<b?a:b)
inline int read(){
	int f=1,x=0;char c=getchar();
	while(c<'0'||c>'9'){
		if(c=='-')
			f=-1;
		c=getchar();
	}
	while(c<='9'&&c>='0'){
		x=x*10+c-'0';
		c=getchar();
	}
	return x*f;
}

inline void file(){
	freopen("1.in","r",stdin);
	freopen("1.out","w",stdout);
}

using namespace std;

int main(){
	string s;
	cin>>s;
	s[3]='8';
	cout<<s;


	return 0;
}




Measured memory_bytes: 256
from sys import stdin


def main():
    O = stdin.readline().rstrip()
    E = stdin.readline().rstrip()
    for o, e in zip(O, E):
        print(o, end='')
        print(e, end='')
    if len(O) > len(E):
        print(O[-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#include <iostream>
using namespace std;
long long K;
void Solve()
{
    cin >> K;
    cout << "50\n";
    long long a = K / 50 + 49;
    long long rem = K % 50;
    for(int i = 1; i <= 50 - rem; i++)
        cout << (a + 1) - 50 + (50 - rem - 1) << " ";
    for(int i = 1; i <= rem; i++)
        cout << (a + 1) + (50 - rem) << " ";
    cout << "\n";
}
int main()
{
    Solve();
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

#define mod ((ull)(1e9)+7)

int main(){
	int n, m;
	cin >> n >> m;
	bool s[n], g[n];
	for(int i=0; i<n; i++){
		s[i]=false, g[i]=false;
	}
	for(int i=0; i<m; i++){
		int a, b;
		cin >> a >> b;
		if(a==1) s[b]=true;
		if(a==n) g[b]=true;
		if(b==1) s[a]=true;
		if(b==n) g[a]=true;
	}

	for(int i=0; i<n; i++){
		if(s[i]&&g[i]){
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}
	cout << "IMPOSSIBLE" << endl;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define endl "\n"
ll n, len;
vector<vector<ll>> dp;
vector<vector<ll>> Data;
ll Vacation(ll i, ll j)
{
    ll t1, t2;
    if (j == 0)
    {
        if (i == n - 2)
            return Data[i][j] + max(Data[i + 1][1], Data[i + 1][2]);
        else
        {
            if (dp[i + 1][1] != 0)
                t1 = dp[i + 1][1];
            else
                t1 = Vacation(i + 1, 1);
            if (dp[i + 1][2] != 0)
                t2 = dp[i + 1][2];
            else
                t2 = Vacation(i + 1, 2);
            dp[i][j] = max(t1, t2) + Data[i][j];
            return dp[i][j];
        }
    }
    if (j == 1)
    {
        if (i == n - 2)
        {
            return Data[i][j] + max(Data[i + 1][0], Data[i + 1][2]);
        }
        else
        {
            if (dp[i + 1][0] != 0)
                t1 = dp[i + 1][0];
            else
                t1 = Vacation(i + 1, 0);
            if (dp[i + 1][2] != 0)
                t2 = dp[i + 1][2];
            else
                t2 = Vacation(i + 1, 2);
            dp[i][j] = max(t1, t2) + Data[i][j];
            return dp[i][j];
        }
    }
    if (j == 2)
    {
        if (i == n - 2)
        {
            return Data[i][j] + max(Data[i + 1][1], Data[i + 1][0]);
        }
        else
        {
            if (dp[i + 1][1] != 0)
                t1 = dp[i + 1][1];
            else
                t1 = Vacation(i + 1, 1);
            if (dp[i + 1][0] != 0)
                t2 = dp[i + 1][0];
            else
                t2 = Vacation(i + 1, 0);
            dp[i][j] = max(t1, t2) + Data[i][j];
            return dp[i][j];
        }
    }
    return 0;
}
void solve()
{
    ll t1, t2, t3;
    cin >> n;
    len = n;
    for (ll i = 0; i < n; i++)
    {
        cin >> t1 >> t2 >> t3;
        Data.push_back({t1, t2, t3});
        dp.push_back({0, 0, 0});
    }
    if (n != 1)
        cout << max(Vacation(0, 0), max(Vacation(0, 1), Vacation(0, 2))) << endl;
    else
        cout << max(Data[0][0], max(Data[0][1], Data[0][2])) << endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll T = 1;
    while (T--)
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 17340
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args)throws IOException{
		InputStreamReader isr = new InputStreamReader(System.in);
		BufferedReader reader = new BufferedReader(isr);
		String str, s[];
		
		int n, q, date[];
		x : while(!(str = reader.readLine()).equals("0 0")){
			s = str.split(" ");
			n = Integer.valueOf(s[0]);
			q = Integer.valueOf(s[1]);
			
			date = new int[150];
			for(int i = 0; i < n; i++){
				s = reader.readLine().split(" ");
				for(int j = 1; j <= Integer.valueOf(s[0]); j++){
					date[Integer.valueOf(s[j])]++;
				}
			}
			for(int i = n; i >= q; i--)
				for(int j = 1; j < date.length; j++){
					if(date[j] == i){
						System.out.println(j);
						continue x;
					}
				}
			System.out.println(0);
		}
		reader.close();
	}
}

Measured memory_bytes: 35936
#include <iostream>
#include <vector>
using namespace std;
const int INF = 1001001001;

template<typename T> int LIS_leq(const vector<T> &v, const T inf) {
	vector<T> dp(v.size(), inf);
	for (const T &e : v) {
		*upper_bound(dp.begin(), dp.end(), e) = e;
	}
	return lower_bound(dp.begin(), dp.end(), inf) - dp.begin();
}

int main() {
	int n;
	cin >> n;
	vector<int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
		A[i] = -A[i];
	}
	int ans = LIS_leq(A, INF);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3676
#include <stdio.h>
#include <vector>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
 
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<double> vd;



vector<vector<pair<int, int> > > tree;
vi ans;


void dfs(int i, int p=-1, int pc=-1){
  int color = 1;
  rep(j, tree[i].size()){
    if (tree[i][j].first == p) continue;
    if (color == pc) color++;
    ans[tree[i][j].second] = color;
    dfs(tree[i][j].first, i, color);
    color++;
  }
}

int main(){
  int n;
  cin >> n;
  tree.resize(n);
  ans.resize(n-1);

  rep(i, n-1){
    int a, b;
    cin >> a >> b;
    a--; b--;
    tree[a].push_back(make_pair(b, i));
    tree[b].push_back(make_pair(a, i));
  }

  int m=0;
  rep(i, tree.size()) m = max(m, (int)tree[i].size());

  dfs(0);
  cout << m << endl;
  rep(i, n-1){
    cout << ans[i] << endl;
  }

  return 0;
}

Measured memory_bytes: 8320
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <iomanip>
#include <map>
#include <cmath>
#include <bitset>
using namespace std;

typedef long long ll;
typedef pair<int,int> Pi;
const ll inf = 1e18 + 1;
const ll limit = 1e9;

int main() {
    int n,m,x; cin >> n >> m >> x;
    vector<int> c(n);
    vector<vector<int>> v(n,vector<int>(m));
    for (int i = 0; i < n; i++) {
        cin >> c[i];
        for (int j = 0; j < m; j++) cin >> v[i][j];
    }
    ll ans = inf;
    bool ok = false;
    for (int i = 0; i < (1 << n); i++) {
        bool flag = true;
        vector<int> a(m);
        ll cost = 0;
        for (int j = 0; j < n; j++) {
            if (i >> j & 1) {
                cost += c[j];
                for (int k = 0; k < m; k++) a[k] += v[j][k];
            }
        }
        for (int j = 0; j < m; j++) {
            if (a[j] < x) {
                flag = false;
                break;
            }
        }
        if (flag) {
            ok = true;
            ans = min(ans,cost);
        }
    }
    if (ok) cout << ans << "\n";
    else cout << -1 << "\n";
}   
 

Measured memory_bytes: 3632
import sys


inint = lambda: int(sys.stdin.readline())
inintm = lambda: map(int, sys.stdin.readline().split())
inintl = lambda: list(inintm())
instr = lambda: sys.stdin.readline()
instrm = lambda: map(str, sys.stdin.readline().split())
instrl = lambda: list(instrm())

s = instr()

prev = s[0]
ans = 0

for i in range(1,len(s)):
    if s[i] != prev:
        prev = s[i]
    else:
        ans += 1
        if s[i] == "0":
            prev = "1"
        else:
            prev = "0"

print(ans)

Measured memory_bytes: 73072
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

using namespace std;

#define SORT(c) sort((c).begin(),(c).end())
#define ANS(ans) cout<<(ans)<<endl;
typedef vector<int> VI;

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)


int main() {

	string s;
	cin >> s;
	int ans = 700;
	REP(i, 3) {
		if (s[i] == 'o') {
			ans += 100;
		}
	}
	ANS(ans);

	return 0;
}



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

using namespace std;

int dp[100005];
vector<int> adj[100005];

int dfs(int u){
    if (dp[u] > 0){
        return dp[u];
    }
    for (int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i];
        dp[u] = max(dp[u], dfs(v));
    }
    dp[u] += 1;
    return dp[u];
}
int main(){
    //freopen("LONGESTPATH.INP", "r", stdin);

    int n, m;
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int a, b;
        cin >> a >> b;
        adj[a].push_back(b);
    }

    memset(dp, 0, sizeof(dp));

    int res = 0;
    for (int i = 1; i <= n; i++){
        res = max(res, dfs(i));
    }

    cout << res - 1;
    return 0;
}


Measured memory_bytes: 8192
#include <cstdio>
#include <algorithm>
using namespace std;
int r[20001];
int main() {
    int n, s;
    while (scanf("%d%d",&n,&s)) {
        if (!n&&!s) break;
        for (int i=0; i<n; i++) scanf("%d",&r[i]);
        sort(r, r+n);
        int cnt=0;
        for (int i=n-1; i>0; i--) {
            if (r[i]>=s) cnt+=i;
            else {
                for (int j=i-1; j>=0; j--) {
                    if (r[i]+r[j]<=s) break;
                    cnt++;
                }
            }
        }
        printf("%d\n",cnt);
    }
}

Measured memory_bytes: 796
import java.util.Scanner;
import java.util.TreeMap;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		long k = sc.nextLong();
		TreeMap<Long,Long> g=new TreeMap<Long,Long>();
		long[] aa=new long[n];
		long[] bb = new long[n];
		long sum = 0;
		for(int i = 0; i < n; i++){
			long a = sc.nextLong();
			long b = sc.nextInt();
			aa[i]=a;
			bb[i]=b;
			if(!g.containsKey(aa[i])){
				g.put(aa[i],bb[i]);
			}else{
				g.put(aa[i],bb[i]+g.get(aa[i]));
			}
		}
		for(long i :g.keySet()){
			sum+=g.get(i);
			if(sum>=k){
				System.out.println(i);
				return;
			}
		}
	}
}

Measured memory_bytes: 96040
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ii pair <int, int>
#define app push_back
#define all(a) a.begin(), a.end()
#define bp __builtin_popcountll
#define ll long long
#define mp make_pair
#define f first
#define s second
#define Time (double)clock()/CLOCKS_PER_SEC

const int N = 1e6 + 7;

struct Edge {
    int u, v, c;
    bool operator < (Edge e) {
        return c < e.c;
    }   
};  

int par[N];
bool cyc[N];

int root(int u) {
    if (u == par[u])
        return u;
    else
        return par[u] = root(par[u]);
}   

signed main() {
    #ifdef HOME
    freopen("input.txt", "r", stdin);
    #else
    #define endl '\n'
    ios_base::sync_with_stdio(0); cin.tie(0);
    #endif

    int k, n, m;
    cin >> k >> n >> m;
    vector <Edge> a(k);
    for (int i = 0; i < k; ++i) {
        cin >> a[i].u >> a[i].v >> a[i].c;
        a[i].v += n;                
    }   

    sort(all(a));
    reverse(all(a));

    for (int i = 0; i < N; ++i)
        par[i] = i;
    int ans = 0;
    for (auto e : a) {
        int u = root(e.u), v = root(e.v);
        if (u == v) {
            if (cyc[u])
                continue;
            ans += e.c;
            cyc[u] = 1;

            //cout << "add " << e.u << ' ' << e.v << ' ' << e.c << endl;

        }   
        else {
            if (cyc[u] && cyc[v]) {
                continue;
            }   
            ans += e.c;
            par[u] = v;
            cyc[v] |= cyc[u];

            //cout << "add " << e.u << ' ' << e.v << ' ' << e.c << endl;

        }   
    }   
    cout << ans << endl;
}

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  a[0] = 0;
  for (int i = 1; i < n; ++i) {
    cin >> a[i];
  }
  map<int, int> mp;
  for (int i = 0; i < n; ++i) {
    mp[a[i]]++;
  }
  for (int i = 1; i < n; ++i) {
    cout << mp[i] << endl;;
  }
  cout << 0 << endl;
}


Measured memory_bytes: 13500
import java.util.Scanner;

public class Main{
 public static void main(String[] args){
 Scanner sc = new Scanner(System.in);
 int a =sc.nextInt();
 int b =sc.nextInt();
 int c =sc.nextInt();
 if(a<b){
  if(b<c){
   System.out.printf("%d %d %d\n",a,b,c);
   }else if(a<c){
   System.out.printf("%d %d %d\n",a,c,b);
   }else{
   System.out.printf("%d %d %d\n",c,a,b);
   }
 }else if(b<a){
  if(a<c){
   System.out.printf("%d %d %d\n",b,a,c);
   }else if(b<c){
   System.out.printf("%d %d %d\n",b,c,a);
   }else{
   System.out.printf("%d %d %d\n",c,b,a);
   }
 }
}
}

Measured memory_bytes: 26188
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
//#define f(i,a,n) for(ll i=a;i<n;i++)
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll isPrime(int n) 
{ 
	// Corner cases 
	if (n <= 1) 
		return 1; 
	if (n <= 3) 
		return 2; 

	// This is checked so that we can skip 
	// middle five numbers in below loop 
	if (n % 2 == 0 || n % 3 == 0) 
		return 1; 

	for (int i = 5; i * i <= n; i = i + 6) 
		if (n % i == 0 || n % (i + 2) == 0) 
			return 1; 

	return 2; 
} 

ll fact(ll n){ll res = 1;for (ll i = 2; i <= n; i++)res = res * i,res%=1000000007; 
    return res; } 
 
int main() 
{
    fast;
    ll t=1;
    //cin>>t;
    while(t--)
    {
        ll n,k,sum=0;
        cin>>n>>k;
        ll A[n];
        for(ll i=0;i<n;i++)
        {
            cin>>A[i];
        }
        sort(A,A+n);
        for(ll i=0;i<k;i++)
        {
            sum=sum+A[n-1-i];
        }
        cout<<sum;
    }
    return 0;
}


Measured memory_bytes: 3584
N,M=map(int, input().split())

a = []
b = []
for i in range(M):
    al, bl = map(int,input().split())
    a.append(al)
    b.append(bl)

c=[]
for i in range(1,N+1):
  c.append(a.count(i)+b.count(i))
  print(a.count(i)+b.count(i))

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

using namespace std;

#define ull unsigned long long
#define ll long long
#define int long long
#define ld long double

#define pb push_back
#define mp make_pair
#define fi first
#define se second

#define MX LLONG_MAX
#define MN LLONG_MIN

const ll mod=1e9+7;
const ll N=1e5+5;

ll powermodm(ll x,ll n,ll M){ll result=1;while(n>0){if(n % 2 ==1)result=(result * x)%M;x=(x*x)%M;n=n/2;}return result;}
ll power(ll _a,ll _b){ll _r=1;while(_b){if(_b%2==1)_r=(_r*_a);_b/=2;_a=(_a*_a);}return _r;}
ll gcd(ll a,ll b){if(a==0)return b;return gcd(b%a,a);}          
ll lcm(ll a,ll b){return (max(a,b)/gcd(a,b))*min(a,b);}

int32_t main()                  
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    vector<pair<ll,ll> > a;
    for(ll i=0;i<n;i++)
    {
        ll x,y;
        cin>>x>>y;
        a.pb({y,x});
    }
    sort(a.begin(),a.end());
    ll pre = 0;
    for(ll i=0;i<n;i++)
    {
        pre += a[i].se;
        if(pre>a[i].fi)
        {
            cout<<"No";
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

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

int main(){
  int a,b,c;
  int d,e;
  cin >> a >> b >> c;
  d = b - a;
  e = c - b;
  if(d == e){
    cout << "YES" << endl;
  }
  else{
    cout <<"NO" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <unordered_map>
#include <random>
#include <cstdio>
#include <cstring>
#include <cmath>

using namespace std;
using ll = long long;

ll N, M;
vector<vector<ll>> paths;
vector<ll> parent_count;

void input() {
    cin >> N >> M;
    paths.resize(N + 1);
    parent_count.resize(N + 1);
    for (ll i = 0; i < N - 1 + M; i++) {
        ll a, b;
        cin >> a >> b;
        paths[a].push_back(b);
        parent_count[b]++;
    }
}

void solve() {
    vector<ll> pars(N + 1, 0);
    
    vector<bool> visited(N + 1);
    for (auto& targets : paths) {
        for (auto target : targets) {
            visited[target] = true;
        }
    }
    queue<ll> qs;
    for (ll i = 1; i < N + 1; i++) {
        if (not visited[i])
            qs.push(i);
    }
    
    while(not qs.empty()) {
        auto q = qs.front(); qs.pop();
        auto& targets = paths[q];
        for (auto target : targets) {
            parent_count[target]--;
            if (parent_count[target] == 0) {
                pars[target] = q;
                qs.push(target);
            }
        }
    }
    for (ll i = 1; i < N + 1; i++) {
        cout << pars[i] << endl;
    }
}


int main() {
    input();
    //    cout << solve() << endl;
    solve();
    
    return 0;
}



Measured memory_bytes: 7936
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
using ll = long long;
#define int long long
const int INF = 1145141919;
    vector <vector<int>> to(2600);
    vector <vector<int>> ot(2600);
bool cone1[2600];
bool conen[2600];
bool ok[2600];
vector <vector<int>> cost(2600,vector <int>(2600));
void dfs(int now){
    if(cone1[now]) return ;
    else cone1[now] = true;
    for(int i=0;i<to[now].size();i++){
        dfs(to[now][i]);
    }
}
void rdfs(int now){
    if(conen[now]) return ;
    else conen[now] = true;
    for(int i=0;i<ot[now].size();i++){
        rdfs(ot[now][i]);
    }
}
signed main(void){
    int n,m,p; cin>>n>>m>>p;
    vector <tuple <int,int,int> > edges;

    rep(i,m){
        int a,b,c; cin>>a>>b>>c; a--; b--;
        cost[a][b] = -c+p;
        to[a].push_back(b);
        ot[b].push_back(a);
        edges.push_back(make_tuple(a,b,cost[a][b]));
    }
    dfs(0);
    rdfs(n-1);
    rep(i,n) ok[i] = cone1[i]&conen[i];
    { // bellman-ford
    vector<int> d(n,INF);
    d[0] = 0;
    bool upd = true;
    int step = 0;
    while (upd) {
      upd = false;
      rep(i,m) {
        int a, b, c;
        tie(a,b,c) = edges[i];
        if (!ok[a]) continue;
        if (!ok[b]) continue;
        int newD = d[a]+c;
        if (newD < d[b]) {
          upd = true;
          d[b] = newD;
        }
      }
      step++;
      if (step > n) {
        puts("-1");
        return 0;
      }
    }
    int ans = -d[n-1];
    ans = max(ans, 0LL);
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 53760
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner inScanner = new Scanner(System.in);

        while (true) {
            int n = inScanner.nextInt();

            if (n == 0) {
                break;
            }

            int s = 0;
            int max = 0;
            int min = 1000;
            for (int i = 0; i < n; i++) {
                int si = inScanner.nextInt();

                if (max <= si) {
                    max = si;
                }
                if (min >= si) {
                    min = si;
                }

                s += si;
            }

            s -= (min + max);

            System.out.println(s/(n-2));
        }
    }
}

Measured memory_bytes: 28540
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		int n = sc.nextInt(), y = sc.nextInt();
		boolean c = false;
		for(int i = 0; i <= n; i++) {
			for(int j = 0; j <= n-i; j++) {
				if(10000*i+5000*j+1000*(n-i-j) == y) {
					System.out.println(i+" "+j+" "+(n-i-j));
					c = true;
					break;
				}
			}
			if(c) {
				break;
			}
		}
		if(!c)System.out.println(-1+" "+-1+" "+-1);
	}

	static class FastScanner {
		private BufferedReader reader = null;
	    private StringTokenizer tokenizer = null;
	    public FastScanner(InputStream in) {
	        reader = new BufferedReader(new InputStreamReader(in));
	        tokenizer = null;
	    }

	    public String next() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                tokenizer = new StringTokenizer(reader.readLine());
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }
	        return tokenizer.nextToken();
	    }

	    public String nextLine() {
	        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
	            try {
	                return reader.readLine();
	            } catch (IOException e) {
	                throw new RuntimeException(e);
	            }
	        }

	        return tokenizer.nextToken("\n");
	    }

	    public long nextLong() {
	        return Long.parseLong(next());
	    }

	    public int nextInt() {
	        return Integer.parseInt(next());
	    }

	    public double nextDouble() {
	         return Double.parseDouble(next());
	     }

	    public int[] nextIntArray(int n) {
	        int[] a = new int[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextInt();
	        return a;
	    }

	    public long[] nextLongArray(int n) {
	        long[] a = new long[n];
	        for (int i = 0; i < n; i++)
	            a[i] = nextLong();
	        return a;
	    }
	}
}


Measured memory_bytes: 37244
#include <bits/stdc++.h>
using namespace std;
using pii=pair<int,int>;
using ll=long long;

#define fi first
#define se second
#define pb push_back
#define rep(i,n) for(int i=0; i<(int)(n); i++)

int main() {
	ll n;
	cin >> n;
	ll mini=1e18;
	ll a;
	for(ll i=1; i<=sqrt(n*1.0); i++) {
		if (n % i == 0) {
			a = n / i;
			mini = mini < (a+i)-2 ? mini : (a+i)-2;
		}
	}
	cout << mini << endl;


  return 0;
}


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

using namespace std;

const int MAX = 2000000;

unsigned long long Heap[MAX];

int n = 0;

//必须自底向上的调用本函数 ，这样，每执行一次，底层的树依次会满足最大堆性质
void maxHeapify(int i) {
	int l = 2*i;
	int r = 2*i+1;
	int maxI = i;

	if (l <= n && Heap[maxI] < Heap[l]) {
		maxI = l;
	}

	if (r <= n && Heap[maxI] < Heap[r]) {
		maxI = r;
	}

	if (maxI != i) {
		unsigned long long t = Heap[i];
		Heap[i] = Heap[maxI];
		Heap[maxI] = t;
		maxHeapify(maxI);
	}
}

void maxHeap() {
	for (int i = n / 2; i>0; i--) {
		maxHeapify(i);
	}
}

int extract() {
	if (n > 0) {
		int q = Heap[1];

		//将最后一个元素放到开头，并重建堆
		Heap[1] = Heap[n];
		n--;
		maxHeapify(1);
		return q;
	}
	return -1;
}

void insert(unsigned long long key) {
	n++;
	Heap[n] = key;
	int i = n;
	int p = i / 2;
	//将新插入的元素移到适当位置 
	while (i > 1 && Heap[p] < Heap[i]) {
		//cout << "i==" << i <<"swap" << Heap[p]  << " "<< Heap[i] << endl;
		unsigned long long t = Heap[i];
		Heap[i] = Heap[p];
		Heap[p] = t;
		i = i / 2;
		p = i / 2;
	}
}

int main() {
	while (1) {
		string op;
		cin >> op;
		if (op == "insert") {
			unsigned long long k;
			cin >> k;
			insert(k);
		} else if (op == "extract") {
			cout << extract() << endl;
		} else if (op == "end") {
			break;
		}
	}
	return 0;

}


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

int main()
{
	int n;
	while(cin >> n){
		if(n == 0) break;
		map<int, int> officers;
		vector<int> ids;
		for(int i = 0; i < n; i++){
			int id;
			int value;
			int num;
			int need;
			cin >> id >> value >> num;
			if(value > 0){
				need = 1000000 % value == 0 ? 1000000 / value : 1000000 / value + 1;
				if(num >= need){
					officers[id] = 1000000;
					if(find(ids.begin(), ids.end(),id) == ids.end())
						ids.push_back(id);
				} else {
					if(find(ids.begin(), ids.end(),id) == ids.end()){
						ids.push_back(id);
						officers[id] = value * num;
					} else {
						officers[id] += value * num;
						if(officers[id] > 1000000)
							officers[id] = 1000000;
					}
				}
			}
		}
		int count = 0;
		for(vector<int>::const_iterator iter = ids.begin(); 
			iter != ids.end(); iter++){
			if(officers[*iter] >= 1000000){
				cout << *iter << endl;
				count++;
			}
		}
		if(!count) cout << "NA" << endl;
	}
	return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <utility>
#include <queue>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <ctime>
#include <cstdlib>
#include <climits>
using namespace std;

#define MOD1097 1000000007

#define ll long long
#define pint pair<int, int>
#define pll pair<ll, ll>
#define pb push_back
#define mpair make_pair
#define pm(first, second) pb(mpair(first, second))
#define SPACE " "
#define fpf first.first
#define fps first.second
#define spf second.first
#define sps second.second

#define all(X) (X).begin(), (X).end()
#define reall(X) (X).rbegin(), (X).rend()
#define divcel(a, b) (((a) + ((b) - 1)) / (b))

int main(){

	ll N;
	cin >> N;
	map<ll, int> mp;
	ll a, sum = 0;
	for(ll i = 0; i < N; i++){
		cin >> a;
		mp[a]++;
		sum += a;
	}
	ll Q;
	cin >> Q;
	ll b, c, d;
	for(ll i = 0; i < Q; i++){
		cin >> b >> c;
		d = mp[b];
		mp[b] = 0;
		sum -= b*d;
		mp[c] += d;
		sum += c*d;
		cout << sum << endl;
	}

	return 0;
}


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

uint64_t grundy(int x, int k){
    if(x < k) return 0;
    if(x % k == 0) return x / k;
    int p = x/k + 1;
    int t = (x%k + p - 1) / p;
    return grundy(x - p*t, k);
}

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    
    int n;
    uint64_t xg = 0;
    cin >> n;
    for(int i=0;i<n;++i){
        uint64_t a, k, g;
        cin >> a >> k;
        xg ^= grundy(a, k);
    }
    cout << (xg ? "Takahashi" : "Aoki") << endl;
    
    return 0;
}

Measured memory_bytes: 384
s = str(input())

s1 = int(s[:2])
s2 = int(s[2:])

if 1 <= s1 <= 12 and 1<=s2<=12:
    print('AMBIGUOUS')
elif 0 <= s1 <= 99 and 1 <= s2 <= 12:
    print('YYMM') 
elif 0 <= s2 <= 99 and 1 <= s1 <= 12:
    print('MMYY')
else:
    print('NA')

Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <vector>

using namespace std;

int pop_count(const string& s) {
  int result = 0;
  for (int i = 0 ; i < s.size() ; i++) {
    if (s[i] == '1') {
      result++;
    }
  }
  return result;
}

int pop_count(const int x) {
  return __builtin_popcount(x);
}

int f(int x) {
  int count = 0;
  while (x > 0) {
    x %= pop_count(x);
    count ++;
  }
  return count;
}

int calc_mod(const string& xs, int mod, vector<int> mods) {
  if (mod == 0) {
    return 0;
  }
  int result = 0;
  
  for (int i = 0 ; i < xs.size() ; i ++) {
    if (xs[i] == '1') {
      result += mods[xs.size() - i - 1];
      result %= mod;
    }
  }
  return result;
}

vector<int> calc_pow2_mod(int mod, int n) {
  vector<int> mods(n+1, 0);
  if (mod == 0) {
    return mods;
  }
  mods[0] = 1;
  for (int i = 1 ; i <= n ; i++) {
    mods[i] = (1L * mods[i-1] * 2) % mod;
  }
  return mods;
}

int main() {
  ios_base::sync_with_stdio(false);

  int n;
  string xs;
  cin >> n;
  cin >> xs;

  int p = pop_count(xs);

  vector<int> pow2_mod_p_minus_1 = calc_pow2_mod(p-1, n);
  vector<int> pow2_mod_p_plus_1 = calc_pow2_mod(p+1, n);

  int xs_mod_p_minus_1 = calc_mod(xs, p-1, pow2_mod_p_minus_1);
  int xs_mod_p_plus_1 = calc_mod(xs, p+1, pow2_mod_p_plus_1);


  vector<int> fx1(n, 0);
  for (int i = 0 ; i < n; i++) {
    int deg = n - i - 1;
    if (xs[i] == '1') {
      if (p == 1) {
        fx1[i] = -1;
      } else {
        fx1[i] = (xs_mod_p_minus_1 - pow2_mod_p_minus_1[deg] + p - 1) % (p - 1);
      }
    } else {
      // 0
      fx1[i] = (xs_mod_p_plus_1 + pow2_mod_p_plus_1[deg]) % (p + 1);
    }
  }

  for (int i = 0 ; i < n ; i ++) {
    if (fx1[i] == -1) {
      cout << 0 ;
    } else {
      cout << 1 + f(fx1[i]);
    }
    cout << endl;
  }





  return 0;
}

Measured memory_bytes: 6056
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  for(int i=1;i<=1009;i++){
    int c=(i*8)/100;
    int d=(i*10)/100;
    if(c==a&&d==b){
      cout<<i;
      return 0;
    }
    else{
      continue;
    }
  }
  cout<<-1;
  return 0;
}


Measured memory_bytes: 256
N,K= [int(i) for i in input().split()]
R,S,P= [int(i) for i in input().split()]
n=input()
C=N//K + 1
s=0
for i in range(K):
        m=""
        for j in range(i,N,K):
                if n[j] =='r':
                        if j < K:
                                s+=P
                                m ='r'
                        elif n[j-K]=='r' and m=='r': m =""
                        else:
                                s+=P
                                m ='r'
                elif n[j] =='s':
                        if j < K:
                                s+=R
                                m ='s'
                        elif n[j-K]=='s' and m=='s': m =""
                        else:
                                s+=R
                                m ='s'
                elif n[j] =='p':
                        if j < K:
                                s+=S
                                m ='p'
                        elif n[j-K]=='p' and m=='p': m =""
                        else:
                                s+=S
                                m ='p'               
print(s)

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

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int n;
    int v[1000], c[1000];
    cin >> n;

    int ans = 0;
    for (int i = 0; i < n; i++)
        cin >> v[i];

    for (int i = 0; i < n; i++)
        cin >> c[i];

    for (int i = 0; i < n; i++){
        if (v[i] > c[i])
            ans += v[i] - c[i];
    }

    cout << ans << '\n';

    return 0;
}


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

using namespace std;

typedef long long ll;

struct tp{ ll f, s, t; };

vector <tp> V;
ll F[101010], S[101010], T[101010], K[101010];
ll n,s,ans;

int main()
{
	ll i,j,k,a,b,c;
	ll l,r,f = 0;
	
	scanf("%lld",&n);
	
	for(i=0;i<n;i++){
		scanf("%lld",&a);
		b = c = 1;
		for(j=2;j<=2500 && j<=a;j++) if(a % j == 0){
			for(k=0;a%j == 0;k++) a /= j;
			if(k % 3 == 1) b *= j, c *= j * j;
			else if(k % 3 == 2) b *= j * j, c *= j;
		}
		if(a == 1 && b == 1) f = 1;
		else V.push_back({b, c, a});
	}
	
	sort(V.begin(), V.end(), [&](tp ca, tp cb){
		if(ca.f != cb.f) return ca.f < cb.f;
		else return ca.t < cb.t;
	});
	
	for(i=s=0;i<V.size();i++){
		if(!i || (V[i].f != V[i-1].f || V[i].t != V[i-1].t)){
			s ++;
			F[s] = V[i].f;
			S[s] = V[i].s;
			T[s] = V[i].t;
			K[s] = 1;
		}
		else K[s] ++;
	}
	
	for(i=1;i<=s;i++){
		if(F[i] > S[i] || T[i] > 1e9 || T[i] * T[i] > 1e10) continue;
		
		l = lower_bound(F+1, F+s+1, S[i]) - F;
		r = upper_bound(F+1, F+s+1, S[i]) - F;
		k = lower_bound(T+l, T+r, T[i] * T[i]) - T;
		
		if(F[k] == S[i] && T[k] == T[i] * T[i]){
			ans += max(K[i], K[k]);
			K[k] = 0;
		}
		else ans += K[i];
		K[i] = 0;
	}
	
	for(i=1;i<=s;i++) ans += K[i];
	
	printf("%lld\n",ans + f);
	
	return 0;
}

Measured memory_bytes: 6512
N, A, B = map(int, input().split())
N_list = [str(i) for i in range(1, N + 1)]
total = 0
for i in N_list:
    subtotal = 0
    for s in i:
        subtotal += int(s)
    if A <= subtotal <= B:
        total += int(i)
print(total)


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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

// const int INF = 1 << 30;
const ll INF = 1LL << 62;
// const int MOD = 1000000007;

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

  vector<pair<int, int>> p;
  rep (i, N) {
    int x, y;
    cin >> x >> y;
    p.eb(mp(x, y));
  }

  sort(all(p));

  ll ans = INF;
  rep (i, N) REP (j, i + 1, N) {
    vector<pair<int, int>> tmp;
    rep (k, N) if (p[i].F <= p[k].F && p[k].F <= p[j].F) tmp.eb(mp(p[k].S, p[k].F));

    ll w = p[j].F - p[i].F;
    sort(all(tmp));

    rep (k, sz(tmp) - K + 1) {
      ll h = tmp[k + K - 1].F - tmp[k].F;
      ans = min(ans, w * h);
    }
  }

  cout << ans << endl;
}


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

int main(void)
{
	char str[256];
	
	fgets(str, 256, stdin);
	
	for (int i = 0; str[i] != '\0'; i++){
		str[i] = toupper(str[i]);
	}
	
	printf("%s", str);
	
	return (0);
}

Measured memory_bytes: 0
#include<stdio.h>

int main(){

	int i, j, height, width;

	while(1){
		scanf("%d %d", &height, &width);

		if(height == 0 && width == 0){
			break;
		}

		for(i = 0; i < height; i++){
			for (j = 0; j < width - 1; j++){
				printf("#");
			}
			printf("#\n");
		}
		printf("\n");
	}

	return 0;

}

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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

int W,H,N;
const int MAX_N = 1000;
vector<int> VP,VQ,A,B,C,D;
int acc [MAX_N * 2 + 17] [MAX_N * 2 + 17];
bool vis [MAX_N * 2 + 17] [MAX_N * 2 + 17];
const int dx [] = {0,1,0,-1};
const int dy [] = {-1,0,1,0};

int getIdx(vector<int>& v,int val)
{
	return int(lower_bound(v.begin(),v.end(),val) - v.begin());
}

void dfs(int x,int y)
{
	vis [x] [y] = true;
	FOR(i,0,4){
		int nx = x + dx [i],ny = y + dy [i];
		if((nx >= 0 && nx + 1 < VP.size() && ny >= 0 && ny + 1 < VQ.size()) == false) continue;
		if(vis [nx] [ny] || acc [nx] [ny] > 0) continue;
		dfs(nx,ny);
	}
}

int main()
{
	while(scanf("%d%d",&W,&H),W){
		scanf("%d",&N);
		VP = {0,W};
		VQ = {0,H};
		memset(vis,0,sizeof(vis));
		memset(acc,0,sizeof(acc));
		A.assign(N,0);
		B.assign(N,0);
		C.assign(N,0);
		D.assign(N,0);
		FOR(i,0,N){
			scanf("%d%d%d%d",&A [i],&B [i],&C [i],&D [i]);
			VP.push_back(max(0,A [i] - 1));
			VP.push_back(A [i]);
			VP.push_back(max(0,C [i] - 1));
			VP.push_back(C [i]);
			VQ.push_back(max(0,B [i] - 1));
			VQ.push_back(B [i]);
			VQ.push_back(max(0,D [i] - 1));
			VQ.push_back(D [i]);
		}
		sort(VP.begin(),VP.end());
		sort(VQ.begin(),VQ.end());
		VP.erase(unique(VP.begin(),VP.end()),VP.end());
		VQ.erase(unique(VQ.begin(),VQ.end()),VQ.end());

		FOR(i,0,N){
			acc [getIdx(VP,A [i])] [getIdx(VQ,B [i])]++;
			acc [getIdx(VP,C [i])] [getIdx(VQ,B [i])]--;
			acc [getIdx(VP,A [i])] [getIdx(VQ,D [i])]--;
			acc [getIdx(VP,C [i])] [getIdx(VQ,D [i])]++;
		}
		FOR(i,0,VP.size()) FOR(j,0,VQ.size()){
			if(i > 0) acc [i] [j] += acc [i - 1] [j];
			if(j > 0) acc [i] [j] += acc [i] [j - 1];
			if(i > 0 && j > 0) acc [i] [j] -= acc [i - 1] [j - 1];
		}
		
		int ans = 0;
		FOR(i,0,int(VP.size()) - 1) FOR(j,0,int(VQ.size()) - 1) if(vis [i] [j] == false && acc [i] [j] == 0){
			dfs(i,j);
			ans++;
		}
		printf("%d\n",ans);
	}

	return 0;
}

Measured memory_bytes: 38392
if __name__ == '__main__':
    x = [list(map(int, input().split())) for i in range(1)]

    try:
        x = int(x[0][0])
    except Exception as e:
        print('error')
        exit(1)

    if x == 0:
        print(1)
    elif x == 1:
        print(0)
        



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

typedef long long ll;

int main(void) {
	int N, P;
	cin >> N >> P;

	bool f_odd = false;
	for (int i = 0; i < N; ++i) {
		int a;
		cin >> a;
		if (!f_odd) {
			if (a % 2 == 1)
				f_odd = true;
		}
	}

	ll ans;
	if (f_odd)
		ans = (1LL << (N - 1));
	else {
		if (P == 0)
			ans = (1LL << N);
		else
			ans = 0LL;
	}

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <regex>
#include <cstdio>
#include <cmath>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>

using namespace std;
using ll = long long int;
#define rep(i,n) for(int i = 0; i < n; i++)
#define FOR(i, a, b)  for(int i = (a); i < (b) ; i++)
#define pb push_back
#define SORT(v,n) sort(v, v+n)
#define ALL(x) (x).begin(),(x).end()
#define debug(x) cerr << #x << ": " << x << '\n'
#define elif else if
#define itn ll
#define int ll
//const int INF = 100100100;
const int INF = (1LL << 32);
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int dx[8] = { 1, 0, -1, 0, 1, -1, -1, 1 };
int dy[8] = { 0, 1, 0, -1, 1, 1, -1, -1 };
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;

int n, c, k;
vector<int> t;
signed main() {
	ios::sync_with_stdio(false);
	cin >> n >> c >> k;
	rep(i, n) {
		int time;
		cin >> time;
		t.pb(time);
	}
	int ans = 0;
	sort(ALL(t));

	int cnt = 0;
	int limit = t[0] + k;
	//for (auto x : t) {
	//	cout << x << ' ';
	//}
	//cout << endl;
	int f = 0;
	for (int i = 0; i < t.size(); i++) {
		if (t[i] > limit or cnt == c) {
			//cout << "ans++" << endl;
			ans++;
			f = i;
			//debug(cnt);
			cnt = 0;
			//cout << "now limt is " << limit << endl;
			limit = t[i] + k;
			//cout << "next kyaku is" << t[i] << "arrive\n";
			//cout << "next limit is " << limit << endl;
		}
		cnt++;
	}
	cout << ans+1 << endl;
	return 0;
}



Measured memory_bytes: 1400