akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <string>
#include <algorithm>
#include <set>
using namespace std;
string s;

int main(){
    cin >> s;
    int n = s.length();
    if(n < 3){cout << '0';return 0;}
    long long ans = 0, na = 0;
    for(int i = 0; i < n - 1; i++){
        if(s[i] == 'A'){
            na++;
        }
        else if(s[i] == 'B' && s[i + 1] == 'C'){
            ans += na;
            i++;
        }
        else{
            na = 0;
        }
    }
    cout << ans;
    return 0;
}


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

int main(){
    string s;
    long long ans = 0;
    cin >> s;
    for(int i = 0, p = 0; i < s.length(); i++){
        if(s[i] == 'W') ans += i - p++;
    }
    cout << ans;
    return 0;
}

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




int N;
string SA[10101], SZ[10101];
string T;
//-----------------------------------------------------------------------------------
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);

    cin >> N;
    rep(i, 0, N) cin >> SA[i];
    cin >> T;

    rep(i, 0, N) {
        SZ[i] = SA[i];
        rep(j, 0, SA[i].length()) if (SA[i][j] == '?') SA[i][j] = 'a';
        rep(j, 0, SA[i].length()) if (SZ[i][j] == '?') SZ[i][j] = 'z';
    }

    sort(SA, SA + N);
    sort(SZ, SZ + N);
    
    int L = lower_bound(SZ, SZ + N, T) - SZ;
    int R = upper_bound(SA, SA + N, T) - SA;

    rep(i, L, R + 1) {
        printf("%d", i + 1);
        if (i != R) printf(" ");
    }
    printf("\n");
}

Measured memory_bytes: 1408
use std::io;


fn main() {
    let n = read_one::<usize>();
    let an = read::<usize>();
    let bn = read::<usize>();

    if an.iter().sum::<usize>() < bn.iter().sum::<usize>() {
        println!("-1");
        return;
    }

    let mut diff = vec![0; n];
    for i in 0..n {
        diff[i] = an[i] as isize - bn[i] as isize;
    }

    diff.sort();
    diff.reverse();

    let mut cnt = 0;
    let mut sum: isize = 0;

    for i in 0..n {
        if an[i] < bn[i] {
            cnt += 1;
            sum += (bn[i] - an[i]) as isize;
        }
    }

    let mut idx = 0;
    while sum > 0 {
        sum -= diff[idx] as isize;
        idx += 1;
    }

    println!("{}", idx + cnt);
}


#[allow(dead_code)]
fn read<T>() -> Vec<T>
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.split_whitespace()
        .map(|s| s.trim().parse().unwrap())
        .collect()
}

#[allow(dead_code)]
fn read_one<T>() -> T
where T:
std::str::FromStr,
T::Err: std::fmt::Debug {

    let mut buf = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    buf.trim().parse().unwrap()
}

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

long long int a,b,c;

int main() {
  cin >> a >> b >> c;
  if (a + b < c) {
    if (4 * a * b < (c -  a - b) * (c - a - b)) {
      cout << "Yes" << endl;
    }else{
      cout << "No" << endl;
    }
  }else{
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define MOD 1000000007
const int INF = 1LL<<30;

int main(){
    int n;
    cin>>n;
    vector<ll> A(n);
    map<ll,ll> mp;
    rep(i,n){
        cin>>A[i];
        mp[A[i]]++;
    }

    if(mp.size()==1){
        if(mp[0]!=0){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    if(mp.size()==2 && n%3==0){
        ll tmp=0;
        for(auto s : mp){
            if(s.first!=0) tmp=s.second;
        }

        if(mp[0]*3==n && tmp*3/2==n){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    if(mp.size()==3 && n%3==0){
        vector<ll> a(0);
        for(auto s : mp){
            a.push_back(s.first);
            if(s.second!=n/3){
                cout<<"No"<<endl;
                return 0;
            }
        }
        if((a[0]^a[1]^a[2])==0){
            cout<<"Yes"<<endl;
            return 0;
        }
    }

    cout<<"No"<<endl;
}

Measured memory_bytes: 8640
#include<bits/stdc++.h>
#define rep(i,a,n) for (int i = a;i < n;i++)
#define per(i,n,a) for (int i = n-1;i >= a;i--)
using namespace std;

int main(){
    int sx,sy,tx,ty; cin >> sx >> sy >> tx >> ty;
    const int dx=tx-sx,dy=ty-sy;
    // Path 1
    cout << string(dy,'U') << string(dx,'R');
    // Path 2
    cout << string(dy,'D') << string(dx,'L');
    // Path 3
    cout << 'L' << string(dy+1,'U') << string(dx+1,'R') << 'D';
    // Path 4
    cout << 'R' << string(dy+1,'D') << string(dx+1,'L') << 'U';
    // EndLine
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define sz(x) int(x.size())
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())

using namespace std;
typedef long long ll;

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; }
const int INF = 1001001001;
const long long INFL = (1LL<<60);
const double eps = (1e-9);

ll mod = 1000000007;

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

  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {
    ll tmp;
    cin >> tmp;
    if (tmp == k) {
      cout << "POSSIBLE" << endl;
      return 0;
    }
    a[i] = tmp;
  }

  sort(ALL(a));

  if (k > a[n-1]) {
    cout << "IMPOSSIBLE" << endl;
    return 0;
  }

  vector<ll> b(n);
  b[0] = a[0];
  for (int i = 0; i < n-1; i++) {
    b[i+1] = a[i+1] - a[i];
  }

  sort(ALL(b));

  for (auto& v : b) {
    if (v == 0) continue;
    k %= v;
  }

  if (k == 0) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
 
#define faster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define mp make_pair
#define mod 1000000007
#define qmod 998244353
#define endl "\n"
#define pb push_back
#define ff first
#define ss second
 
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
 
const int MOD = 1e9 + 7;
const int INF = 1e9 + 5;
const ll LINF = LLONG_MAX;

int main(){
	ll k,n;
    cin>>k>>n;
    ll a[n],d[n];
    for(ll i=0;i<n;i++){
    	cin>>a[i];
    }
    for(ll i=0;i<n;i++){
    	if(i!=n-1){
    		d[i] = a[i+1]-a[i];
    	}
    	else{
    		d[i] = k-a[i]+a[0];
    	}
    }
    ll res=0;
    sort(d,d+n);
    for(ll i=0;i<n-1;i++){
    	res +=d[i];
    }
    cout<<res<<endl;

	
		

	
}

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

using namespace std;

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

	int n; cin >> n;
	double p[n + 1];
	for (int i = 1; i <= n; ++i) {
		cin >> p[i];
	}
	double dp[n + 1][n + 1];
	dp[1][0] = 1 - p[1];
	for (int i = 2; i <= n; ++i) {
		dp[i][0] = (1 - p[i]) * dp[i - 1][0];
	}
	dp[1][1] = p[1];
	for (int i = 2; i <= n; ++i) {
		dp[1][i] = 0;
	}
	for (int i = 2; i <= n; ++i) {
		for (int j = 1; j <= n; ++j) {
			dp[i][j] = p[i] * dp[i - 1][j - 1] + (1 - p[i]) * dp[i - 1][j];
		}
	}
	double ans = 0;
	for (int i = n - (n / 2); i <= n; ++i) {
		ans += dp[n][i];
	}
	cout << fixed << setprecision(10) << ans << endl;
}

Measured memory_bytes: 70528
n = int(input().strip())
r = [[0] * 2] * n

for i in range(n):
    r[i] = list(map(lambda x: x.strip(), input().split()))

for i in range(n):
    r[i].extend([i + 1])

r.sort(key=lambda x: (x[0], -int(x[1])))

for i in range(n):
    print(r[i][2])


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

using ll=long long;
int main(){
    ll n,m;
    cin>>n>>m;
    if(n==1 && m==1){
        cout<<1<<endl;
        return 0;
    }
    if(n==1){
        cout<<m-2<<endl;
        return 0;
    }
    if(m==1){
        cout<<n-2<<endl;
        return 0;
    }
    ll kado=4;
    ll hasi=(n-2)*2+(m-2)*2;
    ll oth=m*n-hasi-kado;
    cout<<oth<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
#define mp make_pair
#define ff first
#define ss second

int n;

inline int read(){
	int x=0,f=1; char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar()) if (ch=='-') f=-1;
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x*f;
}

int main(){
	n=read(); int ans=0;
	for (int i=1;i<=n;i++){
		int a=read(),b=read();
		while (a%b){
			int pp=a%b,pps=a/b+1;
			a-=(pp/pps)*(a/b+1);
			if (pp%pps) a-=a/b+1;
		}
		ans^=a/b;
	}
	puts(ans?"Takahashi":"Aoki");
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <assert.h>
#define INF 2000000001
int A[2000002], heap_size=0;

void maxHeapify(int i){
  int l, r, max, cp;
  l = 2*i;
  r = 2*i+1;
  if(l <= heap_size && A[l] > A[i])
    max = l;
  else max = i;
  if(r <= heap_size && A[r] > A[max])
    max = r;
  if(max != i){
    cp = A[i];
    A[i] = A[max];
    A[max] = cp;
    maxHeapify(max);
  }
  return;
}
int extract(){
  int max;
  max = A[1];
  A[1] = A[heap_size];
  heap_size--;
  maxHeapify(1);
  return max;
}
void heapIncreaseKey(int i, int key){
  int ch;
  A[i] = key;
  while(i > 1 && A[i/2] < A[i]){
    ch = A[i];
    A[i] = A[i/2];
    A[i/2] = ch;
    i = i/2;
  }
  return;
}
void insert(int key){
  //heap_size = heap_size+1;
  heap_size++;
  A[heap_size] = INF;
  heapIncreaseKey(heap_size, key);
  return;
}
int main(){
  int key, max;
  char s[10];
  while(1){
    scanf("%s",s);
    if(s[0] == 'i'){
      scanf("%d",&key);
      //heap_size++;
      insert(key);
    }
    else if(s[1] == 'x'){
      max = extract();
      printf("%d\n",max);
    }
    else if(s[0] == 'e')
      break;
  }
  return 0;
}

Measured memory_bytes: 4696
from collections import defaultdict
N = int(input())
dic = defaultdict(list)

for i in range(1,N+1):
  inf = input().split()
  a = int(inf[0])
  b = int(inf[1])
  dic[b] += [a]

keys = list(dic.keys())
keys.sort()
ps = 0

for k in keys:
  ls = dic[k]
  need = sum(ls)
  ps += need
  if ps>k:
    print('No')
    break
else:
  print('Yes')

Measured memory_bytes: 85720
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <fstream>
#include <sstream>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <string>
#include <queue>
#include <bitset>     //UWAGA - w czasie kompilacji musi byc znany rozmiar wektora - nie mozna go zmienic
#include <cassert>
#include <iomanip>        //do setprecision
#include <ctime>
#include <complex>
using namespace std;

#define FOR(i,b,e) for(int i=(b);i<(e);++i)
#define FORQ(i,b,e) for(int i=(b);i<=(e);++i)
#define FORD(i,b,e) for(int i=(b)-1;i>=(e);--i)
#define REP(x, n) for(int x = 0; x < (n); ++x)

#define ST first
#define ND second
#define PB push_back
#define MP make_pair
#define LL long long
#define ULL unsigned LL
#define LD long double

const double pi = 3.141592653589793238462643383279502884197169399375105820974944592307816406286208998628034825342;
const int mod=1000000007;

int main(){
 	LL a,b,c,x,y,ans=1LL*mod*mod*2;
	cin>>a>>b>>c>>x>>y;
	LL r=min(x,y);
	LL cost=0;
	if(a+b>2*c){
		cost+=2*c*r;
	}else{
		cost+=a*r+b*r;
	}
	if(x>y){
		x=x-r;
		if(2*c<a){
			cost+=2*c*x;
		}else{
			cost+=a*x;

		}
	}else{
		y=y-r;
		if(2*c<b){
			cost+=2*c*y;

		}else{
			cost+=b*y;

		}
	}
	cout<<cost<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>
using namespace std;
typedef long long ll;

int main(){
  ll mod = (ll) pow(10, 9) + 7;
  ll n, k;
  cin >> n >> k;
  ll min = 0;
  ll max = 0;
  ll count = 0;
  for (k; k<=n+1; k++){
    count += (k * (n-k+1) + 1) % mod;
  }
  
  cout << count % mod << endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> VI;
typedef vector<VI> VVI;
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define PRINT(V) for (auto v : (V)) cout << v << " "


int main()
{
    ll n; cin >> n;
    vector<ll> a(n); rep(i, n) cin >> a[i];
    map<ll, ll> ai, aj;
    ll c = 0;
    rep(i, n) {
        ++ai[i + a[i]];
        ++aj[i - a[i]];
    }

    for(const auto& e : ai) {
        if (aj.count(e.first) == 1) {
            c += e.second*aj[e.first];
        }
        
    }
    cout << c << endl;
    return 0;
}


Measured memory_bytes: 27952
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);
#define FO cout.tie(NULL);
#define FI cin.tie(NULL);
#define IN cin>>
#define OUT cout<<
#define loop(i,a,n) for(int i=a; i<n; i++)
#define rloop(i,a,n) for(int i=a; i>=n; i--)
#define endl "\n";
#define pb push_back
#define mp make_pair
#define set_bits(a) __builtin_popcountll(a)
#define ll long long int
#define ld long double
#define vll vector<long long int>
#define pll pair<long long int, long long int>
#define mod 1000000007
#define M 998244353
using namespace std;
ll gcd(ll a, ll b)
{
    return (b?gcd(b,a%b):a);
}
ll P(ll B, ll power, ll modulo)
{
    ll ans=1LL;
    while(power>0LL)
    {
        if(power%2LL==1LL)
        {
            ans=(ans*B)%modulo;
        }
        B=(B*B)%modulo;
        power/=2LL;
    }
    return ans;
}
bool isPrime(ll n)
{
    if(n<=1LL)
    {
        return false;
    }
    if(n<=3LL)
    {
        return true;
    }
    if(n%2==0LL || n%3==0LL)
    {
        return false;
    }
    for(ll i=5LL; (i*i)<=n; i+=6LL)
    {
        if(n%i==0LL || n%(i+2LL)==0LL)
        {
            return false;
        }
    }
    return true;
}
void vok()
{
    FAST
    FO
    FI
}
int main()
{
    vok();
    ll n,k;
    IN n>>k;
    vll a(n);
    bitset<50> b[n];
    loop(i,0,n)
    {
        IN a[i];
        bitset<50> temp(a[i]);
        b[i]=temp;
    }
    bitset<50> ans(0);
    rloop(i,49,0)
    {
        int countt=0;
        loop(j,0,n)
        {
            if(b[j][i])
            {
                countt++;
            }
          	//cout<<"";
        }
        ans[i]=1;
        if((countt*2)<n && ans.to_ullong()<=k)
        {
            //Do Nothing
        }
        else
        {
            ans[i]=0;
        }
    }
    ll fans=0LL;
    ll X=ans.to_ullong();
    loop(i,0,n)
    {
      	//cout<<"";
        fans+=(X^a[i]);
    }
    OUT fans<<endl
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    int A,B; cin>>A>>B;

    set<int> s;
    s.insert(1);
    s.insert(2);
    s.insert(3);

    s.erase(A);
    s.erase(B);

    cout << *s.begin() << endl;
}

Measured memory_bytes: 256
N,M=map(x->parse(Int,x),split(readline()))
s=zeros(Int,M,N)
for i=1:M
	t=map(x->parse(Int,x),split(readline()))
	for j=t[2:end]
		s[i,j]=1
	end
end
p=map(x->parse(Int,x),split(readline()))
ans=0
for i=0:(1<<N)-1
	flag=true
	for j=1:M
		now=p[j]
		for k=1:N
			now+=(i>>(k-1))%2*s[j,k]
		end
		if now%2!=0
			flag=false
		end
	end
	global ans+=flag
end
println(ans)


Measured memory_bytes: 118380
#include <iostream>
#include <utility>
#include <vector>
#include <list>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <cassert>
#include <cmath>
#include <algorithm>
#include <stdlib.h>
#include <stdio.h>
#include <fstream>
#include <tuple>

//....................................................................................................................//

using std::cin;
using std::cout;
using std::vector;
using std::list;
using std::unordered_set;
using std::set;
using std::map;
using std::unordered_map;
using std::multimap;
using std::unordered_multimap;
using std::pair;
using std::make_pair;
using std::min;
using std::max;
using std::swap;
using std::stack;
using std::deque;
using std::queue;
using std::ios_base;
using std::ifstream;
using std::ofstream;
using std::string;
using std::tuple;
using std::make_tuple;
using std::get;
using std::upper_bound;
using std::lower_bound;
using std::max_element;
using std::min_element;
using std::multiset;
using std::greater;
using std::priority_queue;
using std::less;

//....................................................................................................................//

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long ul;

[[maybe_unused]] const string endl = "\n";
[[maybe_unused]] const string sep = " ";
[[maybe_unused]] const string yes = "YES\n";
[[maybe_unused]] const string no = "NO\n";
[[maybe_unused]] const string ng = "NG\n";
[[maybe_unused]] const string ok = "OK\n";
[[maybe_unused]] const double pi = acos(-1);
[[maybe_unused]] const ull modular = 998244353;

//....................................................................................................................//


int main() {
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout.precision(10);
    ll n, k;
    cin >> n >> k;
    vector<ll> A(n);
    for (int i = 0; i < n; ++i) {
        cin >> A[i];
    }
    ll cur = 0;
    ll teleports = 0;
    set<ll> Visited;
    vector<ll> V(n, -1);
    V[0] = 0;
    bool x = true;
    while (teleports != k && x) {
        cur = A[cur] - 1;
        ++teleports;
        if (V[cur] != -1) {
            x = false;
            k -= teleports;
            k %= teleports - V[cur];
            while (k != 0) {
                --k;
                cur = A[cur] - 1;
            }
        } else {
            V[cur] = teleports;
        }
    }
    cout << cur + 1;
}


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

int main()
{
  int n;
  cin >> n;
  set<int> st;
  int d;
  for (int i = 0; i < n; i++) {
    cin >> d;
    st.insert(d);
  }
  cout << st.size() << endl;
}


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

constexpr ll MOD = 1000000007;

vector<vector<char>> field;
ll dp[1010][1010];

int main(int argc, char **argv)
{
	ll H, W; cin >> H >> W;
	field.assign(H, vector<char>(W));
	for (ll h = 0; h < H; ++h)
		for (ll w = 0; w < W; ++w)
			cin >> field[h][w];

	dp[0][0] = 1;

	for (ll h = 0; h < H; ++h)
	{
		for (ll w = 0; w < W; ++w)
		{
			if (h+1 < H && field[h+1][w] == '.')
				(dp[h+1][w] += dp[h][w]) %= MOD ;
			if (w+1 < W && field[h][w+1] == '.')
				(dp[h][w+1] += dp[h][w]) %= MOD;
		}
	}
	std::cout << dp[H-1][W-1] << std::endl;
}

Measured memory_bytes: 9088
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K; cin >> N >> K;
    vector<ll> A(N);
    rep(i,N) cin >> A[i];
    sort(all(A));
    ll ub=1e18,lb=-1e18;
    ub+=1,lb-=1;
    while(ub-lb>1){
        ll mid=(ub+lb)/2;
        ll cnt=0;
        rep(i,N){
            if (A[i]==0) if (0<=mid) cnt+=N-1;
            if (A[i]>0){
                cnt+=upper_bound(all(A),mid/A[i]+(mid<0&&mid%A[i]!=0?-1:0))-A.begin();
                if (A[i]*A[i]<=mid) --cnt;
            }
            if (A[i]<0){
                cnt+=A.end()-lower_bound(all(A),mid/A[i]+(mid<0&&mid%A[i]!=0?1:0));
                if (A[i]*A[i]<=mid) --cnt;
            }
        }
        cnt/=2;
        (K<=cnt?ub:lb)=mid;
    }
    cout << ub << endl;
}

Measured memory_bytes: 1792
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}

enum{N=200023};

class UNI{
public:
	int fa[N];
	bool len[N];
	bool chk[N];
	il void init(int n){
		rep(i,1,n) fa[i]=i, len[i]=0;
	}
	int fd(int x){
		if( fa[x]==x ) return x;
		fd(fa[x]);
		len[x] ^= len[fa[x]];
		fa[x] = fa[fa[x]];
		return fa[x];
	}
	il int merge(int x,int y){
		chk[x]=1, chk[y]=1;
		if( fd(x)!=fd(y) ){
			len[fa[x]]= len[x]^len[y]^1;
			fa[fa[x]]= fa[y];
			return 0;
		}
		return -1;
	}
}uni;

struct Edge{ int nxt,to,id; } bow[N*4];
int head[N],tot_e;
il void add(int x,int y,int id){
//	printf("add %d %d\n",x,y);
	bow[++tot_e]=(Edge){head[x],y,id};
	head[x]=tot_e;
}

int d[N];
struct cmp1{
	bool operator()(int a,int b)const{ return d[a]<d[b]; }
};

int vis[N],ans[N];
void dfs(int u){
	each(i,u){
		int v=bow[i].to;
//		printf("%d -> %d\n",u,v);
		if( vis[v] ){
			ans[bow[i].id] = 1e9;
			continue;
		}
		vis[v] = vis[u];
		ans[bow[i].id] = d[v]-d[u];
		dfs(v);
	}
}

int main(){
	int n=ci(), m=ci();
	uni.init(n);
	rep(i,1,n) d[i]=ci();
	rep(i,1,m){
		int x=ci(), y=ci();
		if( d[x]!=d[y] ){
			if( d[x]>d[y] ) swap(x,y);
			add(x,y,i);
		}else{
			ans[i] = d[x];
//			printf("merge %d %d\n",x,y);
			if( uni.merge(x,y)==-1 ){
				ans[i] = 1e9;
			}
//			rep(j,1,n) printf("%d ",uni.fa[j]); pt('\n');
//			rep(j,1,n) pt( uni.len[j]==0? 'W':'B'); pt('\n');
		}
	}
	rep(i,1,n) if( uni.chk[i] ) uni.fd(i), vis[i] = uni.len[i] ? 1:2 ;
	int tot_seq = 0;
	static int seq[N];
	rep(i,1,n) if( vis[i] ) seq[++tot_seq] = i;
	rep(i,1,tot_seq) dfs(seq[i]);
	bool fail = 0;
	rep(i,1,n) if( vis[i]==0 ) fail=1;
	if( fail ){
		puts("-1");
		return 0;
	}
	rep(i,1,n) pt(vis[i]==1 ? 'W':'B'); pt('\n');
	rep(i,1,m) printf("%d\n",ans[i]);
	return 0;
}


Measured memory_bytes: 9984
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)

#define int ll //!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    int X;
    cin >> X;
    vi v;
    for(int i = 1; i*i <= X; i++)if(X%i == 0){
        v.push_back(i);
        if(i*i < X) v.push_back(X/i);
    }
    rep(i,v.size()){
        int x = v[i];
        int y = X/v[i];
        // a-b = x
        // a^4 + a^3*b + a^2*b^2 + a*b^3 +b^4 = y
        //a = x+bとすると
        //(x+b)^4 + (x+b)^3*b + (x+b)^2*b^2 + (x+b)*b^3 +b^4 = y
        // y = 5b^4 + 10b^3x + 9b^2x^2 + 6bx^3 + x^4
        //これを満たす整数bは存在しますか？
        rep(a,sqrt(y)){
            int b = a - x;
            if(a*a*a*a + a*a*a*b + a*a*b*b + a*b*b*b + b*b*b*b == y){
                cout << a << " " << b << endl;
                return 0;
            }
        }

    }
}


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

int main() {
	string s;
    cin>>s;
  
  if(s.at(0)==s.at(1)){
  	cout<<"Bad"<<endl;
  }
  else if(s.at(1)==s.at(2)){
   	cout<<"Bad"<<endl;
  }
  else if(s.at(2)==s.at(3)){
  	cout<<"Bad"<<endl;
  }
  else
      cout<<"Good"<<endl;
     
    
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n';
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("Ofast")
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr double INFD = 1e100;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
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; }
// ios::sync_with_stdio(false);
// cin.tie(nullptr);
// ---------------------------------------------------------------------------

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  double L;
  cin >> L;
  double ans = L/3.0;
  ans = ans*ans*ans;
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int, a: "List[int]"):
    num = 1
    for aa in a:
        if aa == num:
            num +=1
    
    if num == 1:
        print(-1)
    else:
        print(N-(num-1))
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 25980
# t=int(input())
# for _ in range(t):
#     m,n=tuple(map(int,input().split(" ")))
#     if(m<6):
#         print("NO")
#     elif(m%n==0):
#         print("YES")
#     else:
#         print("NO")
str=input()
if(str[2]==str[3] and str[4]==str[5]):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 2940
while True:
    N = int(raw_input())
    if N == 0:
        break
    secret = []
    for i in xrange(N):
        secret.append(set(map(int, raw_input().split())[1:]))
    leak = set(map(int, raw_input().split())[1:])
    candidate = -1
    for i in xrange(N):
        if leak.issubset(secret[i]):
            if candidate == -1:
                candidate = i + 1
            else:
                candidate = -1
                break
    print candidate

Measured memory_bytes: 4936
import           Control.Monad
import qualified Data.Array.IO               as IO
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

main = do
  n <- getInt
  as <- getIntVec n
  let a i = as V.! (i-1)

  bs <- VM.new (n+1)

  forM_ [n,(n-1)..1] $ \i -> do
    VM.write bs i (a i)
    when (n `div` i > 1) $
      forM_ [2..(n `div` i)] $ \j -> do
        x <- VM.read bs (i*j)
        t <- VM.read bs i
        VM.write bs i ((t + x) `mod` 2)

  bs' <- V.freeze bs

  let ans = [i | i <- [1..n], bs' V.! i > 0]
      m = length ans

  print m
  when (m > 0) $ putStrLn $ foldr (\i a -> show i ++ " " ++ a) "" ans

Measured memory_bytes: 12412
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
using namespace std;
typedef  long long int lint;
typedef pair<int, int> P;
typedef pair<lint, lint> LLP;
typedef pair<char, char>CP;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
/*
vector<char>al(26);
al = {'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
vector<char>AL(26);
AL = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
*/

int main() {
	vector<char>al(10);
	al = { '0','1','2' ,'3' ,'4' ,'5' ,'6' ,'7' ,'8' ,'9' };

	int N;
	cin >> N;
	string S;
	cin >> S;
	vector<vector<char>>H(1000,vector<char>(3));


	int cnt = 0;
	rep(i, 10) {
		rep(j, 10) {
			rep(k, 10) {
				H[cnt][0] = char(al[i]);
				H[cnt][1] = char(al[j]);
				H[cnt][2] = char(al[k]);
				cnt++;
			}
		}
	}
	/*rep(i, 1000) {
		rep(j, 3) {
			cout << H[i][j];
		}
		cout << endl;
	}*/
	int a = -1;
	int b = -1;
	int c = -1;
	int ans = 0;
	rep(i, 1000) {
		rep(j, N) {
			if (H[i][0] == S[j]) {
				a = j;
				break;
			}
		}
		if (a < N - 2&&a!=-1) {
			for (int j = a + 1; j < N; j++) {
				if (H[i][1] == S[j]) {
					b = j;
					break;
				}
			}
		}
		if (b < N - 1&&b!=-1) {
			for (int j = b + 1; j < N; j++) {
				if (H[i][2] == S[j]) {
					c = j;
					break;
				}
			}
		}
		if (a != -1 && b != -1 && c != -1) {
			ans++;
		}
		a = -1;
		b = -1;
		c = -1;
	}
	cout << ans << endl;

}



Measured memory_bytes: 384
#include <iostream>

using namespace std;
long long dp[110][100010],a[110],b[110],ans;
int main(){
	int i,j,n,w;
	cin >> n >> w;
	for(i=1;i<=n;i++){
		cin >> a[i] >> b[i];
	}
	for(i=0;i<=n;i++){
		for(j=0;j<=w;j++){
			dp[i][j] = -1;
		}
	}
	dp[0][0] = 0;
	for(i=1;i<=n;i++){
		for(j=0;j<=w;j++){
			dp[i][j] = max(dp[i][j],dp[i-1][j]);
			if(a[i] + j > w || dp[i-1][j] == -1) continue;
			dp[i][a[i] + j] = max(dp[i][a[i] + j],dp[i-1][j] + b[i]);
		}
	}
	for(i=0;i<=w;i++){
		ans = max(ans,dp[n][i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define pi M_PI
#define R cin>>
#define Z class
#define ll long long
#define ln cout<<'\n'
#define in(a) insert(a)
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define all(c) (c).begin(),(c).end()
#define iter(c) __typeof((c).begin())
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define REP(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define rep(i,n) REP(i,0,n)
#define tr(it,c) for(iter(c) it=(c).begin();it!=(c).end();it++)
template<Z A>void pr(A a){cout<<a;ln;}
template<Z A,Z B>void pr(A a,B b){cout<<a<<' ';pr(b);}
template<Z A,Z B,Z C>void pr(A a,B b,C c){cout<<a<<' ';pr(b,c);}
template<Z A,Z B,Z C,Z D>void pr(A a,B b,C c,D d){cout<<a<<' ';pr(b,c,d);}
template<Z A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}ln;}
ll check(ll n,ll m,ll x,ll y){return x>=0&&x<n&&y>=0&&y<m;}
const ll MAX=1000000007,MAXL=1LL<<61,dx[4]={-1,0,1,0},dy[4]={0,1,0,-1};
typedef pair<int,int> P;

void Main() {
  int n;
  while(R n && n) { 
    map<char,int> m;
    char c[n];
    rep(i,n) R c[i];
    rep(i,n) {
      m[c[i]]++;
      int r=n-i-1;
      char ch;
      int M=0;
      tr(it,m) {
        if(M<it->S) {
          M=it->S;
          ch=it->F;
        }
      }
      bool f=r<M;
      tr(it,m) {
        if(it->F==ch) continue;
        if(it->S+r>=M) f=0;
      }
      if(f) {
        pr(ch,i+1);
        goto next;
      }
    }
    pr("TIE");
  next:;
  }
}

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


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

int main() {
    long long n;cin>>n;
    vector<long long> vec(n);
    for(int i=0;i<n;i++) cin>>vec.at(i);
    int result=0;
    int cnt=0;
    for(int i=0;i<n-1;i++){
        if(vec.at(i)>=vec.at(i+1)){
            cnt++;
        }else{
            if(result<cnt){
                result=cnt;
            }
            cnt=0;
        }
    }
    if(result<cnt){
        result=cnt;
    }
    cout<<result<<endl;
}

Measured memory_bytes: 1024
#include <stdio.h>

int partition(int *A,int p,int r){

  int x,i,j,tmp;
  
  x=A[r];
  i=p-1;
  
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i=i+1;
      tmp=A[i];
      A[i]=A[j];
      A[j]=tmp;
    }
  }
  
  tmp=A[i+1];
  A[i+1]=A[r];
  A[r]=tmp;

  return i+1;
}


int main(){

  int n,i,k;

  scanf("%d",&n);

  int A[n];
  
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
  }

  k=partition(&A[0],0,n-1);

  for(i=0;i<n;i++){
    if(i==k)printf("[");
    printf("%d",A[i]);
    if(i==k)printf("]");
    if(i!=n-1)printf(" ");
  }
  
  printf("\n");
  
  return 0;
}



Measured memory_bytes: 2156
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
int main()
{
  int X, A;
  cin >> X>>A;
  if(X < A){ cout << 0 << endl;}
  else{
    cout << 10 << endl;
  }
}


Measured memory_bytes: 256
S = list(input())
T = list(input())
s = len(S)
t = len(T)
X = False
k = -1
for i in range(s - t + 1):
    OK = True
    for j in range(t):
        if S[i + j] != '?' and S[i + j] != T[j]:
            OK = False
            break
    if OK:
        k = i
if k != -1:
    for j in range(t):
        S[k + j] = T[j]
    X = True
if not X:
    print('UNRESTORABLE')
else:
    for i in range(s):
        if S[i] == '?':
            S[i] = 'a'
        print(S[i], end='')
    print('')

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

int main() {
  //代入する。
  int K, S;
  cin >> K >> S;
  
  int count;
  for (int i = 0; i <= K; i++) {
    for (int j = 0 ; j <= K; j++) {
      if ((S - i - j) >= 0 && (S - i - j) <= K) {
        count ++;
      }
    }
  }
  
  cout << count << endl;
  
}



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

int dp[2][5000][5000];

int main() {
  int n;
  cin >> n;
  int a[n],sum=0;;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    sum+=a[i];
  }
  sort(a,a+n,greater<int>());
  dp[0][0][0]=1;
  for(int i=0; i<n; i++) {
    for(int j=3000; j>=0; j--) {
      for(int k=3000; k>=0; k--) {
        dp[1][a[i]+j][k]|=dp[0][j][k];
        dp[1][j][a[i]+k]|=dp[0][j][k];
      }
    }
    for(int j=3000; j>=0; j--) {
      for(int k=3000; k>=0; k--) {
        dp[0][j][k]|=dp[1][j][k];
        dp[1][j][k]=0;
      }
    }
  }
  int ans=1<<29;
  for(int i=0; i<3000; i++) {
    for(int j=0; j<3000; j++) {
      if(!dp[0][i][j]) continue;
      int k=sum-i-j;
      ans=min(ans,max(i,max(j,k)));
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 98836
#include <iostream>
#include <vector>
#include <string>
#include <sstream>
#include <algorithm>
#include <stack>
using namespace std;

vector<string> split(const string &s, char delim) {
  vector<string> elems;
  stringstream ss(s);
  string item;
  while (getline(ss, item, delim)) {
    if (!item.empty()) {
      elems.push_back(item);
    }
  }
  return elems;
}

int main() {
  string s;
  cin >> s;
  string plus = "+";
  int n = s.size() - 1;
  long long sumAll = 0;
  for (int bit = 0; bit < (1 << n); ++bit) {
    string tmpS = s;
    int countPlus = 0;
    for (int i = 0; i < n; i++) {
      if(bit & (1 << i)) {
        int pos = tmpS.size() - (i + 1 + countPlus);
        tmpS.insert(pos,plus);
        countPlus++;
      }
    }
    
    char del = '+';
    vector<string> vec;
    vec = split(tmpS,del);
    long long sum = 0;
    for (int i = 0; i < vec.size(); i++) {
      sum += stol(vec[i]);
    }
    sumAll += sum;
  }
  cout << sumAll << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int n=scan.nextInt();
		int debt=100000;
		int temp;
		double interest = 0.05;

		for(int i=1;i<=n;i++){
			debt+=debt*interest;
			temp=debt%1000;
			if(temp>0){
				debt=debt-temp+1000;
			}
		}
		System.out.println(debt);
	}

}

Measured memory_bytes: 17148
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <vector>
#define Rep(i, n) for(int i=0;i<n;++i)
#define rep(i, n) for(int i=1;i<=n;++i)
#define ll long long int
#define INF 1e9
#define LINF 1e18
#define MOD 1000000007
#define PI 3.14159265359
#define All(a) (a).begin(), (a).end()

using namespace std;
using P = pair<ll, ll>;
 
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

/**
 * Usage:
 * 
 * G[from].push_back(Edge(to, weight));
 * using Graph = vector<vector<Edge>>;
 * 
 */ 
struct Edge {
  int to;     
  ll weight; 
  Edge(int t, ll w) : to(t), weight(w) { }
};

template<typename T>
void printv(vector<T>& v) {
  if (v.size() == 0) {
    cout << "\n";
    return;
  }

  Rep(i, v.size()) {
    cout << v[i] << ((i + 1 < v.size()) ? ' ' : '\n');
  }
}



int N, M;
int pena[110000];
bool state[110000];

int main () {
  cin >> N >> M;

  int ans_a = 0;
  int ans_p = 0;

  Rep(i, M) {
    int tmp;
    string hoge;
    cin >> tmp >> hoge;

    if (hoge == "AC") {
      if (!state[tmp]) {
        ans_a++;
        ans_p += pena[tmp];
        state[tmp] = true;
      }
    } else {
      if (!state[tmp]) {
        pena[tmp]++;
      }
    }
  }

  cout << ans_a << " " << ans_p << "\n";
}

Measured memory_bytes: 768
#include<iostream>
#include<vector>
using namespace std;
int main(){

  vector<int> Normal_No;
  for(int i=6;i<300000;i+=(i%7==6?2:5)){
    Normal_No.push_back(i);
  }

  bool Prime[300000]={0};
  vector<int> Prime_No;
  for(int i=0,l=Normal_No.size();i<l;i++){
    if(!Prime[Normal_No[i]]){
      for(int j=2;j*Normal_No[i]<300000;j++){
        Prime[j*Normal_No[i]] = true;
      }
      Prime_No.push_back(Normal_No[i]);
    }
  }

  int n;
  while(cin >> n && n!=1){
    cout << n << ":";
    for(int i=0,l=Prime_No.size();i<l;i++){
      if(n % Prime_No[i] == 0) cout << " " << Prime_No[i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 1988
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
template <class T> inline bool  chmax(T &a,T b){if(a<b){a=b;return 1;}return 0;}
#define INF (1e18)

void out(int x){
    int count=5,y=x;
    while(x/10 != 0){
        count--;
        x/=10;
    }
    for(int i=0;i < count;i++)
    {
        cout << '0';
    }
    cout << y;
}
int main(){
int n,m;
cin>>n>>m;
vector<T> Q(m);
int p,y;
for(int i=0;i<m;i++){
    cin>>p>>y;
    Q.at(i)=T(p,y,i);
}
sort(Q.begin(),Q.end());
vector<P> s(m);
int a=0,count=1;
for(int i=0;i<m;i++){
    int b=get<0>(Q.at(i));
    int f=get<2>(Q.at(i));
    if(a!=b){
        a=b;
       count=1;
    }
   s.at(f)=P(a,count);
   count++;
}
for(int i=0;i<m;i++){
    P v=s.at(i);
    out(v.first);
    out(v.second);
    cout<<endl;
}
}


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

using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> v(m+1, 0);

    for(int i = 0; i < n; i++){
        int k;
        cin >> k;
        for(int j = 0; j < k; j++){
            int in;
            cin >> in;
            v[in]++;
        }
    }

    int ans = 0;
    for(int i = 0; i < m+1; i++){
        if(v[i] >= n) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int black[1010][1010];
int white[1010][1010];
int black_total = 0;
int white_total = 0;
void f(int x, int y, string t, int k)
{
    x = x % (2 * k);
    y = y % (2 * k);
    if(x >= k){
        x -= k;
        if(t == "B"){
            t = "W";
        } else {
            t = "B";
        }
    }
    if(y >= k){
        y -= k;
        if(t == "B"){
            t = "W";
        } else {
            t = "B";
        }
    }
    if(t == "B"){
        black_total++;
        black[x][y]++;
    } else {
        white_total++;
        white[x][y]++;
    }
    return;
}

int main()
{
    for(int i = 0; i <= 1005; i++){
        for(int j = 0; j <= 1005; j++){
            black[i][j] = 0;
            white[i][j] = 0;
        }
    }
    int black_square[1010][1010];
    int white_square[1010][1010];
    int n, k;
    cin >> n >> k;
    for(int i = 0; i < n; i++){
        int in1, in2;
        string in3;
        cin >> in1 >> in2 >> in3;
        f(in1, in2, in3, k);
    }
    black_square[0][0] = black[0][0];
    white_square[0][0] = white[0][0];
    for(int i = 1; i < k; i++){
        black_square[i][0] = black_square[i - 1][0] + black[i][0];
        white_square[i][0] = white_square[i - 1][0] + white[i][0];
        black_square[0][i] = black_square[0][i - 1] + black[0][i];
        white_square[0][i] = white_square[0][i - 1] + white[0][i];
    }
    for(int i = 1; i < k; i++){
        for(int j = 1; j < k; j++){
            black_square[i][j] = black_square[i - 1][j] + black_square[i][j - 1] - black_square[i - 1][j - 1] + black[i][j];
            white_square[i][j] = white_square[i - 1][j] + white_square[i][j - 1] - white_square[i - 1][j - 1] + white[i][j];
        }
    }
    /*for(int i = 0; i <= k - 1; i++){
    for(int j = 0; j <= k - 1; j++){
        cout << black_square[i][j] << " ";
    }
    cout << endl;
    }
    for(int i = 0; i <= k - 1; i++){
    for(int j = 0; j <= k - 1; j++){
        cout << white_square[i][j] << " ";
    }
    cout << endl;
    }*/
    int score;
    int ans = max(black_square[k - 1][k - 1], white_square[k - 1][k - 1]);
    for(int i = 0; i <= k - 1; i++){
        for(int j = 0; j <= k - 1; j++){
            score = 2 * black_square[j][i] + black_square[k - 1][k - 1] - black_square[j][k - 1] - black_square[k - 1][i] + white_square[j][k - 1] + white_square[k - 1][i] - 2 * white_square[j][i];
            if(n - score > score){
                score = n - score;
            }
            ans = max(ans, score);
        }
    }
    /*for(int j = 1; j <= k - 1; j++){
        for(int i = 1; i <= k - 1; i++){
            score = 3 * black_square[i][j] + black_square[k - 1][k - 1] - black_square[i][k - 1] - black_square[k - 1][j] + white_square[i][k - 1] + white_square[k - 1][k - 1] - 2 * white_square[i][j];
            if(n - score > score){
                score = n - score;
            }
            ans = max(ans, score);
        }
    }*/
    //for(int i = 1; i <= k - 1; i++){
    //    for(int j = 1; j <= k - 1; j++){
    //        score = 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 16128
#include<cstdio>
#include<cstring>
using namespace std;
#define MAXN 100000
#define MAXK 1000
int x[MAXN+5],y[MAXN+5],m[MAXN+5];
int y1[10*MAXK+5];
int main() {
	int N,K,Max=0,cnt=0;
	scanf("%d %d",&N,&K);
	for(int i=1; i<=N; i++) {
		char ch[25];
		scanf("%d %d %s",&x[i],&y[i],ch);
		x[i]=x[i]%(2*K);
		y[i]=y[i]%(2*K);
		if(ch[0]=='W') m[i]=1;
		else m[i]=0;
	}
	for(int i=0; i<=K; i++) {
		cnt=0;
		memset(y1,0,sizeof(y1));
		for(int j=1; j<=N; j++) {
			int p=(i<=x[j]&&x[j]<i+K);
			int q=(0<=y[j]&&y[j]<K);
			if(p ^ q==m[j]) {
				cnt++;
				y1[y[j]]++;
			} else y1[y[j]]--;
		}
		for(int j=0; j<=K; j++) {
			if(cnt>Max)Max=cnt;
			if(N-cnt>Max) Max=N-cnt;
			if(j!=K) cnt=cnt-y1[j]-y1[K+j];
		}
	}
	printf("%d\n",Max);
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define ll long long
#define ld long double
#define mk make_pair
#define f first
#define se second
#define vll vector<ll>
#define pii pair<ll,ll>
#define vvll vector< vector<ll> >
#define pb push_back
#define sz(v) (v).size()
#define inf 1e18
#define md 1000000007
#define all(v) (v).begin(),(v).end()
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define tel(a){cout<<a<<"\n";}
#define tell(a,b){cout<<a<<" | "<<b<<"\n";}
#define telll(a,b,c){cout<<a<<" | "<<b<<" | "<<c<<"\n";}
#define teln(v,n){cout<<"v- ";rep(i,0,n)cout<<v[i]<<" ";cout<<"\n";}
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0); 

using namespace std;
using namespace __gnu_pbds;

template<typename T>
using o_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define M 1000010


int main(){
	IOS;
	char c;cin>>c;
	char b;
	ll y=c-'a';
	y=y+1;
	b=(char)(y+'a');
	cout<<b;
	return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;
template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}
void sch(string s, string now, int n, int k, vector<bool> &sel, vector<string> &ans) {
  if(n == k) {
    ans.push_back(now);
  } else {
    if(s[k] == 'z' && !sel[s[k]]) return;
    if(s[k] != 'z' && !sel[s[k]+1]) {
      sel[s[k]+1] = true;
      now.push_back(s[k]+1);
      sch(s, now, n, k+1, sel, ans);
      sel[s[k]+1] = false;
      now.pop_back();
    }
    if(sel[s[k]]) {
      now.push_back(s[k]);
      sch(s, now, n, k+1, sel, ans);
      now.pop_back();
    }
  }
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  while(1) {
    string s; cin >> s;
    if(s == "#") break;
    vector<bool> sel(256);
    sel['a'] = true;
    vector<string> ans;
    sch(s, "", (int)(s.size()), 0, sel, ans);
    sort(ans.begin(), ans.end());
    int sz = (int)(ans.size());
    cout << sz << endl;
    if(sz <= 10) {
      for(int i=0;i<sz;++i) {
        cout << ans[i] << endl;
      }
    } else {
      for(int i=0;i<5;++i) {
        cout << ans[i] << endl;
      }
      for(int i=sz-5;i<sz;++i) {
        cout << ans[i] << endl;
      }
    }
  }
}



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

class E
{
	static int[] Read() => Console.ReadLine().Split().Select(int.Parse).ToArray();
	static void Main()
	{
		var h = Read();
		int x = h[0], y = h[1];
		var a = Read();
		var b = Read();
		var c = Read();
		Console.WriteLine(a.OrderByDescending(v => v).Take(x).Concat(b.OrderByDescending(v => v).Take(y)).Concat(c).OrderByDescending(v => v).Take(x + y).Sum(v => (long)v));
	}
}


Measured memory_bytes: 48520
#include<bits/stdc++.h>
#define MAXN 2000005
#define INF 1000000000
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
string str[MAXN];
int tot=1,n;
int trie[MAXN][26],cnt[MAXN][26];
bool ed[MAXN];
bool has[26];
void insert(string s,int rt)
{
    vector<int> nodes;
    nodes.clear(); 
    for(int i=0;i<(int)s.size();i++)
    {
        int x=s[i]-'a';
        if(trie[rt][x]==0) trie[rt][x]=++tot;
        nodes.push_back(rt);
        rt=trie[rt][x];
    }
    memset(has,false,sizeof(has));
    for(int i=(int)s.size()-1;i>=0;i--)
    {
        has[s[i]-'a']=true;
        int cur=nodes[i];
        for(int j=0;j<26;j++) if(has[j]) cnt[cur][j]++;
    }
}
int get_ans(string s,int rt)
{
    for(int i=0;i<(int)s.size()-1;i++)
    {
        int x=s[i]-'a';
        if(trie[rt][x]==0) return false;
        rt=trie[rt][x];
    }
    int x=s[s.size()-1]-'a';
    return cnt[rt][x];
}
map<string,int> mp;
int main()
{
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        cin>>str[i];
        reverse(str[i].begin(),str[i].end());
        insert(str[i],1);
    }
    ll ans=0;
    for(int i=0;i<n;i++) ans+=get_ans(str[i],1)-1;
    for(int i=0;i<n;i++) mp[str[i]]++;
    for(auto p:mp) ans-=1LL*p.S*(p.S-1)/2;
    printf("%lld\n",ans);
}

Measured memory_bytes: 271580