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

using namespace std;

using ll = long long;

int main(void) {
    ll n, m, r;
    cin >> n >> m >> r;

    vector<ll> v(r);
    for(auto &e: v) cin >> e, e--;
    sort(v.begin(), v.end());
    
    vector<vector<ll>> d(n, vector<ll>(n, 1e15));
    for(ll i=0; i<n; i++) d[i][i] = 0;
    for(ll i=0; i<m; i++) {
        ll a, b, c;
        cin >> a >> b >> c;
        a--, b--;
        d[a][b] = d[b][a] = min(c, d[a][b]);
    }
    for(ll k=0; k<n; k++)
    for(ll i=0; i<n; i++)
    for(ll j=0; j<n; j++)
        d[i][j] = min(d[i][j], d[i][k]+d[k][j]);

    ll res = 1e15;
    do {
        ll t = 0;
        for(ll i=0; i<r-1; i++)
            t += d[v[i]][v[i+1]];
        res = min(res, t);
    } while(next_permutation(v.begin(), v.end()));

    cout << res << endl;
}


Measured memory_bytes: 512
#include<iostream>

using namespace std;

int main()
{
	string s;
	cin >> s;
	bool flag = false;
	if(s[0] == 'k'){
		if(s[1] == 'e'){
			if(s[2] == 'y'){
				if(s[3] == 'e'){
					if(s[4] == 'n'){
						if(s[5] == 'c'){
							if(s[6] == 'e')
								flag = true;
							else if(s[s.size()-1] == 'e')
								flag = true;
						}
						else if(s[s.size()-2] == 'c' && s[s.size()-1] == 'e')
							flag = true;
						}
						else if(s[s.size()-3] == 'n' && s[s.size()-2] == 'c' && s[s.size()-1] == 'e')
							flag = true;
					}
					else if(s[s.size()-4] == 'e' && s[s.size()-3] == 'n' && s[s.size()-2] == 'c' && s[s.size()-1] == 'e')
						flag = true;
			}
			else if(s[s.size()-5] == 'y' && s[s.size()-4] == 'e' && s[s.size()-3] == 'n' && s[s.size()-2] == 'c' && s[s.size()-1] == 'e')
				flag = true;
		}
		else if(s[s.size()-6] == 'e' && s[s.size()-5] == 'y' && s[s.size()-4] == 'e' && s[s.size()-3] == 'n' && s[s.size()-2] == 'c' && s[s.size()-1] == 'e')
			flag = true;
	}
	else if(s[s.size()-6] == 'k' && s[s.size()-6] == 'e' && s[s.size()-5] == 'y' && s[s.size()-4] == 'e' && s[s.size()-3] == 'n' && s[s.size()-2] == 'c' && s[s.size()-1] == 'e')
		flag = true;
	if(flag)
		cout << "YES" << endl;
	else
		cout <<"NO" << endl;
	return 0;
}


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

using namespace std;

struct Card
{
	char suit;
	char value;
};


void bubbleSort(Card a[], int n)
{
	bool flag = true;
	for (int i = 0;flag; i++) {
		flag = false;
		for (int j = n - 1; j > i; j--) {
			if (a[j - 1].value > a[j].value) {
				swap(a[j - 1], a[j]);
				flag = true;
			}
		}
	}
}
void selectionSort(Card a[], int n)
{
	int count = 0;
	for (int i = 0; i < n - 1; i++) {
		int index = i;
		for (int j = i + 1; j < n; j++) {
			if (a[index].value > a[j].value) {
				index = j;
			}
		}
		swap(a[i], a[index]);
	}
}

void show(Card a[], int n)
{
	cout << a[0].suit << a[0].value;
	for (int i = 1; i < n; i++) {
		cout << ' ' << a[i].suit << a[i].value;
	}
	cout << endl;
}
bool compare(Card a[], Card b[], int n)
{
	for (int i = 0; i < n; i++) {
		if (a[i].suit != b[i].suit) return false;
	}
	return true;
}

int main(void)
{
	int N;
	Card A[36], B[36];

	cin >> N;
	for (int i = 0; i < N; i++) {
		cin >> A[i].suit >> A[i].value;
		B[i] = A[i];
	}
	bubbleSort(A, N);
	show(A, N);
	cout << "Stable" << endl;
	selectionSort(B, N);
	show(B, N);
	cout << (compare(A, B, N) ? "Stable" : "Not stable") << endl;
	
	return 0;
}



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

int main(){
	int n,cnt=0,x;
	set<int> s;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>x;
		if(s.find(x)!=s.end()){
			s.erase(x);
//			cout<<"00"<<endl;
			cnt++;
		}else{
			s.insert(x);
		}
	}
	cout<<s.size()<<endl;
	return 0;
}

Measured memory_bytes: 4864
#include <bits/stdc++.h>
#define int long long
typedef long long ll;
using namespace std;

const ll MAXN = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;

ll N, ansx=0, ansy=0, ans=0, tmp=0;
vector<vector<ll>> G(200002);
vector<ll> cl(200002,-1);

void bfs(ll id) {
    queue<ll> Q;
    ansx=0;
    ansy=0;
    cl[id]=tmp;
    if(id>100000) ansy++;
    else ansx++;
    Q.push(id);
    while(!Q.empty()) {
        ll u = Q.front();
        Q.pop();
        for(int i=0;i<G[u].size();i++) {
            if(cl[G[u][i]]==-1) {
                cl[G[u][i]] = tmp;                
                if(G[u][i]>100000) ansy++;
                else ansx++;
                Q.push(G[u][i]);
            }
        }
    }
}

signed main(){
    cin >> N;
    for(int i=0;i<N;i++) {
        ll a,b;
        cin >> a >> b;
        b += 100000;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    for(int i=0;i<200002;i++) {
        if(cl[i]==-1) {
            tmp++;
            bfs(i);
            ans += ansx*ansy;
        }
    }
    cout << ans-N << endl;
    return 0;
}

Measured memory_bytes: 13240
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
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; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

#define MAXN 100010

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(m);
    vector<pair<int, int>> key;
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        int s = 0;
        rep(j, b) {
            int c;
            cin >> c;
            --c;
            s |= 1 << c; // 1 << 3 -> 1000
        }
        key.emplace_back(s, a);
    }

    // dp[s]:= sを全て開けられる鍵の買い方の最小コスト
    vector<int> dp(1 << n, INF); // 2^n
    dp[0] = 0;
    rep(s, 1 << n) {
        rep(i, m) {
            int t = s | key[i].first;
            int cost = dp[s] + key[i].second;
            dp[t] = min(dp[t], cost);
        }
    }

    int ans = dp.back();
    if (ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

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

int main(){ 
    int a,b;
    cin>>a>>b;
    int c=0;
    int d=0;
    if(b<10){
        c=a*10+b;
    }else if(b<100){
        c=a*100+b;
    }else{
        c=a*1000+b;
    }
    for(int i=1;i<321;i++){
        if(c==i*i){
            cout<<"Yes";
            return 0;
        }
    }
    cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

void test_case(){
	int n; cin >> n;
	string s; cin >> s;
	int count1 = 0 , count2 = 0;
	for(int i = 0 ; i < n ; i++)
		if(s[i]=='R')
			count1++;
	if(count1==n){
		cout<<"0";
		return;
	}
	for(int i = 0 ; i < count1 ; i++)
		if(s[i]=='R')
			count2++;
	cout<<count1-count2;
	
	
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 3716
//daydream
#include <bits/stdc++.h>
using namespace std;
long long n,m,k,a1[100005],a2[100005],tmp,sum=0;
string s;
char r1,r2,op;
int main(){
	ios::sync_with_stdio(0);
	cin>>n;
	long long cnt1=0,cnt2=0;
	for (int i=1;i<=n;i++){
		if (i%2){
			cnt1++;
			cin>>a1[cnt1];
		}
		else{
			cnt2++;
			cin>>a2[cnt2];
		}
	}
	sort(a1+1,a1+cnt1+1);
	sort(a2+1,a2+cnt2+1);
	long long cnt11=1,cnt22=1;
	for (int i=1;i<=n;i++){
		if (cnt11>cnt1){
			for (int j=i;j<=n;j++){
				if (j%2==1) sum++;
			}
			break;
		}
		else if (cnt22>cnt2){
			for (int j=i;j<=n;j++){
				if (j%2==0) sum++;
			}
			break;
		}
		if (a1[cnt11]<a2[cnt22]){
			cnt11++;
			if (i%2==0) sum++;
		}
		else if (a2[cnt22]<a1[cnt11]){
			cnt22++;
			if (i%2==1) sum++;
		}
	}
	/*for (int i=1;i<=cnt1;i++) cout<<a1[i]<<' ';
	cout<<endl;
	for (int i=1;i<=cnt2;i++) cout<<a2[i]<<' ';
	cout<<endl;*/
	cout<<(sum+1)/2<<endl;
	return 0;
}

Measured memory_bytes: 4384
S=input()
q=int(input())
RV=0
A="A"
for i in range(q):
    IN=input()
    if IN=="1":
        RV+=1
    else:
        t,f,c=IN.split()
        if RV%2==0:
            if f=="1":
                A=c+A               
            else:
                A=A+c
        else:
            if f=="1":
                A=A+c
            else:
                A=c+A
if RV%2==0:
    for i in range(len(A)):
        if A[i]=="A":
            print(A[:i]+S+A[i+1:])
else:
    A=A[::-1]
    for i in range(len(A)):
        if A[i]=="A":
            print(A[:i]+S[::-1]+A[i+1:])

Measured memory_bytes: 4384
#include<iostream>
#include<fstream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<string>
#include<cstring>
#include<ctime>
#include<random>
#include<algorithm>
#define ll long long
using namespace std;
int n,m;
int x[120000];
int b[120000];
int t=0;
int ans;

bool cmp(int a,int b)
{
    return a>b;
}



int main()
{
    scanf("%d%d",&n,&m);
    for (int i=0; i<m; ++i)
        scanf("%d",&x[i]);
    sort(x,x+m);
    for (int i=1; i<m; ++i)
        b[t++]=x[i]-x[i-1];
    sort(b,b+t,cmp);
    int ans=x[m-1]-x[0];
    for (int i=0; i<(n-1); ++i)
        ans-=b[i];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 1024
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::iter::FromIterator;
#[allow(unused_imports)]
use std::io::stdin;

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
    where
        <T as FromStr>::Err: Debug,
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

#[allow(unused_macros)]
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
                   ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
                   ).collect::<Vec<_>>()
    };
    ($t:ty ;;) => {
        {
            let mut line: String = String::new();
            stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    let n = get!(usize);
    let mut aa = util::gets::<u64>();

    aa.sort();
    let sum = aa.iter().sum::<u64>();

    let mut l = 0;
    let mut r = n;

    while l != r {
        let mid = (l + r) / 2;

        let mut s = aa[..mid + 1].iter().sum::<u64>();
        for &x in &aa[mid + 1..] {
            if x <= s * 2 {
                s += x;
            } else {
                break;
            }
        }

        if s == sum {
            r = mid;
        } else {
            l = mid + 1;
        }
    }

    println!("{}", n - l);
}


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

using namespace std;

int main()
{
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i = 0; i < N; i++)
    cin >> A[i];
  long long ans = 0, sum = 0;
  int right = 0, bit = 0;
  for (int i = 0; i < N; i++)
  {
    while ((sum + A[right]) == (bit ^ A[right]) && right < N)
    {
      sum += A[right];
      bit ^= A[right];
      right++;
    }
    ans += right - i;
    sum -= A[i];
    bit ^= A[i];
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1024
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <climits>
using namespace std;
#define MOD int(1e9 + 7)
#define INF (long long)(1e18)

int main()
{
    cout.precision(18);

    long long N, K;
    cin >> N >> K;

    vector<bool> f(N, false);
    for (long long i = 0; i < K; i++)
    {
        long long d;
        cin >> d;
        for (long long j = 0; j < d; j++)
        {
            long long t;
            cin >> t;
            f[t - 1] = true;
        }
    }

    long long c = 0;
    for (long long i = 0; i < N; i++)
        c += f[i];

    cout << N - c << endl;
}

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000

vector<int> G[100010];
deque<int> L;
bool visited[100010];
int ans[100010];

void visit(int v) {
    if (visited[v]) return;
    visited[v] = true;
    for(auto to: G[v]) {
        visit(to);
    }
    L.push_front(v);
}

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    rep(i, N - 1 + M) {
        int s, t;
        cin >> s >> t;
        G[s].push_back(t);
    }
    rep(i, N) {
        visit(i + 1);
    }
    for(auto itr = L.begin(); itr != L.end(); ++itr) {
        for(auto to: G[*itr]) {
            ans[to] = *itr;
        }
    }
    rep(i, N) {
        cout << ans[i + 1] << endl;
    }
   


    return 0;
}


Measured memory_bytes: 10368
def f():
    n,k=map(int,input().split())
    l=list(map(int,input().split()))
    now=1

    for i in range(k.bit_length()):
        if k%2:now=l[now-1]
        l=[l[l[i]-1]for i in range(n)]
        k//=2
    print(now)
if __name__ == "__main__":
    f()

Measured memory_bytes: 32284
#include <iostream>
#include <string>
using namespace std;
int main(){
    int a,j,i,k,b;
    string s;
    cin >> s;
    for(i=0;i<s.length();i++){
        if(s[i]=='A'){
            a = i;
            break;
        }
    }
    for(i=s.length()-1;i>=0;i--){
        if(s[i]=='Z'){
            b = i;
            break;
        }
    }
    cout << b-a+1;
}

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

int main(){
	int n; cin>>n;
	int x[n];
	for(int i=0;i<n;i++) cin>>x[i];
	
	int ans=1000000;
	for(int p=1;p<100;p++){
		int sum=0;
		for(int i=0;i<n;i++){
			sum+=pow((x[i]-p),2);  //pow(x,n)xのn乗を計算
		}
		ans=min(ans,sum);
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import sys

N,K=map(int,input().split())
S=list(map(int,input()))

T=[]
t=1
k=0
for i in range(N):
    if t==S[i]:
        k+=1
    else:
        t^=1
        T.append(k)
        k=1
T.append(k)
if S[-1]==0:
    T.append(0)

X=len(T)
if K>=X//2:
    print(N)
    sys.exit()

M=sum(T[:2*K+1])
F=M
for i in range(X//2-K):
    F=F-(T[2*i]+T[2*i+1])+(T[2*(i+K)+1]+T[2*(i+K+1)])
    M=max(M,F)

print(M)


Measured memory_bytes: 48860
#include<algorithm>
#include<climits>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<stack>
#include<utility>
#include<vector>

#define lint long long
#define REP(i, x, n) for(int i = x ; i < n ; i++)
#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; i--)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX

using namespace std;

int main(){
    int a, b;
    cin >> a >> b;
    if(a*b % 2){
        cout << "Odd" << endl;
    }else{
        cout << "Even" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <climits> // INT_MAX, LONG_MAX, LLONG_MAX, UINT_MAX, ULONG_MAX, ULLONG_MAX
#include <cmath>
#include <cstdint>
#include <cstring> // memset
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

#define ALL(x) (x).begin(), (x).end()
#define INF 1e9
#define LOG(x) cout << #x << " = " << (x) << endl
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)

using namespace std;

int main() {
    string n;
    cin >> n;

    int count = 0;
    bool isGood = false;
    REP(i, n.size()) {
        if (i > 0 && n[i - 1] == n[i]) {
            count++;
            if (count == 2)
                isGood = true;
        } else {
            count = 0;
        }
    }
    if (isGood)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;

    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int main()
{
    int m,n;
    scanf("%d%d",&m,&n);
    for(int i=0;i<=m;i++)
     for(int j=0;j<=m;j++)
      for(int k=0;k<=m,i+j+k<=m;k++)
       {
            if(i+j+k==m && i*1000+j*5000+k*10000==n)
            {
                printf("%d %d %d",k,j,i);
                return 0;   
            }
       }
    printf("-1 -1 -1");
    return 0;
}

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

int main(void){
    int n,k;
    cin>>n>>k;
    map<int,ll> b,w;
    w[-1] = 1;
    ll sum = 0;
    rep(i,n){
        w[i] = b[i-1];
        b[i] = w[i-1] + w[i-k];
        sum += b[i];
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3108
#include <bits/stdc++.h>
using namespace std;
using ll =long long;
using vl=vector<ll>;
using vb=vector<bool>;
using vs=vector<string>;
using vvl=vector<vl>;
using pll=pair<ll,ll>;
const ll oo =0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
#define sz(c) ll((c).size())
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
#define pb push_back
#define eb emplace_back
#define xx first
#define yy second
#define FOR(i,a,b) for(ll i=(a); i<(b); i++)
#define FORD(i,a,b) for(ll i=ll(b)-1;i>=(a);i--)
#define TR(X) ({if(1) cerr << "TR: " << (#X) << " = " << (X) << endl; })
int main(){ cin.sync_with_stdio(0);
        ll N; cin >> N;
        vl ds(N);
        FOR(i, 0, N) cin >> ds[i];
        ll M; cin >> M;
        vl ts(M);
        FOR(i, 0, M) cin >> ts[i];

        map<ll, ll> cnta, cntb;
        FOR(i, 0, N) cnta[ds[i]] ++;
        bool impossible = false;
        FOR(i, 0, M) {
                cnta[ts[i]] --;
                if (cnta[ts[i]] < 0) impossible = true;
        }
        if (impossible) cout << "NO" << endl;
        else cout << "YES" << endl;
} //cin.tie(0) bei schnellem Wechseln


Measured memory_bytes: 15872
s = input()
t = input()
s = list(map(lambda x: ord(x), s))
t = list(map(lambda x: ord(x), t))
s = sorted(s)
t = sorted(t, reverse=True)
num = min(len(s), len(t))
for i in range(num):
    if s[i] < t[i]:
        print("Yes")
        break
    elif t[i] < s[i]:
        print("No")
        break
else:
    if len(s) < len(t):
        print("Yes")
    else:
        print("No")

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto& x:c){cout<<x<<' ';}cout<<endl;

using namespace std;
using ll = long long;

template<typename T=int>
T in(){T x; cin >> x; return (x);}

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

	string S=in<string>();
	char old = S[0];
	for(int i=1,ei=S.size();i<ei;i++){
		int c = S[i];
		if(old==c){
			cout << "Bad" << endl;
			return 0;
		}
		old = c;
	}

	cout << "Good" << endl;
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
// use itertools::Itertools;
use proconio::{input, marker::*};

fn main() {
    input! {
        n: usize,
        tt: [isize; n],
        m: usize,
        ppxx: [(Usize1, isize); m]
    };
    let sum: isize = tt.iter().sum();
    for (p, x) in ppxx {
        println!("{}", sum - (tt[p] - x));
    }
    // println!("{}",);
}


Measured memory_bytes: 2188
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i=l;i<n;i++)
#define rer(i,l,n) for(int i=l;i<=n;i++)
#define all(a) a.begin(),a.end()
#define o(a) cout<<a<<endl
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef vector<int> vint;
typedef pair<int,int> pii;

int main(){
	int n,m;
	while(1){
		cin>>n;
		if(n==0) break;
		string s;
		char in,b[100],a[100];
		rep(i,0,n){
			cin>>b[i]>>a[i];
		}
		cin>>m;
		rep(i,0,m){
			cin>>in;
			rep(j,0,n){
				if(in==b[j]){
					in=a[j]; break;
				}
			}
			s+=in;
		}
		o(s);
	}
}

Measured memory_bytes: 1324
input_num = int(input())
nums = input().split()
ope_cnt = 0
def division_nums(input_num, nums, ope_cnt):
  for i in range(input_num):
    if int(nums[i]) % 2 != 0:
      return ope_cnt
    else:
      nums[i] = int(nums[i]) / 2
  ope_cnt = ope_cnt + 1
  return division_nums(input_num, nums, ope_cnt)
      
print(division_nums(input_num, nums, ope_cnt))

Measured memory_bytes: 3060
#include <boost/multiprecision/cpp_int.hpp>
namespace mp = boost::multiprecision;
using INT=mp::cpp_int;
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll=long long;
using vec=vector<ll>;
using Graph = vector<vector<ll>>;
#define loop(i,n) for(ll i=0;i<n;i++)
#define Loop(i, m, n) for(ll i = m;i < n;i++)
#define pool(i,n) for(ll i=n;i>=0;i--)
#define Pool(i, m, n) for(ll i=n;i>=m;i--)
#define MAX 999999999ll
#define MIN -999999999ll
#define setbit bitset<8>
#define flagcount __builtin_popcount
#define flag(x) (1<<x)
#define flagadd(bit,x) bit|=flag(x)
#define flagpop(bit,x) bit&=~flag(x) 
#define flagon(bit,i) bit&flag(i)
#define flagoff(bit,i) !(bit & (1<<i))
#define all(v) v.begin(),v.end()
#define low2way(v,x) lower_bound(all(v),x)
#define high2way(v,x) upper_bound(all(v),x)
#define count2way(v,x) high2way(v,x)-low2way(v,x)
#define lower(v,x) low2way(v,x)-v.begin() //1番左が0、もし見つから無いならｎを出力
#define higher(v,x) high2way(v,x)-v.begin()-1 //1番左が0、もし見つからないならn-1を出力（注意）
#define putout(x) cout<<x<<endl
#define gcd(x,y) __gcd(x,y) 
#define Gput(a,b) G[a].push_back(b)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
ll lcm(ll x,ll y){
  ll z=gcd(x,y);
  return x*(y/z);
}
ll ctoi(char c){
	if(c>='0'&&c<='9'){
		return c-'0';
	}
	return 0;
}
vector<bool> seen;
void dfs(const Graph &G,ll v){
    seen[v]=true;
    for(auto nextv:G[v]){ 
        if(seen[nextv])continue;
        dfs(G,nextv);
    }
}
ll fact(ll n){
ll sum=0;
Loop(i,1,n+1){
sum+=i;
}
return sum;

}
int main() {
  cout << fixed << setprecision(16);
  ll n;
  cin>>n;
  vector<INT> t(n);
  vector<INT> a(n);
  for(int i=0;i<n;i++){
    cin>>t.at(i);
    cin>>a.at(i);
  }
  INT T=t.at(0),A=a.at(0);
  for(int i=0;i<n;i++){
    if(T*a.at(i)<A*t.at(i)){
      if(A%a.at(i)==0){
        T=t.at(i)*(A/a.at(i));
        continue;
      }
      else{
        A+=(a.at(i)-(A%a.at(i)));
        T=t.at(i)*(A/a.at(i));
        continue;
      }
    }
    if(T*a.at(i)>A*t.at(i)){
      if(T%t.at(i)==0){
        A=a.at(i)*(T/t.at(i));
        continue;
      }
      else{
        T+=(t.at(i)-(T%t.at(i)));
        A=a.at(i)*(T/t.at(i));
        continue;
      }
    }
  }
  cout<<A+T<<endl;
  
  
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <array>
#include <queue>
#include <stack>
#include <algorithm>
#include <tuple>
#include <numeric>
#include <type_traits>

int main()
{
	int N;
	std::vector<std::tuple<std::string, int, int>> SPI;

	std::cin >> N;
	SPI.resize(N);
	for (int i = 0; i < N; ++i) {
		auto& spi = SPI[i];
		std::cin >> std::get<0>(spi) >> std::get<1>(spi);
		std::get<2>(spi) = i+1;
	}
	
	std::sort(SPI.begin(), SPI.end(), [](auto& a, auto& b)->bool{
		if (std::get<0>(a) != std::get<0>(b))
			return std::get<0>(a) < std::get<0>(b);
		return std::get<1>(a) > std::get<1>(b);
	});
	
	for (auto& spi : SPI) {
		std::cout << std::get<2>(spi) << "\n";
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <stdio.h>
#include <cmath>
#include <cfloat>
#include <algorithm>
#include <numeric>
#include <vector>
#include <iterator>
#include <set>
#include <map>
using namespace std;

const double PI=acos(-1);

int main(){
    string s;
    cin >> s;
    char op[] = {'+', '-'},
         op2[][3] = {{'+', '+', '+'},
                    {'+', '+', '-'},
                    {'+', '-', '+'},
                    {'+', '-', '-'},
                    {'-', '+', '+'},
                    {'-', '+', '-'},
                    {'-', '-', '+'},
                    {'-', '-', '-'}};
    int a = s[0] - '0',
        b = s[1] - '0',
        c = s[2] - '0',
        d = s[3] - '0',
        ans[] = {
            a + b + c + d,
            a + b + c - d,
            a + b - c + d,
            a + b - c - d,
            a - b + c + d,
            a - b + c - d,
            a - b - c + d,
            a - b - c - d
        };
    for(int i = 0; i < 8; i++){
        if(ans[i] == 7){
            printf("%d%c%d%c%d%c%d=7", a, op2[i][0], b, op2[i][1], c, op2[i][2], d);
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
string a,b,c;
int main()
{
    cin>>a>>b>>c;
    int sz1=a.size();
    int sz2=b.size();
    int sz3=c.size();

    if(a[sz1-1]==b[0] && b[sz2-1]==c[0])
    cout<<"YES"<<endl;
    else
    cout<<"NO"<<endl;
    return 0;

}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <climits>
#include <algorithm>
#include <unordered_map>
#include <map>
#include <cmath>
#include <bitset>
#include <queue>
#include <set>
#include <numeric>
#include <unordered_set>
#include <iomanip>
#include <string>

using namespace std;

typedef long long ll;
typedef long double ld;

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(0);
	
	ll n, d, a;
	cin>>n>>d>>a;
	vector<pair<ll, ll>> v(n);
	for (auto &x : v){
		cin>>x.first>>x.second;
		x.second=(x.second+a-1)/a;
	}
	sort(v.begin(), v.end());
	ll runsum=0;
	vector<ll> change(n+1);
	
	ll tot=0;
	for (ll i =0;i<n;++i){
		runsum+=change[i];
		ll h=v[i].second - runsum;
		if (h<=0) continue;
		ll lo=0,hi=n-1,ans=-1;
		while (lo<=hi){
			ll mid=lo+(hi-lo)/2;
			if (v[mid].first <= v[i].first + 2 * d){
				ans = mid;
				lo = mid +1;
			}else{
				hi=mid-1;
			}
		}
		runsum += h;
		tot += h;
		change[ans+1]-=h;
	}
	cout<<tot;
}

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

ll gcd(ll a, ll b) {
    if (a < b) swap(a, b);
    if (a % b == 0) return b;
    return gcd(b, a % b);
}

ll check(ll n) {
    ll cnt = 0;
    while (n % 2 == 0) {
        cnt++;
        n /= 2;
    }
    return cnt;
}

int main() {
    ll N, M;
    cin >> N >> M;
    ll a[N], tmp;
    bool flag = true;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        a[i] = a[i]/2;
        if (i == 0) {
            tmp = check(a[i]);
        }
        if (tmp != check(a[i])) {
            flag = false;
        }
    }
    if (!flag) {
        cout << 0 << endl;
        return 0;
    }
    sort(a, a + N);
    ll lcm = 1;
    for (int i = 0; i < N; i++) {
        ll g = gcd(lcm, a[i]);
        lcm *= a[i] / g;
        if (lcm > M) {
            cout << 0 << endl;
            return 0;
        }
    }
    ll cnt = 0;
    ll i = 1;
    //cout << lcm << endl;
    while (lcm * i <= M) {
        cnt++;
        i += 2;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define I int
#define S(a) scanf("%d",&a)
#define S2(a,b) scanf("%d%d",&a,&b)
#define P(a) printf("%d\n",a)
#define PL(a) printf("%lld\n",a)
#define PT(t) printf("Case %d: ",t)
#define PB(a) push_back(a)
#define SET(a) memset(a,0,sizeof a)
#define SETR(a) memset(a,-1,sizeof a)
#define ll long long 
using namespace std;
#define mx 500004
#define md 1000000007ll
typedef pair<int, int >P;
typedef vector<ll>V;

////////define value/////
template <class T> inline T BM(T p, T e, T M)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p) % M;
        p = (p * p) % M;
    }
    return (T)ret;
}
template <class T> inline T gcd(T a, T b)
{
    if(b == 0)return a;
    return gcd(b, a % b);
}
template <class T> inline T mdINV(T a, T M)
{
    return BM(a, M - 2, M);
}
template <class T> inline T PW(T p, T e)
{
    ll ret = 1;
    for(; e > 0; e >>= 1)
    {
        if(e & 1) ret = (ret * p);
        p = (p * p);
    }
    return (T)ret;
}
 
 
template <class T>bool ISLEFT(T a, T b, T c)
{
    if(((a.xx - b.xx) * (b.yy - c.yy) - (b.xx - c.xx) * (a.yy - b.yy)) < 0.0)return 1;  //Uporer dike //A,b,c, x okkher ordera sorted
    else return 0;
}

int main(){

    int n;
    S(n);
    vector<pair<int,int > >ar[n+2];

    for(int i=1;i<n;i++){
        int x,y,z;
        cin>>x>>y>>z;
        z%=2;
        ar[x].push_back(make_pair(y,z));
        ar[y].push_back(make_pair(x,z));
    }
    queue<int>q;
    q.push(1);
    int vis[n+2];
    SETR(vis);
    vis[1] = 0;
    while(!q.empty()){
        int f = q.front();
        q.pop();
        for(int i=0;i<ar[f].size();i++){
            int x= ar[f][i].first;
            int y = ar[f][i].second;
            if(vis[x] == -1){
                vis[x] = vis[f] ^ y;
                q.push(x);
            }
        }
    }

    for(int i=1;i<=n;i++){
        cout<<vis[i]<<endl;
    }

    return 0;
}

Measured memory_bytes: 6784
#include<bits/stdc++.h>
/*
g++ -std=c++11 -Wall -g -fsanitize=undefined -D_GLIBCXX_DEBUG arc/arc102/c.cpp
*/
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define SZ(x) ((int)(x).size())
#define INF (1e16)
typedef long long ll;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);//おまじないでcin, cout早くする
    ll N, K;
    cin >> N >> K;
    if(K % 2 == 1){
        cout << (N/K) * (N/K) * (N/K) << "\n";
    }else{
        if((N/K) * K + (K/2) > N){
            cout << 2 * (N/K) * (N/K) * (N/K) << "\n";
        }else{
            cout << 2 * (N/K) * (N/K) * (N/K) + 3 * (N/K) * (N/K) + 3 * (N/K) + 1 << "\n";
        }
    }
    return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;

  int train = 0, bus = 0;
  if (a >= b) {
    train = b;
  } else {
    train = a;
  }
  if (c >= d) {
    bus = d;
  } else {
    bus = c;
  }
  
  int ans = train + bus;
  cout << ans << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline # 改行コード「\n」を呼んでしまうため、文字数など、注意！！

s = input().replace("\n","")

ans = 0

for i in range(len(s)):
    cnt = 0
    for j in range(i,len(s)):
        # print(len(s),i)
        # print(s[j:])
        # print(s[j])
        if s[j] == 'A' or s[j] == 'C' or s[j] == 'G' or s[j] == 'T':
            cnt += 1
            if cnt > ans:
                ans = cnt
        else:
            # print("AGCT意外です。カウント数：",cnt)
            break

print(ans)

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

public class Solution
{
    public static List<long> GetDivisors(long n)
    {
        var divisors = new List<long>();
        for (int i = 1; i <= Math.Sqrt(n) + 1; i++)
        {
            if (n % i == 0)
            {
                divisors.Add(i);
                if (i != n / i)
                {
                    divisors.Add(n / i);
                }
            }
        }
        return divisors;
    }

    public static void Main()
    {
        var n = long.Parse(Console.ReadLine());
        var divs = GetDivisors(n);

        var min = divs.Min(d => d - 1 + n / d - 1);
        Console.WriteLine(min);
    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  int a, b, c, d; cin >> a >> b >> c >> d;
  auto e = std::max(a, c);
  auto f = std::min(b, d);
  auto ans = std::max(0, f - e);
  cout << ans << CRLF;
  return;
}

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

  solve();

  return 0;
}


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

int main(void){

  int a,b,c,d;
  scanf("%d %d %d %d", &a, &b, &c, &d);
  if (abs(a-c) <= d) {
    printf("Yes\n");
  } else if (abs(a-b) <= d && abs(b-c) <= d) {
    printf("Yes\n");
  } else {
    printf("No\n");
  }

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a=0,b=0,c,sb=1,f=0;
	char ch;
	ch=getchar();
	while(isdigit(ch))
	{
		a=a*10+(ch-48);
		ch=getchar();
	}
	while(!isdigit(ch))
	{
		ch=getchar();
	}
	while(isdigit(ch))
	{
		sb*=10;
		b=b*10+(ch-48);
		ch=getchar();
	}
	c=a*sb+b;
	for(int i=1;i<=320;i++)
	{
		if(i*i==c)
		{
			f=1;
		}
	}
	if(f)
	{
		cout<<"Yes";
	}
	else
	{
		cout<<"No";
	}
	return 0;
}


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

const int mxn = 1e5 + 5;
const long long mod = 1e9 + 7;

long long dp[mxn][15];

int main() {
    string s;
    cin >> s;
    dp[int(s.size())][0] = 1;
    for (int i = int(s.size()) - 1, ex = 1; i >= 0; i--) {
        if (s[i] == '?') {
            for (int c = 0; c < 10; c++) {
                for (int t = 0; t < 13; t++) {
                    dp[i][(c * ex + t) % 13] += dp[i + 1][t];
                    dp[i][(c * ex + t) % 13] %= mod;
                }
            }
        } else {
            int c = s[i] - '0';
            for (int t = 0; t < 13; t++) {
                dp[i][(c * ex + t) % 13] = dp[i + 1][t];
            }
        }
        ex = (ex * 10) % 13;
    }
    cout << dp[0][5] << endl;
}



Measured memory_bytes: 15456
#include <iostream>
#include <math.h>
#include <numeric>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
#include <tuple>
#include <functional>

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define irep(i,n) for(int  i = 0; i < n; i++)
#define irep2(i,a,n) for(int i = a; i < n; i++)
#define lrep(i,n) for(long long  i = 0; i < n; i++)
#define lrep2(i,a,n) for(long long i = a; i < n; i++)
#define in(a) cin >> a
#define out(a) cout << a << endl
typedef long long ll;

using namespace std;

int main() 
{
    int n; cin >> n;
    map<int, int> a;
    vector<int> b(n);
    ll ans = 0;

    irep(i, n) { 
        ll tmp;
        cin >> tmp;
        a[tmp]++;
    }

    //irep(i, n) {
    for(auto num : a) {
        if(num.first != num.second) {
            if(num.second < num.first) {
                ans += num.second;
            } else {
                ans += num.second - num.first;
            }
        }
    }

    cout << ans << endl;

    return 0;
}
    



Measured memory_bytes: 5120
#import pysnooper
#import numpy
#import os,re,sys,operator
from collections import Counter,deque
#from operator import itemgetter
#from itertools import accumulate,combinations,groupby,combinations_with_replacement,permutations
from sys import stdin,setrecursionlimit
#from bisect import bisect_left
#from copy import deepcopy
#import heapq
#import math
#import string
#from time import time
#from functools import lru_cache
setrecursionlimit(10**6)
input=stdin.readline

n,m=map(int,input().split())
s=input().rstrip()
now=n
ans=deque()
while now!=0:
    for i in range(max(0,now-m),now):
        #print(i,s[i],now)
        if s[i]=="0":
            ans.appendleft(now-i)
            now=i
            break
    else:
        print(-1)
        exit()
print(*ans)

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

#define pout(n)  printf ("%d\n", n)
#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--)
 
typedef long long ll;
using namespace std;
 
int main (){
  int n;
  scanf("%d",&n);

  int a[n];
  
  rep(i,0,n){
      scanf("%d",&a[i]);
  }
  sort(a,a+n);
  
  pout(a[n-1]-a[0]);

  return 0;
}

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

using namespace std;

#define MP 999983

int main() {
	vector<int> data(MP+1, 0);
	data[0] = data[1] = 1;
	vector<int> data2;
	for (int i = 2; i*i <= MP; i++) {
		if (data[i] == 0) {
			for (int j = 2; i*j <= MP; j++) {
				data[i*j] = 1;
			}
		}
	}
	for (int i = 0; i <= MP; i++) {
		if (data[i] == 0) {
			data2.push_back(i);
		}
	}
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		int p, m;
		int counter2 = 0;
		for (int i = 0; i < n; i++) {
			cin >> p >> m;
			int ma, mi;
			ma = min(p+m, MP);
			mi = max(p-m, 0);
			vector<int>::iterator ite = lower_bound(data2.begin(), data2.end(), mi);
			vector<int>::iterator ite2 = upper_bound(data2.begin(), data2.end(), ma);
			//cout << ite2-ite << endl;
			counter2 += ite2-ite-1;
		}
		cout << counter2 << endl;
	}
	return 0;
}

Measured memory_bytes: 5500
#include <stdio.h>
#include<string.h>


int main() {

 int N;
 int K;
 char S[256];
 scanf("%d", &N);
 scanf("%d", &K);
 scanf("%s", S); 

 if(S[K-1]>=65&&S[K-1]<=90){
   S[K-1]=S[K-1]+32;
  }

 printf("%s\n", S);
 return 0;

}

Measured memory_bytes: 128
#include<stdio.h>
int main(){
  int n,i,j,r[400],t,p,c;
  unsigned long long int a,id[1001];
  while(scanf("%d",&n),n){
    int u[100000]={0};
    int uc[1000]={0};
    for(i=c=0;i<n;i++){
      r[i]=i;
      scanf("%lld %d %lld %d",&id[i],&u[i],&a,&p);
      id[i]+=((10-a)*1000000+p)*10000;//printf("%lld\n",id[i]);
      for(j=i;j;j--){
	if(id[r[j-1]]>id[r[j]]){
	  t=r[j];
	  r[j]=r[j-1];
	  r[j-1]=t;
	}
      }
    }
    for(i=0;i<n;i++){//printf("%lld\n",id[r[i]]);
      if(c<10){
	if(uc[u[r[i]]]<3){
	  uc[u[r[i]]]++;
	  c++;
	  printf("%lld\n",id[r[i]]%10000);
	}
      }
      else if(c<20){
	if(uc[u[r[i]]]<2){
	  uc[u[r[i]]]++;
	  c++;
	  printf("%lld\n",id[r[i]]%10000);
	}
      } 
      else if(c<26){
	if(uc[u[r[i]]]<1){
	  uc[u[r[i]]]++;
	  c++;
	  printf("%lld\n",id[r[i]]%10000);
	}
      }
    }
  }
  return 0;
}

Measured memory_bytes: 1008
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
using T = tuple<string,int,int>;
const ll INF = 1LL<<60;
const int ny[4] = {-1,1,0,0}, nx[4] = {0,0,-1,1};

int main(){
  int H,W; cin >> H >> W;
  char g[H][W];
  queue<P> q;
  for(int i = 0; i < H; i++){
    for(int j = 0; j < W; j++){
      cin >> g[i][j];
      if(g[i][j] == '#') q.push(P(i,j));
    }
  }
  if(H == 1 && W == 1){
    cout << 0 << endl;
    return 0;
  }
  int ans = 0;
  int a = q.size(), b = 0;
  while(!q.empty()){
    P p = q.front(); q.pop(); a--;
    int dy = p.first, dx = p.second;
    for(int i = 0; i < 4; i++){
      int y = dy+ny[i], x = dx+nx[i];
      if(0 > y || y >= H || 0 > x || x >= W) continue;
      if(g[y][x] == '#') continue;
      g[y][x] = '#';
      q.push(P(y,x));
      b++;
    }
    if(a == 0 && b != 0){
      ans++;
      swap(a,b);
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 9360
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int (x); SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long (x); SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
#define M0(x) memset(x,0,sizeof(x))
#define FILL(x,y) memset(x,y,sizeof(x))
#define MM(x) memset(x,-1,sizeof(x))
#define ALL(x) (x).begin(),(x).end()
using namespace std;
typedef pair<int,int> PII;
typedef pair<long long,long long> PLL;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
///////////////////////////////////////////////
const ll MOD = 1000000007;
ll gcd(ll x,ll y){return y?gcd(y,x%y):x;}

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(){
    int N,x;
    SCD2(N,x);
    vector<int> a;
    REP(i,N){
        int in;
        cin >> in;
        a.PB(in);
    }

    sort(ALL(a));
    //reverse(ALL(a));

    int ans = 0;

    REP(i,N-1){
        if (x <= 0) break;
        if (a[i] <= x){
            x = x - a[i];
            ans++;
        }
    }

    if (a[N-1] == x) ans++;

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <limits>
#define REP(i,n) for(long (i)=0;(i)<(n);(i)++)
#define INF numeric_limits<double>::infinity()
constexpr long MOD = 1e9 + 7;
using namespace std;

int main() {
    long n, t, a;
    long tak, aok;
    cin >> n;
    
    REP(i,n) {
        if (i == 0) {
            cin >> tak >> aok;
        } else {
            cin >> t >> a;
            
            if (t >= tak && a >= aok) {
                tak = t;
                aok = a;
            } else if (t >= tak) {
                long c = aok / a;
                if (aok % a != 0) c++;
                tak = t * c;
                aok = a * c;
            } else if (a >= aok) {
                long d = tak / t;
                if (tak % t != 0) d++;
                tak = t * d;
                aok = a * d;
            } else {
                long c = aok / a;
                if (aok % a != 0) c++;
                long d = tak / t;
                if (tak % t != 0) d++;
                c = max(c,d);
                tak = t * c;
                aok = a * c;
            }
        }
    }
    cout << tak + aok << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2005,mod=1000000007;
int n,dp[N][N],s[N][N],ans;
int main()
{
	scanf("%d",&n);
	for(int j=0;j<=n;j++)
		s[0][j]=1;
	for(int i=1;i<=n;i++)
	{
		for(int j=3;j<=n;j++)
		{
			dp[i][j]=s[i-1][j-3];
			s[i][j]=(s[i][j-1]+dp[i][j])%mod;
		}
		ans=(ans+dp[i][n])%mod;
	}
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;
#define X first
#define Y second
#define mid ((l+r)>>1)
#define lc k<<1,l,mid
#define rc k<<1|1,mid+1,r
#define pb push_back
typedef double db;
typedef long long ll;
typedef pair<int,int> P;
const int MAXN=5e5+10,INF=1<<28;
struct edge{int nxt,to;}e[MAXN<<2];
int head[MAXN],tot;
int n,k,in[MAXN],a[MAXN],pos[MAXN],seg[MAXN<<2];

void add_edge(int x,int y)
{e[++tot]=(edge){head[x],y};head[x]=tot;in[y]++;}
void Update(int pos,int val,int k,int l,int r)
{
	seg[k]=min(seg[k],val);
	if(l==r) return;//最后一层也要先更新再返回！ 
	if(pos<=mid) Update(pos,val,lc);
	else Update(pos,val,rc);
}
void Query(int &mn,int a,int b,int k,int l,int r)
{
	if(a<=l&&r<=b)
	{mn=min(mn,seg[k]);return;}
	if(a<=mid) Query(mn,a,b,lc);
	if(b>mid) Query(mn,a,b,rc);
}

int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++) 
		scanf("%d",&a[i]),pos[a[i]]=i;
	for(int i=0;i<=4*n;i++) seg[i]=INF;
	for(int i=n;i>=1;i--)
	{
		int nxt=INF,pre=INF;
		//注意询问必须保证与[1,n]相交 
		Query(nxt,pos[i],pos[i]+k-1,1,1,n);
		Query(pre,pos[i]-k+1,pos[i],1,1,n);
		if(nxt!=INF) add_edge(pos[i],pos[nxt]);
		if(pre!=INF) add_edge(pos[i],pos[pre]);
		Update(pos[i],i,1,1,n);
	}
	
	priority_queue<int,vector<int>,greater<int> > q;
	for(int i=1;i<=n;i++)
		if(!in[i]) q.push(i);
	for(int i=1;i<=n;i++)
	{
		int t=q.top();q.pop();
		pos[i]=t;
		for(int j=head[t];j;j=e[j].nxt)
			if(!(--in[e[j].to])) q.push(e[j].to);
	}
	for(int i=1;i<=n;i++) a[pos[i]]=i;
	for(int i=1;i<=n;i++) printf("%d\n",a[i]);
	return 0;
}
/*
6 2
2 3 5 6 4 1 
*/

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

class Main {

	public static void main(String[] args) throws Exception {
		final Scanner sc = new Scanner(System.in);
		int M = sc.nextInt();
		long n = 0;
		long sum = 0;
		for (int i = 0; i < M; i++) {
			long d = sc.nextLong();
			long c = sc.nextLong();
			n += c;
			sum += d * c;
		}
		System.out.println((n - 1) + (sum - 1) / 9);
	}
}


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

int main(void)
{
    int N;
    cin >> N;
    int d[N];
    for (int i = 0; i < N; i++) {
        cin >> d[i];
    }

    sort(d, d+N);
    cout << d[N/2] - d[N/2-1] << endl;
}

Measured memory_bytes: 640