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

// #define _GLIBCXX_DEBUG
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define NP next_permutation;
#define pb push_back
#define eb emplace_back
#define pob pop_back
#define puf push_front
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;

const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;

template<class T> bool chmin(T&a,T b){if(a>b){a=b; return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b; return true;}return false;}
template<class T> void decimal(T a){cout<<fixed<<setprecision(a);}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<endl;}
template<class T> void outvp(T v){rep(i,v.size())outp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}

void YesNo(bool a){if(a) out("Yes"); else out("No");}
void yesno(bool a){if(a) out("yes"); else out("no");}
void YESNO(bool a){if(a) out("YES"); else out("NO");}
ll GCD(ll a,ll b){ll c; while(b!=0){c=a%b; a=b; b=c;} return a;}
ll LCM(ll a,ll b){return(a/GCD(a,b))*(b/GCD(a,b))*GCD(a,b);}
ll POW(ll a,ll b){ll c=1; while(b>0){if(b&1){c=a * c%mod;} a=a * a%mod; b>>=1;} return c;}
vi calc(ll x){vi res; while(x>0){res.pb(x%10); x/=10;} reverse(all(res)); return res;}

void solve() {
  int n,x=0,y=0; cin>>n;
  vi A(n); rep(i,n) cin>>A[i];
  sort(all(A));
  rep(i,n){
    if(i%2==0) x+=A[i];
    else y+=A[i];
  }
  out(max(x-y,y-x));
}

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


Measured memory_bytes: 256
//g++  7.4.0

#include <bits/stdc++.h>
using namespace std;
#define int long long
signed main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n , k;
    cin >> n >> k;
    vector<int> ar(n);
    for(int & i : ar) cin >> i;
    
    int l = 0;
    int h = *max_element(ar.begin() , ar.end());

    auto fun = [&](int x){ // want the largest length to be x , minimize x
        int cuts = 0;
        for(const int i : ar){
            if(x >= i)
                continue;
            int rem = i - x;
            cuts++;
            if(rem > x)
                cuts += ((rem + x - 1)/x - 1);
        }
        return cuts <= k;
    };
    
    while(l + 1 < h){
        int mid = (l + h) >> 1;
        if(fun(mid))
            h = mid;
        else
            l = mid;
    }
    cout << h << '\n';
    
    return 0;
}


Measured memory_bytes: 4760
module module_sort
    implicit none
    interface sort
        module procedure int_heap_sort, real_heap_sort
    end interface

    contains

        subroutine int_heap_down(a,node,las)
            implicit none
            integer(8) a(*),x
            integer(8) node,par,ch1,ch2,las
            par = node
            x = a(par); ch1 = par*2
            do while(ch1 <= las)
                ch2 = ch1+1
                if(ch2 <= las .and. a(ch1) < a(ch2)) ch1 = ch2
                if(a(ch1) > x) then
                    a(par) = a(ch1); a(ch1) = x
                else 
                    exit
                end if
                par = ch1; ch1 = par*2
            end do
        end subroutine int_heap_down

        subroutine int_heap_sort(a,n)
            implicit none
            integer(8) a(*),x
            integer(8) n,i
            do i = n/2, 1, -1
                call int_heap_down(a,i,n)
            end do
            do i=n,2,-1
                x = a(i); a(i) = a(1); a(1) = x
                call int_heap_down(a,1_8,i-1)
            end do
        end subroutine int_heap_sort

        subroutine real_heap_down(a,node,las)
            implicit none
            real a(*), x
            integer(8) node,par,ch1,ch2,las
            par = node
            x = a(par); ch1 = par*2
            do while(ch1 <= las)
                ch2 = ch1+1
                if(ch2 <= las .and. a(ch1) < a(ch2)) ch1 = ch2
                if(a(ch1) > x) then
                    a(par) = a(ch1); a(ch1) = x
                else 
                    exit
                end if
                par = ch1; ch1 = par*2
            end do
        end subroutine real_heap_down

        subroutine real_heap_sort(a,n)
            implicit none
            real a(*),x
            integer(8) n,i
            do i = n/2, 1, -1
                call real_heap_down(a,i,n)
            end do
            do i=n,2,-1
                x = a(i); a(i) = a(1); a(1) = x
                call real_heap_down(a,1_8,i-1)
            end do
        end subroutine real_heap_sort

end module module_sort

program ActiveInfants
    use module_sort
    implicit none
    integer(8) :: N,A(3000),B(3000),dp(0:3000,0:3000) = -1,shift = 100000,nowA,nowidx,ans = -1
    integer(8) :: i,j

    read *,N,A(1:N)

    do i = 1, N
        B(i) = A(i)*shift+i
    end do 

    call sort(B,N)
    B(1:N) = B(N:1:-1)

    dp(0,0) = 0

    do i = 0, N
        do j = 0, N
            !print *,i,j,dp(i,j)
            if(i+j == N) ans = max(dp(i,j),ans)
            if(i+j >= N) cycle
            nowA = B(i+j+1)/shift
            nowidx = mod(B(i+j+1),shift)
            dp(i+1,j) = max(dp(i+1,j),dp(i,j)+nowA*abs(nowidx-(i+1)))
            dp(i,j+1) = max(dp(i,j+1),dp(i,j)+nowA*abs(nowidx-(N-j)))
        end do
    end do

    print '(i0)', ans

end program ActiveInfants

Measured memory_bytes: 49916
#include <stdio.h>

int n;
int bounce[300000];

int IsReachable() {
    int i, current = 0;
    for ( i=0; i<n; ++i ) {
	if ( current < 10*i ) return 0;
	if ( current < 10*i + bounce[i] ) current = 10*i + bounce[i];
	if ( current >= 10*n ) return 1;
    }
    return 0;
}

int main() {
    int i;
    scanf("%d", &n);
    for ( i=0; i<n; ++i ) scanf("%d", &bounce[i]);
    if ( !IsReachable() ) {
	printf("no\n");
	return 0;
    }
    
    for ( i=0; i<n/2; ++i ) {
	int tmp = bounce[i];
	bounce[i] = bounce[n-i-1];
	bounce[n-i-1] = tmp;
    }
    if ( !IsReachable() ) printf("no\n");
    else printf("yes\n");
    
    return 0;
}



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

int main()
{
  int N, K;
  string S;
  cin >> N;
  cin>>S;
  cin>>K;
  for (int i=0;i<N;i++) {
    if(S[i]!=S[K-1]){
      S[i]='*';
    }
  }
  cout << S;
}

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

using namespace std;

int main(){
	int n,q,a,c;
	c = 0;
	cin >> n;
	vector<int> s(n);
	for(int i = 0;i < n;++i){
		cin >> a;
		s[i] = a;
	}
	cin >> q;
	vector<int> t(q);
	for(int i = 0;i < q;++i){
		cin >> a;
		t[i] = a;
	}
	for(int i = 0;i < q;++i){
		a = t[i];
		if(find(s.begin(), s.end(), a) != s.end()) ++c;
	}
	cout << c << endl;
	return 0;
}

Measured memory_bytes: 1232
/*
coded by : Bissultanov Yedyge;
:)
¤
•
¦
§
*/
#include <bits/stdc++.h>
 
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
 
#define mp make_pair
#define np next_permutation
 
#define bg begin()
#define ed end()
 
#define int long long
#define ioi return 0;
 
#define sz size()
#define fix fixed<<setprecision
 
#define lb lower_bound
#define ub upper_bound
 
#define fr first
#define sc second
 
#define pb push_back
#define ppb pop_back
 
#define pf push_front
#define ppf pop_front
 
typedef long double ld;
typedef unsigned long long ull;
 
const int N = (int)5e5 + 7;
const int inf = (int)1e9 + 7;
 
using namespace std;
 
int n , m , k;
int a[N] , b[N];
int ans, cnt;
 
main(){
	ios
		cin >> n >> m >> k;
		cout << min(m/n,k);
	ioi	
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;
import java.io.*;
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		int a, b;
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str = br.readLine();
		String[] str1Ary = str.split(" ");
		a = Integer.parseInt(str1Ary[0]);
		b = Integer.parseInt(str1Ary[1]);
		if (a > b){
			System.out.println("a > b");
		}else if (a < b){
			System.out.println("a < b");
		}else{
			System.out.println("a == b");
		}
	}
}

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

#define pb push_back

typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pair<int, int>> vpii;
typedef long long ll;	

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

	int A, B, C;

	cin >> A >> B >> C;

	swap(A, B);
	swap(A, C);

	cout << A << " " << B << " " << C << "\n";
	return 0;	
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
#define N (int)1e5
#define F first
#define S second
typedef pair<int, int> P;
int n, m, ans;
int l[3 * N + 1], r[3 * N + 1];
P lr[3 * N + 1];
int bit[N + 1];
int sum(int i, int *b)
{
	int s = 0;
	while (i > 0)
	{
		s += b[i];
		i = i & (i - 1);
	}
	return s;
}
void add(int i, int x, int *b)
{
	while (i <= m)
	{
		b[i] += x;
		i += i & -i;
	}
}
int main()
{
	cin >> n >> m;
	for (int i = 0; i < n; i++)
	{
		scanf("%d%d", &lr[i].S, &lr[i].F);
		lr[i].F = lr[i].F - lr[i].S + 1;
	}
	sort(lr, lr + n);
	int p1 = 0, p2 = 0;
	for (int i = 1; i <= m; i++)
	{
		ans = 0;
		p2 = lower_bound(lr, lr + n, make_pair(i, 0)) - lr;
		ans = n - p2;
		for (int j = p1; j < p2; j++)
		{
		    add(lr[j].S, 1, bit);
			add(lr[j].F + lr[j].S, -1, bit);
		}
		p1 = p2;
		for (int j = 0; j <= m; j += i)
		{
			ans += sum(j , bit);
		}
		cout << ans << endl;
	}
	return 0;
}



Measured memory_bytes: 4992
#include <iostream>
#include <vector>
#include <string>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>

using namespace std ;

typedef long long ll ;


int dp[3005][3005] ;
int pi[3005][3005] , pj[3005][3005] ;

void print( int arr[3005][3005], int m , int n ){
    for( int i = 0 ; i <= m ; i++ ){
        for( int j = 0 ; j <= n ; j++ ){
            cout << arr[i][j] << " " ;
        }
        cout << endl ;
    }
    cout << endl ;
}

int main(){
    string s , t ;
    cin >> s >> t ;
    for( int i = 1 ; i <= s.size() ; i++ ){
        for( int j = 1 ; j <= t.size() ; j++ ){
            dp[i][j] = 0 ; 
            if( s[i-1] == t[j-1] ) {
                if( dp[i][j] < 1 + dp[i-1][j-1]){
                    dp[i][j] = max(dp[i][j], 1+dp[i-1][j-1]) ;
                    pi[i][j] = i-1 ;
                    pj[i][j] = j-1 ;
                }
            }
            if( dp[i][j] < dp[i-1][j]){
                dp[i][j] = max(dp[i][j],dp[i-1][j]) ;
                pi[i][j] = i-1 ;
                pj[i][j] = j ;
            }
            if( dp[i][j] < dp[i][j-1]){
                dp[i][j] = max(dp[i][j],dp[i][j-1]) ;
                pi[i][j] = i ;
                pj[i][j] = j-1 ;
            } 
        }
    } 
    int i = s.size() , j = t.size() ;
    string ans ;
    // cout << i << " " << j << endl ;
    int I , J ;
    while( i != 0 && j != 0  ){
        if( s[i-1] == t[j-1] ){
            ans += s[i-1] ;
        }
        I = pi[i][j] ;
        J = pj[i][j] ;  
        i = I ;
        j = J ;        
        // cout << i << " " << j << endl ; 
    }
    // print(dp,s.size(), t.size());
    // print(pi,s.size(), t.size()) ;
    // print(pj,s.size(),t.size()) ;
    reverse(ans.begin(),ans.end());
    // cout << dp[s.size()][t.size()] ;
    cout << ans << endl ;
    return 0 ;
}

Measured memory_bytes: 109244
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 
  
int main()
{
    int n,k,s;
    cin>>n>>k>>s;
    int p=s+1;
    if(s==1e+9)
    {
        p=1;
    }
    for(int i=1;i<=k;i++)
        cout<<s<<" ";
    for(int i=k+1;i<=n;i++)
        cout<<p<<" ";
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;


int main() {
    int N;
    cin >> N;
    vec<int> l(N);
    vec<int> r(N);

    rep(i,N){
        cin >> l[i] >> r[i];
    }

    sort(all(l));sort(all(r));
    if(N%2==1){
        cout << r[N/2] - l[N/2] +1 <<endl;
    } else {
        cout << ((r[(N-1)/2] + r[N/2]) - (l[(N-1)/2]+l[N/2])) + 1<<endl;
    }
}


Measured memory_bytes: 4824
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int l = (int)s.size();
    //cout << l << endl;
    vint cnt(26,0);
    if(l==26){
        for(int i=l-1;i>=0;i--){
            cnt[(s[i]-'a')]++;
            for(int j=(s[i]-'a')+1;j<26;j++){
                if(cnt[j]==1){
                    cout << s.substr(0,i) + ((char)('a'+j)) << endl;
                    return 0;
                }
            }
        }
        puts("-1");
        return 0;
    }
    for(char c : s){
        cnt[(c-'a')]++;
    }
    char ad;
    REP(i,26){
        if(cnt[i]==0){
            ad = (char)('a'+i);
            break;
        }
    }
    cout << s << ad << endl;

    return 0;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN3(a,b,c);
  Yes(a==b && b==c);
}

Measured memory_bytes: 256
/****************************
/////  Shubham Singhal
/////  LNMIIT
*****************************/
#include <bits/stdc++.h>
#define ff first
#define ss second
#define mp make_pair
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define eb emplace_back
#define lwr lower_bound
#define upr upper_bound
#define pq priority_queue
#define umap unordered_map
#define rep(i,n) for(i=0; i<n;i++)
#define repp(i,a,n) for(i=a; i<n;i++)
#define precise(x) cout<<fixed<<setprecision(x)
#define all(x) x.begin(),x.end()
#define lcm(a,b) (a*b)/__gcd(a,b)
#define prn(x) cout<<x<<"\n"
#define prn2(x, y) cout<<x<<" "<<y<<"\n"
#define prn3(x, y, z) cout<<x<<" "<<y<<" "<<z<<"\n"
#define prn4(x, y, z, a) cout<<x<<" "<<y<<" "<<z<<" "<<a<<"\n"
#define prnv(x) for(auto i:x) cout<<i<<" "; cout<<"\n"
#define MOD 1000000007
#define MAX 300005
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;
typedef double ld;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<int, ll> pil;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd; 
typedef vector<int> vi;
typedef vector<long> vl;
typedef vector<char> vc;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<pii> vpii;
typedef vector<pil> vpil;
typedef vector<pli> vpli;
typedef vector<pll> vpll;
const long long INF = 1e18;
clock_t time_p=clock();
void time()
{
    time_p=clock()-time_p;
    cerr<<"Time Taken : "<<(float)(time_p)/CLOCKS_PER_SEC<<"\n";
}
void doc()
{
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
}
void fast()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
}
void solve()
{
	ld n,m;
	cin>>n>>m;
	cout<<ceil(n/m);
}
int main()
{
	fast();
	ll t;
	t=1;
	while(t--)
		solve();
}

Measured memory_bytes: 256
#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<double, int>;

double n, t, a;

int main() {
  cin >> n >> t >> a;
  vector<int> h(n);
  rep (i, n) {
    cin >> h[i];
  }
  vector<P> v(n);
  rep (i, n) {
    v[i] = make_pair(abs(a - t + 0.006 * h[i]), i+1);
  }
  sort(v.begin(), v.end());
  cout << v[0].second << endl;
  return 0;
}


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

#define froop1(a,n) for(long long i = a;i < n;i++)
#define froop2(a,n) for(int i = a;i > n;i--)
int main(){
	string N;
  cin >> N;
  froop1(0,N.length()){
    if(N[i] == '7'){
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;

}


Measured memory_bytes: 3620
# -*- coding: utf-8 -*-
# case.rb

loop{ # 無限ループをするメソッド
  
  a, op, b =  STDIN.gets.split(' ')
  a = a.to_i
  b = b.to_i

  # ここから下を変える
  if op == "?" then
    break
  else
    puts(case op
         when "+"
           a + b
         when "-"
           a - b
         when "*"
           a * b
         when "/"
           a / b
         end)
  end
}

Measured memory_bytes: 8632
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end())
#define VRSORT(v) sort(v.rbegin(), v.rend())
#define ll int64_t
#define pb(a) push_back(a)
#define INF 1000000000
#define MOD 1000000007
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

typedef vector<unsigned int>vec;
typedef vector<vec> mat;

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> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

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

vector<int> e[10];
int dp[11][2001];

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    REP(i,a){
        int c,d;
        cin>>c>>d;
        e[d-1].push_back(c);
    }
    REP(i,10) sort(e[i].begin(),e[i].end());
    REP(i,11) REP(j,2001) dp[i][j] = -INF;
    dp[0][0] = 0;
    for(int i=1;i<=10;i++){
        for(int j=0;j<=b;j++){
            int now=0;
            for(int k=0;k<=j&&k<=e[i-1].size();k++){
                chmax(dp[i][j],dp[i-1][j-k] + now + k*(k-1));
                if(k<e[i-1].size()) now+= e[i-1][e[i-1].size()-1-k];
            }
        }
    }
    cout<<dp[10][b]<<endl;
}


Measured memory_bytes: 3276
#include <bits/stdc++.h>
#ifdef __LOCAL
    #define DBG(X) cout << #X << " = " << (X) << endl;
    #define SAY(X) cout << (X) << endl;
    #include <filesystem>
    namespace fs = std::filesystem;
#else
    #define DBG(X)
    #define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

int dx[]={1, 0, -1, 0, 1,-1, 1,-1};
int dy[]={0, 1, 0, -1, 1, 1,-1,-1};
const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);
static mt19937 _g(time(nullptr));
 
inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const map<T, S> p) { for (auto el : p) cout << "[" << el.first << ";" << el.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

int N;
ll Y;
void input(){
    fast_io();
    #ifdef __LOCAL
        fs::path __p = __FILE__;
        fs::path __input, __output;
        __input = __output = __p.parent_path();
        __input += string("/input/") + string(__p.stem()) + string(".txt");
        __output += string("/output/") + string(__p.stem()) + string(".txt");
        freopen(__input.c_str(), "r", stdin);
        freopen(__output.c_str(), "w", stdout);
    #endif
    cin >> N >> Y;
}

int solve(){
    for (int x = 0; x <= N; x++)
    {
        for (int y = 0; y <= N; y++)
        {
            ll Z = (Y-10000*x-5000*y);
            if(Z%1000==0 && Z>=0) {
                int z=Z/1000;
                if((x+y+z)!=N) continue;
                printf("%d %d %d",x,y,z);
                return 0;
            }
        }
        
    }
    printf("%d %d %d",-1,-1,-1);
    return 0;
}   

int main()
{
    input();
    solve();
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using ll  = long long;
using vvl = vector<vector<ll>>;
using vl  = vector<ll>;
#define _GLIBCXX_DEBUG
#define acc_io cin.tie(0);ios::sync_with_stdio(false)
#define all(x) x.begin(),x.end()
#define rep(i,sta,end) for(ll i=sta;i<end;i++)
#define lcm(a,b) (a)/__gcd((a),(b))*(b)
#define pb push_back
const ll MOD = 1000000007;
const double PI = acos(-1);  
//name[i]   -> vl  name(i)
//name[i][j]-> vvl name(i,vl(j))
//or-> ||
//map<int,int>mp

ll n;
ll ans;
//string s;
signed main(){
	acc_io;
	ans=0;
	cin>>n;
	vl t(n);
	rep(i,0,n){
		cin>>t[i];
//		t[i]%=MOD;
	}
	ans=t[0];
	rep(i,1,n){
		ans=lcm(ans,t[i]);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const MOD: i64 = 1e+9 as i64 + 7;

fn calc(depth: usize, rest: usize, seq: &Vec<char>, memo: &mut Vec<Vec<i64>>) -> i64 {
    let n = seq.len();
    if depth == n {
        if rest == 5 {
            return 1;
        } else {
            return 0;
        }
    }
    if memo[depth][rest] != -1 {
        return memo[depth][rest];
    }
    let mut ret = 0;
    for i in 0..10 {
        if seq[depth] == '?' || (seq[depth] as u8 - '0' as u8) as usize == i {
            let nrest = (rest * 10 + i) % 13;
            ret = (ret + calc(depth + 1, nrest, seq, memo)) % MOD;
        }
    }
    memo[depth][rest] = ret;
    return ret;
}

fn main() {
    let seq = read::<String>().chars().collect::<Vec<char>>();
    let n = seq.len();
    let mut memo = vec![vec![-1; 13]; n];
    let ans = calc(0, 0, &seq, &mut memo);
    println!("{}", ans);
}


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

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef vector<vector<pii> > vvpii;

#define pb push_back
#define endl '\n'
#define INF (int)1e9
#define EPS 1e-9
#define gcd __gcd
#define rs resize
#define FOR(i,a,b) for(int i = a; i < b; i++)
#define by(T, x) [](const T& a, const T& b) { return a.x < b.x; } //for struct sorting

void printV(vector<int> v){
	for(int i = 0; i < v.size(); i++){
		cout << v[i] << " " ;
	}
	cout << endl;
}

void print2V(vvi v){
	FOR(i, 0, v.size()){
		FOR(j, 0, v[i].size()){
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
}

int n;
vector<pair<int, int> > opinion[20];

int counter(int a){
	if(a == 0){
		return 0;
	}
	return counter(a>>1) + (a&1);
}

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		int t;
		cin >> t;
		int x, y;
		for(int j = 0; j < t; j++){
			cin >> x >> y;
			x--;
			opinion[i].push_back( make_pair(x, y) );
		}
	}
	int ans = 0;
	for(int bit = 1; bit < (1<<n); bit++){
//		cout << "bit is: " << bit << endl;
		bool flag = 1;
		for(int i = 0; i < n; i++){
//			cout << "i is: " << i << endl;
//			cout << "before choosing the chosen person, we have the current person's bit as: " << ( bit & (1 << i) ) << endl;
			if( !( bit & (1 << i) ) ){
//				cout << "not this person" << endl;
				continue;
			}
//			cout << "chosen person: " << i << endl;
			//now a person who is chosen is found, compare it with all other chosen ones
			for(int j = 0; j < opinion[i].size(); j++){
				int x = opinion[i][j].first;
				int y = opinion[i][j].second;
//				cout << "j is: " << j << endl;
//				cout << "before choosing the person to compare, we have the person's bit as: " << ( bit & (1 << x) ) << endl;
				if( ( (bit >> x) & 1 ) ^ y ){
//					cout << "MISMATCH" << endl;
					flag = 0;
					continue;
				}	
			}
		}
		if(flag == 1){
			ans = max(ans, counter(bit));
		}
//		cout << "ans is: " << ans << endl;
	}
	cout << ans;
}

Measured memory_bytes: 256
#include<stdio.h>
int main() {
	char S[100002];
	scanf("%s", S);
	int ans = 0;
	for (int i = 1; i < strlen(S); i++)
	{
		if (S[i] != S[i - 1]) {
			ans++;
		}
	}
	ans = ans;
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
//#pragma GCC optimize ("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("avx,avx2,fma")


#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/rope>
#define pb push_back
#define F first
#define S second
#define ins insert
#define mp make_pair
#define bit __builtin_popcount
#define md (l + ((r - l) / 2))
#define all(x) x.begin(),x.end()
#define eb emplace_back
#define ub upper_bound
#define lb lower_bound
#define ios ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define file(s) if (fopen(s".in", "r")) freopen(s".in", "r", stdin), freopen(s".out", "w", stdout)

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;


using ll = long long;



const int N = 2e5+33, mod = 1e9 + 7, mod2 = 998244353;
const int MAX = 1e5 + 11 , T = 2000;
const int INF1 = 2e9 + 11;
const ll INF2 = 2e18 + 11;
const double INF3 = 1e8 + 11;
const int base = 500;
const int P = 31;
const int dx[] = {1, -1, 0, 0, 1, 1, -1, -1};
const int dy[] = {0, 0, 1, -1, 1, -1, 1, -1};
const double EPS = 1e-4;
const double PI = acos(-1.0);


template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
template<typename T1, typename T2> inline void chmin(T1 &a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1 &a, T2 b) { if (a < b) a = b; }


typedef pair <int, int> pii;        // #include <ext/pb_ds/assoc_container.hpp>
typedef pair <ll, ll> pll;         // #include <ext/pb_ds/tree_policy.hpp>
typedef vector <int> vi;          // #include <ext/rope>
                // #include <ext/rope>
                                 // #include <ext/rope>
bool prime(int n) {             // template<typename T> using ordered_set = tree <T, null_type, less <T>, rb_tree_tag, tree_order_statistics_node_update>;
    for(int i=2;i<=sqrt(n);i++){
        if(n%i==0){return 0;}
    }return 1;}

void solve() {
    int n , k;
    cin >> n >> k;
    set<int> st;
    for(int i = 1; i <= k; i ++) {
        int d;
        cin >> d;
        while(d --) {
            int x;
            cin >> x;
            st.ins(x);
        }
    }
    cout << n-st.size();
}
/*

*/

main() {
    ios;
    int tt = 1;
//    cin >> tt;
    while(tt --) {
        solve();
//        brute();
    }
    return 0;
}
/*

*/


Measured memory_bytes: 3648
n, b, r = map(int, input().split())
b1 = n//(b+r)
b2 = n % (b+r)
if b == 0:
    print(0)
elif r == 0:
    print(n)
elif b2 != 0 and b2 <= b:
    b1 = b1*b + b2
    print(b1)
elif b2 != 0 and b2 > b:
    b1 = b1*b + b
    print(b1)
elif n % (b+r) == 0:
    print(b1*b)


Measured memory_bytes: 3060
var input = ""
process.stdin.resume();
process.stdin.setEncoding('utf-8');
process.stdin.on('data', function(chunk) {
  input += chunk;
});
 
process.stdin.on('end', function() {
  input = input.split("\n");
  i = 0
  while (input[i] != 0) {
    arr = input[i].split(" ");
    if (arr[0] != 0 || arr[1] != 0) {
      for (j = 0; j < arr[0]; j++) {
        h = "";
        for (k = 0; k < arr[1]; k++) {
          if ((j + k) % 2 == 0) {
            h = h + "#";
          } else {
            h = h + ".";
          }
        }
        console.log(h);
      }
      console.log("");
    }
    i++;
  }
});

Measured memory_bytes: 10472
import java.io.PrintWriter;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		PrintWriter out = new PrintWriter(System.out);
        int x = Integer.parseInt(in.next());
        int y = Integer.parseInt(in.next());
        out.println(x*y+" "+(x*2+y*2));
        out.flush();
        in.close();
	}
}

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

int main(){
 int N;
 cin >> N;
 string str;
 int count = 0;
 for(int i = 1; i <=N; i++){
  str = to_string(i);
  if(str.size() % 2 ==1){
    count++;
  }
 }
 cout << count << endl;
}


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

int n, q;

int main(void){
    // Your code here!
    cin >> n >> q;
    
    long long a[n];
    long long x[q];
    
    for(int i = 0; i < n; i++) cin >> a[i];
    for(int i = 0; i < q; i++) cin >> x[i];
    
    
    
    for(int i = 0; i < q; i++){
        int left;
        int right = 0;
        long long ans = 0;
        long long sum = 0;
        for(int left = 0; left < n; left++){
            while(right < n && sum + a[right] <= x[i]){
                sum += a[right];
                right++;
            }
            
            ans += (right - left);
            if(right == left) right++;
            else sum -= a[left];
            
        }            
        
        cout << ans << endl;
    
    }
   
}



Measured memory_bytes: 3900
import std.stdio, std.string, std.range, std.conv, std.array, std.algorithm, std.math, std.typecons;

void main() {
    auto tmp = readln.split.to!(long[]);
    const N = tmp[0], M = tmp[1];

    class City {long p, index, year, order; }
    City[] cityList;
    foreach (i; 0..M) {
        tmp = readln.split.to!(long[]);
        const P = tmp[0], Y = tmp[1];
        auto c = new City;
        c.p = P;
        c.index = i;
        c.year = Y;
        cityList ~= c;
    }
    cityList
        .dup
        .sort!((a,b) => a.p < b.p)
        .groupBy
        .map!(array)
        .each!(cs => cs
            .sort!((a,b) => a.year < b.year)
            .enumerate
            .array
            .each!(c => c.value.order = c.index));
    cityList.each!(c => writefln("%06d%06d",c.p, c.order+1));
}


Measured memory_bytes: 27260
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
#define INF 100000000
#define rep(i,s,n) for (int i = (int)(s); i < (int)(n); i++)
ll mod = 1000000007;
ll mod2 = 998244353;

int main(){
    vector<int> ans;
    while (true){
        int n;cin>>n;
        if (n==0) break;
        vector<int> a(n);
        ld sum = 0;
        rep(i,0,n){
            cin>>a[i];
            sum+=a[i];
        } 
        ld ave = sum/n;
        int num = 0;
        rep(i,0,n){
            if (a[i]<=ave) num+=1;
        }
        ans.push_back(num);
    }
    for(int an:ans){
        cout<<an<<endl;
    }
}


Measured memory_bytes: 3152
x,y,a,b,c=map(int,input().split())
p=list(map(int,input().split()))
q=list(map(int,input().split()))
r=list(map(int,input().split()))
p=sorted(p,reverse=True)
q=sorted(q,reverse=True)
r=sorted(r,reverse=True)
s=[]
for i in range(x):
    s.append(p[i])
for i in range(y):
    s.append(q[i])
s=sorted(s,reverse=True)
ws=[s[0]]
for i in range(x+y-1):
    ws.append(ws[-1]+s[i+1])
wr=[r[0]]
for i in range(c-1):
    wr.append(wr[-1]+r[i+1])
ans=ws[-1]
for i in range(min(x+y-1,c)):
    ans=max(ans,ws[-2-i]+wr[i])
print(ans)



Measured memory_bytes: 113464
while True:
    record=str(input())
    if record=="0":
        break
    A=0
    B=0
    for i in range(1,len(record)):
        if record[i]=="A":
            A+=1
        else:
            B+=1
    if A>B:
        A+=1
    else:
        B+=1
    print(A,B)


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

int H,W;
char t[3005][3005];

bool check(int y,int x,int dir){
  if(dir==1){
    return (t[y][x]=='R'&&t[y][x+1]=='G'&&t[y][x+2]=='W');
  }else{
    return (t[y][x]=='R'&&t[y+1][x]=='G'&&t[y+2][x]=='W');
  }
}

int mem[5000][5];
int solve(int y,int x,int z,int d){
  if(y>=H || x<0)return 0;
  if( mem[d][z] != -1 )return mem[d][z];
  int res=solve(y+1,x-1,max(z-1,0),d+1);
  if(z==0&&check(y,x,1)){
    res=max(res, solve(y+1,x-1,0,d+1)+1);
  }
  if(check(y,x,0)){
    res=max(res, solve(y+1,x-1,2,d+1)+1);
  }

  return mem[d][z]=res;
}

int main(){
  scanf("%d %d",&H,&W);
  for(int i=0;i<H;i++)scanf("%s",t[i]);
  int ans=0;
  for(int j=0;j<W-1;j++){
    memset( mem, -1, sizeof(mem) );
    int tmp=solve(0,j,0,0);
    ans+=tmp;
  }
  for(int i=0;i<H;i++){
    memset( mem, -1, sizeof(mem) );
    int tmp=solve(i,W-1,0,0);
    ans+=tmp;
  }
  printf("%d\n",ans);
  return 0;
}



Measured memory_bytes: 12392
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) begin(v),end(v)
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

int main() {
	bool ans = true;
	int N;
	cin >> N;
	REP(i, N) {
		int A;
		scanf("%d", &A);
		if (A % 2 == 1) continue;
		ans &= A % 3 == 0 || A % 5 == 0;
	}
	
	puts([&] {
		return ans;
	}() ? "APPROVED": "DENIED");
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;
typedef pair<int, int> ii;

int main() {
    const int INF = 1000000;
    int N, M;
    cin >> N >> M;
    int dist[100][100];
    vector<ii> edges;
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            dist[i][j] = i == j ? 0 : INF;
        }
    }
    for (int i = 0; i < M; i++) {
        int a, b, c;
        cin >> a >> b >> c;
        dist[a-1][b-1] = c;
        dist[b-1][a-1] = c;
        edges.push_back(ii(a-1, b-1));
    }

    int min_dist[100][100];
    for (int i = 0; i < N; i++) {
        for (int j = 0; j < N; j++) {
            min_dist[i][j] = dist[i][j];
        }
    }

    for (int k = 0; k < N; k++) {
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                min_dist[i][j] = min(min_dist[i][j], min_dist[i][k] + min_dist[k][j]);
            }
        }
    }

    int ans = 0;
    for(auto it = edges.begin(); it != edges.end(); ++it) {
        int ci = it->first, cj = it->second;
        for (int i = 0; i < N; i++) {
            for (int j = 0; j < N; j++) {
                if (min_dist[i][j] == min_dist[i][ci] + dist[ci][cj] + min_dist[cj][j]) goto used;
            }
        }
        ans++;
        used: ;
    }
    cout << ans << endl;
}


Measured memory_bytes: 384
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
	public static void main(String[] args) {
		try (Scanner sc = new Scanner(System.in)) {
			int n = sc.nextInt();
			int m = sc.nextInt();
			UnionFind uf = new UnionFind(n);
			for (int i = 0; i < m; i++) {
				int x = sc.nextInt() - 1;
				int y = sc.nextInt() - 1;
				int z = sc.nextInt();
				uf.unit(x, y);
			}
			Set<Integer> group = new HashSet<>();
			for (int i = 0; i < n; i++) {
				group.add(uf.root(i));
			}
			System.out.println(group.size());
		}
	}
}

class UnionFind {
	int[] par;
	int[] rank;

	UnionFind(int n) {
		par = new int[n];
		rank = new int[n];
		for (int i = 0; i < n; i++) {
			par[i] = i;
			rank[i] = 0;
		}
	}

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

	boolean same(int x, int y) {
		return root(x) == root(y);
	}

	void unit(int x, int y) {
		x = root(x);
		y = root(y);
		if (x == y) return;

		if (rank[x] < rank[y]) {
			par[x] = y;
		}
		else {
			par[y] = x;
			if (rank[x] == rank[y]) rank[x]++;
		}
	}
}

Measured memory_bytes: 95628
#include <stdio.h>

int main(void) {
	int kyori[100000];
	int kosuu;
	int nisuu;
	int current;
	int kyorisum;
	int idou;
	int i;
	kyori[0]=0;
	scanf("%d %d",&kosuu,&nisuu);
	for(i=1;i<kosuu;i++) {
		scanf("%d",&current);
		kyori[i]=kyori[i-1]+current;
	}
	kyorisum=0;
	current=0;
	for(i=0;i<nisuu;i++) {
		scanf("%d",&idou);
		if(idou>0)
		kyorisum=(kyorisum+(kyori[current+idou]-kyori[current]))%100000;
		else
		kyorisum=(kyorisum+(kyori[current]-kyori[current+idou]))%100000;
		current+=idou;
	}
	printf("%d\n",kyorisum);
	return 0;
}

Measured memory_bytes: 0
rInt :: String -> Int
rInt str = read str :: Int

divisors :: Int -> Int -> Int
divisors a b
  |a `mod` b  == 0 = 1
  |otherwise      = 0
  
main :: IO ()
main = do
  input <- getLine
  let hour = rInt input `div` 3600 
      min  = rInt input `div` 60 - hour * 60
      sec  = rInt input `mod` 60
  putStrLn $ show hour ++ ":" ++  show min ++ ":" ++ show sec 

Measured memory_bytes: 3640
#include <iostream>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <math.h>
#include <stdlib.h>
#include <algorithm>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

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_MAX	2,147,483,647 = 2*1.0e9

const ll INF = 1e11;

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

  vector<ll> s(A+2);
  s[0] = -INF;
  for(int i = 1; i <= A; i++) cin >> s[i];
  s[A+1] = INF;

  vector<ll> t(B+2);
  t[0] = -INF;
  for(int i = 1; i <= B; i++) cin >> t[i];
  t[B+1] = INF;

  vector<ll> x(Q);
  for(int i = 0; i < Q; i++) cin >> x[i];

  for(int i = 0; i < Q; i++){
    ll ans = 0;
    {
      vector<ll> cost(4,0);
      //最初に神社に行く場合
      auto it = lower_bound(s.begin(), s.end(), x[i]);
      int cnt = 0;
      //右と左で分ける
      for(int j = 0; j < 2; j++){
        int index = it - s.begin() - j;
        cost[cnt] += abs(x[i] - s[index]);
        cost[cnt+1] += abs(x[i] - s[index]);

        auto it2 = lower_bound(t.begin(), t.end(), s[index]);
        for(int k = 0; k < 2; k++){
          int index2 = it2 - t.begin() - k;
          cost[cnt] += abs(s[index] - t[index2]);
          cnt++;
        }
      }
      sort(cost.begin(), cost.end());
      ans = cost[0];
    }
    {
      //最初に寺に行く場合
      vector<ll> cost(4,0);
      auto it = lower_bound(t.begin(), t.end(), x[i]);
      int cnt = 0;
      //右と左で分ける
      for(int j = 0; j < 2; j++){
        int index = it - t.begin() - j;
        cost[cnt] += abs(x[i] - t[index]);
        cost[cnt+1] += abs(x[i] - t[index]);

        auto it2 = lower_bound(s.begin(), s.end(), t[index]);
        for(int k = 0; k < 2; k++){
          int index2 = it2 - s.begin() - k;
          cost[cnt] += abs(t[index] - s[index2]);
          cnt++;
        }
      }
      sort(cost.begin(), cost.end());
      ans = min(ans,cost[0]);
    }

    cout << ans << endl;

  }

  return 0;
}



Measured memory_bytes: 3712
#include <iostream>
#include <string>
#include <limits.h>
#include <math.h>
#include <vector>
#include <map>
#include <algorithm>
#include <queue>
using namespace std;
typedef long long ll;
 
int main(void){
    int Y, X, sy = 1, sx = 1;
    char c[55][55];
    cin >> Y >> X;
    int gy = Y, gx = X;
    for (int i = 0; i < Y; i++) cin >> c[i];
    
    int dy[4] = {1, 0, -1, 0}, dx[4] = {0, 1, 0, -1};
    int q[2500];
    
    queue<int> que_y, que_x;
    que_y.push(sy - 1);
    que_x.push(sx - 1);
    q[0] = 1;
    
    bool psd[55][55];
    int ed = 0;
    for (int i = 0; i <= Y; i++) {
        for (int j = 0; j <= X; j++) {
            if (i != Y && j != X && c[i][j] == '.') {
                psd[i][j] = true;
                ed++;
            }
            else psd[i][j] = false;
        }
    }
    
    int now = 0, cnt = 0, cnt2 = 0, ih = 0;
    while (1) {
        int qy = que_y.front(), qx = que_x.front();
        if (qy == gy - 1 && qx == gx - 1) {
            cout << ed - now - 1 << endl;
            return 0;
        }
        for (int i = 0; i < 4; i++) {
            if (min(qy + dy[i], qx + dx[i]) != -1 && psd[qy + dy[i]][qx + dx[i]]) {
                que_y.push(qy + dy[i]);
                que_x.push(qx + dx[i]);
                psd[qy + dy[i]][qx + dx[i]] = false;
                cnt2++;
            }
        }
        ih += cnt2;
        que_y.pop();  que_x.pop();
        cnt++;
        if (cnt == q[now]) {
            now++;  q[now] = cnt2;
            cnt = cnt2 = 0;
            if (ih == 0) {
                cout << -1 << endl;
                return 0;
            }
            ih = 0;
        }
    }
    
}


Measured memory_bytes: 256
import Data.List
import qualified Data.Map.Strict as M
import qualified Data.Set as S
import qualified Data.Vector.Storable as V

main = do
    s<-getLine
    t<-getLine
    putStrLn $ if check s t && check t s then "Yes" else "No"

check::String -> String -> Bool
check s t = all (==1) tl
    where
        al a (Just x) = Just (a:x)
        al a Nothing = Just [a]
        ms = foldl (\m (c,i) -> M.alter (al i) c m) M.empty $ zip s [0..]
        vt = V.fromList t
        tl = map (S.size . S.fromList . map (\i->vt V.! i)) $ M.elems ms

Measured memory_bytes: 52604
#include <bits/stdc++.h>
#define int long long
int n,k,i,j;
double ans,tmp;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
signed main(void)
{
	read(n),read(k);
	for (i=1;i<=n;i++)
	{
		tmp=1.0/n;
		j=i;
		while (j<k)
			j*=2,tmp/=2;
		ans+=tmp;
	}
	printf("%.11lf",ans);
	return 0;
} 

Measured memory_bytes: 256
import collections


def main():
    n = int(input())

    cuts = []
    chars = set()

    for i in range(n):
        s = input()
        d = collections.defaultdict(int)
        for c in s:
            chars.add(c)
            d[c] += 1
        cuts.append(d)

    res = ''
    for c in sorted(chars):
        count = min([d[c] for d in cuts])
        res = res + str(c * count)

    print(res)


if __name__ == '__main__':
    main()
    

Measured memory_bytes: 3444
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  ll T1, T2, A1, A2, B1, B2;
  cin>>T1>>T2>>A1>>A2>>B1>>B2;
  if(A1-B1<0) {
    swap(A1, B1);
    swap(A2, B2);
  }
  A1 = A1 - B1;
  A2 = A2 - B2;
  if(A1*T1+A2*T2>0) {
    cout<<0<<endl;
    return 0;
  }
  else if(A1*T1+A2*T2==0) {
    cout<<"infinity"<<endl;
    return 0;
  }
  ll x = abs(A1*T1+A2*T2);
  ll ans = 1;
  if(A1*T1%x==0) {
    ans += 2*(A1*T1/x) - 1;
  }
  else {
    ans += 2*(A1*T1/x);
  }
  cout<<ans<<endl;
}



Measured memory_bytes: 3604
from collections import defaultdict


N,P = map(int, input().split())
S = input()

"""
S[l:r]  : (S[l:] - S[r:]) / 10**x

Pが2,5以外であれば、S[l:]とS[r:]がPで割り切れればよい
2,5は10**xと互いに素ではないので例外。

例２の 2020について、左から4つ目の0に着目すると、
0
20
020
2020
いずれも2で割り切れるので、右端にくるものが２で割り切れるだけでよい。
"""

ans = 0

if P in [2,5]:
    for i in range(N):
        if int(S[i]) % P == 0:
            ans += i+1


else:
    mod_P = defaultdict(int)
    mod_P[0] += 1 # S[r:]が空文字になるばあいのやつ
    tmp = 0

    for i in range(N):
        tmp = int(S[N-1-i]) * pow(10, i, P) + tmp
        tmp %= P
        ans += mod_P[tmp]
        mod_P[tmp] += 1


print(ans)

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

int main(){
    int n;
    cin >> n;
    int a[200010]; 
    int b[200010];  //sorted
    for(int i=0; i<n; i++){
        cin >> a[i];
        b[i] = a[i];
    }
    sort(b, b+n);
    for(int i=0; i<n; i++){
        if(b[n-1]==a[i]){
            cout << b[n-2] << endl;
        }else{
            cout << b[n-1] << endl;
        }
    }
    return 0;
}

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


int main(){
  int flag=1;
  int *A;
  int j;
  int num;
  int N;
  int sum=0;

  scanf("%d",&N);
  A=(int *)malloc(num*sizeof(int));
  for(j=0;j<N;j++)
    scanf("%d",&A[j]);

  while(flag){
    flag=0;
    for(j=N-1;j>0;j--){
      if(A[j]<A[j-1]){
	num=A[j];
	A[j]=A[j-1];
	A[j-1]=num;
	sum++;
	flag=1;
      }
    }
  }
  for(j=0;j<N-1;j++)printf("%d ",A[j]);
  printf("%d\n%d\n",A[j],sum);
  


  
  return 0;
}
  
  



Measured memory_bytes: 2100
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

int main()
{
  int N;cin>>N;
  int P,min=0,count=0;

  for(int i=0;i<N;i++)
  {
    cin>>P;
    if(P<=min||i==0)
    {
      count+=1;
      min=P;
    }
  }
  cout<<count<<endl;

  return 0;
}


Measured memory_bytes: 256